Skip to content

Commit

Permalink
Move ConstCheck into checks so that it will run when --checks_only is…
Browse files Browse the repository at this point in the history
… specified, or when creating whitelists, etc.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=127598380
  • Loading branch information
tbreisacher authored and blickly committed Jul 18, 2016
1 parent 8e08ab7 commit 4fc3baf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/com/google/javascript/jscomp/ConstCheck.java
Expand Up @@ -16,7 +16,6 @@

package com.google.javascript.jscomp;

import com.google.common.base.Preconditions;
import com.google.javascript.jscomp.NodeTraversal.AbstractPostOrderCallback;
import com.google.javascript.rhino.JSDocInfo;
import com.google.javascript.rhino.Node;
Expand All @@ -31,6 +30,8 @@
* XX++; // error!
*
*/
// TODO(tbreisacher): Consider merging this with CheckAccessControls so that all
// const-related checks are in the same place.
class ConstCheck extends AbstractPostOrderCallback
implements CompilerPass {

Expand All @@ -53,7 +54,6 @@ public ConstCheck(AbstractCompiler compiler) {

@Override
public void process(Node externs, Node root) {
Preconditions.checkState(compiler.getLifeCycleStage().isNormalized());
NodeTraversal.traverseRootsEs6(compiler, this, externs, root);
}

Expand Down
8 changes: 2 additions & 6 deletions src/com/google/javascript/jscomp/DefaultPassConfig.java
Expand Up @@ -412,6 +412,8 @@ protected List<PassFactory> getChecks() {
checks.add(checkAccessControls);
}

checks.add(checkConsts);

// Analyzer checks must be run after typechecking.
if (options.enables(DiagnosticGroups.ANALYZER_CHECKS)) {
checks.add(analyzerChecks);
Expand Down Expand Up @@ -602,12 +604,6 @@ protected List<PassFactory> getOptimizations() {
passes.add(chainCalls);
}

// Constant checking must be done after property collapsing because
// property collapsing can introduce new constants (e.g. enum values).
// TODO(johnlenz): make checkConsts namespace aware so it can be run
// as during the checks phase.
passes.add(checkConsts);

// Detects whether invocations of the method goog.string.Const.from are done
// with an argument which is a string literal.
passes.add(checkConstParams);
Expand Down
21 changes: 2 additions & 19 deletions test/com/google/javascript/jscomp/IntegrationTest.java
Expand Up @@ -1282,23 +1282,6 @@ public void testProvidedNamespaceIsConst() {
ConstCheck.CONST_REASSIGNED_VALUE_ERROR);
}

public void testProvidedNamespaceIsConst2() {
CompilerOptions options = createCompilerOptions();
options.setClosurePass(true);
options.setInlineConstantVars(true);
options.setCollapseProperties(true);
test(
options,
LINE_JOINER.join(
"var goog = {};",
"goog.provide('foo.bar');",
"function f() { foo.bar = {};}"),
LINE_JOINER.join(
"var foo$bar = {};",
"function f() { foo$bar = {}; }"),
ConstCheck.CONST_REASSIGNED_VALUE_ERROR);
}

public void testProvidedNamespaceIsConst3() {
CompilerOptions options = createCompilerOptions();
options.setClosurePass(true);
Expand Down Expand Up @@ -1338,10 +1321,10 @@ public void testProvidedNamespaceIsConst5() {
"var foo = {}; foo = {}; foo.Bar = {};");
}

public void testProcessDefinesAlwaysOn() {
public void testAtDefineReassigned() {
test(createCompilerOptions(),
"/** @define {boolean} */ var HI = true; HI = false;",
"var HI = false;false;");
ConstCheck.CONST_REASSIGNED_VALUE_ERROR);
}

public void testProcessDefinesAdditionalReplacements() {
Expand Down

0 comments on commit 4fc3baf

Please sign in to comment.