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 · 2 comments
Open

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

JLHwung opened this issue Jul 31, 2022 · 2 comments

Comments

@JLHwung
Copy link
Contributor

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.

@Boshen
Copy link
Member

Boshen commented Oct 13, 2024

Given this proposal is stage 4, these are the remaining test262 case we are unable to flag as syntax errors:

Should phase in the test cases be changed to resolution?

https://github.com/tc39/test262/blob/e48df0b96457b67b2d81fab16cabb230152a6c57/INTERPRETING.md#negative:

phase - the stage of the test interpretation process that the error is expected to be produced; valid phases are:
parse: occurs while parsing the source text, or while checking it for early errors.
resolution: occurs during module resolution.
runtime: occurs during evaluation.

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

3 participants