Skip to content

Commit

Permalink
Use getLhsNodesOfDeclaration instead of just iterating through the pa…
Browse files Browse the repository at this point in the history
…ram list.

This avoids a crash when a param is something other than just a name, such as DEFAULT_VALUE node.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=170752700
  • Loading branch information
tbreisacher authored and dimvar committed Oct 3, 2017
1 parent 37a13db commit 0b5f470
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/com/google/javascript/jscomp/RemoveUnusedVars.java
Expand Up @@ -363,8 +363,8 @@ private void traverseNode(Node n, Node parent, Scope scope) {
&& "arguments".equals(n.getString())
&& var.equals(scope.getArgumentsVar())) {
Scope fnScope = var.getScope();
Node lp = fnScope.getRootNode().getSecondChild();
for (Node p = lp.getFirstChild(); p != null; p = p.getNext()) {
Node paramList = NodeUtil.getFunctionParameters(fnScope.getRootNode());
for (Node p : NodeUtil.getLhsNodesOfDeclaration(paramList)) {
Var paramVar = fnScope.getOwnSlot(p.getString());
checkNotNull(paramVar);
markReferencedVar(paramVar);
Expand Down
3 changes: 1 addition & 2 deletions test/com/google/javascript/jscomp/RemoveUnusedVarsTest.java
Expand Up @@ -305,8 +305,7 @@ public void testDefaultParamsInClass() {
"class Foo extends Bar { constructor(value = undefined) { super(); value; } }; new Foo;");
}

// TODO(tbreisacher): Fix and enable.
public void disabled_testDefaultParamsInClassThatReferencesArguments() {
public void testDefaultParamsInClassThatReferencesArguments() {
testSame(
LINE_JOINER.join(
"class Foo extends Bar {",
Expand Down

0 comments on commit 0b5f470

Please sign in to comment.