Allow keywords to be used in type annotations (#9184)
This commit is contained in:
parent
3c8e15dbc1
commit
5cb38995c0
@ -1384,6 +1384,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
default:
|
default:
|
||||||
if (this.state.type.keyword === "typeof") {
|
if (this.state.type.keyword === "typeof") {
|
||||||
return this.flowParseTypeofType();
|
return this.flowParseTypeofType();
|
||||||
|
} else if (this.state.type.keyword) {
|
||||||
|
const label = this.state.type.label;
|
||||||
|
this.next();
|
||||||
|
return super.createIdentifier(node, label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"throws": "Unexpected token (1:23)"
|
"throws": "Unexpected token, expected \";\" (1:27)"
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/babel-parser/test/fixtures/flow/type-annotations/function-is-valid-type/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/flow/type-annotations/function-is-valid-type/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
function foo(a:function) {}
|
||||||
137
packages/babel-parser/test/fixtures/flow/type-annotations/function-is-valid-type/output.json
vendored
Normal file
137
packages/babel-parser/test/fixtures/flow/type-annotations/function-is-valid-type/output.json
vendored
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
{
|
||||||
|
"type": "File",
|
||||||
|
"start": 0,
|
||||||
|
"end": 27,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 27
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"program": {
|
||||||
|
"type": "Program",
|
||||||
|
"start": 0,
|
||||||
|
"end": 27,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 27
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"sourceType": "module",
|
||||||
|
"interpreter": null,
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "FunctionDeclaration",
|
||||||
|
"start": 0,
|
||||||
|
"end": 27,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 27
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 9,
|
||||||
|
"end": 12,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 9
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 12
|
||||||
|
},
|
||||||
|
"identifierName": "foo"
|
||||||
|
},
|
||||||
|
"name": "foo"
|
||||||
|
},
|
||||||
|
"generator": false,
|
||||||
|
"async": false,
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 13,
|
||||||
|
"end": 23,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 13
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 23
|
||||||
|
},
|
||||||
|
"identifierName": "a"
|
||||||
|
},
|
||||||
|
"name": "a",
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TypeAnnotation",
|
||||||
|
"start": 14,
|
||||||
|
"end": 23,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 14
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 23
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 15,
|
||||||
|
"end": 23,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 15
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 23
|
||||||
|
},
|
||||||
|
"identifierName": "function"
|
||||||
|
},
|
||||||
|
"name": "function"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"body": {
|
||||||
|
"type": "BlockStatement",
|
||||||
|
"start": 25,
|
||||||
|
"end": 27,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 25
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 27
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"body": [],
|
||||||
|
"directives": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"directives": []
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -26,7 +26,6 @@ decorators/migrated_0003.js
|
|||||||
decorators/migrated_0007.js
|
decorators/migrated_0007.js
|
||||||
private_class_properties/multiple.js
|
private_class_properties/multiple.js
|
||||||
private_class_properties/super.js
|
private_class_properties/super.js
|
||||||
types/annotations/migrated_0001.js
|
|
||||||
types/annotations/void_is_reserved_param.js
|
types/annotations/void_is_reserved_param.js
|
||||||
types/member/reserved_words.js
|
types/member/reserved_words.js
|
||||||
types/parameter_defaults/migrated_0032.js
|
types/parameter_defaults/migrated_0032.js
|
||||||
@ -37,4 +36,3 @@ numbers/underscored_float_whole.js
|
|||||||
numbers/underscored_hex.js
|
numbers/underscored_hex.js
|
||||||
numbers/underscored_number.js
|
numbers/underscored_number.js
|
||||||
numbers/underscored_oct.js
|
numbers/underscored_oct.js
|
||||||
types/annotations_in_comments/migrated_0001.js
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user