Skip to content

Commit 2441447

Browse files
committed
Fixes microsoft#106524: Normalize AND expressions with a single operand
1 parent 30143ab commit 2441447

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/vs/platform/contextkey/common/contextkey.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,10 @@ export class ContextKeyAndExpr implements IContextKeyExpression {
884884
}
885885
}
886886

887+
if (expr.length === 1) {
888+
return expr[0];
889+
}
890+
887891
return new ContextKeyAndExpr(expr);
888892
}
889893

src/vs/platform/contextkey/test/common/contextkey.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,25 @@ suite('ContextKeyExpr', () => {
165165
assert.equal(ainb.evaluate(createContext({ 'a': 'x', 'b': { 'x': true } })), true);
166166
assert.equal(ainb.evaluate(createContext({ 'a': 'prototype', 'b': {} })), false);
167167
});
168+
169+
test('issue #106524: distributing AND should normalize', () => {
170+
const actual = ContextKeyExpr.and(
171+
ContextKeyExpr.or(
172+
ContextKeyExpr.has('a'),
173+
ContextKeyExpr.has('b')
174+
),
175+
ContextKeyExpr.has('c')
176+
);
177+
const expected = ContextKeyExpr.or(
178+
ContextKeyExpr.and(
179+
ContextKeyExpr.has('a'),
180+
ContextKeyExpr.has('c')
181+
),
182+
ContextKeyExpr.and(
183+
ContextKeyExpr.has('b'),
184+
ContextKeyExpr.has('c')
185+
)
186+
);
187+
assert.equal(actual!.equals(expected!), true);
188+
});
168189
});

0 commit comments

Comments
 (0)