diff --git a/src/tsdoc-to-ast.ts b/src/tsdoc-to-ast.ts index 3975046..dc92c8f 100644 --- a/src/tsdoc-to-ast.ts +++ b/src/tsdoc-to-ast.ts @@ -4,7 +4,7 @@ import type { AnyTxtNode, TxtParentNode } from '@textlint/ast-node-types'; import { ASTNodeTypes } from '@textlint/ast-node-types'; import { DocExcerpt, TSDocParser } from '@microsoft/tsdoc'; -import { isNonNullable } from './utility'; +import { isNonNullable, isTxtTextNode } from './utility'; /** * parse comment as TSDoc @@ -160,7 +160,9 @@ function traverse(docNode: DocNode, baseNode: AnyTxtNode): AnyTxtNode | null { } } - result.raw = children.map((child) => child.value || child.raw).join(''); + result.raw = children + .map((child) => (isTxtTextNode(child) ? child.value : child.raw)) + .join(''); } return result; diff --git a/src/utility.ts b/src/utility.ts index 8d887ba..158dd5d 100644 --- a/src/utility.ts +++ b/src/utility.ts @@ -1,3 +1,9 @@ +import { + type AnyTxtNode, + type TxtParentNode, + type TxtTextNode +} from '@textlint/ast-node-types'; + /** * filter out nullable * @@ -9,3 +15,13 @@ export function isNonNullable( ): value is NonNullable { return value !== null && value !== undefined; } + +/***/ +export function isTxtParentNode(value: AnyTxtNode): value is TxtParentNode { + return 'children' in value && Array.isArray(value.children); +} + +/***/ +export function isTxtTextNode(value: AnyTxtNode): value is TxtTextNode { + return 'value' in value && typeof value.value === 'string'; +} diff --git a/tsconfig.json b/tsconfig.json index 6f3c7a8..9b74ba4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,8 @@ "module": "CommonJS", "outDir": "./dist", "sourceMap": true, - "target": "ESNext" + "target": "ESNext", + "verbatimModuleSyntax": false }, "include": [ "./src/*.ts"