Skip to content

Commit

Permalink
Revert "feature: introduce short hand false syntax for component props (
Browse files Browse the repository at this point in the history
#48084)"

This reverts commit 901ca01.
  • Loading branch information
driesvints committed Aug 28, 2023
1 parent 4c5d4d5 commit a27629f
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 64 deletions.
24 changes: 0 additions & 24 deletions src/Illuminate/View/Compilers/ComponentTagCompiler.php
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
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';
}
}

0 comments on commit a27629f

Please sign in to comment.