diff --git a/src/com/google/javascript/jscomp/Compiler.java b/src/com/google/javascript/jscomp/Compiler.java index 945f7e7c8dd..ab65f624d6e 100644 --- a/src/com/google/javascript/jscomp/Compiler.java +++ b/src/com/google/javascript/jscomp/Compiler.java @@ -384,7 +384,7 @@ protected void reconcileOptionsWithGuards() { // But we do not want to see the warnings from OTI. if (options.getNewTypeInference()) { options.checkTypes = true; - // Supress warnings from the const checks of CheckAccessControls so as to avoid + // Suppress warnings from the const checks of CheckAccessControls so as to avoid // duplication. options.setWarningLevel(DiagnosticGroups.ACCESS_CONTROLS_CONST, CheckLevel.OFF); if (!options.reportOTIErrorsUnderNTI) { diff --git a/src/com/google/javascript/rhino/JSDocInfoBuilder.java b/src/com/google/javascript/rhino/JSDocInfoBuilder.java index 12666d66078..aaea006f37f 100644 --- a/src/com/google/javascript/rhino/JSDocInfoBuilder.java +++ b/src/com/google/javascript/rhino/JSDocInfoBuilder.java @@ -41,6 +41,7 @@ import com.google.common.base.Preconditions; import com.google.javascript.rhino.JSDocInfo.Visibility; +import java.util.HashSet; import java.util.List; import java.util.Set; import javax.annotation.Nullable; @@ -66,6 +67,9 @@ public final class JSDocInfoBuilder { // the current marker, if any. private JSDocInfo.Marker currentMarker; + // the set of unique license texts + private final Set licenseTexts; + public JSDocInfoBuilder(boolean parseDocumentation) { this(new JSDocInfo(parseDocumentation), parseDocumentation, false); } @@ -75,6 +79,7 @@ private JSDocInfoBuilder( this.currentInfo = info; this.parseDocumentation = parseDocumentation; this.populated = populated; + this.licenseTexts = new HashSet<>(); } public static JSDocInfoBuilder copyFrom(JSDocInfo info) { @@ -814,10 +819,15 @@ public boolean recordLicense(String license) { } public boolean addLicense(String license) { + if (!licenseTexts.add(license)) { + return false; + } + String txt = currentInfo.getLicense(); if (txt == null) { txt = ""; } + currentInfo.setLicense(txt + license); populated = true; return true; diff --git a/test/com/google/javascript/jscomp/CompilerTest.java b/test/com/google/javascript/jscomp/CompilerTest.java index b9402b8fc36..5a4d4b9590d 100644 --- a/test/com/google/javascript/jscomp/CompilerTest.java +++ b/test/com/google/javascript/jscomp/CompilerTest.java @@ -492,7 +492,7 @@ public void testMultipleUniqueImportantComments() throws Exception { assertEquals(expected, compiler.toSource()); } - public void testMultipleIndenticalImportantComments() throws Exception { + public void testMultipleIdenticalImportantComments() throws Exception { String js1 = "/*! Identical license here */\n" + "var x;"; String js2 = "/*! Identical license here */\n" + "var y;"; String expected = "/*\n Identical license here */\n"; @@ -618,25 +618,29 @@ public void testMultipleUniqueLicenses() throws Exception { assertEquals(expected, compiler.toSource()); } - public void testMultipleIndenticalLicenses() throws Exception { + public void testMultipleIdenticalLicenses() throws Exception { String js1 = "/** @license Identical license here */\n" + "var x;"; String js2 = "/** @license Identical license here */\n" + "var y;"; + String js3 = "/** @license Identical license here */\n" + + "var z;\n" + + "/** @license Identical license here */"; String expected = "/*\n Identical license here */\n"; Compiler compiler = new Compiler(); CompilerOptions options = createNewFlagBasedOptions(); List inputs = ImmutableList.of( SourceFile.fromCode("testcode1", js1), - SourceFile.fromCode("testcode2", js2)); + SourceFile.fromCode("testcode2", js2), + SourceFile.fromCode("bundled", js3)); Result result = compiler.compile(EMPTY_EXTERNS, inputs, options); assertTrue(Joiner.on(",").join(result.errors), result.success); assertEquals(expected, compiler.toSource()); } - public void testIndenticalLicenseAndImportantComent() throws Exception { + public void testIdenticalLicenseAndImportantComment() throws Exception { String js1 = "/** @license Identical license here */\n" + "var x;"; String js2 = "/*! Identical license here */\n" + "var y;"; String expected = "/*\n Identical license here */\n";