importStatement(input: string): ImportStatement | MisreadImport | null
An import declaration, read into what it binds — or null for anything else.
A prompt is not a module, so the engine refuses the statement outright: Cannot use import statement outside a module. Reading the clause here is what lets a caller do what the statement
means instead — fetch the module and put those names in scope — without an evaluator that
understands modules.
import() the function is left alone: it is an expression, it already works, and the space after
the keyword is what tells them apart.
A line that is plainly meant to be an import and cannot be read comes back as advice rather than
as nothing. Left as nothing it would reach the page, and the page answers every one of them with
Cannot use import statement outside a module — which is true of the working spellings too, and
so says nothing about which one this is.
import { importStatement } from './input.ts'; const read = importStatement("import * as A from './a.ts'"); read !== null && 'bindings' in read && read.bindings[0]?.name; // 'A' — and `from: null`, the module importStatement("await import('./a.ts')"); // null — the function, not the declaration const wrong = importStatement("import A as * from 'x'"); wrong !== null && 'advice' in wrong; // true — "did you mean `import * as A from 'x'`?"
ImportStatement | MisreadImport | null