Skip to content

Commit

Permalink
Merge pull request #1471 from stealjs/ts-clone
Browse files Browse the repository at this point in the history
Make steal-clone work with tree-shaken trees
  • Loading branch information
matthewp authored Oct 25, 2018
2 parents 709a004 + 947e105 commit 56eb233
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 9 deletions.
8 changes: 8 additions & 0 deletions ext/steal-clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
4 changes: 4 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion test/tree-shake-complex/site.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</script>
<script
main="~/main"
src="../../../steal-with-promises.js"
src="../../steal-with-promises.js"
data-base-url="."
data-config="package.json!npm"></script>
<script>
Expand Down
2 changes: 1 addition & 1 deletion test/tree_shake/anon.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
window.assert = window.parent.assert;
window.done = window.parent.done;
</script>
<script src="../../../steal-with-promises.js"
<script src="../../steal-with-promises.js"
data-base-url="."
data-config="package.json!npm"
data-main="@empty">
Expand Down
2 changes: 1 addition & 1 deletion test/tree_shake/bundle.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
window.done = window.parent.done;
</script>
<script
src="../../../steal-with-promises.js"
src="../../steal-with-promises.js"
data-main="@empty"
data-base-url="."
data-config="package.json!npm"></script>
Expand Down
2 changes: 1 addition & 1 deletion test/tree_shake/dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</script>
<script
main="~/main"
src="../../../steal-with-promises.js"
src="../../steal-with-promises.js"
data-base-url="."
data-config="package.json!npm"></script>
<script>
Expand Down
2 changes: 1 addition & 1 deletion test/tree_shake/race.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
window.assert = window.parent.assert;
window.done = window.parent.done;
</script>
<script src="../../../steal.js"
<script src="../../steal.js"
data-base-url="."
data-main="@empty"
data-config="package.json!npm"></script>
Expand Down
42 changes: 42 additions & 0 deletions test/tree_shake/steal-clone.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Tree shaking with steal-clone</title>
</head>
<body>
<script>
window.assert = window.parent.assert;
window.done = window.parent.done;
</script>
<script
main="~/main"
src="../../steal-with-promises.js"
data-base-url="."
data-config="package.json!npm"></script>
<script>
function runTests() {
return steal.loader.import("steal-clone", { name: steal.loader.main })
.then(function(clone) {
return clone({})
.import(steal.loader.main)
.then(function() {
if(window.assert) {
window.assert.ok(true, "It loaded");
} else {
console.log("it loaded successfully");
}
})
});
}

steal.done()
.then(runTests)
.then(function(){
if(window.assert) {
window.done();
}
});
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion test/tree_shake_reexport/dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</script>
<script
main="~/uses-core"
src="../../../steal-with-promises.js"
src="../../steal-with-promises.js"
data-base-url="."
data-config="package.json!npm"></script>
<script>
Expand Down
2 changes: 1 addition & 1 deletion test/tree_shake_reexport/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</script>
<script
main="~/main"
src="../../../steal-with-promises.js"
src="../../steal-with-promises.js"
data-base-url="."
data-config="package.json!npm"></script>
<script>
Expand Down
2 changes: 1 addition & 1 deletion test/tree_shake_reexport/no-tree-shaking.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
window.done = window.parent.done;
</script>
<script
src="../../../steal-with-promises.js"
src="../../steal-with-promises.js"
data-base-url="."
data-config="package.json!npm"
data-no-tree-shaking></script>
Expand Down
2 changes: 1 addition & 1 deletion test/tree_shake_reexport/tree-shaking-false.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
window.done = window.parent.done;
</script>
<script
src="../../../steal-with-promises.js"
src="../../steal-with-promises.js"
data-base-url="."
data-config="package.json!npm"></script>
<script>
Expand Down

0 comments on commit 56eb233

Please sign in to comment.