Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
774dad8d
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,发现更多精彩内容 >>
提交
774dad8d
编写于
1月 26, 2017
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Inserted user settings badly indented. Fixes #19136
上级
cf07be7a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
34 addition
and
5 deletion
+34
-5
src/vs/base/common/json.ts
src/vs/base/common/json.ts
+3
-2
src/vs/base/test/common/json.test.ts
src/vs/base/test/common/json.test.ts
+24
-3
src/vs/base/test/common/jsonEdit.test.ts
src/vs/base/test/common/jsonEdit.test.ts
+7
-0
未找到文件。
src/vs/base/common/json.ts
浏览文件 @
774dad8d
...
...
@@ -885,7 +885,6 @@ export function parseTree(text: string, errors: ParseError[] = [], options?: Par
function
onValue
(
valueNode
:
Node
):
Node
{
currentParent
.
children
.
push
(
valueNode
);
ensurePropertyComplete
(
valueNode
.
offset
+
valueNode
.
length
);
return
valueNode
;
}
...
...
@@ -898,9 +897,9 @@ export function parseTree(text: string, errors: ParseError[] = [], options?: Par
currentParent
.
children
.
push
({
type
:
'
string
'
,
value
:
name
,
offset
,
length
,
parent
:
currentParent
});
},
onObjectEnd
:
(
offset
:
number
,
length
:
number
)
=>
{
ensurePropertyComplete
(
offset
);
currentParent
.
length
=
offset
+
length
-
currentParent
.
offset
;
currentParent
=
currentParent
.
parent
;
ensurePropertyComplete
(
offset
+
length
);
},
onArrayBegin
:
(
offset
:
number
,
length
:
number
)
=>
{
currentParent
=
onValue
({
type
:
'
array
'
,
offset
,
length
:
-
1
,
parent
:
currentParent
,
children
:
[]
});
...
...
@@ -908,9 +907,11 @@ export function parseTree(text: string, errors: ParseError[] = [], options?: Par
onArrayEnd
:
(
offset
:
number
,
length
:
number
)
=>
{
currentParent
.
length
=
offset
+
length
-
currentParent
.
offset
;
currentParent
=
currentParent
.
parent
;
ensurePropertyComplete
(
offset
+
length
);
},
onLiteralValue
:
(
value
:
any
,
offset
:
number
,
length
:
number
)
=>
{
onValue
({
type
:
getLiteralNodeType
(
value
),
offset
,
length
,
parent
:
currentParent
,
value
});
ensurePropertyComplete
(
offset
+
length
);
},
onSeparator
:
(
sep
:
string
,
offset
:
number
,
length
:
number
)
=>
{
if
(
currentParent
.
type
===
'
property
'
)
{
...
...
src/vs/base/test/common/json.test.ts
浏览文件 @
774dad8d
...
...
@@ -38,11 +38,11 @@ function assertInvalidParse(input: string, expected: any, options?: ParseOptions
assert
.
deepEqual
(
actual
,
expected
);
}
function
assertTree
(
input
:
string
,
expected
:
any
):
void
{
function
assertTree
(
input
:
string
,
expected
:
any
,
expectedErrors
:
number
[]
=
[]
):
void
{
var
errors
:
ParseError
[]
=
[];
var
actual
=
parseTree
(
input
,
errors
);
assert
.
equal
(
errors
.
length
,
0
);
assert
.
deepEqual
(
errors
.
map
(
e
=>
e
.
error
,
expected
),
expectedErrors
);
let
checkParent
=
(
node
:
Node
)
=>
{
if
(
node
.
children
)
{
for
(
let
child
of
node
.
children
)
{
...
...
@@ -313,7 +313,7 @@ suite('JSON', () => {
]
},
{
type
:
'
property
'
,
offset
:
12
,
length
:
1
9
,
columnOffset
:
15
,
children
:
[
type
:
'
property
'
,
offset
:
12
,
length
:
1
8
,
columnOffset
:
15
,
children
:
[
{
type
:
'
string
'
,
offset
:
12
,
length
:
3
,
value
:
'
v
'
},
{
type
:
'
array
'
,
offset
:
17
,
length
:
13
,
children
:
[
...
...
@@ -326,6 +326,27 @@ suite('JSON', () => {
]
}
);
assertTree
(
'
{ "id": { "foo": { } } , }
'
,
{
type
:
'
object
'
,
offset
:
0
,
length
:
27
,
children
:
[
{
type
:
'
property
'
,
offset
:
3
,
length
:
20
,
columnOffset
:
7
,
children
:
[
{
type
:
'
string
'
,
offset
:
3
,
length
:
4
,
value
:
'
id
'
},
{
type
:
'
object
'
,
offset
:
9
,
length
:
14
,
children
:
[
{
type
:
'
property
'
,
offset
:
11
,
length
:
10
,
columnOffset
:
16
,
children
:
[
{
type
:
'
string
'
,
offset
:
11
,
length
:
5
,
value
:
'
foo
'
},
{
type
:
'
object
'
,
offset
:
18
,
length
:
3
,
children
:
[]
}
]
}
]
}
]
}
]
}
,
[
ParseErrorCode
.
PropertyNameExpected
,
ParseErrorCode
.
ValueExpected
]);
});
test
(
'
tree: find location
'
,
()
=>
{
...
...
src/vs/base/test/common/jsonEdit.test.ts
浏览文件 @
774dad8d
...
...
@@ -83,6 +83,13 @@ suite('JSON - edits', () => {
edits
=
setProperty
(
content
,
[
'
x
'
,
'
c
'
],
'
bar
'
,
formatterOptions
,
()
=>
2
);
assertEdit
(
content
,
edits
,
'
{
\n
"x": {
\n
"a": 1,
\n
"b": true,
\n
"c": "bar"
\n
}
\n
}
\n
'
);
edits
=
setProperty
(
content
,
[
'
c
'
],
'
bar
'
,
formatterOptions
);
assertEdit
(
content
,
edits
,
'
{
\n
"x": {
\n
"a": 1,
\n
"b": true
\n
},
\n
"c": "bar"
\n
}
\n
'
);
content
=
'
{
\n
"a": [
\n
{
\n
}
\n
]
\n
}
'
;
edits
=
setProperty
(
content
,
[
'
foo
'
],
'
bar
'
,
formatterOptions
);
assertEdit
(
content
,
edits
,
'
{
\n
"a": [
\n
{
\n
}
\n
],
\n
"foo": "bar"
\n
}
'
);
content
=
''
;
edits
=
setProperty
(
content
,
[
'
foo
'
,
0
],
'
bar
'
,
formatterOptions
);
assertEdit
(
content
,
edits
,
'
{
\n
"foo": [
\n
"bar"
\n
]
\n
}
'
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录