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

Support top-level await #593

Merged
merged 1 commit into from
Oct 28, 2022
Merged

Support top-level await #593

merged 1 commit into from
Oct 28, 2022

Conversation

DamienCassou
Copy link
Contributor

@DamienCassou DamienCassou marked this pull request as ready for review October 28, 2022 09:45
@dgutov dgutov merged commit a297ec2 into mooz:master Oct 28, 2022
@dgutov
Copy link
Collaborator

dgutov commented Oct 28, 2022

Thanks!

@DamienCassou DamienCassou deleted the top-level-await branch October 28, 2022 20:04
@jordigh
Copy link

jordigh commented Nov 25, 2022

Hm, this only works inside ECMAscript modules, though. It should still be an error inside CommonJS files. I can't see anything in js2-mode about distinguishing the two kinds of javascript files, though.

@DamienCassou
Copy link
Contributor Author

@jordigh My PR was only about the syntactical aspect of the problem. We could probably introduce some semantic check as well as JS2 as some already. My opinion is that semantic validation
shouldn't be the responsibility of a major mode but that's just my opinion. If you care you might want to open an issue.

@jordigh
Copy link

jordigh commented Nov 28, 2022

I mean, it's a syntax error if the file isn't an ECMAscript module. It would be like saying that new is a valid keyword in a C file because you don't have a mechanism to tell C and C++ files apart.

@dgutov
Copy link
Collaborator

dgutov commented Nov 28, 2022

Is there a way to distinguish at the lexical or the major mode level?

@jordigh
Copy link

jordigh commented Nov 30, 2022

No, unfortunately, in order to be able to tell if a file is an ESM file or a CJS file you have to look at either the filename (.cjs is guaranteed CJS and .mjs is guaranteed ESM), or you have to parse the nearest package.json to see what is the correct file type.

@dgutov
Copy link
Collaborator

dgutov commented Nov 30, 2022

Someone motivated could add that check (which would look at the extension, and then also look around for package.json and its contents). As long as that won't bring false negatives in the end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants