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 DCE tests with labels in separate namespace #225

Merged
merged 2 commits into from
Oct 27, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,13 @@ module.exports = ({ types: t, traverse }) => {
// here we handle the break labels
// if they are outside switch, we bail out
// if they are within the case, we keep them
const _isAncestor = isAncestor(path.scope.getBinding(label.node.name).path, path);
let labelPath;
if (path.scope.getLabel) {
labelPath = getLabel(label.node.name, path);
} else {
labelPath = path.scope.getBinding(label.node.name).path;
}
const _isAncestor = isAncestor(labelPath, path);

return {
bail: _isAncestor,
Expand Down Expand Up @@ -957,4 +963,16 @@ module.exports = ({ types: t, traverse }) => {
return path.isFunctionDeclaration()
|| path.isVariableDeclaration({ kind: "var" });
}

function getLabel(name, _path) {
let label, path = _path;
while (!path.isProgram()) {
Copy link
Member

Choose a reason for hiding this comment

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

you can use path.find/path.findParent here right?

Copy link
Member Author

@boopathi boopathi Oct 26, 2016

Choose a reason for hiding this comment

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

yes... will change it

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm.. But I want to return the label instead of the parent.

label = path.scope.getLabel(name);
if (label) {
return label;
}
path = path.parentPath;
}
return null;
}
};