Fixes issues with global.
This commit is contained in:
@@ -12,8 +12,8 @@ export function cache<T>(
|
||||
let resultFn: () => any;
|
||||
let key: string;
|
||||
if (typeof expression === "string") {
|
||||
const evalFn = DataExtractorApiImpl.lastEvalFn!;
|
||||
resultFn = () => evalFn(expression);
|
||||
const context = DataExtractorApiImpl.lastContext!;
|
||||
resultFn = () => context.evalFn(expression);
|
||||
key = JSON.stringify({ expr: expression, id });
|
||||
} else {
|
||||
resultFn = () => expression();
|
||||
|
||||
@@ -2,12 +2,22 @@ import { DataExtractorApiImpl } from "../api";
|
||||
|
||||
export function find(predicate: (obj: unknown) => boolean): unknown {
|
||||
const processed = new Set();
|
||||
if (!DataExtractorApiImpl.lastVariablesInScope) {
|
||||
throw new Error("No variables in scope!");
|
||||
if (!DataExtractorApiImpl.lastContext) {
|
||||
throw new Error("No data extractor context!");
|
||||
}
|
||||
|
||||
const values = Object.values(DataExtractorApiImpl.lastVariablesInScope);
|
||||
const queue = [...values];
|
||||
const values = Object.values(
|
||||
DataExtractorApiImpl.lastContext.variablesInScope
|
||||
);
|
||||
const queue = [
|
||||
...values.map((v) => {
|
||||
try {
|
||||
return v();
|
||||
} catch (e) {
|
||||
return undefined;
|
||||
}
|
||||
}),
|
||||
];
|
||||
|
||||
let i = 10000;
|
||||
while (i > 0) {
|
||||
|
||||
@@ -30,17 +30,17 @@ export function tryEval(
|
||||
obj: Record<string, string> | string[] | string
|
||||
): Record<string, unknown> | unknown {
|
||||
const result: Record<string, unknown> = {};
|
||||
const evalFn = DataExtractorApiImpl.lastEvalFn!;
|
||||
const context = DataExtractorApiImpl.lastContext!;
|
||||
if (Array.isArray(obj)) {
|
||||
for (const val of obj) {
|
||||
try {
|
||||
result[val] = evalFn(val);
|
||||
result[val] = context.evalFn(val);
|
||||
} catch (e) {}
|
||||
}
|
||||
} else {
|
||||
for (const [key, val] of Object.entries(obj)) {
|
||||
try {
|
||||
result[key] = evalFn(val);
|
||||
result[key] = context.evalFn(val);
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user