fix: nested array destructuring
This commit is contained in:
parent
b679d15b5c
commit
b98cdb00a3
|
@ -69,12 +69,22 @@ export default class Sandbox {
|
|||
if (null === element) {
|
||||
continue;
|
||||
}
|
||||
if ('Identifier' === element.type) {
|
||||
scope.allocate(element.name, init[i]);
|
||||
}
|
||||
/* v8 ignore next 3 */
|
||||
else {
|
||||
throw new Error(`destructureArray(): Can't array destructure type ${element.type}`);
|
||||
switch (element.type) {
|
||||
case 'ArrayPattern': {
|
||||
this.destructureArray(element, init[i]);
|
||||
break;
|
||||
}
|
||||
case 'ObjectPattern': {
|
||||
this.destructureObject(element, init[i]);
|
||||
break;
|
||||
}
|
||||
case 'Identifier': {
|
||||
scope.allocate(element.name, init[i]);
|
||||
break;
|
||||
}
|
||||
/* v8 ignore next 2 */
|
||||
default:
|
||||
throw new Error(`destructureArray(): Can't array destructure type ${element.type}`);
|
||||
}
|
||||
}
|
||||
return init;
|
||||
|
|
|
@ -84,6 +84,7 @@ test('destructures variables', async () => {
|
|||
const {x: x1, y, z: {zz}} = {x: 4, y: 5, z: {zz: 6}};
|
||||
const [d, e] = await [7, 8];
|
||||
const {t, u: {uu}} = {t: 9, u: {uu: await 10}};
|
||||
const [[v], {w}] = [[11], {w: 12}];
|
||||
`),
|
||||
);
|
||||
await finish(sandbox);
|
||||
|
@ -98,6 +99,8 @@ test('destructures variables', async () => {
|
|||
e: 8,
|
||||
t: 9,
|
||||
uu: 10,
|
||||
v: 11,
|
||||
w: 12,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user