Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MuGuiLin
uni-app
提交
0c071609
U
uni-app
项目概览
MuGuiLin
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0c071609
编写于
1月 10, 2022
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mp): string express with escape quote
上级
a206e689
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
77 addition
and
8 deletion
+77
-8
packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js
...ni-template-compiler/__tests__/compiler-mp-weixin.spec.js
+18
-0
packages/uni-template-compiler/lib/constants.js
packages/uni-template-compiler/lib/constants.js
+3
-1
packages/uni-template-compiler/lib/script/traverse/data/attrs.js
...s/uni-template-compiler/lib/script/traverse/data/attrs.js
+8
-2
packages/uni-template-compiler/lib/script/traverse/index.js
packages/uni-template-compiler/lib/script/traverse/index.js
+7
-1
packages/uni-template-compiler/lib/script/traverse/visitor.js
...ages/uni-template-compiler/lib/script/traverse/visitor.js
+11
-3
packages/uni-template-compiler/lib/util.js
packages/uni-template-compiler/lib/util.js
+30
-1
未找到文件。
packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js
浏览文件 @
0c071609
...
...
@@ -54,6 +54,24 @@ describe('mp:compiler-mp-weixin', () => {
)
})
it
(
'
generate string express with escape quote
'
,
()
=>
{
assertCodegen
(
`<view :data-text="text+'\\''"></view>`
,
'
<view data-text="{{$root.a0}}"></view>
'
,
`with(this){var a0=text+"'";$mp.data=Object.assign({},{$root:{a0:a0}})}`
)
assertCodegen
(
`<view>{{text+'\\''}}</view>`
,
'
<view>{{$root.t0}}</view>
'
,
`with(this){var t0=text+"'";$mp.data=Object.assign({},{$root:{t0:t0}})}`
)
assertCodegen
(
`<view>{{text+"\\""}}</view>`
,
'
<view>{{$root.t0}}</view>
'
,
`with(this){var t0=text+"\\"";$mp.data=Object.assign({},{$root:{t0:t0}})}`
)
})
it
(
'
generate named scoped slot
'
,
()
=>
{
assertCodegen
(
'
<foo><template slot="foo" slot-scope="{bar}">{{ bar.foo }}</template></foo>
'
,
...
...
packages/uni-template-compiler/lib/constants.js
浏览文件 @
0c071609
...
...
@@ -117,6 +117,7 @@ module.exports = {
PREFIX_CLASS
:
'
c
'
,
PREFIX_STYLE
:
'
s
'
,
PREFIX_EVENT
:
'
e
'
,
PREFIX_TEXT
:
'
t
'
,
IDENTIFIER_FOR
:
'
__$$for$$__
'
,
IDENTIFIER_ATTR
:
'
__$$attr$$__
'
,
IDENTIFIER_METHOD
:
'
__$$method$$__
'
,
...
...
@@ -124,5 +125,6 @@ module.exports = {
IDENTIFIER_CLASS
:
'
__$$class$$__
'
,
IDENTIFIER_STYLE
:
'
__$$style$$__
'
,
IDENTIFIER_EVENT
:
'
__$$event$$__
'
,
IDENTIFIER_GLOBAL
:
'
__$$global$$__
'
IDENTIFIER_GLOBAL
:
'
__$$global$$__
'
,
IDENTIFIER_TEXT
:
'
__$$text$$__
'
}
packages/uni-template-compiler/lib/script/traverse/data/attrs.js
浏览文件 @
0c071609
...
...
@@ -3,18 +3,24 @@ const {
}
=
require
(
'
../../../constants
'
)
const
{
isSimpleObjectExpression
isSimpleObjectExpression
,
hasEscapeQuote
}
=
require
(
'
../../../util
'
)
const
getMemberExpr
=
require
(
'
../member-expr
'
)
function
checkObjectExpression
(
path
)
{
return
path
.
isObjectExpression
()
&&
!
isSimpleObjectExpression
(
path
.
node
)
}
module
.
exports
=
function
processAttrs
(
paths
,
path
,
state
,
isComponent
,
tagName
)
{
const
attrsPath
=
paths
.
attrs
if
(
attrsPath
)
{
attrsPath
.
get
(
'
value.properties
'
).
forEach
(
propertyPath
=>
{
const
valuePath
=
propertyPath
.
get
(
'
value
'
)
// 对于简单的ObjectExpression不再单独处理,改为在转换temlplte时用()包裹(微信、QQ)
if
(
valuePath
.
isObjectExpression
()
&&
!
isSimpleObjectExpression
(
valuePath
.
node
))
{
// 属性中包含转义引号时部分小程序平台报错或显示异常
if
(
checkObjectExpression
(
valuePath
)
||
hasEscapeQuote
(
valuePath
))
{
valuePath
.
replaceWith
(
getMemberExpr
(
path
,
IDENTIFIER_ATTR
,
valuePath
.
node
,
state
))
}
})
...
...
packages/uni-template-compiler/lib/script/traverse/index.js
浏览文件 @
0c071609
...
...
@@ -12,6 +12,7 @@ const {
IDENTIFIER_STYLE
,
IDENTIFIER_EVENT
,
IDENTIFIER_GLOBAL
,
IDENTIFIER_TEXT
,
PREFIX_ATTR
,
PREFIX_GLOBAL
,
PREFIX_METHOD
,
...
...
@@ -19,7 +20,8 @@ const {
PREFIX_FOR
,
PREFIX_CLASS
,
PREFIX_STYLE
,
PREFIX_EVENT
PREFIX_EVENT
,
PREFIX_TEXT
}
=
require
(
'
../../constants
'
)
const
{
...
...
@@ -63,6 +65,10 @@ function reIdentifier (identifierArray) {
[
IDENTIFIER_ATTR
]:
{
prefix
:
PREFIX_ATTR
,
id
:
0
},
[
IDENTIFIER_TEXT
]:
{
prefix
:
PREFIX_TEXT
,
id
:
0
}
}
// TODO order
...
...
packages/uni-template-compiler/lib/script/traverse/visitor.js
浏览文件 @
0c071609
...
...
@@ -11,7 +11,8 @@ const {
METHOD_RESOLVE_SCOPED_SLOTS
,
IDENTIFIER_FILTER
,
IDENTIFIER_METHOD
,
IDENTIFIER_GLOBAL
IDENTIFIER_GLOBAL
,
IDENTIFIER_TEXT
}
=
require
(
'
../../constants
'
)
const
{
...
...
@@ -22,7 +23,8 @@ const {
hasOwn
,
hyphenate
,
traverseFilter
,
getComponentName
getComponentName
,
hasEscapeQuote
}
=
require
(
'
../../util
'
)
const
traverseData
=
require
(
'
./data
'
)
...
...
@@ -186,7 +188,13 @@ module.exports = {
break
case
METHOD_TO_STRING
:
{
const
stringNodes
=
path
.
node
.
arguments
[
0
]
const
stringPath
=
path
.
get
(
'
arguments.0
'
)
if
(
hasEscapeQuote
(
stringPath
))
{
// 属性中包含转义引号时部分小程序平台报错或显示异常
// TODO 简单情况翻转外层引号
stringPath
.
replaceWith
(
getMemberExpr
(
path
,
IDENTIFIER_TEXT
,
stringPath
.
node
,
this
))
}
const
stringNodes
=
stringPath
.
node
stringNodes
.
$toString
=
true
path
.
replaceWith
(
stringNodes
)
}
...
...
packages/uni-template-compiler/lib/util.js
浏览文件 @
0c071609
...
...
@@ -232,6 +232,34 @@ function isSimpleObjectExpression (node) {
})
=>
!
t
.
isIdentifier
(
key
)
||
!
(
t
.
isIdentifier
(
value
)
||
t
.
isStringLiteral
(
value
)
||
t
.
isBooleanLiteral
(
value
)
||
t
.
isNumericLiteral
(
value
)
||
t
.
isNullLiteral
(
value
)))
}
/**
* 是否包含转义引号
* @param {*} path
* @returns {boolean}
*/
function
hasEscapeQuote
(
path
)
{
let
has
=
false
function
hasEscapeQuote
(
node
)
{
const
quote
=
node
.
extra
?
node
.
extra
.
raw
[
0
]
:
'
"
'
if
(
node
.
value
.
includes
(
quote
))
{
return
true
}
}
if
(
path
.
isStringLiteral
())
{
return
hasEscapeQuote
(
path
.
node
)
}
else
{
path
.
traverse
({
noScope
:
true
,
StringLiteral
(
path
)
{
if
(
hasEscapeQuote
(
path
.
node
))
{
has
=
true
path
.
stop
()
}
}
})
}
return
has
}
module
.
exports
=
{
hasOwn
,
...
...
@@ -263,5 +291,6 @@ module.exports = {
}),
processMemberExpression
,
getForIndexIdentifier
,
isSimpleObjectExpression
isSimpleObjectExpression
,
hasEscapeQuote
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录