Skip to content

fix(compiler): don't hang on a lowercase @ in selectorless tags - #59

Closed
JounQin wants to merge 1 commit into
prettier:devfrom
JounQin:fix/selectorless-lowercase-directive
Closed

JounQin wants to merge 1 commit into
prettier:devfrom
JounQin:fix/selectorless-lowercase-directive

Conversation

@JounQin

@JounQin JounQin commented Oct 13, 2026

Copy link
Copy Markdown
Member

Summary

enableAngularSelectorlessSyntax (the lexer's selectorlessEnabled option) hangs forever on any @ that is not followed by _ or an uppercase letter — e.g. the common lowercase @triggerName attribute.

Closes #57.

Cause

In _consumeTagOpen, the selectorless branch only consumed @ when isSelectorlessNameStart(nameStart.peek()) was true (_ or A-Z, i.e. a PascalCase component/directive reference). Every other @ fell out of the if/else without consuming a character, so the enclosing while (true) never advanced.

Fix

Fall through to _consumeAttribute() when the @ cannot start a directive — exactly what the lexer does when selectorless syntax is disabled. A lowercase @name therefore stays an attribute (matching Angular, where selectorless directives are referenced by their PascalCase class name), and a lone @ no longer loops.

Tests

  • packages/compiler/test/ml_parser/lexer_spec.ts: @myDir, @myDir="x", @, @1
  • packages/angular-html-parser/test/index_spec.ts: <div @myDir>, <MyComp @myDir>, <div @>

yarn vitest run → 450 passed, lint:prettier and lint:types clean.

With `selectorlessEnabled`, the attribute loop in `_consumeTagOpen` only
consumed `@` when it was followed by a selectorless name start (`_` or an
uppercase letter, i.e. a PascalCase component/directive reference). Any other
`@` — a lowercase animation trigger such as `@triggerName`, or a lone `@` —
matched neither branch, so the cursor never advanced and the lexer looped
forever.

Fall through to `_consumeAttribute()` instead, which is what the lexer already
does when selectorless syntax is disabled.

Fixes #57
Copilot AI balanced review requested due to automatic review settings October 13, 2026 06:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@pkg-pr-new

pkg-pr-new Bot commented Oct 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/angular-html-parser@59

commit: d79a72a

@pkg-pr-new

pkg-pr-new Bot commented Oct 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/angular-html-parser@59

commit: d79a72a

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

enableAngularSelectorlessSyntax hangs on a lowercase directive (@foo)

3 participants