fix(javascript): preserve nested reads through numeric array properties (#12595)

fix(javascript): retain nested reads through numeric array properties
This commit is contained in:
morluto authored and GitHub committed 2026-11-20 00:09:58 +00:00
1 parent a611944533
commit e736d90bdf
4 files changed
+57 -9

No files matched your search

@@ -2091,6 +2091,54 @@ it.each([
resolution,
] as const,
),
[
"a numeric own slot on an array RHS",
'const pairs=[["one"]];const {0:[selected]}=pairs;pairs[0][0]="later";',
["0", "0"],
"resolved",
],
[
"a quoted own array slot captured through a const alias",
'const pairs=[["one"]];const alias=pairs;let selected;({"0":[selected]}=alias);pairs[0][0]="later";',
["0", "0"],
"resolved",
],
[
"the second numeric own slot without acquiring the outer iterator",
'const pairs=[[0],["one"]];const {0:[used],1:[selected]}=pairs;pairs[1][0]="later";',
["1", "0"],
"resolved",
],
[
"an unresolved computed write on the outer array",
'const pairs=[["one"]];pairs[Symbol.iterator]=function*(){};const {0:[selected]}=pairs;pairs[0][0]="later";',
["0", "0"],
"candidate",
],
[
"an absent numeric own array slot",
'const pairs=[,["one"]];const {0:[selected]}=pairs;pairs[0]=["later"];',
["0", "0"],
"candidate",
],
[
"an earlier replacement of the numeric array slot",
'const pairs=[["one"]];pairs[0]=["earlier"];const {0:[selected]}=pairs;pairs[0][0]="later";',
["0", "0"],
"candidate",
],
[
"an overridden inner iterator selected from a numeric property",
'const pairs=[["one"]];pairs[0][Symbol.iterator]=function*(){};const {0:[selected]}=pairs;pairs[0][0]="later";',
["0", "0"],
"candidate",
],
[
"an earlier return hook before selecting the second numeric property",
'const pairs=[[0],["one"]];Object.prototype.return=()=>({});const {0:[used],1:[selected]}=pairs;pairs[1][0]="later";',
["1", "0"],
"candidate",
],
[
"second nested iterator after a prior assignment target",
'const box={first:[0],items:["one"]};let used,selected;({first:[used],items:[selected]}=box);box.items[0]="later";',
@@ -2098,7 +2146,7 @@ it.each([
"candidate",
],
] as const)(
"owns native iterators below an object for %s",
"owns nested native arrays through an object pattern for %s",
(_name, code, path, resolution) => {
const graph = graphForJavaScript(code);
const selected = graph.nodes.find(
@@ -248,7 +248,7 @@ const collectDestructuring = (
(!rootArray || path.length === 1) &&
t.isArrayExpression(selected) &&
propertyPath !== null
? sourcePresence?.readNestedArray?.(
? sourcePresence?.readNestedArray(
selected,
propertyPath,
path,
@@ -35,7 +35,7 @@ type ReadOwnData = (
interface ReadPresence {
readonly read: ReadOwnData;
readonly readNestedArray?: (
readonly readNestedArray: (
literal: t.ArrayExpression,
path: readonly string[],
fromRhs: readonly string[],
@@ -231,12 +231,7 @@ export const createSemanticReadPresenceQuery = (
);
return read === undefined
? undefined
: {
read,
...(iterationPath === undefined
? {}
: { readNestedArray: arraySlots }),
};
: { read, readNestedArray: arraySlots };
}
if (!t.isObjectExpression(value)) return undefined;
const read: ReadOwnData = (path, beforeIterator) => {
@@ -56,6 +56,7 @@ const expectedDependencies = [
["arrayObject", ["0", "mode"]],
["nestedElement", ["items", "0"]],
["siblingObjectElement", ["sibling", "0"]],
["numericInnerElement", ["0", "0"]],
["unreachedSibling", ["sibling", "0"], "candidate"],
["innerElement", ["0", "0"]],
["siblingInnerElement", ["1", "0"]],
@@ -81,6 +82,7 @@ const tracedBindings = [
"arrayObject",
"nestedElement",
"siblingObjectElement",
"numericInnerElement",
"unreachedSibling",
"innerElement",
"siblingInnerElement",
@@ -137,6 +139,9 @@ cliTest(
const { items: [nestedElement], empty: {}, sibling: [siblingObjectElement] } = nestedSource;
nestedSource.items[0] = "later";
nestedSource.sibling[0] = "later";
const numericSource = [["read-time"]];
const { 0: [numericInnerElement] } = numericSource;
numericSource[0][0] = "later";
const nestedPairs = [["read-time"], ["sibling"]];
const [[innerElement], [siblingInnerElement]] = nestedPairs;
nestedPairs[0][0] = "later";