Skip to content

Comments

Support whitespace in component and slot tags#41

Merged
ganyicz merged 2 commits intomainfrom
filip/fix-whitespace-in-closing-tags
Feb 19, 2026
Merged

Support whitespace in component and slot tags#41
ganyicz merged 2 commits intomainfrom
filip/fix-whitespace-in-closing-tags

Conversation

@ganyicz
Copy link
Collaborator

@ganyicz ganyicz commented Feb 19, 2026

The scenario

Laravel's ComponentTagCompiler allows whitespace between < and >:

< x-button >
</ x-button >
< x-slot:header >
</ x-slot >

The problem

The tokenizer matched tags using exact string comparison (<x-, </x-), so any whitespace caused the tag to be missed entirely.

For closing tags, whitespace after the tag was also broken — if the tokenizer didn't find > immediately after tag name, it would consume the whitespace, the >, any text after it, and everything up until the next tag:

<x-button></x-button > some text <x-input />
          |______________________|
                  closing tag

The solution

Changed matchesAt from exact string comparison to regex matching, so the tag matchers can use <\s* and <\/\s* — matching Laravel's ComponentTagCompiler:

// Laravel's ComponentTagCompiler
'<\s*x[-\:]'      // opening tags
'<\/\s*x[-\:]'    // closing tags
'<\s*x[\-\:]slot' // slots

// Ours
$this->match('<\s*' . $prefix)
$this->match('<\/\s*' . $prefix)

Moved the > check outside the name-matching block so whitespace after the tag name is skipped.

Added dedicated TokenizerTest covering tags, slots, whitespace handling, and attributes with angled brackets.

@ganyicz ganyicz changed the title Fix tokenization of whitespace in closing tags Support whitespace in component and slot tags Feb 19, 2026
@ganyicz ganyicz merged commit 764fb48 into main Feb 19, 2026
6 checks passed
@ganyicz ganyicz deleted the filip/fix-whitespace-in-closing-tags branch February 19, 2026 16:40
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