{"version":3,"file":"global_state.mjs","names":[],"sources":["../../../src/expression/definitions/global_state.ts"],"sourcesContent":["import {Type, ValueType} from '../types';\nimport type {Expression} from '../expression';\nimport {ParsingContext} from '../parsing_context';\nimport {EvaluationContext} from '../evaluation_context';\nimport {getOwn} from '../../util/get_own';\n\nexport class GlobalState implements Expression {\n    type: Type = ValueType;\n\n    constructor(public readonly key: string) {}\n\n    static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Expression {\n        if (args.length !== 2) {\n            return context.error(\n                `Expected 1 argument, but found ${args.length - 1} instead.`\n            ) as null;\n        }\n\n        const key = args[1];\n\n        if (key === undefined || key === null) {\n            return context.error('Global state property must be defined.') as null;\n        }\n\n        if (typeof key !== 'string') {\n            return context.error(\n                `Global state property must be string, but found ${typeof args[1]} instead.`\n            ) as null;\n        }\n\n        return new GlobalState(key);\n    }\n\n    evaluate(ctx: EvaluationContext) {\n        const globalState = ctx.globals?.globalState;\n\n        if (!globalState || Object.keys(globalState).length === 0) return null;\n\n        return getOwn(globalState, this.key) ?? null;\n    }\n\n    eachChild() {}\n\n    outputDefined() {\n        return false;\n    }\n}\n"],"mappings":";;;AAMA,IAAa,cAAb,MAAa,YAAkC;CAG3C,YAAY,KAA6B;EAAb,KAAA,MAAA;EAFf,KAAA,OAAA;CAE6B;CAE1C,OAAO,MAAM,MAA8B,SAAqC;EAC5E,IAAI,KAAK,WAAW,GAChB,OAAO,QAAQ,MACX,kCAAkC,KAAK,SAAS,EAAE,UACtD;EAGJ,MAAM,MAAM,KAAK;EAEjB,IAAI,QAAQ,KAAA,KAAa,QAAQ,MAC7B,OAAO,QAAQ,MAAM,wCAAwC;EAGjE,IAAI,OAAO,QAAQ,UACf,OAAO,QAAQ,MACX,mDAAmD,OAAO,KAAK,GAAG,UACtE;EAGJ,OAAO,IAAI,YAAY,GAAG;CAC9B;CAEA,SAAS,KAAwB;EAC7B,MAAM,cAAc,IAAI,SAAS;EAEjC,IAAI,CAAC,eAAe,OAAO,KAAK,WAAW,CAAC,CAAC,WAAW,GAAG,OAAO;EAElE,OAAO,OAAO,aAAa,KAAK,GAAG,KAAK;CAC5C;CAEA,YAAY,CAAC;CAEb,gBAAgB;EACZ,OAAO;CACX;AACJ"}