Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
c7e4bf0f
U
uni-app
项目概览
DCloud
/
uni-app
5 天 前同步成功
通知
815
Star
38709
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
8
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
8
Issue
8
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
c7e4bf0f
编写于
11月 28, 2023
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: UTSJSONObject使用下标进行赋值不符合预期的Bug、vue proxy包裹后访问UTSJSONObject方法报错的Bug
上级
d7b42f1c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
212 addition
and
85 deletion
+212
-85
packages/uni-uts-v1/lib/javascript/lib/runtime/index.d.ts
packages/uni-uts-v1/lib/javascript/lib/runtime/index.d.ts
+31
-10
packages/uni-uts-v1/lib/javascript/lib/runtime/index.js
packages/uni-uts-v1/lib/javascript/lib/runtime/index.js
+181
-75
未找到文件。
packages/uni-uts-v1/lib/javascript/lib/runtime/index.d.ts
浏览文件 @
c7e4bf0f
declare
function
arrayAt
<
T
>
(
array
:
T
[],
index
:
number
):
T
|
null
;
declare
function
arrayFind
<
T
>
(
array
:
T
[],
predicate
:
any
):
T
|
null
;
declare
function
arrayFindLast
<
T
>
(
array
:
T
[],
predicate
:
any
):
T
|
null
;
declare
function
arrayPop
<
T
>
(
array
:
T
[]):
T
|
null
;
declare
function
arrayShift
<
T
>
(
array
:
T
[]):
T
|
null
;
declare
function
isInstanceOf
(
value
:
any
,
type
:
Function
):
boolean
;
declare
function
isInstanceOf
(
value
:
any
,
type
:
Function
):
boolean
;
declare
const
JSON_2
:
{
declare
function
mapGet
<
K
,
V
>
(
map
:
Map
<
K
,
V
>
,
key
:
K
):
V
|
null
;
parse
:
(
text
:
string
,
reviver
:
(
this
:
any
,
key
:
string
,
value
:
any
)
=>
any
)
=>
any
|
null
;
parseArray
(
text
:
string
):
Array
<
any
>
|
null
;
declare
function
stringCodePointAt
(
str
:
string
,
pos
:
number
):
number
|
null
;
parseObject
(
text
:
string
):
UTSJSONObject
|
null
;
stringify
:
(
value
:
any
)
=>
string
;
};
export
{
JSON_2
as
JSON
}
export
declare
const
UTS
:
{
export
declare
const
UTS
:
{
arrayAt
:
typeof
arrayAt
;
arrayFind
:
typeof
arrayFind
;
arrayFindLast
:
typeof
arrayFindLast
;
arrayPop
:
typeof
arrayPop
;
arrayShift
:
typeof
arrayShift
;
isInstanceOf
:
typeof
isInstanceOf
;
isInstanceOf
:
typeof
isInstanceOf
;
mapGet
:
typeof
mapGet
;
stringCodePointAt
:
typeof
stringCodePointAt
;
weakMapGet
:
typeof
weakMapGet
;
JSON
:
{
parse
:
(
text
:
string
,
reviver
:
(
this
:
any
,
key
:
string
,
value
:
any
)
=>
any
)
=>
any
;
parseArray
(
text
:
string
):
any
[]
|
null
;
parseObject
(
text
:
string
):
UTSJSONObject
|
null
;
stringify
:
(
value
:
any
)
=>
string
;
};
};
};
export
declare
class
UTSJSONObject
{
declare
class
UTSJSONObject
{
[
key
:
string
]:
any
;
[
key
:
string
]:
any
;
private
_content
;
constructor
(
content
?:
Record
<
string
,
any
>
);
constructor
(
content
?:
Record
<
string
,
any
>
);
toJSON
():
Record
<
string
,
any
>
;
private
_resolveKeyPath
;
private
_getValue
;
private
_getValue
;
get
(
key
:
string
):
any
|
null
;
get
(
key
:
string
):
any
|
null
;
set
(
key
:
string
,
value
:
any
):
void
;
set
(
key
:
string
,
value
:
any
):
void
;
...
@@ -30,6 +49,8 @@ export declare class UTSJSONObject {
...
@@ -30,6 +49,8 @@ export declare class UTSJSONObject {
forEach
(
callback
:
(
value
:
any
,
key
:
string
)
=>
void
):
void
;
forEach
(
callback
:
(
value
:
any
,
key
:
string
)
=>
void
):
void
;
}
}
declare
function
weakMapGet
<
K
extends
symbol
|
object
,
V
>
(
map
:
WeakMap
<
K
,
V
>
,
key
:
K
):
V
|
null
;
export
*
from
"
tslib
"
;
export
*
from
"
tslib
"
;
...
...
packages/uni-uts-v1/lib/javascript/lib/runtime/index.js
浏览文件 @
c7e4bf0f
function
initUTSJSONObjectProperties
(
obj
)
{
function
initUTSJSONObjectProperties
(
obj
)
{
const
propertyDescriptor
=
{
const
propertyDescriptor
=
{
enumerable
:
false
,
enumerable
:
false
,
configurable
:
false
,
writable
:
false
,
};
};
const
propertyList
=
[
const
propertyList
=
[
'
_
content
'
,
'
_
resolveKeyPath
'
,
'
_getValue
'
,
'
_getValue
'
,
'
toJSON
'
,
'
toJSON
'
,
'
get
'
,
'
get
'
,
...
@@ -28,36 +26,83 @@ function initUTSJSONObjectProperties(obj) {
...
@@ -28,36 +26,83 @@ function initUTSJSONObjectProperties(obj) {
}
}
class
UTSJSONObject
{
class
UTSJSONObject
{
constructor
(
content
=
{})
{
constructor
(
content
=
{})
{
this
.
_content
=
content
;
Object
.
assign
(
this
,
content
);
Object
.
assign
(
this
,
content
);
initUTSJSONObjectProperties
(
this
);
initUTSJSONObjectProperties
(
this
);
}
}
toJSON
()
{
_resolveKeyPath
(
keyPath
)
{
return
this
.
_content
;
// 非法keyPath不抛出错误,直接返回空数组
}
let
token
=
''
;
_getValue
(
keyPathOrKey
)
{
const
keyPathArr
=
[];
if
(
keyPathOrKey
.
includes
(
'
.
'
))
{
let
inOpenParentheses
=
false
;
let
keys
=
keyPathOrKey
.
split
(
'
.
'
);
for
(
let
i
=
0
;
i
<
keyPath
.
length
;
i
++
)
{
let
value
=
this
.
_content
;
const
word
=
keyPath
[
i
];
for
(
let
key
of
keys
)
{
switch
(
word
)
{
if
(
value
instanceof
Object
)
{
case
'
.
'
:
value
=
value
[
key
];
if
(
token
.
length
>
0
)
{
keyPathArr
.
push
(
token
);
token
=
''
;
}
break
;
case
'
[
'
:
{
inOpenParentheses
=
true
;
if
(
token
.
length
>
0
)
{
keyPathArr
.
push
(
token
);
token
=
''
;
}
else
{
return
[];
}
break
;
}
}
else
{
case
'
]
'
:
return
null
;
if
(
inOpenParentheses
)
{
if
(
token
.
length
>
0
)
{
keyPathArr
.
push
(
token
);
token
=
''
;
}
else
{
return
[];
}
inOpenParentheses
=
false
;
}
else
{
return
[];
}
break
;
default
:
token
+=
word
;
break
;
}
if
(
i
===
keyPath
.
length
-
1
)
{
if
(
token
.
length
>
0
)
{
keyPathArr
.
push
(
token
);
token
=
''
;
}
}
}
}
return
value
;
}
}
else
{
return
keyPathArr
;
return
this
.
_content
[
keyPathOrKey
];
}
_getValue
(
keyPath
)
{
const
keyPathArr
=
this
.
_resolveKeyPath
(
keyPath
);
if
(
keyPathArr
.
length
===
0
)
{
return
null
;
}
let
value
=
this
;
for
(
let
key
of
keyPathArr
)
{
if
(
value
instanceof
Object
)
{
value
=
value
[
key
];
}
else
{
return
null
;
}
}
}
return
value
;
}
}
get
(
key
)
{
get
(
key
)
{
return
this
.
_getValue
(
key
);
return
this
.
_getValue
(
key
);
}
}
set
(
key
,
value
)
{
set
(
key
,
value
)
{
this
.
_content
[
key
]
=
value
;
this
[
key
]
=
value
;
}
}
getAny
(
key
)
{
getAny
(
key
)
{
return
this
.
_getValue
(
key
);
return
this
.
_getValue
(
key
);
...
@@ -109,63 +154,53 @@ class UTSJSONObject {
...
@@ -109,63 +154,53 @@ class UTSJSONObject {
}
}
toMap
()
{
toMap
()
{
let
map
=
new
Map
();
let
map
=
new
Map
();
for
(
let
key
in
this
.
_content
)
{
for
(
let
key
in
this
)
{
map
.
set
(
key
,
this
.
_content
[
key
]);
map
.
set
(
key
,
this
[
key
]);
}
}
return
map
;
return
map
;
}
}
forEach
(
callback
)
{
forEach
(
callback
)
{
for
(
let
key
in
this
.
_content
)
{
for
(
let
key
in
this
)
{
callback
(
this
.
_content
[
key
],
key
);
callback
(
this
[
key
],
key
);
}
}
}
}
}
}
const
OriginalJSON
=
JSON
;
// @ts-ignore
const
UTSJSON
=
{
globalThis
.
UTSJSONObject
=
UTSJSONObject
;
parse
:
(
text
,
reviver
)
=>
{
try
{
function
arrayPop
(
array
)
{
const
parseResult
=
OriginalJSON
.
parse
(
text
,
reviver
);
if
(
array
.
length
===
0
)
{
if
(
Array
.
isArray
(
parseResult
))
{
return
null
;
return
parseResult
;
}
}
return
array
.
pop
();
return
new
UTSJSONObject
(
parseResult
);
}
}
function
arrayShift
(
array
)
{
catch
(
error
)
{
if
(
array
.
length
===
0
)
{
console
.
error
(
error
);
return
null
;
return
null
;
}
}
return
array
.
shift
();
},
}
parseArray
(
text
)
{
function
arrayFind
(
array
,
predicate
)
{
try
{
const
index
=
array
.
findIndex
(
predicate
);
const
parseResult
=
OriginalJSON
.
parse
(
text
);
if
(
index
<
0
)
{
if
(
Array
.
isArray
(
parseResult
))
{
return
null
;
return
parseResult
;
}
}
return
array
[
index
];
return
null
;
}
}
function
arrayFindLast
(
array
,
predicate
)
{
catch
(
error
)
{
const
index
=
array
.
findLastIndex
(
predicate
);
console
.
error
(
error
);
if
(
index
<
0
)
{
return
null
;
return
null
;
}
}
},
return
array
[
index
];
parseObject
(
text
)
{
}
try
{
function
arrayAt
(
array
,
index
)
{
const
parseResult
=
OriginalJSON
.
parse
(
text
);
if
(
index
<
0
||
index
>=
array
.
length
)
{
if
(
Array
.
isArray
(
parseResult
))
{
return
null
;
return
null
;
}
}
return
array
[
index
];
return
new
UTSJSONObject
(
parseResult
);
}
}
catch
(
error
)
{
console
.
error
(
error
);
return
null
;
}
},
stringify
:
(
value
)
=>
{
return
OriginalJSON
.
stringify
(
value
);
},
};
var
IDENTIFIER
;
var
IDENTIFIER
;
(
function
(
IDENTIFIER
)
{
(
function
(
IDENTIFIER
)
{
...
@@ -262,8 +297,84 @@ function isInstanceOf(value, type) {
...
@@ -262,8 +297,84 @@ function isInstanceOf(value, type) {
return
isImplementationOf
(
proto
,
type
);
return
isImplementationOf
(
proto
,
type
);
}
}
const
OriginalJSON
=
JSON
;
const
UTSJSON
=
{
parse
:
(
text
,
reviver
)
=>
{
try
{
const
parseResult
=
OriginalJSON
.
parse
(
text
,
reviver
);
if
(
Array
.
isArray
(
parseResult
))
{
return
parseResult
;
}
return
new
UTSJSONObject
(
parseResult
);
}
catch
(
error
)
{
console
.
error
(
error
);
return
null
;
}
},
parseArray
(
text
)
{
try
{
const
parseResult
=
OriginalJSON
.
parse
(
text
);
if
(
Array
.
isArray
(
parseResult
))
{
return
parseResult
;
}
return
null
;
}
catch
(
error
)
{
console
.
error
(
error
);
return
null
;
}
},
parseObject
(
text
)
{
try
{
const
parseResult
=
OriginalJSON
.
parse
(
text
);
if
(
Array
.
isArray
(
parseResult
))
{
return
null
;
}
return
new
UTSJSONObject
(
parseResult
);
}
catch
(
error
)
{
console
.
error
(
error
);
return
null
;
}
},
stringify
:
(
value
)
=>
{
return
OriginalJSON
.
stringify
(
value
);
},
};
function
mapGet
(
map
,
key
)
{
if
(
!
map
.
has
(
key
))
{
return
null
;
}
return
map
.
get
(
key
);
}
function
stringCodePointAt
(
str
,
pos
)
{
if
(
pos
<
0
||
pos
>=
str
.
length
)
{
return
null
;
}
return
str
.
codePointAt
(
pos
);
}
function
weakMapGet
(
map
,
key
)
{
if
(
!
map
.
has
(
key
))
{
return
null
;
}
return
map
.
get
(
key
);
}
const
UTS
=
{
const
UTS
=
{
arrayAt
,
arrayFind
,
arrayFindLast
,
arrayPop
,
arrayShift
,
isInstanceOf
,
isInstanceOf
,
mapGet
,
stringCodePointAt
,
weakMapGet
,
JSON
:
UTSJSON
,
};
};
/******************************************************************************
/******************************************************************************
...
@@ -602,9 +713,4 @@ function __disposeResources(env) {
...
@@ -602,9 +713,4 @@ function __disposeResources(env) {
return
next
();
return
next
();
}
}
// @ts-ignore
export
{
UTS
,
__addDisposableResource
,
__assign
,
__asyncDelegator
,
__asyncGenerator
,
__asyncValues
,
__await
,
__awaiter
,
__classPrivateFieldGet
,
__classPrivateFieldIn
,
__classPrivateFieldSet
,
__createBinding
,
__decorate
,
__disposeResources
,
__esDecorate
,
__exportStar
,
__extends
,
__generator
,
__importDefault
,
__importStar
,
__makeTemplateObject
,
__metadata
,
__param
,
__propKey
,
__read
,
__rest
,
__runInitializers
,
__setFunctionName
,
__spread
,
__spreadArray
,
__spreadArrays
,
__values
};
globalThis
.
JSON
=
UTSJSON
;
// @ts-ignore
globalThis
.
UTSJSONObject
=
UTSJSONObject
;
export
{
UTSJSON
as
JSON
,
UTS
,
UTSJSONObject
,
__addDisposableResource
,
__assign
,
__asyncDelegator
,
__asyncGenerator
,
__asyncValues
,
__await
,
__awaiter
,
__classPrivateFieldGet
,
__classPrivateFieldIn
,
__classPrivateFieldSet
,
__createBinding
,
__decorate
,
__disposeResources
,
__esDecorate
,
__exportStar
,
__extends
,
__generator
,
__importDefault
,
__importStar
,
__makeTemplateObject
,
__metadata
,
__param
,
__propKey
,
__read
,
__rest
,
__runInitializers
,
__setFunctionName
,
__spread
,
__spreadArray
,
__spreadArrays
,
__values
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录