BigInt type for Flow (#10091)

* flow BigIntLiteralTypeAnnotation

* numericSeparator for flow test plugins

* fix flow tuple

* fix code review
This commit is contained in:
Tan Li Hau 2019-07-03 22:48:46 +08:00 committed by Nicolò Ribaudo
parent cbb482e2f9
commit f588e4ec47
4 changed files with 31 additions and 25 deletions

View File

@ -1263,7 +1263,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}); });
case tt.bracketL: case tt.bracketL:
return this.flowParseTupleType(); this.state.noAnonFunctionType = false;
type = this.flowParseTupleType();
this.state.noAnonFunctionType = oldNoAnonFunctionType;
return type;
case tt.relational: case tt.relational:
if (this.state.value === "<") { if (this.state.value === "<") {
@ -1352,15 +1355,27 @@ export default (superClass: Class<Parser>): Class<Parser> =>
case tt.plusMin: case tt.plusMin:
if (this.state.value === "-") { if (this.state.value === "-") {
this.next(); this.next();
if (!this.match(tt.num)) { if (this.match(tt.num)) {
this.unexpected(null, `Unexpected token, expected "number"`); return this.parseLiteral(
-this.state.value,
"NumberLiteralTypeAnnotation",
node.start,
node.loc.start,
);
} }
return this.parseLiteral( if (this.match(tt.bigint)) {
-this.state.value, return this.parseLiteral(
"NumberLiteralTypeAnnotation", -this.state.value,
node.start, "BigIntLiteralTypeAnnotation",
node.loc.start, node.start,
node.loc.start,
);
}
this.unexpected(
null,
`Unexpected token, expected "number" or "bigint"`,
); );
} }
@ -1371,6 +1386,12 @@ export default (superClass: Class<Parser>): Class<Parser> =>
"NumberLiteralTypeAnnotation", "NumberLiteralTypeAnnotation",
); );
case tt.bigint:
return this.parseLiteral(
this.state.value,
"BigIntLiteralTypeAnnotation",
);
case tt._void: case tt._void:
this.next(); this.next();
return this.finishNode(node, "VoidTypeAnnotation"); return this.finishNode(node, "VoidTypeAnnotation");

View File

@ -1,3 +1,3 @@
{ {
"throws": "Unexpected token, expected \"number\" (1:8)" "throws": "Unexpected token, expected \"number\" or \"bigint\" (1:8)"
} }

View File

@ -9,7 +9,6 @@
# Entries should be removed incrementally as the babel parser is improved. # Entries should be removed incrementally as the babel parser is improved.
JSX_invalid/migrated_0000.js JSX_invalid/migrated_0000.js
arrow_function/tuple_return_type.js
arrow_function_invalid/migrated_0002.js arrow_function_invalid/migrated_0002.js
async_await/migrated_0007.js async_await/migrated_0007.js
async_await/migrated_0020.js async_await/migrated_0020.js
@ -26,22 +25,7 @@ private_class_properties/getter_duplicate.js
private_class_properties/setter_and_field.js private_class_properties/setter_and_field.js
private_class_properties/setter_duplicate.js private_class_properties/setter_duplicate.js
types/member/reserved_words.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 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 ES6/modules/migrated_0020.js
export_import_reserved_words/migrated_0003.js export_import_reserved_words/migrated_0003.js
export_statements/export_trailing_comma.js export_statements/export_trailing_comma.js

View File

@ -117,6 +117,7 @@ const options = {
"classPrivateProperties", "classPrivateProperties",
"classPrivateMethods", "classPrivateMethods",
"bigInt", "bigInt",
"numericSeparator",
], ],
sourceType: "module", sourceType: "module",
ranges: true, ranges: true,