Repository: parcel-bundler/parcel
Pull request #5042 (2020-08-19 18:22:49)

Call init for wrapped assets in interop calls
Came up in Squoosh

## 💻 Examples

The real problem was rather that `$a78f483bad27a0e0f7bb0d19c1843709$exports` should be `$a78f483bad27a0e0f7bb0d19c1843709$init()` because it's wrapped:

```js
  var $a78f483bad27a0e0f7bb0d19c1843709$$interop$default = $parcel$interopDefault($a78f483bad27a0e0f7bb0d19c1843709$exports);
```

height[bot]: > Link [Height](https://parcel.height.app) tasks by mentioning a task ID in the pull request title or description, commit messages, or comments.
>
> 💡Tip: You can also use "Close T-X" to automatically close a task when the pull request is merged.
<!-- Sent by Height -->
parcel-benchmark: ## Benchmark Results
<details><summary>Kitchen Sink ✅</summary><p>

#### Timings

| Description | Time | Difference |
| --- | --- | --- |
| Cold | 7.47s | -110.00ms |
| Cached | 2.66s | -8.00ms |

#### Cold Bundles

| Bundle | Size | Difference | Time | Difference |
| --- | --- | --- | --- | --- |
| dist/legacy/parcel.d5807e82.webp | 102.94kb | +0.00b | 296.00ms | -20.00ms 🚀 |
| dist/modern/parcel.d5807e82.webp | 102.94kb | +0.00b | 296.00ms | -20.00ms 🚀 |
| dist/legacy/index.html | 701.00b | +0.00b | 774.00ms | -99.00ms 🚀 |
| dist/modern/index.html | 701.00b | +0.00b | 772.00ms | -98.00ms 🚀 |
| dist/legacy/index.b3acc8eb.css | 77.00b | +0.00b | 2.01s | +229.00ms ⚠️ |

#### Cached Bundles

| Bundle | Size | Difference | Time | Difference |
| --- | --- | --- | --- | --- |
| dist/legacy/parcel.d5807e82.webp | 102.94kb | +0.00b | 239.00ms | -37.00ms 🚀 |
| dist/modern/parcel.d5807e82.webp | 102.94kb | +0.00b | 239.00ms | -29.00ms 🚀 |

</p></details>

<details><summary>React HackerNews ✅</summary><p>

#### Timings

| Description | Time | Difference |
| --- | --- | --- |
| Cold | 34.58s | +719.00ms |
| Cached | 2.81s | +78.00ms |

#### Cold Bundles

| Bundle | Size | Difference | Time | Difference |
| --- | --- | --- | --- | --- |
| dist/logo.24c8bf9e.png | 274.00b | +0.00b | 213.00ms | +28.00ms ⚠️ |

#### Cached Bundles

| Bundle | Size | Difference | Time | Difference |
| --- | --- | --- | --- | --- |
| dist/logo.24c8bf9e.png | 274.00b | +0.00b | 412.00ms | -29.00ms 🚀 |

</p></details>

<details><summary>AtlasKit Editor ✅</summary><p>

#### Timings

| Description | Time | Difference |
| --- | --- | --- |
| Cold | 3.52m | +1.95s |
| Cached | 5.76s | -326.00ms 🚀 |

#### Cold Bundles

| Bundle | Size | Difference | Time | Difference |
| --- | --- | --- | --- | --- |
| dist/index.0fdd3b2f.js | 2.73mb | +522.00b ⚠️ | 1.87m | +2.25s |
| dist/pdfRenderer.bfb9f826.js | 1.11mb | +4.00b ⚠️ | 1.17m | -3.13s |
| dist/popup.f9e0392a.js | 170.62kb | +0.00b | 1.17m | +23.82s ⚠️ |
| dist/media-viewer.befa397f.js | 72.02kb | +0.00b | 21.36s | -2.22s 🚀 |
| dist/card.f6d11305.js | 55.09kb | +0.00b | 17.84s | -1.91s 🚀 |
| dist/card.1a20c16b.js | 52.86kb | +0.00b | 1.87m | +37.00s ⚠️ |
| dist/component.81e8b06d.js | 30.78kb | +0.00b | 3.52s | +236.00ms ⚠️ |
| dist/dropzone.6e6acf73.js | 17.27kb | +0.00b | 1.87m | +38.87s ⚠️ |
| dist/smartMediaEditor.9623570c.js | 16.87kb | +0.00b | 1.20m | -38.13s 🚀 |
| dist/ui.fee77548.js | 13.97kb | +0.00b | 17.84s | -1.91s 🚀 |
| dist/workerHasher.c499c8eb.js | 11.78kb | +0.00b | 1.04m | +45.36s ⚠️ |
| dist/EmojiTypeAheadComponent.1990d771.js | 8.67kb | +0.00b | 1.04m | +45.36s ⚠️ |
| dist/component.77c0f682.js | 6.05kb | +0.00b | 8.33s | +428.00ms ⚠️ |
| dist/card.383bd9bd.js | 5.61kb | +0.00b | 17.83s | -1.91s 🚀 |
| dist/media-viewer.59c17dad.js | 3.92kb | +0.00b | 21.35s | -2.22s 🚀 |
| dist/dropzone.3c67f0a6.js | 3.23kb | +0.00b | 1.13m | +24.26s ⚠️ |
| dist/EmojiUploadComponent.d54a1fc6.js | 2.18kb | +0.00b | 1.04m | +45.36s ⚠️ |
| dist/card.eea6ad8c.js | 2.03kb | +0.00b | 21.36s | -2.22s 🚀 |
| dist/ResourcedEmojiComponent.abe8596c.js | 2.00kb | +0.00b | 8.33s | +696.00ms ⚠️ |
| dist/16.1b6ca79f.js | 1.66kb | +0.00b | 8.65s | -1.27s 🚀 |
| dist/browser.75813db0.js | 1.61kb | +0.00b | 1.87m | +38.87s ⚠️ |
| dist/workerHasher.6d5b22d7.js | 1.54kb | +0.00b | 1.04m | +45.36s ⚠️ |
| dist/workerHasher.fa198233.js | 1.54kb | +0.00b | 1.17m | -39.35s 🚀 |
| dist/16.9ccb5b28.js | 1.38kb | +0.00b | 10.42s | +1.43s ⚠️ |
| dist/16.19c93285.js | 1.33kb | +0.00b | 8.65s | -1.27s 🚀 |
| dist/expand.450f3aea.js | 1.16kb | +0.00b | 10.07s | -5.25s 🚀 |
| dist/16.4e3b0235.js | 1.14kb | +0.00b | 10.54s | +1.55s ⚠️ |
| dist/16.9ba230ea.js | 1.13kb | +0.00b | 8.65s | -1.46s 🚀 |
| dist/16.a37df53b.js | 1.13kb | +0.00b | 10.42s | +1.43s ⚠️ |
| dist/16.9adb4ec7.js | 1.13kb | +0.00b | 10.43s | +1.44s ⚠️ |
| dist/16.eafe1a11.js | 1.13kb | +0.00b | 8.65s | -1.27s 🚀 |
| dist/heading2.a2a1be3f.js | 1.11kb | +0.00b | 9.93s | -49.84s 🚀 |
| dist/16.3920766f.js | 1.10kb | +0.00b | 8.33s | +696.00ms ⚠️ |
| dist/component.6600f83e.js | 1.07kb | +0.00b | 8.33s | +696.00ms ⚠️ |
| dist/panel-warning.97a0e3b3.js | 1008.00b | +0.00b | 9.84s | -49.94s 🚀 |
| dist/panel-success.9b923e58.js | 845.00b | +0.00b | 9.84s | -49.94s 🚀 |
| dist/panel-note.97a4d541.js | 841.00b | +0.00b | 9.84s | -49.94s 🚀 |
| dist/media-picker-analytics-error-boundary.787e0c89.js | 837.00b | +0.00b | 1.13m | +24.26s ⚠️ |
| dist/media-card-analytics-error-boundary.f647e1a8.js | 833.00b | +0.00b | 17.83s | -1.91s 🚀 |
| dist/media-viewer-analytics-error-boundary.2a26440d.js | 757.00b | +0.00b | 21.35s | -2.22s 🚀 |
| dist/EmojiPickerComponent.2e54b9c6.js | 535.00b | +0.00b | 15.09s | -1.66s 🚀 |
| dist/simpleHasher.16c8bf41.js | 528.00b | +0.00b | 17.83s | -1.91s 🚀 |
| dist/simpleHasher.a29b2a8e.js | 528.00b | +0.00b | 1.17m | -39.42s 🚀 |

#### Cached Bundles

| Bundle | Size | Difference | Time | Difference |
| --- | --- | --- | --- | --- |
| dist/index.0fdd3b2f.js | 2.73mb | +525.00b ⚠️ | 610.00ms | -83.00ms 🚀 |
| dist/pdfRenderer.bfb9f826.js | 1.11mb | +4.00b ⚠️ | 606.00ms | -79.00ms 🚀 |
| dist/editorView.f24284d1.js | 585.98kb | +0.00b | 605.00ms | -79.00ms 🚀 |
| dist/popup.f9e0392a.js | 170.62kb | +0.00b | 606.00ms | -79.00ms 🚀 |
| dist/Toolbar.1fa78438.js | 92.34kb | +0.00b | 605.00ms | -79.00ms 🚀 |
| dist/EmojiPickerComponent.ae601247.js | 75.29kb | +0.00b | 607.00ms | -77.00ms 🚀 |
| dist/media-viewer.befa397f.js | 72.02kb | +0.00b | 606.00ms | -79.00ms 🚀 |
| dist/card.f6d11305.js | 55.09kb | +0.00b | 606.00ms | -79.00ms 🚀 |
| dist/card.1a20c16b.js | 52.86kb | +0.00b | 606.00ms | -78.00ms 🚀 |
| dist/Modal.b9755cae.js | 41.40kb | +0.00b | 610.00ms | -83.00ms 🚀 |
| dist/component.81e8b06d.js | 30.78kb | +0.00b | 610.00ms | -83.00ms 🚀 |
| dist/component.cec35177.js | 22.51kb | +0.00b | 609.00ms | -84.00ms 🚀 |
| dist/DatePicker.f18b4801.js | 21.17kb | +0.00b | 607.00ms | -77.00ms 🚀 |
| dist/EmojiPickerComponent.1197c58d.js | 18.23kb | +0.00b | 607.00ms | -77.00ms 🚀 |
| dist/dropzone.6e6acf73.js | 17.27kb | +0.00b | 606.00ms | -78.00ms 🚀 |
| dist/smartMediaEditor.9623570c.js | 16.87kb | +0.00b | 605.00ms | -79.00ms 🚀 |
| dist/js.591cd3d2.js | 16.40kb | +0.00b | 609.00ms | -84.00ms 🚀 |
| dist/ui.fee77548.js | 13.97kb | +0.00b | 606.00ms | -79.00ms 🚀 |
| dist/workerHasher.c499c8eb.js | 11.78kb | +0.00b | 606.00ms | -78.00ms 🚀 |
| dist/EmojiTypeAheadComponent.1990d771.js | 8.67kb | +0.00b | 607.00ms | -77.00ms 🚀 |
| dist/component.77c0f682.js | 6.05kb | +0.00b | 609.00ms | -83.00ms 🚀 |
| dist/card.383bd9bd.js | 5.61kb | +0.00b | 606.00ms | -79.00ms 🚀 |
| dist/media-viewer.59c17dad.js | 3.92kb | +0.00b | 606.00ms | -79.00ms 🚀 |
| dist/EmojiPickerComponent.627aca6b.js | 3.58kb | +0.00b | 607.00ms | -77.00ms 🚀 |
| dist/index.ac562c80.css | 3.46kb | +0.00b | 605.00ms | -79.00ms 🚀 |
| dist/png-chunks-extract.a844fdb6.js | 3.41kb | +0.00b | 609.00ms | -84.00ms 🚀 |
| dist/dropzone.3c67f0a6.js | 3.23kb | +0.00b | 606.00ms | -78.00ms 🚀 |
| dist/Modal.0304b9ed.js | 3.08kb | +0.00b | 610.00ms | -83.00ms 🚀 |
| dist/clipboard.da112b6e.js | 2.75kb | +0.00b | 606.00ms | -78.00ms 🚀 |
| dist/16.290b4a43.js | 2.38kb | +0.00b | 610.00ms | -83.00ms 🚀 |
| dist/EmojiUploadComponent.d54a1fc6.js | 2.18kb | +0.00b | 607.00ms | -77.00ms 🚀 |
| dist/card.eea6ad8c.js | 2.03kb | +0.00b | 606.00ms | -79.00ms 🚀 |
| dist/ResourcedEmojiComponent.abe8596c.js | 2.00kb | +0.00b | 610.00ms | -82.00ms 🚀 |
| dist/date.231500d2.js | 1.73kb | +0.00b | 609.00ms | -77.00ms 🚀 |
| dist/16.d16f14ed.js | 1.73kb | +0.00b | 609.00ms | -83.00ms 🚀 |
| dist/images.80c92f5e.js | 1.67kb | +0.00b | 609.00ms | -77.00ms 🚀 |
| dist/16.1b6ca79f.js | 1.66kb | +0.00b | 609.00ms | -83.00ms 🚀 |
| dist/feedback.d5590b34.js | 1.64kb | +0.00b | 607.00ms | -77.00ms 🚀 |
| dist/browser.75813db0.js | 1.61kb | +0.00b | 606.00ms | -78.00ms 🚀 |
| dist/workerHasher.6d5b22d7.js | 1.54kb | +0.00b | 606.00ms | -78.00ms 🚀 |
| dist/workerHasher.fa198233.js | 1.54kb | +0.00b | 605.00ms | -79.00ms 🚀 |
| dist/list-number.c35f9589.js | 1.46kb | +0.00b | 608.00ms | -77.00ms 🚀 |
| dist/status.8ab4226b.js | 1.46kb | +0.00b | 608.00ms | -77.00ms 🚀 |
| dist/16.9ccb5b28.js | 1.38kb | +0.00b | 609.00ms | -83.00ms 🚀 |
| dist/code.3dd71280.js | 1.38kb | +0.00b | 608.00ms | -78.00ms 🚀 |
| dist/16.19c93285.js | 1.33kb | +0.00b | 609.00ms | -83.00ms 🚀 |
| dist/16.c7751e34.js | 1.33kb | +0.00b | 609.00ms | -83.00ms 🚀 |
| dist/16.51049e2c.js | 1.32kb | +0.00b | 610.00ms | -83.00ms 🚀 |
| dist/16.18344f47.js | 1.31kb | +0.00b | 608.00ms | -78.00ms 🚀 |
| dist/link.2f4427e6.js | 1.30kb | +0.00b | 608.00ms | -77.00ms 🚀 |
| dist/heading6.fdbbdf4d.js | 1.30kb | +0.00b | 607.00ms | -78.00ms 🚀 |
| dist/heading3.2113b7a1.js | 1.29kb | +0.00b | 608.00ms | -77.00ms 🚀 |
| dist/16.2c4c1846.js | 1.27kb | +0.00b | 609.00ms | -77.00ms 🚀 |
| dist/emoji.93ae61d3.js | 1.23kb | +0.00b | 609.00ms | -77.00ms 🚀 |
| dist/16.d17ab186.js | 1.23kb | +0.00b | 609.00ms | -83.00ms 🚀 |
| dist/16.436f097f.js | 1.21kb | +0.00b | 610.00ms | -83.00ms 🚀 |
| dist/16.b4da0acb.js | 1.19kb | +0.00b | 609.00ms | -83.00ms 🚀 |
| dist/16.02c68c4f.js | 1.18kb | +0.00b | 608.00ms | -78.00ms 🚀 |
| dist/heading5.e195aab1.js | 1.17kb | +0.00b | 607.00ms | -78.00ms 🚀 |
| dist/expand.450f3aea.js | 1.16kb | +0.00b | 607.00ms | -77.00ms 🚀 |
| dist/media-card-analytics-error-boundary.2323af57.js | 1.15kb | +0.00b | 606.00ms | -79.00ms 🚀 |
| dist/16.b46ef690.js | 1.14kb | +0.00b | 610.00ms | -83.00ms 🚀 |
| dist/16.4e3b0235.js | 1.14kb | +0.00b | 609.00ms | -83.00ms 🚀 |
| dist/16.9ba230ea.js | 1.13kb | +0.00b | 609.00ms | -83.00ms 🚀 |
| dist/16.a37df53b.js | 1.13kb | +0.00b | 609.00ms | -83.00ms 🚀 |
| dist/16.9adb4ec7.js | 1.13kb | +0.00b | 609.00ms | -83.00ms 🚀 |
| dist/16.eafe1a11.js | 1.13kb | +0.00b | 609.00ms | -83.00ms 🚀 |
| dist/heading2.a2a1be3f.js | 1.11kb | +0.00b | 608.00ms | -77.00ms 🚀 |
| dist/16.3920766f.js | 1.10kb | +0.00b | 610.00ms | -82.00ms 🚀 |
| dist/component.6600f83e.js | 1.07kb | +0.00b | 610.00ms | -82.00ms 🚀 |
| dist/mention.4d64e059.js | 1.07kb | +0.00b | 608.00ms | -77.00ms 🚀 |
| dist/heading4.ec980e93.js | 1.06kb | +0.00b | 608.00ms | -77.00ms 🚀 |
| dist/16.afcb09b6.js | 1.05kb | +0.00b | 609.00ms | -83.00ms 🚀 |
| dist/layout.52ba15f7.js | 1.05kb | +0.00b | 609.00ms | -77.00ms 🚀 |
| dist/divider.16defde6.js | 1.03kb | +0.00b | 609.00ms | -76.00ms 🚀 |
| dist/quote.aa25b83c.js | 1.02kb | +0.00b | 608.00ms | -77.00ms 🚀 |
| dist/action.9aa72b39.js | 1.00kb | +0.00b | 608.00ms | -78.00ms 🚀 |
| dist/decision.20244046.js | 1010.00b | +0.00b | 609.00ms | -76.00ms 🚀 |
| dist/panel-warning.97a0e3b3.js | 1008.00b | +0.00b | 608.00ms | -77.00ms 🚀 |
| dist/list.c9147a62.js | 978.00b | +0.00b | 608.00ms | -77.00ms 🚀 |
| dist/heading1.7d899ba5.js | 976.00b | +0.00b | 608.00ms | -77.00ms 🚀 |
| dist/panel-error.8d11e8b7.js | 906.00b | +0.00b | 608.00ms | -77.00ms 🚀 |
| dist/panel.a28c56ee.js | 897.00b | +0.00b | 608.00ms | -77.00ms 🚀 |
| dist/table.5a4874ee.js | 889.00b | +0.00b | 608.00ms | -78.00ms 🚀 |
| dist/panel-success.9b923e58.js | 845.00b | +0.00b | 608.00ms | -77.00ms 🚀 |
| dist/panel-note.97a4d541.js | 841.00b | +0.00b | 608.00ms | -77.00ms 🚀 |
| dist/media-picker-analytics-error-boundary.787e0c89.js | 837.00b | +0.00b | 606.00ms | -78.00ms 🚀 |
| dist/media-card-analytics-error-boundary.f647e1a8.js | 833.00b | +0.00b | 606.00ms | -79.00ms 🚀 |
| dist/media-card-analytics-error-boundary.d8d4665e.js | 833.00b | +0.00b | 606.00ms | -78.00ms 🚀 |
| dist/media-viewer-analytics-error-boundary.2a26440d.js | 757.00b | +0.00b | 606.00ms | -79.00ms 🚀 |
| dist/EmojiPickerComponent.2e54b9c6.js | 535.00b | +0.00b | 607.00ms | -77.00ms 🚀 |
| dist/simpleHasher.16c8bf41.js | 528.00b | +0.00b | 606.00ms | -78.00ms 🚀 |
| dist/simpleHasher.a29b2a8e.js | 528.00b | +0.00b | 605.00ms | -79.00ms 🚀 |
| dist/index.html | 119.00b | +0.00b | 612.00ms | -82.00ms 🚀 |

</p></details>

<details><summary>Three.js x4 🚨</summary><p>

#### Timings

| Description | Time | Difference |
| --- | --- | --- |
| Cold | **FAILED** | -0.00ms |
| Cached | **FAILED** | -0.00ms |

#### Cold Bundles

*No bundles found, this is probably a failed build...*
#### Cached Bundles

*No bundles found, this is probably a failed build...*
</p></details>

**[Click here to view a detailed benchmark overview.](https://benchmark.parceljs.org/benchmark/274313349411373580)**

Patch:
diff --git a/packages/shared/scope-hoisting/src/link.js b/packages/shared/scope-hoisting/src/link.js
index ba718a033..f5b9fb836 100644
--- a/packages/shared/scope-hoisting/src/link.js
+++ b/packages/shared/scope-hoisting/src/link.js
@@ -235,9 +235,13 @@ export function link({
     // Look for an exports object if we bailed out.
     // TODO remove the first part of the condition once bundleGraph.resolveSymbol().identifier === null covers this
     if ((node === undefined && mod.meta.isCommonJS) || node === null) {
-      node = findSymbol(path, assertString(mod.meta.exportsIdentifier));
-      if (!node) {
-        return null;
+      if (wrappedAssets.has(mod.id)) {
+        node = t.callExpression(getIdentifier(mod, 'init'), []);
+      } else {
+        node = findSymbol(path, assertString(mod.meta.exportsIdentifier));
+        if (!node) {
+          return null;
+        }
       }
 
       node = interop(mod, symbol, path, node);
@@ -267,7 +271,7 @@ export function link({
       if (!path.scope.getBinding(name)) {
         let binding = nullthrows(
           path.scope.getBinding(
-            bundle.hasAsset(mod)
+            bundle.hasAsset(mod) && !wrappedAssets.has(mod.id)
               ? assertString(mod.meta.exportsIdentifier)
               : // If this bundle doesn't have the asset, use the binding for
                 // the `parcelRequire`d init function.


Test patch:
diff --git a/packages/core/integration-tests/test/integration/scope-hoisting/commonjs/wrap-interop-url-import/a.js b/packages/core/integration-tests/test/integration/scope-hoisting/commonjs/wrap-interop-url-import/a.js
new file mode 100644
index 000000000..b5bf67115
--- /dev/null
+++ b/packages/core/integration-tests/test/integration/scope-hoisting/commonjs/wrap-interop-url-import/a.js
@@ -0,0 +1,5 @@
+function run() {
+	return require("./b.js");
+}
+
+output = run().default;
diff --git a/packages/core/integration-tests/test/integration/scope-hoisting/commonjs/wrap-interop-url-import/b.js b/packages/core/integration-tests/test/integration/scope-hoisting/commonjs/wrap-interop-url-import/b.js
new file mode 100644
index 000000000..cceae91ea
--- /dev/null
+++ b/packages/core/integration-tests/test/integration/scope-hoisting/commonjs/wrap-interop-url-import/b.js
@@ -0,0 +1,3 @@
+import logo from "url:./data.txt";
+
+export default logo;
diff --git a/packages/core/integration-tests/test/integration/scope-hoisting/commonjs/wrap-interop-url-import/data.txt b/packages/core/integration-tests/test/integration/scope-hoisting/commonjs/wrap-interop-url-import/data.txt
new file mode 100644
index 000000000..e69de29bb
diff --git a/packages/core/integration-tests/test/scope-hoisting.js b/packages/core/integration-tests/test/scope-hoisting.js
index 6c0383fa1..2b18528ba 100644
--- a/packages/core/integration-tests/test/scope-hoisting.js
+++ b/packages/core/integration-tests/test/scope-hoisting.js
@@ -1740,6 +1740,37 @@ describe('scope hoisting', function() {
       assert.equal(output, 6);
     });
 
+    it('support url imports in wrapped modules with interop', async function() {
+      let b = await bundle(
+        path.join(
+          __dirname,
+          '/integration/scope-hoisting/commonjs/wrap-interop-url-import/a.js',
+        ),
+      );
+
+      assertBundles(b, [
+        {
+          type: 'js',
+          assets: [
+            'a.js',
+            'b.js',
+            'bundle-manifest.js',
+            'bundle-url.js',
+            'JSRuntime.js',
+            'JSRuntime.js',
+            'relative-path.js',
+          ],
+        },
+        {
+          type: 'txt',
+          assets: ['data.txt'],
+        },
+      ]);
+
+      let output = await run(b);
+      assert(output.endsWith('.txt'));
+    });
+
     it('supports module object properties', async function() {
       let b = await bundle(
         path.join(