Skip to content

Commit a90c4e5

Browse files
authored
fix: Skip non-system comments when extracting descriptions (#68)
1 parent 3b14e73 commit a90c4e5

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/components/type-utils.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,15 @@ export function extractValueDescriptions(type: ts.UnionOrIntersectionType, typeN
8686
memberIndex++;
8787
}
8888
}
89-
return rawComments.map((comment): ValueDescription | undefined =>
90-
comment
91-
? {
92-
systemTags: Array.from(comment.matchAll(/@awsuiSystem\s+(\w+)/g), ([_, system]) => system),
93-
}
94-
: undefined
95-
);
89+
// Array.from to fix sparse array
90+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#array_methods_and_empty_slots
91+
return Array.from(rawComments).map((comment): ValueDescription | undefined => {
92+
if (!comment) {
93+
return undefined;
94+
}
95+
const systemTags = Array.from(comment.matchAll(/@awsuiSystem\s+(\w+)/g), ([_, system]) => system);
96+
return systemTags.length > 0 ? { systemTags } : undefined;
97+
});
9698
}
9799

98100
export function extractDeclaration(symbol: ts.Symbol) {

test/components/value-descriptions-extractor.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ test('extract description comments', () => {
3636
expect(extractFromSource(source)).toEqual([{ systemTags: ['fooSystem'] }, { systemTags: ['barSystem'] }]);
3737
});
3838

39+
test('should ignore non-system comments', () => {
40+
const source = `export type MyUnion =
41+
/** this is a foo property */
42+
| 'foo'
43+
/** @awsuiSystem barSystem */
44+
| 'bar';`;
45+
46+
expect(extractFromSource(source)).toEqual([undefined, { systemTags: ['barSystem'] }]);
47+
});
48+
3949
test('extract description comments from a type alias', () => {
4050
const source = `
4151
export type MyUnion = InternalUnion;

0 commit comments

Comments
 (0)