diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index 54d26efda6..b6cf7818b0 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -121,12 +121,20 @@ impl<'a> Transformer<'a> { self.ctx.source_type = program.source_type; self.ctx.source_text = program.source_text; - jsx::update_options_with_comments( - &program.comments, - &mut self.typescript, - &mut self.jsx, - &self.ctx, - ); + + // Update options from comments when source type is JSX or TypeScript which has enabled `only_remove_type_imports`. + // Because if `only_remove_type_imports` is enabled, no imports will be removed, so that we don't care about + // TypeScript's `jsx_pragma` and `jsx_pragma_frag` options. + if program.source_type.is_jsx() + && (!program.source_type.is_typescript() || !self.typescript.only_remove_type_imports) + { + jsx::update_options_with_comments( + &program.comments, + &mut self.typescript, + &mut self.jsx, + &self.ctx, + ); + } let mut transformer = TransformerImpl { common: Common::new(&self.env, &self.ctx), diff --git a/tasks/transform_conformance/snapshots/oxc.snap.md b/tasks/transform_conformance/snapshots/oxc.snap.md index a74634c2fa..7916a5386a 100644 --- a/tasks/transform_conformance/snapshots/oxc.snap.md +++ b/tasks/transform_conformance/snapshots/oxc.snap.md @@ -1,6 +1,6 @@ commit: 578ac4df -Passed: 141/233 +Passed: 143/235 # All Passed: * babel-plugin-transform-class-static-block @@ -43,7 +43,7 @@ after transform: SymbolId(0): [ReferenceId(0), ReferenceId(2), ReferenceId(6), R rebuilt : SymbolId(0): [ReferenceId(0), ReferenceId(2), ReferenceId(6), ReferenceId(10)] -# babel-plugin-transform-typescript (2/15) +# babel-plugin-transform-typescript (4/17) * class-property-definition/input.ts Unresolved references mismatch: after transform: ["const"] diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/jsx/retain-jsx-pragm/input.tsx b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/jsx/retain-jsx-pragm/input.tsx new file mode 100644 index 0000000000..70f8a5ea8e --- /dev/null +++ b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/jsx/retain-jsx-pragm/input.tsx @@ -0,0 +1,4 @@ +// @jsx JSX +import JSX from "module" + +() =>
diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/jsx/retain-jsx-pragm/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/jsx/retain-jsx-pragm/output.js new file mode 100644 index 0000000000..c03402fe9b --- /dev/null +++ b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/jsx/retain-jsx-pragm/output.js @@ -0,0 +1,2 @@ +import JSX from "module"; +() => ; diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/jsx/with-only-remove-import-types/input.tsx b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/jsx/with-only-remove-import-types/input.tsx new file mode 100644 index 0000000000..70f8a5ea8e --- /dev/null +++ b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/jsx/with-only-remove-import-types/input.tsx @@ -0,0 +1,4 @@ +// @jsx JSX +import JSX from "module" + +() => diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/jsx/with-only-remove-import-types/options.json b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/jsx/with-only-remove-import-types/options.json new file mode 100644 index 0000000000..ac8ffdfa79 --- /dev/null +++ b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/jsx/with-only-remove-import-types/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["transform-typescript", { "onlyRemoveTypeImports": true }]] +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/jsx/with-only-remove-import-types/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/jsx/with-only-remove-import-types/output.js new file mode 100644 index 0000000000..c03402fe9b --- /dev/null +++ b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/jsx/with-only-remove-import-types/output.js @@ -0,0 +1,2 @@ +import JSX from "module"; +() => ;