Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion rhino/src/main/java/org/mozilla/javascript/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4920,7 +4920,10 @@ boolean destructuringObject(
boolean defaultValuesSetup = false;

for (AbstractObjectProperty abstractProp : node.getElements()) {
if (abstractProp instanceof SpreadObjectProperty) throw Kit.codeBug();
if (abstractProp instanceof SpreadObjectProperty) {
reportError("msg.no.object.rest");
return false;
}
ObjectProperty prop = (ObjectProperty) abstractProp;

int lineno = 0, column = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ msg.no.paren.after.parms =\
msg.parm.after.rest =\
parameter after rest parameter

msg.no.object.rest =\
object rest properties in destructuring are not supported

msg.no.brace.body =\
missing '{' before function body

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.mozilla.javascript.tests;

import org.junit.Test;
import org.mozilla.javascript.testutils.Utils;

/** Object rest in destructuring throws SyntaxError */
public class ObjectRestErrorTest {

@Test
public void objectRestThrowsSyntaxError() {
Utils.assertEvaluatorExceptionES6(
"object rest properties in destructuring are not supported",
"function f() { var { a, ...rest } = { a: 1, b: 2, c: 3 }; }");
}

@Test
public void objectRestInFunctionParamThrowsSyntaxError() {
Utils.assertEvaluatorExceptionES6(
"object rest properties in destructuring are not supported",
"function f({ a, ...rest }) { return rest; }");
}

@Test
public void objectRestInVariableDeclarationThrowsSyntaxError() {
Utils.assertEvaluatorExceptionES6(
"object rest properties in destructuring are not supported",
"var { a, ...rest } = { a: 1, b: 2, c: 3 };");
}
}