Test that destructured parameter bindings correctly do NOT receive local indices when defeated by closure capture, direct eval, with statements, or arguments object access.
30 lines
753 B
JavaScript
30 lines
753 B
JavaScript
// Destructured parameter captured by a closure loses its local index.
|
|
function captured_by_closure({ x }) {
|
|
return function () {
|
|
return x;
|
|
};
|
|
}
|
|
|
|
// Direct eval in the function defeats local indices.
|
|
function eval_defeats({ a, b }) {
|
|
eval("");
|
|
return a + b;
|
|
}
|
|
|
|
// `with` statement defeats local indices for identifiers used inside.
|
|
function with_defeats({ x }, obj) {
|
|
with (obj) {
|
|
return x;
|
|
}
|
|
}
|
|
|
|
// Accessing `arguments` object prevents parameter locals.
|
|
function arguments_access({ x }) {
|
|
return arguments[0];
|
|
}
|
|
|
|
// Plain + destructured: only plain should keep [argument:N] when
|
|
// no defeating conditions apply within the same function.
|
|
function mixed_no_defeat(first, [a, b]) {
|
|
return first + a + b;
|
|
}
|