Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
sasaplus1 committed Jul 4, 2024
1 parent 4a5c45f commit 43e5eaf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/tsdoc-to-ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions src/utility.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import {
type AnyTxtNode,
type TxtParentNode,
type TxtTextNode
} from '@textlint/ast-node-types';

/**
* filter out nullable
*
Expand All @@ -9,3 +15,13 @@ export function isNonNullable<T>(
): value is NonNullable<T> {
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';
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"module": "CommonJS",
"outDir": "./dist",
"sourceMap": true,
"target": "ESNext"
"target": "ESNext",
"verbatimModuleSyntax": false
},
"include": [
"./src/*.ts"
Expand Down

0 comments on commit 43e5eaf

Please sign in to comment.