globals, not global functions

This commit is contained in:
Chris Wanstrath 2025-10-28 13:07:59 -07:00
parent 20e2dd3b31
commit 7a4affd01e

View File

@ -33,7 +33,7 @@ declare module 'bun:test' {
toMatchTree(expected: string): T toMatchTree(expected: string): T
toMatchExpression(expected: string): T toMatchExpression(expected: string): T
toFailParse(): T toFailParse(): T
toEvaluateTo(expected: unknown, nativeFunctions?: Record<string, Function>): Promise<T> toEvaluateTo(expected: unknown, globals?: Record<string, any>): Promise<T>
toFailEvaluation(): Promise<T> toFailEvaluation(): Promise<T>
} }
} }
@ -96,13 +96,13 @@ expect.extend({
async toEvaluateTo( async toEvaluateTo(
received: unknown, received: unknown,
expected: unknown, expected: unknown,
nativeFunctions: Record<string, Function> = {} globals: Record<string, any> = {}
) { ) {
assert(typeof received === 'string', 'toEvaluateTo can only be used with string values') assert(typeof received === 'string', 'toEvaluateTo can only be used with string values')
try { try {
const compiler = new Compiler(received) const compiler = new Compiler(received)
const result = await run(compiler.bytecode, nativeFunctions) const result = await run(compiler.bytecode, globals)
let value = VMResultToValue(result) let value = VMResultToValue(result)
// Just treat regex as strings for comparison purposes // Just treat regex as strings for comparison purposes