-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Preserve string-literal names in re-export clauses #29245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Jarred-Sumner
merged 6 commits into
main
from
farm/964629d3/fix-reexport-string-literal
Apr 14, 2026
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0f8671e
Preserve string-literal names in re-exports
robobun 8620891
[autofix.ci] apply automated fixes
autofix-ci[bot] d6d67f4
Address review: use original_name, concurrent tests, assertion order
robobun 6f510fb
[autofix.ci] apply automated fixes
autofix-ci[bot] 3ef5fb3
Review nits: fix test title, make unquoted-token guard quote-agnostic
robobun b8f7fd5
Re-run CI (empty commit to retrigger stalled build)
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| // https://github.com/oven-sh/bun/issues/29242 | ||
| // | ||
| // The parser handles string-literal names in `export { ... } from 'mod'` | ||
| // clauses, but when transpiling without bundling the printer dropped the | ||
| // quotes around the local name, producing invalid syntax that JSC then | ||
| // rejected: | ||
| // | ||
| // export { "a b c" } from './b.mjs'; // input | ||
| // export { a b c } from './b.mjs'; // old output — SyntaxError | ||
| // export { "a b c" } from './b.mjs'; // fixed output | ||
| import { expect, test } from "bun:test"; | ||
| import { bunEnv, bunExe, tempDir } from "harness"; | ||
|
|
||
|
robobun marked this conversation as resolved.
|
||
| test.concurrent("re-export with string literal local name (export { 'a b c' } from 'mod')", async () => { | ||
| using dir = tempDir("issue-29242-bare", { | ||
| "a.mjs": `export { "a b c" } from './b.mjs';`, | ||
| "b.mjs": `const a = 1;\nexport { a as "a b c" };`, | ||
| "main.mjs": `import { "a b c" as a } from './a.mjs';\nconsole.log(a);`, | ||
| }); | ||
|
|
||
|
claude[bot] marked this conversation as resolved.
|
||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "main.mjs"], | ||
| env: bunEnv, | ||
| cwd: String(dir), | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| expect(stderr).not.toContain("SyntaxError"); | ||
| expect(stdout).toBe("1\n"); | ||
| expect(exitCode).toBe(0); | ||
| }); | ||
|
|
||
| test.concurrent("re-export aliasing from string literal to identifier", async () => { | ||
| using dir = tempDir("issue-29242-alias", { | ||
| "a.mjs": `export { "a b c" as a } from './b.mjs';`, | ||
| "b.mjs": `const a = 1;\nexport { a as "a b c" };`, | ||
| "main.mjs": `import { a } from './a.mjs';\nconsole.log(a);`, | ||
| }); | ||
|
|
||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "main.mjs"], | ||
| env: bunEnv, | ||
| cwd: String(dir), | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| expect(stderr).not.toContain("SyntaxError"); | ||
| expect(stdout).toBe("1\n"); | ||
| expect(exitCode).toBe(0); | ||
| }); | ||
|
|
||
| test.concurrent("re-export aliasing string literal to string literal", async () => { | ||
| using dir = tempDir("issue-29242-both", { | ||
| "a.mjs": `export { "a b c" as "x y z" } from './b.mjs';`, | ||
| "b.mjs": `const a = 1;\nexport { a as "a b c" };`, | ||
| "main.mjs": `import { "x y z" as a } from './a.mjs';\nconsole.log(a);`, | ||
| }); | ||
|
|
||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "main.mjs"], | ||
| env: bunEnv, | ||
| cwd: String(dir), | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| expect(stderr).not.toContain("SyntaxError"); | ||
| expect(stdout).toBe("1\n"); | ||
| expect(exitCode).toBe(0); | ||
| }); | ||
|
|
||
| test.concurrent.each([ | ||
| [`export { "a b c" } from './mod';`, [`"a b c"`]], | ||
| [`export { "a b c" as a } from './mod';`, [`"a b c"`]], | ||
| [`export { "a b c" as "x y z" } from './mod';`, [`"a b c"`, `"x y z"`]], | ||
| [`export { plain, "a b c" as aliased } from './mod';`, [`"a b c"`, `plain`]], | ||
| ])("transpiler preserves string literal names in export-from clauses: %s", async (source, mustContain) => { | ||
| // Direct test of the printer: transpile without bundling and confirm the | ||
| // quotes around the local names are preserved. | ||
| using dir = tempDir("issue-29242-printer", { | ||
| "input.ts": source, | ||
| }); | ||
|
|
||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "build", "input.ts", "--target=bun", "--no-bundle"], | ||
| env: bunEnv, | ||
| cwd: String(dir), | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| expect(stderr).not.toContain("SyntaxError"); | ||
| for (const frag of mustContain) { | ||
| expect(stdout).toContain(frag); | ||
| } | ||
| // No unquoted `a b c` or `x y z` anywhere (guard quote-style agnostic). | ||
| expect(stdout).not.toMatch(/(^|[^"'])a b c(?!["'])/); | ||
| expect(stdout).not.toMatch(/(^|[^"'])x y z(?!["'])/); | ||
| expect(exitCode).toBe(0); | ||
| }); | ||
|
|
||
| test.concurrent("transpiler preserves string literal names under --minify-identifiers", async () => { | ||
| // Regression for a subtlety: the export-from clause's left-side symbol | ||
| // is a synthesized intermediate that a minifier may rename. Printing | ||
| // `original_name` (the raw source text) keeps re-exports correct. | ||
| using dir = tempDir("issue-29242-minify", { | ||
| "input.ts": [`export { "a b c" as aliased } from './mod';`, `export { foo as bar } from './mod';`].join("\n"), | ||
| }); | ||
|
|
||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "build", "input.ts", "--target=bun", "--no-bundle", "--minify-identifiers"], | ||
| env: bunEnv, | ||
| cwd: String(dir), | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| expect(stderr).not.toContain("SyntaxError"); | ||
| expect(stdout).toContain(`"a b c" as aliased`); | ||
| expect(stdout).toContain(`foo as bar`); | ||
| expect(stdout).not.toMatch(/(^|[^"'])a b c(?!["'])/); | ||
| expect(exitCode).toBe(0); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Trim the top-of-file bug-context prose to keep regression tests concise.
Consider keeping just the issue URL and removing the long reproduction/output narrative block; this context already lives in the PR/issue and makes the test noisier to scan.
Based on learnings: In oven-sh/bun regression test files, do not suggest adding inline comments that explain bug context or issue number being tested; PR descriptions cover that context and test code is kept clean.
🤖 Prompt for AI Agents