Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
41b414c2
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
41b414c2
编写于
10月 28, 2021
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes #134942: When parsing comparison expressions, try to parse the value as numbers
上级
fcca3787
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
63 addition
and
30 deletion
+63
-30
src/vs/platform/contextkey/common/contextkey.ts
src/vs/platform/contextkey/common/contextkey.ts
+49
-29
src/vs/platform/contextkey/test/common/contextkey.test.ts
src/vs/platform/contextkey/test/common/contextkey.test.ts
+14
-1
未找到文件。
src/vs/platform/contextkey/common/contextkey.ts
浏览文件 @
41b414c2
...
...
@@ -81,50 +81,45 @@ export abstract class ContextKeyExpr {
public
static
false
():
ContextKeyExpression
{
return
ContextKeyFalseExpr
.
INSTANCE
;
}
public
static
true
():
ContextKeyExpression
{
return
ContextKeyTrueExpr
.
INSTANCE
;
}
public
static
has
(
key
:
string
):
ContextKeyExpression
{
return
ContextKeyDefinedExpr
.
create
(
key
);
}
public
static
equals
(
key
:
string
,
value
:
any
):
ContextKeyExpression
{
return
ContextKeyEqualsExpr
.
create
(
key
,
value
);
}
public
static
notEquals
(
key
:
string
,
value
:
any
):
ContextKeyExpression
{
return
ContextKeyNotEqualsExpr
.
create
(
key
,
value
);
}
public
static
regex
(
key
:
string
,
value
:
RegExp
):
ContextKeyExpression
{
return
ContextKeyRegexExpr
.
create
(
key
,
value
);
}
public
static
in
(
key
:
string
,
value
:
string
):
ContextKeyExpression
{
return
ContextKeyInExpr
.
create
(
key
,
value
);
}
public
static
not
(
key
:
string
):
ContextKeyExpression
{
return
ContextKeyNotExpr
.
create
(
key
);
}
public
static
and
(...
expr
:
Array
<
ContextKeyExpression
|
undefined
|
null
>
):
ContextKeyExpression
|
undefined
{
return
ContextKeyAndExpr
.
create
(
expr
,
null
);
}
public
static
or
(...
expr
:
Array
<
ContextKeyExpression
|
undefined
|
null
>
):
ContextKeyExpression
|
undefined
{
return
ContextKeyOrExpr
.
create
(
expr
,
null
,
true
);
}
public
static
greater
(
key
:
string
,
value
:
any
):
ContextKeyExpression
{
public
static
greater
(
key
:
string
,
value
:
number
):
ContextKeyExpression
{
return
ContextKeyGreaterExpr
.
create
(
key
,
value
);
}
public
static
less
(
key
:
string
,
value
:
any
):
ContextKeyExpression
{
public
static
greaterEquals
(
key
:
string
,
value
:
number
):
ContextKeyExpression
{
return
ContextKeyGreaterEqualsExpr
.
create
(
key
,
value
);
}
public
static
smaller
(
key
:
string
,
value
:
number
):
ContextKeyExpression
{
return
ContextKeySmallerExpr
.
create
(
key
,
value
);
}
public
static
smallerEquals
(
key
:
string
,
value
:
number
):
ContextKeyExpression
{
return
ContextKeySmallerEqualsExpr
.
create
(
key
,
value
);
}
public
static
deserialize
(
serialized
:
string
|
null
|
undefined
,
strict
:
boolean
=
false
):
ContextKeyExpression
|
undefined
{
if
(
!
serialized
)
{
...
...
@@ -741,17 +736,30 @@ export class ContextKeyNotExpr implements IContextKeyExpression {
}
}
function
withFloatOrStr
<
T
extends
ContextKeyExpression
>
(
value
:
any
,
callback
:
(
value
:
number
|
string
)
=>
T
):
T
|
ContextKeyFalseExpr
{
if
(
typeof
value
===
'
string
'
)
{
const
n
=
parseFloat
(
value
);
if
(
!
isNaN
(
n
))
{
value
=
n
;
}
}
if
(
typeof
value
===
'
string
'
||
typeof
value
===
'
number
'
)
{
return
callback
(
value
);
}
return
ContextKeyFalseExpr
.
INSTANCE
;
}
export
class
ContextKeyGreaterExpr
implements
IContextKeyExpression
{
public
static
create
(
key
:
string
,
value
:
any
,
negated
:
ContextKeyExpression
|
null
=
null
):
ContextKeyExpression
{
return
new
ContextKeyGreaterExpr
(
key
,
value
,
negated
);
public
static
create
(
key
:
string
,
_
value
:
any
,
negated
:
ContextKeyExpression
|
null
=
null
):
ContextKeyExpression
{
return
withFloatOrStr
(
_value
,
(
value
)
=>
new
ContextKeyGreaterExpr
(
key
,
value
,
negated
)
);
}
public
readonly
type
=
ContextKeyExprType
.
Greater
;
private
constructor
(
private
readonly
key
:
string
,
private
readonly
value
:
any
,
private
readonly
value
:
number
|
string
,
private
negated
:
ContextKeyExpression
|
null
)
{
}
...
...
@@ -774,7 +782,10 @@ export class ContextKeyGreaterExpr implements IContextKeyExpression {
}
public
evaluate
(
context
:
IContext
):
boolean
{
return
(
parseFloat
(
<
any
>
context
.
getValue
(
this
.
key
))
>
parseFloat
(
this
.
value
));
if
(
typeof
this
.
value
===
'
string
'
)
{
return
false
;
}
return
(
parseFloat
(
<
any
>
context
.
getValue
(
this
.
key
))
>
this
.
value
);
}
public
serialize
():
string
{
...
...
@@ -799,15 +810,15 @@ export class ContextKeyGreaterExpr implements IContextKeyExpression {
export
class
ContextKeyGreaterEqualsExpr
implements
IContextKeyExpression
{
public
static
create
(
key
:
string
,
value
:
any
,
negated
:
ContextKeyExpression
|
null
=
null
):
ContextKeyExpression
{
return
new
ContextKeyGreaterEqualsExpr
(
key
,
value
,
negated
);
public
static
create
(
key
:
string
,
_
value
:
any
,
negated
:
ContextKeyExpression
|
null
=
null
):
ContextKeyExpression
{
return
withFloatOrStr
(
_value
,
(
value
)
=>
new
ContextKeyGreaterEqualsExpr
(
key
,
value
,
negated
)
);
}
public
readonly
type
=
ContextKeyExprType
.
GreaterEquals
;
private
constructor
(
private
readonly
key
:
string
,
private
readonly
value
:
any
,
private
readonly
value
:
number
|
string
,
private
negated
:
ContextKeyExpression
|
null
)
{
}
...
...
@@ -830,7 +841,10 @@ export class ContextKeyGreaterEqualsExpr implements IContextKeyExpression {
}
public
evaluate
(
context
:
IContext
):
boolean
{
return
(
parseFloat
(
<
any
>
context
.
getValue
(
this
.
key
))
>=
parseFloat
(
this
.
value
));
if
(
typeof
this
.
value
===
'
string
'
)
{
return
false
;
}
return
(
parseFloat
(
<
any
>
context
.
getValue
(
this
.
key
))
>=
this
.
value
);
}
public
serialize
():
string
{
...
...
@@ -855,15 +869,15 @@ export class ContextKeyGreaterEqualsExpr implements IContextKeyExpression {
export
class
ContextKeySmallerExpr
implements
IContextKeyExpression
{
public
static
create
(
key
:
string
,
value
:
any
,
negated
:
ContextKeyExpression
|
null
=
null
):
ContextKeyExpression
{
return
new
ContextKeySmallerExpr
(
key
,
value
,
negated
);
public
static
create
(
key
:
string
,
_
value
:
any
,
negated
:
ContextKeyExpression
|
null
=
null
):
ContextKeyExpression
{
return
withFloatOrStr
(
_value
,
(
value
)
=>
new
ContextKeySmallerExpr
(
key
,
value
,
negated
)
);
}
public
readonly
type
=
ContextKeyExprType
.
Smaller
;
private
constructor
(
private
readonly
key
:
string
,
private
readonly
value
:
any
,
private
readonly
value
:
number
|
string
,
private
negated
:
ContextKeyExpression
|
null
)
{
}
...
...
@@ -887,7 +901,10 @@ export class ContextKeySmallerExpr implements IContextKeyExpression {
}
public
evaluate
(
context
:
IContext
):
boolean
{
return
(
parseFloat
(
<
any
>
context
.
getValue
(
this
.
key
))
<
parseFloat
(
this
.
value
));
if
(
typeof
this
.
value
===
'
string
'
)
{
return
false
;
}
return
(
parseFloat
(
<
any
>
context
.
getValue
(
this
.
key
))
<
this
.
value
);
}
public
serialize
():
string
{
...
...
@@ -912,15 +929,15 @@ export class ContextKeySmallerExpr implements IContextKeyExpression {
export
class
ContextKeySmallerEqualsExpr
implements
IContextKeyExpression
{
public
static
create
(
key
:
string
,
value
:
any
,
negated
:
ContextKeyExpression
|
null
=
null
):
ContextKeyExpression
{
return
new
ContextKeySmallerEqualsExpr
(
key
,
value
,
negated
);
public
static
create
(
key
:
string
,
_
value
:
any
,
negated
:
ContextKeyExpression
|
null
=
null
):
ContextKeyExpression
{
return
withFloatOrStr
(
_value
,
(
value
)
=>
new
ContextKeySmallerEqualsExpr
(
key
,
value
,
negated
)
);
}
public
readonly
type
=
ContextKeyExprType
.
SmallerEquals
;
private
constructor
(
private
readonly
key
:
string
,
private
readonly
value
:
any
,
private
readonly
value
:
number
|
string
,
private
negated
:
ContextKeyExpression
|
null
)
{
}
...
...
@@ -944,7 +961,10 @@ export class ContextKeySmallerEqualsExpr implements IContextKeyExpression {
}
public
evaluate
(
context
:
IContext
):
boolean
{
return
(
parseFloat
(
<
any
>
context
.
getValue
(
this
.
key
))
<=
parseFloat
(
this
.
value
));
if
(
typeof
this
.
value
===
'
string
'
)
{
return
false
;
}
return
(
parseFloat
(
<
any
>
context
.
getValue
(
this
.
key
))
<=
this
.
value
);
}
public
serialize
():
string
{
...
...
src/vs/platform/contextkey/test/common/contextkey.test.ts
浏览文件 @
41b414c2
...
...
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import
*
as
assert
from
'
assert
'
;
import
{
isLinux
,
isMacintosh
,
isWindows
}
from
'
vs/base/common/platform
'
;
import
{
ContextKeyExpr
,
implies
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
ContextKeyExpr
,
ContextKeyExpression
,
implies
}
from
'
vs/platform/contextkey/common/contextkey
'
;
function
createContext
(
ctx
:
any
)
{
return
{
...
...
@@ -45,6 +45,19 @@ suite('ContextKeyExpr', () => {
assert
(
a
.
equals
(
b
),
'
expressions should be equal
'
);
});
test
(
'
issue #134942: Equals in comparator expressions
'
,
()
=>
{
function
testEquals
(
expr
:
ContextKeyExpression
|
undefined
,
str
:
string
):
void
{
const
deserialized
=
ContextKeyExpr
.
deserialize
(
str
);
assert
.
ok
(
expr
);
assert
.
ok
(
deserialized
);
assert
.
strictEqual
(
expr
.
equals
(
deserialized
),
true
,
str
);
}
testEquals
(
ContextKeyExpr
.
greater
(
'
value
'
,
0
),
'
value > 0
'
);
testEquals
(
ContextKeyExpr
.
greaterEquals
(
'
value
'
,
0
),
'
value >= 0
'
);
testEquals
(
ContextKeyExpr
.
smaller
(
'
value
'
,
0
),
'
value < 0
'
);
testEquals
(
ContextKeyExpr
.
smallerEquals
(
'
value
'
,
0
),
'
value <= 0
'
);
});
test
(
'
normalize
'
,
()
=>
{
let
key1IsTrue
=
ContextKeyExpr
.
equals
(
'
key1
'
,
true
);
let
key1IsNotFalse
=
ContextKeyExpr
.
notEquals
(
'
key1
'
,
false
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录