diff --git a/packages/babel-plugin-transform-typescript/src/index.js b/packages/babel-plugin-transform-typescript/src/index.js index f53a1e343715..7598836f6a52 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)) { @@ -203,7 +208,7 @@ export default declare( isImportTypeOnly({ binding, programPath: path, - jsxPragma: fileJsxPragma || jsxPragma, + jsxPragma: pragmaImportName, }) ) { importsToRemove.push(binding.path); 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"; +
;