Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
40c59751
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
720
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
40c59751
编写于
9月 10, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mp): support app.component #2872
上级
1807150c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
29 addition
and
18 deletion
+29
-18
packages/webpack-uni-mp-loader/lib/babel/global-component-traverse.js
...pack-uni-mp-loader/lib/babel/global-component-traverse.js
+20
-11
packages/webpack-uni-mp-loader/lib/babel/scoped-component-traverse.js
...pack-uni-mp-loader/lib/babel/scoped-component-traverse.js
+1
-1
packages/webpack-uni-mp-loader/lib/babel/util.js
packages/webpack-uni-mp-loader/lib/babel/util.js
+8
-6
未找到文件。
packages/webpack-uni-mp-loader/lib/babel/global-component-traverse.js
浏览文件 @
40c59751
const
t
=
require
(
'
@babel/types
'
)
const
babelTraverse
=
require
(
'
@babel/traverse
'
).
default
const
{
parseComponents
}
=
require
(
'
./util
'
)
const
{
parseComponents
}
=
require
(
'
./util
'
)
const
uniI18n
=
require
(
'
@dcloudio/uni-cli-i18n
'
)
module
.
exports
=
function
(
ast
,
state
=
{})
{
const
imports
=
[]
let
bindings
=
false
let
parentPath
=
false
let
nodePath
=
false
babelTraverse
(
ast
,
{
CallExpression
(
path
)
{
const
callee
=
path
.
node
.
callee
if
(
!
callee
.
object
||
!
callee
.
property
)
{
return
}
if
(
callee
.
object
.
name
===
'
Vue
'
&&
callee
.
property
.
name
===
'
component
'
)
{
parentPath
=
path
.
parentPath
bindings
=
path
.
scope
.
bindings
const
objectName
=
callee
.
object
.
name
const
propertyName
=
callee
.
property
.
name
if
(
propertyName
===
'
component
'
&&
(
objectName
===
'
Vue
'
||
objectName
===
'
app
'
)
)
{
const
args
=
path
.
node
.
arguments
const
nameNode
=
args
[
0
]
const
valueNode
=
args
[
1
]
nodePath
=
path
if
(
!
t
.
isStringLiteral
(
nameNode
))
{
throw
new
Error
(
uniI18n
.
__
(
'
mpLoader.firstParameterNeedStaticString
'
,
{
0
:
'
Vue.component()
'
}))
throw
new
Error
(
uniI18n
.
__
(
'
mpLoader.firstParameterNeedStaticString
'
,
{
0
:
objectName
+
'
.component()
'
})
)
}
if
(
!
t
.
isIdentifier
(
valueNode
))
{
throw
new
Error
(
uniI18n
.
__
(
'
mpLoader.requireTwoParameter
'
,
{
0
:
'
Vue.component()
'
}))
throw
new
Error
(
uniI18n
.
__
(
'
mpLoader.requireTwoParameter
'
,
{
0
:
objectName
+
'
.component()
'
})
)
}
imports
.
push
({
name
:
nameNode
.
value
,
...
...
@@ -37,7 +46,7 @@ module.exports = function (ast, state = {}) {
}
})
if
(
imports
.
length
)
{
state
.
components
=
parseComponents
(
imports
,
bindings
,
parent
Path
)
state
.
components
=
parseComponents
(
imports
,
node
Path
)
}
else
{
state
.
components
=
[]
}
...
...
packages/webpack-uni-mp-loader/lib/babel/scoped-component-traverse.js
浏览文件 @
40c59751
...
...
@@ -61,7 +61,7 @@ function handleComponentsObjectExpression (componentsObjExpr, path, state, prepe
name
:
prop
.
key
.
name
||
prop
.
key
.
value
,
value
:
prop
.
value
.
name
}
}),
path
.
scope
.
bindings
,
path
)
}),
path
)
state
.
components
=
prepend
?
components
.
concat
(
state
.
components
)
:
components
}
...
...
packages/webpack-uni-mp-loader/lib/babel/util.js
浏览文件 @
40c59751
...
...
@@ -15,8 +15,8 @@ const hyphenate = cached((str) => {
return
str
.
replace
(
hyphenateRE
,
'
-$1
'
).
toLowerCase
()
})
function
findImportDeclaration
(
identifierName
,
bindings
)
{
const
binding
=
bindings
[
identifierName
]
function
findImportDeclaration
(
identifierName
,
path
)
{
const
binding
=
path
.
scope
.
getBinding
(
identifierName
)
if
(
!
binding
)
{
return
}
...
...
@@ -26,16 +26,18 @@ function findImportDeclaration (identifierName, bindings) {
}
}
function
parseComponents
(
names
,
bindings
,
path
)
{
function
parseComponents
(
names
,
path
)
{
const
components
=
[]
const
dynamicImportMap
=
new
Map
()
names
.
forEach
(({
name
,
value
})
=>
{
const
importDeclaration
=
findImportDeclaration
(
value
,
bindings
)
const
importDeclaration
=
findImportDeclaration
(
value
,
path
)
if
(
!
importDeclaration
)
{
throw
new
Error
(
uniI18n
.
__
(
'
mpLoader.componentReferenceErrorOnlySupportImport
'
,
{
0
:
name
}))
throw
new
Error
(
uniI18n
.
__
(
'
mpLoader.componentReferenceErrorOnlySupportImport
'
,
{
0
:
name
}))
}
let
source
=
importDeclaration
.
node
.
source
.
value
if
(
process
.
UNI_LIBRARIES
&&
process
.
UNI_LIBRARIES
.
includes
(
source
))
{
...
...
@@ -83,4 +85,4 @@ module.exports = {
addDynamicImport
,
findBabelLoader
,
parseComponents
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录