narrow type

This commit is contained in:
Chris Wanstrath 2025-10-26 12:29:14 -07:00
parent f1367b64ef
commit 36fe676495

View File

@ -3,7 +3,7 @@ import { parser } from '#parser/shrimp'
import { $ } from 'bun'
import { assert, errorMessage } from '#utils/utils'
import { Compiler } from '#compiler/compiler'
import { run, VM } from 'reefvm'
import { run, VM, type TypeScriptFunction } from 'reefvm'
import { treeToString, VMResultToValue } from '#utils/tree'
const regenerateParser = async () => {
@ -33,7 +33,7 @@ declare module 'bun:test' {
toMatchTree(expected: string): T
toMatchExpression(expected: string): T
toFailParse(): T
toEvaluateTo(expected: unknown, nativeFunctions?: Record<string, Function>): Promise<T>
toEvaluateTo(expected: unknown, globalFunctions?: Record<string, TypeScriptFunction>): Promise<T>
toFailEvaluation(): Promise<T>
}
}
@ -96,13 +96,13 @@ expect.extend({
async toEvaluateTo(
received: unknown,
expected: unknown,
nativeFunctions: Record<string, Function> = {}
globalFunctions: Record<string, TypeScriptFunction> = {}
) {
assert(typeof received === 'string', 'toEvaluateTo can only be used with string values')
try {
const compiler = new Compiler(received)
const result = await run(compiler.bytecode, nativeFunctions)
const result = await run(compiler.bytecode, globalFunctions)
let value = VMResultToValue(result)
// Just treat regex as strings for comparison purposes