diff --git a/test/com/google/javascript/jscomp/CompilerTypeTestCase.java b/test/com/google/javascript/jscomp/CompilerTypeTestCase.java index 99f1826ebe9..33ff110a31f 100644 --- a/test/com/google/javascript/jscomp/CompilerTypeTestCase.java +++ b/test/com/google/javascript/jscomp/CompilerTypeTestCase.java @@ -66,7 +66,7 @@ abstract class CompilerTypeTestCase extends BaseJSTypeTestCase { protected Compiler compiler; - protected CompilerOptions getOptions() { + protected CompilerOptions getDefaultOptions() { CompilerOptions options = new CompilerOptions(); options.setLanguageIn(LanguageMode.ECMASCRIPT5); options.setWarningLevel( @@ -102,9 +102,14 @@ protected void checkReportedWarningsHelper(String[] expected) { } @Override - protected void setUp() { + protected void setUp() throws Exception { + super.setUp(); + initializeNewCompiler(getDefaultOptions()); + } + + protected void initializeNewCompiler(CompilerOptions options) { compiler = new Compiler(); - compiler.initOptions(getOptions()); + compiler.initOptions(options); registry = compiler.getTypeRegistry(); initTypes(); } diff --git a/test/com/google/javascript/jscomp/LinkedFlowScopeTest.java b/test/com/google/javascript/jscomp/LinkedFlowScopeTest.java index 18827e0da4a..3fcc2799eb0 100644 --- a/test/com/google/javascript/jscomp/LinkedFlowScopeTest.java +++ b/test/com/google/javascript/jscomp/LinkedFlowScopeTest.java @@ -40,7 +40,7 @@ public final class LinkedFlowScopeTest extends CompilerTypeTestCase { private FlowScope localEntry; @Override - public void setUp() { + public void setUp() throws Exception { super.setUp(); globalScope = TypedScope.createGlobalScope(blockNode); diff --git a/test/com/google/javascript/jscomp/NewTypeInferenceTest.java b/test/com/google/javascript/jscomp/NewTypeInferenceTest.java index 1dbadd5dbd5..966279f9946 100644 --- a/test/com/google/javascript/jscomp/NewTypeInferenceTest.java +++ b/test/com/google/javascript/jscomp/NewTypeInferenceTest.java @@ -16656,7 +16656,7 @@ public void testSimpleInferPrototypeProperties() { } public void testReportUknownTypes() { - this.reportUnknownTypes = true; + compilerOptions.setWarningLevel(DiagnosticGroups.REPORT_UNKNOWN_TYPES, CheckLevel.WARNING); typeCheck( "var x = globalvar;", diff --git a/test/com/google/javascript/jscomp/NewTypeInferenceTestBase.java b/test/com/google/javascript/jscomp/NewTypeInferenceTestBase.java index 08f7e88abf5..f240ffc564b 100644 --- a/test/com/google/javascript/jscomp/NewTypeInferenceTestBase.java +++ b/test/com/google/javascript/jscomp/NewTypeInferenceTestBase.java @@ -18,6 +18,7 @@ import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; +import com.google.javascript.jscomp.CompilerOptions.LanguageMode; import com.google.javascript.rhino.IR; import com.google.javascript.rhino.InputId; import com.google.javascript.rhino.Node; @@ -32,8 +33,8 @@ * @author dimvar@google.com (Dimitris Vardoulakis) */ public abstract class NewTypeInferenceTestBase extends CompilerTypeTestCase { - private List passes; - protected boolean reportUnknownTypes; + + protected CompilerOptions compilerOptions; protected static final String CLOSURE_BASE = LINE_JOINER.join( @@ -170,14 +171,21 @@ public abstract class NewTypeInferenceTestBase extends CompilerTypeTestCase { ""); @Override - protected void setUp() { + protected void setUp() throws Exception { super.setUp(); - this.passes = new ArrayList<>(); + compilerOptions = getDefaultOptions(); } @Override - protected void tearDown() { - this.reportUnknownTypes = false; + protected CompilerOptions getDefaultOptions() { + CompilerOptions compilerOptions = super.getDefaultOptions(); + compilerOptions.setClosurePass(true); + compilerOptions.setNewTypeInference(true); + compilerOptions.setWarningLevel( + DiagnosticGroups.NEW_CHECK_TYPES_ALL_CHECKS, CheckLevel.WARNING); + // EC5 is the highest language level that type inference understands. + compilerOptions.setLanguage(LanguageMode.ECMASCRIPT5); + return compilerOptions; } protected final PassFactory makePassFactory( @@ -191,23 +199,11 @@ protected CompilerPass create(AbstractCompiler compiler) { } private final void parseAndTypeCheck(String externs, String js) { - // NOTE(dimvar): it's unusual that we run setUp for each test in a test - // method rather than once per test method. But the parent class creates a - // new compiler object at every setUp call, and we need that. - setUp(); - final CompilerOptions options = compiler.getOptions(); - options.setClosurePass(true); - options.setNewTypeInference(true); - options.setWarningLevel( - DiagnosticGroups.NEW_CHECK_TYPES_ALL_CHECKS, CheckLevel.WARNING); - if (this.reportUnknownTypes) { - options.setWarningLevel( - DiagnosticGroups.REPORT_UNKNOWN_TYPES, CheckLevel.WARNING); - } + initializeNewCompiler(compilerOptions); compiler.init( ImmutableList.of(SourceFile.fromCode("[externs]", externs)), ImmutableList.of(SourceFile.fromCode("[testcode]", js)), - options); + compilerOptions); Node externsRoot = IR.block(); externsRoot.setIsSyntheticBlock(true); @@ -233,15 +229,17 @@ private final void parseAndTypeCheck(String externs, String js) { DeclaredGlobalExternsOnWindow rewriteExterns = new DeclaredGlobalExternsOnWindow(compiler); + List passes = new ArrayList<>(); passes.add(makePassFactory("globalExternsOnWindow", rewriteExterns)); ProcessClosurePrimitives closurePass = new ProcessClosurePrimitives(compiler, null, CheckLevel.ERROR, false); passes.add(makePassFactory("ProcessClosurePrimitives", closurePass)); - if (options.getLanguageIn() == CompilerOptions.LanguageMode.ECMASCRIPT6_TYPED) { + if (compilerOptions.getLanguageIn() == LanguageMode.ECMASCRIPT6_TYPED) { passes.add(makePassFactory("convertEs6TypedToEs6", new Es6TypedToEs6Converter(compiler))); } - if (options.getLanguageIn().isEs6OrHigher()) { + if (compilerOptions.getLanguageIn().isEs6OrHigher() + && !compilerOptions.getLanguageOut().isEs6OrHigher()) { TranspilationPasses.addEs6EarlyPasses(passes); TranspilationPasses.addEs6LatePasses(passes); } diff --git a/test/com/google/javascript/jscomp/NewTypeInferenceWithTranspilationTest.java b/test/com/google/javascript/jscomp/NewTypeInferenceWithTranspilationTest.java index 36d31f49254..d5b2232d9a4 100644 --- a/test/com/google/javascript/jscomp/NewTypeInferenceWithTranspilationTest.java +++ b/test/com/google/javascript/jscomp/NewTypeInferenceWithTranspilationTest.java @@ -29,9 +29,10 @@ public final class NewTypeInferenceWithTranspilationTest extends NewTypeInferenceTestBase { @Override - protected void setUp() { + protected void setUp() throws Exception { super.setUp(); - compiler.getOptions().setLanguageIn(LanguageMode.ECMASCRIPT6); + compilerOptions.setLanguageIn(LanguageMode.ECMASCRIPT6); + compilerOptions.setLanguageOut(LanguageMode.ECMASCRIPT3); } public void testSimpleClasses() { diff --git a/test/com/google/javascript/jscomp/NewTypeInferenceWithTypeSyntaxTranspilationTest.java b/test/com/google/javascript/jscomp/NewTypeInferenceWithTypeSyntaxTranspilationTest.java index f7666c2db42..9a24f859c26 100644 --- a/test/com/google/javascript/jscomp/NewTypeInferenceWithTypeSyntaxTranspilationTest.java +++ b/test/com/google/javascript/jscomp/NewTypeInferenceWithTypeSyntaxTranspilationTest.java @@ -34,9 +34,10 @@ public final class NewTypeInferenceWithTypeSyntaxTranspilationTest extends NewTypeInferenceTestBase { @Override - protected void setUp() { + protected void setUp() throws Exception { super.setUp(); - compiler.getOptions().setLanguageIn(LanguageMode.ECMASCRIPT6_TYPED); + compilerOptions.setLanguageIn(LanguageMode.ECMASCRIPT6_TYPED); + compilerOptions.setLanguageOut(LanguageMode.ECMASCRIPT3); } public void testSimpleAnnotationsNoWarnings() { @@ -214,6 +215,8 @@ public void testAmbientDeclarationsInCode() { } public void testGetterReturnNonDeclaredType() { + // getters cannot be transpiled to EC3 + compilerOptions.setLanguageOut(LanguageMode.ECMASCRIPT5); typeCheck( "var x = {get a(): number { return 'str'; }}", NewTypeInference.RETURN_NONDECLARED_TYPE); diff --git a/test/com/google/javascript/jscomp/PolymerBehaviorExtractorTest.java b/test/com/google/javascript/jscomp/PolymerBehaviorExtractorTest.java index 61b20c62f9c..910477b9e1d 100644 --- a/test/com/google/javascript/jscomp/PolymerBehaviorExtractorTest.java +++ b/test/com/google/javascript/jscomp/PolymerBehaviorExtractorTest.java @@ -31,7 +31,7 @@ public class PolymerBehaviorExtractorTest extends CompilerTypeTestCase { private Node behaviorArray; @Override - protected void setUp() { + protected void setUp() throws Exception { super.setUp(); behaviorArray = null; } diff --git a/test/com/google/javascript/jscomp/PolymerClassDefinitionTest.java b/test/com/google/javascript/jscomp/PolymerClassDefinitionTest.java index 98f5395b16b..e8b5f021c53 100644 --- a/test/com/google/javascript/jscomp/PolymerClassDefinitionTest.java +++ b/test/com/google/javascript/jscomp/PolymerClassDefinitionTest.java @@ -25,7 +25,7 @@ public final class PolymerClassDefinitionTest extends CompilerTypeTestCase { private Node polymerCall; @Override - protected void setUp() { + protected void setUp() throws Exception { super.setUp(); polymerCall = null; } diff --git a/test/com/google/javascript/jscomp/PolymerClassRewriterTest.java b/test/com/google/javascript/jscomp/PolymerClassRewriterTest.java index 99064c4c7c2..0f9bded9b0c 100644 --- a/test/com/google/javascript/jscomp/PolymerClassRewriterTest.java +++ b/test/com/google/javascript/jscomp/PolymerClassRewriterTest.java @@ -60,7 +60,7 @@ public final class PolymerClassRewriterTest extends CompilerTypeTestCase { private Node polymerCall; @Override - protected void setUp() { + protected void setUp() throws Exception { super.setUp(); polymerCall = null; rootNode = null; @@ -116,7 +116,7 @@ public void testPathAssignmentTarget() { } @Override - protected CompilerOptions getOptions() { + protected CompilerOptions getDefaultOptions() { CompilerOptions options = new CompilerOptions(); options.setLanguageIn(LanguageMode.ECMASCRIPT5); options.setWarningLevel( diff --git a/test/com/google/javascript/jscomp/SemanticReverseAbstractInterpreterTest.java b/test/com/google/javascript/jscomp/SemanticReverseAbstractInterpreterTest.java index 26149bceee4..2e8d539d4e5 100644 --- a/test/com/google/javascript/jscomp/SemanticReverseAbstractInterpreterTest.java +++ b/test/com/google/javascript/jscomp/SemanticReverseAbstractInterpreterTest.java @@ -33,7 +33,7 @@ public final class SemanticReverseAbstractInterpreterTest private TypedScope functionScope; @Override - protected void setUp() { + protected void setUp() throws Exception { super.setUp(); interpreter = new SemanticReverseAbstractInterpreter(registry); diff --git a/test/com/google/javascript/jscomp/TypeCheckTest.java b/test/com/google/javascript/jscomp/TypeCheckTest.java index 40cb24ade84..87356ab8c77 100644 --- a/test/com/google/javascript/jscomp/TypeCheckTest.java +++ b/test/com/google/javascript/jscomp/TypeCheckTest.java @@ -56,7 +56,7 @@ public final class TypeCheckTest extends CompilerTypeTestCase { + " make sure to give it a type.)"; @Override - public void setUp() { + public void setUp() throws Exception { super.setUp(); } diff --git a/test/com/google/javascript/jscomp/TypeTransformationTest.java b/test/com/google/javascript/jscomp/TypeTransformationTest.java index 5f447940b8a..cd2fa39a4ab 100644 --- a/test/com/google/javascript/jscomp/TypeTransformationTest.java +++ b/test/com/google/javascript/jscomp/TypeTransformationTest.java @@ -39,7 +39,7 @@ public final class TypeTransformationTest extends CompilerTypeTestCase { + "var n = 10;"; @Override - public void setUp() { + public void setUp() throws Exception { super.setUp(); errorReporter = new TestErrorReporter(null, null); initRecordTypeTests();