{"version":3,"file":"collator.mjs","names":[],"sources":["../../../src/expression/definitions/collator.ts"],"sourcesContent":["import {StringType, BooleanType, CollatorType} from '../types';\nimport {Collator} from '../types/collator';\n\nimport type {Expression} from '../expression';\nimport type {EvaluationContext} from '../evaluation_context';\nimport type {ParsingContext} from '../parsing_context';\nimport type {Type} from '../types';\n\nexport class CollatorExpression implements Expression {\n    type: Type;\n    caseSensitive: Expression;\n    diacriticSensitive: Expression;\n    locale: Expression | null;\n\n    constructor(\n        caseSensitive: Expression,\n        diacriticSensitive: Expression,\n        locale: Expression | null\n    ) {\n        this.type = CollatorType;\n        this.locale = locale;\n        this.caseSensitive = caseSensitive;\n        this.diacriticSensitive = diacriticSensitive;\n    }\n\n    static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Expression {\n        if (args.length !== 2) return context.error('Expected one argument.') as null;\n\n        const options = args[1] as any;\n        if (typeof options !== 'object' || Array.isArray(options))\n            return context.error('Collator options argument must be an object.') as null;\n\n        const caseSensitive = context.parse(\n            options['case-sensitive'] === undefined ? false : options['case-sensitive'],\n            1,\n            BooleanType\n        );\n        if (!caseSensitive) return null;\n\n        const diacriticSensitive = context.parse(\n            options['diacritic-sensitive'] === undefined ? false : options['diacritic-sensitive'],\n            1,\n            BooleanType\n        );\n        if (!diacriticSensitive) return null;\n\n        let locale = null;\n        if (options['locale']) {\n            locale = context.parse(options['locale'], 1, StringType);\n            if (!locale) return null;\n        }\n\n        return new CollatorExpression(caseSensitive, diacriticSensitive, locale);\n    }\n\n    evaluate(ctx: EvaluationContext) {\n        return new Collator(\n            this.caseSensitive.evaluate(ctx),\n            this.diacriticSensitive.evaluate(ctx),\n            this.locale ? this.locale.evaluate(ctx) : null\n        );\n    }\n\n    eachChild(fn: (_: Expression) => void) {\n        fn(this.caseSensitive);\n        fn(this.diacriticSensitive);\n        if (this.locale) {\n            fn(this.locale);\n        }\n    }\n\n    outputDefined() {\n        // Technically the set of possible outputs is the combinatoric set of Collators produced\n        // by all possible outputs of locale/caseSensitive/diacriticSensitive\n        // But for the primary use of Collators in comparison operators, we ignore the Collator's\n        // possible outputs anyway, so we can get away with leaving this false for now.\n        return false;\n    }\n}\n"],"mappings":";;;AAQA,IAAa,qBAAb,MAAa,mBAAyC;CAMlD,YACI,eACA,oBACA,QACF;EACE,KAAK,OAAO;EACZ,KAAK,SAAS;EACd,KAAK,gBAAgB;EACrB,KAAK,qBAAqB;CAC9B;CAEA,OAAO,MAAM,MAA8B,SAAqC;EAC5E,IAAI,KAAK,WAAW,GAAG,OAAO,QAAQ,MAAM,wBAAwB;EAEpE,MAAM,UAAU,KAAK;EACrB,IAAI,OAAO,YAAY,YAAY,MAAM,QAAQ,OAAO,GACpD,OAAO,QAAQ,MAAM,8CAA8C;EAEvE,MAAM,gBAAgB,QAAQ,MAC1B,QAAQ,sBAAsB,KAAA,IAAY,QAAQ,QAAQ,mBAC1D,GACA,WACJ;EACA,IAAI,CAAC,eAAe,OAAO;EAE3B,MAAM,qBAAqB,QAAQ,MAC/B,QAAQ,2BAA2B,KAAA,IAAY,QAAQ,QAAQ,wBAC/D,GACA,WACJ;EACA,IAAI,CAAC,oBAAoB,OAAO;EAEhC,IAAI,SAAS;EACb,IAAI,QAAQ,WAAW;GACnB,SAAS,QAAQ,MAAM,QAAQ,WAAW,GAAG,UAAU;GACvD,IAAI,CAAC,QAAQ,OAAO;EACxB;EAEA,OAAO,IAAI,mBAAmB,eAAe,oBAAoB,MAAM;CAC3E;CAEA,SAAS,KAAwB;EAC7B,OAAO,IAAI,SACP,KAAK,cAAc,SAAS,GAAG,GAC/B,KAAK,mBAAmB,SAAS,GAAG,GACpC,KAAK,SAAS,KAAK,OAAO,SAAS,GAAG,IAAI,IAC9C;CACJ;CAEA,UAAU,IAA6B;EACnC,GAAG,KAAK,aAAa;EACrB,GAAG,KAAK,kBAAkB;EAC1B,IAAI,KAAK,QACL,GAAG,KAAK,MAAM;CAEtB;CAEA,gBAAgB;EAKZ,OAAO;CACX;AACJ"}