Merged
Conversation
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.
The scenario
@usedirectives don't work. Twousestatements in a single@phpblock throw an "unexpected use" exception:The problem
Use statements need to be hoisted before the function definition. We were extracting them with regexes and juggling raw block placeholders. The regex couldn't handle all valid PHP use syntax, and the placeholder dance made the code fragile.
The
Wrapperclass had accumulated other issues that made fixing this harder. Props were assigned at the top of the function body before$attributesexisted, this added conditional branches and syncing logic throughout the wrapper. This PR refactors this class significantly.The solution
UseExtractor— uses php-parser to extract use statements from<?php ?>blocks. Handles all valid syntax — aliases, group use, function/const imports — without regex.Unified raw block handling — raw blocks are restored before wrapping so
UseExtractorworks on actual PHP. Verbatim blocks are re-stored afterward so they survive compilation.Props and aware as directives — compiled in-place instead of hoisted to the top of the function body. The attribute bag is created once, before any directive runs, so props read from
$attributesdirectly. This matches Laravel's behavior and eliminates the dual attribute bag.Output trimming — component output is captured with
ob_start()and passed throughltrimbefore echoing, matching Laravel's behavior directly instead of regex hacks.Adds
$_instancesupport for Livewire's@thisdirective.