Skip to content

Commit

Permalink
Clean up unused function parameters and unnecessary Map<T, T> that co…
Browse files Browse the repository at this point in the history
…uld be a Set<T>

PiperOrigin-RevId: 704413159
  • Loading branch information
lauraharker authored and copybara-github committed Dec 9, 2024
1 parent 482663d commit e3d3882
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/com/google/javascript/jscomp/StripCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import com.google.common.collect.ImmutableSet;
import com.google.javascript.jscomp.CodingConvention.SubclassRelationship;
import com.google.javascript.jscomp.base.LinkedIdentityHashMap;
import com.google.javascript.jscomp.base.LinkedIdentityHashSet;
import com.google.javascript.jscomp.diagnostic.LogFile;
import com.google.javascript.rhino.IR;
import com.google.javascript.rhino.Node;
Expand Down Expand Up @@ -54,7 +54,7 @@ class StripCode implements CompilerPass {
private final AbstractCompiler compiler;
private final ImmutableSet<String> stripNameSuffixes;
private final ImmutableSet<String> stripNamePrefixes;
private final LinkedIdentityHashMap<String, String> varsToRemove = new LinkedIdentityHashMap<>();
private final LinkedIdentityHashSet<String> varsToRemove = new LinkedIdentityHashSet<>();

private final String[] stripTypesList;
private final String[] stripTypePrefixesList;
Expand Down Expand Up @@ -246,7 +246,7 @@ public void visit(NodeTraversal t, Node n, Node parent) {
break;

case OBJECTLIT:
eliminateKeysWithStripNamesFromObjLit(t, n);
eliminateKeysWithStripNamesFromObjLit(n);
break;

case EXPR_RESULT:
Expand Down Expand Up @@ -288,7 +288,7 @@ void removeVarDeclarationsByNameOrRvalue(NodeTraversal t, Node n, Node parent) {
|| qualifiedNameBeginsWithStripType(nameNode)
|| isCallWhoseReturnValueShouldBeStripped(nameNode.getFirstChild())) {
// Remove the NAME.
varsToRemove.put(name, name);
varsToRemove.add(name);
if (name.contains("$")) {
// We need to be careful with this code pattern that appears after
// collapsing properties.
Expand Down Expand Up @@ -353,7 +353,7 @@ void maybeRemoveReferenceToRemovedVariable(NodeTraversal t, Node n, Node parent)
// GETELEM
// NAME
// NUMBER|STRING|NAME|...
if (parent.getFirstChild() == n && isReferenceToRemovedVar(t, n)) {
if (parent.getFirstChild() == n && isReferenceToRemovedVar(n)) {
decisionsLog.log(() -> n.getString() + ": removing getelem/getprop/call chain");
replaceHighestNestedCallWithNull(t, parent, parent.getParent());
}
Expand All @@ -371,7 +371,7 @@ void maybeRemoveReferenceToRemovedVariable(NodeTraversal t, Node n, Node parent)
case ASSIGN_MUL:
case ASSIGN_DIV:
case ASSIGN_MOD:
if (isReferenceToRemovedVar(t, n)) {
if (isReferenceToRemovedVar(n)) {
if (parent.getFirstChild() == n) {
Node grandparent = parent.getParent();
decisionsLog.log(
Expand Down Expand Up @@ -399,7 +399,7 @@ void maybeRemoveReferenceToRemovedVariable(NodeTraversal t, Node n, Node parent)

case NEW:
case CALL:
if (!n.isFirstChildOf(parent) && isReferenceToRemovedVar(t, n)) {
if (!n.isFirstChildOf(parent) && isReferenceToRemovedVar(n)) {
// NOTE: the callee is handled when we visit the CALL or NEW node
decisionsLog.log(
() -> n.getQualifiedName() + ": replacing parameter reference with null");
Expand All @@ -419,7 +419,7 @@ void maybeRemoveReferenceToRemovedVariable(NodeTraversal t, Node n, Node parent)
boolean parentIsCallee =
(grandparent.isCall() || grandparent.isNew()) && parent.isFirstChildOf(grandparent);
boolean isSafeToRemove = !isLastChild || !parentIsCallee;
if (isSafeToRemove && isReferenceToRemovedVar(t, n)) {
if (isSafeToRemove && isReferenceToRemovedVar(n)) {
decisionsLog.log(
() -> n.getQualifiedName() + ": replacing reference in comma expr with null");
replaceWithNull(n);
Expand All @@ -428,7 +428,7 @@ void maybeRemoveReferenceToRemovedVariable(NodeTraversal t, Node n, Node parent)
break;

default:
if (isReferenceToRemovedVar(t, n)) {
if (isReferenceToRemovedVar(n)) {
decisionsLog.log(() -> n.getQualifiedName() + ": replacing reference with null");
replaceWithNull(n);
t.reportCodeChange();
Expand Down Expand Up @@ -550,10 +550,9 @@ void maybeEliminateExpressionByName(Node n) {
/**
* Eliminates any object literal keys in an object literal declaration that have strip names.
*
* @param t The traversal
* @param n An OBJLIT node
*/
void eliminateKeysWithStripNamesFromObjLit(NodeTraversal t, Node n) {
void eliminateKeysWithStripNamesFromObjLit(Node n) {
// OBJLIT
// key1
// value1
Expand Down Expand Up @@ -680,12 +679,11 @@ boolean qualifiedNameBeginsWithStripType(String name) {
/**
* Determines whether a NAME node represents a reference to a variable that has been removed.
*
* @param t The traversal
* @param n A NAME node
* @return Whether the variable was removed
*/
boolean isReferenceToRemovedVar(NodeTraversal t, Node n) {
return varsToRemove.get(n.getString()) != null;
boolean isReferenceToRemovedVar(Node n) {
return varsToRemove.contains(n.getString());
}

/**
Expand All @@ -695,7 +693,7 @@ boolean isReferenceToRemovedVar(NodeTraversal t, Node n) {
* class-defining functions (e.g. goog.inherits).
*
* @param t The traversal
* @param n A CALL node
* @param n A CALL or NEW node
* @return Whether the node triggers statement removal
*/
boolean isMethodOrCtorCallThatTriggersRemoval(NodeTraversal t, Node n, Node parent) {
Expand Down

0 comments on commit e3d3882

Please sign in to comment.