Skip to content

Commit

Permalink
Merge pull request #1406 from simonihmig/fix-template-locals-block-pa…
Browse files Browse the repository at this point in the history
…rams

Fix getTemplateLocals for yielded block params
  • Loading branch information
chriskrycho committed Jan 18, 2023
2 parents ec5648f + 7a80c96 commit 82ea580
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/@glimmer/syntax/lib/get-template-locals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,17 @@ function addTokens(

(Array.isArray(maybeTokens) ? maybeTokens : [maybeTokens]).forEach((maybeToken) => {
if (maybeToken !== undefined && maybeToken[0] !== '@') {
tokensSet.add(maybeToken.split('.')[0]);
const maybeTokenFirstSegment = maybeToken.split('.')[0];
if (!scopedTokens.includes(maybeTokenFirstSegment)) {
tokensSet.add(maybeToken.split('.')[0]);
}
}
});
}

/**
* Parses and traverses a given handlebars html template to extract all template locals
* referenced that could possible come from the praent scope. Can exclude known keywords
* referenced that could possible come from the parent scope. Can exclude known keywords
* optionally.
*/
export function getTemplateLocals(
Expand Down
12 changes: 12 additions & 0 deletions packages/@glimmer/syntax/test/template-locals-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ QUnit.test('it works', function (assert) {
<this.dynamicAngleComponent>
</this.dynamicAngleComponent>
<ComponentYieldingContextual as |hash|>
<InsideHash />
<hash.some as |some|>
{{inside-another-hash}}
<some.other/>
{{some.value}}
</hash.some>
</ComponentYieldingContextual>
`);

assert.deepEqual(locals, [
Expand All @@ -45,6 +54,9 @@ QUnit.test('it works', function (assert) {
'global-value',
'some',
'someOther',
'ComponentYieldingContextual',
'InsideHash',
'inside-another-hash',
]);
});

Expand Down

0 comments on commit 82ea580

Please sign in to comment.