Skip to content

fix: correctly resolve string literals in export specifiers#386

Merged
Swatinem merged 1 commit into
Swatinem:masterfrom
cueaz:fix-string-literal-export-names
May 19, 2026
Merged

fix: correctly resolve string literals in export specifiers#386
Swatinem merged 1 commit into
Swatinem:masterfrom
cueaz:fix-string-literal-export-names

Conversation

@cueaz

@cueaz cueaz commented May 19, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes the resolution of ES2022 string literal export names (e.g., export { b as "bb" }).

Currently, Rollup fails to link identifiers exported as string literals, resulting in missing exports and [undefined] properties in the bundled output. This occurs because createIdentifier uses node.getText(), which preserves the surrounding quotes for ts.StringLiteral nodes (e.g., '"bb"'), causing a mismatch in Rollup's linker.

Updating this to use node.text passes the unquoted identifier value, resolving the issue.

Test Case

mod.d.ts
declare const a: "a";
declare const b: "b";
declare const c: "c";

export { a as aa, b as "bb", c as "c c" };
index.d.ts
import * as mod from "./mod";
import { "c c" as cc } from "./mod";

declare class Test {
  [mod.aa]: string;
  [mod.bb]: string;
  [cc]: string;
}

export { Test };
Actual Output (Failing):
declare const a: "a";
declare const c: "c";
declare class Test {
  [a]: string;
  [undefined]: string;
  [c]: string;
}
export { Test };
expected.d.ts
declare const a: "a";
declare const b: "b";
declare const c: "c";
declare class Test {
  [a]: string;
  [b]: string;
  [c]: string;
}
export { Test };

@cueaz cueaz force-pushed the fix-string-literal-export-names branch from 44d8b68 to 18ed4d7 Compare May 19, 2026 02:36

@Swatinem Swatinem left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m actually surprised that this works, and doesn’t require the AST node to be a Literal instead.

But okay, I guess this is simpler so why not :-)

@Swatinem

Copy link
Copy Markdown
Owner

well, CI says the syntax is not supported.

Does it depend on TS6, which I think we haven’t updated to yet, or does it need a specific tsconfig, in which case you would need to add that to a meta file. There are a bunch of those among the testcases for inspiration.

@cueaz

cueaz commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

Ah, you're right. It requires TS 5.6 for arbitrary module identifiers. I'll add the meta.js file.

For the identifier part, I also worried about invalid names, but followed createIdentifier since it accepts StringLiteral. It’s interesting that Rollup links them without errors.

@cueaz cueaz force-pushed the fix-string-literal-export-names branch from 18ed4d7 to ed325ce Compare May 19, 2026 14:05
@cueaz cueaz force-pushed the fix-string-literal-export-names branch from ed325ce to 56fc57a Compare May 19, 2026 15:30
@Swatinem Swatinem merged commit b9e9551 into Swatinem:master May 19, 2026
4 checks passed
@Swatinem

Copy link
Copy Markdown
Owner

thanks for the fix.
even though without a TS update, the tests are effectively disabled, the actual fix is trivial enough to not cause problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants