summaryrefslogtreecommitdiffstats
path: root/lib/precompiler.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/precompiler.js')
-rw-r--r--lib/precompiler.js23
1 files changed, 9 insertions, 14 deletions
diff --git a/lib/precompiler.js b/lib/precompiler.js
index 8a2019d..12a5a1f 100644
--- a/lib/precompiler.js
+++ b/lib/precompiler.js
@@ -94,7 +94,9 @@ module.exports.cli = function(opts) {
if (opts.simple && opts.min) {
throw new Handlebars.Exception('Unable to minimize simple output');
}
- if (opts.simple && (opts.templates.length !== 1 || opts.hasDirectory)) {
+
+ const multiple = opts.templates.length !== 1 || opts.hasDirectory;
+ if (opts.simple && multiple) {
throw new Handlebars.Exception('Unable to output multiple templates in simple mode');
}
@@ -109,6 +111,8 @@ module.exports.cli = function(opts) {
}
}
+ const objectName = opts.partial ? 'Handlebars.partials' : 'templates';
+
let output = new SourceNode();
if (!opts.simple) {
if (opts.amd) {
@@ -151,28 +155,19 @@ module.exports.cli = function(opts) {
if (opts.simple) {
output.add([precompiled, '\n']);
- } else if (opts.partial) {
- if (opts.amd && (opts.templates.length == 1 && !opts.hasDirectory)) {
- output.add('return ');
- }
- output.add(['Handlebars.partials[\'', template.name, '\'] = template(', precompiled, ');\n']);
} else {
- if (opts.amd && (opts.templates.length == 1 && !opts.hasDirectory)) {
+ if (opts.amd && !multiple) {
output.add('return ');
}
- output.add(['templates[\'', template.name, '\'] = template(', precompiled, ');\n']);
+ output.add([objectName, '[\'', template.name, '\'] = template(', precompiled, ');\n']);
}
});
// Output the content
if (!opts.simple) {
if (opts.amd) {
- if (opts.templates.length > 1 || (opts.templates.length == 1 && opts.hasDirectory)) {
- if (opts.partial) {
- output.add('return Handlebars.partials;\n');
- } else {
- output.add('return templates;\n');
- }
+ if (multiple) {
+ output.add(['return ', objectName, ';\n']);
}
output.add('});');
} else if (!opts.commonjs) {