Permit %%placeholder%% in left-hand-side of a let declaration (#12725)

* Permit %%placeholder%% in left-hand-side of a let declaration

* Test that "let" followed by modulo is still treated as an identifier

* More tests for edge-case handling of "let" with placeholders enabled
This commit is contained in:
Stuart Cook
2021-02-02 12:00:21 +11:00
committed by GitHub
parent ecfe20395b
commit 20664a430e
16 changed files with 375 additions and 0 deletions

View File

@@ -150,6 +150,28 @@ export default (superClass: Class<Parser>): Class<Parser> =>
* parser/statement.js *
* ============================================================ */
isLet(context: ?string): boolean {
if (super.isLet(context)) {
return true;
}
// Replicate the original checks that lead to looking ahead for an
// identifier.
if (!this.isContextual("let")) {
return false;
}
if (context) return false;
// Accept "let %%" as the start of "let %%placeholder%%", as though the
// placeholder were an identifier.
const nextToken = this.lookahead();
if (nextToken.type === tt.placeholder) {
return true;
}
return false;
}
verifyBreakContinue(node: N.BreakStatement | N.ContinueStatement) {
if (node.label && node.label.type === "Placeholder") return;
super.verifyBreakContinue(...arguments);