Skip to content

Commit

Permalink
Don't attempt to remove the RHS from a 'const' statement.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=174107759
  • Loading branch information
tbreisacher authored and brad4d committed Nov 1, 2017
1 parent f91dcb4 commit 307e4db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Expand Up @@ -210,6 +210,11 @@ private void tryRemoveAssignment(NodeTraversal t, Node n, Node exprRoot,


if (NodeUtil.isAssignmentOp(n) || n.isInc() || n.isDec() || isDeclarationNode) { if (NodeUtil.isAssignmentOp(n) || n.isInc() || n.isDec() || isDeclarationNode) {


if (parent.isConst()) {
// Removing the RHS of a const produces as invalid AST.
return;
}

Node lhs = isDeclarationNode ? n : n.getFirstChild(); Node lhs = isDeclarationNode ? n : n.getFirstChild();
Node rhs = NodeUtil.getRValueOfLValue(lhs); Node rhs = NodeUtil.getRValueOfLValue(lhs);


Expand Down
Expand Up @@ -706,10 +706,16 @@ public void testLet() {
"let a; let b; foo(); b = 2; return b;"); "let a; let b; foo(); b = 2; return b;");
} }


public void testConst() { public void testConst1() {
inFunction("const a = 1;"); inFunction("const a = 1;");
} }


public void testConst2() {
test(
"async function f(d) { if (d) { d = 5; } const a = 1; const b = 2; const [x, y] = b; }",
"async function f(d) { if (d) { 5; } const a = 1; const b = 2; const [x, y] = b; }");
}

public void testBlockScoping() { public void testBlockScoping() {
inFunction( inFunction(
LINE_JOINER.join( LINE_JOINER.join(
Expand Down

0 comments on commit 307e4db

Please sign in to comment.