Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: await + 0 or await () become await 0 in strict mode #1296

Open
p51lee opened this issue Nov 7, 2022 · 2 comments
Open

[Bug]: await + 0 or await () become await 0 in strict mode #1296

p51lee opened this issue Nov 7, 2022 · 2 comments
Labels
bug parser Issue in the parse step

Comments

@p51lee
Copy link

p51lee commented Nov 7, 2022

Bug report

Version (complete output of terser -V or specific git commit)

$ terser -V
terser 5.15.1

Complete CLI command or minify() options used
I turned off the unsafe option.

$ terser input.js -c unsafe=false

terser input

"use strict";
await + 0;

or

"use strict";
await ( ) ;

terser output or error

"use strict";await 0;

Expected result
Input codes throw ReferenceError:

$ node -e '"use strict"; await + 0;'
ReferenceError: await is not defined
    at [eval]:1:1
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:313:38)
    at node:internal/process/execution:79:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:78:60)
    at node:internal/main/eval_string:28:3

Node.js v18.11.0

$ node -e '"use strict"; await ( ) ;'
ReferenceError: await is not defined
...

but output code throws SyntaxError:

$ node -e '"use strict"; await 0 ;'
[eval]:1
"use strict"; await 0 ;
              ^^^^^

SyntaxError: await is only valid in async functions and the top level bodies of modules
    at new Script (node:vm:100:7)
    at createScript (node:vm:265:10)
    at Object.runInThisContext (node:vm:313:10)
    at node:internal/process/execution:79:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:78:60)
    at node:internal/main/eval_string:28:3

Node.js v18.11.0
@fabiosantoscode
Copy link
Collaborator

I'm not even sure what the expected behavior is in the top level.

await ( ) is clearly not an await expression, it would only be reasonable to mix it up with a function call.

But for await + 0 or await ( 0 ) I think Terser needs to know the context of the code it's looking at.

Terser might be looking at module code, or not, and those await constructs mean different things in those contexts.

@fabiosantoscode
Copy link
Collaborator

I think the way I'll solve this is by allowing await on the top-level, at least by default, that is to assume the source code is an ES module for the case of await.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug parser Issue in the parse step
Projects
None yet
Development

No branches or pull requests

2 participants