diff --git a/packages/babel-plugin-proposal-decorators/src/transformer.js b/packages/babel-plugin-proposal-decorators/src/transformer.js index 3ed8f71a3fe8..22a493183a1c 100644 --- a/packages/babel-plugin-proposal-decorators/src/transformer.js +++ b/packages/babel-plugin-proposal-decorators/src/transformer.js @@ -7,8 +7,11 @@ function prop(key, value) { return t.objectProperty(t.identifier(key), value); } -function value(body, params = []) { - return t.objectMethod("method", t.identifier("value"), params, body); +function value(body, params = [], async, generator) { + const method = t.objectMethod("method", t.identifier("value"), params, body); + method.async = !!async; + method.generator = !!generator; + return method; } function hasDecorators({ node }) { @@ -77,7 +80,7 @@ function getSingleElementDefinition(path, superRef, classRef, file) { prop("static", node.static && t.booleanLiteral(true)), prop("key", getKey(node)), isMethod - ? value(node.body, node.params) + ? value(node.body, node.params, node.async, node.generator) : node.value ? value(template.ast`{ return ${node.value} }`) : prop("value", scope.buildUndefinedNode()), diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/transformation/async-generator-method/input.js b/packages/babel-plugin-proposal-decorators/test/fixtures/transformation/async-generator-method/input.js new file mode 100644 index 000000000000..be2fdae25d4b --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/transformation/async-generator-method/input.js @@ -0,0 +1,8 @@ +@decorator +class Foo { + async f1() {} + + *f2() {} + + async *f3() {} +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/transformation/async-generator-method/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/transformation/async-generator-method/options.json new file mode 100644 index 000000000000..c77f4109f467 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/transformation/async-generator-method/options.json @@ -0,0 +1,8 @@ +{ + "plugins": [ + ["proposal-decorators", { "decoratorsBeforeExport": false }], + "proposal-class-properties", + "syntax-async-generators", + ["external-helpers", { "helperVersion": "7.0.2" }] + ] +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/transformation/async-generator-method/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/transformation/async-generator-method/output.js new file mode 100644 index 000000000000..75ce76d3f1d7 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/transformation/async-generator-method/output.js @@ -0,0 +1,33 @@ +let Foo = babelHelpers.decorate([decorator], function (_initialize) { + "use strict"; + + class Foo { + constructor() { + _initialize(this); + } + + } + + return { + F: Foo, + d: [{ + kind: "method", + key: "f1", + + async value() {} + + }, { + kind: "method", + key: "f2", + + *value() {} + + }, { + kind: "method", + key: "f3", + + async *value() {} + + }] + }; +});