Skip to content

Commit

Permalink
Comprehension fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohnson committed Sep 25, 2017
1 parent 97109a6 commit eaa42cd
Show file tree
Hide file tree
Showing 4 changed files with 373 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -1100,10 +1100,10 @@ pp.parseObj = function (isPattern, refShorthandDefaultPos) {
this.hasPlugin("enhancedComprehension") &&
(this.match(tt._for) || this.match(tt._case))
) {
if (isPattern) {
this.unexpected(null, "Comprehensions are illegal in patterns.");
}
if (this.lookahead().type !== tt.colon) {
if (isPattern) {
this.unexpected(null, "Comprehensions are illegal in patterns.");
}
node.properties.push(this.parseSomeComprehension());
hasComprehension = true;
continue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if true: {
for elem e in arr: e
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
{
"type": "File",
"start": 0,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "IfStatement",
"start": 0,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"test": {
"type": "BooleanLiteral",
"start": 3,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 7
}
},
"value": true
},
"consequent": {
"type": "BlockStatement",
"start": 7,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 3,
"column": 1
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 9,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 3,
"column": 1
}
},
"expression": {
"type": "ObjectComprehension",
"start": 9,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 3,
"column": 1
}
},
"properties": [],
"loop": {
"type": "ForInArrayStatement",
"start": 13,
"end": 33,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 22
}
},
"elem": {
"type": "Identifier",
"start": 22,
"end": 23,
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 12
},
"identifierName": "e"
},
"name": "e"
},
"body": {
"type": "ExpressionStatement",
"start": 32,
"end": 33,
"loc": {
"start": {
"line": 2,
"column": 21
},
"end": {
"line": 2,
"column": 22
}
},
"expression": {
"type": "Identifier",
"start": 32,
"end": 33,
"loc": {
"start": {
"line": 2,
"column": 21
},
"end": {
"line": 2,
"column": 22
},
"identifierName": "e"
},
"name": "e"
}
},
"array": {
"type": "Identifier",
"start": 27,
"end": 30,
"loc": {
"start": {
"line": 2,
"column": 16
},
"end": {
"line": 2,
"column": 19
},
"identifierName": "arr"
},
"name": "arr"
}
}
}
}
],
"directives": [],
"extra": {
"curly": false
}
},
"alternate": null
}
],
"directives": []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
{
"type": "File",
"start": 0,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "IfStatement",
"start": 0,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"test": {
"type": "BooleanLiteral",
"start": 3,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 7
}
},
"value": true
},
"consequent": {
"type": "BlockStatement",
"start": 9,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 3,
"column": 1
}
},
"body": [
{
"type": "ForInArrayStatement",
"start": 13,
"end": 33,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 22
}
},
"elem": {
"type": "Identifier",
"start": 22,
"end": 23,
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 12
},
"identifierName": "e"
},
"name": "e"
},
"body": {
"type": "ExpressionStatement",
"start": 32,
"end": 33,
"loc": {
"start": {
"line": 2,
"column": 21
},
"end": {
"line": 2,
"column": 22
}
},
"expression": {
"type": "Identifier",
"start": 32,
"end": 33,
"loc": {
"start": {
"line": 2,
"column": 21
},
"end": {
"line": 2,
"column": 22
},
"identifierName": "e"
},
"name": "e"
}
},
"array": {
"type": "Identifier",
"start": 27,
"end": 30,
"loc": {
"start": {
"line": 2,
"column": 16
},
"end": {
"line": 2,
"column": 19
},
"identifierName": "arr"
},
"name": "arr"
}
}
],
"directives": [],
"extra": {
"curly": true
}
},
"alternate": null
}
],
"directives": []
}
}

0 comments on commit eaa42cd

Please sign in to comment.