From 55f38933bfb16ceb3610faf6dbecc3548c6c6fa3 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Tue, 29 Aug 2017 14:11:50 -0500 Subject: [PATCH] Add allowPrimitiveOverride option to flowParseTypeAnnotatableIdentifier --- src/plugins/flow.js | 12 ++- .../flow/declare-statements/19/actual.js | 1 + .../flow/declare-statements/19/expected.json | 96 +++++++++++++++++++ 3 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/flow/declare-statements/19/actual.js create mode 100644 test/fixtures/flow/declare-statements/19/expected.json diff --git a/src/plugins/flow.js b/src/plugins/flow.js index b5fdd6ee39..6e0bca571d 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -180,7 +180,9 @@ export default (superClass: Class): Class => 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): Class => 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); diff --git a/test/fixtures/flow/declare-statements/19/actual.js b/test/fixtures/flow/declare-statements/19/actual.js new file mode 100644 index 0000000000..44827eb7af --- /dev/null +++ b/test/fixtures/flow/declare-statements/19/actual.js @@ -0,0 +1 @@ +declare var string: any; diff --git a/test/fixtures/flow/declare-statements/19/expected.json b/test/fixtures/flow/declare-statements/19/expected.json new file mode 100644 index 0000000000..eaf7fc9f0c --- /dev/null +++ b/test/fixtures/flow/declare-statements/19/expected.json @@ -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": [] + } +} \ No newline at end of file