mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-12 20:42:21 +00:00
LibJS: Parse arrow function expression with correct precedence
The parser was chomping on commas present after the arrow function expression. eg. [x=>x,2] would parse as [x=>(x,2)] instead of [(x=>x),2]. This is not the case anymore. I've added a small test to prove this.
This commit is contained in:
parent
20faa93cb0
commit
4e8de753c9
Notes:
sideshowbarker
2024-07-19 05:58:53 +09:00
Author: https://github.com/nooga
Commit: 4e8de753c9
Pull-request: https://github.com/SerenityOS/serenity/pull/2448
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/linusg ✅
3 changed files with 7 additions and 5 deletions
|
@ -67,8 +67,7 @@ try {
|
|||
result = [5, 4, 3, 2, 1].reduce((accum, elem) => accum + elem);
|
||||
assert(result === 15);
|
||||
|
||||
// likely parser bug: arrow func parser eats ", 100" as a part of the function, hence the parens
|
||||
result = [1, 2, 3, 4, 5, 6].reduce(((accum, elem) => accum + elem), 100);
|
||||
result = [1, 2, 3, 4, 5, 6].reduce((accum, elem) => accum + elem, 100);
|
||||
assert(result === 121);
|
||||
|
||||
result = [6, 5, 4, 3, 2, 1].reduce((accum, elem) => { return accum + elem }, 100);
|
||||
|
|
|
@ -16,6 +16,10 @@ try {
|
|||
};
|
||||
assert(addBlock(5, 4) === 9);
|
||||
|
||||
let chompy = [(x) => x, 2];
|
||||
assert(chompy.length === 2);
|
||||
assert(chompy[0](1) === 1);
|
||||
|
||||
const makeObject = (a, b) => ({ a, b });
|
||||
const obj = makeObject(33, 44);
|
||||
assert(typeof obj === "object");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue