diff options
-rw-r--r-- | lib/handlebars/compiler/helpers.js | 3 | ||||
-rw-r--r-- | lib/handlebars/compiler/javascript-compiler.js | 4 | ||||
-rw-r--r-- | spec/artifacts/bom.handlebars | 1 | ||||
-rw-r--r-- | spec/precompiler.js | 31 |
4 files changed, 35 insertions, 4 deletions
diff --git a/lib/handlebars/compiler/helpers.js b/lib/handlebars/compiler/helpers.js index 20f13d6..5aa0f2c 100644 --- a/lib/handlebars/compiler/helpers.js +++ b/lib/handlebars/compiler/helpers.js @@ -98,7 +98,8 @@ export function prepareProgram(statements, isRoot) { if (omitLeft(statements, i)) { // If we are on a standalone node, save the indent info for partials if (current.type === 'partial') { - current.indent = (/([ \t]+$)/).exec(statements[i-1].original) ? RegExp.$1 : ''; + // Pull out the whitespace from the final line + current.indent = (/([ \t]+$)/).exec(statements[i-1].original)[1]; } } } diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index 4b7ee6f..376bc6b 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -732,8 +732,8 @@ JavaScriptCompiler.prototype = { usedLiteral = true; } else { // Get or create the current stack name for use by the inline - createdStack = !this.stackSlot; - var name = !createdStack ? this.topStackName() : this.incrStack(); + createdStack = true; + var name = this.incrStack(); prefix = '(' + this.push(name) + ' = ' + top + ')'; stack = this.topStack(); diff --git a/spec/artifacts/bom.handlebars b/spec/artifacts/bom.handlebars new file mode 100644 index 0000000..548d714 --- /dev/null +++ b/spec/artifacts/bom.handlebars @@ -0,0 +1 @@ +a
\ No newline at end of file diff --git a/spec/precompiler.js b/spec/precompiler.js index bd19fbf..9d883b6 100644 --- a/spec/precompiler.js +++ b/spec/precompiler.js @@ -9,27 +9,38 @@ describe('precompiler', function() { var Handlebars = require('../lib'), Precompiler = require('../lib/precompiler'), + fs = require('fs'), uglify = require('uglify-js'); var log, logFunction, precompile, - minify; + minify, + + file, + content, + writeFileSync; beforeEach(function() { precompile = Handlebars.precompile; minify = uglify.minify; + writeFileSync = fs.writeFileSync; logFunction = console.log; log = ''; console.log = function() { log += Array.prototype.join.call(arguments, ''); }; + fs.writeFileSync = function(_file, _content) { + file = _file; + content = _content; + }; }); afterEach(function() { Handlebars.precompile = precompile; uglify.minify = minify; + fs.writeFileSync = writeFileSync; console.log = logFunction; }); @@ -121,6 +132,24 @@ describe('precompiler', function() { equal(log, 'simple\n'); }); + it('should handle different root', function() { + Handlebars.precompile = function() { return 'simple'; }; + Precompiler.cli({templates: [__dirname + '/artifacts/empty.handlebars'], simple: true, extension: 'handlebars', root: 'foo/'}); + equal(log, 'simple\n'); + }); + it('should output to file system', function() { + Handlebars.precompile = function() { return 'simple'; }; + Precompiler.cli({templates: [__dirname + '/artifacts/empty.handlebars'], simple: true, extension: 'handlebars', output: 'file!'}); + equal(file, 'file!'); + equal(content, 'simple\n'); + equal(log, ''); + }); + it('should handle BOM', function() { + Handlebars.precompile = function(template) { return template === 'a' ? 'simple' : 'fail'; }; + Precompiler.cli({templates: [__dirname + '/artifacts/bom.handlebars'], simple: true, extension: 'handlebars', bom: true}); + equal(log, 'simple\n'); + }); + it('should output minimized templates', function() { Handlebars.precompile = function() { return 'amd'; }; uglify.minify = function() { return {code: 'min'}; }; |