diff options
-rw-r--r-- | lib/handlebars/compiler/helpers.js | 4 | ||||
-rw-r--r-- | lib/handlebars/compiler/javascript-compiler.js | 18 | ||||
-rw-r--r-- | lib/precompiler.js | 6 | ||||
-rw-r--r-- | spec/precompiler.js | 30 | ||||
-rw-r--r-- | src/parser-prefix.js | 1 |
5 files changed, 43 insertions, 16 deletions
diff --git a/lib/handlebars/compiler/helpers.js b/lib/handlebars/compiler/helpers.js index c93b811..dd32299 100644 --- a/lib/handlebars/compiler/helpers.js +++ b/lib/handlebars/compiler/helpers.js @@ -135,12 +135,12 @@ function isNextWhitespace(statements, i, isRoot) { return checkWhitespace(isRoot, statements[i+1], statements[i+2]); } -function checkWhitespace(isRoot, next1, next2, disallowIndent) { +function checkWhitespace(isRoot, next1, next2) { if (!next1) { return isRoot; } else if (next1.type === 'content') { // Check if the previous node is empty or whitespace only - if (disallowIndent ? !next1.string : /^[\s]*$/.test(next1.string)) { + if (/^[\s]*$/.test(next1.string)) { if (next2) { return next2.type === 'content' || /\n$/.test(next1.string); } else { diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index fcd58fd..e53b4f2 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -50,7 +50,7 @@ JavaScriptCompiler.prototype = { compile: function(environment, options, context, asObject) { this.environment = environment; - this.options = options || {}; + this.options = options; this.stringParams = this.options.stringParams; this.trackIds = this.options.trackIds; this.precompile = !asObject; @@ -361,9 +361,9 @@ JavaScriptCompiler.prototype = { return ' != null ? ' + lookup + ' : ' + current; } else { // Otherwise we can use generic falsy handling - return (falsy ? ' && ' : ' != null && ') + lookup; + return ' && ' + lookup; } - }, true); + }); } }, @@ -385,7 +385,7 @@ JavaScriptCompiler.prototype = { for (var i = 0; i < len; i++) { this.replaceStack(function(current) { return ' && ' + this.nameLookup(current, parts[i], 'data'); - }, true); + }); } }, @@ -714,7 +714,7 @@ JavaScriptCompiler.prototype = { return stack; }, - replaceStack: function(callback, chain) { + replaceStack: function(callback) { var prefix = '', inline = this.isInline(), stack, @@ -731,18 +731,14 @@ JavaScriptCompiler.prototype = { if (top instanceof Literal) { // Literals do not need to be inlined - stack = top.value; + prefix = stack = top.value; usedLiteral = true; - - if (chain) { - prefix = stack; - } } else { // Get or create the current stack name for use by the inline createdStack = !this.stackSlot; var name = !createdStack ? this.topStackName() : this.incrStack(); - prefix = '(' + this.push(name) + ' = ' + top + (chain ? ')' : '),'); + prefix = '(' + this.push(name) + ' = ' + top + ')'; stack = this.topStack(); } diff --git a/lib/precompiler.js b/lib/precompiler.js index bae923c..6764022 100644 --- a/lib/precompiler.js +++ b/lib/precompiler.js @@ -60,7 +60,7 @@ module.exports.cli = function(opts) { output.push(opts.namespace); output.push(' || {};\n'); } - function processTemplate(template, root, explicit) { + function processTemplate(template, root) { var path = template, stat = fs.statSync(path); if (stat.isDirectory()) { @@ -71,7 +71,7 @@ module.exports.cli = function(opts) { processTemplate(path, root || template); } }); - } else if (explicit || extension.test(path)) { + } else { var data = fs.readFileSync(path, 'utf8'); if (opts.bom && data.indexOf('\uFEFF') === 0) { @@ -112,7 +112,7 @@ module.exports.cli = function(opts) { } opts.templates.forEach(function(template) { - processTemplate(template, opts.root, true); + processTemplate(template, opts.root); }); // Output the content diff --git a/spec/precompiler.js b/spec/precompiler.js index 57fc280..3b66353 100644 --- a/spec/precompiler.js +++ b/spec/precompiler.js @@ -75,9 +75,39 @@ describe('precompiler', function() { Precompiler.cli({templates: [__dirname + '/artifacts/empty.handlebars'], amd: true, extension: 'handlebars'}); equal(/template\(amd\)/.test(log), true); }); + it('should output multiple amd', function() { + Handlebars.precompile = function() { return 'amd'; }; + Precompiler.cli({templates: [__dirname + '/artifacts'], amd: true, extension: 'handlebars'}); + equal(/return templates/.test(log), true); + equal(/template\(amd\)/.test(log), true); + }); + it('should output amd partials', function() { + Handlebars.precompile = function() { return 'amd'; }; + Precompiler.cli({templates: [__dirname + '/artifacts/empty.handlebars'], amd: true, partial: true, extension: 'handlebars'}); + equal(/return Handlebars\.partials\['empty'\]/.test(log), true); + equal(/template\(amd\)/.test(log), true); + }); + it('should output multiple amd partials', function() { + Handlebars.precompile = function() { return 'amd'; }; + Precompiler.cli({templates: [__dirname + '/artifacts'], amd: true, partial: true, extension: 'handlebars'}); + equal(/return Handlebars\.partials\[/.test(log), false); + equal(/template\(amd\)/.test(log), true); + }); it('should output commonjs templates', function() { Handlebars.precompile = function() { return 'commonjs'; }; Precompiler.cli({templates: [__dirname + '/artifacts/empty.handlebars'], commonjs: true, extension: 'handlebars'}); equal(/template\(commonjs\)/.test(log), true); }); + + it('should set data flag', function() { + Handlebars.precompile = function(data, options) { equal(options.data, true); return 'simple'; }; + Precompiler.cli({templates: [__dirname + '/artifacts/empty.handlebars'], simple: true, extension: 'handlebars', data: true}); + equal(log, 'simple\n'); + }); + + it('should set known helpers', function() { + Handlebars.precompile = function(data, options) { equal(options.knownHelpers.foo, true); return 'simple'; }; + Precompiler.cli({templates: [__dirname + '/artifacts/empty.handlebars'], simple: true, extension: 'handlebars', known: 'foo'}); + equal(log, 'simple\n'); + }); }); diff --git a/src/parser-prefix.js b/src/parser-prefix.js index 685b6ec..a4ba487 100644 --- a/src/parser-prefix.js +++ b/src/parser-prefix.js @@ -1 +1,2 @@ /* jshint ignore:start */ +/* istanbul ignore next */ |