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
[Flow] Function predicate declaration #103
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a411e1e
[Flow] Function predicate declaration
panagosg7 502b996
[Flow] Minor tweaks and more examples to function predicates
panagosg7 d5782a9
[Flow] Porting master changes on function predicates
panagosg7 7c81009
[Flow] Clean-up and better message for function predicates
panagosg7 f972e80
[Flow] Adding abstract function predicate example
panagosg7 e42d60c
[Flow] Rearranging the `predicate` field to ease babel generator.
panagosg7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare function foo(x: mixed): boolean %checks(x !== null); |
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,226 @@ | ||
{ | ||
"type": "File", | ||
"start": 0, | ||
"end": 60, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 60 | ||
} | ||
}, | ||
"program": { | ||
"type": "Program", | ||
"start": 0, | ||
"end": 60, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 60 | ||
} | ||
}, | ||
"sourceType": "module", | ||
"body": [ | ||
{ | ||
"type": "DeclareFunction", | ||
"start": 0, | ||
"end": 60, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 60 | ||
} | ||
}, | ||
"id": { | ||
"type": "Identifier", | ||
"start": 17, | ||
"end": 59, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 17 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 59 | ||
}, | ||
"identifierName": "foo" | ||
}, | ||
"name": "foo", | ||
"typeAnnotation": { | ||
"type": "TypeAnnotation", | ||
"start": 20, | ||
"end": 59, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 20 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 59 | ||
} | ||
}, | ||
"typeAnnotation": { | ||
"type": "FunctionTypeAnnotation", | ||
"start": 20, | ||
"end": 59, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 20 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 59 | ||
} | ||
}, | ||
"typeParameters": null, | ||
"params": [ | ||
{ | ||
"type": "FunctionTypeParam", | ||
"start": 21, | ||
"end": 29, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 21 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 29 | ||
} | ||
}, | ||
"name": { | ||
"type": "Identifier", | ||
"start": 21, | ||
"end": 22, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 21 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 22 | ||
}, | ||
"identifierName": "x" | ||
}, | ||
"name": "x" | ||
}, | ||
"optional": false, | ||
"typeAnnotation": { | ||
"type": "MixedTypeAnnotation", | ||
"start": 24, | ||
"end": 29, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 24 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 29 | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"rest": null, | ||
"returnType": { | ||
"type": "BooleanTypeAnnotation", | ||
"start": 32, | ||
"end": 39, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 32 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 39 | ||
} | ||
} | ||
} | ||
}, | ||
"predicate": { | ||
"type": "DeclaredPredicate", | ||
"start": 40, | ||
"end": 59, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 40 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 59 | ||
} | ||
}, | ||
"expression": { | ||
"type": "BinaryExpression", | ||
"start": 48, | ||
"end": 58, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 48 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 58 | ||
} | ||
}, | ||
"left": { | ||
"type": "Identifier", | ||
"start": 48, | ||
"end": 49, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 48 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 49 | ||
}, | ||
"identifierName": "x" | ||
}, | ||
"name": "x" | ||
}, | ||
"operator": "!==", | ||
"right": { | ||
"type": "NullLiteral", | ||
"start": 54, | ||
"end": 58, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 54 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 58 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"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 @@ | ||
var f = (x: mixed): %checks => typeof x === "string"; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.state.inType
seems to be only necessary forthis.flowParseType()
, so maybe we could just do this two lines in the else branch? Then the reset only has to happen there either.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.
It looks like
this.state.inType
needs to betrue
forthis.expect(tt.colon)
to succeed (I tried to move it further down, but other tests failed). So,oldInType
needs to be recorded in the beginning in order to be restored beforethis.flowParsePredicate()
is called (note thatflowParsePredicate
possibly parses expressions).Bottom line is I wasn't able to perform the optimization you suggested.