提交 8d24d8a6 编写于 作者: J Johannes Rieken

support ignore-case-flag for the regexp context key, #42605

上级 ce745369
......@@ -112,8 +112,9 @@ export abstract class ContextKeyExpr {
}
let value = serializedValue.slice(start + 1, end);
let caseIgnoreFlag = serializedValue[end + 1] === 'i' ? 'i' : '';
try {
return new RegExp(value);
return new RegExp(value, caseIgnoreFlag);
} catch (e) {
console.warn(`bad regexp-value '${serializedValue}', parse error: ${e}`);
return null;
......@@ -400,7 +401,7 @@ export class ContextKeyRegexExpr implements ContextKeyExpr {
}
public serialize(): string {
return `${this.key} =~ /${this.regexp ? this.regexp.source : '<invalid>'}/`;
return `${this.key} =~ /${this.regexp ? this.regexp.source : '<invalid>'}/${this.regexp.ignoreCase ? 'i' : ''}`;
}
public keys(): string[] {
......
......@@ -81,6 +81,7 @@ suite('ContextKeyExpr', () => {
testExpression(expr + ' != 5', value != <any>'5');
testExpression('!' + expr, !value);
testExpression(expr + ' =~ /d.*/', /d.*/.test(value));
testExpression(expr + ' =~ /D/i', /D/i.test(value));
}
testBatch('a', true);
......@@ -92,7 +93,7 @@ suite('ContextKeyExpr', () => {
testExpression('a && !b', true && !false);
testExpression('a && b', true && false);
testExpression('a && !b && c == 5', true && !false && '5' == '5');
testExpression('dddd =~ d.*', false);
testExpression('d =~ /e.*/', false);
/* tslint:enable:triple-equals */
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册