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

Respect @pureOrBreakMyCode in destructuring assignment #4179

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions src/com/google/javascript/jscomp/RemoveUnusedCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,14 @@ private void traverseCall(Node callNode, Scope scope) {
}

if (classVar == null || !classVar.isGlobal()) {
if (!mayHaveSideEffects(callNode) && parent.isExprResult()) {
RemovableBuilder builder = new RemovableBuilder();
for (Node child = callNode.getFirstChild(); child != null; child = child.getNext()) {
builder.addContinuation(new Continuation(child, scope));
}
builder.buildClassSetupCall(callNode).remove(compiler);
return;
}
// The call we are traversing does not modify a class definition,
// or the class is not specified with a simple variable name,
// or the variable name is not global.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2953,5 +2953,7 @@ public void testPureOrBreakMyCode() {
test("const a = /** @pureOrBreakMyCode */(alert());", "");
test("let a = /** @pureOrBreakMyCode */(alert());", "");
test("var a = /** @pureOrBreakMyCode */(alert());", "");
test("/** @pureOrBreakMyCode */(alert());", "");
test("/** @pureOrBreakMyCode */(alert(alert()));", "alert()");
}
}