implement object rest/spread (#2265)

- improve parse errors for destructuring spread elements
- `unsafe` for object literals with rest elements

Miscellaneous
- increase mocha unicode surrogate test timeout
This commit is contained in:
kzc
2017-08-02 01:47:58 -04:00
committed by Alex Lam S.L
parent f54ab16843
commit 4700c14855
5 changed files with 117 additions and 16 deletions

View File

@@ -253,13 +253,19 @@ describe("Left-hand side expressions", function () {
// Multiple spreads are not allowed in destructuring array
expect("[...a, ...b] = [1, 2, 3, 4]", "Spread must the be last element in destructuring array");
// Spread in obvious object pattern
expect("({...a} = foo)", "Unexpected token: expand (...)");
// Array spread must be last in destructuring declaration
expect("let [ ...x, a ] = o;", "Rest element must be last element");
// Only one spread per destructuring array declaration
expect("let [ a, ...x, ...y ] = o;", "Rest element must be last element");
// Spread in block should not be allowed
expect("{...a} = foo", "Unexpected token: expand (...)");
// Not in standard yet
expect("let foo = {bar: 42}, bar; bar = {...foo}", "Unexpected token: expand (...)");
// Object spread must be last in destructuring declaration
expect("let { ...x, a } = o;", "Rest element must be last element");
// Only one spread per destructuring declaration
expect("let { a, ...x, ...y } = o;", "Rest element must be last element");
});
});