Skip to content

Commit 245d7d9

Browse files
authored
fix(oxc_transformer): alias es2015 to es6 (#7673)
Supported in [esbuild](https://esbuild.github.io/try/#dAAwLjI0LjAALS10YXJnZXQ9ZXM2ADEqKjI)
1 parent d0b78f7 commit 245d7d9

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

crates/oxc_transformer/src/options/es_target.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl FromStr for ESTarget {
2727
fn from_str(s: &str) -> Result<Self, Self::Err> {
2828
match s.cow_to_lowercase().as_ref() {
2929
"es5" => Ok(Self::ES5),
30-
"es2015" => Ok(Self::ES2015),
30+
"es6" | "es2015" => Ok(Self::ES2015),
3131
"es2016" => Ok(Self::ES2016),
3232
"es2017" => Ok(Self::ES2017),
3333
"es2018" => Ok(Self::ES2018),

crates/oxc_transformer/tests/integrations/es_target.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ fn es_target() {
1010

1111
let cases = [
1212
("es5", "() => {}"),
13+
("es6", "a ** b"),
1314
("es2015", "a ** b"),
1415
("es2016", "async function foo() {}"),
1516
("es2017", "({ ...x })"),

crates/oxc_transformer/tests/integrations/snapshots/es_target.snap

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
---
22
source: crates/oxc_transformer/tests/integrations/es_target.rs
3+
assertion_line: 50
34
snapshot_kind: text
45
---
56
########## 0 es5
67
() => {}
78
----------
89
(function() {});
910

10-
########## 1 es2015
11+
########## 1 es6
1112
a ** b
1213
----------
1314
Math.pow(a, b);
1415

15-
########## 2 es2016
16+
########## 2 es2015
17+
a ** b
18+
----------
19+
Math.pow(a, b);
20+
21+
########## 3 es2016
1622
async function foo() {}
1723
----------
1824
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
@@ -24,35 +30,35 @@ function _foo() {
2430
return _foo.apply(this, arguments);
2531
}
2632

27-
########## 3 es2017
33+
########## 4 es2017
2834
({ ...x })
2935
----------
3036
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
3137
_objectSpread({}, x);
3238

33-
########## 4 es2018
39+
########## 5 es2018
3440
try {} catch {}
3541
----------
3642
try {} catch (_unused) {}
3743

38-
########## 5 es2019
44+
########## 6 es2019
3945
a?.b
4046
----------
4147
var _a;
4248
(_a = a) === null || _a === void 0 ? void 0 : _a.b;
4349

44-
########## 6 es2019
50+
########## 7 es2019
4551
a ?? b
4652
----------
4753
var _a;
4854
(_a = a) !== null && _a !== void 0 ? _a : b;
4955

50-
########## 7 es2020
56+
########## 8 es2020
5157
a ||= b
5258
----------
5359
a || (a = b);
5460

55-
########## 8 es2019
61+
########## 9 es2019
5662
1n ** 2n
5763
----------
5864

@@ -71,14 +77,14 @@ a || (a = b);
7177
: ^^
7278
`----
7379

74-
########## 9 es2021
80+
########## 10 es2021
7581
class foo { static {} }
7682
----------
7783
class foo {
7884
static #_ = (() => {})();
7985
}
8086

81-
########## 10 es2021
87+
########## 11 es2021
8288
class Foo { #a; }
8389
----------
8490
class Foo {

napi/transform/test/transform.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ describe('transform', () => {
5757

5858
describe('target', () => {
5959
const data = [
60+
['es5', '() => {};\n'],
61+
['es6', 'a ** b;\n'],
6062
['es2015', 'a ** b;\n'],
6163
['es2016', 'async function foo() {}\n'],
6264
['es2017', '({ ...x });\n'],

0 commit comments

Comments
 (0)