Skip to content

Commit 9243723

Browse files
committed
feat: sync with upstream phpdoc-parser v1.25-v1.33
Adds features from PHPStan phpdoc-parser v1.25.0 through v1.33.0: - Callable template types: `Closure<T>(T): T` syntax - Template tag lower bounds: `@template T super int` - Unsealed array shapes: `array{foo: int, ...}` and `array{...<string, int>}` - Non-empty array/list shapes: `non-empty-array{...}`, `non-empty-list{...}` - Array shape key constants: `array{Foo::BAR: int}` - New PHPDoc tags: @param-closure-this, @param-immediately-invoked-callable, @param-later-invoked-callable, @pure-unless-callable-is-impure, @require-extends, @require-implements - Unified SealedTagValueNode (replaces PhpstanSealedTagValueNode and PsalmInheritorsTagValueNode) - Phan annotation aliases (@phan-param, @phan-var, @phan-return, etc.) - Moved parseTemplateTagValue from PhpDocParser to TypeParser (upstream refactor)
1 parent 0777e38 commit 9243723

16 files changed

Lines changed: 1302 additions & 55 deletions

src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export { InvalidTagValueNode } from './phpdoc-parser/ast/php-doc/invalid-tag-val
2727
export { MethodTagValueNode } from './phpdoc-parser/ast/php-doc/method-tag-value-node';
2828
export { MethodTagValueParameterNode } from './phpdoc-parser/ast/php-doc/method-tag-value-parameter-node';
2929
export { MixinTagValueNode } from './phpdoc-parser/ast/php-doc/mixin-tag-value-node';
30+
export { ParamClosureThisTagValueNode } from './phpdoc-parser/ast/php-doc/param-closure-this-tag-value-node';
31+
export { ParamImmediatelyInvokedCallableTagValueNode } from './phpdoc-parser/ast/php-doc/param-immediately-invoked-callable-tag-value-node';
32+
export { ParamLaterInvokedCallableTagValueNode } from './phpdoc-parser/ast/php-doc/param-later-invoked-callable-tag-value-node';
3033
export { ParamOutTagValueNode } from './phpdoc-parser/ast/php-doc/param-out-tag-value-node';
3134
export { ParamTagValueNode } from './phpdoc-parser/ast/php-doc/param-tag-value-node';
3235
export { PhpDocChildNode } from './phpdoc-parser/ast/php-doc/php-doc-child-node';
@@ -35,7 +38,11 @@ export { PhpDocTagNode } from './phpdoc-parser/ast/php-doc/php-doc-tag-node';
3538
export { PhpDocTagValueNode } from './phpdoc-parser/ast/php-doc/php-doc-tag-value-node';
3639
export { PhpDocTextNode } from './phpdoc-parser/ast/php-doc/php-doc-text-node';
3740
export { PropertyTagValueNode } from './phpdoc-parser/ast/php-doc/property-tag-value-node';
41+
export { PureUnlessCallableIsImpureTagValueNode } from './phpdoc-parser/ast/php-doc/pure-unless-callable-is-impure-tag-value-node';
42+
export { RequireExtendsTagValueNode } from './phpdoc-parser/ast/php-doc/require-extends-tag-value-node';
43+
export { RequireImplementsTagValueNode } from './phpdoc-parser/ast/php-doc/require-implements-tag-value-node';
3844
export { ReturnTagValueNode } from './phpdoc-parser/ast/php-doc/return-tag-value-node';
45+
export { SealedTagValueNode } from './phpdoc-parser/ast/php-doc/sealed-tag-value-node';
3946
export { SelfOutTagValueNode } from './phpdoc-parser/ast/php-doc/self-out-tag-value-node';
4047
export { TemplateTagValueNode } from './phpdoc-parser/ast/php-doc/template-tag-value-node';
4148
export { ThrowsTagValueNode } from './phpdoc-parser/ast/php-doc/throws-tag-value-node';
@@ -46,6 +53,7 @@ export { UsesTagValueNode } from './phpdoc-parser/ast/php-doc/uses-tag-value-nod
4653
export { VarTagValueNode } from './phpdoc-parser/ast/php-doc/var-tag-value-node';
4754
export { ArrayShapeItemNode } from './phpdoc-parser/ast/type/array-shape-item-node';
4855
export { ArrayShapeNode } from './phpdoc-parser/ast/type/array-shape-node';
56+
export { ArrayShapeUnsealedTypeNode } from './phpdoc-parser/ast/type/array-shape-unsealed-type-node';
4957
export { ArrayTypeNode } from './phpdoc-parser/ast/type/array-type-node';
5058
export { CallableTypeNode } from './phpdoc-parser/ast/type/callable-type-node';
5159
export { CallableTypeParameterNode } from './phpdoc-parser/ast/type/callable-type-parameter-node';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { TypeNode } from '../type/type-node';
2+
import { PhpDocTagValueNode } from './php-doc-tag-value-node';
3+
4+
export class ParamClosureThisTagValueNode extends PhpDocTagValueNode {
5+
constructor(
6+
public type: TypeNode,
7+
public parameterName: string,
8+
public description: string,
9+
) {
10+
super();
11+
}
12+
13+
public toString(): string {
14+
return `${this.type.toString()} ${this.parameterName} ${this.description}`.trim();
15+
}
16+
17+
public getNodeType(): string {
18+
return 'ParamClosureThisTagValueNode';
19+
}
20+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { PhpDocTagValueNode } from './php-doc-tag-value-node';
2+
3+
export class ParamImmediatelyInvokedCallableTagValueNode extends PhpDocTagValueNode {
4+
constructor(
5+
public parameterName: string,
6+
public description: string,
7+
) {
8+
super();
9+
}
10+
11+
public toString(): string {
12+
return `${this.parameterName} ${this.description}`.trim();
13+
}
14+
15+
public getNodeType(): string {
16+
return 'ParamImmediatelyInvokedCallableTagValueNode';
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { PhpDocTagValueNode } from './php-doc-tag-value-node';
2+
3+
export class ParamLaterInvokedCallableTagValueNode extends PhpDocTagValueNode {
4+
constructor(
5+
public parameterName: string,
6+
public description: string,
7+
) {
8+
super();
9+
}
10+
11+
public toString(): string {
12+
return `${this.parameterName} ${this.description}`.trim();
13+
}
14+
15+
public getNodeType(): string {
16+
return 'ParamLaterInvokedCallableTagValueNode';
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { PhpDocTagValueNode } from './php-doc-tag-value-node';
2+
3+
export class PureUnlessCallableIsImpureTagValueNode extends PhpDocTagValueNode {
4+
constructor(
5+
public parameterName: string,
6+
public description: string,
7+
) {
8+
super();
9+
}
10+
11+
public toString(): string {
12+
return `${this.parameterName} ${this.description}`.trim();
13+
}
14+
15+
public getNodeType(): string {
16+
return 'PureUnlessCallableIsImpureTagValueNode';
17+
}
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { TypeNode } from '../type/type-node';
2+
import { PhpDocTagValueNode } from './php-doc-tag-value-node';
3+
4+
export class RequireExtendsTagValueNode extends PhpDocTagValueNode {
5+
constructor(
6+
public type: TypeNode,
7+
public description: string,
8+
) {
9+
super();
10+
}
11+
12+
public toString(): string {
13+
return `${this.type.toString()} ${this.description}`.trim();
14+
}
15+
16+
public getNodeType(): string {
17+
return 'RequireExtendsTagValueNode';
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { TypeNode } from '../type/type-node';
2+
import { PhpDocTagValueNode } from './php-doc-tag-value-node';
3+
4+
export class RequireImplementsTagValueNode extends PhpDocTagValueNode {
5+
constructor(
6+
public type: TypeNode,
7+
public description: string,
8+
) {
9+
super();
10+
}
11+
12+
public toString(): string {
13+
return `${this.type.toString()} ${this.description}`.trim();
14+
}
15+
16+
public getNodeType(): string {
17+
return 'RequireImplementsTagValueNode';
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { TypeNode } from '../type/type-node';
2+
import { PhpDocTagValueNode } from './php-doc-tag-value-node';
3+
4+
export class SealedTagValueNode extends PhpDocTagValueNode {
5+
constructor(
6+
public type: TypeNode,
7+
public description: string,
8+
) {
9+
super();
10+
}
11+
12+
public toString(): string {
13+
return `${this.type.toString()} ${this.description}`.trim();
14+
}
15+
16+
public getNodeType(): string {
17+
return 'SealedTagValueNode';
18+
}
19+
}

src/phpdoc-parser/ast/php-doc/template-tag-value-node.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ export class TemplateTagValueNode extends PhpDocTagValueNode {
77
public bound: TypeNode | null,
88
public description: string,
99
public defaultTypeNode: TypeNode | null = null,
10+
public lowerBound: TypeNode | null = null,
1011
) {
1112
super();
1213
}
1314

1415
public toString(): string {
1516
const bound = this.bound !== null ? ` of ${this.bound.toString()}` : '';
17+
const lowerBoundStr =
18+
this.lowerBound !== null ? ` super ${this.lowerBound.toString()}` : '';
1619
const defaultString =
1720
this.defaultTypeNode !== null
1821
? ` = ${this.defaultTypeNode.toString()}`
1922
: '';
20-
return `${this.name}${bound}${defaultString} ${this.description}`.trim();
23+
return `${this.name}${bound}${lowerBoundStr}${defaultString} ${this.description}`.trim();
2124
}
2225

2326
public getNodeType(): string {

src/phpdoc-parser/ast/type/array-shape-item-node.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ConstExprIntegerNode } from '../const-expr/const-expr-integer-node';
22
import type { ConstExprStringNode } from '../const-expr/const-expr-string-node';
3+
import type { ConstFetchNode } from '../const-expr/const-fetch-node';
34
import type { IdentifierTypeNode } from './identifier-type-node';
45
import { TypeNode } from './type-node';
56

@@ -8,6 +9,7 @@ export class ArrayShapeItemNode extends TypeNode {
89
public keyName:
910
| ConstExprIntegerNode
1011
| ConstExprStringNode
12+
| ConstFetchNode
1113
| IdentifierTypeNode
1214
| null,
1315
public optional: boolean,

0 commit comments

Comments
 (0)