Skip to content

Commit

Permalink
When rewriting, mark newly constructed "this" nodes as non-indexable.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=158038298
  • Loading branch information
salguarnieri authored and brad4d committed Jun 6, 2017
1 parent fb05a42 commit 42ceeff
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/com/google/javascript/jscomp/Es6RewriteArrowFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ private void addVarDecls(ThisContext thisContext) {
Node name = IR.name(THIS_VAR);
Node thisVar = IR.constNode(name, IR.thisNode());
thisVar.useSourceInfoIfMissingFromForTree(scopeBody);
makeTreeNonIndexable(thisVar);
if (thisContext.lastSuperStatement == null) {
scopeBody.addChildToFront(thisVar);
} else {
Expand All @@ -171,6 +172,13 @@ private void addVarDecls(ThisContext thisContext) {
}
}

private void makeTreeNonIndexable(Node n) {
n.makeNonIndexable();
for (Node child : n.children()) {
makeTreeNonIndexable(child);
}
}

private static class UpdateThisAndArgumentsReferences implements NodeTraversal.Callback {
private boolean changedThis = false;
private boolean changedArguments = false;
Expand All @@ -184,6 +192,7 @@ public UpdateThisAndArgumentsReferences(AbstractCompiler compiler) {
public void visit(NodeTraversal t, Node n, Node parent) {
if (n.isThis()) {
Node name = IR.name(THIS_VAR).srcref(n);
name.makeNonIndexable();
if (compiler.getOptions().preservesDetailedSourceInfo()) {
name.setOriginalName("this");
}
Expand Down

0 comments on commit 42ceeff

Please sign in to comment.