Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path lookup inside helpers #707

Merged
merged 3 commits into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/@glimmer/compiler/lib/template-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ export default class TemplateCompiler {

if (expr.this) {
this.opcode('get', expr, 0, expr.parts);
} else if (symbols.has(head)) {
} else if (symbols.has(head)) {
this.opcode('get', expr, symbols.get(head), expr.parts.slice(1));
} else {
this.opcode('get', expr, 0, expr.parts);
this.opcode('maybeLocal',expr, expr.parts);
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions packages/@glimmer/runtime/test/partial-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,32 @@ QUnit.test('dynamic partial with local reference (unknown)', () => {
equalTokens(root, `You smaht. You loyal. `);
});

QUnit.test('partial with if statement on a simple local reference works as expected', () => {
let template = compile(`{{#each qualities key='@index' as |quality|}}{{partial name}}. {{/each}}`);

env.registerPartial('test', `{{#if quality}}You {{quality}}{{else}}No quality{{/if}}`);
render(template, { name: 'test', qualities: ['smaht', 'loyal', undefined] });

rerender(null, { assertStable: true });

equalTokens(root, `You smaht. You loyal. No quality. `);
rerender({ name: 'test', qualities: ['smaht', 'loyal', undefined] }, { assertStable: true });
equalTokens(root, `You smaht. You loyal. No quality. `);
});

QUnit.test('partial with if statement on a path local reference works as expected', () => {
let template = compile(`{{#each qualities key='@index' as |quality|}}{{partial name}}. {{/each}}`);

env.registerPartial('test', `{{#if quality.name}}You {{quality.name}}{{else}}No quality{{/if}}`);
render(template, { name: 'test', qualities: [{ name: 'smaht' }, { name: 'loyal' }, { name: undefined }] });

rerender(null, { assertStable: true });

equalTokens(root, `You smaht. You loyal. No quality. `);
rerender({ name: 'test', qualities: [{ name: 'smaht' }, { name: 'loyal' }, { name: undefined }] }, { assertStable: true });
equalTokens(root, `You smaht. You loyal. No quality. `);
});

QUnit.test('partial without arguments throws', assert => {
assert.throws(function() {
compile(`Before {{partial}} After`);
Expand Down