Skip to content

Commit

Permalink
Merge pull request #86 from canjs/major
Browse files Browse the repository at this point in the history
Merge major branch for 6.0 release
  • Loading branch information
matthewp authored Oct 2, 2019
2 parents ea18a97 + c0ef192 commit 4f57d27
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
node_js: node
addons:
firefox: '57.0'
firefox: latest
dist: xenial
services:
- xvfb
dist: xenial
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "steal-stache",
"version": "4.1.5",
"version": "5.0.0-pre.2",
"description": "Load can-stache templates with StealJS",
"homepage": "http://canjs.com",
"repository": {
Expand Down Expand Up @@ -46,17 +46,15 @@
},
"dependencies": {
"can-assign": "^1.0.0",
"can-stache": "^4.0.0",
"can-stache": "^5.0.0-pre.3",
"can-stache-ast": "^1.0.0",
"can-stache-bindings": "^4.0.0",
"can-view-import": "^4.2.2",
"can-stache-bindings": "^5.0.0-pre.4",
"can-view-import": "^5.0.0-pre.1",
"steal-config-utils": "^1.0.0"
},
"devDependencies": {
"bit-docs": "0.0.7",
"can-test-helpers": "^1.1.0",
"can-view-callbacks": "^4.1.1",
"can-view-nodelist": "^4.0.0",
"can-view-callbacks": "^5.0.0-pre.1",
"jshint": "^2.9.4",
"steal": "^1.7.0",
"steal-qunit": "^2.0.0",
Expand Down
22 changes: 17 additions & 5 deletions steal-stache.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,32 @@ var loader = require("@loader");
var addImportSpecifiers = require("steal-config-utils/import-specifiers").addImportSpecifiers;

function template(imports, intermediate, filename){
var tagImportNames = JSON.stringify(imports.slice(7));
imports = JSON.stringify(imports);
intermediate = JSON.stringify(intermediate);

return "define("+imports+",function(module, assign, stache, mustacheCore){ \n" +
return "define("+imports+",function(module, assign, stache, mustacheCore, Scope, viewImport, bindings){ \n" +
"\tstache.addBindings(bindings);\n"+
(filename ?
"\tvar renderer = stache(" + JSON.stringify(filename) + ", " + intermediate + ");\n" :
"\tvar renderer = stache(" + intermediate + ");\n"
) +
"\tvar tagImports = Array.prototype.slice.call(arguments, 7);\n" +
"\treturn function(scope, options, nodeList){\n" +
"\t\tvar moduleOptions = assign({}, options);\n" +
"\t\tif(moduleOptions.helpers) {\n" +
"\t\t\tmoduleOptions.helpers = assign({ module: module }, moduleOptions.helpers);\n" +
"\t\t} else {\n" +
"\t\t\tmoduleOptions.module = module;\n" +
"\t\tvar tagImportMap = " + tagImportNames + ".reduce(function(map, name, index) {\n" +
"\t\t\tmap[name] = tagImports[index];\n" +
"\t\t\treturn map;\n" +
"\t\t}, {});\n" +
"\n"+
"\t\tif (!(scope instanceof Scope)) { scope = new Scope(scope); }\n" +
"\t\tvar variableScope = scope.getScope(function(s) { return s._meta.variable === true });\n" +
"\t\tif (!variableScope) {\n" +
"\t\t\tscope = scope.addLetContext();\n" +
"\t\t\tvariableScope = scope;\n" +
"\t\t}\n" +
"\t\tassign(variableScope._context, { module: module, tagImportMap: tagImportMap });\n" +
"\n" +
"\t\treturn renderer(scope, moduleOptions, nodeList);\n" +
"\t};\n" +
"});";
Expand Down Expand Up @@ -74,6 +85,7 @@ function translate(load) {
ast.imports, imports
);

ast.imports.unshift("can-view-scope");
ast.imports.unshift("can-stache/src/mustache_core");
ast.imports.unshift("can-stache");
ast.imports.unshift("can-assign");
Expand Down
34 changes: 17 additions & 17 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
var template = require("./template.stache!");
var nodeLists = require("can-view-nodelist");
var stache = require("can-stache");
var QUnit = require("steal-qunit");
var loader = require("@loader");
var clone = require("steal-clone");
var tag = require("can-view-callbacks").tag;

QUnit.module("steal-stache");

QUnit.test("node-lists work", function(assert) {
var nl = nodeLists.register([], undefined, true);
stache.registerHelper("importTestHelper", function(options) {
assert.equal(
options.nodeList,
nl.replacements[0],
"correct node list reference"
);
});
template({}, {}, nl);
});

QUnit.test("can-import works", function(assert) {
var done = assert.async();

Expand All @@ -38,6 +23,21 @@ QUnit.test("can-import works", function(assert) {
});
});

QUnit.test("`can-import`ed modules are available synchronously, and in a LetContext", function(assert){
var done = assert.async();

loader["import"]("test/tests/baz.stache").then(function(template) {
template({
test: function(value, scope) {
assert.equal(value, "works", "Initial render occurs with can-import already completed.");
assert.ok(scope._meta.variable, "Bottom scope is a LetContext.");
assert.equal(scope._context._data.bar, "works", "`bar` variable is in the LetContext.");
done();
}
});
});
});

QUnit.test("error messages includes the source", function(assert) {
var done = assert.async();

Expand Down Expand Up @@ -73,7 +73,7 @@ QUnit.test("module info is set when 'options' is missing", function(assert) {
var done = assert.async(2);

tag("fake-import", function fakeImport(el, tagData) {
var m = tagData.scope.get("scope.helpers.module");
var m = tagData.scope.get("module");
assert.ok(m.id.includes("test/module-meta/index"));
done();
});
Expand All @@ -88,7 +88,7 @@ QUnit.test("module info is set when 'options.helpers' exists", function(assert)
var done = assert.async(2);

tag("fake-import", function fakeImport(el, tagData) {
var m = tagData.scope.get("scope.helpers.module");
var m = tagData.scope.get("module");
assert.ok(m.id.includes("test/module-meta/index"));
done();
});
Expand Down
2 changes: 2 additions & 0 deletions test/tests/baz.stache
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<can-import from='test/tests/bar' module:to="bar" />
{{ test(bar, scope) }}

0 comments on commit 4f57d27

Please sign in to comment.