Skip to content

Commit 1a8cca2

Browse files
concavelenzlauraharker
authored andcommitted
Create a warn_on_disambiguation_failure_for flag to expose CompilerOptions#setPropertyInvalidationErrors to the command-line.
This emits warnings when configured property can not be disambiguated due to various ambiguous uses. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=208698924
1 parent d12ef3e commit 1a8cca2

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

test/com/google/javascript/jscomp/IntegrationTest.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.google.javascript.jscomp;
1818

1919
import static com.google.common.truth.Truth.assertThat;
20-
import static com.google.javascript.jscomp.CompilerTestCase.lines;
2120
import static com.google.javascript.jscomp.TypeValidator.TYPE_MISMATCH_WARNING;
2221

2322
import com.google.common.annotations.GwtIncompatible;
@@ -1811,7 +1810,7 @@ public void testDisambiguateProperties2() {
18111810
options.setRemoveDeadCode(true);
18121811
options.setRemoveAbstractMethods(true);
18131812
test(options,
1814-
LINE_JOINER.join(
1813+
lines(
18151814
"/** @const */ var goog = {};",
18161815
"goog.abstractMethod = function() {};",
18171816
"/** @interface */ function I() {}",
@@ -1820,7 +1819,7 @@ public void testDisambiguateProperties2() {
18201819
"/** @override */ Foo.prototype.a = goog.abstractMethod;",
18211820
"/** @constructor @extends Foo */ function Bar() {}",
18221821
"/** @override */ Bar.prototype.a = function(x) {};"),
1823-
LINE_JOINER.join(
1822+
lines(
18241823
"var goog={};",
18251824
"goog.abstractMethod = function() {};",
18261825
"function I(){}",
@@ -1830,6 +1829,35 @@ public void testDisambiguateProperties2() {
18301829
"Bar.prototype.a=function(x){};"));
18311830
}
18321831

1832+
public void testDisambiguatePropertiesWithPropertyInvalidationError() {
1833+
CompilerOptions options = createCompilerOptions();
1834+
options.setClosurePass(true);
1835+
options.setCheckTypes(true);
1836+
options.setDisambiguateProperties(true);
1837+
options.setPropertyInvalidationErrors(
1838+
ImmutableMap.of("a", CheckLevel.ERROR));
1839+
options.setRemoveDeadCode(true);
1840+
options.setRemoveAbstractMethods(true);
1841+
test(options,
1842+
lines(
1843+
"function fn(x){return x.a;}",
1844+
"/** @interface */ function I() {}",
1845+
"I.prototype.a = function(x) {};",
1846+
"/** @constructor @implements {I} */ function Foo() {}",
1847+
"/** @override */ Foo.prototype.a = function(x) {};",
1848+
"/** @constructor @extends Foo */ function Bar() {}",
1849+
"/** @override */ Bar.prototype.a = function(x) {};"),
1850+
lines(
1851+
"function fn(x){return x.a;}",
1852+
"function I(){}",
1853+
"I.prototype.a=function(x){};",
1854+
"function Foo(){}",
1855+
"Foo.prototype.a = function(x) {};",
1856+
"function Bar(){}",
1857+
"Bar.prototype.a=function(x){};"),
1858+
DisambiguateProperties.Warnings.INVALIDATION);
1859+
}
1860+
18331861
public void testMarkPureCalls() {
18341862
String testCode = "function foo() {} foo();";
18351863
CompilerOptions options = createCompilerOptions();

test/com/google/javascript/jscomp/IntegrationTestCase.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,20 @@ abstract class IntegrationTestCase extends TestCase {
3636
protected static final Joiner LINE_JOINER = Joiner.on('\n');
3737
protected static final Joiner EMPTY_JOINER = Joiner.on("");
3838

39+
protected static String lines(String line) {
40+
return line;
41+
}
42+
43+
protected static String lines(String... lines) {
44+
return LINE_JOINER.join(lines);
45+
}
46+
3947
/** Externs for the test */
4048
protected static final ImmutableList<SourceFile> DEFAULT_EXTERNS =
4149
ImmutableList.of(
4250
SourceFile.fromCode(
4351
"externs",
44-
LINE_JOINER.join(
52+
lines(
4553
"var arguments;",
4654
"var undefined;",
4755
"/**",

0 commit comments

Comments
 (0)