-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
65 lines (55 loc) · 1.57 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var loaderUtils = require("loader-utils");
var parse = require("can-stache-ast").parse;
function makeRenderer(imports, intermediate, filename) {
intermediate = JSON.stringify(intermediate);
filename = JSON.stringify(filename);
var requires = imports.map(function(imported) {
return 'require(\'' + imported + '\');';
}).join('\n');
return `
var stache = require('can-stache');
var mustacheCore = require( "can-stache/src/mustache_core" );
var parse = require("can-stache-ast").parse;
//common deps
require('can-view-import');
require('can-stache-bindings');
${requires}
${
filename ?
`var renderer = stache(${filename}, ${intermediate})` :
`var renderer = stache(${intermediate}) ;`
}
module.exports = function(scope, options, nodeList) {
var moduleOptions = Object.assign({}, options);
if(moduleOptions.helpers) {
moduleOptions.helpers = Object.assign({ module: module }, moduleOptions.helpers);
} else {
moduleOptions.module = module;
}
return renderer( scope, moduleOptions, nodeList );
};
`;
}
module.exports = function(source, map) {
var filename = loaderUtils.getRemainingRequest(this);
var ast = parse(filename, source);
var callback = this.async();
Promise.all([
ast.dynamicImports
]).then(function(results) {
var imports = results[0];
ast.imports.unshift.apply(
ast.imports, imports
);
var renderer = makeRenderer(
ast.imports,
ast.intermediate,
filename
);
callback(
null,
renderer,
map
);
});
};