BUGFIX: template-no-yield-only — guard against native <template> as first HBS child#59
Closed
BUGFIX: template-no-yield-only — guard against native <template> as first HBS child#59
Conversation
…first HBS child
In classic HBS, a native HTML `<template>` element can appear anywhere in
a template body — including as the first child. The current gjs-wrapper
detection descends into `body[0].children` whenever `body[0].tag === 'template'`,
so an HBS template like `<template>{{yield}}</template>{{#each items}}…{{/each}}`
is mistakenly treated as the GJS `<template>` module wrapper: the rule
walks the inner `<template>`'s children, sees only `{{yield}}`, and
flags it as yield-only — a false positive.
The GJS module wrapper is always `body.length === 1`. Add that guard so
we only descend in the actual GJS/GTS case. Matches the shape of the
sibling rule `template-no-bare-yield.js`.
Added an HBS-only regression test (the construct is invalid in GJS/GTS,
where a nested `<template>` is a parse error).
🏎️ Benchmark Comparison
Full mitata output |
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.
Summary
template-no-yield-only's gjs-wrapper detection descends intobody[0].childrenwheneverbody[0].tag === 'template', without checkingbody.length. In classic HBS, a native HTML<template>element can appear anywhere, and the rule mistakes it for the GJS module wrapper.<template>{{yield}}</template>{{#each items}}item{{/each}}. The rule walks the inner<template>'s children, sees only{{yield}}, and flags the whole template as yield-only — even though the real template has a{{#each}}block and is not yield-only.body.length === 1before descending, matching the shape of the sibling ruletemplate-no-bare-yield.js.Context
Closes drift with
template-no-bare-yield.js, which has this guard. Both rules are near-duplicates of the same upstreamember-template-lint/no-yield-only; the sibling kept pace, this one didn't.Independent of ember-cli#2736 (ember-cli/eslint-plugin-ember) and the CI fix there — that PR addresses the comment-node handling; this one addresses a separately latent wrapper-detection bug. They touch the same file but different regions.
Test plan
<template>{{yield}}</template>{{#each items}}item{{/each}}tovalidHbs; without the guard it false-positives, with it the template is correctly accepted.<template>(parse error); split intovalidHbsOnlyand fed to the hbs rule tester.pnpm exec vitest run tests/lib/rules/template-no-yield-only.js— 19/19 pass.