Skip to content

Commit e4c1cd8

Browse files
committed
Fix component custom key defintion + add test
1 parent c7fd02a commit e4c1cd8

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/LivewireTokenParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function parse(Token $token)
8282
$variables = $this->parser->parseExpression();
8383
} elseif ($stream->test(Token::NAME_TYPE, 'key')) {
8484
$stream->next(); // Consume the 'key' token
85-
$stream->expect(Token::PUNCTUATION_TYPE, '(');
85+
$stream->expect(Token::OPERATOR_TYPE, '(');
8686
$key = $this->parser->parseExpression();
8787
$stream->expect(Token::PUNCTUATION_TYPE, ')');
8888
} else {

tests/RenderTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ public function test_nested_component_correctly_renders()
4242
$this->assertStringContainsString('Bar', $rendered);
4343
}
4444

45+
public function test_key_renders_correctly()
46+
{
47+
$this->expectNotToPerformAssertions();
48+
49+
Livewire::component('counter', Counter::class);
50+
51+
view('key-test')->render();
52+
}
53+
4554
public function test_unknown_component_throws_exception()
4655
{
4756
$this->expectException(\ErrorException::class);

tests/views/key-test.twig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% extends 'layout' %}
2+
3+
{% block content %}
4+
{% livewire.component 'counter' key('fixed-key') %}
5+
6+
{% set variableKey = 'variable-key' %}
7+
{% livewire.component 'counter' key(variableKey) %}
8+
9+
{% livewire.component 'counter' with {'count': 3, 'title': 'Lorem ipsum!'} key('fixed-key-with-variables-as-well') %}
10+
{% endblock %}

0 commit comments

Comments
 (0)