swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
31.15k stars 1.23k forks source link

Await is not a keyword in script mode #8473

Open Austaras opened 10 months ago

Austaras commented 10 months ago

Describe the bug

SWC would still treat input as top level await enabled even if source is script.

Input code

var await = () => {

}

await(2)

Config

No response

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.3.100&code=H4sIAAAAAAAAAytLLFJILE%2FMLFGwVdDQVLC1U6jm4qrl4gKLaRhpAgBOvX7AIAAAAA%3D%3D&config=H4sIAAAAAAAAA1WPSw7DIBBD9zkFmnW33fQOPQSik4iInzCViqLcvUAgbXbYfmOLbRKCVih6iK08iwgyguOpi4PskvwUh1hZCRV1SHQb6YoazdKAm7UfCSUZF07tCveOk%2FEePPDuWe30nP8HlbchMnAFKyrdYvg6N%2FVJsv71bmH%2FSMqhqtpmvVtBP3Isnu2k8RznR%2Ff%2BBaNtxkwaAQAA

SWC Info output

No response

Expected behavior

Should not error.

Actual behavior

x top level await is only allowed in module ,-[input.js:2:1] 2 | 3 | } 4 | 5 | await(2) : ^^^^^ `----

Version

latest

Additional context

No response

ParadeTo commented 7 months ago

Some JS parser also treat it as keyword, for example "https://astexplorer.net/"