Post-merge-review: Fix template-no-implicit-this: callee detection, block-param scoping, bare {{this}}#2659
Open
johanrd wants to merge 1 commit intoember-cli:masterfrom
Open
Conversation
… JS scope, bare {{this}}
Four false positives in the port:
1. SubExpression, ElementModifier, and BlockStatement callees were
incorrectly flagged as ambiguous paths. Upstream whitelists all
callee positions via a `nextPathIsCallee` flag.
2. Block-param scope tracking only checked the direct parent, so
`{{#each @Items as |item|}}{{item.name}}{{/each}}` falsely flagged
`item.name`. Fix walks the ancestor chain.
3. Bare JS scope bindings (imports, const, function params) in GJS/GTS
strict mode were flagged as ambiguous — `const x = 1; <template>{{x}}</template>`
would report `x` as needing `@x` or `this.x`. Fix uses
`sourceCode.getScope()` to detect legitimate JS bindings. Pattern
already used by `template-no-restricted-invocations`,
`template-no-redundant-fn`, and `template-no-let-reference`.
4. Bare `{{this}}` was flagged because the startsWith-check didn't
catch the exact string "this".
This also replaces the previous `CONTROL_FLOW_HELPERS` workaround (which
blanket-skipped positional args of if/unless/each/etc) with the more
precise JS scope check. `{{if condition "y" "n"}}` without any binding
for `condition` is now correctly flagged as ambiguous.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's broken on
masterFour independent false positives:
{{echo (my-helper)}},<div {{my-modifier}}>, and{{#my-component}}…{{/my-component}}are all flagged as ambiguousthis.*candidates. Upstream whitelists all callee positions via anextPathIsCalleeflag (no-implicit-this.jsL104–151).{{#each @items as |item|}}{{item.name}}{{/each}}flagsitem.namebecause the scope walker stops at the direct parent. Fix walks the ancestor chain.import x from '…'; <template>{{x}}</template>orconst cond = false; <template>{{if cond "y" "n"}}</template>produce false positives because the port doesn't check whether the identifier resolves to a JavaScript binding. The existingCONTROL_FLOW_HELPERSblanket-skip is a coarse workaround (it exempts all positional args ofif/unless/each/etc., even truly-ambiguous ones).{{this}}flagged. Master's startsWith-check doesn't catch the exact string"this".Fix
isCalleePositionthat treatsSubExpression/BlockStatement/ElementModifierStatementcallees as always-valid, andMustacheStatementcallees as valid only when the mustache has arguments.isLocalBlockParamwalks up the ancestor chain collectingGlimmerBlockStatement.program.blockParams.isJsScopeVariableusessourceCode.getScope()to detect JS bindings. Replaces the coarseCONTROL_FLOW_HELPERSworkaround with precise detection: truly-ambiguous paths like{{if condition "y" "n"}}(no binding forcondition) are now correctly flagged again. Pattern matchestemplate-no-redundant-fnandtemplate-no-restricted-invocations(isJsScopeVariable).path === 'this'.Test plan
{{this}}, and 3 new valid tests for JS-scope bindings (const,import,constwith{{#each}}). All fail on master.{{if condition "yes" "no"}}with no JS binding) confirms control-flow args are correctly flagged when truly ambiguous. Fails on master (master silently allowed viaCONTROL_FLOW_HELPERS).Co-written by Claude.