diff --git a/packages/babel-helper-evaluate-path/src/index.js b/packages/babel-helper-evaluate-path/src/index.js index e8b13e656..3917af417 100644 --- a/packages/babel-helper-evaluate-path/src/index.js +++ b/packages/babel-helper-evaluate-path/src/index.js @@ -120,21 +120,27 @@ function evaluateBasedOnControlFlow(binding, refPath) { // early-exit const declaration = binding.path.parentPath; - /** - * Handle when binding is created inside a parent block and - * the corresponding parent is removed by other plugins - * if (false) { var a } -> var a - */ - if (declaration.parentPath && declaration.parentPath.removed) { - return { confident: true, value: void 0 }; - } - - if ( - declaration.parentPath.isIfStatement() || - declaration.parentPath.isLoop() || - declaration.parentPath.isSwitchCase() - ) { - return { shouldDeopt: true }; + if (declaration.parentPath) { + /** + * Handle when binding is created inside a parent block and + * the corresponding parent is removed by other plugins + * if (false) { var a } -> var a + */ + if (declaration.parentPath.removed) { + return { + confident: true, + value: void 0 + }; + } + if ( + declaration.parentPath.isIfStatement() || + declaration.parentPath.isLoop() || + declaration.parentPath.isSwitchCase() + ) { + return { + shouldDeopt: true + }; + } } const fnParent = ( diff --git a/packages/babel-preset-minify/__tests__/minify-env-tests.js b/packages/babel-preset-minify/__tests__/minify-env-tests.js index 99c6036ea..f13a7de34 100644 --- a/packages/babel-preset-minify/__tests__/minify-env-tests.js +++ b/packages/babel-preset-minify/__tests__/minify-env-tests.js @@ -251,4 +251,25 @@ describe("preset along with env", () => { } ` ); + + thePlugin( + "should fix issue#845 - class body non array", + ` + class A {} + + A.B = {} + exports.A = A; + `, + ` + function _classCallCheck(a, b) { if (!(a instanceof b)) throw new TypeError("Cannot call a class as a function"); } + + var A = function a() { + "use strict"; + + _classCallCheck(this, a); + }; + + A.B = {}, exports.A = A; + ` + ); });