fix handling of flow method shorthand - fixes #2169
This commit is contained in:
parent
94e345e0b2
commit
71bbffa797
@ -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);
|
||||
|
||||
// add typeParameters if we found them
|
||||
if (typeParameters) {
|
||||
prop.value.typeParameters = typeParameters;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
1
test/fixtures/flow/type-annotations/97/actual.js
vendored
Normal file
1
test/fixtures/flow/type-annotations/97/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
({f: function <T>() {}})
|
||||
170
test/fixtures/flow/type-annotations/97/expected.json
vendored
Normal file
170
test/fixtures/flow/type-annotations/97/expected.json
vendored
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user