Skip to content

Commit

Permalink
fix(es/parser): Support type-only export-import declarations (#5122)
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari authored and kdy1 committed Jul 6, 2022
1 parent 43744c9 commit fbfca36
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
10 changes: 7 additions & 3 deletions crates/swc_ecma_parser/src/parser/stmt/module_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,15 @@ impl<I: Tokens> Parser<I> {

if self.input.syntax().typescript() {
if eat!(self, "import") {
let is_type_only = is!(self, "type") && peeked_is!(self, IdentRef);

if is_type_only {
assert_and_bump!(self, "type");
}

// export import A = B
return self
.parse_ts_import_equals_decl(
start, /* is_export */ true, /* is_type_only */ false,
)
.parse_ts_import_equals_decl(start, /* is_export */ true, is_type_only)
.map(From::from);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export import type React = require("react");
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 45,
"ctxt": 0
},
"body": [
{
"type": "TsImportEqualsDeclaration",
"span": {
"start": 1,
"end": 45,
"ctxt": 0
},
"declare": false,
"isExport": true,
"isTypeOnly": true,
"id": {
"type": "Identifier",
"span": {
"start": 20,
"end": 25,
"ctxt": 0
},
"value": "React",
"optional": false
},
"moduleRef": {
"type": "TsExternalModuleReference",
"span": {
"start": 28,
"end": 44,
"ctxt": 0
},
"expression": {
"type": "StringLiteral",
"span": {
"start": 36,
"end": 43,
"ctxt": 0
},
"value": "react",
"raw": "\"react\""
}
}
}
],
"interpreter": null
}

1 comment on commit fbfca36

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: fbfca36 Previous: 1b34096 Ratio
es/full/minify/libraries/antd 1684663397 ns/iter (± 57523537) 1693615692 ns/iter (± 23505815) 0.99
es/full/minify/libraries/d3 431033776 ns/iter (± 5711636) 412903222 ns/iter (± 11355017) 1.04
es/full/minify/libraries/echarts 1961786819 ns/iter (± 469074577) 1662517279 ns/iter (± 28373379) 1.18
es/full/minify/libraries/jquery 92816003 ns/iter (± 12558033) 93132156 ns/iter (± 3196226) 1.00
es/full/minify/libraries/lodash 116715309 ns/iter (± 10835847) 119162782 ns/iter (± 4844053) 0.98
es/full/minify/libraries/moment 51071989 ns/iter (± 5675228) 55266362 ns/iter (± 2270355) 0.92
es/full/minify/libraries/react 17211563 ns/iter (± 1454353) 18053522 ns/iter (± 383126) 0.95
es/full/minify/libraries/terser 592219676 ns/iter (± 10835871) 618165281 ns/iter (± 13170322) 0.96
es/full/minify/libraries/three 534777188 ns/iter (± 5974478) 590573186 ns/iter (± 20566820) 0.91
es/full/minify/libraries/typescript 3385052917 ns/iter (± 68254170) 3607324774 ns/iter (± 91750060) 0.94
es/full/minify/libraries/victory 707682707 ns/iter (± 26987974) 711117122 ns/iter (± 6813167) 1.00
es/full/minify/libraries/vue 135195545 ns/iter (± 13181956) 133203979 ns/iter (± 5000884) 1.01
es/full/codegen/es3 31043 ns/iter (± 909) 31256 ns/iter (± 947) 0.99
es/full/codegen/es5 31081 ns/iter (± 367) 31723 ns/iter (± 1929) 0.98
es/full/codegen/es2015 31046 ns/iter (± 219) 31415 ns/iter (± 1876) 0.99
es/full/codegen/es2016 31056 ns/iter (± 287) 30794 ns/iter (± 2298) 1.01
es/full/codegen/es2017 31066 ns/iter (± 264) 31084 ns/iter (± 986) 1.00
es/full/codegen/es2018 31040 ns/iter (± 500) 30994 ns/iter (± 844) 1.00
es/full/codegen/es2019 31107 ns/iter (± 587) 30955 ns/iter (± 903) 1.00
es/full/codegen/es2020 30992 ns/iter (± 722) 31001 ns/iter (± 1357) 1.00
es/full/all/es3 179998116 ns/iter (± 4989703) 181413586 ns/iter (± 5824283) 0.99
es/full/all/es5 168274733 ns/iter (± 8084248) 171509673 ns/iter (± 4953998) 0.98
es/full/all/es2015 137243792 ns/iter (± 5176278) 137837158 ns/iter (± 4645783) 1.00
es/full/all/es2016 136159917 ns/iter (± 4421328) 141518922 ns/iter (± 3681837) 0.96
es/full/all/es2017 135770979 ns/iter (± 4017049) 139188022 ns/iter (± 3803195) 0.98
es/full/all/es2018 133791382 ns/iter (± 8973214) 138043781 ns/iter (± 5085847) 0.97
es/full/all/es2019 133512557 ns/iter (± 4682337) 137759363 ns/iter (± 4626760) 0.97
es/full/all/es2020 129058101 ns/iter (± 4255750) 134546802 ns/iter (± 3379568) 0.96
es/full/parser 691949 ns/iter (± 19331) 729566 ns/iter (± 28671) 0.95
es/full/base/fixer 28508 ns/iter (± 343) 30487 ns/iter (± 1195) 0.94
es/full/base/resolver_and_hygiene 86072 ns/iter (± 2387) 89688 ns/iter (± 3568) 0.96
serialization of ast node 217 ns/iter (± 9) 223 ns/iter (± 9) 0.97
serialization of serde 223 ns/iter (± 5) 230 ns/iter (± 7) 0.97

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.