From d4df2cece8bd08cad314086743165ef653f016ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Sat, 23 Jan 2021 15:46:42 +0900 Subject: [PATCH] fix(es): Fix bugs (#1347) swc_ecma_parser: - Do not emit strict mode error while backtracking. (#1252) swc_ecma_transforms_proposal: - Handle decorator on methods with computed key. --- Cargo.toml | 12 +- bundler/Cargo.toml | 10 +- ecmascript/Cargo.toml | 10 +- ecmascript/codegen/Cargo.toml | 4 +- ecmascript/dep-graph/Cargo.toml | 4 +- ecmascript/ext-transforms/Cargo.toml | 4 +- ecmascript/jsdoc/Cargo.toml | 4 +- ecmascript/parser/Cargo.toml | 2 +- ecmascript/parser/src/parser/mod.rs | 3 + .../case1}/input.ts | 0 .../case1}/input.ts.json | 0 .../typescript/issue-1252/case1/input.tsx | 4 + .../issue-1252/case1/input.tsx.json | 352 ++++++++++++++++++ .../typescript/issue-814/{ => case1}/input.ts | 0 .../issue-814/{ => case1}/input.ts.json | 0 .../{issue-814-2 => issue-814/case2}/input.ts | 0 .../case2}/input.ts.json | 0 .../{issue-818-1 => issue-818/case1}/input.ts | 0 .../case1}/input.ts.json | 0 .../{issue-818-2 => issue-818/case2}/input.ts | 0 .../case2}/input.ts.json | 0 ecmascript/preset_env/Cargo.toml | 8 +- ecmascript/transforms/Cargo.toml | 22 +- ecmascript/transforms/base/Cargo.toml | 6 +- ecmascript/transforms/compat/Cargo.toml | 8 +- ecmascript/transforms/module/Cargo.toml | 10 +- ecmascript/transforms/optimization/Cargo.toml | 18 +- ecmascript/transforms/proposal/Cargo.toml | 12 +- .../proposal/src/decorators/legacy.rs | 16 +- ecmascript/transforms/react/Cargo.toml | 12 +- ecmascript/transforms/testing/Cargo.toml | 8 +- ecmascript/transforms/tests/decorators.rs | 25 ++ ecmascript/transforms/typescript/Cargo.toml | 16 +- tests/fixture/issue-1252/case1/input/.swcrc | 8 + tests/fixture/issue-1252/case1/input/index.ts | 4 + .../fixture/issue-1252/case1/output/index.ts | 4 + .../issue-1314/{ => case1}/input/.swcrc | 0 .../issue-1314/{ => case1}/input/index.js | 0 .../issue-1314/{ => case1}/output/index.js | 0 tests/fixture/issue-1314/case2/input/index.ts | 5 + .../fixture/issue-1314/case2/output/index.ts | 1 + 41 files changed, 504 insertions(+), 88 deletions(-) rename ecmascript/parser/tests/typescript/{issue-1066-1 => issue-1066/case1}/input.ts (100%) rename ecmascript/parser/tests/typescript/{issue-1066-1 => issue-1066/case1}/input.ts.json (100%) create mode 100644 ecmascript/parser/tests/typescript/issue-1252/case1/input.tsx create mode 100644 ecmascript/parser/tests/typescript/issue-1252/case1/input.tsx.json rename ecmascript/parser/tests/typescript/issue-814/{ => case1}/input.ts (100%) rename ecmascript/parser/tests/typescript/issue-814/{ => case1}/input.ts.json (100%) rename ecmascript/parser/tests/typescript/{issue-814-2 => issue-814/case2}/input.ts (100%) rename ecmascript/parser/tests/typescript/{issue-814-2 => issue-814/case2}/input.ts.json (100%) rename ecmascript/parser/tests/typescript/{issue-818-1 => issue-818/case1}/input.ts (100%) rename ecmascript/parser/tests/typescript/{issue-818-1 => issue-818/case1}/input.ts.json (100%) rename ecmascript/parser/tests/typescript/{issue-818-2 => issue-818/case2}/input.ts (100%) rename ecmascript/parser/tests/typescript/{issue-818-2 => issue-818/case2}/input.ts.json (100%) create mode 100644 tests/fixture/issue-1252/case1/input/.swcrc create mode 100644 tests/fixture/issue-1252/case1/input/index.ts create mode 100644 tests/fixture/issue-1252/case1/output/index.ts rename tests/fixture/issue-1314/{ => case1}/input/.swcrc (100%) rename tests/fixture/issue-1314/{ => case1}/input/index.js (100%) rename tests/fixture/issue-1314/{ => case1}/output/index.js (100%) create mode 100644 tests/fixture/issue-1314/case2/input/index.ts create mode 100644 tests/fixture/issue-1314/case2/output/index.ts diff --git a/Cargo.toml b/Cargo.toml index 18f17f01571..377441e97ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc" repository = "https://github.com/swc-project/swc.git" -version = "0.2.2" +version = "0.2.3" [lib] name = "swc" @@ -28,11 +28,11 @@ sourcemap = "6" swc_atoms = {version = "0.2", path = "./atoms"} swc_common = {version = "0.10", path = "./common", features = ["sourcemap", "concurrent"]} swc_ecma_ast = {version = "0.37.1", path = "./ecmascript/ast"} -swc_ecma_codegen = {version = "0.43.2", path = "./ecmascript/codegen"} -swc_ecma_ext_transforms = {version = "0.2.1", path = "./ecmascript/ext-transforms"} -swc_ecma_parser = {version = "0.45.1", path = "./ecmascript/parser"} -swc_ecma_preset_env = {version = "0.3.2", path = "./ecmascript/preset_env"} -swc_ecma_transforms = {version = "0.33.2", path = "./ecmascript/transforms", features = [ +swc_ecma_codegen = {version = "0.43.3", path = "./ecmascript/codegen"} +swc_ecma_ext_transforms = {version = "0.2.2", path = "./ecmascript/ext-transforms"} +swc_ecma_parser = {version = "0.45.2", path = "./ecmascript/parser"} +swc_ecma_preset_env = {version = "0.3.3", path = "./ecmascript/preset_env"} +swc_ecma_transforms = {version = "0.33.3", path = "./ecmascript/transforms", features = [ "compat", "module", "optimization", diff --git a/bundler/Cargo.toml b/bundler/Cargo.toml index ef1ea3ec941..ad2b0ca7ccf 100644 --- a/bundler/Cargo.toml +++ b/bundler/Cargo.toml @@ -9,7 +9,7 @@ include = ["Cargo.toml", "build.rs", "src/**/*.rs", "src/**/*.js"] license = "Apache-2.0/MIT" name = "swc_bundler" repository = "https://github.com/swc-project/swc.git" -version = "0.20.2" +version = "0.20.3" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] @@ -32,9 +32,9 @@ retain_mut = "0.1.2" swc_atoms = {version = "0.2.4", path = "../atoms"} swc_common = {version = "0.10.0", path = "../common"} swc_ecma_ast = {version = "0.37.1", path = "../ecmascript/ast"} -swc_ecma_codegen = {version = "0.43.2", path = "../ecmascript/codegen"} -swc_ecma_parser = {version = "0.45.1", path = "../ecmascript/parser"} -swc_ecma_transforms = {version = "0.33.2", path = "../ecmascript/transforms", features = ["optimization"]} +swc_ecma_codegen = {version = "0.43.3", path = "../ecmascript/codegen"} +swc_ecma_parser = {version = "0.45.2", path = "../ecmascript/parser"} +swc_ecma_transforms = {version = "0.33.3", path = "../ecmascript/transforms", features = ["optimization"]} swc_ecma_utils = {version = "0.27.1", path = "../ecmascript/utils"} swc_ecma_visit = {version = "0.23.1", path = "../ecmascript/visit"} @@ -43,7 +43,7 @@ hex = "0.4" ntest = "0.7.2" reqwest = {version = "0.10.8", features = ["blocking"]} sha-1 = "0.9" -swc_ecma_transforms = {version = "0.33.2", path = "../ecmascript/transforms", features = ["react", "typescript"]} +swc_ecma_transforms = {version = "0.33.3", path = "../ecmascript/transforms", features = ["react", "typescript"]} tempfile = "3.1.0" testing = {version = "0.10.0", path = "../testing"} url = "2.1.1" diff --git a/ecmascript/Cargo.toml b/ecmascript/Cargo.toml index 70ba7bdd1e7..33d4250654c 100644 --- a/ecmascript/Cargo.toml +++ b/ecmascript/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecmascript" repository = "https://github.com/swc-project/swc.git" -version = "0.18.2" +version = "0.18.3" [features] codegen = ["swc_ecma_codegen"] @@ -25,10 +25,10 @@ typescript = ["swc_ecma_transforms/typescript"] [dependencies] swc_ecma_ast = {version = "0.37.1", path = "./ast"} -swc_ecma_codegen = {version = "0.43.2", path = "./codegen", optional = true} -swc_ecma_dep_graph = {version = "0.12.1", path = "./dep-graph", optional = true} -swc_ecma_parser = {version = "0.45.1", path = "./parser", optional = true} -swc_ecma_transforms = {version = "0.33.2", path = "./transforms", optional = true} +swc_ecma_codegen = {version = "0.43.3", path = "./codegen", optional = true} +swc_ecma_dep_graph = {version = "0.12.2", path = "./dep-graph", optional = true} +swc_ecma_parser = {version = "0.45.2", path = "./parser", optional = true} +swc_ecma_transforms = {version = "0.33.3", path = "./transforms", optional = true} swc_ecma_utils = {version = "0.27.1", path = "./utils", optional = true} swc_ecma_visit = {version = "0.23.1", path = "./visit", optional = true} diff --git a/ecmascript/codegen/Cargo.toml b/ecmascript/codegen/Cargo.toml index 52c85c95207..e06cae3fc2f 100644 --- a/ecmascript/codegen/Cargo.toml +++ b/ecmascript/codegen/Cargo.toml @@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs"] license = "Apache-2.0/MIT" name = "swc_ecma_codegen" repository = "https://github.com/swc-project/swc.git" -version = "0.43.2" +version = "0.43.3" [dependencies] bitflags = "1" @@ -17,7 +17,7 @@ swc_atoms = {version = "0.2", path = "../../atoms"} swc_common = {version = "0.10.0", path = "../../common"} swc_ecma_ast = {version = "0.37.1", path = "../ast"} swc_ecma_codegen_macros = {version = "0.5", path = "./macros"} -swc_ecma_parser = {version = "0.45.1", path = "../parser"} +swc_ecma_parser = {version = "0.45.2", path = "../parser"} [dev-dependencies] swc_common = {version = "0.10.0", path = "../../common", features = ["sourcemap"]} diff --git a/ecmascript/dep-graph/Cargo.toml b/ecmascript/dep-graph/Cargo.toml index 2c174cdbc38..0dedb7c2e9a 100644 --- a/ecmascript/dep-graph/Cargo.toml +++ b/ecmascript/dep-graph/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_dep_graph" repository = "https://github.com/swc-project/swc.git" -version = "0.12.1" +version = "0.12.2" [dependencies] swc_atoms = {version = "0.2", path = "../../atoms"} @@ -15,5 +15,5 @@ swc_ecma_ast = {version = "0.37.1", path = "../ast"} swc_ecma_visit = {version = "0.23.1", path = "../visit"} [dev-dependencies] -swc_ecma_parser = {version = "0.45.1", path = "../parser"} +swc_ecma_parser = {version = "0.45.2", path = "../parser"} testing = {version = "0.10.0", path = "../../testing"} diff --git a/ecmascript/ext-transforms/Cargo.toml b/ecmascript/ext-transforms/Cargo.toml index 827d8a6ae4e..febaef322b4 100644 --- a/ecmascript/ext-transforms/Cargo.toml +++ b/ecmascript/ext-transforms/Cargo.toml @@ -5,7 +5,7 @@ documentation = "https://swc.rs/rustdoc/swc_ecma_ext_transforms/" edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_ext_transforms" -version = "0.2.1" +version = "0.2.2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -14,6 +14,6 @@ phf = {version = "0.8.0", features = ["macros"]} swc_atoms = {version = "0.2", path = "../../atoms"} swc_common = {version = "0.10", path = "../../common"} swc_ecma_ast = {version = "0.37.1", path = "../ast"} -swc_ecma_parser = {version = "0.45.1", path = "../parser"} +swc_ecma_parser = {version = "0.45.2", path = "../parser"} swc_ecma_utils = {version = "0.27.1", path = "../utils"} swc_ecma_visit = {version = "0.23.1", path = "../visit"} diff --git a/ecmascript/jsdoc/Cargo.toml b/ecmascript/jsdoc/Cargo.toml index 33b69a56bcf..342a453eb89 100644 --- a/ecmascript/jsdoc/Cargo.toml +++ b/ecmascript/jsdoc/Cargo.toml @@ -5,7 +5,7 @@ documentation = "https://swc.rs/rustdoc/jsdoc/" edition = "2018" license = "Apache-2.0/MIT" name = "jsdoc" -version = "0.13.1" +version = "0.13.2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -19,6 +19,6 @@ swc_common = {version = "0.10.0", path = "../../common"} anyhow = "1" dashmap = "3" swc_ecma_ast = {version = "0.37.1", path = "../ast"} -swc_ecma_parser = {version = "0.45.1", path = "../parser"} +swc_ecma_parser = {version = "0.45.2", path = "../parser"} testing = {version = "0.10.0", path = "../../testing"} walkdir = "2" diff --git a/ecmascript/parser/Cargo.toml b/ecmascript/parser/Cargo.toml index 9196d74c96c..9de2e45e5b1 100644 --- a/ecmascript/parser/Cargo.toml +++ b/ecmascript/parser/Cargo.toml @@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs", "examples/**/*.rs"] license = "Apache-2.0/MIT" name = "swc_ecma_parser" repository = "https://github.com/swc-project/swc.git" -version = "0.45.1" +version = "0.45.2" [features] default = [] diff --git a/ecmascript/parser/src/parser/mod.rs b/ecmascript/parser/src/parser/mod.rs index 50a28f871c6..19440509046 100644 --- a/ecmascript/parser/src/parser/mod.rs +++ b/ecmascript/parser/src/parser/mod.rs @@ -220,6 +220,9 @@ impl Parser { #[cold] fn emit_strict_mode_err(&self, span: Span, error: SyntaxError) { + if !self.emit_err { + return; + } let error = Error { error: Box::new((span, error)), }; diff --git a/ecmascript/parser/tests/typescript/issue-1066-1/input.ts b/ecmascript/parser/tests/typescript/issue-1066/case1/input.ts similarity index 100% rename from ecmascript/parser/tests/typescript/issue-1066-1/input.ts rename to ecmascript/parser/tests/typescript/issue-1066/case1/input.ts diff --git a/ecmascript/parser/tests/typescript/issue-1066-1/input.ts.json b/ecmascript/parser/tests/typescript/issue-1066/case1/input.ts.json similarity index 100% rename from ecmascript/parser/tests/typescript/issue-1066-1/input.ts.json rename to ecmascript/parser/tests/typescript/issue-1066/case1/input.ts.json diff --git a/ecmascript/parser/tests/typescript/issue-1252/case1/input.tsx b/ecmascript/parser/tests/typescript/issue-1252/case1/input.tsx new file mode 100644 index 00000000000..8e2c7265218 --- /dev/null +++ b/ecmascript/parser/tests/typescript/issue-1252/case1/input.tsx @@ -0,0 +1,4 @@ +export const then = (callback: (...args: TupleReturns) => R) => { + let returns: R + let called: boolean +} \ No newline at end of file diff --git a/ecmascript/parser/tests/typescript/issue-1252/case1/input.tsx.json b/ecmascript/parser/tests/typescript/issue-1252/case1/input.tsx.json new file mode 100644 index 00000000000..cf63130b709 --- /dev/null +++ b/ecmascript/parser/tests/typescript/issue-1252/case1/input.tsx.json @@ -0,0 +1,352 @@ +{ + "type": "Module", + "span": { + "start": 0, + "end": 117, + "ctxt": 0 + }, + "body": [ + { + "type": "ExportDeclaration", + "span": { + "start": 0, + "end": 117, + "ctxt": 0 + }, + "declaration": { + "type": "VariableDeclaration", + "span": { + "start": 7, + "end": 117, + "ctxt": 0 + }, + "kind": "const", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 13, + "end": 117, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 13, + "end": 17, + "ctxt": 0 + }, + "value": "then", + "typeAnnotation": null, + "optional": false + }, + "init": { + "type": "ArrowFunctionExpression", + "span": { + "start": 23, + "end": 117, + "ctxt": 0 + }, + "params": [ + { + "type": "Identifier", + "span": { + "start": 24, + "end": 66, + "ctxt": 0 + }, + "value": "callback", + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 32, + "end": 66, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsFunctionType", + "span": { + "start": 34, + "end": 66, + "ctxt": 0 + }, + "params": [ + { + "type": "RestElement", + "span": { + "start": 35, + "end": 60, + "ctxt": 0 + }, + "rest": { + "start": 35, + "end": 38, + "ctxt": 0 + }, + "argument": { + "type": "Identifier", + "span": { + "start": 38, + "end": 42, + "ctxt": 0 + }, + "value": "args", + "typeAnnotation": null, + "optional": false + }, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 42, + "end": 60, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsTypeReference", + "span": { + "start": 44, + "end": 60, + "ctxt": 0 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 44, + "end": 56, + "ctxt": 0 + }, + "value": "TupleReturns", + "typeAnnotation": null, + "optional": false + }, + "typeParams": { + "type": "TsTypeParameterInstantiation", + "span": { + "start": 56, + "end": 60, + "ctxt": 0 + }, + "params": [ + { + "type": "TsTypeReference", + "span": { + "start": 57, + "end": 59, + "ctxt": 0 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 57, + "end": 59, + "ctxt": 0 + }, + "value": "Ws", + "typeAnnotation": null, + "optional": false + }, + "typeParams": null + } + ] + } + } + } + } + ], + "typeParams": null, + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 62, + "end": 66, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsTypeReference", + "span": { + "start": 65, + "end": 66, + "ctxt": 0 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 65, + "end": 66, + "ctxt": 0 + }, + "value": "R", + "typeAnnotation": null, + "optional": false + }, + "typeParams": null + } + } + } + }, + "optional": false + } + ], + "body": { + "type": "BlockStatement", + "span": { + "start": 71, + "end": 117, + "ctxt": 0 + }, + "stmts": [ + { + "type": "VariableDeclaration", + "span": { + "start": 77, + "end": 91, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 81, + "end": 91, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 81, + "end": 88, + "ctxt": 0 + }, + "value": "returns", + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 88, + "end": 91, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsTypeReference", + "span": { + "start": 90, + "end": 91, + "ctxt": 0 + }, + "typeName": { + "type": "Identifier", + "span": { + "start": 90, + "end": 91, + "ctxt": 0 + }, + "value": "R", + "typeAnnotation": null, + "optional": false + }, + "typeParams": null + } + }, + "optional": false + }, + "init": null, + "definite": false + } + ] + }, + { + "type": "VariableDeclaration", + "span": { + "start": 96, + "end": 115, + "ctxt": 0 + }, + "kind": "let", + "declare": false, + "declarations": [ + { + "type": "VariableDeclarator", + "span": { + "start": 100, + "end": 115, + "ctxt": 0 + }, + "id": { + "type": "Identifier", + "span": { + "start": 100, + "end": 106, + "ctxt": 0 + }, + "value": "called", + "typeAnnotation": { + "type": "TsTypeAnnotation", + "span": { + "start": 106, + "end": 115, + "ctxt": 0 + }, + "typeAnnotation": { + "type": "TsKeywordType", + "span": { + "start": 108, + "end": 115, + "ctxt": 0 + }, + "kind": "boolean" + } + }, + "optional": false + }, + "init": null, + "definite": false + } + ] + } + ] + }, + "async": false, + "generator": false, + "typeParameters": { + "type": "TsTypeParameterDeclaration", + "span": { + "start": 20, + "end": 23, + "ctxt": 0 + }, + "parameters": [ + { + "type": "TsTypeParameter", + "span": { + "start": 21, + "end": 22, + "ctxt": 0 + }, + "name": { + "type": "Identifier", + "span": { + "start": 21, + "end": 22, + "ctxt": 0 + }, + "value": "R", + "typeAnnotation": null, + "optional": false + }, + "constraint": null, + "default": null + } + ] + }, + "returnType": null + }, + "definite": false + } + ] + } + } + ], + "interpreter": null +} diff --git a/ecmascript/parser/tests/typescript/issue-814/input.ts b/ecmascript/parser/tests/typescript/issue-814/case1/input.ts similarity index 100% rename from ecmascript/parser/tests/typescript/issue-814/input.ts rename to ecmascript/parser/tests/typescript/issue-814/case1/input.ts diff --git a/ecmascript/parser/tests/typescript/issue-814/input.ts.json b/ecmascript/parser/tests/typescript/issue-814/case1/input.ts.json similarity index 100% rename from ecmascript/parser/tests/typescript/issue-814/input.ts.json rename to ecmascript/parser/tests/typescript/issue-814/case1/input.ts.json diff --git a/ecmascript/parser/tests/typescript/issue-814-2/input.ts b/ecmascript/parser/tests/typescript/issue-814/case2/input.ts similarity index 100% rename from ecmascript/parser/tests/typescript/issue-814-2/input.ts rename to ecmascript/parser/tests/typescript/issue-814/case2/input.ts diff --git a/ecmascript/parser/tests/typescript/issue-814-2/input.ts.json b/ecmascript/parser/tests/typescript/issue-814/case2/input.ts.json similarity index 100% rename from ecmascript/parser/tests/typescript/issue-814-2/input.ts.json rename to ecmascript/parser/tests/typescript/issue-814/case2/input.ts.json diff --git a/ecmascript/parser/tests/typescript/issue-818-1/input.ts b/ecmascript/parser/tests/typescript/issue-818/case1/input.ts similarity index 100% rename from ecmascript/parser/tests/typescript/issue-818-1/input.ts rename to ecmascript/parser/tests/typescript/issue-818/case1/input.ts diff --git a/ecmascript/parser/tests/typescript/issue-818-1/input.ts.json b/ecmascript/parser/tests/typescript/issue-818/case1/input.ts.json similarity index 100% rename from ecmascript/parser/tests/typescript/issue-818-1/input.ts.json rename to ecmascript/parser/tests/typescript/issue-818/case1/input.ts.json diff --git a/ecmascript/parser/tests/typescript/issue-818-2/input.ts b/ecmascript/parser/tests/typescript/issue-818/case2/input.ts similarity index 100% rename from ecmascript/parser/tests/typescript/issue-818-2/input.ts rename to ecmascript/parser/tests/typescript/issue-818/case2/input.ts diff --git a/ecmascript/parser/tests/typescript/issue-818-2/input.ts.json b/ecmascript/parser/tests/typescript/issue-818/case2/input.ts.json similarity index 100% rename from ecmascript/parser/tests/typescript/issue-818-2/input.ts.json rename to ecmascript/parser/tests/typescript/issue-818/case2/input.ts.json diff --git a/ecmascript/preset_env/Cargo.toml b/ecmascript/preset_env/Cargo.toml index 1e74f9fed0c..43b07879841 100644 --- a/ecmascript/preset_env/Cargo.toml +++ b/ecmascript/preset_env/Cargo.toml @@ -5,7 +5,7 @@ documentation = "https://swc.rs/rustdoc/swc_ecma_preset_env/" edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_preset_env" -version = "0.3.2" +version = "0.3.3" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -21,13 +21,13 @@ string_enum = {version = "0.3", path = "../../macros/string_enum"} swc_atoms = {version = "0.2", path = "../../atoms"} swc_common = {version = "0.10", path = "../../common"} swc_ecma_ast = {version = "0.37.1", path = "../ast"} -swc_ecma_transforms = {version = "0.33.2", path = "../transforms", features = ["compat", "proposal"]} +swc_ecma_transforms = {version = "0.33.3", path = "../transforms", features = ["compat", "proposal"]} swc_ecma_utils = {version = "0.27.1", path = "../utils"} swc_ecma_visit = {version = "0.23.1", path = "../visit"} walkdir = "2" [dev-dependencies] pretty_assertions = "0.6" -swc_ecma_codegen = {version = "0.43.2", path = "../codegen"} -swc_ecma_parser = {version = "0.45.1", path = "../parser"} +swc_ecma_codegen = {version = "0.43.3", path = "../codegen"} +swc_ecma_parser = {version = "0.45.2", path = "../parser"} testing = {version = "0.10", path = "../../testing"} diff --git a/ecmascript/transforms/Cargo.toml b/ecmascript/transforms/Cargo.toml index 4d863b1edca..2723adc6266 100644 --- a/ecmascript/transforms/Cargo.toml +++ b/ecmascript/transforms/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms" repository = "https://github.com/swc-project/swc.git" -version = "0.33.2" +version = "0.33.3" [features] compat = ["swc_ecma_transforms_compat"] @@ -20,14 +20,14 @@ typescript = ["swc_ecma_transforms_typescript"] swc_atoms = {version = "0.2.0", path = "../../atoms"} swc_common = {version = "0.10.0", path = "../../common"} swc_ecma_ast = {version = "0.37.1", path = "../ast"} -swc_ecma_parser = {version = "0.45.1", path = "../parser"} -swc_ecma_transforms_base = {version = "0.2.2", path = "./base"} -swc_ecma_transforms_compat = {version = "0.3.1", path = "./compat", optional = true} -swc_ecma_transforms_module = {version = "0.3.1", path = "./module", optional = true} -swc_ecma_transforms_optimization = {version = "0.3.2", path = "./optimization", optional = true} -swc_ecma_transforms_proposal = {version = "0.3.1", path = "./proposal", optional = true} -swc_ecma_transforms_react = {version = "0.3.1", path = "./react", optional = true} -swc_ecma_transforms_typescript = {version = "0.3.2", path = "./typescript", optional = true} +swc_ecma_parser = {version = "0.45.2", path = "../parser"} +swc_ecma_transforms_base = {version = "0.2.3", path = "./base"} +swc_ecma_transforms_compat = {version = "0.3.2", path = "./compat", optional = true} +swc_ecma_transforms_module = {version = "0.3.2", path = "./module", optional = true} +swc_ecma_transforms_optimization = {version = "0.3.3", path = "./optimization", optional = true} +swc_ecma_transforms_proposal = {version = "0.3.2", path = "./proposal", optional = true} +swc_ecma_transforms_react = {version = "0.3.2", path = "./react", optional = true} +swc_ecma_transforms_typescript = {version = "0.3.3", path = "./typescript", optional = true} swc_ecma_utils = {version = "0.27.1", path = "../utils"} swc_ecma_visit = {version = "0.23.1", path = "../visit"} unicode-xid = "0.2" @@ -35,8 +35,8 @@ unicode-xid = "0.2" [dev-dependencies] pretty_assertions = "0.6" sourcemap = "6" -swc_ecma_codegen = {version = "0.43.2", path = "../codegen"} -swc_ecma_transforms_testing = {version = "0.2.1", path = "./testing"} +swc_ecma_codegen = {version = "0.43.3", path = "../codegen"} +swc_ecma_transforms_testing = {version = "0.2.2", path = "./testing"} tempfile = "3" testing = {version = "0.10.0", path = "../../testing"} walkdir = "2" diff --git a/ecmascript/transforms/base/Cargo.toml b/ecmascript/transforms/base/Cargo.toml index 8bb179ff067..9b1db2c4c86 100644 --- a/ecmascript/transforms/base/Cargo.toml +++ b/ecmascript/transforms/base/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms_base" repository = "https://github.com/swc-project/swc.git" -version = "0.2.2" +version = "0.2.3" [dependencies] fxhash = "0.2.1" @@ -17,10 +17,10 @@ smallvec = "1.6.0" swc_atoms = {version = "0.2", path = "../../../atoms"} swc_common = {version = "0.10", path = "../../../common"} swc_ecma_ast = {version = "0.37.1", path = "../../ast"} -swc_ecma_parser = {version = "0.45.1", path = "../../parser"} +swc_ecma_parser = {version = "0.45.2", path = "../../parser"} swc_ecma_utils = {version = "0.27.1", path = "../../utils"} swc_ecma_visit = {version = "0.23.1", path = "../../visit"} [dev-dependencies] -swc_ecma_codegen = {version = "0.43.2", path = "../../codegen"} +swc_ecma_codegen = {version = "0.43.3", path = "../../codegen"} testing = {version = "0.10", path = "../../../testing"} diff --git a/ecmascript/transforms/compat/Cargo.toml b/ecmascript/transforms/compat/Cargo.toml index 2edb9203cb2..4d2825ce99a 100644 --- a/ecmascript/transforms/compat/Cargo.toml +++ b/ecmascript/transforms/compat/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms_compat" repository = "https://github.com/swc-project/swc.git" -version = "0.3.1" +version = "0.3.2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -21,12 +21,12 @@ smallvec = "1.6.0" swc_atoms = {version = "0.2.5", path = "../../../atoms"} swc_common = {version = "0.10.8", path = "../../../common"} swc_ecma_ast = {version = "0.37.1", path = "../../ast"} -swc_ecma_transforms_base = {version = "0.2.2", path = "../base"} +swc_ecma_transforms_base = {version = "0.2.3", path = "../base"} swc_ecma_transforms_macros = {version = "0.2.0", path = "../macros"} swc_ecma_utils = {version = "0.27.1", path = "../../utils"} swc_ecma_visit = {version = "0.23.1", path = "../../visit"} [dev-dependencies] -swc_ecma_parser = {version = "0.45.1", path = "../../parser"} -swc_ecma_transforms_testing = {version = "0.2.1", path = "../testing"} +swc_ecma_parser = {version = "0.45.2", path = "../../parser"} +swc_ecma_transforms_testing = {version = "0.2.2", path = "../testing"} testing = {version = "0.10.2", path = "../../../testing"} diff --git a/ecmascript/transforms/module/Cargo.toml b/ecmascript/transforms/module/Cargo.toml index faa3fe3bf93..6b67e540cca 100644 --- a/ecmascript/transforms/module/Cargo.toml +++ b/ecmascript/transforms/module/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms_module" repository = "https://github.com/swc-project/swc.git" -version = "0.3.1" +version = "0.3.2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -17,12 +17,12 @@ serde = {version = "1.0.118", features = ["derive"]} swc_atoms = {version = "0.2", path = "../../../atoms"} swc_common = {version = "0.10", path = "../../../common"} swc_ecma_ast = {version = "0.37.1", path = "../../ast"} -swc_ecma_parser = {version = "0.45.1", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.2.2", path = "../base"} +swc_ecma_parser = {version = "0.45.2", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.2.3", path = "../base"} swc_ecma_utils = {version = "0.27.1", path = "../../utils"} swc_ecma_visit = {version = "0.23.1", path = "../../visit"} [dev-dependencies] -swc_ecma_transforms_compat = {version = "0.3.1", path = "../compat"} -swc_ecma_transforms_testing = {version = "0.2.1", path = "../testing/"} +swc_ecma_transforms_compat = {version = "0.3.2", path = "../compat"} +swc_ecma_transforms_testing = {version = "0.2.2", path = "../testing/"} testing = {version = "0.10", path = "../../../testing/"} diff --git a/ecmascript/transforms/optimization/Cargo.toml b/ecmascript/transforms/optimization/Cargo.toml index 861f1e3bc34..93c187d0195 100644 --- a/ecmascript/transforms/optimization/Cargo.toml +++ b/ecmascript/transforms/optimization/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms_optimization" repository = "https://github.com/swc-project/swc.git" -version = "0.3.2" +version = "0.3.3" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -20,15 +20,15 @@ serde_json = "1.0.61" swc_atoms = {version = "0.2", path = "../../../atoms"} swc_common = {version = "0.10", path = "../../../common"} swc_ecma_ast = {version = "0.37.1", path = "../../ast"} -swc_ecma_parser = {version = "0.45.1", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.2.2", path = "../base"} +swc_ecma_parser = {version = "0.45.2", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.2.3", path = "../base"} swc_ecma_utils = {version = "0.27.1", path = "../../utils"} swc_ecma_visit = {version = "0.23.1", path = "../../visit"} [dev-dependencies] -swc_ecma_transforms_compat = {version = "0.3.1", path = "../compat"} -swc_ecma_transforms_module = {version = "0.3.1", path = "../module"} -swc_ecma_transforms_proposal = {version = "0.3.1", path = "../proposal"} -swc_ecma_transforms_react = {version = "0.3.1", path = "../react"} -swc_ecma_transforms_testing = {version = "0.2.1", path = "../testing"} -swc_ecma_transforms_typescript = {version = "0.3.2", path = "../typescript"} +swc_ecma_transforms_compat = {version = "0.3.2", path = "../compat"} +swc_ecma_transforms_module = {version = "0.3.2", path = "../module"} +swc_ecma_transforms_proposal = {version = "0.3.2", path = "../proposal"} +swc_ecma_transforms_react = {version = "0.3.2", path = "../react"} +swc_ecma_transforms_testing = {version = "0.2.2", path = "../testing"} +swc_ecma_transforms_typescript = {version = "0.3.3", path = "../typescript"} diff --git a/ecmascript/transforms/proposal/Cargo.toml b/ecmascript/transforms/proposal/Cargo.toml index 32c1b4f3cb3..009ea3fc437 100644 --- a/ecmascript/transforms/proposal/Cargo.toml +++ b/ecmascript/transforms/proposal/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms_proposal" repository = "https://github.com/swc-project/swc.git" -version = "0.3.1" +version = "0.3.2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -18,12 +18,12 @@ smallvec = "1.6.0" swc_atoms = {version = "0.2", path = "../../../atoms"} swc_common = {version = "0.10", path = "../../../common"} swc_ecma_ast = {version = "0.37.1", path = "../../ast"} -swc_ecma_parser = {version = "0.45.1", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.2.2", path = "../base"} +swc_ecma_parser = {version = "0.45.2", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.2.3", path = "../base"} swc_ecma_utils = {version = "0.27.1", path = "../../utils"} swc_ecma_visit = {version = "0.23.1", path = "../../visit"} [dev-dependencies] -swc_ecma_transforms_compat = {version = "0.3.1", path = "../compat"} -swc_ecma_transforms_module = {version = "0.3.1", path = "../module"} -swc_ecma_transforms_testing = {version = "0.2.1", path = "../testing"} +swc_ecma_transforms_compat = {version = "0.3.2", path = "../compat"} +swc_ecma_transforms_module = {version = "0.3.2", path = "../module"} +swc_ecma_transforms_testing = {version = "0.2.2", path = "../testing"} diff --git a/ecmascript/transforms/proposal/src/decorators/legacy.rs b/ecmascript/transforms/proposal/src/decorators/legacy.rs index 2d2bad28125..2ae50fdcd71 100644 --- a/ecmascript/transforms/proposal/src/decorators/legacy.rs +++ b/ecmascript/transforms/proposal/src/decorators/legacy.rs @@ -361,9 +361,19 @@ impl Legacy { dec_exprs.push(Some(i.as_arg())) } - let name = match m.key { - PropName::Computed(..) => { - unimplemented!("decorators on methods with computed key") + let name = match &m.key { + PropName::Computed(e) => { + let (name, aliased) = alias_if_required(&e.expr, "key"); + if aliased { + self.initialized_vars.push(VarDeclarator { + span: DUMMY_SP, + name: Pat::Ident(name.clone()), + init: Some(e.expr.clone()), + definite: Default::default(), + }) + } + + Expr::Ident(name) } _ => prop_name_to_expr_value(m.key.clone()), }; diff --git a/ecmascript/transforms/react/Cargo.toml b/ecmascript/transforms/react/Cargo.toml index 7642b3628c7..560fc705b98 100644 --- a/ecmascript/transforms/react/Cargo.toml +++ b/ecmascript/transforms/react/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms_react" repository = "https://github.com/swc-project/swc.git" -version = "0.3.1" +version = "0.3.2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -17,12 +17,12 @@ serde = {version = "1.0.118", features = ["derive"]} swc_atoms = {version = "0.2", path = "../../../atoms"} swc_common = {version = "0.10", path = "../../../common"} swc_ecma_ast = {version = "0.37.1", path = "../../ast"} -swc_ecma_parser = {version = "0.45.1", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.2.2", path = "../base"} +swc_ecma_parser = {version = "0.45.2", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.2.3", path = "../base"} swc_ecma_utils = {version = "0.27.1", path = "../../utils"} swc_ecma_visit = {version = "0.23.1", path = "../../visit"} [dev-dependencies] -swc_ecma_transforms_compat = {version = "0.3.1", path = "../compat/"} -swc_ecma_transforms_module = {version = "0.3.1", path = "../module"} -swc_ecma_transforms_testing = {version = "0.2.1", path = "../testing/"} +swc_ecma_transforms_compat = {version = "0.3.2", path = "../compat/"} +swc_ecma_transforms_module = {version = "0.3.2", path = "../module"} +swc_ecma_transforms_testing = {version = "0.2.2", path = "../testing/"} diff --git a/ecmascript/transforms/testing/Cargo.toml b/ecmascript/transforms/testing/Cargo.toml index 8e5559cf279..3321cf67969 100644 --- a/ecmascript/transforms/testing/Cargo.toml +++ b/ecmascript/transforms/testing/Cargo.toml @@ -6,16 +6,16 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms_testing" repository = "https://github.com/swc-project/swc.git" -version = "0.2.1" +version = "0.2.2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] swc_common = {version = "0.10", path = "../../../common"} swc_ecma_ast = {version = "0.37.1", path = "../../ast"} -swc_ecma_codegen = {version = "0.43.2", path = "../../codegen"} -swc_ecma_parser = {version = "0.45.1", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.2.2", path = "../base"} +swc_ecma_codegen = {version = "0.43.3", path = "../../codegen"} +swc_ecma_parser = {version = "0.45.2", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.2.3", path = "../base"} swc_ecma_utils = {version = "0.27.1", path = "../../utils"} swc_ecma_visit = {version = "0.23.1", path = "../../visit"} tempfile = "3.1.0" diff --git a/ecmascript/transforms/tests/decorators.rs b/ecmascript/transforms/tests/decorators.rs index 97abb2daa10..62e85df72e5 100644 --- a/ecmascript/transforms/tests/decorators.rs +++ b/ecmascript/transforms/tests/decorators.rs @@ -5667,3 +5667,28 @@ eval: function _eval() { "# ); + +test!( + ts(), + |_| decorators(decorators::Config { + legacy: true, + ..Default::default() + }), + swc_node_210, + " + class Foo{ + @dec + [foo]() { + } + } + ", + " + var _class; + let Foo = ((_class = class Foo { + [foo]() { + } + }) || _class, _applyDecoratedDescriptor(_class.prototype, foo, [ + dec + ], Object.getOwnPropertyDescriptor(_class.prototype, foo), _class.prototype), _class); + " +); diff --git a/ecmascript/transforms/typescript/Cargo.toml b/ecmascript/transforms/typescript/Cargo.toml index b5b06d07ea5..f9446003d82 100644 --- a/ecmascript/transforms/typescript/Cargo.toml +++ b/ecmascript/transforms/typescript/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_ecma_transforms_typescript" repository = "https://github.com/swc-project/swc.git" -version = "0.3.2" +version = "0.3.3" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -15,16 +15,16 @@ serde = {version = "1.0.118", features = ["derive"]} swc_atoms = {version = "0.2", path = "../../../atoms"} swc_common = {version = "0.10.9", path = "../../../common"} swc_ecma_ast = {version = "0.37.1", path = "../../ast"} -swc_ecma_parser = {version = "0.45.1", path = "../../parser"} -swc_ecma_transforms_base = {version = "0.2.2", path = "../base"} +swc_ecma_parser = {version = "0.45.2", path = "../../parser"} +swc_ecma_transforms_base = {version = "0.2.3", path = "../base"} swc_ecma_utils = {version = "0.27.1", path = "../../utils"} swc_ecma_visit = {version = "0.23.1", path = "../../visit"} [dev-dependencies] -swc_ecma_codegen = {version = "0.43.2", path = "../../codegen"} -swc_ecma_transforms_compat = {version = "0.3.1", path = "../compat"} -swc_ecma_transforms_module = {version = "0.3.1", path = "../module"} -swc_ecma_transforms_proposal = {version = "0.3.1", path = "../proposal/"} -swc_ecma_transforms_testing = {version = "0.2.1", path = "../testing"} +swc_ecma_codegen = {version = "0.43.3", path = "../../codegen"} +swc_ecma_transforms_compat = {version = "0.3.2", path = "../compat"} +swc_ecma_transforms_module = {version = "0.3.2", path = "../module"} +swc_ecma_transforms_proposal = {version = "0.3.2", path = "../proposal/"} +swc_ecma_transforms_testing = {version = "0.2.2", path = "../testing"} testing = {version = "0.10.2", path = "../../../testing"} walkdir = "2.3.1" diff --git a/tests/fixture/issue-1252/case1/input/.swcrc b/tests/fixture/issue-1252/case1/input/.swcrc new file mode 100644 index 00000000000..68b72e11547 --- /dev/null +++ b/tests/fixture/issue-1252/case1/input/.swcrc @@ -0,0 +1,8 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript", + "tsx": true + } + } +} diff --git a/tests/fixture/issue-1252/case1/input/index.ts b/tests/fixture/issue-1252/case1/input/index.ts new file mode 100644 index 00000000000..8e2c7265218 --- /dev/null +++ b/tests/fixture/issue-1252/case1/input/index.ts @@ -0,0 +1,4 @@ +export const then = (callback: (...args: TupleReturns) => R) => { + let returns: R + let called: boolean +} \ No newline at end of file diff --git a/tests/fixture/issue-1252/case1/output/index.ts b/tests/fixture/issue-1252/case1/output/index.ts new file mode 100644 index 00000000000..15f11b6eb92 --- /dev/null +++ b/tests/fixture/issue-1252/case1/output/index.ts @@ -0,0 +1,4 @@ +export var then = function(callback) { + var returns; + var called; +}; diff --git a/tests/fixture/issue-1314/input/.swcrc b/tests/fixture/issue-1314/case1/input/.swcrc similarity index 100% rename from tests/fixture/issue-1314/input/.swcrc rename to tests/fixture/issue-1314/case1/input/.swcrc diff --git a/tests/fixture/issue-1314/input/index.js b/tests/fixture/issue-1314/case1/input/index.js similarity index 100% rename from tests/fixture/issue-1314/input/index.js rename to tests/fixture/issue-1314/case1/input/index.js diff --git a/tests/fixture/issue-1314/output/index.js b/tests/fixture/issue-1314/case1/output/index.js similarity index 100% rename from tests/fixture/issue-1314/output/index.js rename to tests/fixture/issue-1314/case1/output/index.js diff --git a/tests/fixture/issue-1314/case2/input/index.ts b/tests/fixture/issue-1314/case2/input/index.ts new file mode 100644 index 00000000000..e9513d1d3e4 --- /dev/null +++ b/tests/fixture/issue-1314/case2/input/index.ts @@ -0,0 +1,5 @@ +const text = ` + +hello world + +`; diff --git a/tests/fixture/issue-1314/case2/output/index.ts b/tests/fixture/issue-1314/case2/output/index.ts new file mode 100644 index 00000000000..1a1c94ad663 --- /dev/null +++ b/tests/fixture/issue-1314/case2/output/index.ts @@ -0,0 +1 @@ +var text = "\n\nhello world\n\n";