diff --git a/package.json b/package.json
index b2a3f64..3eca2b3 100644
--- a/package.json
+++ b/package.json
@@ -46,15 +46,17 @@
},
"dependencies": {
"can-stache": "^4.0.0",
+ "can-stache-ast": "^1.0.0",
"can-stache-bindings": "^4.0.0",
- "can-view-import": "^4.0.0"
+ "can-view-import": "^4.0.0",
+ "steal-config-utils": "^1.0.0"
},
"devDependencies": {
"bit-docs": "0.0.7",
"can-test-helpers": "^1.1.0",
"can-view-nodelist": "^4.0.0",
"jshint": "^2.9.4",
- "steal": "^1.5.11",
+ "steal": "^1.7.0",
"steal-qunit": "^1.0.0",
"steal-tools": "^1.0.0",
"testee": "^0.7.0"
diff --git a/steal-stache.js b/steal-stache.js
index 6043247..3784d4e 100644
--- a/steal-stache.js
+++ b/steal-stache.js
@@ -1,7 +1,8 @@
"format cjs";
-var getIntermediateAndImports = require("can-stache/src/intermediate_and_imports");
+var parse = require("can-stache-ast").parse;
var addBundles = require("./add-bundles");
var loader = require("@loader");
+var addImportSpecifiers = require("steal-config-utils/import-specifiers").addImportSpecifiers;
function template(imports, intermediate, filename){
imports = JSON.stringify(imports);
@@ -35,7 +36,7 @@ function translate(load) {
filename = getFilename(load.name);
//!steal-remove-end
- var intermediateAndImports = getIntermediateAndImports(filename, load.source);
+ var ast = parse(filename, load.source);
var commonDependencies = Promise.all([
this.normalize("can-view-import", module.id),
@@ -49,29 +50,32 @@ function translate(load) {
var push = Array.prototype.push;
var toMap = localLoader.slimConfig.toMap;
- push.apply(toMap, intermediateAndImports.imports);
- push.apply(toMap, intermediateAndImports.dynamicImports);
+ push.apply(toMap, ast.imports);
+ push.apply(toMap, ast.dynamicImports);
}
+ // Add import specifier line numbers for debugging
+ addImportSpecifiers(load, ast);
+
// Add bundle configuration for these dynamic imports
return Promise.all([
- addBundles(intermediateAndImports.dynamicImports, load.name),
+ addBundles(ast.dynamicImports, load.name),
commonDependencies
]).then(function(results){
var imports = results[1];
// In add in the common dependencies of every stache file
- intermediateAndImports.imports.unshift.apply(
- intermediateAndImports.imports, imports
+ ast.imports.unshift.apply(
+ ast.imports, imports
);
- intermediateAndImports.imports.unshift("can-stache/src/mustache_core");
- intermediateAndImports.imports.unshift("can-stache");
- intermediateAndImports.imports.unshift("module");
+ ast.imports.unshift("can-stache/src/mustache_core");
+ ast.imports.unshift("can-stache");
+ ast.imports.unshift("module");
return template(
- intermediateAndImports.imports,
- intermediateAndImports.intermediate,
+ ast.imports,
+ ast.intermediate,
filename
);
});
diff --git a/test/test.js b/test/test.js
index 430228b..c655396 100644
--- a/test/test.js
+++ b/test/test.js
@@ -32,6 +32,16 @@ QUnit.test("can-import works", function(){
});
});
+QUnit.test("error messages includes the source", function(){
+ stop();
+ loader["import"]("test/tests/oops.stache")
+ .then(null, function(err){
+ ok(/can-import/.test(err.message), "can-import code is in the message");
+ ok(/oops.stache/.test(err.stack), "the importing file is in the stack");
+ start();
+ });
+});
+
QUnit.test("can-import is provided the filename", function(){
stop();
clone({
diff --git a/test/tests/oops.stache b/test/tests/oops.stache
new file mode 100644
index 0000000..196e669
--- /dev/null
+++ b/test/tests/oops.stache
@@ -0,0 +1,5 @@
+
+
+