-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(es): Handle import assertions correctly (#3113)
swc_ecma_codegen: - Implement codegen for static import assertions. swc_ecma_transforms_proposal: - `import_assertions`: Support `export`s. swc: - Add `jsc.experimental.keep_import_assertions`. node-swc: - Fix typo.
- Loading branch information
1 parent
cec325b
commit c9adf03
Showing
9 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import data from "./data.json" assert { type: "json" }; | ||
export { default as data2 } from "./data2.json" assert { type: "json" }; | ||
export * as data3 from "./data3.json" assert { type: "json" }; | ||
|
||
console.log(data); |
10 changes: 10 additions & 0 deletions
10
crates/swc_ecma_codegen/tests/fixture/issues/3110/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import data from "./data.json" assert { | ||
type: "json" | ||
}; | ||
export { default as data2 } from "./data2.json" assert { | ||
type: "json" | ||
}; | ||
export * as data3 from "./data3.json" assert { | ||
type: "json" | ||
}; | ||
console.log(data); |
1 change: 1 addition & 0 deletions
1
crates/swc_ecma_codegen/tests/fixture/issues/3110/output.min.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import data from"./data.json"assert{type:"json"};export{default as data2}from"./data2.json"assert{type:"json"};export*as data3 from"./data3.json"assert{type:"json"};console.log(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
crates/swc_ecma_transforms_proposal/tests/import_assertions.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use swc_ecma_parser::{EsConfig, Syntax}; | ||
use swc_ecma_transforms_proposal::import_assertions; | ||
use swc_ecma_transforms_testing::test; | ||
use swc_ecma_visit::Fold; | ||
|
||
fn tr() -> impl Fold { | ||
import_assertions() | ||
} | ||
|
||
fn syntax() -> Syntax { | ||
Syntax::Es(EsConfig { | ||
import_assertions: true, | ||
..Default::default() | ||
}) | ||
} | ||
|
||
test!( | ||
syntax(), | ||
|_| tr(), | ||
import_with_assertions, | ||
r#"import test from "./test.json" assert {type: "json"};"#, | ||
r#"import test from "./test.json";"# | ||
); | ||
|
||
test!( | ||
syntax(), | ||
|_| tr(), | ||
named_export_with_assertions, | ||
r#"export {default as test} from "./test.json" assert {type: "json"};"#, | ||
r#"export {default as test} from "./test.json";"# | ||
); | ||
|
||
test!( | ||
syntax(), | ||
|_| tr(), | ||
export_all_with_assertions, | ||
r#"export * from "./test.json" assert {type: "json"};"#, | ||
r#"export * from "./test.json";"# | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c9adf03
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
full_es2015
187498580
ns/iter (± 7260432
)189076559
ns/iter (± 7655898
)0.99
full_es2016
155759014
ns/iter (± 14395507
)156019303
ns/iter (± 6551378
)1.00
full_es2017
144298043
ns/iter (± 9650998
)160841750
ns/iter (± 5900545
)0.90
full_es2018
146159690
ns/iter (± 22739513
)161142346
ns/iter (± 9944646
)0.91
full_es2019
157485032
ns/iter (± 4631327
)160272282
ns/iter (± 5997001
)0.98
full_es2020
155930256
ns/iter (± 28949146
)161095291
ns/iter (± 8169884
)0.97
full_es3
191438500
ns/iter (± 25794382
)224226893
ns/iter (± 9766868
)0.85
full_es5
195575677
ns/iter (± 25387112
)201317059
ns/iter (± 10338457
)0.97
parser
689566
ns/iter (± 18212
)689438
ns/iter (± 21498
)1.00
This comment was automatically generated by workflow using github-action-benchmark.