Skip to content

Commit 5c4b530

Browse files
authored
Fix: Don't pass undefined identifier for array pattern varargs (#152)
* Fix: Don't pass undefined identifier for array pattern varargs * fix test
1 parent 395de17 commit 5c4b530

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

.idea/webdoc.iml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/webdoc-parser/src/symbols-babel/extract-metadata.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,10 @@ export function extractParams(
216216
optional: paramNode.optional || false,
217217
};
218218
} else if (isRestElement(paramNode)) {
219+
const argument = paramNode.argument;
220+
219221
param = {
220-
identifier: paramNode.argument.name,
222+
identifier: isIdentifier(argument) ? argument.name : "rest_args",
221223
optional: paramNode.optional || false,
222224
variadic: true,
223225
};

packages/webdoc-parser/test/lang-ts.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,32 @@ describe("@webdoc/parser.LanguageIntegration{@lang ts}", function() {
181181
expect(symtree.members[0].members.length).to.equal(1);
182182
});
183183

184+
// it("should work with spread object parameters", function() {
185+
// const symbolTree = buildSymbolTree(`
186+
// /** Build */
187+
// class Factory {
188+
// /** Build with options. */
189+
// build({ arg0, arg1, arg2 }: Opts) { }
190+
// }
191+
// `);
192+
// const build = symbolTree.members[0].members[0];
193+
//
194+
// expect(build.meta.params.length).to.equal(4);// implicit param!
195+
// });
196+
197+
it("should work with spread tuple parameters", function() {
198+
const symbolTree = buildSymbolTree(`
199+
/** Figure it out. */
200+
function dynamic_call(...[a0, a1]: [string, number] | [number, string]) {
201+
}
202+
`);
203+
const dynamicCall = symbolTree.members[0];
204+
205+
expect(dynamicCall.meta.params.length).to.equal(1);
206+
expect(dynamicCall.meta.params[0].identifier).to.not.equal(undefined);
207+
expect(dynamicCall.meta.params[0].dataType[0]).to.equal("[string, number] | [number, string]");
208+
});
209+
184210
it("should parse type parameters", function() {
185211
const symbolTree = buildSymbolTree(`
186212
class Builder {
@@ -195,7 +221,7 @@ describe("@webdoc/parser.LanguageIntegration{@lang ts}", function() {
195221
expect(symbolTree.members[0].members[1].meta.dataType[0]).to.equal("Map<K, V>");
196222
});
197223

198-
it("should parse parameter types", function() {
224+
it("should parse parameter types with default values", function() {
199225
const symbolTree = buildSymbolTree(`
200226
function mark(what: object | string = 'test') {
201227
}

packages/webdoc-parser/test/parse-ts.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,27 @@ describe("@webdoc/parser.parse (Typescript)", function() {
154154
expect(lengthProperty.dataType[0]).to.equal("number");
155155
});
156156

157+
it("should work with arrow function properties", async function() {
158+
const documentTree = await parse([{
159+
content: `
160+
class Factory {
161+
/**
162+
* Build the object.
163+
* @param args - Args.
164+
*/
165+
create = (args: Opts) => undefined
166+
}
167+
`,
168+
path: "*.ts",
169+
package: createPackageDoc(),
170+
}]);
171+
const createMethod = findDoc("Factory.create", documentTree);
172+
173+
// expect(createMethod.type).to.equal("MethodDoc");
174+
expect(createMethod.params.length).to.equal(1);
175+
// expect(createMethod.params[0].dataType[0]).to.equal("Opts");
176+
});
177+
157178
it("should properly inherit all method overloads", async function() {
158179
const documentTree = await parse([{
159180
content: `

0 commit comments

Comments
 (0)