Skip to content

Commit

Permalink
fix(es): Run esnext transforms on esnext target (#9644)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #9640
 - Closes #9641
  • Loading branch information
kdy1 authored Oct 15, 2024
1 parent 88a2186 commit 8a19201
Show file tree
Hide file tree
Showing 134 changed files with 2,861 additions and 863 deletions.
6 changes: 6 additions & 0 deletions .changeset/beige-moles-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc: patch
swc_core: patch
---

fix(es): Run esnext transforms on esnext target
17 changes: 4 additions & 13 deletions crates/swc/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ use swc_ecma_visit::{Fold, VisitMutWith};

pub use crate::plugin::PluginConfig;
use crate::{
builder::{should_enable, PassBuilder},
dropped_comments_preserver::dropped_comments_preserver,
SwcImportResolver,
builder::PassBuilder, dropped_comments_preserver::dropped_comments_preserver, SwcImportResolver,
};

#[cfg(test)]
Expand Down Expand Up @@ -712,21 +710,14 @@ impl Options {
!disable_all_lints
),
// Decorators may use type information
Optional::new(
decorator_pass,
should_enable(es_version, EsVersion::EsNext) && syntax.decorators()
),
Optional::new(decorator_pass, syntax.decorators()),
Optional::new(
explicit_resource_management(),
should_enable(es_version, EsVersion::EsNext)
&& syntax.explicit_resource_management()
syntax.explicit_resource_management()
),
// The transform strips import assertions, so it's only enabled if
// keep_import_assertions is false.
Optional::new(
import_assertions(),
should_enable(es_version, EsVersion::EsNext) && !keep_import_attributes
),
Optional::new(import_assertions(), !keep_import_attributes),
Optional::new(
typescript::tsx::<Option<&dyn Comments>>(
cm.clone(),
Expand Down
1 change: 1 addition & 0 deletions crates/swc/tests/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ fn create_matrix(entry: &Path) -> Vec<Options> {
.unwrap_or_default();

[
EsVersion::EsNext,
EsVersion::Es2022,
EsVersion::Es2021,
EsVersion::Es2020,
Expand Down
25 changes: 25 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9640/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$schema": "https://swc.rs/schema.json",
"module": {
"type": "es6"
},
"jsc": {
"target": "esnext",
"parser": {
"syntax": "typescript",
"decorators": true,
"importAssertions": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true,
"useDefineForClassFields": true
},
"keepClassNames": true,
"experimental": {
"keepImportAttributes": true,
"emitAssertForImportAttributes": false
}
},
"minify": false
}
12 changes: 12 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9640/input/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function computed() {
return function (target) {
console.log(target)
}
}

class User {
@computed()
get fullName() {
return 'foo'
}
}
17 changes: 17 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9640/output/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var _ts_decorate = require("@swc/helpers/_/_ts_decorate");
var _ts_metadata = require("@swc/helpers/_/_ts_metadata");
function computed() {
return function(target) {
console.log(target);
};
}
let User = class User {
get fullName() {
return 'foo';
}
};
_ts_decorate._([
computed(),
_ts_metadata._("design:type", void 0),
_ts_metadata._("design:paramtypes", [])
], User.prototype, "fullName", null);
25 changes: 25 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9641/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$schema": "https://swc.rs/schema.json",
"module": {
"type": "es6"
},
"jsc": {
"target": "es2015",
"parser": {
"syntax": "typescript",
"decorators": true,
"importAssertions": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true,
"useDefineForClassFields": true
},
"keepClassNames": true,
"experimental": {
"keepImportAttributes": true,
"emitAssertForImportAttributes": false
}
},
"minify": false
}
3 changes: 3 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9641/input/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@Injectable()
export class MyService { }

6 changes: 6 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9641/output/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate";
export class MyService {
}
MyService = _ts_decorate([
Injectable()
], MyService);
Loading

0 comments on commit 8a19201

Please sign in to comment.