Skip to content

Commit

Permalink
feat(type): union with spread
Browse files Browse the repository at this point in the history
  • Loading branch information
h13i32maru committed Dec 31, 2016
1 parent cf8fe9e commit 199d834
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/Parser/ParamParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ export default class ParamParser {
// union in generics. e.g. `Array<string|number>`
// hack: in this case, process this type in DocBuilder#_buildTypeDocLinkHTML
result.types = [typeText];
} else if (typeText.match(/^\.\.\.\(.*?\)/)) {
// union with spread. e.g. `...(string|number)`
// hack: in this case, process this type in DocBuilder#_buildTypeDocLinkHTML
result.types = [typeText];
} else {
result.types = typeText.split('|');
}
Expand Down
8 changes: 7 additions & 1 deletion src/Publisher/Builder/DocBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,13 @@ export default class DocBuilder {

if (typeName.indexOf('...') === 0) {
typeName = typeName.replace('...', '');
return `...${this._buildDocLinkHTML(typeName)}`;
if (typeName.includes('|')) {
const typeNames = typeName.replace('(', '').replace(')', '').split('|');
const typeLinks = typeNames.map((v) => this._buildDocLinkHTML(v));
return `...(${typeLinks.join('|')})`;
} else {
return `...${this._buildDocLinkHTML(typeName)}`;
}
} else if (typeName.indexOf('?') === 0) {
typeName = typeName.replace('?', '');
return `?${this._buildDocLinkHTML(typeName)}`;
Expand Down
7 changes: 7 additions & 0 deletions test/fixture/package/src/Type/Complex.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ export default class TestTypeComplex {
* @param {Promise<string|number, Error>} p1 - this is p1.
*/
method5(p1){}

// union with spread
/**
* this is method6.
* @param {...(number|string)} p1 - this is p1.
*/
method6(...p1){}
}
4 changes: 2 additions & 2 deletions test/src/HTMLTest/CoverageTest/CoverageTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('test coverage', ()=> {
it('has coverage summary', ()=> {
assert(badge.includes('79%'));
assert.includes(doc, '[data-ice="coverageBadge"]', './badge.svg', 'src');
assert.includes(doc, '[data-ice="totalCoverageCount"]', '278/348');
assert.includes(doc, '[data-ice="totalCoverageCount"]', '279/349');
assert.equal(doc.find('[data-ice="file"] [data-ice="coverage"]').length, 119);
});

Expand Down Expand Up @@ -120,7 +120,7 @@ describe('test coverage', ()=> {
test('file/src/TrailingComma/Definition.js.html', '100 %3/3');
test('file/src/Type/Array.js.html', '100 %2/2');
test('file/src/Type/Class.js.html#errorLines=1,9', '33 %1/3');
test('file/src/Type/Complex.js.html#errorLines=1', '83 %5/6');
test('file/src/Type/Complex.js.html#errorLines=1', '85 %6/7');
test('file/src/Type/Default.js.html', '100 %2/2');
test('file/src/Type/External.js.html', '100 %2/2');
test('file/src/Type/Function.js.html', '100 %2/2');
Expand Down
10 changes: 10 additions & 0 deletions test/src/HTMLTest/DocumentTest/TypeTest/ComplexTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,14 @@ describe('TestTypeComplex', ()=> {
], 'href');
});
});

it('has complex union type with spread.', ()=>{
findParent(doc, '[data-ice="summary"] [href$="#instance-method-method6"]', '[data-ice="target"]', (doc)=> {
assert.includes(doc, null, 'method6(p1: ...(number|string))');
assert.multiIncludes(doc, '[data-ice="signature"] a', [
'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number',
'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String'
], 'href');
});
});
});

0 comments on commit 199d834

Please sign in to comment.