Skip to content

Commit 308d16b

Browse files
committed
map TS 4.3+ JSDocTagInfo to CompilerJsDocTagInfo
See microsoft/TypeScript#43312
1 parent ad2c239 commit 308d16b

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

src/compiler/transformers/decorators-to-static/method-decorator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
createStaticGetter,
66
getAttributeTypeInfo,
77
isMemberPrivate,
8+
mapJSDocTagInfo,
89
serializeSymbol,
910
typeToString,
1011
validateReferences,
@@ -95,7 +96,7 @@ const parseMethodDecorator = (
9596
},
9697
docs: {
9798
text: ts.displayPartsToString(signature.getDocumentationComment(typeChecker)),
98-
tags: signature.getJsDocTags(),
99+
tags: mapJSDocTagInfo(signature.getJsDocTags()),
99100
},
100101
};
101102
validateReferences(diagnostics, methodMeta.complexType.references, method.type || method.name);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { mapJSDocTagInfo } from '../transform-utils';
2+
3+
describe('transform utils', () => {
4+
it('flattens TypeScript JSDocTagInfo to Stencil JSDocTagInfo', () => {
5+
const tags = [
6+
{
7+
name: 'param',
8+
text: [
9+
{ kind: 'text', text: 'foo' },
10+
{ kind: 'space', text: ' ' },
11+
{ kind: 'text', text: 'the first parameter' },
12+
],
13+
},
14+
{
15+
name: 'param',
16+
text: [
17+
{ kind: 'text', text: 'bar' },
18+
{ kind: 'space', text: ' ' },
19+
{ kind: 'text', text: 'the second parameter' },
20+
],
21+
},
22+
];
23+
24+
expect(mapJSDocTagInfo(tags)).toEqual([
25+
{ name: 'param', text: 'foo the first parameter' },
26+
{ name: 'param', text: 'bar the second parameter' },
27+
]);
28+
});
29+
});

src/compiler/transformers/transform-utils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,20 @@ export const serializeSymbol = (checker: ts.TypeChecker, symbol: ts.Symbol): d.C
515515
};
516516
}
517517
return {
518-
tags: symbol.getJsDocTags().map((tag) => ({ text: tag.text, name: tag.name })),
518+
tags: mapJSDocTagInfo(symbol.getJsDocTags()),
519519
text: ts.displayPartsToString(symbol.getDocumentationComment(checker)),
520520
};
521521
};
522522

523+
/**
524+
* Maps a TypeScript 4.3+ JSDocTagInfo to a flattened Stencil CompilerJsDocTagInfo.
525+
* @param tags An array of JSDocTagInfo objects.
526+
* @return An array of CompilerJsDocTagInfo objects.
527+
*/
528+
export const mapJSDocTagInfo = (tags: ts.JSDocTagInfo[]): d.CompilerJsDocTagInfo[] => {
529+
return tags.map((tag) => ({ ...tag, text: tag.text?.map((part) => part.text).join('') }));
530+
};
531+
523532
export const serializeDocsSymbol = (checker: ts.TypeChecker, symbol: ts.Symbol) => {
524533
const type = checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration);
525534
const set = new Set<string>();

0 commit comments

Comments
 (0)