Skip to content

Commit

Permalink
Change the default input language to ES 2017 to match the command-lin…
Browse files Browse the repository at this point in the history
…e default.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=173947967
  • Loading branch information
tbreisacher authored and brad4d committed Oct 31, 2017
1 parent 63a7a96 commit 6ee9f39
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/CompilerOptions.java
Expand Up @@ -1207,7 +1207,7 @@ public void setPrintConfig(boolean printConfig) {
*/
public CompilerOptions() {
// Accepted language
languageIn = LanguageMode.ECMASCRIPT3;
languageIn = LanguageMode.ECMASCRIPT_2017;
languageOut = LanguageMode.NO_TRANSPILE;

// Which environment to use
Expand Down
6 changes: 2 additions & 4 deletions src/com/google/javascript/jscomp/ComposeWarningsGuard.java
Expand Up @@ -46,8 +46,7 @@ public class ComposeWarningsGuard extends WarningsGuard {
private final Map<WarningsGuard, Integer> orderOfAddition = new HashMap<>();
private int numberOfAdds = 0;

private final Comparator<WarningsGuard> guardComparator =
new GuardComparator(orderOfAddition);
private final Comparator<WarningsGuard> guardComparator = new GuardComparator(orderOfAddition);
private boolean demoteErrors = false;

private static class GuardComparator
Expand All @@ -73,8 +72,7 @@ public int compare(WarningsGuard a, WarningsGuard b) {
}

// The order that the guards are applied in.
private final TreeSet<WarningsGuard> guards =
new TreeSet<>(guardComparator);
private final TreeSet<WarningsGuard> guards = new TreeSet<>(guardComparator);

public ComposeWarningsGuard(List<WarningsGuard> guards) {
addGuards(guards);
Expand Down
2 changes: 2 additions & 0 deletions test/com/google/debugging/sourcemap/SourceMapTestCase.java
Expand Up @@ -22,6 +22,7 @@
import com.google.debugging.sourcemap.proto.Mapping.OriginalMapping;
import com.google.javascript.jscomp.Compiler;
import com.google.javascript.jscomp.CompilerOptions;
import com.google.javascript.jscomp.CompilerOptions.LanguageMode;
import com.google.javascript.jscomp.Result;
import com.google.javascript.jscomp.SourceFile;
import com.google.javascript.jscomp.SourceMap;
Expand Down Expand Up @@ -262,6 +263,7 @@ protected RunResult compile(String js, String fileName) {

protected CompilerOptions getCompilerOptions() {
CompilerOptions options = new CompilerOptions();
options.setLanguageIn(LanguageMode.ECMASCRIPT3);
options.setSourceMapOutputPath("testcode_source_map.out");
options.setSourceMapFormat(getSourceMapFormat());
options.setSourceMapDetailLevel(detailLevel);
Expand Down
Expand Up @@ -22,6 +22,7 @@

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.javascript.jscomp.CompilerOptions.LanguageMode;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
Expand Down Expand Up @@ -67,6 +68,7 @@ protected void setUp() throws Exception {
*/
protected CompilerOptions getOptions(DiagnosticGroup... typesOfGuard) {
CompilerOptions options = new CompilerOptions();
options.setLanguageIn(LanguageMode.ECMASCRIPT3);
options.declaredGlobalExternsOnWindow = false;
options.setClosurePass(true);
// These are the options that are always on in JsDev which is the only
Expand Down
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.javascript.jscomp;

import com.google.javascript.jscomp.CompilerOptions.LanguageMode;

/**
* Tests that the property renaming primitive goog.reflect.objectProperty
Expand Down Expand Up @@ -145,6 +146,8 @@ public void testStaticPropRenameSimple() {
@Override
protected CompilerOptions createCompilerOptions() {
CompilerOptions options = new CompilerOptions();
options.setLanguageIn(LanguageMode.ECMASCRIPT_2017);
options.setLanguageOut(LanguageMode.ECMASCRIPT3);
if (useSimpleMode) {
CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
} else {
Expand Down
Expand Up @@ -16,6 +16,7 @@

package com.google.javascript.jscomp;

import com.google.javascript.jscomp.CompilerOptions.LanguageMode;
import com.google.javascript.jscomp.deps.ModuleLoader;

/**
Expand Down Expand Up @@ -314,6 +315,7 @@ public void testCrossModuleSubclass6() {
@Override
protected CompilerOptions createCompilerOptions() {
CompilerOptions options = new CompilerOptions();
options.setLanguageIn(LanguageMode.ECMASCRIPT3);
options.setCodingConvention(new GoogleCodingConvention());
WarningLevel.VERBOSE.setOptionsForWarningLevel(options);
options.setProcessCommonJSModules(true);
Expand Down
24 changes: 16 additions & 8 deletions test/com/google/javascript/jscomp/CompilerTest.java
Expand Up @@ -114,6 +114,7 @@ public void testPrintExterns() {
List<SourceFile> externs =
ImmutableList.of(SourceFile.fromCode("extern", "function alert(x) {}"));
CompilerOptions options = new CompilerOptions();
options.setLanguageIn(LanguageMode.ECMASCRIPT3);
options.setPrintExterns(true);
Compiler compiler = new Compiler();
compiler.init(externs, ImmutableList.<SourceFile>of(), options);
Expand All @@ -131,8 +132,7 @@ public void testLocalUndefined() throws Exception {
//
// This test is just to make sure that the compiler doesn't crash.
CompilerOptions options = new CompilerOptions();
CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(
options);
CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
Compiler compiler = new Compiler();
SourceFile externs = SourceFile.fromCode("externs.js", "");
SourceFile input = SourceFile.fromCode("input.js",
Expand Down Expand Up @@ -318,6 +318,7 @@ public void testApplyInputSourceMaps() throws Exception {
originalSourcePosition));

CompilerOptions options = new CompilerOptions();
options.setLanguageIn(LanguageMode.ECMASCRIPT3);
options.sourceMapOutputPath = "fake/source_map_path.js.map";
options.inputSourceMaps = inputSourceMaps;
options.applyInputSourceMaps = true;
Expand Down Expand Up @@ -874,6 +875,9 @@ static Result test(String js, String expected, DiagnosticType error) {

public void testConsecutiveSemicolons() {
Compiler compiler = new Compiler();
CompilerOptions options = new CompilerOptions();
options.setEmitUseStrict(false);
compiler.initOptions(options);
String js = "if(a);";
Node n = compiler.parseTestCode(js);
Compiler.CodeBuilder cb = new Compiler.CodeBuilder();
Expand Down Expand Up @@ -914,6 +918,7 @@ public void testWarningsFiltering() {
public void testExportSymbolReservesNamesForRenameVars() {
Compiler compiler = new Compiler();
CompilerOptions options = new CompilerOptions();
options.setEmitUseStrict(false);
options.setClosurePass(true);
options.setVariableRenaming(VariableRenamingPolicy.ALL);

Expand All @@ -923,12 +928,13 @@ public void testExportSymbolReservesNamesForRenameVars() {
Result result = compiler.compile(EMPTY_EXTERNS, inputs, options);

assertTrue(result.success);
assertEquals("var b;var c;b.exportSymbol(\"a\",c);", compiler.toSource());
assertThat(compiler.toSource()).isEqualTo("var b;var c;b.exportSymbol(\"a\",c);");
}

public void testGenerateExportsReservesNames() {
Compiler compiler = new Compiler();
CompilerOptions options = new CompilerOptions();
options.setEmitUseStrict(false);
options.setClosurePass(true);
options.setVariableRenaming(VariableRenamingPolicy.ALL);
options.setGenerateExports(true);
Expand All @@ -939,8 +945,7 @@ public void testGenerateExportsReservesNames() {
Result result = compiler.compile(EMPTY_EXTERNS, inputs, options);

assertTrue(result.success);
assertEquals("var b;var c={};b.exportSymbol(\"a\",c);",
compiler.toSource());
assertThat(compiler.toSource()).isEqualTo("var b;var c={};b.exportSymbol(\"a\",c);");
}

private static final DiagnosticType TEST_ERROR =
Expand Down Expand Up @@ -1432,9 +1437,12 @@ public Class<String> getType() {
}

private static CompilerOptions createNewFlagBasedOptions() {
CompilerOptions opt = new CompilerOptions();
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(opt);
return opt;
CompilerOptions options = new CompilerOptions();
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
options.setLanguageIn(LanguageMode.ECMASCRIPT3);
options.setLanguageOut(LanguageMode.ECMASCRIPT3);
options.setEmitUseStrict(false);
return options;
}

private static byte[] serialize(Object obj) throws IOException {
Expand Down
Expand Up @@ -160,6 +160,9 @@ private Node getSideEffectsHookNode() {
private void checkKeepSimplifiedShortCircuitExpr(Node root,
List<String> expected) {
Compiler compiler = new Compiler();
CompilerOptions options = new CompilerOptions();
options.setEmitUseStrict(false);
compiler.initOptions(options);
List<Node> replacements = new ArrayList<>();
GetReplacementSideEffectSubexpressions accumulator =
new GetReplacementSideEffectSubexpressions(compiler, replacements);
Expand All @@ -177,6 +180,9 @@ private void checkKeepSimplifiedHookExpr(Node root,
boolean elseHasSideEffects,
List<String> expected) {
Compiler compiler = new Compiler();
CompilerOptions options = new CompilerOptions();
options.setEmitUseStrict(false);
compiler.initOptions(options);
List<Node> replacements = new ArrayList<>();
GetReplacementSideEffectSubexpressions accumulator =
new GetReplacementSideEffectSubexpressions(compiler, replacements);
Expand Down
2 changes: 2 additions & 0 deletions test/com/google/javascript/jscomp/GoldenFileComparer.java
Expand Up @@ -20,6 +20,7 @@

import com.google.common.collect.ImmutableList;
import com.google.common.io.Files;
import com.google.javascript.jscomp.CompilerOptions.LanguageMode;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -107,6 +108,7 @@ private static void compileAndCompare(
*/
public static CompilerOptions options() {
CompilerOptions options = new CompilerOptions();
options.setLanguageIn(LanguageMode.ECMASCRIPT3);
// Instrumentation done
options.setPrettyPrint(true);
return options;
Expand Down

0 comments on commit 6ee9f39

Please sign in to comment.