Skip to content
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

Fix bundling for bun not using ascii_only #9571

Merged
merged 3 commits into from Mar 23, 2024

Conversation

pfgithub
Copy link
Contributor

What does this PR do?

Fixes #9559

In printWithWriterAndPlatform(), its NewPrinter call was always setting ascii_only to false, but that means when bundling for the bun target, the code is not emitted as ascii only and there will be errors when running because it tries to run as latin1.

This code

console.log(JSON.stringify({: "a"}));

const  = "b";
console.log(JSON.stringify({}));

When built with bun build --target bun code.js now emits:

// @bun
// code.js
console.log(JSON.stringify({ "\u{6211}": "a" }));
var \u{6211} = "b";
console.log(JSON.stringify({ "\u{6211}": \u{6211} }));

instead of:

// @bun
// code.js
console.log(JSON.stringify({ "我": "a" }));
var  = "b";
console.log(JSON.stringify({ "我":  }));

It also works with bun build --compile.

  • Documentation or TypeScript types (it's okay to leave the rest blank in this case)
  • Code changes

How did you verify your code works?

Added a regression test for the issue

It tests bun build --target bun and not bun build --compile because compile takes a second and they're both the same issue.

If Zig files changed:

  • N/A I checked the lifetime of memory allocated to verify it's (1) freed and (2) only freed when it should be
  • I included a test for the new code, or an existing test covers it
  • N/A JSValue used outside outside of the stack is either wrapped in a JSC.Strong or is JSValueProtect'ed
  • I wrote TypeScript/JavaScript tests and they pass locally (bun-debug test test-file-name.test)

@pfgithub pfgithub changed the title Fix bundling not using ascii_only Fix bundling for bun not using ascii_only Mar 22, 2024
Copy link
Collaborator

@paperdave paperdave left a comment

Choose a reason for hiding this comment

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

today i learned \u{6211} is valid identifier

@Jarred-Sumner
Copy link
Collaborator

Thank you for this.

Can you add a test for bun build --compile as well? You can see the tests in bundler_compile for an example

@pfgithub
Copy link
Contributor Author

Added one in bundler_compile

@pfgithub
Copy link
Contributor Author

I don't think any of the CI failures are my fault

@Jarred-Sumner Jarred-Sumner merged commit ee5fd51 into oven-sh:main Mar 23, 2024
26 of 31 checks passed
@Jarred-Sumner
Copy link
Collaborator

Agreed, thank you for this

zackradisic pushed a commit that referenced this pull request Mar 25, 2024
* Fix bundling not using ascii_only

* add utf8 test to bundler_compile & make test source ascii

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
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.

When using bun to build a binary file, the Chinese key in the js object will be garbled.
3 participants