Repository navigation
fix(parser): fix bytecode CJS pragma detection after shebang #25868
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
Changes from all commits
c62b8bc
b55d9ac
a80acc2
48cb836
c860ccd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -203,4 +203,33 @@ module.exports = 1;`, | |
| `); | ||
| }, | ||
| }); | ||
|
|
||
| itBundled("banner/SourceHashbangWithBytecodeAndCJSTargetBun", { | ||
| banner: "// Copyright 2024 Example Corp", | ||
| format: "cjs", | ||
| target: "bun", | ||
| bytecode: true, | ||
| outdir: "/out", | ||
| minifyWhitespace: true, | ||
| backend: "api", | ||
| files: { | ||
| "/a.js": `#!/usr/bin/env bun | ||
| module.exports = 1; | ||
| console.log("bun!");`, | ||
| }, | ||
| onAfterBundle(api) { | ||
| const content = api.readFile("/out/a.js"); | ||
| // Shebang from source should come first, then @bun pragma | ||
| expect(content).toMatchInlineSnapshot(` | ||
| "#!/usr/bin/env bun | ||
| // @bun @bytecode @bun-cjs | ||
| (function(exports, require, module, __filename, __dirname) {// Copyright 2024 Example Corp | ||
| module.exports=1;console.log("bun!");}) | ||
| " | ||
| `); | ||
| }, | ||
| run: { | ||
| stdout: "bun!\n", | ||
| }, | ||
| }); | ||
|
Comment on lines
+207
to
+234
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Consider adding explicit order verification. The test includes a comment (line 222) emphasizing that "Shebang from source should come first, then @Bun pragma," which suggests order is critical for this bug fix. Consider adding explicit order checks similar to the // After the snapshot assertion
const shebangIndex = content.indexOf("#!/usr/bin/env bun");
const pragmaIndex = content.indexOf("// @bun @bytecode @bun-cjs");
const wrapperIndex = content.indexOf("(function(exports, require, module, __filename, __dirname) {");
const bannerIndex = content.indexOf("// Copyright 2024 Example Corp");
expect(shebangIndex).toBe(0);
expect(pragmaIndex).toBeGreaterThan(shebangIndex);
expect(wrapperIndex).toBeGreaterThan(pragmaIndex);
expect(bannerIndex).toBeGreaterThan(wrapperIndex);This would provide more specific failure messages if the ordering regresses and be consistent with similar tests in the file. 🤖 Prompt for AI Agents |
||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.