-
-
Notifications
You must be signed in to change notification settings - Fork 258
Add support for flow type spread #418
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type A = { | ||
...any, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
{ | ||
"type": "File", | ||
"start": 0, | ||
"end": 22, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 2 | ||
} | ||
}, | ||
"program": { | ||
"type": "Program", | ||
"start": 0, | ||
"end": 22, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 2 | ||
} | ||
}, | ||
"sourceType": "module", | ||
"body": [ | ||
{ | ||
"type": "TypeAlias", | ||
"start": 0, | ||
"end": 22, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 2 | ||
} | ||
}, | ||
"id": { | ||
"type": "Identifier", | ||
"start": 5, | ||
"end": 6, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 5 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 6 | ||
}, | ||
"identifierName": "A" | ||
}, | ||
"name": "A" | ||
}, | ||
"typeParameters": null, | ||
"right": { | ||
"type": "ObjectTypeAnnotation", | ||
"start": 9, | ||
"end": 21, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 9 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 1 | ||
} | ||
}, | ||
"callProperties": [], | ||
"properties": [ | ||
{ | ||
"type": "ObjectTypeSpreadProperty", | ||
"start": 12, | ||
"end": 19, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 1 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 8 | ||
} | ||
}, | ||
"argument": { | ||
"type": "AnyTypeAnnotation", | ||
"start": 15, | ||
"end": 18, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 4 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 7 | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"indexers": [], | ||
"exact": false | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
type A = { | ||
p: {}, | ||
...{}, | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not parse I think. Probably related to what @gabelevi wrote. At least flow is also throwing errors: http://astexplorer.net/#/gist/7703a4fb36053ce507e10d396c5f7d71/c2f5ba5c1048c1e8bade34bebccc16efa44d7367 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should parse. How are you testing? Gabe's comment is that parsePrimaryType is actually too restrictive. We also parse non-primary types in this position, like unions. E.g., There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh okay sorry. I see astexplorer uses flow 0.40 which supports it spreading only for Identifiers? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, we "reserved" the syntax in 0.40, but 0.42 extends support to all type syntax and adds support. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, PR for astexplorer hasn't been merged yet fkling/astexplorer#208 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But https://flowtype.org/try/ should work and it has an AST tab There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should see if we can setup greenkeeper or a bot to update the package + yarn @fkling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think felix is working on this. fkling/astexplorer#197 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
{ | ||
"type": "File", | ||
"start": 0, | ||
"end": 29, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 4, | ||
"column": 2 | ||
} | ||
}, | ||
"program": { | ||
"type": "Program", | ||
"start": 0, | ||
"end": 29, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 4, | ||
"column": 2 | ||
} | ||
}, | ||
"sourceType": "module", | ||
"body": [ | ||
{ | ||
"type": "TypeAlias", | ||
"start": 0, | ||
"end": 29, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 4, | ||
"column": 2 | ||
} | ||
}, | ||
"id": { | ||
"type": "Identifier", | ||
"start": 5, | ||
"end": 6, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 5 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 6 | ||
}, | ||
"identifierName": "A" | ||
}, | ||
"name": "A" | ||
}, | ||
"typeParameters": null, | ||
"right": { | ||
"type": "ObjectTypeAnnotation", | ||
"start": 9, | ||
"end": 28, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 9 | ||
}, | ||
"end": { | ||
"line": 4, | ||
"column": 1 | ||
} | ||
}, | ||
"callProperties": [], | ||
"properties": [ | ||
{ | ||
"type": "ObjectTypeProperty", | ||
"start": 12, | ||
"end": 18, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 1 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 7 | ||
} | ||
}, | ||
"key": { | ||
"type": "Identifier", | ||
"start": 12, | ||
"end": 13, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 1 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 2 | ||
}, | ||
"identifierName": "p" | ||
}, | ||
"name": "p" | ||
}, | ||
"value": { | ||
"type": "ObjectTypeAnnotation", | ||
"start": 15, | ||
"end": 17, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 4 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 6 | ||
} | ||
}, | ||
"callProperties": [], | ||
"properties": [], | ||
"indexers": [], | ||
"exact": false | ||
}, | ||
"optional": false, | ||
"static": false, | ||
"variance": null | ||
}, | ||
{ | ||
"type": "ObjectTypeSpreadProperty", | ||
"start": 20, | ||
"end": 26, | ||
"loc": { | ||
"start": { | ||
"line": 3, | ||
"column": 1 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 7 | ||
} | ||
}, | ||
"argument": { | ||
"type": "ObjectTypeAnnotation", | ||
"start": 23, | ||
"end": 25, | ||
"loc": { | ||
"start": { | ||
"line": 3, | ||
"column": 4 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 6 | ||
} | ||
}, | ||
"callProperties": [], | ||
"properties": [], | ||
"indexers": [], | ||
"exact": false | ||
} | ||
} | ||
], | ||
"indexers": [], | ||
"exact": false | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
interface A { | ||
...any, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"throws": "Spread operator cannnot appear in class or interface definitions (2:1)" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any
is also not allowed here it seems, flow is throwing an error. Seems to also happen for all primitive types:number, string, boolean, any, null, ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should parse. How are you testing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay was testing on astexplorer, which was a bad idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, no worries. Per your initial comment, the typing support is incomplete, but eventually we will also support spreading
string
(implicitly promotes toString
instance, which has no own properties).