summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartok <martok@martoks-place.de>2022-06-17 21:02:38 +0200
committerMartok <martok@martoks-place.de>2022-06-17 21:02:38 +0200
commita492c5bdb9802cf235ad69b879dd50aee6105c5f (patch)
tree9ee87624c5be943494a41619bdfcd89956acae54
parent5d0bc8e811c9a4fb206dbda9667e07c970fd0a26 (diff)
downloaduxp-a492c5bdb9802cf235ad69b879dd50aee6105c5f.tar.gz
Issue #1918 - m-c 1353690: Properly exclude |await| from consideration as a |let| variable name in async functions, so that a newline between the two separates them into two distinct expressions.
-rw-r--r--js/src/frontend/Parser.cpp5
-rw-r--r--js/src/tests/test262/local/let-newline-await-in-async-function.js18
-rw-r--r--js/src/tests/test262/local/let-newline-await-in-normal-function.js20
3 files changed, 43 insertions, 0 deletions
diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp
index 1969628f38..f2d87f52be 100644
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -7348,6 +7348,11 @@ Parser<ParseHandler>::nextTokenContinuesLetDeclaration(TokenKind next, YieldHand
if (next == TOK_YIELD)
return yieldHandling == YieldIsName;
+ // Somewhat similar logic applies for "await", except that it's not tracked
+ // with an AwaitHandling argument.
+ if (next == TOK_AWAIT)
+ return !awaitIsKeyword();
+
// Otherwise a let declaration must have a name.
if (TokenKindIsPossibleIdentifier(next)) {
// A "let" edge case deserves special comment. Consider this:
diff --git a/js/src/tests/test262/local/let-newline-await-in-async-function.js b/js/src/tests/test262/local/let-newline-await-in-async-function.js
new file mode 100644
index 0000000000..c43a5b2745
--- /dev/null
+++ b/js/src/tests/test262/local/let-newline-await-in-async-function.js
@@ -0,0 +1,18 @@
+// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+author: Jeff Walden <jwalden+code@mit.edu>
+esid: sec-let-and-const-declarations
+description: >
+ |await| is excluded from LexicalDeclaration by grammar parameter, in
+ AsyncFunction. Therefore |let| followed by |await| inside AsyncFunction is
+ an ASI opportunity, and this code must parse without error.
+---*/
+
+async function f() {
+ let
+ await 0;
+}
+
+reportCompare(true, f instanceof Function);
diff --git a/js/src/tests/test262/local/let-newline-await-in-normal-function.js b/js/src/tests/test262/local/let-newline-await-in-normal-function.js
new file mode 100644
index 0000000000..f49f9ea528
--- /dev/null
+++ b/js/src/tests/test262/local/let-newline-await-in-normal-function.js
@@ -0,0 +1,20 @@
+// |reftest| error:SyntaxError
+// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+author: Jeff Walden <jwalden+code@mit.edu>
+esid: sec-let-and-const-declarations
+description: >
+ Outside AsyncFunction, |await| is a perfectly cromulent LexicalDeclaration
+ variable name. Therefore ASI doesn't apply, and so the |0| where a |=| was
+ expected is a syntax error.
+negative:
+ phase: early
+ type: SyntaxError
+---*/
+
+function f() {
+ let
+ await 0;
+}