Skip to content

Commit 199d834

Browse files
committed
feat(type): union with spread
1 parent cf8fe9e commit 199d834

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

src/Parser/ParamParser.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ export default class ParamParser {
106106
// union in generics. e.g. `Array<string|number>`
107107
// hack: in this case, process this type in DocBuilder#_buildTypeDocLinkHTML
108108
result.types = [typeText];
109+
} else if (typeText.match(/^\.\.\.\(.*?\)/)) {
110+
// union with spread. e.g. `...(string|number)`
111+
// hack: in this case, process this type in DocBuilder#_buildTypeDocLinkHTML
112+
result.types = [typeText];
109113
} else {
110114
result.types = typeText.split('|');
111115
}

src/Publisher/Builder/DocBuilder.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,13 @@ export default class DocBuilder {
789789

790790
if (typeName.indexOf('...') === 0) {
791791
typeName = typeName.replace('...', '');
792-
return `...${this._buildDocLinkHTML(typeName)}`;
792+
if (typeName.includes('|')) {
793+
const typeNames = typeName.replace('(', '').replace(')', '').split('|');
794+
const typeLinks = typeNames.map((v) => this._buildDocLinkHTML(v));
795+
return `...(${typeLinks.join('|')})`;
796+
} else {
797+
return `...${this._buildDocLinkHTML(typeName)}`;
798+
}
793799
} else if (typeName.indexOf('?') === 0) {
794800
typeName = typeName.replace('?', '');
795801
return `?${this._buildDocLinkHTML(typeName)}`;

test/fixture/package/src/Type/Complex.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,11 @@ export default class TestTypeComplex {
3434
* @param {Promise<string|number, Error>} p1 - this is p1.
3535
*/
3636
method5(p1){}
37+
38+
// union with spread
39+
/**
40+
* this is method6.
41+
* @param {...(number|string)} p1 - this is p1.
42+
*/
43+
method6(...p1){}
3744
}

test/src/HTMLTest/CoverageTest/CoverageTest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('test coverage', ()=> {
99
it('has coverage summary', ()=> {
1010
assert(badge.includes('79%'));
1111
assert.includes(doc, '[data-ice="coverageBadge"]', './badge.svg', 'src');
12-
assert.includes(doc, '[data-ice="totalCoverageCount"]', '278/348');
12+
assert.includes(doc, '[data-ice="totalCoverageCount"]', '279/349');
1313
assert.equal(doc.find('[data-ice="file"] [data-ice="coverage"]').length, 119);
1414
});
1515

@@ -120,7 +120,7 @@ describe('test coverage', ()=> {
120120
test('file/src/TrailingComma/Definition.js.html', '100 %3/3');
121121
test('file/src/Type/Array.js.html', '100 %2/2');
122122
test('file/src/Type/Class.js.html#errorLines=1,9', '33 %1/3');
123-
test('file/src/Type/Complex.js.html#errorLines=1', '83 %5/6');
123+
test('file/src/Type/Complex.js.html#errorLines=1', '85 %6/7');
124124
test('file/src/Type/Default.js.html', '100 %2/2');
125125
test('file/src/Type/External.js.html', '100 %2/2');
126126
test('file/src/Type/Function.js.html', '100 %2/2');

test/src/HTMLTest/DocumentTest/TypeTest/ComplexTest.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,14 @@ describe('TestTypeComplex', ()=> {
6969
], 'href');
7070
});
7171
});
72+
73+
it('has complex union type with spread.', ()=>{
74+
findParent(doc, '[data-ice="summary"] [href$="#instance-method-method6"]', '[data-ice="target"]', (doc)=> {
75+
assert.includes(doc, null, 'method6(p1: ...(number|string))');
76+
assert.multiIncludes(doc, '[data-ice="signature"] a', [
77+
'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number',
78+
'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String'
79+
], 'href');
80+
});
81+
});
7282
});

0 commit comments

Comments
 (0)