es-module-shims 1.4.3 → 1.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ES Module Shims 1.4.4
2
+ * Fix: import.meta.resolve support for inline scripts (https://github.com/guybedford/es-module-shims/pull/251)
3
+ * Fix: CSS imports unquoted URL normalization (https://github.com/guybedford/es-module-shims/pull/252)
4
+ * Fix: Reword polyfill info message (https://github.com/guybedford/es-module-shims/pull/253)
5
+
1
6
  ES Module Shims 1.4.3 (2022/01/25)
2
7
  * Feature: Support import map overrides when existing resolution matches new resolution (https://github.com/guybedford/es-module-shims/pull/249, @vovacodes)
3
8
  * Fix: Import assertions support with dynamic imports (https://github.com/guybedford/es-module-shims/pull/248)
package/README.md CHANGED
@@ -27,7 +27,7 @@ Because we are still using the native module loader the edge cases work out comp
27
27
  Include ES Module Shims with a `async` attribute on the script, then include an import map and module scripts normally:
28
28
 
29
29
  ```html
30
- <script async src="https://ga.jspm.io/npm:es-module-shims@1.4.3/dist/es-module-shims.js"></script>
30
+ <script async src="https://ga.jspm.io/npm:es-module-shims@1.4.4/dist/es-module-shims.js"></script>
31
31
 
32
32
  <!-- https://generator.jspm.io/#U2NhYGBkDM0rySzJSU1hKEpNTC5xMLTQM9Az0C1K1jMAAKFS5w0gAA -->
33
33
  <script type="importmap">
@@ -287,7 +287,7 @@ import sheet from 'https://site.com/sheet.css' assert { type: 'css' };
287
287
  To support the polyfill or shim of this feature, the [Constructable Stylesheets polyfill](https://github.com/calebdwilliams/construct-style-sheets#readme) must be separately included in browsers not supporting [Constructable Stylesheets](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/CSSStyleSheet) eg via:
288
288
 
289
289
  ```html
290
- <script async src="https://unpkg.com/construct-style-sheets-polyfill@3.0.0/dist/adoptedStyleSheets.js"></script>
290
+ <script async src="https://unpkg.com/construct-style-sheets-polyfill@3.1.0/dist/adoptedStyleSheets.js"></script>
291
291
  ```
292
292
 
293
293
  For more information see the [web.dev article](https://web.dev/css-module-scripts/).
@@ -1,11 +1,10 @@
1
- /* ES Module Shims 1.4.3 */
1
+ /* ES Module Shims 1.4.4 */
2
2
  (function () {
3
3
 
4
- const uaMatch = navigator.userAgent.match(/(Edge|Safari)\/\d+\.\d+/);
5
- const edge = uaMatch && uaMatch[1] === 'Edge';
6
- const safari = uaMatch && uaMatch[1] === 'Safari';
4
+ const edge = !!navigator.userAgent.match(/Edge\/\d+\.\d+/);
5
+ const safari = !!window.safari;
7
6
 
8
- let baseUrl;
7
+ const baseUrl = document.baseURI;
9
8
 
10
9
  function createBlob (source, type = 'text/javascript') {
11
10
  return URL.createObjectURL(new Blob([source], { type }));
@@ -13,17 +12,6 @@
13
12
 
14
13
  const noop = () => {};
15
14
 
16
- const baseEl = document.querySelector('base[href]');
17
- if (baseEl)
18
- baseUrl = baseEl.href;
19
-
20
- if (!baseUrl && typeof location !== 'undefined') {
21
- baseUrl = location.href.split('#')[0].split('?')[0];
22
- const lastSepIndex = baseUrl.lastIndexOf('/');
23
- if (lastSepIndex !== -1)
24
- baseUrl = baseUrl.slice(0, lastSepIndex + 1);
25
- }
26
-
27
15
  function isURL (url) {
28
16
  try {
29
17
  new URL(url);
@@ -87,28 +75,25 @@
87
75
  output.push(segmented.slice(segmentIndex, i + 1));
88
76
  segmentIndex = -1;
89
77
  }
78
+ continue;
90
79
  }
91
-
92
80
  // new segment - check if it is relative
93
81
  else if (segmented[i] === '.') {
94
82
  // ../ segment
95
83
  if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
96
84
  output.pop();
97
85
  i += 2;
86
+ continue;
98
87
  }
99
88
  // ./ segment
100
89
  else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
101
90
  i += 1;
102
- }
103
- else {
104
- // the start of a new segment as below
105
- segmentIndex = i;
91
+ continue;
106
92
  }
107
93
  }
108
94
  // it is the start of a new segment
109
- else {
110
- segmentIndex = i;
111
- }
95
+ while (segmented[i] === '/') i++;
96
+ segmentIndex = i;
112
97
  }
113
98
  // finish reading out the last segment
114
99
  if (segmentIndex !== -1)
@@ -210,7 +195,7 @@
210
195
  }
211
196
 
212
197
  const onerror = globalHook(esmsInitOptions.onerror || noop);
213
- const onpolyfill = esmsInitOptions.onpolyfill ? globalHook(esmsInitOptions.onpolyfill) : () => console.info(`OK: "Uncaught TypeError" module failure has been polyfilled`);
198
+ const onpolyfill = esmsInitOptions.onpolyfill ? globalHook(esmsInitOptions.onpolyfill) : () => console.info(`OK: ^ TypeError module failure has been polyfilled`);
214
199
 
215
200
  const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
216
201
 
@@ -315,7 +300,6 @@
315
300
 
316
301
  const resolve = resolveHook ? async (id, parentUrl) => ({ r: await resolveHook(id, parentUrl, defaultResolve), b: false }) : _resolve;
317
302
 
318
- let id = 0;
319
303
  const registry = {};
320
304
 
321
305
  async function loadAll (load, seen) {
@@ -523,7 +507,7 @@
523
507
  }
524
508
  // dynamic import
525
509
  else {
526
- resolvedSource += `${source.slice(lastIndex, dynamicImportIndex + 6)}Shim(${source.slice(start, end)}, ${load.r && urlJsString(load.r)}${source.slice(end, statementEnd)}`;
510
+ resolvedSource += `${source.slice(lastIndex, dynamicImportIndex + 6)}Shim(${source.slice(start, end)}, ${urlJsString(load.r)}${source.slice(end, statementEnd)}`;
527
511
  lastIndex = statementEnd;
528
512
  }
529
513
  }
@@ -581,24 +565,25 @@
581
565
  return { r: res.url, s: await res.text(), t: 'js' };
582
566
  else if (jsonContentType.test(contentType))
583
567
  return { r: res.url, s: `export default ${await res.text()}`, t: 'json' };
584
- else if (cssContentType.test(contentType))
568
+ else if (cssContentType.test(contentType)) {
585
569
  return { r: res.url, s: `var s=new CSSStyleSheet();s.replaceSync(${
586
- JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes, relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
570
+ JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes = '', relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
587
571
  });export default s;`, t: 'css' };
572
+ }
588
573
  else
589
574
  throw Error(`Unsupported Content-Type "${contentType}"`);
590
575
  }
591
576
 
592
577
  function getOrCreateLoad (url, fetchOpts, source) {
593
578
  let load = registry[url];
594
- if (load)
579
+ if (load && !source)
595
580
  return load;
596
581
 
597
- load = registry[url] = {
582
+ load = {
598
583
  // url
599
584
  u: url,
600
585
  // response url
601
- r: undefined,
586
+ r: source ? url : undefined,
602
587
  // fetchPromise
603
588
  f: undefined,
604
589
  // source
@@ -618,6 +603,12 @@
618
603
  // type
619
604
  t: null
620
605
  };
606
+ if (registry[url]) {
607
+ let i = 0;
608
+ while (registry[load.u + ++i]);
609
+ load.u += i;
610
+ }
611
+ registry[load.u] = load;
621
612
 
622
613
  load.f = (async () => {
623
614
  if (!source) {
@@ -764,7 +755,7 @@
764
755
  if (isReadyScript) readyStateCompleteCnt++;
765
756
  if (isDomContentLoadedScript) domContentLoadedCnt++;
766
757
  const blocks = script.getAttribute('async') === null && isReadyScript;
767
- const loadPromise = topLevelLoad(script.src || `${baseUrl}?${id++}`, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, blocks && lastStaticLoadPromise).catch(e => {
758
+ const loadPromise = topLevelLoad(script.src || baseUrl, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, blocks && lastStaticLoadPromise).catch(e => {
768
759
  // Safari only gives error via console.error
769
760
  if (safari)
770
761
  console.error(e);
@@ -1,11 +1,10 @@
1
- /* ES Module Shims Wasm 1.4.3 */
1
+ /* ES Module Shims Wasm 1.4.4 */
2
2
  (function () {
3
3
 
4
- const uaMatch = navigator.userAgent.match(/(Edge|Safari)\/\d+\.\d+/);
5
- const edge = uaMatch && uaMatch[1] === 'Edge';
6
- const safari = uaMatch && uaMatch[1] === 'Safari';
4
+ const edge = !!navigator.userAgent.match(/Edge\/\d+\.\d+/);
5
+ const safari = !!window.safari;
7
6
 
8
- let baseUrl;
7
+ const baseUrl = document.baseURI;
9
8
 
10
9
  function createBlob (source, type = 'text/javascript') {
11
10
  return URL.createObjectURL(new Blob([source], { type }));
@@ -13,17 +12,6 @@
13
12
 
14
13
  const noop = () => {};
15
14
 
16
- const baseEl = document.querySelector('base[href]');
17
- if (baseEl)
18
- baseUrl = baseEl.href;
19
-
20
- if (!baseUrl && typeof location !== 'undefined') {
21
- baseUrl = location.href.split('#')[0].split('?')[0];
22
- const lastSepIndex = baseUrl.lastIndexOf('/');
23
- if (lastSepIndex !== -1)
24
- baseUrl = baseUrl.slice(0, lastSepIndex + 1);
25
- }
26
-
27
15
  function isURL (url) {
28
16
  try {
29
17
  new URL(url);
@@ -87,28 +75,25 @@
87
75
  output.push(segmented.slice(segmentIndex, i + 1));
88
76
  segmentIndex = -1;
89
77
  }
78
+ continue;
90
79
  }
91
-
92
80
  // new segment - check if it is relative
93
81
  else if (segmented[i] === '.') {
94
82
  // ../ segment
95
83
  if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
96
84
  output.pop();
97
85
  i += 2;
86
+ continue;
98
87
  }
99
88
  // ./ segment
100
89
  else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
101
90
  i += 1;
102
- }
103
- else {
104
- // the start of a new segment as below
105
- segmentIndex = i;
91
+ continue;
106
92
  }
107
93
  }
108
94
  // it is the start of a new segment
109
- else {
110
- segmentIndex = i;
111
- }
95
+ while (segmented[i] === '/') i++;
96
+ segmentIndex = i;
112
97
  }
113
98
  // finish reading out the last segment
114
99
  if (segmentIndex !== -1)
@@ -210,7 +195,7 @@
210
195
  }
211
196
 
212
197
  const onerror = globalHook(esmsInitOptions.onerror || noop);
213
- const onpolyfill = esmsInitOptions.onpolyfill ? globalHook(esmsInitOptions.onpolyfill) : () => console.info(`OK: "Uncaught TypeError" module failure has been polyfilled`);
198
+ const onpolyfill = esmsInitOptions.onpolyfill ? globalHook(esmsInitOptions.onpolyfill) : () => console.info(`OK: ^ TypeError module failure has been polyfilled`);
214
199
 
215
200
  const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
216
201
 
@@ -313,7 +298,6 @@
313
298
 
314
299
  const resolve = resolveHook ? async (id, parentUrl) => ({ r: await resolveHook(id, parentUrl, defaultResolve), b: false }) : _resolve;
315
300
 
316
- let id = 0;
317
301
  const registry = {};
318
302
 
319
303
  async function loadAll (load, seen) {
@@ -521,7 +505,7 @@
521
505
  }
522
506
  // dynamic import
523
507
  else {
524
- resolvedSource += `${source.slice(lastIndex, dynamicImportIndex + 6)}Shim(${source.slice(start, end)}, ${load.r && urlJsString(load.r)}${source.slice(end, statementEnd)}`;
508
+ resolvedSource += `${source.slice(lastIndex, dynamicImportIndex + 6)}Shim(${source.slice(start, end)}, ${urlJsString(load.r)}${source.slice(end, statementEnd)}`;
525
509
  lastIndex = statementEnd;
526
510
  }
527
511
  }
@@ -579,24 +563,25 @@
579
563
  return { r: res.url, s: await res.text(), t: 'js' };
580
564
  else if (jsonContentType.test(contentType))
581
565
  return { r: res.url, s: `export default ${await res.text()}`, t: 'json' };
582
- else if (cssContentType.test(contentType))
566
+ else if (cssContentType.test(contentType)) {
583
567
  return { r: res.url, s: `var s=new CSSStyleSheet();s.replaceSync(${
584
- JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes, relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
568
+ JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes = '', relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
585
569
  });export default s;`, t: 'css' };
570
+ }
586
571
  else
587
572
  throw Error(`Unsupported Content-Type "${contentType}"`);
588
573
  }
589
574
 
590
575
  function getOrCreateLoad (url, fetchOpts, source) {
591
576
  let load = registry[url];
592
- if (load)
577
+ if (load && !source)
593
578
  return load;
594
579
 
595
- load = registry[url] = {
580
+ load = {
596
581
  // url
597
582
  u: url,
598
583
  // response url
599
- r: undefined,
584
+ r: source ? url : undefined,
600
585
  // fetchPromise
601
586
  f: undefined,
602
587
  // source
@@ -616,6 +601,12 @@
616
601
  // type
617
602
  t: null
618
603
  };
604
+ if (registry[url]) {
605
+ let i = 0;
606
+ while (registry[load.u + ++i]);
607
+ load.u += i;
608
+ }
609
+ registry[load.u] = load;
619
610
 
620
611
  load.f = (async () => {
621
612
  if (!source) {
@@ -762,7 +753,7 @@
762
753
  if (isReadyScript) readyStateCompleteCnt++;
763
754
  if (isDomContentLoadedScript) domContentLoadedCnt++;
764
755
  const blocks = script.getAttribute('async') === null && isReadyScript;
765
- const loadPromise = topLevelLoad(script.src || `${baseUrl}?${id++}`, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, blocks && lastStaticLoadPromise).catch(e => {
756
+ const loadPromise = topLevelLoad(script.src || baseUrl, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, blocks && lastStaticLoadPromise).catch(e => {
766
757
  // Safari only gives error via console.error
767
758
  if (safari)
768
759
  console.error(e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-module-shims",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "Shims for the latest ES module features",
5
5
  "main": "dist/es-module-shims.js",
6
6
  "exports": {