Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal: Update code intelligence class parsing to evaluate Alpine classes #1619

Merged
merged 10 commits into from
Mar 18, 2024
16 changes: 16 additions & 0 deletions monorepo/CodeIntelligence/CodeIntelligence.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,24 @@ protected function findBladeElementClasses(): array
$classes = [];

foreach ($this->bladeFiles as $contents) {
// Extract static classes from dynamic Alpine.js classes containing boolean logic
$contents = preg_replace_callback('/:class=(["\'])(.*?)\1/', function (array $matches): string {
$staticClasses = '';
$dynamicClasses = $matches[2];

// Parse the dynamic classes to separate static classes
preg_match_all('/\'\s*([^\'\s]*)\s*\'/', $dynamicClasses, $staticMatches);
if (! empty($staticMatches[1])) {
$staticClasses = sprintf('class="%s"', implode(' ', $staticMatches[1]));
}

return $staticClasses;
}, $contents);

$matches = [];

preg_match_all('/class="([^"]+)"/', $contents, $matches);

foreach ($matches[1] as $match) {
$match = explode(' ', $match);
foreach ($match as $class) {
Expand Down
Loading