Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(evaluate): handle when parentpath is removed #848

Merged
merged 2 commits into from May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
`
);
});