Skip to content

Commit a47a6de

Browse files
committed
fix(napi/parser): lazy deser: do not expose getElement method from NodeArray (#11777)
`getElement` is an internal method. Don't publicly expose it on `NodeArray` class.
1 parent 4e5beb0 commit a47a6de

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

napi/parser/raw-transfer/node-array.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const { TOKEN, constructorError } = require('./lazy-common.js');
99
// Seems necessary because `this` in methods is a proxy, so accessing `this.#internal` throws.
1010
const nodeArrays = new WeakMap();
1111

12+
// Function to get element from an array. Initialized in class static block below.
13+
let getElement;
14+
1215
// An array of AST nodes where elements are deserialized lazily upon access.
1316
//
1417
// Extends `Array` to make `Array.isArray` return `true` for a `NodeArray`.
@@ -119,22 +122,22 @@ class NodeArray extends Array {
119122
return values;
120123
}
121124

122-
/**
123-
* Get element of `NodeArray` at index `index`.
124-
* `index` must be in bounds (i.e. `< arr.length`).
125-
*
126-
* @param {NodeArray} arr - `NodeArray` object
127-
* @param {number} index - Index of element to get
128-
* @returns {*} - Element at index `index`
129-
*/
130-
static getElement(arr, index) {
131-
const internal = arr.#internal;
132-
return (0, internal.construct)(internal.pos + index * internal.stride, internal.ast);
125+
static {
126+
/**
127+
* Get element of `NodeArray` at index `index`.
128+
* `index` must be in bounds (i.e. `< arr.length`).
129+
*
130+
* @param {NodeArray} arr - `NodeArray` object
131+
* @param {number} index - Index of element to get
132+
* @returns {*} - Element at index `index`
133+
*/
134+
getElement = (arr, index) => {
135+
const internal = arr.#internal;
136+
return (0, internal.construct)(internal.pos + index * internal.stride, internal.ast);
137+
};
133138
}
134139
}
135140

136-
const { getElement } = NodeArray;
137-
138141
NodeArray.prototype[Symbol.iterator] = NodeArray.prototype.values;
139142

140143
module.exports = NodeArray;

0 commit comments

Comments
 (0)