Skip to content

Commit e7719e7

Browse files
committed
Add support of ConstMaskFieldNode and ClassConstMaskFieldNode of parser v1.6
1 parent 55b1f1d commit e7719e7

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

src/PrettyPrinter.php

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
use TypeLang\Parser\Node\Stmt\LogicalTypeNode;
2626
use TypeLang\Parser\Node\Stmt\NamedTypeNode;
2727
use TypeLang\Parser\Node\Stmt\NullableTypeNode;
28+
use TypeLang\Parser\Node\Stmt\Shape\ClassConstMaskFieldNode;
29+
use TypeLang\Parser\Node\Stmt\Shape\ConstMaskFieldNode;
2830
use TypeLang\Parser\Node\Stmt\Shape\FieldNode;
2931
use TypeLang\Parser\Node\Stmt\Shape\FieldsListNode;
3032
use TypeLang\Parser\Node\Stmt\Shape\NamedFieldNode;
@@ -289,13 +291,56 @@ protected function printShapeFieldNode(FieldNode $field): string
289291
protected function printShapeFieldName(FieldNode $field): string
290292
{
291293
return match (true) {
292-
$field instanceof StringNamedFieldNode,
293-
$field instanceof NumericFieldNode => $field->key->getRawValue(),
294-
$field instanceof NamedFieldNode => $field->key->toString(),
295-
default => '',
294+
$field instanceof StringNamedFieldNode => $this->printStringShapeFieldName($field),
295+
$field instanceof NumericFieldNode => $this->printNumericShapeFieldName($field),
296+
$field instanceof NamedFieldNode => $this->printNamedShapeFieldName($field),
297+
$field instanceof ConstMaskFieldNode => $this->printConstMaskShapeFieldName($field),
298+
$field instanceof ClassConstMaskFieldNode => $this->printClassConstMaskShapeFieldName($field),
299+
default => $this->printUnknownShapeFieldName($field),
296300
};
297301
}
298302

303+
protected function printStringShapeFieldName(StringNamedFieldNode $field): string
304+
{
305+
return $field->key->getRawValue();
306+
}
307+
308+
protected function printNumericShapeFieldName(NumericFieldNode $field): string
309+
{
310+
return $field->key->getRawValue();
311+
}
312+
313+
protected function printNamedShapeFieldName(NamedFieldNode $field): string
314+
{
315+
return $field->key->toString();
316+
}
317+
318+
protected function printConstMaskShapeFieldName(ConstMaskFieldNode $field): string
319+
{
320+
return $field->key->name->toString() . '*';
321+
}
322+
323+
protected function printClassConstMaskShapeFieldName(ClassConstMaskFieldNode $field): string
324+
{
325+
$class = $field->key->class;
326+
$constant = $field->key->constant;
327+
328+
if ($field->key instanceof ClassConstNode) {
329+
return $class . '::' . $constant;
330+
}
331+
332+
if ($constant === null) {
333+
return $class . '::*';
334+
}
335+
336+
return $class . '::' . $constant . '*';
337+
}
338+
339+
protected function printUnknownShapeFieldName(FieldNode $field): string
340+
{
341+
return '';
342+
}
343+
299344
/**
300345
* @param ArgumentsListNode<ArgumentNode>|TemplateArgumentsListNode $arguments
301346
*

0 commit comments

Comments
 (0)