Skip to content

Commit

Permalink
Create a warn_on_disambiguation_failure_for flag to expose CompilerOp…
Browse files Browse the repository at this point in the history
…tions#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
  • Loading branch information
concavelenz authored and lauraharker committed Aug 14, 2018
1 parent d12ef3e commit 1a8cca2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
34 changes: 31 additions & 3 deletions test/com/google/javascript/jscomp/IntegrationTest.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {}",
Expand All @@ -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(){}",
Expand All @@ -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();
Expand Down
10 changes: 9 additions & 1 deletion test/com/google/javascript/jscomp/IntegrationTestCase.java
Expand Up @@ -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<SourceFile> DEFAULT_EXTERNS =
ImmutableList.of(
SourceFile.fromCode(
"externs",
LINE_JOINER.join(
lines(
"var arguments;",
"var undefined;",
"/**",
Expand Down

0 comments on commit 1a8cca2

Please sign in to comment.