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

Revert "feature: introduce short hand false syntax for component prop… #48220

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions src/Illuminate/View/Compilers/ComponentTagCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ protected function compileOpeningTags(string $value)
(\:\\\$)(\w+)
)
|
(?:
(![\w]+)
)
|
(?:
[\w\-:.@%]+
(
Expand Down Expand Up @@ -196,10 +192,6 @@ protected function compileSelfClosingTags(string $value)
(\:\\\$)(\w+)
)
|
(?:
(![\w]+)
)
|
(?:
[\w\-:.@%]+
(
Expand Down Expand Up @@ -590,7 +582,6 @@ public function compileSlots(string $value)
protected function getAttributesFromAttributeString(string $attributeString)
{
$attributeString = $this->parseShortAttributeSyntax($attributeString);
$attributeString = $this->parseShortFalseSyntax($attributeString);
$attributeString = $this->parseAttributeBag($attributeString);
$attributeString = $this->parseComponentTagClassStatements($attributeString);
$attributeString = $this->parseComponentTagStyleStatements($attributeString);
Expand Down Expand Up @@ -659,21 +650,6 @@ protected function parseShortAttributeSyntax(string $value)
}, $value);
}

/**
* Parses a short false syntax like !required into a fully-qualified syntax like :required="false".
*
* @param string $value
* @return string
*/
protected function parseShortFalseSyntax(string $value)
{
$pattern = "/\s!(\w+)/x";

return preg_replace_callback($pattern, function (array $matches) {
return " :{$matches[1]}=\"false\"";
}, $value);
}

/**
* Parse the attribute bag in a given attribute string into its fully-qualified syntax.
*
Expand Down
40 changes: 0 additions & 40 deletions tests/View/Blade/BladeComponentTagCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -734,31 +734,6 @@ public function testAttributesTreatedAsPropsAreRemovedFromFinalAttributes()
$this->assertSame($attributes->get('other'), 'ok');
}

public function testFalseShortSyntax()
{
$this->mockViewFactory();
$result = $this->compiler(['bool' => TestBoolComponent::class])->compileTags('<x-bool !bool></x-bool>');

$this->assertSame("##BEGIN-COMPONENT-CLASS##@component('Illuminate\Tests\View\Blade\TestBoolComponent', 'bool', ['bool' => false])
<?php if (isset(\$attributes) && \$attributes instanceof Illuminate\View\ComponentAttributeBag && \$constructor = (new ReflectionClass(Illuminate\Tests\View\Blade\TestBoolComponent::class))->getConstructor()): ?>
<?php \$attributes = \$attributes->except(collect(\$constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php \$component->withAttributes([]); ?> @endComponentClass##END-COMPONENT-CLASS##", trim($result));
}

public function testSelfClosingComponentWithFalseShortSyntax()
{
$this->mockViewFactory();
$result = $this->compiler(['bool' => TestBoolComponent::class])->compileTags('<x-bool !bool />');

$this->assertSame("##BEGIN-COMPONENT-CLASS##@component('Illuminate\Tests\View\Blade\TestBoolComponent', 'bool', ['bool' => false])
<?php if (isset(\$attributes) && \$attributes instanceof Illuminate\View\ComponentAttributeBag && \$constructor = (new ReflectionClass(Illuminate\Tests\View\Blade\TestBoolComponent::class))->getConstructor()): ?>
<?php \$attributes = \$attributes->except(collect(\$constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php \$component->withAttributes([]); ?>
@endComponentClass##END-COMPONENT-CLASS##", trim($result));
}

protected function mockViewFactory($existsSucceeds = true)
{
$container = new Container;
Expand Down Expand Up @@ -822,18 +797,3 @@ public function render()
return 'input';
}
}

class TestBoolComponent extends Component
{
public $bool;

public function __construct($bool)
{
$this->bool = $bool;
}

public function render()
{
return 'bool';
}
}