Skip to content

Commit

Permalink
fix(oxc_transformer): alias es2015 to es6 (#7673)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz authored Dec 5, 2024
1 parent d0b78f7 commit 245d7d9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/options/es_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl FromStr for ESTarget {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.cow_to_lowercase().as_ref() {
"es5" => Ok(Self::ES5),
"es2015" => Ok(Self::ES2015),
"es6" | "es2015" => Ok(Self::ES2015),
"es2016" => Ok(Self::ES2016),
"es2017" => Ok(Self::ES2017),
"es2018" => Ok(Self::ES2018),
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_transformer/tests/integrations/es_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fn es_target() {

let cases = [
("es5", "() => {}"),
("es6", "a ** b"),
("es2015", "a ** b"),
("es2016", "async function foo() {}"),
("es2017", "({ ...x })"),
Expand Down
26 changes: 16 additions & 10 deletions crates/oxc_transformer/tests/integrations/snapshots/es_target.snap
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
---
source: crates/oxc_transformer/tests/integrations/es_target.rs
assertion_line: 50
snapshot_kind: text
---
########## 0 es5
() => {}
----------
(function() {});

########## 1 es2015
########## 1 es6
a ** b
----------
Math.pow(a, b);

########## 2 es2016
########## 2 es2015
a ** b
----------
Math.pow(a, b);

########## 3 es2016
async function foo() {}
----------
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
Expand All @@ -24,35 +30,35 @@ function _foo() {
return _foo.apply(this, arguments);
}

########## 3 es2017
########## 4 es2017
({ ...x })
----------
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
_objectSpread({}, x);

########## 4 es2018
########## 5 es2018
try {} catch {}
----------
try {} catch (_unused) {}

########## 5 es2019
########## 6 es2019
a?.b
----------
var _a;
(_a = a) === null || _a === void 0 ? void 0 : _a.b;

########## 6 es2019
########## 7 es2019
a ?? b
----------
var _a;
(_a = a) !== null && _a !== void 0 ? _a : b;

########## 7 es2020
########## 8 es2020
a ||= b
----------
a || (a = b);

########## 8 es2019
########## 9 es2019
1n ** 2n
----------

Expand All @@ -71,14 +77,14 @@ a || (a = b);
: ^^
`----

########## 9 es2021
########## 10 es2021
class foo { static {} }
----------
class foo {
static #_ = (() => {})();
}

########## 10 es2021
########## 11 es2021
class Foo { #a; }
----------
class Foo {
Expand Down
2 changes: 2 additions & 0 deletions napi/transform/test/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ describe('transform', () => {

describe('target', () => {
const data = [
['es5', '() => {};\n'],
['es6', 'a ** b;\n'],
['es2015', 'a ** b;\n'],
['es2016', 'async function foo() {}\n'],
['es2017', '({ ...x });\n'],
Expand Down

0 comments on commit 245d7d9

Please sign in to comment.