summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/javascript-compiler.js
diff options
context:
space:
mode:
authorCharles O'Farrell <charleso@charleso.org>2016-02-20 07:20:27 +1100
committerCharles O'Farrell <charleso@charleso.org>2016-03-08 07:23:45 +1100
commitc7be766902dee30fcd4e25f3674d537716e10c99 (patch)
tree8673a695de72a216b9b74fe87adb68d8b58d5078 /lib/handlebars/compiler/javascript-compiler.js
parent27212f59533d4d1f710d52e9463d2226b813d615 (diff)
downloadhandlebars.js-c7be766902dee30fcd4e25f3674d537716e10c99.zip
handlebars.js-c7be766902dee30fcd4e25f3674d537716e10c99.tar.gz
handlebars.js-c7be766902dee30fcd4e25f3674d537716e10c99.tar.bz2
Ensure that existing blockParams and depths are respected on dupe programs
Fixes #1186
Diffstat (limited to 'lib/handlebars/compiler/javascript-compiler.js')
-rw-r--r--lib/handlebars/compiler/javascript-compiler.js18
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js
index 1708032..4e4f288 100644
--- a/lib/handlebars/compiler/javascript-compiler.js
+++ b/lib/handlebars/compiler/javascript-compiler.js
@@ -701,11 +701,11 @@ JavaScriptCompiler.prototype = {
child = children[i];
compiler = new this.compiler(); // eslint-disable-line new-cap
- let index = this.matchExistingProgram(child);
+ let existing = this.matchExistingProgram(child);
- if (index == null) {
+ if (existing == null) {
this.context.programs.push(''); // Placeholder to prevent name conflicts for nested children
- index = this.context.programs.length;
+ let index = this.context.programs.length;
child.index = index;
child.name = 'program' + index;
this.context.programs[index] = compiler.compile(child, options, this.context, !this.precompile);
@@ -714,12 +714,14 @@ JavaScriptCompiler.prototype = {
this.useDepths = this.useDepths || compiler.useDepths;
this.useBlockParams = this.useBlockParams || compiler.useBlockParams;
+ child.useDepths = this.useDepths;
+ child.useBlockParams = this.useBlockParams;
} else {
- child.index = index;
- child.name = 'program' + index;
+ child.index = existing.index;
+ child.name = 'program' + existing.index;
- this.useDepths = this.useDepths || child.useDepths;
- this.useBlockParams = this.useBlockParams || child.useBlockParams;
+ this.useDepths = this.useDepths || existing.useDepths;
+ this.useBlockParams = this.useBlockParams || existing.useBlockParams;
}
}
},
@@ -727,7 +729,7 @@ JavaScriptCompiler.prototype = {
for (let i = 0, len = this.context.environments.length; i < len; i++) {
let environment = this.context.environments[i];
if (environment && environment.equals(child)) {
- return i;
+ return environment;
}
}
},