Skip to content

Commit

Permalink
BigInt type for Flow (#10091)
Browse files Browse the repository at this point in the history
* flow BigIntLiteralTypeAnnotation

* numericSeparator for flow test plugins

* fix flow tuple

* fix code review
  • Loading branch information
tanhauhau authored and nicolo-ribaudo committed Jul 3, 2019
1 parent cbb482e commit f588e4e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
37 changes: 29 additions & 8 deletions packages/babel-parser/src/plugins/flow.js
Expand Up @@ -1263,7 +1263,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
});

case tt.bracketL:
return this.flowParseTupleType();
this.state.noAnonFunctionType = false;
type = this.flowParseTupleType();
this.state.noAnonFunctionType = oldNoAnonFunctionType;
return type;

case tt.relational:
if (this.state.value === "<") {
Expand Down Expand Up @@ -1352,15 +1355,27 @@ export default (superClass: Class<Parser>): Class<Parser> =>
case tt.plusMin:
if (this.state.value === "-") {
this.next();
if (!this.match(tt.num)) {
this.unexpected(null, `Unexpected token, expected "number"`);
if (this.match(tt.num)) {
return this.parseLiteral(
-this.state.value,
"NumberLiteralTypeAnnotation",
node.start,
node.loc.start,
);
}

if (this.match(tt.bigint)) {
return this.parseLiteral(
-this.state.value,
"BigIntLiteralTypeAnnotation",
node.start,
node.loc.start,
);
}

return this.parseLiteral(
-this.state.value,
"NumberLiteralTypeAnnotation",
node.start,
node.loc.start,
this.unexpected(
null,
`Unexpected token, expected "number" or "bigint"`,
);
}

Expand All @@ -1371,6 +1386,12 @@ export default (superClass: Class<Parser>): Class<Parser> =>
"NumberLiteralTypeAnnotation",
);

case tt.bigint:
return this.parseLiteral(
this.state.value,
"BigIntLiteralTypeAnnotation",
);

case tt._void:
this.next();
return this.finishNode(node, "VoidTypeAnnotation");
Expand Down
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token, expected \"number\" (1:8)"
"throws": "Unexpected token, expected \"number\" or \"bigint\" (1:8)"
}
16 changes: 0 additions & 16 deletions scripts/tests/flow/flow_tests_whitelist.txt
Expand Up @@ -9,7 +9,6 @@
# Entries should be removed incrementally as the babel parser is improved.

JSX_invalid/migrated_0000.js
arrow_function/tuple_return_type.js
arrow_function_invalid/migrated_0002.js
async_await/migrated_0007.js
async_await/migrated_0020.js
Expand All @@ -26,22 +25,7 @@ private_class_properties/getter_duplicate.js
private_class_properties/setter_and_field.js
private_class_properties/setter_duplicate.js
types/member/reserved_words.js
types/bigint_literal/migrated_0000.js
types/bigint_literal/migrated_0002.js
types/bigint_literal/migrated_0003.js
types/bigint_literal/migrated_0004.js
types/bigint_literal/migrated_0005.js
types/bigint_literal/migrated_0006.js
types/bigint_literal/migrated_0007.js
types/bigint_literal/migrated_0008.js
types/bigint_literal/migrated_0009.js
class_method_kinds/polymorphic_getter.js
numbers/underscored_bin.js
numbers/underscored_float.js
numbers/underscored_float_whole.js
numbers/underscored_hex.js
numbers/underscored_number.js
numbers/underscored_oct.js
ES6/modules/migrated_0020.js
export_import_reserved_words/migrated_0003.js
export_statements/export_trailing_comma.js
1 change: 1 addition & 0 deletions scripts/tests/flow/run_babel_parser_flow_tests.js
Expand Up @@ -117,6 +117,7 @@ const options = {
"classPrivateProperties",
"classPrivateMethods",
"bigInt",
"numericSeparator",
],
sourceType: "module",
ranges: true,
Expand Down

0 comments on commit f588e4e

Please sign in to comment.