Skip to content

Commit 5d8154c

Browse files
committed
fix(esm): fix minify es5 for esm
1 parent bb48234 commit 5d8154c

7 files changed

Lines changed: 35 additions & 13 deletions

File tree

readme.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,18 @@ For the small minority of browsers that do not support modern browser features a
157157
- [async/await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) *(transpiled to promises)*
158158
- [fetch()](https://github.com/github/fetch)
159159
- [URL](https://github.com/lifaon74/url-polyfill)
160+
- [Array.fill](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)
160161
- [Array.find](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
161162
- [Array.findIndex](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
162163
- [Array.from](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
163164
- [Array.includes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
164-
- [Array.fill](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)
165165
- [Element.closest](https://github.com/jonathantneal/closest)
166166
- [Element.matches](https://github.com/jonathantneal/closest)
167167
- [Element.remove](https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove)
168+
- [Map/Set/WeakMap/WeakSet](https://github.com/WebReflection/es6-collections)
168169
- [Object.assign](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
169170
- [Object.entries](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
170-
- [Object.values](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
171+
- [Object.values](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
171172
- [String.startsWith](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)
172173
- [String.endsWith](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
173174
- [String.includes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)

scripts/build-polyfills.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,18 @@ module.exports = async function buildPolyfills(transpiledPolyfillsDir, outputPol
5555

5656
const minify = terser.minify(transpile.outputText);
5757

58+
const cssShimOutput = minify.code;
59+
60+
const mapPolyfillFilePath = path.join(SRC_DIR, 'map.js');
61+
const mapPolyfill = fs.readFileSync(mapPolyfillFilePath, 'utf8');
62+
63+
const cssShimMapPolyfill = mapPolyfill + '\n' + cssShimOutput;
64+
5865
const esmFilePath = path.join(esmDir, 'css-shim.js');
5966
const es5FilePath = path.join(es5Dir, 'css-shim.js');
6067

61-
fs.writeFileSync(esmFilePath, esmWrap(minify.code));
62-
fs.writeFileSync(es5FilePath, minify.code);
68+
fs.writeFileSync(esmFilePath, esmWrap(cssShimMapPolyfill));
69+
fs.writeFileSync(es5FilePath, cssShimMapPolyfill);
6370
};
6471

6572

src/client/polyfills/array.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*!
2+
Array.prototype.fill
3+
*/
4+
Array.prototype.fill||Object.defineProperty(Array.prototype,"fill",{value:function(t){var r,e,i,n,o,a,l;if(null==this)throw new TypeError("this is null or not defined");for(e=(r=Object(this)).length>>>0,n=(i=arguments[1]>>0)<0?Math.max(e+i,0):Math.min(i,e),l=(a=void 0===(o=arguments[2])?e:o>>0)<0?Math.max(e+a,0):Math.min(a,e);n<l;)r[n]=t,n++;return r}});
5+
16
/*!
27
Array.prototype.find
38
*/
@@ -15,7 +20,3 @@ Number(k.length);a=isNaN(a)?0:0!==a&&isFinite(a)?(0<a?1:-1)*Math.floor(Math.abs(
1520
Array.prototype.includes
1621
*/
1722
Array.prototype.includes||Object.defineProperty(Array.prototype,"includes",{writable:!0,configurable:!0,value:function(r,e){if(null==this)throw new TypeError('"this" is null or not defined');var t=Object(this),n=t.length>>>0;if(0===n)return!1;var i,o,a=0|e,u=Math.max(0<=a?a:n-Math.abs(a),0);for(;u<n;){if((i=t[u])===(o=r)||"number"==typeof i&&"number"==typeof o&&isNaN(i)&&isNaN(o))return!0;u++}return!1}});
18-
/*!
19-
Array.prototype.fill
20-
*/
21-
Array.prototype.fill||Object.defineProperty(Array.prototype,"fill",{value:function(t){var r,e,i,n,o,a,l;if(null==this)throw new TypeError("this is null or not defined");for(e=(r=Object(this)).length>>>0,n=(i=arguments[1]>>0)<0?Math.max(e+i,0):Math.min(i,e),l=(a=void 0===(o=arguments[2])?e:o>>0)<0?Math.max(e+a,0):Math.min(a,e);n<l;)r[n]=t,n++;return r}});

src/client/polyfills/index.js

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/polyfills/map.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/app/app-polyfills.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const INLINE_POLYFILLS = [
4040
'object.js',
4141
'string.js',
4242
'promise.js',
43+
'map.js',
4344
'fetch.js',
4445
'url.js'
4546
];

src/compiler/app/build-core-content.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export async function minifyCore(config: d.Config, compilerCtx: d.CompilerCtx, s
5050
opts.output.ecma = 5;
5151
opts.compress.ecma = 5;
5252
opts.compress.arrows = false;
53+
opts.compress.module = false;
5354

5455
} else {
5556
opts.ecma = 7;
@@ -58,8 +59,6 @@ export async function minifyCore(config: d.Config, compilerCtx: d.CompilerCtx, s
5859
opts.compress.module = true;
5960
}
6061

61-
opts.compress.toplevel = true;
62-
6362
if (config.minifyJs) {
6463
if (sourceTarget !== 'es5') {
6564
opts.compress.arrows = true;
@@ -139,8 +138,9 @@ const DEV_MINIFY_OPTS: any = {
139138
sequences: true,
140139
side_effects: true,
141140
switches: false,
142-
typeofs: false,
141+
toplevel: true,
143142
top_retain: false,
143+
typeofs: false,
144144
unsafe: false,
145145
unsafe_arrows: false,
146146
unsafe_comps: false,
@@ -206,6 +206,7 @@ const PROD_MINIFY_OPTS: any = {
206206
sequences: true,
207207
side_effects: true,
208208
switches: true,
209+
toplevel: true,
209210
typeofs: true,
210211
unsafe: false,
211212
unsafe_arrows: false,

0 commit comments

Comments
 (0)