Skip to content

fix(template-no-shadowed-elements): report tags shadowed by a JS binding - #2917

Merged
NullVoxPopuli merged 4 commits into
ember-cli:masterfrom
johanrd:fix/shadowed-elements-js-scope
Dec 1, 2026
Merged

NullVoxPopuli merged 4 commits into
ember-cli:masterfrom
johanrd:fix/shadowed-elements-js-scope

Conversation

@johanrd

@johanrd johanrd commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

In gjs/gts the template compiler resolves a tag against the JS scope around the template: a tag whose name is bound there is a component invocation, whatever its case (classifyTag in @glimmer/syntax: "In strict mode, values are always elements unless they are in scope"; RFC 779 gives const foo = <template>...</template> invoked as <foo />; confirmed as intended in glimmerjs/glimmer-vm#1637).

So a binding named like an element silently turns that element into an invocation:

const code = (value) => value.toLowerCase();

<template>
  {{code @name}}
  <code>{{@name}}</code>
</template>

This fails at render ("Attempted to load a component, but there wasn't a component manager associated with the definition"), and the rule did not report it because it only tracked block params.

  • The rule now also reads the reference ember-eslint-parser already resolves for the tag, so there is no scope walk in the rule.
  • Only value bindings of real element names count (ELEMENT_TAGS from is-native-element). Configured globals, type-only names and a deliberate const item = Item; <item /> are left alone.

Verified: the new cases fail before the fix; pnpm vitest run and pnpm lint pass.

…js/gts

In gjs/gts the template compiler resolves a tag against the JS scope
around the template, so a tag named like a const, import or parameter
is compiled as a component invocation. The rule only tracks block
params and misses it.
A module-level `const code = ...` turns `<code>` into an invocation of
that value, which fails at render time. Walk the scope chain of the
element as well as the block params.
Review follow-up. Configured globals and type-only names (type
aliases, interfaces, type imports, type parameters) are not bindings
the template compiler sees, so they no longer count. A lowercase
binding that is not an element name is a deliberate invocation and is
left alone.
ember-eslint-parser already resolves a tag against the JS scope and
registers the reference, so the rule asks for that reference and no
longer walks the scope chain itself.
@NullVoxPopuli

Copy link
Copy Markdown
Contributor

tyty!

@NullVoxPopuli
NullVoxPopuli merged commit 334ba30 into ember-cli:master Dec 1, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants