Merge pull request #705 from babel/flow-declare-var-primitive

Add allowPrimitiveOverride option to flowParseTypeAnnotatableIdentifier
This commit is contained in:
Brian Ng 2017-08-29 21:19:20 -05:00 committed by GitHub
commit 0beaf4d54e
3 changed files with 106 additions and 3 deletions

View File

@ -180,7 +180,9 @@ export default (superClass: Class<Parser>): Class<Parser> =>
node: N.FlowDeclareVariable,
): N.FlowDeclareVariable {
this.next();
node.id = this.flowParseTypeAnnotatableIdentifier();
node.id = this.flowParseTypeAnnotatableIdentifier(
/*allowPrimitiveOverride*/ true,
);
this.semicolon();
return this.finishNode(node, "DeclareVariable");
}
@ -1145,8 +1147,12 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return this.finishNode(node, "TypeAnnotation");
}
flowParseTypeAnnotatableIdentifier(): N.Identifier {
const ident = this.flowParseRestrictedIdentifier();
flowParseTypeAnnotatableIdentifier(
allowPrimitiveOverride?: boolean,
): N.Identifier {
const ident = allowPrimitiveOverride
? this.parseIdentifier()
: this.flowParseRestrictedIdentifier();
if (this.match(tt.colon)) {
ident.typeAnnotation = this.flowParseTypeAnnotation();
this.finishNode(ident, ident.type);

View File

@ -0,0 +1 @@
declare var string: any;

View File

@ -0,0 +1,96 @@
{
"type": "File",
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 24
}
},
"program": {
"type": "Program",
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 24
}
},
"sourceType": "module",
"body": [
{
"type": "DeclareVariable",
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 24
}
},
"id": {
"type": "Identifier",
"start": 12,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 12
},
"end": {
"line": 1,
"column": 23
},
"identifierName": "string"
},
"name": "string",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 18,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 23
}
},
"typeAnnotation": {
"type": "AnyTypeAnnotation",
"start": 20,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 20
},
"end": {
"line": 1,
"column": 23
}
}
}
}
}
}
],
"directives": []
}
}