Skip to content

Commit

Permalink
Merge pull request #82 from canjs/68-object-assign-polyfill
Browse files Browse the repository at this point in the history
68 object assign polyfill
  • Loading branch information
Mike 'mitch' Mitchel authored Jul 3, 2019
2 parents 15fecac + 4cbea85 commit a4f97e8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
}
},
"dependencies": {
"can-assign": "^1.0.0",
"can-stache": "^4.0.0",
"can-stache-ast": "^1.0.0",
"can-stache-bindings": "^4.0.0",
Expand Down
7 changes: 4 additions & 3 deletions steal-stache.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ function template(imports, intermediate, filename){
imports = JSON.stringify(imports);
intermediate = JSON.stringify(intermediate);

return "define("+imports+",function(module, stache, mustacheCore){\n" +
return "define("+imports+",function(module, assign, stache, mustacheCore){ \n" +
(filename ?
"\tvar renderer = stache(" + JSON.stringify(filename) + ", " + intermediate + ");\n" :
"\tvar renderer = stache(" + intermediate + ");\n"
) +
"\treturn function(scope, options, nodeList){\n" +
"\t\tvar moduleOptions = Object.assign({}, options);\n" +
"\t\tvar moduleOptions = assign({}, options);\n" +
"\t\tif(moduleOptions.helpers) {\n" +
"\t\t\tmoduleOptions.helpers = Object.assign({ module: module }, moduleOptions.helpers);\n" +
"\t\t\tmoduleOptions.helpers = assign({ module: module }, moduleOptions.helpers);\n" +
"\t\t} else {\n" +
"\t\t\tmoduleOptions.module = module;\n" +
"\t\t}\n" +
Expand Down Expand Up @@ -76,6 +76,7 @@ function translate(load) {

ast.imports.unshift("can-stache/src/mustache_core");
ast.imports.unshift("can-stache");
ast.imports.unshift("can-assign");
ast.imports.unshift("module");

return template(
Expand Down
1 change: 1 addition & 0 deletions test/test.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!doctype html>
<title>steal-stache</title>
<script src="../node_modules/steal/steal.js" main="steal-stache/test/test"></script>
<div id="qunit-fixture"></div>
23 changes: 23 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,26 @@ QUnit.test("Can call helpers passed into the renderer", function(assert){
done();
});
});

QUnit.test("pass can-assign for IE11 compatibility (#81)", function(assert){
var done = assert.async();
var oldAssign = window.Object.assign;
window.Object.assign = null;

loader["import"]("test/tests/helper.stache")
.then(function(renderer){

var frag = renderer({}, {
test: function(){
return "works without Object.assign";
}
});

window.Object.assign = oldAssign;
assert.equal(frag.firstChild.firstChild.nodeValue, "works without Object.assign");
done();
})
.catch(function (err) {
console.log(err);
});
});

0 comments on commit a4f97e8

Please sign in to comment.