diff --git a/Cargo.lock b/Cargo.lock index 8b1f8d515d7f..d734788e742c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2325,7 +2325,7 @@ checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" [[package]] name = "swc" -version = "0.79.0" +version = "0.79.1" dependencies = [ "ahash", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index f748864f9296..802e7db4ca30 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ include = ["Cargo.toml", "src/**/*.rs"] license = "Apache-2.0/MIT" name = "swc" repository = "https://github.com/swc-project/swc.git" -version = "0.79.0" +version = "0.79.1" [lib] name = "swc" diff --git a/node-swc/__tests__/transform/api_test.js b/node-swc/__tests__/transform/api_test.js index 89b3392491b0..405dfb28acfb 100644 --- a/node-swc/__tests__/transform/api_test.js +++ b/node-swc/__tests__/transform/api_test.js @@ -1,4 +1,5 @@ const swc = require("../../../"); +const path = require("path"); it("should handle minify", () => { const src = '/* Comment */import foo, {bar} from "foo"'; @@ -173,4 +174,20 @@ it("should respect `error.filename = false`", async () => { expect(e).not.toContain("-->") } +}); + +it("should merge parser config", async () => { + const filename = path.resolve( + __dirname + "/../../tests/issue-2546/input.ts" + ); + + const { code } = await swc.transformFile(filename, { + jsc: { + parser: { + syntax: "typescript", + } + } + }) + + expect(code).not.toBeFalsy() }); \ No newline at end of file diff --git a/node-swc/tests/issue-2546/.swcrc b/node-swc/tests/issue-2546/.swcrc new file mode 100644 index 000000000000..cd0ed9512c9a --- /dev/null +++ b/node-swc/tests/issue-2546/.swcrc @@ -0,0 +1,12 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript", + "decorators": true + }, + "transform": { + "legacyDecorator": true, + "decoratorMetadata": true + } + } +} \ No newline at end of file diff --git a/node-swc/tests/issue-2546/input.ts b/node-swc/tests/issue-2546/input.ts new file mode 100644 index 000000000000..52e60b7f45ac --- /dev/null +++ b/node-swc/tests/issue-2546/input.ts @@ -0,0 +1,6 @@ +import { injectable } from 'inversify'; + + +@injectable() +export default abstract class MyClass { +} \ No newline at end of file diff --git a/src/config/mod.rs b/src/config/mod.rs index a85413759d52..43fa60c2e136 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1361,7 +1361,48 @@ impl Merge for bool { impl Merge for Syntax { fn merge(&mut self, from: &Self) { - *self = *from; + match (&mut *self, from) { + (Syntax::Es(a), Syntax::Es(b)) => { + a.merge(b); + } + (Syntax::Typescript(a), Syntax::Typescript(b)) => { + a.merge(b); + } + _ => { + *self = *from; + } + } + } +} + +impl Merge for swc_ecma_parser::EsConfig { + fn merge(&mut self, from: &Self) { + self.jsx |= from.jsx; + self.class_private_props |= from.class_private_props; + self.class_private_methods |= from.class_private_methods; + self.class_props |= from.class_props; + self.fn_bind |= from.fn_bind; + self.decorators |= from.decorators; + self.decorators_before_export |= from.decorators_before_export; + self.export_default_from |= from.export_default_from; + self.export_namespace_from |= from.export_namespace_from; + self.dynamic_import |= from.dynamic_import; + self.nullish_coalescing |= from.nullish_coalescing; + self.optional_chaining |= from.optional_chaining; + self.import_meta |= from.import_meta; + self.top_level_await |= from.top_level_await; + self.import_assertions |= from.import_assertions; + self.static_blocks |= from.static_blocks; + self.private_in_object |= from.private_in_object; + } +} + +impl Merge for swc_ecma_parser::TsConfig { + fn merge(&mut self, from: &Self) { + self.tsx |= from.tsx; + self.decorators |= from.decorators; + self.dynamic_import |= from.dynamic_import; + self.import_assertions |= from.import_assertions; } }