diff --git a/src/plugins/flow.js b/src/plugins/flow.js index b95ceeab60..718f0f4921 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -837,12 +837,19 @@ export default function (instance) { instance.extend("parseObjPropValue", function (inner) { return function (prop) { var typeParameters; + + // method shorthand if (this.isRelational("<")) { typeParameters = this.flowParseTypeParameterDeclaration(); if (!this.match(tt.parenL)) this.unexpected(); } + inner.apply(this, arguments); - prop.value.typeParameters = typeParameters; + + // add typeParameters if we found them + if (typeParameters) { + prop.value.typeParameters = typeParameters; + } }; }); diff --git a/test/fixtures/flow/type-annotations/97/actual.js b/test/fixtures/flow/type-annotations/97/actual.js new file mode 100644 index 0000000000..c1de3d58cd --- /dev/null +++ b/test/fixtures/flow/type-annotations/97/actual.js @@ -0,0 +1 @@ +({f: function () {}}) diff --git a/test/fixtures/flow/type-annotations/97/expected.json b/test/fixtures/flow/type-annotations/97/expected.json new file mode 100644 index 0000000000..e23eb4353e --- /dev/null +++ b/test/fixtures/flow/type-annotations/97/expected.json @@ -0,0 +1,170 @@ +{ + "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": "ExpressionStatement", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 1, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "properties": [ + { + "type": "Property", + "start": 2, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 2, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "name": "f" + }, + "value": { + "type": "FunctionExpression", + "start": 5, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 14, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "params": [ + { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "name": "T" + } + ] + }, + "params": [], + "body": { + "type": "BlockStatement", + "start": 20, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "body": [] + } + }, + "kind": "init" + } + ], + "parenthesizedExpression": true + } + } + ] + } +} \ No newline at end of file