Ensure that existing blockParams and depths are respected on dupe programs

Fixes #1186
This commit is contained in:
Charles O'Farrell
2016-02-20 07:20:27 +11:00
committed by Lon Ingram
parent 1b885d496a
commit 8ff49cef52
2 changed files with 19 additions and 8 deletions
+10 -8
View File
@@ -778,11 +778,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);
@@ -791,12 +791,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;
}
}
},
@@ -804,7 +806,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;
}
}
},
+9
View File
@@ -268,4 +268,13 @@ describe('Regressions', function() {
' 1. IF: John--\n'
+ ' 2. MYIF: John==\n');
});
it('GH-1186: Support block params for existing programs', function() {
var string =
'{{#*inline "test"}}{{> @partial-block }}{{/inline}}'
+ '{{#>test }}{{#each listOne as |item|}}{{ item }}{{/each}}{{/test}}'
+ '{{#>test }}{{#each listTwo as |item|}}{{ item }}{{/each}}{{/test}}';
shouldCompileTo(string, { listOne: ['a'], listTwo: ['b']}, 'ab', '');
});
});