Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Fixes SyntaxError position with flow optional type #65

Merged
merged 1 commit into from
Aug 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ pp.parseParenAndDistinguishExpression = function (startPos, startLoc, canBeArrow
if (first) {
first = false;
} else {
this.expect(tt.comma);
this.expect(tt.comma, refNeedsArrowPos.start || null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this just 0 b/c there's let refNeedsArrowPos = { start: 0 }; at 550?

Copy link
Member Author

@danez danez Jul 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is first triggered in the second iteration if (first) ... and refNeedsArrowPos is supplied to parseMaybeAssign on line 567 and this function might be changed it there.

if (this.match(tt.parenR) && this.hasPlugin("trailingFunctionCommas")) {
optionalCommaStart = this.state.start;
break;
Expand Down
6 changes: 3 additions & 3 deletions src/parser/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ pp.semicolon = function () {
};

// Expect a token of a given type. If found, consume it, otherwise,
// raise an unexpected token error.
// raise an unexpected token error at given pos.

pp.expect = function (type) {
return this.eat(type) || this.unexpected();
pp.expect = function (type, pos) {
return this.eat(type) || this.unexpected(pos);
};

// Raise an unexpected token error.
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/flow/optional-type/4/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const f = (...x?) => {}
153 changes: 153 additions & 0 deletions test/fixtures/flow/optional-type/4/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
{
"type": "File",
"start": 0,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
}
},
"program": {
"type": "Program",
"start": 0,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
}
},
"sourceType": "module",
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 6,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 23
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
}
},
"name": "f"
},
"init": {
"type": "ArrowFunctionExpression",
"start": 10,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 23
}
},
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "RestElement",
"start": 11,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 15
}
},
"argument": {
"type": "Identifier",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 15
}
},
"name": "x"
},
"optional": true
}
],
"body": {
"type": "BlockStatement",
"start": 21,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 23
}
},
"body": [],
"directives": []
}
}
}
],
"kind": "const"
}
],
"directives": []
}
}
1 change: 1 addition & 0 deletions test/fixtures/flow/optional-type/5/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a ? b : c ? d : e ? f : g ? h : i ? j : k ? l : m ? n : (o ? p : =);
3 changes: 3 additions & 0 deletions test/fixtures/flow/optional-type/5/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token (1:65)"
}