Skip to content

Commit dbbb961

Browse files
author
Max Schaefer
committed
JavaScript: Accept let expressions with an object literal as their body.
1 parent 63ed569 commit dbbb961

File tree

3 files changed

+642
-348
lines changed

3 files changed

+642
-348
lines changed

javascript/extractor/src/com/semmle/jcorn/CustomParser.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,12 @@ protected Node parseLetExpression(Position startLoc, boolean maybeStatement) {
196196
this.expect(TokenType.parenR);
197197

198198
if (this.type == TokenType.braceL) {
199-
if (!maybeStatement)
200-
this.unexpected();
199+
if (!maybeStatement) {
200+
// must be the start of an object literal
201+
Expression body = this.parseObj(false, null);
202+
return this.finishNode(new LetExpression(new SourceLocation(startLoc), decl.getDeclarations(), body));
203+
}
204+
201205
BlockStatement body = this.parseBlock(false);
202206
return this.finishNode(new LetStatement(new SourceLocation(startLoc), decl.getDeclarations(), body));
203207
} else if (maybeStatement) {

javascript/extractor/tests/mozilla/input/letExpr.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ var x = 42, y = 19;
22

33
console.log(let (x = 23, y = 19) x + y);
44

5-
console.log(x - y);
5+
console.log(x - y);
6+
7+
JSON.stringify(let (x = 23, y = 19) { x: x, y: y});

0 commit comments

Comments
 (0)