-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Error when parsing keys with hyphen in some JSON files #7261
Comments
Interesting |
So it turns out that JSON config files are handled differently bun/src/bun.js/module_loader.zig Lines 1574 to 1585 in 22818e6
Lines 1608 to 1615 in 22818e6
They go through are a special parser Line 885 in 22818e6
and are rewritten as modules, thus producing a syntax error in this case: var key_with_hyphen = !0
export {
key_with_hyphen as key-with-hyphen
};
export default { "key-with-hyphen": key_with_hyphen }; @Jarred-Sumner why are these files rewritten like this ? Is it for JSON5 compatibility ? |
According to MDN quoting the alias should work, but I get the same error rewriting it like this: var key_with_hyphen = !0
export {
key_with_hyphen as "key-with-hyphen"
};
export default { "key-with-hyphen": key_with_hyphen }; Edit: I'm not sure why this is not working, according WebKit's Bugzilla this has been supported for a while... |
What version of Bun is running?
1.0.13+f5bf67bd1
What platform is your computer?
Linux 5.15.0-101.103.2.1.el8uek.x86_64 x86_64 x86_64
What steps can reproduce the bug?
When importing/requiring some JSON files that contain hyphens in the keys, Bun can throw a syntax error. Currently can reproduce with files named
tsconfig.json
. Maybe parsing oftsconfig
is somehow different?Results in:
With files named other than
tsconfig.json
everything works as expected:What is the expected behavior?
All JSON files should be treated and parsed the same.
What do you see instead?
tsconfig.json
files throw when threre are hyphens in keys.Additional information
The issue was discovered with
tsconfig.json
containing a key forts-node
configuration (which includes a hyphen).The text was updated successfully, but these errors were encountered: