Skip to content

Commit c3d73c2

Browse files
committed
fix: Update Compiler class to use object type for context parameter
The Compiler class in compiler.ts has been updated to use the object type for the context parameter in the compile method. This ensures that the context parameter is always an object, even if it is not provided or is not of type object. This change improves the type safety and reliability of the code.
1 parent f7c1580 commit c3d73c2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

packages/util/src/compiler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { randomUUID } from 'crypto';
1010
class Compiler {
1111

1212
@cache({ unwrapPromise: true })
13-
public compile(code: string, options?: { mode: 'vm' | 'sandbox' }) : (context?: any, contextMutable?: boolean) => any {
13+
public compile(code: string, options?: { mode: 'vm' | 'sandbox' }) : (context?: object, contextMutable?: boolean) => any {
1414
let compiledFn : (context: any) => any;
1515
if (options?.mode === 'sandbox') {
1616
// eslint-disable-next-line @typescript-eslint/no-implied-eval
@@ -31,7 +31,7 @@ class Compiler {
3131

3232
return function (context?: any, contextMutable?: boolean): any {
3333
const sandboxValues = {};
34-
const sandboxContext = new Proxy(context, {
34+
const sandboxContext = new Proxy(typeof context === 'object' ? context : {}, {
3535
get(target, prop) {
3636
return sandboxValues[prop] ?? target[prop];
3737
},

0 commit comments

Comments
 (0)