mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: Allow assignment expression in spreading property definition
See: https://tc39.es/ecma262/#sec-runtime-semantics-propertydefinitionevaluation PropertyDefinition : ... AssignmentExpression Also add a test for this in array spreading, which already had this in place.
This commit is contained in:
parent
766cd852d3
commit
3ceedbd16a
Notes:
sideshowbarker
2024-07-16 17:12:03 +09:00
Author: https://github.com/Lubrsi Commit: https://github.com/SerenityOS/serenity/commit/3ceedbd16a Pull-request: https://github.com/SerenityOS/serenity/pull/20842
3 changed files with 41 additions and 1 deletions
|
@ -1926,7 +1926,7 @@ NonnullRefPtr<ObjectExpression const> Parser::parse_object_expression()
|
|||
|
||||
if (match(TokenType::TripleDot)) {
|
||||
consume();
|
||||
property_key = parse_expression(4);
|
||||
property_key = parse_expression(2);
|
||||
properties.append(create_ast_node<ObjectProperty>({ m_source_code, rule_start.position(), position() }, *property_key, nullptr, ObjectProperty::Type::Spread, false));
|
||||
if (!match(TokenType::Comma))
|
||||
break;
|
||||
|
|
|
@ -23,3 +23,23 @@ test("basic functionality", () => {
|
|||
|
||||
expect([...[], ...[...[1, 2, 3]], 4]).toEqual([1, 2, 3, 4]);
|
||||
});
|
||||
|
||||
test("allows assignment expressions", () => {
|
||||
expect("([ ...a = { hello: 'world' } ])").toEval();
|
||||
expect("([ ...a += 'hello' ])").toEval();
|
||||
expect("([ ...a -= 'hello' ])").toEval();
|
||||
expect("([ ...a **= 'hello' ])").toEval();
|
||||
expect("([ ...a *= 'hello' ])").toEval();
|
||||
expect("([ ...a /= 'hello' ])").toEval();
|
||||
expect("([ ...a %= 'hello' ])").toEval();
|
||||
expect("([ ...a <<= 'hello' ])").toEval();
|
||||
expect("([ ...a >>= 'hello' ])").toEval();
|
||||
expect("([ ...a >>>= 'hello' ])").toEval();
|
||||
expect("([ ...a &= 'hello' ])").toEval();
|
||||
expect("([ ...a ^= 'hello' ])").toEval();
|
||||
expect("([ ...a |= 'hello' ])").toEval();
|
||||
expect("([ ...a &&= 'hello' ])").toEval();
|
||||
expect("([ ...a ||= 'hello' ])").toEval();
|
||||
expect("([ ...a ??= 'hello' ])").toEval();
|
||||
expect("function* test() { return ([ ...yield a ]); }").toEval();
|
||||
});
|
||||
|
|
|
@ -172,3 +172,23 @@ describe("modification of spreadable objects during spread", () => {
|
|||
expect(arrayResult).toHaveProperty("1000", 1000);
|
||||
});
|
||||
});
|
||||
|
||||
test("allows assignment expressions", () => {
|
||||
expect("({ ...a = { hello: 'world' } })").toEval();
|
||||
expect("({ ...a += 'hello' })").toEval();
|
||||
expect("({ ...a -= 'hello' })").toEval();
|
||||
expect("({ ...a **= 'hello' })").toEval();
|
||||
expect("({ ...a *= 'hello' })").toEval();
|
||||
expect("({ ...a /= 'hello' })").toEval();
|
||||
expect("({ ...a %= 'hello' })").toEval();
|
||||
expect("({ ...a <<= 'hello' })").toEval();
|
||||
expect("({ ...a >>= 'hello' })").toEval();
|
||||
expect("({ ...a >>>= 'hello' })").toEval();
|
||||
expect("({ ...a &= 'hello' })").toEval();
|
||||
expect("({ ...a ^= 'hello' })").toEval();
|
||||
expect("({ ...a |= 'hello' })").toEval();
|
||||
expect("({ ...a &&= 'hello' })").toEval();
|
||||
expect("({ ...a ||= 'hello' })").toEval();
|
||||
expect("({ ...a ??= 'hello' })").toEval();
|
||||
expect("function* test() { return ({ ...yield a }); }").toEval();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue