File tree Expand file tree Collapse file tree 2 files changed +19
-7
lines changed
Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Original file line number Diff line number Diff 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 ( / @ a w s u i S y s t e m \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 ( / @ a w s u i S y s t e m \s + ( \w + ) / g) , ( [ _ , system ] ) => system ) ;
96+ return systemTags . length > 0 ? { systemTags } : undefined ;
97+ } ) ;
9698}
9799
98100export function extractDeclaration ( symbol : ts . Symbol ) {
Original file line number Diff line number Diff 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+
3949test ( 'extract description comments from a type alias' , ( ) => {
4050 const source = `
4151 export type MyUnion = InternalUnion;
You can’t perform that action at this time.
0 commit comments