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 another issue with getTemplateLocals and block params #1412

Merged
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
13 changes: 13 additions & 0 deletions packages/@glimmer/syntax/lib/get-template-locals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ function tokensFromType(
return;
}

// the tag may be from a yielded object
// example:
// <x.button>
// An ElementNode does not parse the "tag" in to a PathExpression
// so we have to split on `.`, just like how `this` presence is checked.
if (tag.indexOf('.') !== -1) {
let [potentialLocal] = tag.split('.');

if (scopedTokens.indexOf(potentialLocal) !== -1) {
return;
}
}

if (scopedTokens.indexOf(tag) !== -1) {
return;
}
Expand Down
28 changes: 28 additions & 0 deletions packages/@glimmer/syntax/test/template-locals-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,34 @@ QUnit.test('it does not include locals', function (assert) {
assert.deepEqual(locals, ['SomeComponent']);
});

QUnit.test('it excludes object locals', function (assert) {
let locals = getTemplateLocals(
`
<SomeComponent as |b|>
<b.button />
</SomeComponent>
NullVoxPopuli marked this conversation as resolved.
Show resolved Hide resolved
`
);

assert.deepEqual(locals, ['SomeComponent']);
});

QUnit.test('it excludes object locals from nested blocks', function (assert) {
let locals = getTemplateLocals(
`
<SomeComponent as |some|>
<some.foo as |foo|>
<foo.bar as |bar|>
<bar.baz />
</foo.bar>
</some.foo>
</SomeComponent>
`
);

assert.deepEqual(locals, ['SomeComponent']);
});

QUnit.test('it can include keywords', function (assert) {
let locals = getTemplateLocals(
`
Expand Down