Permalink
Browse files

fix(type): union in generics

  • Loading branch information...
h13i32maru committed Dec 30, 2016
1 parent 09452b6 commit eb051e729b83bca552a3d4b43351dc1272ee4154
@@ -102,7 +102,13 @@ export default class ParamParser {
typeText = typeText.replace(/^[(]/, '').replace(/[)]$/, '');
result.types = typeText.split('|');
} else if (typeText.includes('|')) {
- result.types = typeText.split('|');
+ if (typeText.match(/<.*?\|.*?>/)) {
+ // union in generics. e.g. `Array<string|number>`
+ // hack: in this case, process this type in DocBuilder#_buildTypeDocLinkHTML
+ result.types = [typeText];
+ } else {
+ result.types = typeText.split('|');
+ }
} else {
result.types = [typeText];
}
@@ -777,8 +777,10 @@ export default class DocBuilder {
.replace(/<.*?>/g, (a)=> a.replace(/,/g, '\\Z'))
.replace(/{.*?}/g, (a)=> a.replace(/,/g, '\\Z').replace(/:/g, '\\Y'));
const innerTypes = inner.split(',').map((v) => {
- v = v.trim().replace(/\\Z/g, ',').replace(/\\Y/g, ':');
- return this._buildTypeDocLinkHTML(v);
+ return v.split('|').map((vv) => {
+ vv = vv.trim().replace(/\\Z/g, ',').replace(/\\Y/g, ':');
+ return this._buildTypeDocLinkHTML(vv);
+ }).join('|');
});
const html = `${this._buildDocLinkHTML(mainType, mainType)}<${innerTypes.join(', ')}>`;
@@ -27,4 +27,11 @@ export default class TestTypeComplex {
* @param {!(number|string)} p2 - this is p2.
*/
method4(p1, p2){}
+
+ // union in generics
+ /**
+ * this is method5.
+ * @param {Promise<string|number, Error>} p1 - this is p1.
+ */
+ method5(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"]', '277/347');
+ assert.includes(doc, '[data-ice="totalCoverageCount"]', '278/348');
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', '80 %4/5');
+ test('file/src/Type/Complex.js.html#errorLines=1', '83 %5/6');
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');
@@ -57,4 +57,16 @@ describe('TestTypeComplex', ()=> {
], 'href');
});
});
+
+ it('has complex union type in generics.', ()=>{
+ findParent(doc, '[data-ice="summary"] [href$="#instance-method-method5"]', '[data-ice="target"]', (doc)=> {
+ assert.includes(doc, null, 'method5(p1: Promise<string|number, Error>)');
+ assert.multiIncludes(doc, '[data-ice="signature"] a', [
+ 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise',
+ 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String',
+ '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/Error'
+ ], 'href');
+ });
+ });
});

0 comments on commit eb051e7

Please sign in to comment.