Skip to content

parser: ModuleKind::Unambiguous does not allow Top-level await #15541

@sapphi-red

Description

@sapphi-red

await new Promise(resolve => {}) cannot be parsed with ModuleKind::Unambiguous.
This is allowed by babel.

Babel REPL (strict is enabled, so that means it's parsing in module mode)

Related code:

if source_type.is_unambiguous() {
program.source_type = if module_record.has_module_syntax {
source_type.with_module(true)
} else {
source_type.with_script(true)
};
}

(we may need to add a separate flag for TLA as whether TLA is a module syntax can be controversial)

tsc has some logic to reparse https://github.com/microsoft/TypeScript/blob/efca03ffed10dccede4fbc8dd8a624374e5424d9/src/compiler/parser.ts#L1862
#15494 (review)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions