diff --git a/packages/babel-plugin-proposal-decorators/src/index.js b/packages/babel-plugin-proposal-decorators/src/index.js index 0a6d1f6c60..65324fb4ea 100644 --- a/packages/babel-plugin-proposal-decorators/src/index.js +++ b/packages/babel-plugin-proposal-decorators/src/index.js @@ -27,6 +27,8 @@ const buildGetObjectInitializer = template(` `); export default function() { + const WARNING_CALLS = new WeakSet(); + /** * If the decorator expressions are non-identifiers, hoist them to before the class so we can be sure * that they are evaluated in order. @@ -151,11 +153,14 @@ export default function() { t.blockStatement([t.returnStatement(node.value)]), ) : t.nullLiteral(); + node.value = t.callExpression( state.addHelper("initializerWarningHelper"), [descriptor, t.thisExpression()], ); + WARNING_CALLS.add(node.value); + acc = acc.concat([ t.assignmentExpression( "=", @@ -255,10 +260,7 @@ export default function() { }, AssignmentExpression(path, state) { - if (!path.get("left").isMemberExpression()) return; - if (!path.get("left.property").isIdentifier()) return; - if (!path.get("right").isCallExpression()) return; - if (!path.get("right.callee").isIdentifier()) return; + if (!WARNING_CALLS.has(path.node.right)) return; path.replaceWith( t.callExpression(state.addHelper("initializerDefineProperty"), [ diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/regression/7030/actual.js b/packages/babel-plugin-proposal-decorators/test/fixtures/regression/7030/actual.js new file mode 100644 index 0000000000..2a7e2ce934 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/regression/7030/actual.js @@ -0,0 +1,22 @@ +function generateAsyncAction(type) { + type = type.toUpperCase() + const request = createAction(type+'_REQUEST', + undefined, requestMetaCreator + ) + request.request = request // crazy + request.success = createAction(type+'_SUCCESS', undefined, metaCreator) + request.error = createAction(type+'_ERROR', undefined, metaCreator) + request.cancel = createAction(type+'_CANCEL', undefined, metaCreator) + request.progress = createAction(type+'_PROGRESS', undefined, metaCreator) + request.process = createAction(type+'_PROCESS', undefined, metaCreator) + + return request +} + +class A extends B { + constructor(timestamp) { + super() + this.timestamp = timestamp + this.moment = moment(timestamp) + } +} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/regression/7030/expected.js b/packages/babel-plugin-proposal-decorators/test/fixtures/regression/7030/expected.js new file mode 100644 index 0000000000..b47a62b382 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/regression/7030/expected.js @@ -0,0 +1,41 @@ +function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return right[Symbol.hasInstance](left); } else { return left instanceof right; } } + +function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!_instanceof(instance, Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +function generateAsyncAction(type) { + type = type.toUpperCase(); + var request = createAction(type + '_REQUEST', undefined, requestMetaCreator); + request.request = request; // crazy + + request.success = createAction(type + '_SUCCESS', undefined, metaCreator); + request.error = createAction(type + '_ERROR', undefined, metaCreator); + request.cancel = createAction(type + '_CANCEL', undefined, metaCreator); + request.progress = createAction(type + '_PROGRESS', undefined, metaCreator); + request.process = createAction(type + '_PROCESS', undefined, metaCreator); + return request; +} + +var A = +/*#__PURE__*/ +function (_B) { + _inherits(A, _B); + + function A(timestamp) { + var _this; + + _classCallCheck(this, A); + + _this = _possibleConstructorReturn(this, (A.__proto__ || Object.getPrototypeOf(A)).call(this)); + _this.timestamp = timestamp; + _this.moment = moment(timestamp); + return _this; + } + + return A; +}(B); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/regression/7030/options.json b/packages/babel-plugin-proposal-decorators/test/fixtures/regression/7030/options.json new file mode 100644 index 0000000000..eaf32387b5 --- /dev/null +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/regression/7030/options.json @@ -0,0 +1,3 @@ +{ + "presets": ["es2015", "stage-0"] +}