File tree Expand file tree Collapse file tree 3 files changed +39
-2
lines changed
Expand file tree Collapse file tree 3 files changed +39
-2
lines changed Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change @@ -194,6 +194,8 @@ private function containsAttributesVar(string $content): bool
194194 return Str::contains (mb_strtolower ($ content ), '$attributes ' );
195195 }
196196
197+ public static $ break = false ;
198+
197199 private function parseParameters (): array
198200 {
199201 $ containsValue = false ;
@@ -211,17 +213,18 @@ private function parseParameters(): array
211213 $ startIndex = $ this ->currentIndex ;
212214 }
213215
214- if ($ this ->cur == self ::C_LeftCurlyBracket && $ this ->next == self ::C_LeftCurlyBracket && $ this ->fetchAtRelative (3 , 1 ) == self ::C_LeftCurlyBracket) {
216+ if ($ this ->cur == self ::C_LeftCurlyBracket && $ this ->next == self ::C_LeftCurlyBracket && $ this ->fetchAtRelative ($ this -> currentIndex + 2 , 1 ) == self ::C_LeftCurlyBracket) {
215217 $ this ->seekToEndOfTripleEcho ();
216218 $ parameters [] = $ this ->makeEchoParameter (ParameterType::AttributeTripleEcho, $ startIndex );
217219
218220 continue ;
219- } if ($ this ->cur == self ::C_LeftCurlyBracket && $ this ->next == self ::C_ExclamationMark && $ this ->fetchAtRelative (3 , 1 ) == self ::C_ExclamationMark) {
221+ } if ($ this ->cur == self ::C_LeftCurlyBracket && $ this ->next == self ::C_ExclamationMark && $ this ->fetchAtRelative ($ this -> currentIndex + 2 , 1 ) == self ::C_ExclamationMark) {
220222 $ this ->seekToEndOfRawEcho ();
221223 $ parameters [] = $ this ->makeEchoParameter (ParameterType::AttributeRawEcho, $ startIndex );
222224
223225 continue ;
224226 } elseif ($ this ->cur == self ::C_LeftCurlyBracket && $ this ->next == self ::C_LeftCurlyBracket) {
227+ self ::$ break = true ;
225228 $ this ->seekEndOfEcho ();
226229 $ parameters [] = $ this ->makeEchoParameter (ParameterType::AttributeEcho, $ startIndex );
227230
Original file line number Diff line number Diff line change 423423 expect ($ nodes [1 ])->toBeInstanceOf (LiteralNode::class);
424424 expect ($ nodes [2 ])->toBeInstanceOf (ComponentNode::class);
425425});
426+
427+ test ('echo params are parsed ' , function () {
428+ $ template = <<<'EOT'
429+ <x-alert
430+ data-one={{ $something }}
431+ data-two={{{ $something }}}
432+ data-three={!! $something !!}
433+ />
434+ EOT;
435+ $ nodes = $ this ->parser ()->onlyParseComponents ()->parse ($ template );
436+
437+ expect ($ nodes )->toHaveCount (1 );
438+ expect ($ nodes [0 ])->toBeInstanceOf (ComponentNode::class);
439+
440+ /** @var ComponentNode $component */
441+ $ component = $ nodes [0 ];
442+ expect ($ component ->parameters )->toHaveCount (3 );
443+
444+ /** @var ParameterNode $param1 */
445+ $ param1 = $ component ->parameters [0 ];
446+ expect ($ param1 ->content )->toBe ('data-one={{ $something }} ' );
447+ expect ($ param1 ->type )->toBe (ParameterType::UnknownEcho);
448+
449+ /** @var ParameterNode $param2 */
450+ $ param2 = $ component ->parameters [1 ];
451+ expect ($ param2 ->content )->toBe ('data-two={{{ $something }}} ' );
452+ expect ($ param2 ->type )->toBe (ParameterType::UnknownTripleEcho);
453+
454+ /** @var ParameterNode $param3 */
455+ $ param3 = $ component ->parameters [2 ];
456+ expect ($ param3 ->content )->toBe ('data-three={!! $something !!} ' );
457+ expect ($ param3 ->type )->toBe (ParameterType::UnknownRawEcho);
458+ });
You can’t perform that action at this time.
0 commit comments