22
22
23
23
import com .google .common .collect .ImmutableSet ;
24
24
import com .google .javascript .jscomp .CodingConvention .SubclassRelationship ;
25
- import com .google .javascript .jscomp .base .LinkedIdentityHashMap ;
25
+ import com .google .javascript .jscomp .base .LinkedIdentityHashSet ;
26
26
import com .google .javascript .jscomp .diagnostic .LogFile ;
27
27
import com .google .javascript .rhino .IR ;
28
28
import com .google .javascript .rhino .Node ;
@@ -54,7 +54,7 @@ class StripCode implements CompilerPass {
54
54
private final AbstractCompiler compiler ;
55
55
private final ImmutableSet <String > stripNameSuffixes ;
56
56
private final ImmutableSet <String > stripNamePrefixes ;
57
- private final LinkedIdentityHashMap <String , String > varsToRemove = new LinkedIdentityHashMap <>();
57
+ private final LinkedIdentityHashSet <String > varsToRemove = new LinkedIdentityHashSet <>();
58
58
59
59
private final String [] stripTypesList ;
60
60
private final String [] stripTypePrefixesList ;
@@ -246,7 +246,7 @@ public void visit(NodeTraversal t, Node n, Node parent) {
246
246
break ;
247
247
248
248
case OBJECTLIT :
249
- eliminateKeysWithStripNamesFromObjLit (t , n );
249
+ eliminateKeysWithStripNamesFromObjLit (n );
250
250
break ;
251
251
252
252
case EXPR_RESULT :
@@ -288,7 +288,7 @@ void removeVarDeclarationsByNameOrRvalue(NodeTraversal t, Node n, Node parent) {
288
288
|| qualifiedNameBeginsWithStripType (nameNode )
289
289
|| isCallWhoseReturnValueShouldBeStripped (nameNode .getFirstChild ())) {
290
290
// Remove the NAME.
291
- varsToRemove .put ( name , name );
291
+ varsToRemove .add ( name );
292
292
if (name .contains ("$" )) {
293
293
// We need to be careful with this code pattern that appears after
294
294
// collapsing properties.
@@ -353,7 +353,7 @@ void maybeRemoveReferenceToRemovedVariable(NodeTraversal t, Node n, Node parent)
353
353
// GETELEM
354
354
// NAME
355
355
// NUMBER|STRING|NAME|...
356
- if (parent .getFirstChild () == n && isReferenceToRemovedVar (t , n )) {
356
+ if (parent .getFirstChild () == n && isReferenceToRemovedVar (n )) {
357
357
decisionsLog .log (() -> n .getString () + ": removing getelem/getprop/call chain" );
358
358
replaceHighestNestedCallWithNull (t , parent , parent .getParent ());
359
359
}
@@ -371,7 +371,7 @@ void maybeRemoveReferenceToRemovedVariable(NodeTraversal t, Node n, Node parent)
371
371
case ASSIGN_MUL :
372
372
case ASSIGN_DIV :
373
373
case ASSIGN_MOD :
374
- if (isReferenceToRemovedVar (t , n )) {
374
+ if (isReferenceToRemovedVar (n )) {
375
375
if (parent .getFirstChild () == n ) {
376
376
Node grandparent = parent .getParent ();
377
377
decisionsLog .log (
@@ -399,7 +399,7 @@ void maybeRemoveReferenceToRemovedVariable(NodeTraversal t, Node n, Node parent)
399
399
400
400
case NEW :
401
401
case CALL :
402
- if (!n .isFirstChildOf (parent ) && isReferenceToRemovedVar (t , n )) {
402
+ if (!n .isFirstChildOf (parent ) && isReferenceToRemovedVar (n )) {
403
403
// NOTE: the callee is handled when we visit the CALL or NEW node
404
404
decisionsLog .log (
405
405
() -> n .getQualifiedName () + ": replacing parameter reference with null" );
@@ -419,7 +419,7 @@ void maybeRemoveReferenceToRemovedVariable(NodeTraversal t, Node n, Node parent)
419
419
boolean parentIsCallee =
420
420
(grandparent .isCall () || grandparent .isNew ()) && parent .isFirstChildOf (grandparent );
421
421
boolean isSafeToRemove = !isLastChild || !parentIsCallee ;
422
- if (isSafeToRemove && isReferenceToRemovedVar (t , n )) {
422
+ if (isSafeToRemove && isReferenceToRemovedVar (n )) {
423
423
decisionsLog .log (
424
424
() -> n .getQualifiedName () + ": replacing reference in comma expr with null" );
425
425
replaceWithNull (n );
@@ -428,7 +428,7 @@ void maybeRemoveReferenceToRemovedVariable(NodeTraversal t, Node n, Node parent)
428
428
break ;
429
429
430
430
default :
431
- if (isReferenceToRemovedVar (t , n )) {
431
+ if (isReferenceToRemovedVar (n )) {
432
432
decisionsLog .log (() -> n .getQualifiedName () + ": replacing reference with null" );
433
433
replaceWithNull (n );
434
434
t .reportCodeChange ();
@@ -550,10 +550,9 @@ void maybeEliminateExpressionByName(Node n) {
550
550
/**
551
551
* Eliminates any object literal keys in an object literal declaration that have strip names.
552
552
*
553
- * @param t The traversal
554
553
* @param n An OBJLIT node
555
554
*/
556
- void eliminateKeysWithStripNamesFromObjLit (NodeTraversal t , Node n ) {
555
+ void eliminateKeysWithStripNamesFromObjLit (Node n ) {
557
556
// OBJLIT
558
557
// key1
559
558
// value1
@@ -680,12 +679,11 @@ boolean qualifiedNameBeginsWithStripType(String name) {
680
679
/**
681
680
* Determines whether a NAME node represents a reference to a variable that has been removed.
682
681
*
683
- * @param t The traversal
684
682
* @param n A NAME node
685
683
* @return Whether the variable was removed
686
684
*/
687
- boolean isReferenceToRemovedVar (NodeTraversal t , Node n ) {
688
- return varsToRemove .get (n .getString ()) != null ;
685
+ boolean isReferenceToRemovedVar (Node n ) {
686
+ return varsToRemove .contains (n .getString ());
689
687
}
690
688
691
689
/**
@@ -695,7 +693,7 @@ boolean isReferenceToRemovedVar(NodeTraversal t, Node n) {
695
693
* class-defining functions (e.g. goog.inherits).
696
694
*
697
695
* @param t The traversal
698
- * @param n A CALL node
696
+ * @param n A CALL or NEW node
699
697
* @return Whether the node triggers statement removal
700
698
*/
701
699
boolean isMethodOrCtorCallThatTriggersRemoval (NodeTraversal t , Node n , Node parent ) {
0 commit comments