Allow keywords to be used in type annotations (#9184)

This commit is contained in:
Daniel Tschinder 2018-12-15 12:51:24 -08:00 committed by GitHub
parent 3c8e15dbc1
commit 5cb38995c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 143 additions and 3 deletions

View File

@ -1384,6 +1384,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
default:
if (this.state.type.keyword === "typeof") {
return this.flowParseTypeofType();
} else if (this.state.type.keyword) {
const label = this.state.type.label;
this.next();
return super.createIdentifier(node, label);
}
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:23)"
"throws": "Unexpected token, expected \";\" (1:27)"
}

View File

@ -0,0 +1 @@
function foo(a:function) {}

View 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": []
}
}

View File

@ -26,7 +26,6 @@ decorators/migrated_0003.js
decorators/migrated_0007.js
private_class_properties/multiple.js
private_class_properties/super.js
types/annotations/migrated_0001.js
types/annotations/void_is_reserved_param.js
types/member/reserved_words.js
types/parameter_defaults/migrated_0032.js
@ -37,4 +36,3 @@ numbers/underscored_float_whole.js
numbers/underscored_hex.js
numbers/underscored_number.js
numbers/underscored_oct.js
types/annotations_in_comments/migrated_0001.js