Skip to content

Commit

Permalink
Fixes change tracking in ProcessTweaks.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=153004831
  • Loading branch information
stalcup authored and brad4d committed Apr 13, 2017
1 parent eac8c5b commit 9ec6262
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
18 changes: 7 additions & 11 deletions src/com/google/javascript/jscomp/ProcessTweaks.java
Expand Up @@ -206,37 +206,32 @@ public void process(Node externs, Node root) {
CollectTweaksResult result = collectTweaks(root); CollectTweaksResult result = collectTweaks(root);
applyCompilerDefaultValueOverrides(result.tweakInfos); applyCompilerDefaultValueOverrides(result.tweakInfos);


boolean changed = false;

if (stripTweaks) { if (stripTweaks) {
changed = stripAllCalls(result.tweakInfos); stripAllCalls(result.tweakInfos);
} else if (!compilerDefaultValueOverrides.isEmpty()) { } else if (!compilerDefaultValueOverrides.isEmpty()) {
changed = replaceGetCompilerOverridesCalls(result.getOverridesCalls); replaceGetCompilerOverridesCalls(result.getOverridesCalls);
}
if (changed) {
compiler.reportCodeChange();
} }
} }


/** /**
* Passes the compiler default value overrides to the JS by replacing calls * Passes the compiler default value overrides to the JS by replacing calls
* to goog.tweak.getCompilerOverrids_ with a map of tweak ID->default value; * to goog.tweak.getCompilerOverrids_ with a map of tweak ID->default value;
*/ */
private boolean replaceGetCompilerOverridesCalls( private void replaceGetCompilerOverridesCalls(
List<TweakFunctionCall> calls) { List<TweakFunctionCall> calls) {
for (TweakFunctionCall call : calls) { for (TweakFunctionCall call : calls) {
Node callNode = call.callNode; Node callNode = call.callNode;
Node objNode = createCompilerDefaultValueOverridesVarNode(callNode); Node objNode = createCompilerDefaultValueOverridesVarNode(callNode);
callNode.replaceWith(objNode); callNode.replaceWith(objNode);
compiler.reportChangeToEnclosingScope(objNode);
} }
return !calls.isEmpty();
} }


/** /**
* Removes all CALL nodes in the given TweakInfos, replacing calls to getter * Removes all CALL nodes in the given TweakInfos, replacing calls to getter
* functions with the tweak's default value. * functions with the tweak's default value.
*/ */
private boolean stripAllCalls(Map<String, TweakInfo> tweakInfos) { private void stripAllCalls(Map<String, TweakInfo> tweakInfos) {
for (TweakInfo tweakInfo : tweakInfos.values()) { for (TweakInfo tweakInfo : tweakInfos.values()) {
boolean isRegistered = tweakInfo.isRegistered(); boolean isRegistered = tweakInfo.isRegistered();
for (TweakFunctionCall functionCall : tweakInfo.functionCalls) { for (TweakFunctionCall functionCall : tweakInfo.functionCalls) {
Expand All @@ -255,14 +250,15 @@ private boolean stripAllCalls(Map<String, TweakInfo> tweakInfos) {
newValue = registerFunction.createDefaultValueNode(); newValue = registerFunction.createDefaultValueNode();
} }
parent.replaceChild(callNode, newValue); parent.replaceChild(callNode, newValue);
compiler.reportChangeToEnclosingScope(parent);
} else { } else {
Node voidZeroNode = IR.voidNode(IR.number(0).srcref(callNode)) Node voidZeroNode = IR.voidNode(IR.number(0).srcref(callNode))
.srcref(callNode); .srcref(callNode);
parent.replaceChild(callNode, voidZeroNode); parent.replaceChild(callNode, voidZeroNode);
compiler.reportChangeToEnclosingScope(parent);
} }
} }
} }
return !tweakInfos.isEmpty();
} }


/** /**
Expand Down
1 change: 0 additions & 1 deletion test/com/google/javascript/jscomp/ProcessTweaksTest.java
Expand Up @@ -38,7 +38,6 @@ public ProcessTweaksTest() {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
validateAstChangeMarking(false);
defaultValueOverrides = new HashMap<>(); defaultValueOverrides = new HashMap<>();
stripTweaks = false; stripTweaks = false;
} }
Expand Down

0 comments on commit 9ec6262

Please sign in to comment.