-
Notifications
You must be signed in to change notification settings - Fork 853
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
Javascript parser does not support top-level await #7408
Comments
Please check/test #7417. There is also a nightly build available from the check page or directly: https://github.com/apache/netbeans/suites/24280981849/artifacts/1549006976 |
Thanks, the dev build improves the situation but it is still incomplete as it makes the validity of the |
The language requirement is, that top level await is allowed for modules. The NB implementation currently guesses whether the file should be parsed as a module based on the import and export keywords. A work around might be to add support for the But before doing this: Is there a real world example for JS modules without export/import? |
I'll start by saying I may be guilty of mistaking "Firefox doesn't prevent you doing it" for "valid" in terms of the language. I've been going off the MDN pages on Regarding The only real-world example I can speak on is my own codebase, which I'm in the midst of rewriting (thus how I washed up here). Some time ago I adapted my existing class-loader code to employ dynamic
Obviously this is a side-effect, which modules are discouraged from having, but not using It's useful that Would a warning, rather than error, condition be a compromise worth considering? (In context where |
I looked a bit longer into this and my take on this that it can't be done without very ugly compromises. I tried to add a variant to the parset, that allows callers to allow top-level-await also in script context. However, that breaks in subtle ways. consider this: var await = 3; If parsed as a module this is invalid code as the keyword The definition can be found a bit more wordy here (Note 1): https://tc39.es/ecma262/#sec-async-function-definitions The TL;DR version is, that you can't parse a JS file without knowing how it is going to be used, because grammar depends on that. That becomes even more fun, when the same file is used as script and module. Using different extensions for scripts and modules as introduced by node looks like a sane decision to escape this dilemma, which I added to the PR. |
Blimey. I'd never have expected that the above example would be permissible in any context! Makes no sense to me, but the spec per your link is clear enough. Given that the proper Anyway I can't fault your conclusion and thanks for your work on this. I've benefited from this "looseness" in the definition of a module up til now, but I do hope it gets tightened up a little (based on extension does seem a sensible method) eventually so the whole ecosystem can coalesce on it. |
Apache NetBeans version
Apache NetBeans 21
What happened
It's now possible to use
await
in top-level code in JavaScript module context (which may be a normal JS file loaded via dynamicinclude()
call). However NetBeans's Javascript parser interprets such a statement as an error.Language / Project Type / NetBeans Component
Editor Javascript parser (PHP project)
How to reproduce
await
statement in the file, e.g.Did this work correctly in an earlier version?
No / Don't know
Operating System
Gentoo Linux amd64
JDK
openjdk-21.0.3_p9 Prebuilt Java JDK binaries provided by Eclipse Temurin
Apache NetBeans packaging
Apache NetBeans binary zip
Anything else
No response
Are you willing to submit a pull request?
No
The text was updated successfully, but these errors were encountered: