proposal-source-phase-imports icon indicating copy to clipboard operation
proposal-source-phase-imports copied to clipboard

Is importing JS modules in the source phase expected to throw?

Open lpardosixtosMs opened this issue 9 months ago • 2 comments

From the JS Module Source section in github I understand that importing a JS module in the source phase should return a valid object with AbstractModuleSource.prototype in the prototype chain, but from the spec, I understand that it should throw. What is the expected behavior?

Here is how I'm reading the spec:   HTML's create a JavaScript module script calls TC39's Parse Module, which is not modified in the source phase import proposal, so it leaves the Abstract Module Record's new [[ModuleSource]] slot EMPTY. So that would throw in the Linking inside InitializeEnvironments when checking the imports and for dynamic imports in ContinueDynamicImport when finishing the import for the JS script.

lpardosixtosMs avatar Mar 20 '25 23:03 lpardosixtosMs

Under this specification, it throws a SyntaxError when it sees no [[ModuleSource]] defined as you describe in https://tc39.es/proposal-source-phase-imports/#sec-source-text-module-record-initialize-environment (and also separately for dynamic imports).

With the new ESM Phase Imports proposal (https://github.com/tc39/proposal-esm-phase-imports) this case is then supported and does not throw.

guybedford avatar Mar 20 '25 23:03 guybedford

Thanks! It would be nice to update this section to reflect this.

lpardosixtosMs avatar Mar 24 '25 16:03 lpardosixtosMs