diff --git a/packages/babylon/src/plugins/flow.js b/packages/babylon/src/plugins/flow.js index 06af0a4838..b4630f67b4 100644 --- a/packages/babylon/src/plugins/flow.js +++ b/packages/babylon/src/plugins/flow.js @@ -164,7 +164,7 @@ pp.flowParseTypeParameterDeclaration = function () { this.expectRelational("<"); while (!this.isRelational(">")) { - node.params.push(this.parseFlowTypeParam()); + node.params.push(this.flowParseExistentialTypeParam() || this.flowParseTypeAnnotatableIdentifier()); if (!this.isRelational(">")) { this.expect(tt.comma); } @@ -174,13 +174,11 @@ pp.flowParseTypeParameterDeclaration = function () { return this.finishNode(node, "TypeParameterDeclaration"); }; -pp.parseFlowTypeParam = function () { +pp.flowParseExistentialTypeParam = function () { if (this.match(tt.star)) { let node = this.startNode(); this.next(); return this.finishNode(node, "ExistentialTypeParam"); - } else { - return this.flowParseTypeAnnotatableIdentifier(); } }; @@ -192,7 +190,7 @@ pp.flowParseTypeParameterInstantiation = function () { this.expectRelational("<"); while (!this.isRelational(">")) { - node.params.push(this.parseFlowTypeParam()); + node.params.push(this.flowParseExistentialTypeParam() || this.flowParseType()); if (!this.isRelational(">")) { this.expect(tt.comma); } diff --git a/packages/babylon/test/fixtures/flow/type-annotations/existential-type-param/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/existential-type-param/expected.json index a412ffa9a8..c67f730713 100644 --- a/packages/babylon/test/fixtures/flow/type-annotations/existential-type-param/expected.json +++ b/packages/babylon/test/fixtures/flow/type-annotations/existential-type-param/expected.json @@ -121,7 +121,7 @@ }, "params": [ { - "type": "Identifier", + "type": "GenericTypeAnnotation", "start": 23, "end": 24, "loc": { @@ -134,7 +134,23 @@ "column": 24 } }, - "name": "T" + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "name": "T" + } }, { "type": "ExistentialTypeParam",