Skip to content

Commit b58aa05

Browse files
committed
feat(experimental): object rest spread
1 parent c0e170d commit b58aa05

File tree

9 files changed

+45
-7
lines changed

9 files changed

+45
-7
lines changed

src/Parser/ESParser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export default class ESParser {
6161

6262
if (experimental) {
6363
if (experimental.classProperties) option.plugins.push('classProperties');
64+
if (experimental.objectRestSpread) option.plugins.push('objectRestSpread');
6465
}
6566

6667
return option;

src/Parser/ParamParser.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,13 @@ export default class ParamParser {
237237
const objectPattern = [];
238238
const raw = {};
239239
for (const property of param.properties) {
240-
objectPattern.push(`"${property.key.name}": *`);
241-
raw[property.key.name] = null;
240+
if (property.type === 'ObjectProperty') {
241+
objectPattern.push(`"${property.key.name}": *`);
242+
raw[property.key.name] = null;
243+
} else if (property.type === 'RestProperty') {
244+
objectPattern.push(`...${property.argument.name}: Object`);
245+
raw[property.argument.name] = {};
246+
}
242247
}
243248
result.name = `objectPattern${i === 0 ? '' : i}`;
244249
result.types = [`{${objectPattern.join(', ')}}`];

src/Typedef/typedef.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* @property {string[]} manual.changelog
3131
* @property {Object} [experimentalProposal]
3232
* @property {boolean} experimentalProposal.classProperties
33+
* @property {boolean} experimentalProposal.objectRestSpread
3334
* @see https://esdoc.org/config.html
3435
*/
3536

test/fixture/package/esdoc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"changelog": ["./test/fixture/package/CHANGELOG.md"]
2323
},
2424
"experimentalProposal": {
25-
"classProperties": true
25+
"classProperties": true,
26+
"objectRestSpread": true
2627
}
2728
}

test/fixture/package/src/Guess/Param.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ export default class TestGuessParam {
1717
method7(p1 = value){}
1818

1919
method8(p1 = new Foo()){}
20+
21+
method9({x, y, ...z}){}
2022
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,14 @@ export default class TestTypeSpread {
77
* @param {...number} p1 - this is spread number p1.
88
*/
99
method1(...p1){}
10+
11+
/**
12+
* this is method2.
13+
* @param {Object} config - this is config.
14+
* @param {number} config.x - this is number x.
15+
* @param {string} config.y - this is string y.
16+
* @param {number[]} config.a - thi is number[] a.
17+
* @param {string[]} config.b - thi is number[] b.
18+
*/
19+
method2({x, y, ...z}){}
1020
}

test/src/HTMLTest/CoverageTest/CoverageTest.js

Lines changed: 3 additions & 3 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"]', '266/333');
12+
assert.includes(doc, '[data-ice="totalCoverageCount"]', '267/335');
1313
assert.equal(doc.find('[data-ice="file"] [data-ice="coverage"]').length, 117);
1414
});
1515

@@ -82,7 +82,7 @@ describe('test coverage', ()=> {
8282
test('file/src/External/Definition.js.html', '-');
8383
test('file/src/Generator/Function.js.html', '100 %1/1');
8484
test('file/src/Generator/Method.js.html', '100 %2/2');
85-
test('file/src/Guess/Param.js.html#errorLines=11,13,15,17,19,5,7,9', '11 %1/9');
85+
test('file/src/Guess/Param.js.html#errorLines=11,13,15,17,19,21,5,7,9', '10 %1/10');
8686
test('file/src/Guess/Property.js.html#errorLines=10,12,5,6,8', '16 %1/6');
8787
test('file/src/Guess/Return.js.html#errorLines=13,17,5,9', '20 %1/5');
8888
test('file/src/Guess/Variable.js.html#errorLines=1,3,5,7', '0 %0/4');
@@ -128,7 +128,7 @@ describe('test coverage', ()=> {
128128
test('file/src/Type/Object.js.html', '100 %2/2');
129129
test('file/src/Type/Optional.js.html', '100 %2/2');
130130
test('file/src/Type/Record.js.html', '100 %2/2');
131-
test('file/src/Type/Spread.js.html', '100 %2/2');
131+
test('file/src/Type/Spread.js.html', '100 %3/3');
132132
test('file/src/Type/Typedef.js.html', '100 %2/2');
133133
test('file/src/Type/Union.js.html', '100 %2/2');
134134
test('file/src/Typedef/Definition.js.html', '-');

test/src/HTMLTest/DocumentTest/GuessTest/ParamTest.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ describe('TestGuessParam', ()=> {
3737
findParent(doc, '[data-ice="summary"] [href$="#instance-method-method8"]', '[data-ice="target"]', (doc)=> {
3838
assert.includes(doc, null, 'public method8(p1: *)');
3939
});
40+
41+
findParent(doc, '[data-ice="summary"] [href$="#instance-method-method9"]', '[data-ice="target"]', (doc)=> {
42+
assert.includes(doc, null, 'public method9(objectPattern: {"x": *, "y": *, ...z: Object})');
43+
});
4044
});
4145
});
4246

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

8286
findParent(doc, '[id="instance-method-method8"]', '[data-ice="detail"]', (doc)=>{
83-
assert.includes(doc, 'h3', 'public ');
87+
assert.includes(doc, 'h3', 'public method8(p1: *)');
8488
assert.includes(doc, '.params tbody tr:nth-child(1)', 'p1 * optional');
8589
});
90+
91+
findParent(doc, '[id="instance-method-method9"]', '[data-ice="detail"]', (doc)=>{
92+
assert.includes(doc, 'h3', 'public method9(objectPattern: {"x": *, "y": *, ...z: Object})');
93+
assert.includes(doc, '.params tbody tr:nth-child(1)', 'objectPattern {"x": *, "y": *, ...z: Object} default: {"x":null,"y":null,"z":{}}');
94+
});
8695
});
8796
});
8897
});

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,13 @@ describe('TestTypeSpread', ()=> {
1515
], 'href');
1616
});
1717
});
18+
19+
it('has object spread type.', ()=> {
20+
findParent(doc, '[data-ice="summary"] [href$="#instance-method-method2"]', '[data-ice="target"]', (doc)=> {
21+
assert.includes(doc, null, 'method2(config: Object)');
22+
assert.multiIncludes(doc, '[data-ice="signature"] a', [
23+
'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object'
24+
], 'href');
25+
});
26+
});
1827
});

0 commit comments

Comments
 (0)