@tracecode/harness 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +113 -0
- package/LICENSE +674 -0
- package/README.md +266 -0
- package/dist/browser.cjs +1352 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.cts +49 -0
- package/dist/browser.d.ts +49 -0
- package/dist/browser.js +1317 -0
- package/dist/browser.js.map +1 -0
- package/dist/cli.cjs +70 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +70 -0
- package/dist/cli.js.map +1 -0
- package/dist/core.cjs +286 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +69 -0
- package/dist/core.d.ts +69 -0
- package/dist/core.js +254 -0
- package/dist/core.js.map +1 -0
- package/dist/index.cjs +2603 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2538 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/browser.cjs +647 -0
- package/dist/internal/browser.cjs.map +1 -0
- package/dist/internal/browser.d.cts +143 -0
- package/dist/internal/browser.d.ts +143 -0
- package/dist/internal/browser.js +617 -0
- package/dist/internal/browser.js.map +1 -0
- package/dist/javascript.cjs +549 -0
- package/dist/javascript.cjs.map +1 -0
- package/dist/javascript.d.cts +11 -0
- package/dist/javascript.d.ts +11 -0
- package/dist/javascript.js +518 -0
- package/dist/javascript.js.map +1 -0
- package/dist/python.cjs +744 -0
- package/dist/python.cjs.map +1 -0
- package/dist/python.d.cts +97 -0
- package/dist/python.d.ts +97 -0
- package/dist/python.js +698 -0
- package/dist/python.js.map +1 -0
- package/dist/runtime-types-C7d1LFbx.d.ts +85 -0
- package/dist/runtime-types-Dvgn07z9.d.cts +85 -0
- package/dist/types-Bzr1Ohcf.d.cts +96 -0
- package/dist/types-Bzr1Ohcf.d.ts +96 -0
- package/package.json +89 -0
- package/workers/javascript/javascript-worker.js +2918 -0
- package/workers/python/generated-python-harness-snippets.js +20 -0
- package/workers/python/pyodide-worker.js +1197 -0
- package/workers/python/runtime-core.js +1529 -0
- package/workers/vendor/typescript.js +200276 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../packages/harness-javascript/src/index.ts","../packages/harness-javascript/src/typescript-runtime-declarations.ts","../packages/harness-javascript/src/javascript-executor.ts"],"sourcesContent":["export * from './javascript-executor';\nexport * from './typescript-runtime-declarations';\n","export const TYPESCRIPT_RUNTIME_DECLARATIONS = `\ndeclare class ListNode {\n val: any;\n next: ListNode | SerializedListNode | SerializedRef | null;\n prev?: ListNode | SerializedListNode | SerializedRef | null;\n constructor(val?: any, next?: ListNode | null);\n}\n\ndeclare class TreeNode {\n val: any;\n left: TreeNode | SerializedTreeNode | SerializedRef | null;\n right: TreeNode | SerializedTreeNode | SerializedRef | null;\n constructor(val?: any, left?: TreeNode | null, right?: TreeNode | null);\n}\n\ntype SerializedRef = { __ref__: string };\n\ntype SerializedListNode = {\n __id__?: string;\n __type__?: 'ListNode';\n val?: any;\n next?: SerializedListNode | SerializedRef | ListNode | null;\n prev?: SerializedListNode | SerializedRef | ListNode | null;\n};\n\ntype SerializedTreeNode = {\n __id__?: string;\n __type__?: 'TreeNode';\n val?: any;\n left?: SerializedTreeNode | SerializedRef | TreeNode | null;\n right?: SerializedTreeNode | SerializedRef | TreeNode | null;\n};\n`;\n\nexport function withTypeScriptRuntimeDeclarations(sourceCode: string): string {\n return `${sourceCode}\\n\\n${TYPESCRIPT_RUNTIME_DECLARATIONS}\\n`;\n}\n\n","import type { RuntimeExecutionStyle } from '../../harness-core/src/runtime-types';\nimport type { CodeExecutionResult, ExecutionResult } from '../../harness-core/src/types';\nimport { withTypeScriptRuntimeDeclarations } from './typescript-runtime-declarations';\n\ntype TypeScriptModule = typeof import('typescript');\n\nlet typeScriptModulePromise: Promise<TypeScriptModule> | null = null;\n\ntype DynamicRunner = (...args: unknown[]) => unknown;\n\nasync function getTypeScriptModule(): Promise<TypeScriptModule> {\n if (!typeScriptModulePromise) {\n const specifier = 'typescript';\n typeScriptModulePromise = import(/* webpackIgnore: true */ specifier);\n }\n return typeScriptModulePromise;\n}\n\nfunction performanceNow(): number {\n if (typeof performance !== 'undefined' && typeof performance.now === 'function') {\n return performance.now();\n }\n return Date.now();\n}\n\nfunction formatConsoleArg(value: unknown): string {\n if (typeof value === 'string') return value;\n if (typeof value === 'number' || typeof value === 'boolean' || value === null || value === undefined) {\n return String(value);\n }\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n}\n\nfunction createConsoleProxy(output: string[]): Console {\n const capture = (...args: unknown[]) => {\n output.push(args.map(formatConsoleArg).join(' '));\n };\n\n return {\n ...console,\n log: capture,\n info: capture,\n warn: capture,\n error: capture,\n debug: capture,\n };\n}\n\nfunction isLikelyTreeNodeValue(value: unknown): value is Record<string, unknown> {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return false;\n const hasValue = 'val' in value || 'value' in value;\n const hasTreeLinks = 'left' in value || 'right' in value;\n return hasValue && hasTreeLinks;\n}\n\nfunction isLikelyListNodeValue(value: unknown): value is Record<string, unknown> {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return false;\n const hasValue = 'val' in value || 'value' in value;\n const hasTreeLinks = 'left' in value || 'right' in value;\n const hasListLinks = 'next' in value || 'prev' in value;\n return hasValue && hasListLinks && !hasTreeLinks;\n}\n\nfunction serializeValue(\n value: unknown,\n depth = 0,\n seen = new WeakSet<object>(),\n nodeRefState: { ids: Map<object, string>; nextId: number } = { ids: new Map<object, string>(), nextId: 1 }\n): unknown {\n if (depth > 48) return '<max depth>';\n if (value === null || value === undefined) return value;\n\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {\n return value;\n }\n if (typeof value === 'bigint') {\n return Number.isSafeInteger(Number(value)) ? Number(value) : String(value);\n }\n if (typeof value === 'function') {\n return '<function>';\n }\n\n if (Array.isArray(value)) {\n return value.map((item) => serializeValue(item, depth + 1, seen));\n }\n\n if (value instanceof Set) {\n return {\n __type__: 'set',\n values: [...value].map((item) => serializeValue(item, depth + 1, seen, nodeRefState)),\n };\n }\n\n if (value instanceof Map) {\n return {\n __type__: 'map',\n entries: [...value.entries()].map(([k, v]) => [\n serializeValue(k, depth + 1, seen, nodeRefState),\n serializeValue(v, depth + 1, seen, nodeRefState),\n ]),\n };\n }\n\n if (typeof value === 'object') {\n if (isLikelyTreeNodeValue(value) || isLikelyListNodeValue(value)) {\n const objectValue = value as object;\n const nodeValue = value as Record<string, unknown>;\n const existingId = nodeRefState.ids.get(objectValue);\n if (existingId) {\n return { __ref__: existingId };\n }\n\n const isTree = isLikelyTreeNodeValue(value);\n const nodePrefix = isTree ? 'tree' : 'list';\n const nodeId = `${nodePrefix}-${nodeRefState.nextId++}`;\n nodeRefState.ids.set(objectValue, nodeId);\n\n if (isTree) {\n return {\n __type__: 'TreeNode',\n __id__: nodeId,\n val: serializeValue(nodeValue.val ?? nodeValue.value ?? null, depth + 1, seen, nodeRefState),\n left: serializeValue(nodeValue.left ?? null, depth + 1, seen, nodeRefState),\n right: serializeValue(nodeValue.right ?? null, depth + 1, seen, nodeRefState),\n };\n }\n\n return {\n __type__: 'ListNode',\n __id__: nodeId,\n val: serializeValue(nodeValue.val ?? nodeValue.value ?? null, depth + 1, seen, nodeRefState),\n next: serializeValue(nodeValue.next ?? null, depth + 1, seen, nodeRefState),\n ...('prev' in nodeValue\n ? { prev: serializeValue(nodeValue.prev ?? null, depth + 1, seen, nodeRefState) }\n : {}),\n };\n }\n\n if (seen.has(value as object)) return '<cycle>';\n seen.add(value as object);\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n out[k] = serializeValue(v, depth + 1, seen, nodeRefState);\n }\n seen.delete(value as object);\n return out;\n }\n\n return String(value);\n}\n\nfunction extractUserErrorLine(error: unknown): number | undefined {\n if (typeof error === 'object' && error && '__tracecodeLine' in error) {\n const line = Number((error as { __tracecodeLine?: unknown }).__tracecodeLine);\n if (Number.isFinite(line)) return line;\n }\n\n const stack =\n typeof error === 'object' && error && 'stack' in error\n ? String((error as { stack?: unknown }).stack ?? '')\n : '';\n if (!stack) return undefined;\n const match = stack.match(/<anonymous>:(\\d+):\\d+/);\n if (!match) return undefined;\n const line = Number.parseInt(match[1], 10);\n return Number.isFinite(line) ? line : undefined;\n}\n\nfunction isPlainObjectRecord(value: unknown): value is Record<string, unknown> {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return false;\n return Object.prototype.toString.call(value) === '[object Object]';\n}\n\nfunction collectReferenceTargets(\n value: unknown,\n byId: Map<string, Record<string, unknown>>,\n seen: WeakSet<object>\n): void {\n if (value === null || value === undefined) return;\n if (typeof value !== 'object') return;\n if (seen.has(value)) return;\n seen.add(value);\n\n if (Array.isArray(value)) {\n for (const item of value) {\n collectReferenceTargets(item, byId, seen);\n }\n return;\n }\n\n if (!isPlainObjectRecord(value)) return;\n if (typeof value.__id__ === 'string' && value.__id__.length > 0 && !byId.has(value.__id__)) {\n byId.set(value.__id__, value);\n }\n\n for (const nested of Object.values(value)) {\n collectReferenceTargets(nested, byId, seen);\n }\n}\n\nfunction resolveReferenceGraph(\n value: unknown,\n byId: Map<string, Record<string, unknown>>,\n resolved: WeakMap<object, unknown>\n): unknown {\n if (value === null || value === undefined) return value;\n if (typeof value !== 'object') return value;\n\n if (resolved.has(value)) {\n return resolved.get(value);\n }\n\n if (Array.isArray(value)) {\n const out: unknown[] = [];\n resolved.set(value, out);\n for (const item of value) {\n out.push(resolveReferenceGraph(item, byId, resolved));\n }\n return out;\n }\n\n if (!isPlainObjectRecord(value)) {\n return value;\n }\n\n const keys = Object.keys(value);\n if (keys.length === 1 && typeof value.__ref__ === 'string') {\n const target = byId.get(value.__ref__);\n if (!target) return null;\n return resolveReferenceGraph(target, byId, resolved);\n }\n\n const out: Record<string, unknown> = {};\n resolved.set(value, out);\n for (const [key, nested] of Object.entries(value)) {\n out[key] = resolveReferenceGraph(nested, byId, resolved);\n }\n return out;\n}\n\nfunction normalizeInputs(inputs: Record<string, unknown>): Record<string, unknown> {\n if (!inputs || typeof inputs !== 'object' || Array.isArray(inputs)) return {};\n const byId = new Map<string, Record<string, unknown>>();\n collectReferenceTargets(inputs, byId, new WeakSet<object>());\n if (byId.size === 0) {\n return inputs;\n }\n const hydrated = resolveReferenceGraph(inputs, byId, new WeakMap<object, unknown>());\n if (!hydrated || typeof hydrated !== 'object' || Array.isArray(hydrated)) {\n return inputs;\n }\n return hydrated as Record<string, unknown>;\n}\n\ntype FunctionLikeNode =\n | import('typescript').FunctionDeclaration\n | import('typescript').FunctionExpression\n | import('typescript').ArrowFunction\n | import('typescript').MethodDeclaration;\n\nfunction collectSimpleParameterNames(\n ts: TypeScriptModule,\n functionLikeNode: FunctionLikeNode\n): string[] | null {\n const names: string[] = [];\n\n for (const parameter of functionLikeNode.parameters ?? []) {\n if (!ts.isIdentifier(parameter.name)) {\n return null;\n }\n if (parameter.name.text === 'this') {\n continue;\n }\n names.push(parameter.name.text);\n }\n\n return names;\n}\n\nfunction getPropertyNameText(ts: TypeScriptModule, name: import('typescript').PropertyName | undefined): string | null {\n if (!name) return null;\n if (ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNumericLiteral(name)) {\n return name.text;\n }\n return null;\n}\n\nfunction findFunctionLikeNode(\n ts: TypeScriptModule,\n sourceFile: import('typescript').SourceFile,\n functionName: string,\n executionStyle: RuntimeExecutionStyle\n): FunctionLikeNode | null {\n let found: FunctionLikeNode | null = null;\n\n const visit = (node: import('typescript').Node): void => {\n if (found) return;\n\n if (executionStyle === 'solution-method' && ts.isClassDeclaration(node) && node.name?.text === 'Solution') {\n for (const member of node.members) {\n if (found) break;\n\n if (ts.isMethodDeclaration(member) && getPropertyNameText(ts, member.name) === functionName) {\n found = member;\n break;\n }\n\n if (\n ts.isPropertyDeclaration(member) &&\n getPropertyNameText(ts, member.name) === functionName &&\n member.initializer &&\n (ts.isArrowFunction(member.initializer) || ts.isFunctionExpression(member.initializer))\n ) {\n found = member.initializer;\n break;\n }\n }\n return;\n }\n\n if (executionStyle === 'function') {\n if (ts.isFunctionDeclaration(node) && node.name?.text === functionName) {\n found = node;\n return;\n }\n\n if (\n ts.isVariableDeclaration(node) &&\n ts.isIdentifier(node.name) &&\n node.name.text === functionName &&\n node.initializer &&\n (ts.isArrowFunction(node.initializer) || ts.isFunctionExpression(node.initializer))\n ) {\n found = node.initializer;\n return;\n }\n }\n\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n return found;\n}\n\nasync function resolveOrderedInputKeys(\n code: string,\n functionName: string,\n inputs: Record<string, unknown>,\n executionStyle: RuntimeExecutionStyle\n): Promise<string[]> {\n const fallbackKeys = Object.keys(inputs);\n if (!functionName || executionStyle === 'ops-class' || fallbackKeys.length <= 1) {\n return fallbackKeys;\n }\n\n try {\n const ts = await getTypeScriptModule();\n const sourceFile = ts.createSourceFile('runtime-input.js', code, ts.ScriptTarget.ES2020, true, ts.ScriptKind.JS);\n const target = findFunctionLikeNode(ts, sourceFile, functionName, executionStyle);\n if (!target) {\n return fallbackKeys;\n }\n\n const parameterNames = collectSimpleParameterNames(ts, target);\n if (!parameterNames || parameterNames.length === 0) {\n return fallbackKeys;\n }\n\n const matchedKeys = parameterNames.filter((name) => Object.prototype.hasOwnProperty.call(inputs, name));\n if (matchedKeys.length === 0) {\n return fallbackKeys;\n }\n\n const extras = fallbackKeys.filter((key) => !matchedKeys.includes(key));\n return [...matchedKeys, ...extras];\n } catch {\n return fallbackKeys;\n }\n}\n\nfunction buildRunner(code: string, executionStyle: RuntimeExecutionStyle, argNames: string[]): DynamicRunner {\n if (executionStyle === 'function') {\n return new Function(\n 'console',\n '__functionName',\n ...argNames,\n `\"use strict\";\n${code}\nlet __target;\ntry {\n __target = eval(__functionName);\n} catch (_err) {\n __target = undefined;\n}\nif (typeof __target !== 'function') {\n throw new Error('Function \"' + __functionName + '\" not found');\n}\nreturn __target(${argNames.join(', ')});`\n ) as DynamicRunner;\n }\n\n if (executionStyle === 'solution-method') {\n return new Function(\n 'console',\n '__functionName',\n ...argNames,\n `\"use strict\";\n${code}\nif (typeof Solution !== 'function') {\n throw new Error('Class \"Solution\" not found');\n}\nconst __solver = new Solution();\nconst __method = __solver[__functionName];\nif (typeof __method !== 'function') {\n throw new Error('Method \"Solution.' + __functionName + '\" not found');\n}\nreturn __method.call(__solver, ${argNames.join(', ')});`\n ) as DynamicRunner;\n }\n\n if (executionStyle === 'ops-class') {\n return new Function(\n 'console',\n '__className',\n '__operations',\n '__arguments',\n `\"use strict\";\n${code}\nif (!Array.isArray(__operations) || !Array.isArray(__arguments)) {\n throw new Error('ops-class execution requires inputs.operations and inputs.arguments (or ops/args)');\n}\nif (__operations.length !== __arguments.length) {\n throw new Error('operations and arguments must have the same length');\n}\nlet __targetClass;\ntry {\n __targetClass = eval(__className);\n} catch (_err) {\n __targetClass = undefined;\n}\nif (typeof __targetClass !== 'function') {\n throw new Error('Class \"' + __className + '\" not found');\n}\nlet __instance = null;\nconst __out = [];\nfor (let __i = 0; __i < __operations.length; __i++) {\n const __op = __operations[__i];\n let __callArgs = __arguments[__i];\n if (__callArgs === null || __callArgs === undefined) {\n __callArgs = [];\n }\n if (!Array.isArray(__callArgs)) {\n __callArgs = [__callArgs];\n }\n if (__i === 0) {\n __instance = new __targetClass(...__callArgs);\n __out.push(null);\n continue;\n }\n if (!__instance || typeof __instance[__op] !== 'function') {\n throw new Error('Required method \"' + __op + '\" is not implemented on ' + (__className || 'target class'));\n }\n __out.push(__instance[__op](...__callArgs));\n}\nreturn __out;`\n ) as DynamicRunner;\n }\n\n throw new Error(`Execution style \"${executionStyle}\" is not supported for JavaScript runtime yet.`);\n}\n\nfunction getOpsClassInputs(inputs: Record<string, unknown>): {\n operations: unknown[] | null;\n argumentsList: unknown[] | null;\n} {\n const operations = Array.isArray(inputs.operations)\n ? inputs.operations\n : (Array.isArray(inputs.ops) ? inputs.ops : null);\n const argumentsList = Array.isArray(inputs.arguments)\n ? inputs.arguments\n : (Array.isArray(inputs.args) ? inputs.args : null);\n return { operations, argumentsList };\n}\n\nasync function transpileTypeScript(code: string): Promise<string> {\n const ts = await getTypeScriptModule();\n const transpileInput = withTypeScriptRuntimeDeclarations(code);\n const transpiled = ts.transpileModule(transpileInput, {\n compilerOptions: {\n target: ts.ScriptTarget.ES2020,\n module: ts.ModuleKind.None,\n strict: false,\n esModuleInterop: true,\n },\n reportDiagnostics: true,\n fileName: 'solution.ts',\n });\n\n const diagnostics = Array.isArray(transpiled.diagnostics) ? transpiled.diagnostics : [];\n const errors = diagnostics.filter((diag) => diag.category === ts.DiagnosticCategory.Error);\n if (errors.length > 0) {\n const first = errors[0];\n const messageText = ts.flattenDiagnosticMessageText(first.messageText, '\\n');\n let lineNumber: number | undefined;\n if (first.file && typeof first.start === 'number') {\n const position = first.file.getLineAndCharacterOfPosition(first.start);\n lineNumber = position.line + 1;\n }\n const error = new Error(\n lineNumber\n ? `TypeScript transpilation failed (line ${lineNumber}): ${messageText}`\n : `TypeScript transpilation failed: ${messageText}`\n );\n if (lineNumber) {\n (error as Error & { __tracecodeLine?: number }).__tracecodeLine = lineNumber;\n }\n throw error;\n }\n\n return transpiled.outputText;\n}\n\nexport async function executeJavaScriptCode(\n code: string,\n functionName: string,\n inputs: Record<string, unknown>,\n executionStyle: RuntimeExecutionStyle = 'function'\n): Promise<CodeExecutionResult> {\n const consoleOutput: string[] = [];\n const consoleProxy = createConsoleProxy(consoleOutput);\n const normalizedInputs = normalizeInputs(inputs);\n\n try {\n let output: unknown;\n\n if (executionStyle === 'ops-class') {\n const { operations, argumentsList } = getOpsClassInputs(normalizedInputs);\n const runner = buildRunner(code, executionStyle, []);\n output = await Promise.resolve(runner(consoleProxy, functionName, operations, argumentsList));\n } else {\n const inputKeys = await resolveOrderedInputKeys(code, functionName, normalizedInputs, executionStyle);\n const argNames = inputKeys.map((_, index) => `__arg${index}`);\n const argValues = inputKeys.map((key) => normalizedInputs[key]);\n const runner = buildRunner(code, executionStyle, argNames);\n output = await Promise.resolve(runner(consoleProxy, functionName, ...argValues));\n }\n\n return {\n success: true,\n output: serializeValue(output),\n consoleOutput,\n };\n } catch (error) {\n return {\n success: false,\n output: null,\n error: error instanceof Error ? error.message : String(error),\n errorLine: extractUserErrorLine(error),\n consoleOutput,\n };\n }\n}\n\nexport async function executeJavaScriptWithTracing(\n code: string,\n functionName: string | null,\n inputs: Record<string, unknown>,\n executionStyle: RuntimeExecutionStyle = 'function'\n): Promise<ExecutionResult> {\n const startedAt = performanceNow();\n const codeResult = await executeJavaScriptCode(code, functionName ?? '', inputs, executionStyle);\n const executionTimeMs = performanceNow() - startedAt;\n\n if (!codeResult.success) {\n return {\n success: false,\n error: codeResult.error,\n errorLine: codeResult.errorLine,\n trace: [],\n executionTimeMs,\n consoleOutput: codeResult.consoleOutput ?? [],\n lineEventCount: 0,\n traceStepCount: 0,\n };\n }\n\n return {\n success: true,\n output: codeResult.output,\n trace: [],\n executionTimeMs,\n consoleOutput: codeResult.consoleOutput ?? [],\n lineEventCount: 0,\n traceStepCount: 0,\n };\n}\n\nexport async function executeTypeScriptCode(\n code: string,\n functionName: string,\n inputs: Record<string, unknown>,\n executionStyle: RuntimeExecutionStyle = 'function'\n): Promise<CodeExecutionResult> {\n const transpiledCode = await transpileTypeScript(code);\n return executeJavaScriptCode(transpiledCode, functionName, inputs, executionStyle);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,kCAAkC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkCxC,SAAS,kCAAkC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"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { c as RuntimeExecutionStyle } from './runtime-types-Dvgn07z9.cjs';
|
|
2
|
+
import { a as CodeExecutionResult, E as ExecutionResult } from './types-Bzr1Ohcf.cjs';
|
|
3
|
+
|
|
4
|
+
declare function executeJavaScriptCode(code: string, functionName: string, inputs: Record<string, unknown>, executionStyle?: RuntimeExecutionStyle): Promise<CodeExecutionResult>;
|
|
5
|
+
declare function executeJavaScriptWithTracing(code: string, functionName: string | null, inputs: Record<string, unknown>, executionStyle?: RuntimeExecutionStyle): Promise<ExecutionResult>;
|
|
6
|
+
declare function executeTypeScriptCode(code: string, functionName: string, inputs: Record<string, unknown>, executionStyle?: RuntimeExecutionStyle): Promise<CodeExecutionResult>;
|
|
7
|
+
|
|
8
|
+
declare const TYPESCRIPT_RUNTIME_DECLARATIONS = "\ndeclare class ListNode {\n val: any;\n next: ListNode | SerializedListNode | SerializedRef | null;\n prev?: ListNode | SerializedListNode | SerializedRef | null;\n constructor(val?: any, next?: ListNode | null);\n}\n\ndeclare class TreeNode {\n val: any;\n left: TreeNode | SerializedTreeNode | SerializedRef | null;\n right: TreeNode | SerializedTreeNode | SerializedRef | null;\n constructor(val?: any, left?: TreeNode | null, right?: TreeNode | null);\n}\n\ntype SerializedRef = { __ref__: string };\n\ntype SerializedListNode = {\n __id__?: string;\n __type__?: 'ListNode';\n val?: any;\n next?: SerializedListNode | SerializedRef | ListNode | null;\n prev?: SerializedListNode | SerializedRef | ListNode | null;\n};\n\ntype SerializedTreeNode = {\n __id__?: string;\n __type__?: 'TreeNode';\n val?: any;\n left?: SerializedTreeNode | SerializedRef | TreeNode | null;\n right?: SerializedTreeNode | SerializedRef | TreeNode | null;\n};\n";
|
|
9
|
+
declare function withTypeScriptRuntimeDeclarations(sourceCode: string): string;
|
|
10
|
+
|
|
11
|
+
export { TYPESCRIPT_RUNTIME_DECLARATIONS, executeJavaScriptCode, executeJavaScriptWithTracing, executeTypeScriptCode, withTypeScriptRuntimeDeclarations };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { c as RuntimeExecutionStyle } from './runtime-types-C7d1LFbx.js';
|
|
2
|
+
import { a as CodeExecutionResult, E as ExecutionResult } from './types-Bzr1Ohcf.js';
|
|
3
|
+
|
|
4
|
+
declare function executeJavaScriptCode(code: string, functionName: string, inputs: Record<string, unknown>, executionStyle?: RuntimeExecutionStyle): Promise<CodeExecutionResult>;
|
|
5
|
+
declare function executeJavaScriptWithTracing(code: string, functionName: string | null, inputs: Record<string, unknown>, executionStyle?: RuntimeExecutionStyle): Promise<ExecutionResult>;
|
|
6
|
+
declare function executeTypeScriptCode(code: string, functionName: string, inputs: Record<string, unknown>, executionStyle?: RuntimeExecutionStyle): Promise<CodeExecutionResult>;
|
|
7
|
+
|
|
8
|
+
declare const TYPESCRIPT_RUNTIME_DECLARATIONS = "\ndeclare class ListNode {\n val: any;\n next: ListNode | SerializedListNode | SerializedRef | null;\n prev?: ListNode | SerializedListNode | SerializedRef | null;\n constructor(val?: any, next?: ListNode | null);\n}\n\ndeclare class TreeNode {\n val: any;\n left: TreeNode | SerializedTreeNode | SerializedRef | null;\n right: TreeNode | SerializedTreeNode | SerializedRef | null;\n constructor(val?: any, left?: TreeNode | null, right?: TreeNode | null);\n}\n\ntype SerializedRef = { __ref__: string };\n\ntype SerializedListNode = {\n __id__?: string;\n __type__?: 'ListNode';\n val?: any;\n next?: SerializedListNode | SerializedRef | ListNode | null;\n prev?: SerializedListNode | SerializedRef | ListNode | null;\n};\n\ntype SerializedTreeNode = {\n __id__?: string;\n __type__?: 'TreeNode';\n val?: any;\n left?: SerializedTreeNode | SerializedRef | TreeNode | null;\n right?: SerializedTreeNode | SerializedRef | TreeNode | null;\n};\n";
|
|
9
|
+
declare function withTypeScriptRuntimeDeclarations(sourceCode: string): string;
|
|
10
|
+
|
|
11
|
+
export { TYPESCRIPT_RUNTIME_DECLARATIONS, executeJavaScriptCode, executeJavaScriptWithTracing, executeTypeScriptCode, withTypeScriptRuntimeDeclarations };
|
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
// packages/harness-javascript/src/typescript-runtime-declarations.ts
|
|
2
|
+
var TYPESCRIPT_RUNTIME_DECLARATIONS = `
|
|
3
|
+
declare class ListNode {
|
|
4
|
+
val: any;
|
|
5
|
+
next: ListNode | SerializedListNode | SerializedRef | null;
|
|
6
|
+
prev?: ListNode | SerializedListNode | SerializedRef | null;
|
|
7
|
+
constructor(val?: any, next?: ListNode | null);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare class TreeNode {
|
|
11
|
+
val: any;
|
|
12
|
+
left: TreeNode | SerializedTreeNode | SerializedRef | null;
|
|
13
|
+
right: TreeNode | SerializedTreeNode | SerializedRef | null;
|
|
14
|
+
constructor(val?: any, left?: TreeNode | null, right?: TreeNode | null);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type SerializedRef = { __ref__: string };
|
|
18
|
+
|
|
19
|
+
type SerializedListNode = {
|
|
20
|
+
__id__?: string;
|
|
21
|
+
__type__?: 'ListNode';
|
|
22
|
+
val?: any;
|
|
23
|
+
next?: SerializedListNode | SerializedRef | ListNode | null;
|
|
24
|
+
prev?: SerializedListNode | SerializedRef | ListNode | null;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type SerializedTreeNode = {
|
|
28
|
+
__id__?: string;
|
|
29
|
+
__type__?: 'TreeNode';
|
|
30
|
+
val?: any;
|
|
31
|
+
left?: SerializedTreeNode | SerializedRef | TreeNode | null;
|
|
32
|
+
right?: SerializedTreeNode | SerializedRef | TreeNode | null;
|
|
33
|
+
};
|
|
34
|
+
`;
|
|
35
|
+
function withTypeScriptRuntimeDeclarations(sourceCode) {
|
|
36
|
+
return `${sourceCode}
|
|
37
|
+
|
|
38
|
+
${TYPESCRIPT_RUNTIME_DECLARATIONS}
|
|
39
|
+
`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// packages/harness-javascript/src/javascript-executor.ts
|
|
43
|
+
var typeScriptModulePromise = null;
|
|
44
|
+
async function getTypeScriptModule() {
|
|
45
|
+
if (!typeScriptModulePromise) {
|
|
46
|
+
const specifier = "typescript";
|
|
47
|
+
typeScriptModulePromise = import(
|
|
48
|
+
/* webpackIgnore: true */
|
|
49
|
+
specifier
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
return typeScriptModulePromise;
|
|
53
|
+
}
|
|
54
|
+
function performanceNow() {
|
|
55
|
+
if (typeof performance !== "undefined" && typeof performance.now === "function") {
|
|
56
|
+
return performance.now();
|
|
57
|
+
}
|
|
58
|
+
return Date.now();
|
|
59
|
+
}
|
|
60
|
+
function formatConsoleArg(value) {
|
|
61
|
+
if (typeof value === "string") return value;
|
|
62
|
+
if (typeof value === "number" || typeof value === "boolean" || value === null || value === void 0) {
|
|
63
|
+
return String(value);
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
return JSON.stringify(value);
|
|
67
|
+
} catch {
|
|
68
|
+
return String(value);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function createConsoleProxy(output) {
|
|
72
|
+
const capture = (...args) => {
|
|
73
|
+
output.push(args.map(formatConsoleArg).join(" "));
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
...console,
|
|
77
|
+
log: capture,
|
|
78
|
+
info: capture,
|
|
79
|
+
warn: capture,
|
|
80
|
+
error: capture,
|
|
81
|
+
debug: capture
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function isLikelyTreeNodeValue(value) {
|
|
85
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
86
|
+
const hasValue = "val" in value || "value" in value;
|
|
87
|
+
const hasTreeLinks = "left" in value || "right" in value;
|
|
88
|
+
return hasValue && hasTreeLinks;
|
|
89
|
+
}
|
|
90
|
+
function isLikelyListNodeValue(value) {
|
|
91
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
92
|
+
const hasValue = "val" in value || "value" in value;
|
|
93
|
+
const hasTreeLinks = "left" in value || "right" in value;
|
|
94
|
+
const hasListLinks = "next" in value || "prev" in value;
|
|
95
|
+
return hasValue && hasListLinks && !hasTreeLinks;
|
|
96
|
+
}
|
|
97
|
+
function serializeValue(value, depth = 0, seen = /* @__PURE__ */ new WeakSet(), nodeRefState = { ids: /* @__PURE__ */ new Map(), nextId: 1 }) {
|
|
98
|
+
if (depth > 48) return "<max depth>";
|
|
99
|
+
if (value === null || value === void 0) return value;
|
|
100
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
if (typeof value === "bigint") {
|
|
104
|
+
return Number.isSafeInteger(Number(value)) ? Number(value) : String(value);
|
|
105
|
+
}
|
|
106
|
+
if (typeof value === "function") {
|
|
107
|
+
return "<function>";
|
|
108
|
+
}
|
|
109
|
+
if (Array.isArray(value)) {
|
|
110
|
+
return value.map((item) => serializeValue(item, depth + 1, seen));
|
|
111
|
+
}
|
|
112
|
+
if (value instanceof Set) {
|
|
113
|
+
return {
|
|
114
|
+
__type__: "set",
|
|
115
|
+
values: [...value].map((item) => serializeValue(item, depth + 1, seen, nodeRefState))
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
if (value instanceof Map) {
|
|
119
|
+
return {
|
|
120
|
+
__type__: "map",
|
|
121
|
+
entries: [...value.entries()].map(([k, v]) => [
|
|
122
|
+
serializeValue(k, depth + 1, seen, nodeRefState),
|
|
123
|
+
serializeValue(v, depth + 1, seen, nodeRefState)
|
|
124
|
+
])
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
if (typeof value === "object") {
|
|
128
|
+
if (isLikelyTreeNodeValue(value) || isLikelyListNodeValue(value)) {
|
|
129
|
+
const objectValue = value;
|
|
130
|
+
const nodeValue = value;
|
|
131
|
+
const existingId = nodeRefState.ids.get(objectValue);
|
|
132
|
+
if (existingId) {
|
|
133
|
+
return { __ref__: existingId };
|
|
134
|
+
}
|
|
135
|
+
const isTree = isLikelyTreeNodeValue(value);
|
|
136
|
+
const nodePrefix = isTree ? "tree" : "list";
|
|
137
|
+
const nodeId = `${nodePrefix}-${nodeRefState.nextId++}`;
|
|
138
|
+
nodeRefState.ids.set(objectValue, nodeId);
|
|
139
|
+
if (isTree) {
|
|
140
|
+
return {
|
|
141
|
+
__type__: "TreeNode",
|
|
142
|
+
__id__: nodeId,
|
|
143
|
+
val: serializeValue(nodeValue.val ?? nodeValue.value ?? null, depth + 1, seen, nodeRefState),
|
|
144
|
+
left: serializeValue(nodeValue.left ?? null, depth + 1, seen, nodeRefState),
|
|
145
|
+
right: serializeValue(nodeValue.right ?? null, depth + 1, seen, nodeRefState)
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
__type__: "ListNode",
|
|
150
|
+
__id__: nodeId,
|
|
151
|
+
val: serializeValue(nodeValue.val ?? nodeValue.value ?? null, depth + 1, seen, nodeRefState),
|
|
152
|
+
next: serializeValue(nodeValue.next ?? null, depth + 1, seen, nodeRefState),
|
|
153
|
+
..."prev" in nodeValue ? { prev: serializeValue(nodeValue.prev ?? null, depth + 1, seen, nodeRefState) } : {}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
if (seen.has(value)) return "<cycle>";
|
|
157
|
+
seen.add(value);
|
|
158
|
+
const out = {};
|
|
159
|
+
for (const [k, v] of Object.entries(value)) {
|
|
160
|
+
out[k] = serializeValue(v, depth + 1, seen, nodeRefState);
|
|
161
|
+
}
|
|
162
|
+
seen.delete(value);
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
return String(value);
|
|
166
|
+
}
|
|
167
|
+
function extractUserErrorLine(error) {
|
|
168
|
+
if (typeof error === "object" && error && "__tracecodeLine" in error) {
|
|
169
|
+
const line2 = Number(error.__tracecodeLine);
|
|
170
|
+
if (Number.isFinite(line2)) return line2;
|
|
171
|
+
}
|
|
172
|
+
const stack = typeof error === "object" && error && "stack" in error ? String(error.stack ?? "") : "";
|
|
173
|
+
if (!stack) return void 0;
|
|
174
|
+
const match = stack.match(/<anonymous>:(\d+):\d+/);
|
|
175
|
+
if (!match) return void 0;
|
|
176
|
+
const line = Number.parseInt(match[1], 10);
|
|
177
|
+
return Number.isFinite(line) ? line : void 0;
|
|
178
|
+
}
|
|
179
|
+
function isPlainObjectRecord(value) {
|
|
180
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
181
|
+
return Object.prototype.toString.call(value) === "[object Object]";
|
|
182
|
+
}
|
|
183
|
+
function collectReferenceTargets(value, byId, seen) {
|
|
184
|
+
if (value === null || value === void 0) return;
|
|
185
|
+
if (typeof value !== "object") return;
|
|
186
|
+
if (seen.has(value)) return;
|
|
187
|
+
seen.add(value);
|
|
188
|
+
if (Array.isArray(value)) {
|
|
189
|
+
for (const item of value) {
|
|
190
|
+
collectReferenceTargets(item, byId, seen);
|
|
191
|
+
}
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (!isPlainObjectRecord(value)) return;
|
|
195
|
+
if (typeof value.__id__ === "string" && value.__id__.length > 0 && !byId.has(value.__id__)) {
|
|
196
|
+
byId.set(value.__id__, value);
|
|
197
|
+
}
|
|
198
|
+
for (const nested of Object.values(value)) {
|
|
199
|
+
collectReferenceTargets(nested, byId, seen);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function resolveReferenceGraph(value, byId, resolved) {
|
|
203
|
+
if (value === null || value === void 0) return value;
|
|
204
|
+
if (typeof value !== "object") return value;
|
|
205
|
+
if (resolved.has(value)) {
|
|
206
|
+
return resolved.get(value);
|
|
207
|
+
}
|
|
208
|
+
if (Array.isArray(value)) {
|
|
209
|
+
const out2 = [];
|
|
210
|
+
resolved.set(value, out2);
|
|
211
|
+
for (const item of value) {
|
|
212
|
+
out2.push(resolveReferenceGraph(item, byId, resolved));
|
|
213
|
+
}
|
|
214
|
+
return out2;
|
|
215
|
+
}
|
|
216
|
+
if (!isPlainObjectRecord(value)) {
|
|
217
|
+
return value;
|
|
218
|
+
}
|
|
219
|
+
const keys = Object.keys(value);
|
|
220
|
+
if (keys.length === 1 && typeof value.__ref__ === "string") {
|
|
221
|
+
const target = byId.get(value.__ref__);
|
|
222
|
+
if (!target) return null;
|
|
223
|
+
return resolveReferenceGraph(target, byId, resolved);
|
|
224
|
+
}
|
|
225
|
+
const out = {};
|
|
226
|
+
resolved.set(value, out);
|
|
227
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
228
|
+
out[key] = resolveReferenceGraph(nested, byId, resolved);
|
|
229
|
+
}
|
|
230
|
+
return out;
|
|
231
|
+
}
|
|
232
|
+
function normalizeInputs(inputs) {
|
|
233
|
+
if (!inputs || typeof inputs !== "object" || Array.isArray(inputs)) return {};
|
|
234
|
+
const byId = /* @__PURE__ */ new Map();
|
|
235
|
+
collectReferenceTargets(inputs, byId, /* @__PURE__ */ new WeakSet());
|
|
236
|
+
if (byId.size === 0) {
|
|
237
|
+
return inputs;
|
|
238
|
+
}
|
|
239
|
+
const hydrated = resolveReferenceGraph(inputs, byId, /* @__PURE__ */ new WeakMap());
|
|
240
|
+
if (!hydrated || typeof hydrated !== "object" || Array.isArray(hydrated)) {
|
|
241
|
+
return inputs;
|
|
242
|
+
}
|
|
243
|
+
return hydrated;
|
|
244
|
+
}
|
|
245
|
+
function collectSimpleParameterNames(ts, functionLikeNode) {
|
|
246
|
+
const names = [];
|
|
247
|
+
for (const parameter of functionLikeNode.parameters ?? []) {
|
|
248
|
+
if (!ts.isIdentifier(parameter.name)) {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
if (parameter.name.text === "this") {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
names.push(parameter.name.text);
|
|
255
|
+
}
|
|
256
|
+
return names;
|
|
257
|
+
}
|
|
258
|
+
function getPropertyNameText(ts, name) {
|
|
259
|
+
if (!name) return null;
|
|
260
|
+
if (ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNumericLiteral(name)) {
|
|
261
|
+
return name.text;
|
|
262
|
+
}
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
function findFunctionLikeNode(ts, sourceFile, functionName, executionStyle) {
|
|
266
|
+
let found = null;
|
|
267
|
+
const visit = (node) => {
|
|
268
|
+
if (found) return;
|
|
269
|
+
if (executionStyle === "solution-method" && ts.isClassDeclaration(node) && node.name?.text === "Solution") {
|
|
270
|
+
for (const member of node.members) {
|
|
271
|
+
if (found) break;
|
|
272
|
+
if (ts.isMethodDeclaration(member) && getPropertyNameText(ts, member.name) === functionName) {
|
|
273
|
+
found = member;
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
if (ts.isPropertyDeclaration(member) && getPropertyNameText(ts, member.name) === functionName && member.initializer && (ts.isArrowFunction(member.initializer) || ts.isFunctionExpression(member.initializer))) {
|
|
277
|
+
found = member.initializer;
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (executionStyle === "function") {
|
|
284
|
+
if (ts.isFunctionDeclaration(node) && node.name?.text === functionName) {
|
|
285
|
+
found = node;
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.name.text === functionName && node.initializer && (ts.isArrowFunction(node.initializer) || ts.isFunctionExpression(node.initializer))) {
|
|
289
|
+
found = node.initializer;
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
ts.forEachChild(node, visit);
|
|
294
|
+
};
|
|
295
|
+
visit(sourceFile);
|
|
296
|
+
return found;
|
|
297
|
+
}
|
|
298
|
+
async function resolveOrderedInputKeys(code, functionName, inputs, executionStyle) {
|
|
299
|
+
const fallbackKeys = Object.keys(inputs);
|
|
300
|
+
if (!functionName || executionStyle === "ops-class" || fallbackKeys.length <= 1) {
|
|
301
|
+
return fallbackKeys;
|
|
302
|
+
}
|
|
303
|
+
try {
|
|
304
|
+
const ts = await getTypeScriptModule();
|
|
305
|
+
const sourceFile = ts.createSourceFile("runtime-input.js", code, ts.ScriptTarget.ES2020, true, ts.ScriptKind.JS);
|
|
306
|
+
const target = findFunctionLikeNode(ts, sourceFile, functionName, executionStyle);
|
|
307
|
+
if (!target) {
|
|
308
|
+
return fallbackKeys;
|
|
309
|
+
}
|
|
310
|
+
const parameterNames = collectSimpleParameterNames(ts, target);
|
|
311
|
+
if (!parameterNames || parameterNames.length === 0) {
|
|
312
|
+
return fallbackKeys;
|
|
313
|
+
}
|
|
314
|
+
const matchedKeys = parameterNames.filter((name) => Object.prototype.hasOwnProperty.call(inputs, name));
|
|
315
|
+
if (matchedKeys.length === 0) {
|
|
316
|
+
return fallbackKeys;
|
|
317
|
+
}
|
|
318
|
+
const extras = fallbackKeys.filter((key) => !matchedKeys.includes(key));
|
|
319
|
+
return [...matchedKeys, ...extras];
|
|
320
|
+
} catch {
|
|
321
|
+
return fallbackKeys;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function buildRunner(code, executionStyle, argNames) {
|
|
325
|
+
if (executionStyle === "function") {
|
|
326
|
+
return new Function(
|
|
327
|
+
"console",
|
|
328
|
+
"__functionName",
|
|
329
|
+
...argNames,
|
|
330
|
+
`"use strict";
|
|
331
|
+
${code}
|
|
332
|
+
let __target;
|
|
333
|
+
try {
|
|
334
|
+
__target = eval(__functionName);
|
|
335
|
+
} catch (_err) {
|
|
336
|
+
__target = undefined;
|
|
337
|
+
}
|
|
338
|
+
if (typeof __target !== 'function') {
|
|
339
|
+
throw new Error('Function "' + __functionName + '" not found');
|
|
340
|
+
}
|
|
341
|
+
return __target(${argNames.join(", ")});`
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
if (executionStyle === "solution-method") {
|
|
345
|
+
return new Function(
|
|
346
|
+
"console",
|
|
347
|
+
"__functionName",
|
|
348
|
+
...argNames,
|
|
349
|
+
`"use strict";
|
|
350
|
+
${code}
|
|
351
|
+
if (typeof Solution !== 'function') {
|
|
352
|
+
throw new Error('Class "Solution" not found');
|
|
353
|
+
}
|
|
354
|
+
const __solver = new Solution();
|
|
355
|
+
const __method = __solver[__functionName];
|
|
356
|
+
if (typeof __method !== 'function') {
|
|
357
|
+
throw new Error('Method "Solution.' + __functionName + '" not found');
|
|
358
|
+
}
|
|
359
|
+
return __method.call(__solver, ${argNames.join(", ")});`
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
if (executionStyle === "ops-class") {
|
|
363
|
+
return new Function(
|
|
364
|
+
"console",
|
|
365
|
+
"__className",
|
|
366
|
+
"__operations",
|
|
367
|
+
"__arguments",
|
|
368
|
+
`"use strict";
|
|
369
|
+
${code}
|
|
370
|
+
if (!Array.isArray(__operations) || !Array.isArray(__arguments)) {
|
|
371
|
+
throw new Error('ops-class execution requires inputs.operations and inputs.arguments (or ops/args)');
|
|
372
|
+
}
|
|
373
|
+
if (__operations.length !== __arguments.length) {
|
|
374
|
+
throw new Error('operations and arguments must have the same length');
|
|
375
|
+
}
|
|
376
|
+
let __targetClass;
|
|
377
|
+
try {
|
|
378
|
+
__targetClass = eval(__className);
|
|
379
|
+
} catch (_err) {
|
|
380
|
+
__targetClass = undefined;
|
|
381
|
+
}
|
|
382
|
+
if (typeof __targetClass !== 'function') {
|
|
383
|
+
throw new Error('Class "' + __className + '" not found');
|
|
384
|
+
}
|
|
385
|
+
let __instance = null;
|
|
386
|
+
const __out = [];
|
|
387
|
+
for (let __i = 0; __i < __operations.length; __i++) {
|
|
388
|
+
const __op = __operations[__i];
|
|
389
|
+
let __callArgs = __arguments[__i];
|
|
390
|
+
if (__callArgs === null || __callArgs === undefined) {
|
|
391
|
+
__callArgs = [];
|
|
392
|
+
}
|
|
393
|
+
if (!Array.isArray(__callArgs)) {
|
|
394
|
+
__callArgs = [__callArgs];
|
|
395
|
+
}
|
|
396
|
+
if (__i === 0) {
|
|
397
|
+
__instance = new __targetClass(...__callArgs);
|
|
398
|
+
__out.push(null);
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
if (!__instance || typeof __instance[__op] !== 'function') {
|
|
402
|
+
throw new Error('Required method "' + __op + '" is not implemented on ' + (__className || 'target class'));
|
|
403
|
+
}
|
|
404
|
+
__out.push(__instance[__op](...__callArgs));
|
|
405
|
+
}
|
|
406
|
+
return __out;`
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
throw new Error(`Execution style "${executionStyle}" is not supported for JavaScript runtime yet.`);
|
|
410
|
+
}
|
|
411
|
+
function getOpsClassInputs(inputs) {
|
|
412
|
+
const operations = Array.isArray(inputs.operations) ? inputs.operations : Array.isArray(inputs.ops) ? inputs.ops : null;
|
|
413
|
+
const argumentsList = Array.isArray(inputs.arguments) ? inputs.arguments : Array.isArray(inputs.args) ? inputs.args : null;
|
|
414
|
+
return { operations, argumentsList };
|
|
415
|
+
}
|
|
416
|
+
async function transpileTypeScript(code) {
|
|
417
|
+
const ts = await getTypeScriptModule();
|
|
418
|
+
const transpileInput = withTypeScriptRuntimeDeclarations(code);
|
|
419
|
+
const transpiled = ts.transpileModule(transpileInput, {
|
|
420
|
+
compilerOptions: {
|
|
421
|
+
target: ts.ScriptTarget.ES2020,
|
|
422
|
+
module: ts.ModuleKind.None,
|
|
423
|
+
strict: false,
|
|
424
|
+
esModuleInterop: true
|
|
425
|
+
},
|
|
426
|
+
reportDiagnostics: true,
|
|
427
|
+
fileName: "solution.ts"
|
|
428
|
+
});
|
|
429
|
+
const diagnostics = Array.isArray(transpiled.diagnostics) ? transpiled.diagnostics : [];
|
|
430
|
+
const errors = diagnostics.filter((diag) => diag.category === ts.DiagnosticCategory.Error);
|
|
431
|
+
if (errors.length > 0) {
|
|
432
|
+
const first = errors[0];
|
|
433
|
+
const messageText = ts.flattenDiagnosticMessageText(first.messageText, "\n");
|
|
434
|
+
let lineNumber;
|
|
435
|
+
if (first.file && typeof first.start === "number") {
|
|
436
|
+
const position = first.file.getLineAndCharacterOfPosition(first.start);
|
|
437
|
+
lineNumber = position.line + 1;
|
|
438
|
+
}
|
|
439
|
+
const error = new Error(
|
|
440
|
+
lineNumber ? `TypeScript transpilation failed (line ${lineNumber}): ${messageText}` : `TypeScript transpilation failed: ${messageText}`
|
|
441
|
+
);
|
|
442
|
+
if (lineNumber) {
|
|
443
|
+
error.__tracecodeLine = lineNumber;
|
|
444
|
+
}
|
|
445
|
+
throw error;
|
|
446
|
+
}
|
|
447
|
+
return transpiled.outputText;
|
|
448
|
+
}
|
|
449
|
+
async function executeJavaScriptCode(code, functionName, inputs, executionStyle = "function") {
|
|
450
|
+
const consoleOutput = [];
|
|
451
|
+
const consoleProxy = createConsoleProxy(consoleOutput);
|
|
452
|
+
const normalizedInputs = normalizeInputs(inputs);
|
|
453
|
+
try {
|
|
454
|
+
let output;
|
|
455
|
+
if (executionStyle === "ops-class") {
|
|
456
|
+
const { operations, argumentsList } = getOpsClassInputs(normalizedInputs);
|
|
457
|
+
const runner = buildRunner(code, executionStyle, []);
|
|
458
|
+
output = await Promise.resolve(runner(consoleProxy, functionName, operations, argumentsList));
|
|
459
|
+
} else {
|
|
460
|
+
const inputKeys = await resolveOrderedInputKeys(code, functionName, normalizedInputs, executionStyle);
|
|
461
|
+
const argNames = inputKeys.map((_, index) => `__arg${index}`);
|
|
462
|
+
const argValues = inputKeys.map((key) => normalizedInputs[key]);
|
|
463
|
+
const runner = buildRunner(code, executionStyle, argNames);
|
|
464
|
+
output = await Promise.resolve(runner(consoleProxy, functionName, ...argValues));
|
|
465
|
+
}
|
|
466
|
+
return {
|
|
467
|
+
success: true,
|
|
468
|
+
output: serializeValue(output),
|
|
469
|
+
consoleOutput
|
|
470
|
+
};
|
|
471
|
+
} catch (error) {
|
|
472
|
+
return {
|
|
473
|
+
success: false,
|
|
474
|
+
output: null,
|
|
475
|
+
error: error instanceof Error ? error.message : String(error),
|
|
476
|
+
errorLine: extractUserErrorLine(error),
|
|
477
|
+
consoleOutput
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
async function executeJavaScriptWithTracing(code, functionName, inputs, executionStyle = "function") {
|
|
482
|
+
const startedAt = performanceNow();
|
|
483
|
+
const codeResult = await executeJavaScriptCode(code, functionName ?? "", inputs, executionStyle);
|
|
484
|
+
const executionTimeMs = performanceNow() - startedAt;
|
|
485
|
+
if (!codeResult.success) {
|
|
486
|
+
return {
|
|
487
|
+
success: false,
|
|
488
|
+
error: codeResult.error,
|
|
489
|
+
errorLine: codeResult.errorLine,
|
|
490
|
+
trace: [],
|
|
491
|
+
executionTimeMs,
|
|
492
|
+
consoleOutput: codeResult.consoleOutput ?? [],
|
|
493
|
+
lineEventCount: 0,
|
|
494
|
+
traceStepCount: 0
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
return {
|
|
498
|
+
success: true,
|
|
499
|
+
output: codeResult.output,
|
|
500
|
+
trace: [],
|
|
501
|
+
executionTimeMs,
|
|
502
|
+
consoleOutput: codeResult.consoleOutput ?? [],
|
|
503
|
+
lineEventCount: 0,
|
|
504
|
+
traceStepCount: 0
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
async function executeTypeScriptCode(code, functionName, inputs, executionStyle = "function") {
|
|
508
|
+
const transpiledCode = await transpileTypeScript(code);
|
|
509
|
+
return executeJavaScriptCode(transpiledCode, functionName, inputs, executionStyle);
|
|
510
|
+
}
|
|
511
|
+
export {
|
|
512
|
+
TYPESCRIPT_RUNTIME_DECLARATIONS,
|
|
513
|
+
executeJavaScriptCode,
|
|
514
|
+
executeJavaScriptWithTracing,
|
|
515
|
+
executeTypeScriptCode,
|
|
516
|
+
withTypeScriptRuntimeDeclarations
|
|
517
|
+
};
|
|
518
|
+
//# sourceMappingURL=javascript.js.map
|