globals accepts {} too

This commit is contained in:
Chris Wanstrath 2025-11-07 21:05:42 -08:00
parent 4258503c0e
commit bae0da31c2
2 changed files with 4 additions and 4 deletions

View File

@ -58,9 +58,9 @@ export class Compiler {
bytecode: Bytecode bytecode: Bytecode
pipeCounter = 0 pipeCounter = 0
constructor(public input: string, globals?: string[]) { constructor(public input: string, globals?: string[] | Record<string, any>) {
try { try {
if (globals) setGlobals(globals) if (globals) setGlobals(Array.isArray(globals) ? globals : Object.keys(globals))
const cst = parser.parse(input) const cst = parser.parse(input)
const errors = checkTreeForErrors(cst) const errors = checkTreeForErrors(cst)

View File

@ -8,9 +8,9 @@ export function specializeKeyword(ident: string) {
// tell the dotGet searcher about builtin globals // tell the dotGet searcher about builtin globals
export const globals: string[] = [] export const globals: string[] = []
export const setGlobals = (newGlobals: string[]) => { export const setGlobals = (newGlobals: string[] | Record<string, any>) => {
globals.length = 0 globals.length = 0
globals.push(...newGlobals) globals.push(...(Array.isArray(newGlobals) ? newGlobals : Object.keys(newGlobals)))
} }
// The only chars that can't be words are whitespace, apostrophes, closing parens, and EOF. // The only chars that can't be words are whitespace, apostrophes, closing parens, and EOF.