Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
erosXXX
uni-app
提交
238086e3
U
uni-app
项目概览
erosXXX
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
238086e3
编写于
11月 16, 2021
作者:
Q
qiang
提交者:
折腾笔记
12月 15, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mp-jd): resolveScopedSlots
上级
269e1b8c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
116 addition
and
1 deletion
+116
-1
packages/uni-mp-jd/lib/uni.compiler.js
packages/uni-mp-jd/lib/uni.compiler.js
+116
-1
未找到文件。
packages/uni-mp-jd/lib/uni.compiler.js
浏览文件 @
238086e3
const
compiler
=
require
(
'
@dcloudio/uni-mp-weixin/lib/uni.compiler.js
'
)
const
path
=
require
(
'
path
'
)
const
t
=
require
(
'
@babel/types
'
)
const
uniI18n
=
require
(
'
@dcloudio/uni-cli-i18n
'
)
function
generateJsCode
(
properties
=
'
{}
'
)
{
return
`
jd.createComponent({
generic:true,
props:
${
properties
}
,
render: function(){}
})
`
}
function
generateCssCode
(
filename
)
{
return
`
@import "./
${
filename
}
"
`
}
function
hasOwn
(
obj
,
key
)
{
return
Object
.
prototype
.
hasOwnProperty
.
call
(
obj
,
key
)
}
module
.
exports
=
Object
.
assign
({},
compiler
,
{
directive
:
'
jd:
'
directive
:
'
jd:
'
,
resolveScopedSlots
(
slotName
,
{
genCode
,
generate
,
ownerName
,
parentName
,
parentNode
,
resourcePath
,
paramExprNode
,
returnExprNodes
,
traverseExpr
},
state
)
{
if
(
!
state
.
scopedSlots
)
{
state
.
scopedSlots
=
{}
}
const
baseName
=
`
${
ownerName
}
-
${
parentName
}
-
${
slotName
}
`
let
componentName
=
baseName
if
(
!
hasOwn
(
state
.
scopedSlots
,
baseName
))
{
state
.
scopedSlots
[
baseName
]
=
0
}
if
(
state
.
scopedSlots
[
baseName
])
{
componentName
=
baseName
+
state
.
scopedSlots
[
baseName
]
}
state
.
scopedSlots
[
baseName
]
++
parentNode
.
attr
[
'
generic:scoped-slots-
'
+
slotName
]
=
componentName
if
(
state
.
options
.
platform
.
name
===
'
mp-weixin
'
)
{
parentNode
.
attr
[
'
data-vue-generic
'
]
=
'
scoped
'
}
if
(
!
parentNode
.
attr
.
generic
)
{
parentNode
.
attr
.
generic
=
{}
}
parentNode
.
attr
.
generic
[
slotName
]
=
true
// 生成 scopedSlots 文件,包括 json,js,wxml,wxss,还需要更新 owner 的 usingComponents
if
(
!
state
.
files
)
{
state
.
files
=
{}
}
const
extname
=
path
.
extname
(
resourcePath
)
// TODO 需要存储 resourcePath 相关 json
const
templateFile
=
resourcePath
.
replace
(
ownerName
+
extname
,
componentName
+
extname
)
const
templateContent
=
generate
(
traverseExpr
(
returnExprNodes
,
state
),
state
)
state
.
files
[
templateFile
]
=
templateContent
const
jsFile
=
resourcePath
.
replace
(
ownerName
+
extname
,
componentName
+
'
.js
'
)
const
objectProperties
=
[]
if
(
t
.
isObjectPattern
(
paramExprNode
))
{
paramExprNode
.
properties
.
forEach
(
property
=>
{
const
key
=
property
.
key
const
value
=
property
.
value
const
valueObjectProperties
=
[
t
.
objectProperty
(
t
.
identifier
(
'
type
'
),
t
.
nullLiteral
())
]
if
(
t
.
isIdentifier
(
value
))
{
if
(
value
.
name
!==
key
.
name
)
{
state
.
errors
.
add
(
uniI18n
.
__
(
'
mpWeChat.slotPropNoSupportReanme
'
,
{
0
:
key
.
name
,
1
:
value
.
name
}))
}
}
else
if
(
t
.
isAssignmentPattern
(
value
))
{
valueObjectProperties
.
push
(
t
.
objectProperty
(
t
.
identifier
(
'
default
'
),
value
.
right
))
}
objectProperties
.
push
(
t
.
objectProperty
(
key
,
t
.
objectExpression
(
valueObjectProperties
)))
})
}
else
{
state
.
errors
.
add
(
uniI18n
.
__
(
'
mpWeChat.onlySupportDestructuringSlot
'
,
{
0
:
paramExprNode
.
name
,
1
:
'
v-slot="{ user }"
'
}))
}
const
jsContent
=
generateJsCode
(
genCode
(
t
.
objectExpression
(
objectProperties
),
true
))
state
.
files
[
jsFile
]
=
jsContent
try
{
// TODO 使用 getPlatformExts 在单元测试报错,改从 state.options.platform 判断
const
{
getPlatformExts
}
=
require
(
'
@dcloudio/uni-cli-shared
'
)
const
styleExtname
=
getPlatformExts
().
style
const
styleFile
=
resourcePath
.
replace
(
ownerName
+
extname
,
componentName
+
styleExtname
)
const
styleContent
=
generateCssCode
(
ownerName
+
styleExtname
)
state
.
files
[
styleFile
]
=
styleContent
}
catch
(
error
)
{
}
if
(
!
state
.
generic
)
{
state
.
generic
=
[]
}
// 存储,方便后续生成 json
state
.
generic
.
push
(
componentName
)
return
''
}
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录