From 947e105b84ddf9ee33c88e4a767fe6ab3778cbab Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Wed, 24 Oct 2018 16:07:25 -0400 Subject: [PATCH] Make steal-clone work with tree-shaken trees tree-shaken dep trees uses Sets to store information about used exports. When steal-clone copies configuration, it attempts to clone that configuration. This makes it so that it detects Sets, and clones those correctly. Fixes #1470 --- ext/steal-clone.js | 8 ++++ test/test.js | 4 ++ test/tree-shake-complex/site.html | 2 +- test/tree_shake/anon.html | 2 +- test/tree_shake/bundle.html | 2 +- test/tree_shake/dev.html | 2 +- test/tree_shake/race.html | 2 +- test/tree_shake/steal-clone.html | 42 +++++++++++++++++++ test/tree_shake_reexport/dev.html | 2 +- test/tree_shake_reexport/main.html | 2 +- test/tree_shake_reexport/no-tree-shaking.html | 2 +- .../tree-shaking-false.html | 2 +- 12 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 test/tree_shake/steal-clone.html diff --git a/ext/steal-clone.js b/ext/steal-clone.js index 225c3829f..af2563254 100644 --- a/ext/steal-clone.js +++ b/ext/steal-clone.js @@ -41,6 +41,14 @@ function cloneConfig(obj, isTopLevel) { return clone; } + if(obj instanceof Set) { + clone = new Set(); + obj.forEach(function(item) { + clone.add(item); + }); + return clone; + } + // instanceof fails to catch objects created with `null` as prototype if (obj instanceof Object || toString.call(obj) === "[object Object]") { clone = {}; diff --git a/test/test.js b/test/test.js index 0cd36ae8d..3d2074a08 100644 --- a/test/test.js +++ b/test/test.js @@ -376,6 +376,10 @@ QUnit.test("Can disable tree shaking using treeShaking: false", function(assert) makeIframe("tree_shake_reexport/tree-shaking-false.html", assert); }); +QUnit.test("Using steal-clone with a tree-shaken dep tree", function(assert){ + makeIframe("tree_shake/steal-clone.html", assert); +}); + QUnit.test("Can replace loads midway through the process", function(assert){ makeIframe("replace/site.html", assert); }); diff --git a/test/tree-shake-complex/site.html b/test/tree-shake-complex/site.html index c279b5160..43a4aacc7 100644 --- a/test/tree-shake-complex/site.html +++ b/test/tree-shake-complex/site.html @@ -11,7 +11,7 @@ - diff --git a/test/tree_shake/dev.html b/test/tree_shake/dev.html index bf9265c01..98b5bb69a 100644 --- a/test/tree_shake/dev.html +++ b/test/tree_shake/dev.html @@ -11,7 +11,7 @@ - diff --git a/test/tree_shake/steal-clone.html b/test/tree_shake/steal-clone.html new file mode 100644 index 000000000..5e696f228 --- /dev/null +++ b/test/tree_shake/steal-clone.html @@ -0,0 +1,42 @@ + + + + + Tree shaking with steal-clone + + + + + + + diff --git a/test/tree_shake_reexport/dev.html b/test/tree_shake_reexport/dev.html index 119aee8bf..67b6e0b20 100644 --- a/test/tree_shake_reexport/dev.html +++ b/test/tree_shake_reexport/dev.html @@ -11,7 +11,7 @@ diff --git a/test/tree_shake_reexport/tree-shaking-false.html b/test/tree_shake_reexport/tree-shaking-false.html index 655d70559..40986507d 100644 --- a/test/tree_shake_reexport/tree-shaking-false.html +++ b/test/tree_shake_reexport/tree-shaking-false.html @@ -10,7 +10,7 @@ window.done = window.parent.done;