diff --git a/packages/babel-plugin-proposal-decorators/src/transformer-legacy.ts b/packages/babel-plugin-proposal-decorators/src/transformer-legacy.ts index 22d0d5c7ab65..2b45fe874f2d 100644 --- a/packages/babel-plugin-proposal-decorators/src/transformer-legacy.ts +++ b/packages/babel-plugin-proposal-decorators/src/transformer-legacy.ts @@ -324,10 +324,8 @@ const visitor: Visitor = { ClassDeclaration(path) { const replacement = decoratedClassToExpression(path); if (replacement) { - path.replaceWith(replacement); - - const decl = path.get("declarations.0"); - const { id } = decl.node; + const decl = path.replaceWith(replacement)[0].get("declarations.0"); + const id = decl.node.id as t.Identifier; // TODO: Maybe add this logic to @babel/traverse const binding = path.scope.getOwnBinding(id.name); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/legacy-regression/8559/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/legacy-regression/8559/options.json index ea51d6b70917..a4756a4c3fba 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/legacy-regression/8559/options.json +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/legacy-regression/8559/options.json @@ -1,12 +1,13 @@ { - "plugins": [ - ["proposal-decorators", { "legacy": true }] - ], + "plugins": [["proposal-decorators", { "version": "legacy" }]], "presets": [ - ["env", { - "targets": { - "node": 8 + [ + "env", + { + "targets": { + "node": 8 + } } - }] + ] ] } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/legacy-regression/8559/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/legacy-regression/8559/output.js index 321fea76385d..11140092ad3e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/legacy-regression/8559/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/legacy-regression/8559/output.js @@ -7,8 +7,6 @@ exports.default = wrap; var _coreDecorators = require("core-decorators"); -function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object['ke' + 'ys'](descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object['define' + 'Property'](target, property, desc); desc = null; } return desc; } - function wrap() { return function () { var _class; @@ -16,7 +14,7 @@ function wrap() { let Foo = (_class = class Foo { method() {} - }, (_applyDecoratedDescriptor(_class.prototype, "method", [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, "method"), _class.prototype)), _class); + }, (babelHelpers.applyDecoratedDescriptor(_class.prototype, "method", [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, "method"), _class.prototype)), _class); return Foo; }; }