diff --git a/packages/babel-plugin-transform-es2015-shorthand-properties/src/index.js b/packages/babel-plugin-transform-es2015-shorthand-properties/src/index.js index 357d57887a..c3aa80e4f5 100644 --- a/packages/babel-plugin-transform-es2015-shorthand-properties/src/index.js +++ b/packages/babel-plugin-transform-es2015-shorthand-properties/src/index.js @@ -6,9 +6,12 @@ export default function () { ObjectMethod(path) { let { node } = path; 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( node.key, - t.functionExpression(null, node.params, node.body, node.generator, node.async), + func, node.computed )); } diff --git a/packages/babel-plugin-transform-es2015-shorthand-properties/test/fixtures/shorthand-properties/method-type-annotations/actual.js b/packages/babel-plugin-transform-es2015-shorthand-properties/test/fixtures/shorthand-properties/method-type-annotations/actual.js new file mode 100644 index 0000000000..b6ce120afd --- /dev/null +++ b/packages/babel-plugin-transform-es2015-shorthand-properties/test/fixtures/shorthand-properties/method-type-annotations/actual.js @@ -0,0 +1,6 @@ +// @flow +var obj = { + method(a: string): number { + return 5 + 5; + } +}; diff --git a/packages/babel-plugin-transform-es2015-shorthand-properties/test/fixtures/shorthand-properties/method-type-annotations/expected.js b/packages/babel-plugin-transform-es2015-shorthand-properties/test/fixtures/shorthand-properties/method-type-annotations/expected.js new file mode 100644 index 0000000000..cfd883f5b1 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-shorthand-properties/test/fixtures/shorthand-properties/method-type-annotations/expected.js @@ -0,0 +1,6 @@ +// @flow +var obj = { + method: function (a: string): number { + return 5 + 5; + } +}; diff --git a/packages/babel-plugin-transform-es2015-shorthand-properties/test/fixtures/shorthand-properties/method-type-annotations/options.json b/packages/babel-plugin-transform-es2015-shorthand-properties/test/fixtures/shorthand-properties/method-type-annotations/options.json new file mode 100644 index 0000000000..0f8f7d5c7a --- /dev/null +++ b/packages/babel-plugin-transform-es2015-shorthand-properties/test/fixtures/shorthand-properties/method-type-annotations/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-shorthand-properties", "syntax-flow"] +} diff --git a/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/object-method-type-annotations/actual.js b/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/object-method-type-annotations/actual.js new file mode 100644 index 0000000000..b6ce120afd --- /dev/null +++ b/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/object-method-type-annotations/actual.js @@ -0,0 +1,6 @@ +// @flow +var obj = { + method(a: string): number { + return 5 + 5; + } +}; diff --git a/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/object-method-type-annotations/expected.js b/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/object-method-type-annotations/expected.js new file mode 100644 index 0000000000..766a0cdfb9 --- /dev/null +++ b/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/object-method-type-annotations/expected.js @@ -0,0 +1,6 @@ +// @flow +var obj = { + method: function (a /*: string*/) /*: number*/ { + return 5 + 5; + } +}; diff --git a/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/object-method-type-annotations/options.json b/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/object-method-type-annotations/options.json new file mode 100644 index 0000000000..f4d9553043 --- /dev/null +++ b/packages/babel-plugin-transform-flow-comments/test/fixtures/flow-comments/object-method-type-annotations/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-shorthand-properties", "transform-flow-comments"] +} diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/regression/object-method-type-annotations/actual.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/regression/object-method-type-annotations/actual.js new file mode 100644 index 0000000000..b6ce120afd --- /dev/null +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/regression/object-method-type-annotations/actual.js @@ -0,0 +1,6 @@ +// @flow +var obj = { + method(a: string): number { + return 5 + 5; + } +}; diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/regression/object-method-type-annotations/expected.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/regression/object-method-type-annotations/expected.js new file mode 100644 index 0000000000..a8a2d4e244 --- /dev/null +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/regression/object-method-type-annotations/expected.js @@ -0,0 +1,5 @@ +var obj = { + method: function (a) { + return 5 + 5; + } +}; diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/regression/object-method-type-annotations/options.json b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/regression/object-method-type-annotations/options.json new file mode 100644 index 0000000000..421aa84183 --- /dev/null +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/regression/object-method-type-annotations/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-shorthand-properties", "transform-flow-strip-types"] +}