Skip to content

Commit

Permalink
Lexical "this" capture
Browse files Browse the repository at this point in the history
  • Loading branch information
ef4 committed Jan 9, 2025
1 parent c7f8e59 commit c9a01af
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 0 additions & 1 deletion packages/@glimmer/syntax/lib/v2/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ export class Builder {
isTemplateLocal: boolean,
loc: SourceSpan
): ASTv2.VariableReference {
assert(name !== 'this', `You called builders.var() with 'this'. Call builders.this instead`);
assert(
name[0] !== '@',
`You called builders.var() with '${name}'. Call builders.at('${name}') instead`
Expand Down
4 changes: 4 additions & 0 deletions packages/@glimmer/syntax/lib/v2/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ class ExpressionNormalizer {

switch (head.type) {
case 'ThisHead':
if (block.hasBinding('this')) {
let [symbol, isRoot] = table.get('this');
return block.builder.localVar('this', symbol, isRoot, offsets);
}
return builder.self(offsets);
case 'AtHead': {
let symbol = table.allocateNamed(head.name);
Expand Down

0 comments on commit c9a01af

Please sign in to comment.