Skip to content

Commit 947e105

Browse files
committed
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
1 parent 709a004 commit 947e105

File tree

12 files changed

+63
-9
lines changed

12 files changed

+63
-9
lines changed

ext/steal-clone.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ function cloneConfig(obj, isTopLevel) {
4141
return clone;
4242
}
4343

44+
if(obj instanceof Set) {
45+
clone = new Set();
46+
obj.forEach(function(item) {
47+
clone.add(item);
48+
});
49+
return clone;
50+
}
51+
4452
// instanceof fails to catch objects created with `null` as prototype
4553
if (obj instanceof Object || toString.call(obj) === "[object Object]") {
4654
clone = {};

test/test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,10 @@ QUnit.test("Can disable tree shaking using treeShaking: false", function(assert)
376376
makeIframe("tree_shake_reexport/tree-shaking-false.html", assert);
377377
});
378378

379+
QUnit.test("Using steal-clone with a tree-shaken dep tree", function(assert){
380+
makeIframe("tree_shake/steal-clone.html", assert);
381+
});
382+
379383
QUnit.test("Can replace loads midway through the process", function(assert){
380384
makeIframe("replace/site.html", assert);
381385
});

test/tree-shake-complex/site.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</script>
1212
<script
1313
main="~/main"
14-
src="../../../steal-with-promises.js"
14+
src="../../steal-with-promises.js"
1515
data-base-url="."
1616
data-config="package.json!npm"></script>
1717
<script>

test/tree_shake/anon.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
window.assert = window.parent.assert;
1010
window.done = window.parent.done;
1111
</script>
12-
<script src="../../../steal-with-promises.js"
12+
<script src="../../steal-with-promises.js"
1313
data-base-url="."
1414
data-config="package.json!npm"
1515
data-main="@empty">

test/tree_shake/bundle.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
window.done = window.parent.done;
1111
</script>
1212
<script
13-
src="../../../steal-with-promises.js"
13+
src="../../steal-with-promises.js"
1414
data-main="@empty"
1515
data-base-url="."
1616
data-config="package.json!npm"></script>

test/tree_shake/dev.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</script>
1212
<script
1313
main="~/main"
14-
src="../../../steal-with-promises.js"
14+
src="../../steal-with-promises.js"
1515
data-base-url="."
1616
data-config="package.json!npm"></script>
1717
<script>

test/tree_shake/race.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
window.assert = window.parent.assert;
1010
window.done = window.parent.done;
1111
</script>
12-
<script src="../../../steal.js"
12+
<script src="../../steal.js"
1313
data-base-url="."
1414
data-main="@empty"
1515
data-config="package.json!npm"></script>

test/tree_shake/steal-clone.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Tree shaking with steal-clone</title>
6+
</head>
7+
<body>
8+
<script>
9+
window.assert = window.parent.assert;
10+
window.done = window.parent.done;
11+
</script>
12+
<script
13+
main="~/main"
14+
src="../../steal-with-promises.js"
15+
data-base-url="."
16+
data-config="package.json!npm"></script>
17+
<script>
18+
function runTests() {
19+
return steal.loader.import("steal-clone", { name: steal.loader.main })
20+
.then(function(clone) {
21+
return clone({})
22+
.import(steal.loader.main)
23+
.then(function() {
24+
if(window.assert) {
25+
window.assert.ok(true, "It loaded");
26+
} else {
27+
console.log("it loaded successfully");
28+
}
29+
})
30+
});
31+
}
32+
33+
steal.done()
34+
.then(runTests)
35+
.then(function(){
36+
if(window.assert) {
37+
window.done();
38+
}
39+
});
40+
</script>
41+
</body>
42+
</html>

test/tree_shake_reexport/dev.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</script>
1212
<script
1313
main="~/uses-core"
14-
src="../../../steal-with-promises.js"
14+
src="../../steal-with-promises.js"
1515
data-base-url="."
1616
data-config="package.json!npm"></script>
1717
<script>

test/tree_shake_reexport/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</script>
1212
<script
1313
main="~/main"
14-
src="../../../steal-with-promises.js"
14+
src="../../steal-with-promises.js"
1515
data-base-url="."
1616
data-config="package.json!npm"></script>
1717
<script>

0 commit comments

Comments
 (0)