Skip to content

Commit 415688f

Browse files
author
Kirill Nesmeyanov
committed
Add support of offset access
1 parent 9198333 commit 415688f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/PrettyPrinter.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use TypeLang\Parser\Node\Stmt\Template\ArgumentsListNode;
3535
use TypeLang\Parser\Node\Stmt\Template\TemplateArgumentsListNode;
3636
use TypeLang\Parser\Node\Stmt\TernaryConditionNode;
37+
use TypeLang\Parser\Node\Stmt\TypeOffsetAccessNode;
3738
use TypeLang\Parser\Node\Stmt\TypesListNode;
3839
use TypeLang\Parser\Node\Stmt\TypeStatement;
3940
use TypeLang\Parser\Node\Stmt\UnionTypeNode;
@@ -145,6 +146,7 @@ protected function make(Statement $stmt): string
145146
$stmt instanceof NullableTypeNode => $this->printNullableType($stmt),
146147
$stmt instanceof TernaryConditionNode => $this->printTernaryType($stmt),
147148
$stmt instanceof TypesListNode => $this->printTypeListNode($stmt),
149+
$stmt instanceof TypeOffsetAccessNode => $this->printTypeOffsetAccessNode($stmt),
148150
default => throw NonPrintableNodeException::fromInvalidNode($stmt),
149151
};
150152
}
@@ -287,7 +289,8 @@ protected function printShapeFieldNode(FieldNode $field): string
287289
protected function printShapeFieldName(FieldNode $field): string
288290
{
289291
return match (true) {
290-
$field instanceof StringNamedFieldNode, $field instanceof NumericFieldNode => $field->key->getRawValue(),
292+
$field instanceof StringNamedFieldNode,
293+
$field instanceof NumericFieldNode => $field->key->getRawValue(),
291294
$field instanceof NamedFieldNode => $field->key->toString(),
292295
default => '',
293296
};
@@ -550,4 +553,17 @@ protected function printTypeListNode(TypesListNode $node): string
550553

551554
return $result . '[]';
552555
}
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+
}
553569
}

0 commit comments

Comments
 (0)