Skip to content

Commit

Permalink
fix(evaluate): handle when parentpath is removed (#848)
Browse files Browse the repository at this point in the history
* fix(evaluate): handle when parentpath is removed

* add test for class body
  • Loading branch information
vigneshshanmugam authored and boopathi committed May 15, 2018
1 parent 2dc4bd0 commit 85c9b6d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
36 changes: 21 additions & 15 deletions packages/babel-helper-evaluate-path/src/index.js
Expand Up @@ -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 = (
Expand Down
21 changes: 21 additions & 0 deletions packages/babel-preset-minify/__tests__/minify-env-tests.js
Expand Up @@ -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;
`
);
});

0 comments on commit 85c9b6d

Please sign in to comment.