You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now this code throws a ReferenceError, because there are no JS source objects:
importsourcesfrom"./mod.js";
I believe this code should throw a SyntaxError, even if might appear conter-intuitive. ReferenceError is only used for code that runs, and not before evaluation. As a very strong precedent ("very strong" because it's basically the same thing), import { x } from "./a" is a SyntaxError is ./a does not export x.
Older versions of the language used to have ReferenceErrors for some errors that happen before evaluation, but in ES2020 we updated all of them to be SyntaxErrors (tc39/ecma262#1527).
The text was updated successfully, but these errors were encountered:
This is still somewhat of a semantic question since source phases aren't really associated with any execution, they are more like slots on the module map.
We could similarly say that this is more like TDZ, since the slot is there but it is not filled. Note also that modules in cycles with TDZ provide reference errors when attempting to access a binding from a module which has not yet been executed.
That all said, I don't have strong opinions and am open to changing the error type, but some further discussion could be worthwhile.
Right now this code throws a ReferenceError, because there are no JS source objects:
I believe this code should throw a SyntaxError, even if might appear conter-intuitive. ReferenceError is only used for code that runs, and not before evaluation. As a very strong precedent ("very strong" because it's basically the same thing),
import { x } from "./a"
is a SyntaxError is./a
does not exportx
.Older versions of the language used to have ReferenceErrors for some errors that happen before evaluation, but in ES2020 we updated all of them to be SyntaxErrors (tc39/ecma262#1527).
The text was updated successfully, but these errors were encountered: