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

Fixup issues with dynamic angle bracket invocation. #827

Merged
merged 1 commit into from
Jun 4, 2018
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
10 changes: 6 additions & 4 deletions packages/@glimmer/compiler/lib/template-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,19 +464,21 @@ function isArg(path: AST.PathExpression): boolean {
function isDynamicComponent(element: AST.ElementNode): boolean {
let open = element.tag.charAt(0);

let [maybeLocal] = element.tag.split('.');
let isNamedArgument = open === '@';
let isLocal = element['symbols'].has(element.tag);
let isPath = element.tag.indexOf('.') > -1;
let isLocal = element['symbols'].has(maybeLocal);
let isThisPath = element.tag.indexOf('this.') === 0;

return isLocal || isNamedArgument || isPath;
return isLocal || isNamedArgument || isThisPath;
}

function isComponent(element: AST.ElementNode): boolean {
let open = element.tag.charAt(0);
let isPath = element.tag.indexOf('.') > -1;

let isUpperCase = open === open.toUpperCase() && open !== open.toLowerCase();

return isUpperCase || isDynamicComponent(element);
return (isUpperCase && !isPath) || isDynamicComponent(element);
}

function assertIsSimplePath(path: AST.PathExpression, loc: AST.SourceLocation, context: string) {
Expand Down
60 changes: 60 additions & 0 deletions packages/@glimmer/test-helpers/lib/suites/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,23 @@ export class BasicComponents extends RenderTest {
this.assertStableRerender();
}

@test({
kind: 'glimmer',
})
'invoking dynamic component (named arg path) via angle brackets'() {
this.registerHelper('hash', (_positional, named) => named);
this.registerComponent('Glimmer', 'Foo', 'hello world!');
this.render({
layout: '<@stuff.Foo />',
args: {
stuff: 'hash Foo=(component "Foo")',
},
});

this.assertHTML(`<div>hello world!</div>`);
this.assertStableRerender();
}

@test({
kind: 'glimmer',
})
Expand Down Expand Up @@ -297,6 +314,18 @@ export class BasicComponents extends RenderTest {
this.assertStableRerender();
}

@test({
kind: 'glimmer',
})
'invoking dynamic component (local path) via angle brackets'() {
this.registerHelper('hash', (_positional, named) => named);
this.registerComponent('Glimmer', 'Foo', 'hello world!');
this.render(`{{#with (hash Foo=(component 'Foo')) as |Other|}}<Other.Foo />{{/with}}`);

this.assertHTML(`hello world!`);
this.assertStableRerender();
}

@test({
kind: 'glimmer',
})
Expand Down Expand Up @@ -412,6 +441,37 @@ export class BasicComponents extends RenderTest {
this.assertStableRerender();
}

@test({
kind: 'glimmer',
})
'invoking dynamic component (path) via angle brackets does not support implicit `this` fallback'() {
class TestHarness extends EmberishGlimmerComponent {
public stuff: any;

constructor(args: any) {
super();
this.stuff = {
Foo: args.attrs.Foo,
};
}
}
this.registerComponent('Glimmer', 'TestHarness', '<stuff.Foo />', TestHarness);
this.registerComponent(
'Glimmer',
'Foo',
'hello world!',
class extends EmberishGlimmerComponent {
constructor() {
super(...arguments);
throw new Error('Should not have instantiated Foo component.');
}
}
);

this.render('<TestHarness @Foo={{component "Foo"}} />');
this.assertStableRerender();
}

@test({
kind: 'glimmer',
})
Expand Down