Skip to content
Permalink
Browse files

feat(experimental): object rest spread

  • Loading branch information...
h13i32maru committed Nov 19, 2016
1 parent c0e170d commit b58aa054620e7335d7dcf8e0c81d4cb221e1fc6e
@@ -61,6 +61,7 @@ export default class ESParser {

if (experimental) {
if (experimental.classProperties) option.plugins.push('classProperties');
if (experimental.objectRestSpread) option.plugins.push('objectRestSpread');
}

return option;
@@ -237,8 +237,13 @@ export default class ParamParser {
const objectPattern = [];
const raw = {};
for (const property of param.properties) {
objectPattern.push(`"${property.key.name}": *`);
raw[property.key.name] = null;
if (property.type === 'ObjectProperty') {
objectPattern.push(`"${property.key.name}": *`);
raw[property.key.name] = null;
} else if (property.type === 'RestProperty') {
objectPattern.push(`...${property.argument.name}: Object`);
raw[property.argument.name] = {};
}
}
result.name = `objectPattern${i === 0 ? '' : i}`;
result.types = [`{${objectPattern.join(', ')}}`];
@@ -30,6 +30,7 @@
* @property {string[]} manual.changelog
* @property {Object} [experimentalProposal]
* @property {boolean} experimentalProposal.classProperties
* @property {boolean} experimentalProposal.objectRestSpread
* @see https://esdoc.org/config.html
*/

@@ -22,6 +22,7 @@
"changelog": ["./test/fixture/package/CHANGELOG.md"]
},
"experimentalProposal": {
"classProperties": true
"classProperties": true,
"objectRestSpread": true
}
}
@@ -17,4 +17,6 @@ export default class TestGuessParam {
method7(p1 = value){}

method8(p1 = new Foo()){}

method9({x, y, ...z}){}
}
@@ -7,4 +7,14 @@ export default class TestTypeSpread {
* @param {...number} p1 - this is spread number p1.
*/
method1(...p1){}

/**
* this is method2.
* @param {Object} config - this is config.
* @param {number} config.x - this is number x.
* @param {string} config.y - this is string y.
* @param {number[]} config.a - thi is number[] a.
* @param {string[]} config.b - thi is number[] b.
*/
method2({x, y, ...z}){}
}
@@ -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"]', '266/333');
assert.includes(doc, '[data-ice="totalCoverageCount"]', '267/335');
assert.equal(doc.find('[data-ice="file"] [data-ice="coverage"]').length, 117);
});

@@ -82,7 +82,7 @@ describe('test coverage', ()=> {
test('file/src/External/Definition.js.html', '-');
test('file/src/Generator/Function.js.html', '100 %1/1');
test('file/src/Generator/Method.js.html', '100 %2/2');
test('file/src/Guess/Param.js.html#errorLines=11,13,15,17,19,5,7,9', '11 %1/9');
test('file/src/Guess/Param.js.html#errorLines=11,13,15,17,19,21,5,7,9', '10 %1/10');
test('file/src/Guess/Property.js.html#errorLines=10,12,5,6,8', '16 %1/6');
test('file/src/Guess/Return.js.html#errorLines=13,17,5,9', '20 %1/5');
test('file/src/Guess/Variable.js.html#errorLines=1,3,5,7', '0 %0/4');
@@ -128,7 +128,7 @@ describe('test coverage', ()=> {
test('file/src/Type/Object.js.html', '100 %2/2');
test('file/src/Type/Optional.js.html', '100 %2/2');
test('file/src/Type/Record.js.html', '100 %2/2');
test('file/src/Type/Spread.js.html', '100 %2/2');
test('file/src/Type/Spread.js.html', '100 %3/3');
test('file/src/Type/Typedef.js.html', '100 %2/2');
test('file/src/Type/Union.js.html', '100 %2/2');
test('file/src/Typedef/Definition.js.html', '-');
@@ -37,6 +37,10 @@ describe('TestGuessParam', ()=> {
findParent(doc, '[data-ice="summary"] [href$="#instance-method-method8"]', '[data-ice="target"]', (doc)=> {
assert.includes(doc, null, 'public method8(p1: *)');
});

findParent(doc, '[data-ice="summary"] [href$="#instance-method-method9"]', '[data-ice="target"]', (doc)=> {
assert.includes(doc, null, 'public method9(objectPattern: {"x": *, "y": *, ...z: Object})');
});
});
});

@@ -80,9 +84,14 @@ describe('TestGuessParam', ()=> {
});

findParent(doc, '[id="instance-method-method8"]', '[data-ice="detail"]', (doc)=>{
assert.includes(doc, 'h3', 'public ');
assert.includes(doc, 'h3', 'public method8(p1: *)');
assert.includes(doc, '.params tbody tr:nth-child(1)', 'p1 * optional');
});

findParent(doc, '[id="instance-method-method9"]', '[data-ice="detail"]', (doc)=>{
assert.includes(doc, 'h3', 'public method9(objectPattern: {"x": *, "y": *, ...z: Object})');
assert.includes(doc, '.params tbody tr:nth-child(1)', 'objectPattern {"x": *, "y": *, ...z: Object} default: {"x":null,"y":null,"z":{}}');
});
});
});
});
@@ -15,4 +15,13 @@ describe('TestTypeSpread', ()=> {
], 'href');
});
});

it('has object spread type.', ()=> {
findParent(doc, '[data-ice="summary"] [href$="#instance-method-method2"]', '[data-ice="target"]', (doc)=> {
assert.includes(doc, null, 'method2(config: Object)');
assert.multiIncludes(doc, '[data-ice="signature"] a', [
'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object'
], 'href');
});
});
});

0 comments on commit b58aa05

Please sign in to comment.
You can’t perform that action at this time.