fix(codegen): preserve default import names in source maps (#28058)

Default imports with escaped identifiers (for example, `import s\u006furce from "./a.js"`) lose their original spelling from JS codegen source maps. The default-import printer records an unnamed mapping for the specifier instead of a named mapping for its local identifier.

Use the same named identifier mapping as the other import forms. Add regressions for default imports, type-only imports, and defaults combined with named or namespace imports; each compares code and complete source maps against Rust in both parenthesis modes.

Exposed by the TypeScript fixture update in #28057 and [this failed CI job](https://github.com/oxc-project/oxc/actions/runs/39690771786/job/119536110779). Stack: this fix targets `main`; #28057 targets this branch.
This commit is contained in:
camc314 committed 2026-10-21 23:58:27 +00:00
1 parent f5b625f242
commit 0e2934fbe6
2 files changed
+24 -5

No files matched your search

+4 -5
View File
@@ -72,13 +72,12 @@ export function printImportDeclaration(node: ESTree.ImportDeclaration, state: St
}
printSpaceBeforeIdentifier(state);
writeWithMap(
writeWithMapNamed(
state,
specifier.local.name,
CAT_IDENT,
specifier.start,
specifier.end,
specifier,
specifier.local.start,
specifier.local.end,
specifier.local,
);
if (i === length - 1) write(state, " ", CAT_OTHER);
+20
View File
@@ -94,6 +94,26 @@ describe("Rust conformance", () => {
lang: "js" as const,
},
{ name: "astral-new.js", code: "new 𐐀;", lang: "js" as const },
{
name: "escaped-default-import.js",
code: 'import s\\u006furce from "./a.js";',
lang: "js" as const,
},
{
name: "escaped-default-import.ts",
code: 'import type s\\u006furce from "./a.js";',
lang: "ts" as const,
},
{
name: "escaped-default-and-named-import.js",
code: 'import s\\u006furce, { value } from "./a.js";',
lang: "js" as const,
},
{
name: "escaped-default-and-namespace-import.js",
code: 'import s\\u006furce, * as ns from "./a.js";',
lang: "js" as const,
},
{
name: "large-line-gap.js",
code: `\`${"\n".repeat(200)}\`;\nvalue;`,