Skip to content

Commit 34125d1

Browse files
committed
Update to closure compiler v20220601, add flag closureIsolatePolyfills
1 parent 1b2388c commit 34125d1

File tree

15 files changed

+402
-17
lines changed

15 files changed

+402
-17
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
See also the [closure compiler changelog](https://github.com/google/closure-compiler/wiki/Releases).
44

5+
## 2.23.0
6+
7+
* Update to closure compiler `v20220601`
8+
* Set default input language of JSCompiler to `ES_NEXT`
9+
* Add flag for isolating polyfills (`closureIsolatePolyfills`)
10+
511
## 2.22.0
612

713
* Compiled against Java 11.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Configure your project's `pom.xml` to run the plugin during the project's build
3838
<plugin>
3939
<groupId>com.github.blutorange</groupId>
4040
<artifactId>closure-compiler-maven-plugin</artifactId>
41-
<version>2.22.0</version>
41+
<version>2.23.0</version>
4242
<configuration>
4343
<!-- Base configuration for all executions (bundles) -->
4444
<baseSourceDir>${project.basedir}/src/main/resources</baseSourceDir>

pom.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<modelVersion>4.0.0</modelVersion>
77
<groupId>com.github.blutorange</groupId>
88
<artifactId>closure-compiler-maven-plugin</artifactId>
9-
<version>2.22.0</version>
9+
<version>2.23.0</version>
1010
<packaging>maven-plugin</packaging>
1111

1212
<name>Closure Compiler Maven Plugin</name>
@@ -75,19 +75,19 @@
7575
<properties>
7676
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
7777
<github.global.server>github</github.global.server>
78-
<maven.version>3.8.3</maven.version>
79-
<maven.embedder.version>3.6.3</maven.embedder.version>
78+
<maven.version>3.8.5</maven.version>
79+
<maven.embedder.version>3.8.5</maven.embedder.version>
8080
<maven-resources-plugin.version>3.1.0</maven-resources-plugin.version>
8181
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
82-
<maven-plugin-plugin.version>3.6.1</maven-plugin-plugin.version>
82+
<maven-plugin-plugin.version>3.6.4</maven-plugin-plugin.version>
8383
<maven-jar-plugin.version>3.1.0</maven-jar-plugin.version>
8484
<maven-javadoc-plugin.version>3.0.1</maven-javadoc-plugin.version>
8585
<maven-jar-plugin>3.1.0</maven-jar-plugin>
8686
<maven-release-plugin-version>2.5.3</maven-release-plugin-version>
8787
<maven-site-plugin.version>3.7.1</maven-site-plugin.version>
8888
<maven-jxr-plugin.version>2.1</maven-jxr-plugin.version>
89-
<maven.plugin.api.version>3.6.3</maven.plugin.api.version>
90-
<maven.plugin.annotations.version>3.6.1</maven.plugin.annotations.version>
89+
<maven.plugin.api.version>3.8.5</maven.plugin.api.version>
90+
<maven.plugin.annotations.version>3.6.4</maven.plugin.annotations.version>
9191
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>
9292
<maven-project-info-reports-plugin.version>3.0.0</maven-project-info-reports-plugin.version>
9393
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
@@ -97,13 +97,13 @@
9797
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
9898
<junit.version>4.13.2</junit.version>
9999
<nexus-staging.version>1.6.8</nexus-staging.version>
100-
<closure.compiler.version>v20211006</closure.compiler.version>
100+
<closure.compiler.version>v20220601</closure.compiler.version>
101101
<dataurl-version>2.0.0</dataurl-version>
102102
<commons-io-version>2.11.0</commons-io-version>
103103
<commons.collections4.version>4.4</commons.collections4.version>
104104
<commons-lang3-version>3.12.0</commons-lang3-version>
105105
<commons-text.version>1.9</commons-text.version>
106-
<gson.version>2.8.8</gson.version>
106+
<gson.version>2.9.0</gson.version>
107107
<plexus.build.api.version>0.0.7</plexus.build.api.version>
108108
<site-maven-plugin.version>0.12</site-maven-plugin.version>
109109
</properties>

src/main/java/com/github/blutorange/maven/plugin/closurecompiler/common/ClosureConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ private static CompilerOptions createCompilerOptions(MinifyMojo mojo) throws Moj
8282
options.setOutputCharset(Charset.forName(mojo.getEncoding()));
8383
options.setPreferLineBreakAtEndOfFile(true);
8484
options.setPreferSingleQuotes(mojo.isClosurePreferSingleQuotes());
85+
options.setIsolatePolyfills(mojo.isClosureIsolatePolyfills());
8586
options.setPrettyPrint(mojo.isClosurePrettyPrint());
8687
options.setPreventLibraryInjection(!mojo.isClosureInjectLibraries());
8788
options.setProcessCommonJSModules(mojo.isClosureProcessCommonJsModules());

src/main/java/com/github/blutorange/maven/plugin/closurecompiler/plugin/MinifyMojo.java

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,36 @@ public class MinifyMojo extends AbstractMojo {
369369
@Parameter(property = "closureJsModuleRoots", defaultValue = "")
370370
private ArrayList<String> closureJsModuleRoots;
371371

372+
/**
373+
* Whether to isolate polyfills from the global scope.
374+
* <p>
375+
* Polyfill isolation is an output mode that may optionally be used alongside
376+
* polyfill injection.
377+
* <p>
378+
* Polyfill isolation was motivated by two related issues.
379+
* <ul>
380+
* <li>sometimes, the existence of Closure polyfills on the page would cause
381+
* other non-Closure-compiled code to break, because of conflicting
382+
* assumptions in a polyfill implementation used by third-party code.<li>
383+
* <li>sometimes, Closure-compiled code would break, because of existing
384+
* polyfills on the page that violated some assumption Closure Compiler makes.
385+
* </li>
386+
* </ul>
387+
* These issues were generally seen by projects compiling code for inclusion
388+
* as a script on third-party websites, along with arbitrary JavaScript not
389+
* under their control.
390+
* <p>
391+
* Polyfill isolation mode attempts to solve these problems by "isolating"
392+
* Closure polyfills and code from other code & polyfills. It is not intended
393+
* to protect against malicious actors; it is instead intended to solve cases
394+
* where other polyfill implementations are either buggy or (more likely) make
395+
* conflicting assumptions.
396+
*
397+
* @since 2.23.0
398+
*/
399+
@Parameter(property = "closureIsolatePolyfills", defaultValue = "false")
400+
private boolean closureIsolatePolyfills;
401+
372402
/**
373403
* Refers to which version of ECMAScript to assume when checking for errors in your code.<br/>
374404
* Possible values are:
@@ -388,14 +418,12 @@ public class MinifyMojo extends AbstractMojo {
388418
* <li>{@code ECMASCRIPT_2020}: Checks code assuming ECMAScript 2020 compliance.</li>
389419
* <li>{@code ECMASCRIPT_2021}: Checks code assuming ECMAScript 2021 compliance.</li>
390420
* <li>{@code ECMASCRIPT_NEXT}: Checks code assuming ECMAScript latest draft standard.</li>
391-
* <li>{@code ECMASCRIPT_NEXT_IN}: Checks code assuming ECMAScript latest draft standard (latest
392-
* features supported for input, but not output yet).</li>
393421
* <li>{@code STABLE} Use stable features</li>
394422
* </ul>
395423
*
396424
* @since 1.7.2
397425
*/
398-
@Parameter(property = "closureLanguageIn", defaultValue = "ECMASCRIPT_2021")
426+
@Parameter(property = "closureLanguageIn", defaultValue = "ECMASCRIPT_NEXT")
399427
private LanguageMode closureLanguageIn;
400428

401429
/**
@@ -412,6 +440,7 @@ public class MinifyMojo extends AbstractMojo {
412440
* <li>{@code ECMASCRIPT_2018}: Outputs code with ECMAScript 2018.</li>
413441
* <li>{@code ECMASCRIPT_2019}: Outputs code with ECMAScript 2019.</li>
414442
* <li>{@code STABLE}: Use stable features</li>
443+
* <li>{@code NO_TRANSPILE}: Do not perform any transpilation.</li>
415444
* </ul>
416445
*
417446
* @since 1.7.5
@@ -424,6 +453,10 @@ public class MinifyMojo extends AbstractMojo {
424453
* <ul>
425454
* <li><code>BROWSER</code>: Requires all module imports to begin with a '.' or '/' and have a
426455
* file extension. Mimics the behavior of MS Edge.</li>
456+
* <li><code>BROWSER_WITH_TRANSFORMED_PREFIXES</code>: A limited superset of
457+
* <code>BROWSER</code> that transforms some path prefixes. For example, one
458+
* could configure this so that "@root/" is replaced with
459+
* "/my/path/to/project/" within import paths.</li>
427460
* <li><code>NODE</code>: Uses the node module rules. Modules which do not begin with a "." or "/"
428461
* character are looked up from the appropriate node_modules folder. Includes the ability to
429462
* require directories and JSON files. Exact match, then ".js", then ".json" file extensions are
@@ -1149,6 +1182,10 @@ public boolean isClosureInjectLibraries() {
11491182
return closureInjectLibraries;
11501183
}
11511184

1185+
public boolean isClosureIsolatePolyfills() {
1186+
return closureIsolatePolyfills;
1187+
}
1188+
11521189
public boolean isClosurePreferSingleQuotes() {
11531190
return closurePreferSingleQuotes;
11541191
}
@@ -1305,6 +1342,10 @@ public void setClosureInjectLibraries(boolean closureInjectLibraries) {
13051342
this.closureInjectLibraries = closureInjectLibraries;
13061343
}
13071344

1345+
public void setClosureIsolatePolyfills(boolean closureIsolatePolyfills) {
1346+
this.closureIsolatePolyfills = closureIsolatePolyfills;
1347+
}
1348+
13081349
public void setClosureJsModuleRoots(ArrayList<String> closureJsModuleRoots) {
13091350
this.closureJsModuleRoots = closureJsModuleRoots;
13101351
}

src/test/java/com/github/blutorange/maven/plugin/closurecompiler/test/MinifyMojoTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ public void testRewritePolyfills() throws Exception {
289289
runMinifyAndAssertDirContent("rewritepolyfills");
290290
}
291291

292+
@Test
293+
public void testIsolatePolyfills() throws Exception {
294+
runMinifyAndAssertDirContent("isolatepolyfills");
295+
}
296+
292297
@Test
293298
public void testSkip() throws Exception {
294299
runMinifyAndAssertDirContent("skip");

src/test/resources/projects/allowdynamicimport/expected/dynamic-imports-false.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ $jscomp.polyfillIsolated = function(a, b, c, d) {
7272
e = e[e.length - 1];
7373
c = $jscomp.IS_SYMBOL_NATIVE && "es6" === c ? d[e] : null;
7474
b = b(c);
75-
null != b && (a ? $jscomp.defineProperty($jscomp.polyfills, e, {configurable:!0, writable:!0, value:b}) : b !== c && (void 0 === $jscomp.propertyToPolyfillSymbol[e] && (c = 1e9 * Math.random() >>> 0, $jscomp.propertyToPolyfillSymbol[e] = $jscomp.IS_SYMBOL_NATIVE ? $jscomp.global.Symbol(e) : $jscomp.POLYFILL_PREFIX + c + "$" + e), $jscomp.defineProperty(d, $jscomp.propertyToPolyfillSymbol[e], {configurable:!0, writable:!0, value:b})));
75+
null != b && (a ? $jscomp.defineProperty($jscomp.polyfills, e, {configurable:!0, writable:!0, value:b}) : b !== c && (void 0 === $jscomp.propertyToPolyfillSymbol[e] && (c = 1E9 * Math.random() >>> 0, $jscomp.propertyToPolyfillSymbol[e] = $jscomp.IS_SYMBOL_NATIVE ? $jscomp.global.Symbol(e) : $jscomp.POLYFILL_PREFIX + c + "$" + e), $jscomp.defineProperty(d, $jscomp.propertyToPolyfillSymbol[e], {configurable:!0, writable:!0, value:b})));
7676
};
7777
$jscomp.underscoreProtoCanBeSet = function() {
7878
var a = {a:!0}, b = {};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
'use strict';for(var a=[{title:"Note 1",content:"Content of Note 1"},{title:"Note 2",content:"Content of Note 2"}],b=document.getElementById("notes"),c=0;c<a.length;c++){var d=a[c].content,e=b,f=textDiv(a[c].title),g=textDiv(d),h=document.createElement("div");h.appendChild(f);h.appendChild(g);e.appendChild(h)}
1+
'use strict';for(var a=document.getElementById("notes"),b=[{title:"Note 1",content:"Content of Note 1"},{title:"Note 2",content:"Content of Note 2"}],c=0;c<b.length;c++){var d=b[c].content,e=a,f=textDiv(b[c].title),g=textDiv(d),h=document.createElement("div");h.appendChild(f);h.appendChild(g);e.appendChild(h)}
22
;
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
'use strict';
2+
var $jscomp = $jscomp || {};
3+
$jscomp.scope = {};
4+
$jscomp.arrayIteratorImpl = function(a) {
5+
var c = 0;
6+
return function() {
7+
return c < a.length ? {done:!1, value:a[c++],} : {done:!0};
8+
};
9+
};
10+
$jscomp.arrayIterator = function(a) {
11+
return {next:$jscomp.arrayIteratorImpl(a)};
12+
};
13+
$jscomp.ASSUME_ES5 = !1;
14+
$jscomp.ASSUME_NO_NATIVE_MAP = !1;
15+
$jscomp.ASSUME_NO_NATIVE_SET = !1;
16+
$jscomp.SIMPLE_FROUND_POLYFILL = !1;
17+
$jscomp.ISOLATE_POLYFILLS = !1;
18+
$jscomp.FORCE_POLYFILL_PROMISE = !1;
19+
$jscomp.FORCE_POLYFILL_PROMISE_WHEN_NO_UNHANDLED_REJECTION = !1;
20+
$jscomp.defineProperty = $jscomp.ASSUME_ES5 || "function" == typeof Object.defineProperties ? Object.defineProperty : function(a, c, b) {
21+
if (a == Array.prototype || a == Object.prototype) {
22+
return a;
23+
}
24+
a[c] = b.value;
25+
return a;
26+
};
27+
$jscomp.getGlobal = function(a) {
28+
a = ["object" == typeof globalThis && globalThis, a, "object" == typeof window && window, "object" == typeof self && self, "object" == typeof global && global,];
29+
for (var c = 0; c < a.length; ++c) {
30+
var b = a[c];
31+
if (b && b.Math == Math) {
32+
return b;
33+
}
34+
}
35+
throw Error("Cannot find global object");
36+
};
37+
$jscomp.global = $jscomp.getGlobal(this);
38+
$jscomp.IS_SYMBOL_NATIVE = "function" === typeof Symbol && "symbol" === typeof Symbol("x");
39+
$jscomp.TRUST_ES6_POLYFILLS = !$jscomp.ISOLATE_POLYFILLS || $jscomp.IS_SYMBOL_NATIVE;
40+
$jscomp.polyfills = {};
41+
$jscomp.propertyToPolyfillSymbol = {};
42+
$jscomp.POLYFILL_PREFIX = "$jscp$";
43+
var $jscomp$lookupPolyfilledValue = function(a, c) {
44+
var b = $jscomp.propertyToPolyfillSymbol[c];
45+
if (null == b) {
46+
return a[c];
47+
}
48+
b = a[b];
49+
return void 0 !== b ? b : a[c];
50+
};
51+
$jscomp.polyfill = function(a, c, b, d) {
52+
c && ($jscomp.ISOLATE_POLYFILLS ? $jscomp.polyfillIsolated(a, c, b, d) : $jscomp.polyfillUnisolated(a, c, b, d));
53+
};
54+
$jscomp.polyfillUnisolated = function(a, c, b, d) {
55+
b = $jscomp.global;
56+
a = a.split(".");
57+
for (d = 0; d < a.length - 1; d++) {
58+
var e = a[d];
59+
if (!(e in b)) {
60+
return;
61+
}
62+
b = b[e];
63+
}
64+
a = a[a.length - 1];
65+
d = b[a];
66+
c = c(d);
67+
c != d && null != c && $jscomp.defineProperty(b, a, {configurable:!0, writable:!0, value:c});
68+
};
69+
$jscomp.polyfillIsolated = function(a, c, b, d) {
70+
var e = a.split(".");
71+
a = 1 === e.length;
72+
d = e[0];
73+
d = !a && d in $jscomp.polyfills ? $jscomp.polyfills : $jscomp.global;
74+
for (var f = 0; f < e.length - 1; f++) {
75+
var g = e[f];
76+
if (!(g in d)) {
77+
return;
78+
}
79+
d = d[g];
80+
}
81+
e = e[e.length - 1];
82+
b = $jscomp.IS_SYMBOL_NATIVE && "es6" === b ? d[e] : null;
83+
c = c(b);
84+
null != c && (a ? $jscomp.defineProperty($jscomp.polyfills, e, {configurable:!0, writable:!0, value:c}) : c !== b && (void 0 === $jscomp.propertyToPolyfillSymbol[e] && (b = 1E9 * Math.random() >>> 0, $jscomp.propertyToPolyfillSymbol[e] = $jscomp.IS_SYMBOL_NATIVE ? $jscomp.global.Symbol(e) : $jscomp.POLYFILL_PREFIX + b + "$" + e), $jscomp.defineProperty(d, $jscomp.propertyToPolyfillSymbol[e], {configurable:!0, writable:!0, value:c})));
85+
};
86+
$jscomp.initSymbol = function() {
87+
};
88+
$jscomp.iteratorPrototype = function(a) {
89+
a = {next:a};
90+
a[Symbol.iterator] = function() {
91+
return this;
92+
};
93+
return a;
94+
};
95+
$jscomp.iteratorFromArray = function(a, c) {
96+
a instanceof String && (a += "");
97+
var b = 0, d = !1, e = {next:function() {
98+
if (!d && b < a.length) {
99+
var f = b++;
100+
return {value:c(f, a[f]), done:!1};
101+
}
102+
d = !0;
103+
return {done:!0, value:void 0};
104+
}};
105+
e[Symbol.iterator] = function() {
106+
return e;
107+
};
108+
return e;
109+
};
110+
$jscomp.polyfill("Array.prototype.values", function(a) {
111+
return a ? a : function() {
112+
return $jscomp.iteratorFromArray(this, function(c, b) {
113+
return b;
114+
});
115+
};
116+
}, "es8", "es3");
117+
function makeUnique(a) {
118+
a = new Set(a);
119+
return Array.from(a);
120+
}
121+
function uniqueByKey(a, c) {
122+
a = new Map(a.map(b => [c(b), b]));
123+
return Array.from(a.values());
124+
}
125+
;

0 commit comments

Comments
 (0)