This repository has been archived by the owner on May 19, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix flow plugin when flow+arrow+spread used together
The fix includes creating a new method on the parser called `parseArrow`. This new function by default only checks if current position matches an arrow. If it does returns the `node` otherwise `undefined`. The flow plugin can then extend this function and correctly parse the typeAnnotation and add it to the node. With this change, in the flow plugin there is no need anymore to extend `parseParenAndDistinguishExpression` and the arrow handling in `parseParenItem` could also be removed, because it is all handled now in `parseArrow`. Some existing tests were failing, because `extra->parentesized` is now missing, but this is correct as it is now inline with parsing without flow annotation. No extra is added for arrow function without type annotations. In the expression-parser `this.next()` was replaced by a more specific `this.expect(tt.parenL)`.
- Loading branch information
Showing
13 changed files
with
793 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
( ...props: SomeType ) : ?ReturnType => ( 3 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
{ | ||
"type": "File", | ||
"start": 0, | ||
"end": 46, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 46 | ||
} | ||
}, | ||
"program": { | ||
"type": "Program", | ||
"start": 0, | ||
"end": 46, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 46 | ||
} | ||
}, | ||
"sourceType": "module", | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start": 0, | ||
"end": 46, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 46 | ||
} | ||
}, | ||
"expression": { | ||
"type": "ArrowFunctionExpression", | ||
"start": 0, | ||
"end": 45, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 45 | ||
} | ||
}, | ||
"returnType": { | ||
"type": "TypeAnnotation", | ||
"start": 23, | ||
"end": 36, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 23 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 36 | ||
} | ||
}, | ||
"typeAnnotation": { | ||
"type": "NullableTypeAnnotation", | ||
"start": 25, | ||
"end": 36, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 25 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 36 | ||
} | ||
}, | ||
"typeAnnotation": { | ||
"type": "GenericTypeAnnotation", | ||
"start": 26, | ||
"end": 36, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 26 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 36 | ||
} | ||
}, | ||
"typeParameters": null, | ||
"id": { | ||
"type": "Identifier", | ||
"start": 26, | ||
"end": 36, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 26 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 36 | ||
} | ||
}, | ||
"name": "ReturnType" | ||
} | ||
} | ||
} | ||
}, | ||
"id": null, | ||
"generator": false, | ||
"expression": true, | ||
"async": false, | ||
"params": [ | ||
{ | ||
"type": "RestElement", | ||
"start": 2, | ||
"end": 10, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 2 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 10 | ||
} | ||
}, | ||
"argument": { | ||
"type": "Identifier", | ||
"start": 5, | ||
"end": 10, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 5 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 10 | ||
} | ||
}, | ||
"name": "props" | ||
}, | ||
"typeAnnotation": { | ||
"type": "TypeAnnotation", | ||
"start": 10, | ||
"end": 20, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 10 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 20 | ||
} | ||
}, | ||
"typeAnnotation": { | ||
"type": "GenericTypeAnnotation", | ||
"start": 12, | ||
"end": 20, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 12 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 20 | ||
} | ||
}, | ||
"typeParameters": null, | ||
"id": { | ||
"type": "Identifier", | ||
"start": 12, | ||
"end": 20, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 12 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 20 | ||
} | ||
}, | ||
"name": "SomeType" | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"body": { | ||
"type": "NumericLiteral", | ||
"start": 42, | ||
"end": 43, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 42 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 43 | ||
} | ||
}, | ||
"extra": { | ||
"rawValue": 3, | ||
"raw": "3", | ||
"parenthesized": true, | ||
"parenStart": 40 | ||
}, | ||
"value": 3 | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default (...modifiers): Array<string> => {}; |
Oops, something went wrong.