Permalink
Browse files

feat(type): union with spread

  • Loading branch information...
h13i32maru committed Dec 31, 2016
1 parent cf8fe9e commit 199d834cfe68ba986212b51cb59ea2d9de55ba1c
@@ -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('|');
}
@@ -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)}`;
@@ -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){}
}
@@ -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);
});
@@ -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');
@@ -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.