| 715 | } |
| 716 | |
| 717 | export class ContextKeyLessOrEqualsExpr implements IContextKeyExpression { |
| 718 | |
| 719 | public static create(key: string, value: any): ContextKeyExpression { |
| 720 | if (typeof value === 'boolean') { |
| 721 | return (value ? ContextKeyDefinedExpr.create(key) : ContextKeyNotExpr.create(key)); |
| 722 | } |
| 723 | const staticValue = STATIC_VALUES.get(key); |
| 724 | if (typeof staticValue === 'boolean') { |
| 725 | const trueValue = staticValue ? 'true' : 'false'; |
| 726 | return (value === trueValue ? ContextKeyTrueExpr.INSTANCE : ContextKeyFalseExpr.INSTANCE); |
| 727 | } |
| 728 | return new ContextKeyLessOrEqualsExpr(key, value); |
| 729 | } |
| 730 | |
| 731 | public readonly type = ContextKeyExprType.LessOrEquals; |
| 732 | |
| 733 | private constructor(private readonly key: string, private readonly value: any) { |
| 734 | } |
| 735 | |
| 736 | public cmp(other: ContextKeyExpression): number { |
| 737 | if (other.type !== this.type) { |
| 738 | return this.type - other.type; |
| 739 | } |
| 740 | if (this.key < other.key) { |
| 741 | return -1; |
| 742 | } |
| 743 | if (this.key > other.key) { |
| 744 | return 1; |
| 745 | } |
| 746 | if (this.value < other.value) { |
| 747 | return -1; |
| 748 | } |
| 749 | if (this.value > other.value) { |
| 750 | return 1; |
| 751 | } |
| 752 | return 0; |
| 753 | } |
| 754 | |
| 755 | public equals(other: ContextKeyExpression): boolean { |
| 756 | if (other.type === this.type) { |
| 757 | return (this.key === other.key && this.value === other.value); |
| 758 | } |
| 759 | return false; |
| 760 | } |
| 761 | |
| 762 | public evaluate(context: IContext): boolean { |
| 763 | // Intentional == |
| 764 | // eslint-disable-next-line eqeqeq |
| 765 | return (Number(context.getValue(this.key)) <= this.value); |
| 766 | } |
| 767 | |
| 768 | public serialize(): string { |
| 769 | return this.key + ' == \'' + this.value + '\''; |
| 770 | } |
| 771 | |
| 772 | public keys(): string[] { |
| 773 | return [this.key]; |
| 774 | } |
nothing calls this directly
no outgoing calls
no test coverage detected