Skip to content

Commit 0f263a7

Browse files
authored
Merge pull request #71 from webdoc-labs/fix/rest-object
Fix crash on rest element applied to object destructuring
2 parents d3fec49 + 8ad2322 commit 0f263a7

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

packages/webdoc-parser/src/symbols-babel/build-symbol-tree.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
isIdentifier,
2626
isObjectMethod,
2727
isObjectPattern,
28+
isRestElement,
2829
isScope,
2930
isVariableDeclaration,
3031
} from "@babel/types";
@@ -470,6 +471,14 @@ function registerObjectPropertyVariables(node: ObjectPattern): void {
470471
for (let i = 0, j = props.length; i < j; i++) {
471472
const prop = props[i];
472473

474+
if (isRestElement(prop)) {
475+
continue;
476+
}
477+
478+
if (!prop.key) {
479+
throw new Error("WTF");
480+
}
481+
473482
declareVariable(prop.key.name);
474483

475484
if (isObjectPattern(prop.value)) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,12 @@ describe("@webdoc/parser.LanguageIntegration{@lang js}", function() {
112112
expect(symtree.members[0].meta.readonly).to.equal(true);
113113
expect(symtree.members[1].meta.readonly).to.not.equal(true);
114114
});
115+
116+
it("should not crash with rest object properties syntax", function() {
117+
expect(
118+
() => buildSymbolTree(`
119+
const { a, b, ...rest } = globalThis;
120+
`),
121+
).to.not.throw();
122+
});
115123
});

0 commit comments

Comments
 (0)