Skip to content

Commit

Permalink
fix: use isPropertyTagValueNode to filter tag value nodes in comment
Browse files Browse the repository at this point in the history
  • Loading branch information
yilun.sun committed Mar 7, 2024
1 parent cf14291 commit 30a08d5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/phpdoc-parser/transpiler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { renderTsNodeToString } from './helpers';
import { PhpDocTypeNodeToTypescriptTypeNodeTranspiler } from './php-doc-to-typescript-type-transpiler';
import type { ParamTagValueNode, PropertyTagValueNode, ReturnTagValueNode } from '../ast/php-doc';
import { Lexer, ConstExprParser, PhpDocParser, TokenIterator, TypeParser } from '../lexer/parser';
import { isPropertyTagValueNode } from '../ast/php-doc/helpers'
```

## Step 2: Define a Custom Transpiler Class
Expand Down Expand Up @@ -60,6 +61,7 @@ const getPropertyTagValueNodesFromComment = (commentText: string) => {
const propertyTagValueNodes = astRootNode
.getTags()
.map((node) => node.value)
.filter(isPropertyTagValueNode);

return propertyTagValueNodes;
};
Expand Down
5 changes: 3 additions & 2 deletions tests/transpiler/transpiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
TypeParser,
PhpDocParser,
renderTsNodeToString,
type PropertyTagValueNode,
isPropertyTagValueNode,
} from '../../src';

class ExtendedTranspiler extends PhpDocTypeNodeToTypescriptTypeNodeTranspiler {
Expand Down Expand Up @@ -41,7 +41,8 @@ const getPropertyTagValueNodesFromComment = (commentText: string) => {
// Extract property, return, or parameter nodes from the AST.
const propertyTagValueNodes = astRootNode
.getTags()
.map((node) => node.value) as PropertyTagValueNode[];
.map((node) => node.value)
.filter(isPropertyTagValueNode);

return propertyTagValueNodes;
};
Expand Down

0 comments on commit 30a08d5

Please sign in to comment.