Skip to content

Commit b0c366d

Browse files
committed
Fix token indexes in TypeAliasImportTagValueNode
1 parent 5f901f0 commit b0c366d

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/Parser/PhpDocParser.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,8 @@ private function enrichWithAttributes(TokenIterator $tokens, Ast\Node $tag, int
137137

138138
if ($this->useIndexAttributes) {
139139
$tokensArray = $tokens->getTokens();
140-
if ($tokensArray[$endIndex][Lexer::TYPE_OFFSET] === Lexer::TOKEN_CLOSE_PHPDOC) {
141-
$endIndex--;
142-
if ($tokensArray[$endIndex][Lexer::TYPE_OFFSET] === Lexer::TOKEN_HORIZONTAL_WS) {
143-
$endIndex--;
144-
}
145-
} elseif ($tokensArray[$endIndex][Lexer::TYPE_OFFSET] === Lexer::TOKEN_PHPDOC_EOL) {
140+
$endIndex--;
141+
if ($tokensArray[$endIndex][Lexer::TYPE_OFFSET] === Lexer::TOKEN_HORIZONTAL_WS) {
146142
$endIndex--;
147143
}
148144

tests/PHPStan/Parser/PhpDocParserTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5614,7 +5614,7 @@ public function dataLinesAndIndexes(): iterable
56145614
yield [
56155615
'/** @phpstan-import-type TypeAlias from AnotherClass[] */',
56165616
[
5617-
[1, 1, 8, 12],
5617+
[1, 1, 8, 11],
56185618
],
56195619
];
56205620

tests/PHPStan/Printer/PrinterTest.php

+17
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,23 @@ public function enterNode(Node $node)
14621462

14631463
},
14641464
];
1465+
1466+
yield [
1467+
'/** @phpstan-import-type Foo from \Bar as Lorem */',
1468+
'/** @phpstan-import-type Foo from Bar as Lorem */',
1469+
new class extends AbstractNodeVisitor {
1470+
1471+
public function enterNode(Node $node)
1472+
{
1473+
if ($node instanceof TypeAliasImportTagValueNode) {
1474+
$node->importedFrom = new IdentifierTypeNode('Bar');
1475+
}
1476+
1477+
return $node;
1478+
}
1479+
1480+
},
1481+
];
14651482
}
14661483

14671484
/**

0 commit comments

Comments
 (0)