mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-11 09:27:00 +02:00
Add 39 test cases exercising AST dump output and scope analysis. Tests cover local/global identifier marking, eval/with poisoning, destructuring, closures, hoisting, classes, generators, and more.
41 lines
860 B
JavaScript
41 lines
860 B
JavaScript
// Comprehensive test of different binding forms and their local/global status.
|
|
|
|
// let, const, var at top level are all global.
|
|
let top_let = 1;
|
|
const top_const = 2;
|
|
var top_var = 3;
|
|
|
|
function all_binding_types() {
|
|
// These should all be local.
|
|
let a = 1;
|
|
const b = 2;
|
|
var c = 3;
|
|
return a + b + c;
|
|
}
|
|
|
|
// for-loop heads create locals.
|
|
function for_binding_forms() {
|
|
for (let i = 0; i < 1; i++) {}
|
|
for (const x of [1]) {
|
|
x;
|
|
}
|
|
for (var j = 0; j < 1; j++) {}
|
|
j;
|
|
}
|
|
|
|
// Destructuring bindings in all forms.
|
|
function destructuring_bindings() {
|
|
let [a, b] = [1, 2];
|
|
const { c, d } = { c: 3, d: 4 };
|
|
var [e, ...f] = [5, 6, 7];
|
|
return a + b + c + d + e + f[0];
|
|
}
|
|
|
|
// Multiple declarators in one statement.
|
|
function multi_declarator() {
|
|
let x = 1,
|
|
y = 2,
|
|
z = 3;
|
|
return x + y + z;
|
|
}
|