Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigInt type for Flow #10091

Merged
merged 4 commits into from Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 27 additions & 9 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,16 +1355,25 @@ 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,
);
}

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,
);
}

this.unexpected(null, `Unexpected token, expected "number"`);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
this.unexpected(null, `Unexpected token, expected "number"`);
this.unexpected(null, `Unexpected token, expected "number" or "bigint"`);

}

this.unexpected();
Expand All @@ -1371,6 +1383,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
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 @@ -27,22 +26,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