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

Should named JSON module import be a parsing stage error? #27

Open
JLHwung opened this issue Jul 31, 2022 · 1 comment
Open

Should named JSON module import be a parsing stage error? #27

JLHwung opened this issue Jul 31, 2022 · 1 comment

Comments

@JLHwung
Copy link

JLHwung commented Jul 31, 2022

Currently Babel parser throws syntax error for the following cases:

import { foo } from "./foo" asserts { type: "json" };

which conforms to this test262 test.

But the spec only states that JSON module should provide only a single default export, so a SyntaxError should be thrown no later than the module resolution stage. However unlike random modules, a parser can recognize JSON module imports thanks to the import assertion syntax. So should a JavaScript parser throw such errors?

Either way an end user will not observe any differences, but it helps us define the scope.

Context: babel/babel#14816

@ljharb
Copy link
Member

ljharb commented Aug 1, 2022

It’s a host-dependent behavior, and the assertion is not supposed to be required outside a browser. It definitely should error, but probably not at the parsing stage.

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

No branches or pull requests

2 participants