Skip to content

Commit

Permalink
Merge pull request #60 from canjs/err
Browse files Browse the repository at this point in the history
Add improved error messaging.
  • Loading branch information
matthewp authored Mar 1, 2018
2 parents fd04162 + 9dfd057 commit 693c1e5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 16 additions & 12 deletions steal-stache.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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),
Expand All @@ -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
);
});
Expand Down
10 changes: 10 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
5 changes: 5 additions & 0 deletions test/tests/oops.stache
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<can-import from="./file-missing" />

<section class="app">
<div>...</div>
</section>

0 comments on commit 693c1e5

Please sign in to comment.