quick-lint / quick-lint-js

quick-lint-js finds bugs in JavaScript programs
https://quick-lint-js.com
GNU General Public License v3.0
1.52k stars 191 forks source link

Use of undeclared variable `await` #1220

Open coderaiser opened 3 months ago

coderaiser commented 3 months ago

Just trapped on couple issues:

image

Acorn:

image

ESPree:

image

No error:

image

In chrome:

image

Babel:

image
strager commented 3 months ago

() => await; is legal in script mode. https://astexplorer.net/#/gist/ce7f1c8465166e5dd8923f21a71e6c5a/ca4992a4e78c2dfe0dbda6ade70d4700e7ce7efc quick-lint-js currently permits code which is legal in either script or module mode. It would be nice to have a better diagnostic like "missing expression after await and missing 'async' on function" though.

The story is similar for const await = 5; which is also legal in script mode. https://astexplorer.net/#/gist/ce7f1c8465166e5dd8923f21a71e6c5a/f4af94e61dfc6f2dd6bd6366074563db10196b73

What do you think quick-lint-js should do for these two examples?

coderaiser commented 3 months ago

I think would be great to handle them as an error by default as other parsers and runtimes since no one will write such code nowadays or provide an option to switch between script and module.