Skip to content

Commit

Permalink
Use compiler.toSource instead of CodePrinter, to speed up Google-inte…
Browse files Browse the repository at this point in the history
…rnal builds of the compiler.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178149573
  • Loading branch information
tbreisacher authored and blickly committed Dec 7, 2017
1 parent e1d6fd6 commit e388e5e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/com/google/javascript/jscomp/Linter.java
Expand Up @@ -79,6 +79,10 @@ static void lint(Path path, Compiler compiler) throws IOException {
CompilerOptions options = new CompilerOptions();
options.setLanguage(LanguageMode.ECMASCRIPT_NEXT);

// These are necessary to make sure that suggested fixes are printed correctly.
options.setPrettyPrint(true);
options.setPreserveTypeAnnotations(true);

options.setParseJsDocDocumentation(INCLUDE_DESCRIPTIONS_WITH_WHITESPACE);
options.setCodingConvention(new GoogleCodingConvention());

Expand Down
Expand Up @@ -21,8 +21,6 @@
import com.google.common.base.Function;
import com.google.common.collect.Ordering;
import com.google.javascript.jscomp.AbstractCompiler;
import com.google.javascript.jscomp.CodePrinter;
import com.google.javascript.jscomp.CompilerOptions;
import com.google.javascript.jscomp.DiagnosticType;
import com.google.javascript.jscomp.HotSwapCompilerPass;
import com.google.javascript.jscomp.JSError;
Expand Down Expand Up @@ -202,13 +200,8 @@ public void visit(NodeTraversal t, Node n, Node parent) {
private void reportIfOutOfOrder(List<Node> requiresOrProvides, DiagnosticType warning) {
if (!alphabetical.isOrdered(requiresOrProvides)) {
StringBuilder correctOrder = new StringBuilder();
for (Node require : alphabetical.sortedCopy(requiresOrProvides)) {
CodePrinter.Builder builder = new CodePrinter.Builder(require);
CompilerOptions options = new CompilerOptions();
options.setPrettyPrint(true);
options.setPreserveTypeAnnotations(true);
builder.setCompilerOptions(options);
correctOrder.append(builder.build());
for (Node n : alphabetical.sortedCopy(requiresOrProvides)) {
correctOrder.append(compiler.toSource(n));
}
compiler.report(
JSError.make(requiresOrProvides.get(0), warning, correctOrder.toString()));
Expand Down
Expand Up @@ -21,6 +21,7 @@
import static com.google.javascript.jscomp.lint.CheckRequiresAndProvidesSorted.REQUIRES_NOT_SORTED;

import com.google.javascript.jscomp.Compiler;
import com.google.javascript.jscomp.CompilerOptions;
import com.google.javascript.jscomp.CompilerOptions.LanguageMode;
import com.google.javascript.jscomp.CompilerPass;
import com.google.javascript.jscomp.CompilerTestCase;
Expand All @@ -42,6 +43,14 @@ protected void setUp() throws Exception {
setAcceptedLanguage(LanguageMode.ECMASCRIPT_2017);
}

@Override
protected CompilerOptions getOptions() {
CompilerOptions options = super.getOptions();
options.setPrettyPrint(true);
options.setPreserveTypeAnnotations(true);
return options;
}

public void testNoWarning_require() {
testNoWarning("goog.require('a.b');\ngoog.require('a.c')");
testNoWarning(
Expand Down

0 comments on commit e388e5e

Please sign in to comment.