@nodesecure/js-x-ray
Version:
JavaScript AST XRay analysis
42 lines • 1.27 kB
JavaScript
// Import Internal Dependencies
import {} from "./utils/toArrayLocation.js";
export class DefaultCollectableSet {
#entries = new Map();
type;
constructor(type) {
this.type = type;
}
add(value, { file = null, location, metadata }) {
if (!this.#entries.has(value)) {
this.#entries.set(value, new Map([[file, [{ location, metadata }]]]));
return;
}
const files = this.#entries.get(value);
if (files?.has(file)) {
files?.get(file)?.push({ location, metadata });
return;
}
files?.set(file, [{ location, metadata }]);
}
values() {
return this.#entries.keys();
}
*[Symbol.iterator]() {
for (const [value, files] of this.#entries) {
const locations = [];
for (const [file, locs] of files) {
for (const { location, metadata } of locs) {
locations.push({
file,
location: [location],
...(metadata && { metadata })
});
}
}
yield {
value, locations
};
}
}
}
//# sourceMappingURL=CollectableSet.js.map