From 1237dce90dfb67fa7a084b01fefe7aec6843d5f4 Mon Sep 17 00:00:00 2001 From: Jason Quense Date: Tue, 5 May 2020 11:02:28 -0400 Subject: [PATCH 1/2] fix: don't elide jsx pragma import namespaces --- packages/babel-plugin-transform-typescript/src/index.js | 5 +++++ .../fixtures/imports/elide-jsx-pragma-namespace-no/input.ts | 4 ++++ .../imports/elide-jsx-pragma-namespace-no/options.json | 3 +++ .../imports/elide-jsx-pragma-namespace-no/output.mjs | 4 ++++ 4 files changed, 16 insertions(+) create mode 100644 packages/babel-plugin-transform-typescript/test/fixtures/imports/elide-jsx-pragma-namespace-no/input.ts create mode 100644 packages/babel-plugin-transform-typescript/test/fixtures/imports/elide-jsx-pragma-namespace-no/options.json create mode 100644 packages/babel-plugin-transform-typescript/test/fixtures/imports/elide-jsx-pragma-namespace-no/output.mjs diff --git a/packages/babel-plugin-transform-typescript/src/index.js b/packages/babel-plugin-transform-typescript/src/index.js index f53a1e343715..a006e04a622a 100644 --- a/packages/babel-plugin-transform-typescript/src/index.js +++ b/packages/babel-plugin-transform-typescript/src/index.js @@ -169,6 +169,11 @@ export default declare( } } + let pragmaImportName = fileJsxPragma || jsxPragma; + if (pragmaImportName) { + [pragmaImportName] = pragmaImportName.split("."); + } + // remove type imports for (let stmt of path.get("body")) { if (t.isImportDeclaration(stmt)) { diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/imports/elide-jsx-pragma-namespace-no/input.ts b/packages/babel-plugin-transform-typescript/test/fixtures/imports/elide-jsx-pragma-namespace-no/input.ts new file mode 100644 index 000000000000..9ba83b13ea8c --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/imports/elide-jsx-pragma-namespace-no/input.ts @@ -0,0 +1,4 @@ +/* @jsx jsx.htm */ +// Don't elide htm if a JSX element appears somewhere. +import * as jsx from "fake-jsx-package"; +
; diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/imports/elide-jsx-pragma-namespace-no/options.json b/packages/babel-plugin-transform-typescript/test/fixtures/imports/elide-jsx-pragma-namespace-no/options.json new file mode 100644 index 000000000000..2c7aa7bce294 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/imports/elide-jsx-pragma-namespace-no/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["transform-typescript", { "isTSX": true }]] +} diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/imports/elide-jsx-pragma-namespace-no/output.mjs b/packages/babel-plugin-transform-typescript/test/fixtures/imports/elide-jsx-pragma-namespace-no/output.mjs new file mode 100644 index 000000000000..9ba83b13ea8c --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/imports/elide-jsx-pragma-namespace-no/output.mjs @@ -0,0 +1,4 @@ +/* @jsx jsx.htm */ +// Don't elide htm if a JSX element appears somewhere. +import * as jsx from "fake-jsx-package"; +
; From 27c5224834bf20cb9ddaee53bcea66102992bb49 Mon Sep 17 00:00:00 2001 From: Jason Quense Date: Tue, 5 May 2020 14:41:58 -0400 Subject: [PATCH 2/2] use the correct pragma oops --- packages/babel-plugin-transform-typescript/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-plugin-transform-typescript/src/index.js b/packages/babel-plugin-transform-typescript/src/index.js index a006e04a622a..7598836f6a52 100644 --- a/packages/babel-plugin-transform-typescript/src/index.js +++ b/packages/babel-plugin-transform-typescript/src/index.js @@ -208,7 +208,7 @@ export default declare( isImportTypeOnly({ binding, programPath: path, - jsxPragma: fileJsxPragma || jsxPragma, + jsxPragma: pragmaImportName, }) ) { importsToRemove.push(binding.path);