Skip to content

Commit

Permalink
fix: Update Compiler class to use object type for context parameter
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Codeneos committed Aug 7, 2024
1 parent f7c1580 commit c3d73c2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/util/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { randomUUID } from 'crypto';
class Compiler {

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

return function (context?: any, contextMutable?: boolean): any {
const sandboxValues = {};
const sandboxContext = new Proxy(context, {
const sandboxContext = new Proxy(typeof context === 'object' ? context : {}, {
get(target, prop) {
return sandboxValues[prop] ?? target[prop];
},
Expand Down

0 comments on commit c3d73c2

Please sign in to comment.