retain return types on ObjectMethods in transform-es2015-shorthand-properties (#4670)
This commit is contained in:
parent
9e6ac7b693
commit
9e17aaf043
@ -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
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,6 @@
|
|||||||
|
// @flow
|
||||||
|
var obj = {
|
||||||
|
method(a: string): number {
|
||||||
|
return 5 + 5;
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
// @flow
|
||||||
|
var obj = {
|
||||||
|
method: function (a: string): number {
|
||||||
|
return 5 + 5;
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["transform-es2015-shorthand-properties", "syntax-flow"]
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
// @flow
|
||||||
|
var obj = {
|
||||||
|
method(a: string): number {
|
||||||
|
return 5 + 5;
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
// @flow
|
||||||
|
var obj = {
|
||||||
|
method: function (a /*: string*/) /*: number*/ {
|
||||||
|
return 5 + 5;
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["transform-es2015-shorthand-properties", "transform-flow-comments"]
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
// @flow
|
||||||
|
var obj = {
|
||||||
|
method(a: string): number {
|
||||||
|
return 5 + 5;
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
var obj = {
|
||||||
|
method: function (a) {
|
||||||
|
return 5 + 5;
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["transform-es2015-shorthand-properties", "transform-flow-strip-types"]
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user