retain return types on ObjectMethods in transform-es2015-shorthand-properties (#4670)

This commit is contained in:
Dan Harper 2016-10-05 02:32:43 +01:00 committed by Henry Zhu
parent 9e6ac7b693
commit 9e17aaf043
10 changed files with 48 additions and 1 deletions

View File

@ -6,9 +6,12 @@ export default function () {
ObjectMethod(path) { ObjectMethod(path) {
let { node } = path; let { node } = path;
if (node.kind === "method") { if (node.kind === "method") {
const func = t.functionExpression(null, node.params, node.body, node.generator, node.async);
func.returnType = node.returnType;
path.replaceWith(t.objectProperty( path.replaceWith(t.objectProperty(
node.key, node.key,
t.functionExpression(null, node.params, node.body, node.generator, node.async), func,
node.computed node.computed
)); ));
} }

View File

@ -0,0 +1,6 @@
// @flow
var obj = {
method(a: string): number {
return 5 + 5;
}
};

View File

@ -0,0 +1,6 @@
// @flow
var obj = {
method: function (a: string): number {
return 5 + 5;
}
};

View File

@ -0,0 +1,3 @@
{
"plugins": ["transform-es2015-shorthand-properties", "syntax-flow"]
}

View File

@ -0,0 +1,6 @@
// @flow
var obj = {
method(a: string): number {
return 5 + 5;
}
};

View File

@ -0,0 +1,6 @@
// @flow
var obj = {
method: function (a /*: string*/) /*: number*/ {
return 5 + 5;
}
};

View File

@ -0,0 +1,3 @@
{
"plugins": ["transform-es2015-shorthand-properties", "transform-flow-comments"]
}

View File

@ -0,0 +1,6 @@
// @flow
var obj = {
method(a: string): number {
return 5 + 5;
}
};

View File

@ -0,0 +1,5 @@
var obj = {
method: function (a) {
return 5 + 5;
}
};

View File

@ -0,0 +1,3 @@
{
"plugins": ["transform-es2015-shorthand-properties", "transform-flow-strip-types"]
}