Skip to content

Commit

Permalink
Fix another NPE in ErrorToFixMapper that I found by trying it on some…
Browse files Browse the repository at this point in the history
… real world code.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=136640327
  • Loading branch information
tbreisacher authored and blickly committed Oct 19, 2016
1 parent 9ef78a0 commit 30c350b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/com/google/javascript/refactoring/ErrorToFixMapper.java
Expand Up @@ -343,6 +343,8 @@ public final void visit(NodeTraversal nodeTraversal, Node n, Node parent) {
&& n.getFirstChild().matchesQualifiedName(closureFunction)) {
calls.add(parent);
} else if (NodeUtil.isNameDeclaration(parent)
&& n.hasChildren()
&& n.getLastChild().isCall()
&& n.getLastChild().getFirstChild().matchesQualifiedName(closureFunction)) {
Preconditions.checkState(n.isName() || n.isDestructuringLhs());
calls.add(parent);
Expand Down
46 changes: 46 additions & 0 deletions test/com/google/javascript/refactoring/ErrorToFixMapperTest.java
Expand Up @@ -291,6 +291,52 @@ public void testRequiresSorted2() {
"alert(1);"));
}

@Test
public void testSortRequiresInGoogModule_let() {
assertChanges(
LINE_JOINER.join(
"goog.module('m');",
"",
"/** @suppress {extraRequire} */",
"goog.require('a.c');",
"/** @suppress {extraRequire} */",
"goog.require('a.b');",
"",
"let localVar;"),
LINE_JOINER.join(
"goog.module('m');",
"",
"/** @suppress {extraRequire} */",
"goog.require('a.b');",
"/** @suppress {extraRequire} */",
"goog.require('a.c');",
"",
"let localVar;"));
}

@Test
public void testSortRequiresInGoogModule_const() {
assertChanges(
LINE_JOINER.join(
"goog.module('m');",
"",
"/** @suppress {extraRequire} */",
"goog.require('a.c');",
"/** @suppress {extraRequire} */",
"goog.require('a.b');",
"",
"const FOO = 0;"),
LINE_JOINER.join(
"goog.module('m');",
"",
"/** @suppress {extraRequire} */",
"goog.require('a.b');",
"/** @suppress {extraRequire} */",
"goog.require('a.c');",
"",
"const FOO = 0;"));
}

/**
* Using this form in a goog.module is a violation of the style guide, but still fairly common.
*/
Expand Down

0 comments on commit 30c350b

Please sign in to comment.