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

Bare unicode characters after bundle of json #977

Closed
retorquere opened this issue Mar 15, 2021 · 14 comments · Fixed by #1139
Closed

Bare unicode characters after bundle of json #977

retorquere opened this issue Mar 15, 2021 · 14 comments · Fixed by #1139

Comments

@retorquere
Copy link

bundle script:

const esbuild = require('esbuild')

async function rebuild() {
  await esbuild.build({
    entryPoints: ['tt.ts'],
    format: 'iife',
    bundle: true,
    outfile: 'tt.js',
    target: ['firefox60'],
  })
}

rebuild().catch(err => console.log(err))

tt.ts:

import x from './ascii.json'
console.log(x)

ascii.json:

{
  "\ud835\udfce": {"math": "\\mathbf{0}"}
}

output:

(() => {
  // ascii.json
  var _ = {math: "\\mathbf{0}"};
  var ascii_default = {
    \u{1D7CE}: _
  };

  // tt.ts
  console.log(ascii_default);
})();

I'm trying to run the results through jscodeshift and it doesn't like that bare \u{1D7CE} (I didn't know this was valid javascript)

@retorquere
Copy link
Author

FF60 says SyntaxError: invalid escape sequence when I try to run this.

@evanw
Copy link
Owner

evanw commented Mar 15, 2021

Huh. My compatibility table data says that this is supported since Firefox 53: https://github.com/kangax/compat-table/blob/c06fcd3387a5770708a452fb90dbc4e99bb37e4f/data-es6.js#L18988. If you want to use UTF-8 instead you can enable this: https://esbuild.github.io/api/#charset.

@retorquere
Copy link
Author

Maybe Zotero has done something that caused a regression, but I have to say it is not very likely. But thanks, this will fix it for me.

@retorquere
Copy link
Author

Setting the charset to utf-8 causes dict literals with unicode keys to be output unescaped, which also gives me errors in Zotero. Is there a target that is close to firefox60 but which will not produce bare unicode escapes?

@retorquere
Copy link
Author

What is the current target list? This doesn't list firefox60 but that does work, where firefox52 does not.

@retorquere
Copy link
Author

(alternately, can I just convince esbuild not to use bare unicode escapes?)

@retorquere
Copy link
Author

Or if I could replace the json loader, that would also work; I'd just use jsesc to output it in a way that works in Zotero, as the problem is limited to JSON files for me.

@retorquere retorquere reopened this Apr 11, 2021
@retorquere
Copy link
Author

If I delete versions.UnicodeEscapes.firefox in scripts/compat-table.js, my code mostly works after bundling -- it's just the bare unicode that blocks a transition to esbuild for me.

@evanw
Copy link
Owner

evanw commented Apr 11, 2021

It turns out this doesn't have to do with Firefox at all. The bug is that when validating whether esbuild can print an identifier without quotes, non-BMP characters always being treated as ID_Continue because they extend past the first code unit. This is incorrect because the first character should be treated as ID_Start instead. I'll fix this.

@retorquere
Copy link
Author

Sweet!

@retorquere
Copy link
Author

This does fix it for me.

@retorquere
Copy link
Author

If you don't mind me asking -- do you have a release planned that would include this? I understand no hard ETAs in open source work.

@evanw
Copy link
Owner

evanw commented Apr 12, 2021

No worries. I generally release changes within a day or two.

@retorquere
Copy link
Author

I've migrated my project, and builds are not only amazingly fast (including type-checking using tsc), my bundler code is now significantly simpler because an increasing part of my bundler setup consisted of workarounds for webpack.

Thank you!

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 a pull request may close this issue.

2 participants