Skip to content

fix: improve string module specifiers support - #18504

Merged
JLHwung merged 5 commits into
babel:mainfrom
JLHwung:fix-string-module-specifiers
Nov 10, 2026
Merged

JLHwung merged 5 commits into
babel:mainfrom
JLHwung:fix-string-module-specifiers

Conversation

@JLHwung

@JLHwung JLHwung commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor
Q                       A
Fixed Issues? See below
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
Need backport? 7.x
License MIT

As a follow-up to #18498, in this PR we implemented the following fixes related to string module specifiers:

  • t.isSpecifierDefault now recognizes "default"
  • referencesImport now matches string import names, so transform-react-pure-annotations now annotates import {"createElement" as h}
  • JSX tags that can't be rewritten now get a clear error instead of a crash
  • The TS parser now accepts type "a" specifiers and export { type X as "a" } from "foo". Both forms already supported by tsc.

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories 7.x: needs backport labels Nov 3, 2026
@JLHwung
JLHwung force-pushed the fix-string-module-specifiers branch from d32aa77 to d4e5147 Compare November 3, 2026 15:23
@pkg-pr-new

pkg-pr-new Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

commit: 20f325a

@JLHwung
JLHwung force-pushed the fix-string-module-specifiers branch from d4e5147 to fbe60f2 Compare November 4, 2026 00:21
@babel-bot

babel-bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/63122

`import { "default" as a }` and `export { a as "default" }` are equivalent
to their identifier forms, but only the identifier was compared.

Assisted-by: Claude Opus 5.5
`import { "createElement" as h } from "react"` was not recognized as a
reference to `createElement`, so for example
`transform-react-pure-annotations` did not annotate calls to `h`.

Assisted-by: Claude Opus 5.5
With JSX preserved, `import { "a b" as Foo } from "m"; <Foo />` rewrites
`Foo` to `_m["a b"]`, which has no JSX member expression form. Building one
crashed with `Property name expected type of string but got undefined`.
The same happened to any JSX tag with lazy imports, as `_m().Foo` has no
JSX form either. Throw a code frame error asking to transform JSX instead.

Assisted-by: Claude Opus 5.5
`parseTypeOnlyImportSpecifier` and `parseTypeOnlyExportSpecifier` only looked
for an identifier after `type`, even if the export branches then called
`parseModuleExportName`, so these were rejected with "Unexpected token":

    export { type "a" } from "m";
    export { type "a" as b } from "m";
    import { type "a" as b } from "m";
    export { type as as "a" } from "m";

Also `export { type as "a" }`, which is valid JavaScript exporting a binding
named `type`, could not be parsed with the `typescript` plugin.

Assisted-by: Claude Opus 5.5
@JLHwung
JLHwung force-pushed the fix-string-module-specifiers branch from 72b4732 to 23a6011 Compare November 10, 2026 14:05
The "Did you mean" hint for a string local name without `from` dropped
the `type` modifier, so `export { type "a" }` and `export type { "a" }`
both suggested `export { 'a' as 'a' } from 'some-module'`, which is a
value export. Now they suggest `export { type 'a' as 'a' } from ...` and
`export type { 'a' as 'a' } from ...` respectively.

Assisted-by: Claude Opus 5.5
@JLHwung
JLHwung force-pushed the fix-string-module-specifiers branch from 23a6011 to 20f325a Compare November 10, 2026 14:23
@JLHwung
JLHwung added this pull request to the merge queue Nov 10, 2026
Merged via the queue into babel:main with commit 0afa86a Nov 10, 2026
44 of 45 checks passed
@JLHwung
JLHwung deleted the fix-string-module-specifiers branch November 10, 2026 19:04
@babel-bot

Copy link
Copy Markdown
Collaborator

Backported to 7.x in #18574.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants