|
34 | 34 | use TypeLang\Parser\Node\Stmt\Template\ArgumentsListNode; |
35 | 35 | use TypeLang\Parser\Node\Stmt\Template\TemplateArgumentsListNode; |
36 | 36 | use TypeLang\Parser\Node\Stmt\TernaryConditionNode; |
| 37 | +use TypeLang\Parser\Node\Stmt\TypeOffsetAccessNode; |
37 | 38 | use TypeLang\Parser\Node\Stmt\TypesListNode; |
38 | 39 | use TypeLang\Parser\Node\Stmt\TypeStatement; |
39 | 40 | use TypeLang\Parser\Node\Stmt\UnionTypeNode; |
@@ -145,6 +146,7 @@ protected function make(Statement $stmt): string |
145 | 146 | $stmt instanceof NullableTypeNode => $this->printNullableType($stmt), |
146 | 147 | $stmt instanceof TernaryConditionNode => $this->printTernaryType($stmt), |
147 | 148 | $stmt instanceof TypesListNode => $this->printTypeListNode($stmt), |
| 149 | + $stmt instanceof TypeOffsetAccessNode => $this->printTypeOffsetAccessNode($stmt), |
148 | 150 | default => throw NonPrintableNodeException::fromInvalidNode($stmt), |
149 | 151 | }; |
150 | 152 | } |
@@ -287,7 +289,8 @@ protected function printShapeFieldNode(FieldNode $field): string |
287 | 289 | protected function printShapeFieldName(FieldNode $field): string |
288 | 290 | { |
289 | 291 | return match (true) { |
290 | | - $field instanceof StringNamedFieldNode, $field instanceof NumericFieldNode => $field->key->getRawValue(), |
| 292 | + $field instanceof StringNamedFieldNode, |
| 293 | + $field instanceof NumericFieldNode => $field->key->getRawValue(), |
291 | 294 | $field instanceof NamedFieldNode => $field->key->toString(), |
292 | 295 | default => '', |
293 | 296 | }; |
@@ -550,4 +553,17 @@ protected function printTypeListNode(TypesListNode $node): string |
550 | 553 |
|
551 | 554 | return $result . '[]'; |
552 | 555 | } |
| 556 | + |
| 557 | + /** |
| 558 | + * @param TypeOffsetAccessNode<TypeStatement> $node |
| 559 | + * |
| 560 | + * @return non-empty-string |
| 561 | + * @throws NonPrintableNodeException |
| 562 | + */ |
| 563 | + protected function printTypeOffsetAccessNode(TypeOffsetAccessNode $node): string |
| 564 | + { |
| 565 | + $result = $this->make($node->type); |
| 566 | + |
| 567 | + return $result . '[' . $this->make($node->access) . ']'; |
| 568 | + } |
553 | 569 | } |
0 commit comments