Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MuGuiLin
uni-app
提交
3fc1d5a9
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,发现更多精彩内容 >>
提交
3fc1d5a9
编写于
1月 11, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(mp): externalClasses
上级
3ce5c1ee
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
105 addition
and
38 deletion
+105
-38
packages/uni-cli-shared/__tests__/externalClasses.spec.ts
packages/uni-cli-shared/__tests__/externalClasses.spec.ts
+15
-0
packages/uni-cli-shared/__tests__/usingComponents.spec.ts
packages/uni-cli-shared/__tests__/usingComponents.spec.ts
+1
-1
packages/uni-cli-shared/src/mp/ast.ts
packages/uni-cli-shared/src/mp/ast.ts
+13
-0
packages/uni-cli-shared/src/mp/externalClasses.ts
packages/uni-cli-shared/src/mp/externalClasses.ts
+49
-0
packages/uni-cli-shared/src/mp/index.ts
packages/uni-cli-shared/src/mp/index.ts
+7
-1
packages/uni-cli-shared/src/mp/usingComponents.ts
packages/uni-cli-shared/src/mp/usingComponents.ts
+1
-17
packages/uni-mp-compiler/src/transforms/transformComponent.ts
...ages/uni-mp-compiler/src/transforms/transformComponent.ts
+19
-19
未找到文件。
packages/uni-cli-shared/__tests__/externalClasses.spec.ts
0 → 100644
浏览文件 @
3fc1d5a9
import
{
parseProgram
}
from
'
../src/mp/ast
'
import
{
parseExternalClasses
}
from
'
../src/mp/externalClasses
'
describe
(
'
externalClasses
'
,
()
=>
{
const
filename
=
'
/usr/xxx/projects/test/src/components/test/test.vue
'
test
(
`basic`
,
async
()
=>
{
const
source
=
`
export default {
externalClasses: ['my-class']
}
`
const
program
=
parseProgram
(
source
,
filename
,
{})
expect
(
parseExternalClasses
(
program
)).
toEqual
([
'
my-class
'
])
})
})
packages/uni-cli-shared/__tests__/usingComponents.spec.ts
浏览文件 @
3fc1d5a9
import
path
from
'
path
'
import
{
ResolvedId
}
from
'
rollup
'
import
{
findUsingComponents
}
from
'
../src/json/mp/jsonFile
'
import
{
parseProgram
}
from
'
../src/mp/ast
'
import
{
parseMainDescriptor
,
parseProgram
,
transformDynamicImports
,
updateMiniProgramComponentsByMainFilename
,
updateMiniProgramGlobalComponents
,
...
...
packages/uni-cli-shared/src/mp/ast.ts
0 → 100644
浏览文件 @
3fc1d5a9
import
{
parse
,
ParserPlugin
}
from
'
@babel/parser
'
import
{
normalizeParsePlugins
}
from
'
../utils
'
export
function
parseProgram
(
code
:
string
,
importer
:
string
,
{
babelParserPlugins
}:
{
babelParserPlugins
?:
ParserPlugin
[]
}
)
{
return
parse
(
code
,
{
plugins
:
normalizeParsePlugins
(
importer
,
babelParserPlugins
),
sourceType
:
'
module
'
,
}).
program
}
packages/uni-cli-shared/src/mp/externalClasses.ts
0 → 100644
浏览文件 @
3fc1d5a9
import
{
isArrayExpression
,
isIdentifier
,
isObjectProperty
,
isStringLiteral
,
Program
,
}
from
'
@babel/types
'
import
{
walk
}
from
'
estree-walker
'
const
externalClassesCache
=
new
Map
<
string
,
string
[]
>
()
export
function
hasExternalClasses
(
code
:
string
)
{
return
code
.
includes
(
'
externalClasses
'
)
}
export
function
findMiniProgramComponentExternalClasses
(
filename
:
string
)
{
return
externalClassesCache
.
get
(
filename
)
}
export
function
updateMiniProgramComponentExternalClasses
(
filename
:
string
,
classes
:
string
[]
)
{
externalClassesCache
.
set
(
filename
,
classes
)
}
export
function
parseExternalClasses
(
ast
:
Program
)
{
const
classes
:
string
[]
=
[]
;(
walk
as
any
)(
ast
,
{
enter
(
child
:
Node
,
parent
:
Node
)
{
if
(
!
isIdentifier
(
child
)
||
child
.
name
!==
'
externalClasses
'
)
{
return
}
// export default { externalClasses: ['my-class'] }
if
(
!
isObjectProperty
(
parent
))
{
return
}
if
(
!
isArrayExpression
(
parent
.
value
))
{
return
}
parent
.
value
.
elements
.
forEach
((
element
)
=>
{
if
(
isStringLiteral
(
element
))
{
classes
.
push
(
element
.
value
)
}
})
},
})
return
classes
}
packages/uni-cli-shared/src/mp/index.ts
浏览文件 @
3fc1d5a9
export
*
from
'
./ast
'
export
*
from
'
./nvue
'
export
*
from
'
./event
'
export
*
from
'
./style
'
...
...
@@ -6,7 +7,6 @@ export * from './constants'
export
{
HTML_TO_MINI_PROGRAM_TAGS
}
from
'
./tags
'
export
{
copyMiniProgramPluginJson
}
from
'
./plugin
'
export
{
parseProgram
,
parseMainDescriptor
,
parseScriptDescriptor
,
parseTemplateDescriptor
,
...
...
@@ -16,3 +16,9 @@ export {
updateMiniProgramComponentsByScriptFilename
,
updateMiniProgramComponentsByTemplateFilename
,
}
from
'
./usingComponents
'
export
{
hasExternalClasses
,
parseExternalClasses
,
findMiniProgramComponentExternalClasses
,
updateMiniProgramComponentExternalClasses
,
}
from
'
./externalClasses
'
packages/uni-cli-shared/src/mp/usingComponents.ts
浏览文件 @
3fc1d5a9
...
...
@@ -17,7 +17,6 @@ import {
Statement
,
StringLiteral
,
}
from
'
@babel/types
'
import
{
parse
,
ParserPlugin
}
from
'
@babel/parser
'
import
{
walk
}
from
'
estree-walker
'
import
MagicString
from
'
magic-string
'
import
type
{
PluginContext
}
from
'
rollup
'
...
...
@@ -25,11 +24,7 @@ import { camelize, capitalize, hyphenate } from '@vue/shared'
import
{
addLeadingSlash
}
from
'
@dcloudio/uni-shared
'
import
{
M
}
from
'
../messages
'
import
{
BINDING_COMPONENTS
,
EXTNAME_VUE_RE
}
from
'
../constants
'
import
{
normalizeMiniProgramFilename
,
normalizeParsePlugins
,
removeExt
,
}
from
'
../utils
'
import
{
normalizeMiniProgramFilename
,
removeExt
}
from
'
../utils
'
import
{
cleanUrl
,
parseVueRequest
}
from
'
../vite/utils
'
import
{
addMiniProgramUsingComponents
}
from
'
../json/mp/jsonFile
'
...
...
@@ -38,17 +33,6 @@ type BindingComponents = Record<
{
tag
:
string
;
type
:
'
unknown
'
|
'
setup
'
|
'
self
'
}
>
export
function
parseProgram
(
code
:
string
,
importer
:
string
,
{
babelParserPlugins
}:
{
babelParserPlugins
?:
ParserPlugin
[]
}
)
{
return
parse
(
code
,
{
plugins
:
normalizeParsePlugins
(
importer
,
babelParserPlugins
),
sourceType
:
'
module
'
,
}).
program
}
const
mainDescriptors
=
new
Map
<
string
,
MainDescriptor
>
()
const
scriptDescriptors
=
new
Map
<
string
,
ScriptDescriptor
>
()
const
templateDescriptors
=
new
Map
<
string
,
TemplateDescriptor
>
()
...
...
packages/uni-mp-compiler/src/transforms/transformComponent.ts
浏览文件 @
3fc1d5a9
...
...
@@ -111,26 +111,26 @@ function processBooleanAttr({ props }: ComponentNode) {
})
}
const
builtInProps
=
[
'
class
'
,
'
style
'
,
ATTR_VUE_ID
,
ATTR_VUE_PROPS
,
ATTR_VUE_SLOTS
,
ATTR_VUE_REF
,
ATTR_VUE_REF_IN_FOR
,
ATTR_COM_TYPE
,
'
eO
'
,
'
e-o
'
,
'
onVI
'
,
'
ref
'
,
'
slot
'
,
'
key
'
,
'
is
'
,
]
function
isComponentProp
(
name
:
string
)
{
if
(
[
'
class
'
,
'
style
'
,
ATTR_VUE_ID
,
ATTR_VUE_PROPS
,
ATTR_VUE_SLOTS
,
ATTR_VUE_REF
,
ATTR_VUE_REF_IN_FOR
,
ATTR_COM_TYPE
,
'
eO
'
,
'
e-o
'
,
'
onVI
'
,
'
ref
'
,
'
slot
'
,
'
key
'
,
'
is
'
,
].
includes
(
name
)
)
{
if
(
builtInProps
.
includes
(
name
))
{
return
false
}
if
(
name
.
startsWith
(
'
data-
'
))
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录