Skip to content

Commit

Permalink
Slightly simplify the i.js generator's node removal logic
Browse files Browse the repository at this point in the history
This is a refactoring-only CL that doens't change behavior.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=180958495
  • Loading branch information
blickly committed Jan 5, 2018
1 parent d971967 commit 7ae63b9
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/com/google/javascript/jscomp/ijs/PotentialDeclaration.java
Expand Up @@ -84,10 +84,7 @@ Node getRhs() {
return rhs;
}

Node getStatement() {
return NodeUtil.getEnclosingStatement(lhs);
}

@Nullable
JSDocInfo getJsDoc() {
return NodeUtil.getBestJSDocInfo(lhs);
}
Expand All @@ -101,6 +98,10 @@ private boolean isDetached() {
return true;
}

Node getRemovableNode() {
return NodeUtil.getEnclosingStatement(lhs);
}

/**
* Remove this "potential declaration" completely.
* Usually, this is because the same symbol has already been declared in this file.
Expand All @@ -109,11 +110,7 @@ final void remove(AbstractCompiler compiler) {
if (isDetached()) {
return;
}
doRemove(compiler);
}

void doRemove(AbstractCompiler compiler) {
Node statement = getStatement();
Node statement = getRemovableNode();
NodeUtil.deleteNode(statement, compiler);
statement.removeChildren();
}
Expand Down Expand Up @@ -183,7 +180,7 @@ void simplify(AbstractCompiler compiler) {
Node newStatement =
NodeUtil.newQNameDeclaration(compiler, nameNode.getQualifiedName(), null, jsdoc);
newStatement.useSourceInfoIfMissingFromForTree(nameNode);
Node oldStatement = getStatement();
Node oldStatement = getRemovableNode();
NodeUtil.deleteChildren(oldStatement, compiler);
oldStatement.replaceWith(newStatement);
compiler.reportChangeToEnclosingScope(newStatement);
Expand Down Expand Up @@ -219,7 +216,7 @@ void simplify(AbstractCompiler compiler) {
Node newStatement =
NodeUtil.newQNameDeclaration(compiler, getFullyQualifiedName(), null, getJsDoc());
newStatement.useSourceInfoIfMissingFromForTree(getLhs());
NodeUtil.deleteNode(getStatement(), compiler);
NodeUtil.deleteNode(getRemovableNode(), compiler);
insertionPoint.getParent().addChildAfter(newStatement, insertionPoint);
compiler.reportChangeToEnclosingScope(newStatement);
}
Expand Down Expand Up @@ -254,8 +251,8 @@ private static class MethodDeclaration extends PotentialDeclaration {
void simplify(AbstractCompiler compiler) {}

@Override
void doRemove(AbstractCompiler compiler) {
NodeUtil.deleteNode(getLhs(), compiler);
Node getRemovableNode() {
return getLhs();
}
}

Expand Down

0 comments on commit 7ae63b9

Please sign in to comment.