summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2015-08-04 12:33:05 -0500
committerkpdecker <kpdecker@gmail.com>2015-08-04 12:33:05 -0500
commit77e6bfc5a1c62336b1eb67427bc194b79226127a (patch)
treeafce422201b94f9121c5c81b7beba72a07d6b46f
parent00f74420f949a42bedd99af022c20cdc5027228d (diff)
downloadhandlebars.js-77e6bfc5a1c62336b1eb67427bc194b79226127a.zip
handlebars.js-77e6bfc5a1c62336b1eb67427bc194b79226127a.tar.gz
handlebars.js-77e6bfc5a1c62336b1eb67427bc194b79226127a.tar.bz2
Simplify object assignment generation logic
-rw-r--r--lib/precompiler.js23
-rw-r--r--spec/precompiler.js7
2 files changed, 16 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) {
diff --git a/spec/precompiler.js b/spec/precompiler.js
index 72a7ce6..25c57a8 100644
--- a/spec/precompiler.js
+++ b/spec/precompiler.js
@@ -196,5 +196,12 @@ describe('precompiler', function() {
done(err);
});
});
+
+ it('should complete when no args are passed', function(done) {
+ Precompiler.loadTemplates({}, function(err, opts) {
+ equal(opts.templates.length, 0);
+ done(err);
+ });
+ });
});
});