-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (48 loc) · 1.32 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
const parse = require('can-stache-ast').parse
function makeRenderer (imports, intermediate, filename) {
intermediate = JSON.stringify(intermediate)
filename = JSON.stringify(filename)
const requires = imports.map(function (imported) {
return 'require(\'' + imported + '\');'
}).join('\n')
return `
const stache = require('can-stache');
const mustacheCore = require( "can-stache/src/mustache_core" );
const parse = require("can-stache-ast").parse;
//common deps
require('can-view-import');
require('can-stache-bindings');
${requires}
${
filename
? `const renderer = stache(${filename}, ${intermediate})`
: `const renderer = stache(${intermediate}) ;`
}
module.exports = function(scope, options, nodeList) {
const 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 = {
process (src, filename, config, options) {
const ast = parse(filename, src)
const results = ast.dynamicImports
const imports = results[0]
ast.imports.unshift.apply(
ast.imports, imports
)
return {
code: makeRenderer(
ast.imports,
ast.intermediate,
filename
)
}
}
}