Skip to content

Erase as |…| block-param clause when Glint substitutes a block-form component#14

Open
johanrd wants to merge 2 commits intomainfrom
fix/fp-blank-component-yield
Open

Erase as |…| block-param clause when Glint substitutes a block-form component#14
johanrd wants to merge 2 commits intomainfrom
fix/fp-blank-component-yield

Conversation

@johanrd
Copy link
Copy Markdown
Owner

@johanrd johanrd commented May 7, 2026

Summary

When Glint resolves a yielding component to a native tag (e.g. <MyList as |item|><div>), the in-place open-tag rename in handleGlintSubstitution's block-form path renamed <MyList><div> but left the as |item| clause in place. html-validate's parser then treated |item| as an attribute, firing attr-case (Attribute "|item|" should be lowercase); downstream rules like element-permitted-content cascaded.

The rendered DOM has no such attribute — block params are a Glimmer-side binding for yielded content, not HTML — so the blanker must erase the as |…| clause when it does the in-place rename.

Implementation

In the block-form Glint substitution path, when node.blockParams.length > 0, scan the open-tag text for \bas\s+\|[^|]*\| and add the LAST match to blankRanges. The last match is unambiguously the block-params clause (per Glimmer syntax it's always the rightmost thing before >), defending against the rare case where an attribute value happens to contain a literal as |x|.

Surfaced by

Ecosystem CI on hashicorp/design-system: 881× spurious attr-case plus a cascade of element-permitted-content and element-required-attributes reports — all rooted in this single leak. After the fix HDS dropped from 1184 → 303 findings (with Glint enabled).

Test plan

  • New test: block-form <MyList as |item|> substituted to <div>|item| must not appear in output
  • New test: multi-param as |item index| covered by the same regex
  • npm test — 129/129 passing
  • npm run typecheck:tests — clean
  • npm run build — clean

@johanrd johanrd added the bug Something isn't working label May 7, 2026
@johanrd johanrd requested a review from Copilot May 7, 2026 11:05
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a false-positive cascade in html-validate output when Glint substitutes a yielding, block-form component invocation (e.g. <MyList as |item|>…</MyList>) to a native tag by ensuring the Glimmer-only block-param clause is removed from the emitted open tag.

Changes:

  • In block-form Glint substitution, detect and blank the last as |…| clause in the open-tag source span when node.blockParams are present.
  • Add unit tests asserting that |…| block-param syntax does not leak into the blanked output for substituted block-form components.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
blank.ts Blanks the `as
test/blank.test.ts Adds regression tests to ensure block-param syntax is removed when substituting block-form components to native tags.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/blank.test.ts Outdated
Per Copilot review on #14: the test name claimed coverage for
comma-separated and typed block-param forms but the src only exercised
the space-separated form (which is what the AST actually carries —
typed annotations are stripped earlier by stripBlockParamTypeAnnotations,
and Glimmer's parser doesn't accept the comma form anyway). Adjusted
the name and comment to describe what's tested.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@johanrd johanrd requested a review from Copilot May 7, 2026 13:25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants