diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index 5a86e9a0..63b97c71 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -164,12 +164,10 @@ JavaScriptCompiler.prototype = { let { programs, decorators } = this.context; for (i = 0, l = programs.length; i < l; i++) { - if (programs[i]) { - ret[i] = programs[i]; - if (decorators[i]) { - ret[i + '_d'] = decorators[i]; - ret.useDecorators = true; - } + ret[i] = programs[i]; + if (decorators[i]) { + ret[i + '_d'] = decorators[i]; + ret.useDecorators = true; } } @@ -833,8 +831,8 @@ JavaScriptCompiler.prototype = { let existing = this.matchExistingProgram(child); if (existing == null) { - this.context.programs.push(''); // Placeholder to prevent name conflicts for nested children - let index = this.context.programs.length; + // Placeholder to prevent name conflicts for nested children + let index = this.context.programs.push('') - 1; child.index = index; child.name = 'program' + index; this.context.programs[index] = compiler.compile( diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js index 49842c34..0f654dbe 100644 --- a/lib/handlebars/runtime.js +++ b/lib/handlebars/runtime.js @@ -93,15 +93,8 @@ export function template(templateSpec, env) { } if (result != null) { if (options.indent) { - let lines = result.split('\n'); - for (let i = 0, l = lines.length; i < l; i++) { - if (!lines[i] && i + 1 === l) { - break; - } - - lines[i] = options.indent + lines[i]; - } - result = lines.join('\n'); + result = + options.indent + result.replace(/\n(?!$)/g, '\n' + options.indent); } return result; } else { diff --git a/spec/expected/non.empty.amd.known.helper.js b/spec/expected/non.empty.amd.known.helper.js index 75c81cdc..81e4b117 100644 --- a/spec/expected/non.empty.amd.known.helper.js +++ b/spec/expected/non.empty.amd.known.helper.js @@ -1,6 +1,6 @@ define(['handlebars.runtime'], function(Handlebars) { Handlebars = Handlebars["default"]; var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; -return templates['known.helpers'] = template({"1":function(container,depth0,helpers,partials,data) { +return templates['known.helpers'] = template({"0":function(container,depth0,helpers,partials,data) { var stack1, lookupProperty = container.lookupProperty || function(parent, propertyName) { if (Object.prototype.hasOwnProperty.call(parent, propertyName)) { return parent[propertyName]; @@ -8,8 +8,8 @@ return parent[propertyName]; return undefined }; return "