-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
module: correctly detect top-level await in ambiguous contexts #58646
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #58646 +/- ##
==========================================
+ Coverage 90.10% 90.11% +0.01%
==========================================
Files 640 640
Lines 188493 188431 -62
Branches 36971 36965 -6
==========================================
- Hits 169843 169808 -35
+ Misses 11358 11342 -16
+ Partials 7292 7281 -11
🚀 New features to boost your workflow:
|
src/node_contextify.cc
Outdated
std::array<std::string_view, 2>{// example: `func(await 1);` | ||
"missing ) after argument list", | ||
// example: `if(await 1)` | ||
"SyntaxError: Unexpected"}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did the linter/formatter format the code this way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but now that you mention it, it's a weird format.
I've changed the comment's position.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jasnell
Could you take another look when you have a moment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some tests to ensure that unrelated errors stays the same? For example, when it's const foo bar
(which is supposed to throw SyntaxError: Unexpected identifier 'bar'
) or console.log('PI: ' Math.PI);
(which is supposed throw missing ) after argument list
).
I added several tests to confirm that unrelated errors are not affected by top-level await. |
test/es-module/test-esm-tla-syntax-errors-not-recognized-as-tla-error.mjs
Outdated
Show resolved
Hide resolved
…a-error.mjs Co-authored-by: Joyee Cheung <joyeec9h3@gmail.com>
Fixes: #58331
Many syntax errors are incorrectly treated as requiring ESM recompilation, but since they can't be clearly distinguished from top-level await-related errors, the current fix ends up handling them together.
From what I can tell by looking at the issues reported on V8, this appears to be a problem on the V8 side, so I will see if a fix can be made there.
https://issues.chromium.org/issues/40070895#comment1
That said, this patch will be necessary until the issue is resolved in V8.