Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 88be67a

Browse files
author
Max Schaefer
committed
JavaScript: Add support for for-each-in comprehensions.
1 parent d3ae295 commit 88be67a

5 files changed

Lines changed: 1356 additions & 1099 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,17 @@ protected ComprehensionExpression parseComprehension(Position startLoc, boolean
274274
List<ComprehensionBlock> blocks = new ArrayList<ComprehensionBlock>();
275275
while (this.type == TokenType._for) {
276276
SourceLocation blockStart = new SourceLocation(this.startLoc);
277+
boolean of = false;
277278
this.next();
279+
if (this.eatContextual("each"))
280+
of = true;
278281
this.expect(TokenType.parenL);
279282
Expression left = this.parseBindingAtom();
280283
this.checkLVal(left, true, null);
281-
boolean of;
282284
if (this.eatContextual("of")) {
283285
of = true;
284286
} else {
285287
this.expect(TokenType._in);
286-
of = false;
287288
}
288289
Expression right = this.parseExpression(false, null);
289290
this.expect(TokenType.parenR);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[for (year of years) if (year > 2000) year];
22
year;
33
[for (i of numbers) for (j of letters) i+j];
4-
[for (i of numbers) for (j of letters) if (i<j) i+j];
4+
[for (i of numbers) for (j of letters) if (i<j) i+j];
5+
[for each (i in numbers) i];

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ year;
33
(for (i of numbers) for (j of letters) i+j);
44
(for (i of numbers) for (j of letters) if (i<j) i+j);
55
(x.p for (x in xs));
6+
(x.p for each (x in xs));

0 commit comments

Comments
 (0)