Skip to content

Comments

Improve attribute parser#40

Merged
ganyicz merged 1 commit intomainfrom
filip/refactor-attribute-parser
Feb 19, 2026
Merged

Improve attribute parser#40
ganyicz merged 1 commit intomainfrom
filip/refactor-attribute-parser

Conversation

@ganyicz
Copy link
Collaborator

@ganyicz ganyicz commented Feb 19, 2026

The scenario

These syntaxes were broken:

{{-- JavaScript inside attribute values produced ghost attributes --}}
<flux:menu.item x-data="{
    init() {
        this.document.title = '{{ $title }}';
    }
}">

{{-- @ attributes silently dropped --}}
<x-button @click="handle" />

The problem

The old AttributeParser used hand-rolled regexes that were buggy and inconsistent with Laravel.

  • We would match this.document.title = '{{ ... }}' inside the x-data JavaScript as a separate attribute.
  • Attributes with @ symbols were silently dropped because the old regex didn't include @.

The solution

Replace the old attribute parsing with Laravel's own approach from ComponentTagCompiler::getAttributesFromAttributeString():

  1. Run Laravel's full preprocessing pipeline on attribute strings before parsing, to avoid further drift.
  2. Use Laravel's attribute regex, added as LaravelRegex::ATTRIBUTE_PATTERN:
const ATTRIBUTE_PATTERN = '/
    (?<attribute>[\w\-:.@%]+)
    (=(?<value>("[^"]+"|\'[^\']+\'|[^\s>]+)))?
/x';

@ganyicz ganyicz changed the title Refactor attribute parser Improve attribute parser Feb 19, 2026
@ganyicz ganyicz merged commit df8c903 into main Feb 19, 2026
6 checks passed
@ganyicz ganyicz deleted the filip/refactor-attribute-parser branch February 19, 2026 14:57
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.

1 participant