diff --git a/test/com/google/javascript/jscomp/IntegrationTest.java b/test/com/google/javascript/jscomp/IntegrationTest.java index b8a33780044..9c9bd1d3dc5 100644 --- a/test/com/google/javascript/jscomp/IntegrationTest.java +++ b/test/com/google/javascript/jscomp/IntegrationTest.java @@ -17,7 +17,6 @@ package com.google.javascript.jscomp; import static com.google.common.truth.Truth.assertThat; -import static com.google.javascript.jscomp.CompilerTestCase.lines; import static com.google.javascript.jscomp.TypeValidator.TYPE_MISMATCH_WARNING; import com.google.common.annotations.GwtIncompatible; @@ -1811,7 +1810,7 @@ public void testDisambiguateProperties2() { options.setRemoveDeadCode(true); options.setRemoveAbstractMethods(true); test(options, - LINE_JOINER.join( + lines( "/** @const */ var goog = {};", "goog.abstractMethod = function() {};", "/** @interface */ function I() {}", @@ -1820,7 +1819,7 @@ public void testDisambiguateProperties2() { "/** @override */ Foo.prototype.a = goog.abstractMethod;", "/** @constructor @extends Foo */ function Bar() {}", "/** @override */ Bar.prototype.a = function(x) {};"), - LINE_JOINER.join( + lines( "var goog={};", "goog.abstractMethod = function() {};", "function I(){}", @@ -1830,6 +1829,35 @@ public void testDisambiguateProperties2() { "Bar.prototype.a=function(x){};")); } + public void testDisambiguatePropertiesWithPropertyInvalidationError() { + CompilerOptions options = createCompilerOptions(); + options.setClosurePass(true); + options.setCheckTypes(true); + options.setDisambiguateProperties(true); + options.setPropertyInvalidationErrors( + ImmutableMap.of("a", CheckLevel.ERROR)); + options.setRemoveDeadCode(true); + options.setRemoveAbstractMethods(true); + test(options, + lines( + "function fn(x){return x.a;}", + "/** @interface */ function I() {}", + "I.prototype.a = function(x) {};", + "/** @constructor @implements {I} */ function Foo() {}", + "/** @override */ Foo.prototype.a = function(x) {};", + "/** @constructor @extends Foo */ function Bar() {}", + "/** @override */ Bar.prototype.a = function(x) {};"), + lines( + "function fn(x){return x.a;}", + "function I(){}", + "I.prototype.a=function(x){};", + "function Foo(){}", + "Foo.prototype.a = function(x) {};", + "function Bar(){}", + "Bar.prototype.a=function(x){};"), + DisambiguateProperties.Warnings.INVALIDATION); + } + public void testMarkPureCalls() { String testCode = "function foo() {} foo();"; CompilerOptions options = createCompilerOptions(); diff --git a/test/com/google/javascript/jscomp/IntegrationTestCase.java b/test/com/google/javascript/jscomp/IntegrationTestCase.java index fec779eab5e..df0c6c7c734 100644 --- a/test/com/google/javascript/jscomp/IntegrationTestCase.java +++ b/test/com/google/javascript/jscomp/IntegrationTestCase.java @@ -36,12 +36,20 @@ abstract class IntegrationTestCase extends TestCase { protected static final Joiner LINE_JOINER = Joiner.on('\n'); protected static final Joiner EMPTY_JOINER = Joiner.on(""); + protected static String lines(String line) { + return line; + } + + protected static String lines(String... lines) { + return LINE_JOINER.join(lines); + } + /** Externs for the test */ protected static final ImmutableList DEFAULT_EXTERNS = ImmutableList.of( SourceFile.fromCode( "externs", - LINE_JOINER.join( + lines( "var arguments;", "var undefined;", "/**",