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: handle non array statements in evaluate helper #846

Merged
merged 4 commits into from May 14, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion packages/babel-helper-evaluate-path/package.json
Expand Up @@ -11,5 +11,8 @@
"license": "MIT",
"author": "boopathi",
"main": "lib/index.js",
"repository": "https://github.com/babel/minify/tree/master/packages/babel-helper-evaluate-path"
"repository": "https://github.com/babel/minify/tree/master/packages/babel-helper-evaluate-path",
"dependencies": {
"@babel/types": "^7.0.0-beta.46"
}
}
11 changes: 7 additions & 4 deletions packages/babel-helper-evaluate-path/src/index.js
Expand Up @@ -181,9 +181,9 @@ function evaluateBasedOnControlFlow(binding, refPath) {
const declaration = declarator.parentPath;

if (
declaration.parentPath.isIfStatement() ||
declaration.parentPath.isLoop() ||
declaration.parentPath.isSwitchCase()
t.isIfStatement(declaration.parentPath) ||
t.isLoop(declaration.parentPath) ||
t.isSwitchCase(declaration.parentPath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be declaration.parentPath.node.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with that is it would fail if node is removed, so I went with this check which we do already when binding is of kind "var"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah. so isRemoved should be the first check. I think there is a difference between using t.is methods on a path and a node.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went back to using path.isCheck since its wrong to use types check for path as you mentioned.

) {
return { shouldDeopt: true };
}
Expand All @@ -194,7 +194,10 @@ function evaluateBasedOnControlFlow(binding, refPath) {
}

// Detect Usage before Init
const stmts = scopePath.get("body");
let stmts = scopePath.get("body");
if (!Array.isArray(stmts)) {
stmts = [stmts];
}

const compareResult = compareBindingAndReference({
binding,
Expand Down
@@ -0,0 +1,2 @@
class MyComponent {}
MyComponent.propTypes = { userName: 123 };
@@ -0,0 +1,5 @@
class MyComponent {}

MyComponent.propTypes = {
userName: 123
};
2 changes: 1 addition & 1 deletion yarn.lock
Expand Up @@ -504,7 +504,7 @@
invariant "^2.2.0"
lodash "^4.2.0"

"@babel/types@7.0.0-beta.46":
"@babel/types@7.0.0-beta.46", "@babel/types@^7.0.0-beta.46":
version "7.0.0-beta.46"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.0.0-beta.46.tgz#eb84399a699af9fcb244440cce78e1acbeb40e0c"
dependencies:
Expand Down