From 30a08d52ee6873cb0b8b06aa7dfc9af5d73199ec Mon Sep 17 00:00:00 2001 From: "yilun.sun" Date: Thu, 7 Mar 2024 15:07:19 +0800 Subject: [PATCH] fix: use `isPropertyTagValueNode` to filter tag value nodes in comment --- src/phpdoc-parser/transpiler/README.md | 2 ++ tests/transpiler/transpiler.test.ts | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/phpdoc-parser/transpiler/README.md b/src/phpdoc-parser/transpiler/README.md index 84827dc..198117b 100644 --- a/src/phpdoc-parser/transpiler/README.md +++ b/src/phpdoc-parser/transpiler/README.md @@ -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 @@ -60,6 +61,7 @@ const getPropertyTagValueNodesFromComment = (commentText: string) => { const propertyTagValueNodes = astRootNode .getTags() .map((node) => node.value) + .filter(isPropertyTagValueNode); return propertyTagValueNodes; }; diff --git a/tests/transpiler/transpiler.test.ts b/tests/transpiler/transpiler.test.ts index 1fcd033..52b9abb 100644 --- a/tests/transpiler/transpiler.test.ts +++ b/tests/transpiler/transpiler.test.ts @@ -9,7 +9,7 @@ import { TypeParser, PhpDocParser, renderTsNodeToString, - type PropertyTagValueNode, + isPropertyTagValueNode, } from '../../src'; class ExtendedTranspiler extends PhpDocTypeNodeToTypescriptTypeNodeTranspiler { @@ -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; };