Skip to content

Commit 0b498ad

Browse files
committed
Fixed T_FN tokenizing when using yield (ref #2706, #2523)
1 parent 1a59388 commit 0b498ad

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/Tokenizers/PHP.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,6 @@ protected function processAdditional()
17171717
$endTokens = [
17181718
T_COLON => true,
17191719
T_COMMA => true,
1720-
T_DOUBLE_ARROW => true,
17211720
T_SEMICOLON => true,
17221721
T_CLOSE_PARENTHESIS => true,
17231722
T_CLOSE_SQUARE_BRACKET => true,

tests/Core/Tokenizer/BackfillFnTokenTest.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,6 @@ fn&($x) => $x;
5151
$a = [
5252
'a' => fn() => return 1,
5353
];
54+
55+
/* testYield */
56+
$a = fn($x) => yield 'k' => $x;

tests/Core/Tokenizer/BackfillFnTokenTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,34 @@ public function testArrayValue()
403403
}//end testArrayValue()
404404

405405

406+
/**
407+
* Test arrow functions that use the yield keyword.
408+
*
409+
* @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
410+
*
411+
* @return void
412+
*/
413+
public function testYield()
414+
{
415+
$tokens = self::$phpcsFile->getTokens();
416+
417+
$token = $this->getTargetToken('/* testYield */', T_FN);
418+
$this->backfillHelper($token);
419+
420+
$this->assertSame($tokens[$token]['scope_opener'], ($token + 5), 'Scope opener is not the arrow token');
421+
$this->assertSame($tokens[$token]['scope_closer'], ($token + 14), 'Scope closer is not the semicolon token');
422+
423+
$opener = $tokens[$token]['scope_opener'];
424+
$this->assertSame($tokens[$opener]['scope_opener'], ($token + 5), 'Opener scope opener is not the arrow token');
425+
$this->assertSame($tokens[$opener]['scope_closer'], ($token + 14), 'Opener scope closer is not the semicolon token');
426+
427+
$closer = $tokens[$token]['scope_opener'];
428+
$this->assertSame($tokens[$closer]['scope_opener'], ($token + 5), 'Closer scope opener is not the arrow token');
429+
$this->assertSame($tokens[$closer]['scope_closer'], ($token + 14), 'Closer scope closer is not the semicolon token');
430+
431+
}//end testYield()
432+
433+
406434
/**
407435
* Test that anonymous class tokens without parenthesis do not get assigned a parenthesis owner.
408436
*

0 commit comments

Comments
 (0)