🔎 Search Terms
import defer, deferred import, side-effect import, import phase
🕗 Version & Regression Information
- This is the behavior in every version I tried: 5.9.3 and 7.1.0-dev.20261004.1.
⏯ Playground Link
https://www.typescriptlang.org/play/?module=99&target=99#code/JYWwDg9gTgLgBAEwKYDMlTgIgHQHoCG2AVgM6YDcAUEA
💻 Code
🙁 Actual behavior
No error. The output leaves out defer, so the module is evaluated eagerly:
🙂 Expected behavior
An error. The import defer proposal only allows a namespace import after defer (import defer * as ns from "./a.js"), so this is a syntax error in JavaScript. Babel rejects it (Unexpected token, expected "{").
TypeScript 7.1 already reports an error for the same form with the source phase:
import source "./b.wasm";
// error TS18111: A source phase import must specify a local binding.
Additional information about the issue
In tryParseImportClause, a phase without bindings keeps an empty import clause only for source. For defer, the function returns nil, so the declaration has no import clause, and its phase is lost. checkGrammarImportClause also has no check for a deferred import without bindings: it reports a default import (TS18058) and named imports (TS18059) only.
Keeping the empty import clause for defer too, and reporting an error for it in checkGrammarImportClause, would match import source "./b.wasm".
Found while matching TypeScript's diagnostics in TSRX's parser.
🔎 Search Terms
import defer, deferred import, side-effect import, import phase
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?module=99&target=99#code/JYWwDg9gTgLgBAEwKYDMlTgIgHQHoCG2AVgM6YDcAUEA
💻 Code
🙁 Actual behavior
No error. The output leaves out defer, so the module is evaluated eagerly:
🙂 Expected behavior
An error. The import defer proposal only allows a namespace import after defer (import defer * as ns from "./a.js"), so this is a syntax error in JavaScript. Babel rejects it (Unexpected token, expected "{").
TypeScript 7.1 already reports an error for the same form with the source phase:
Additional information about the issue
In tryParseImportClause, a phase without bindings keeps an empty import clause only for source. For defer, the function returns nil, so the declaration has no import clause, and its phase is lost. checkGrammarImportClause also has no check for a deferred import without bindings: it reports a default import (TS18058) and named imports (TS18059) only.
Keeping the empty import clause for defer too, and reporting an error for it in checkGrammarImportClause, would match import source "./b.wasm".
Found while matching TypeScript's diagnostics in TSRX's parser.