Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
7bc2b65f
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
725
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,发现更多精彩内容 >>
提交
7bc2b65f
编写于
10月 28, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(mp): support node_modules component
上级
fddbaa7f
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
131 addition
and
64 deletion
+131
-64
packages/uni-cli-shared/src/mp/constants.ts
packages/uni-cli-shared/src/mp/constants.ts
+2
-0
packages/uni-cli-shared/src/mp/index.ts
packages/uni-cli-shared/src/mp/index.ts
+1
-0
packages/uni-cli-shared/src/utils.ts
packages/uni-cli-shared/src/utils.ts
+8
-7
packages/uni-cli-shared/src/vue/transforms/transformComponent.ts
...s/uni-cli-shared/src/vue/transforms/transformComponent.ts
+24
-19
packages/uni-mp-baidu/dist/uni.compiler.js
packages/uni-mp-baidu/dist/uni.compiler.js
+1
-1
packages/uni-mp-baidu/src/compiler/options.ts
packages/uni-mp-baidu/src/compiler/options.ts
+1
-1
packages/uni-mp-compiler/__tests__/component.spec.ts
packages/uni-mp-compiler/__tests__/component.spec.ts
+12
-20
packages/uni-mp-compiler/__tests__/slot.fallback.spec.ts
packages/uni-mp-compiler/__tests__/slot.fallback.spec.ts
+52
-0
packages/uni-mp-compiler/src/template/codegen.ts
packages/uni-mp-compiler/src/template/codegen.ts
+2
-1
packages/uni-mp-qq/dist/uni.compiler.js
packages/uni-mp-qq/dist/uni.compiler.js
+1
-1
packages/uni-mp-qq/src/compiler/options.ts
packages/uni-mp-qq/src/compiler/options.ts
+5
-2
packages/uni-mp-toutiao/dist/uni.compiler.js
packages/uni-mp-toutiao/dist/uni.compiler.js
+2
-2
packages/uni-mp-toutiao/src/compiler/options.ts
packages/uni-mp-toutiao/src/compiler/options.ts
+6
-3
packages/uni-mp-vite/src/plugin/build.ts
packages/uni-mp-vite/src/plugin/build.ts
+2
-4
packages/uni-mp-weixin/dist/uni.compiler.js
packages/uni-mp-weixin/dist/uni.compiler.js
+4
-1
packages/uni-mp-weixin/src/compiler/options.ts
packages/uni-mp-weixin/src/compiler/options.ts
+8
-2
未找到文件。
packages/uni-cli-shared/src/mp/constants.ts
0 → 100644
浏览文件 @
7bc2b65f
export
const
COMPONENT_ON_LINK
=
'
onVI
'
export
const
COMPONENT_BIND_LINK
=
'
__l
'
packages/uni-cli-shared/src/mp/index.ts
浏览文件 @
7bc2b65f
...
...
@@ -2,4 +2,5 @@ export * from './nvue'
export
*
from
'
./event
'
export
*
from
'
./style
'
export
*
from
'
./template
'
export
*
from
'
./constants
'
export
{
transformVueComponentImports
}
from
'
./transformImports
'
packages/uni-cli-shared/src/utils.ts
浏览文件 @
7bc2b65f
...
...
@@ -7,21 +7,22 @@ export { default as hash } from 'hash-sum'
import
{
PAGE_EXTNAME
,
PAGE_EXTNAME_APP
}
from
'
./constants
'
import
{
SFCTemplateCompileOptions
}
from
'
@vue/compiler-sfc
'
import
{
NodeTypes
,
ElementNode
,
Node
}
from
'
@vue/compiler-core
'
import
{
NodeTypes
,
ElementNode
,
RootNode
,
TemplateChildNode
,
}
from
'
@vue/compiler-core
'
export
const
isWindows
=
os
.
platform
()
===
'
win32
'
export
function
normalizePath
(
id
:
string
):
string
{
return
isWindows
?
id
.
replace
(
/
\\
/g
,
'
/
'
)
:
id
}
export
function
checkElementNodeTag
(
node
:
Node
|
null
|
undefined
,
node
:
RootNode
|
TemplateChild
Node
|
null
|
undefined
,
tag
:
string
):
node
is
ElementNode
{
return
(
!!
node
&&
node
.
type
===
NodeTypes
.
ELEMENT
&&
(
node
as
ElementNode
).
tag
===
tag
)
return
!!
node
&&
node
.
type
===
NodeTypes
.
ELEMENT
&&
node
.
tag
===
tag
}
export
const
resolveMainPathOnce
=
once
((
inputDir
:
string
)
=>
{
...
...
packages/uni-cli-shared/src/vue/transforms/transformComponent.ts
浏览文件 @
7bc2b65f
...
...
@@ -9,30 +9,35 @@ import {
TemplateChildNode
,
TransformContext
,
}
from
'
@vue/compiler-core
'
import
{
COMPONENT_BIND_LINK
,
COMPONENT_ON_LINK
}
from
'
../../mp/constants
'
export
function
addComponentBindLink
(
node
:
RootNode
|
TemplateChildNode
,
context
:
TransformContext
export
function
createTransformComponentLink
(
name
:
typeof
COMPONENT_BIND_LINK
|
typeof
COMPONENT_ON_LINK
)
{
if
(
node
.
type
===
NodeTypes
.
ELEMENT
&&
node
.
tagType
===
ElementTypes
.
COMPONENT
return
function
transformComponentLink
(
node
:
RootNode
|
TemplateChildNode
,
context
:
TransformContext
)
{
const
{
tag
}
=
node
if
(
isComponentTag
(
tag
)
||
isCoreComponent
(
tag
)
||
context
.
isBuiltInComponent
(
tag
)
node
.
type
===
NodeTypes
.
ELEMENT
&&
node
.
tagType
===
ElementTypes
.
COMPONENT
)
{
return
const
{
tag
}
=
node
if
(
isComponentTag
(
tag
)
||
isCoreComponent
(
tag
)
||
context
.
isBuiltInComponent
(
tag
)
)
{
return
}
node
.
props
.
push
({
type
:
NodeTypes
.
DIRECTIVE
,
name
:
'
on
'
,
modifiers
:
[],
loc
:
locStub
,
arg
:
createSimpleExpression
(
name
,
true
),
exp
:
createSimpleExpression
(
'
__l
'
,
true
),
})
}
node
.
props
.
push
({
type
:
NodeTypes
.
DIRECTIVE
,
name
:
'
on
'
,
modifiers
:
[],
loc
:
locStub
,
arg
:
createSimpleExpression
(
'
__l
'
,
true
),
exp
:
createSimpleExpression
(
'
__l
'
,
true
),
})
}
}
packages/uni-mp-baidu/dist/uni.compiler.js
浏览文件 @
7bc2b65f
...
...
@@ -148,7 +148,7 @@ const miniProgram = {
array
:
true
,
},
slot
:
{
fallback
:
fals
e
,
fallback
:
tru
e
,
},
directive
:
'
s-
'
,
};
...
...
packages/uni-mp-baidu/src/compiler/options.ts
浏览文件 @
7bc2b65f
...
...
@@ -12,7 +12,7 @@ export const miniProgram: MiniProgramCompilerOptions = {
array
:
true
,
},
slot
:
{
fallback
:
fals
e
,
fallback
:
tru
e
,
},
directive
:
'
s-
'
,
}
...
...
packages/uni-mp-compiler/__tests__/component.spec.ts
浏览文件 @
7bc2b65f
import
{
addComponentBindLink
}
from
'
@dcloudio/uni-cli-shared
'
import
{
COMPONENT_BIND_LINK
,
createTransformComponentLink
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
assert
}
from
'
./testUtils
'
const
nodeTransforms
=
[
createTransformComponentLink
(
COMPONENT_BIND_LINK
)]
describe
(
'
compiler: transform component
'
,
()
=>
{
// test('basic', () => {
// assert(
// `<custom/>`,
// `<custom v-i="2a9ec0b0-0" bind:__l="__l"/>`,
// `(_ctx, _cache) => {
// return {}
// }`,
// {
// nodeTransforms: [addComponentBindLink as any],
// }
// )
// })
test
(
'
component + component
'
,
()
=>
{
assert
(
`<custom><custom1/></custom>`
,
...
...
@@ -22,7 +14,7 @@ describe('compiler: transform component', () => {
return {}
}`
,
{
nodeTransforms
:
[
addComponentBindLink
as
any
]
,
nodeTransforms
,
}
)
})
...
...
@@ -34,7 +26,7 @@ describe('compiler: transform component', () => {
return {}
}`
,
{
nodeTransforms
:
[
addComponentBindLink
as
any
]
,
nodeTransforms
,
}
)
})
...
...
@@ -46,7 +38,7 @@ describe('compiler: transform component', () => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }) }
}`
,
{
nodeTransforms
:
[
addComponentBindLink
as
any
]
,
nodeTransforms
,
}
)
assert
(
...
...
@@ -56,7 +48,7 @@ describe('compiler: transform component', () => {
return { a: _f(_ctx.items, (item, key, index) => { return { a: '2a9ec0b0-0' + '-' + index }; }) }
}`
,
{
nodeTransforms
:
[
addComponentBindLink
as
any
]
,
nodeTransforms
,
}
)
})
...
...
@@ -68,7 +60,7 @@ describe('compiler: transform component', () => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0' }; }) }
}`
,
{
nodeTransforms
:
[
addComponentBindLink
as
any
]
,
nodeTransforms
,
}
)
})
...
...
@@ -80,7 +72,7 @@ describe('compiler: transform component', () => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-1' + '-' + i0 + ',' + ('2a9ec0b0-0' + '-' + i0), b: '2a9ec0b0-0' + '-' + i0 }; }) }
}`
,
{
nodeTransforms
:
[
addComponentBindLink
as
any
]
,
nodeTransforms
,
}
)
})
...
...
@@ -92,7 +84,7 @@ describe('compiler: transform component', () => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _f(item.items, (item1, k1, i1) => { return { a: '2a9ec0b0-1' + '-' + i0 + '-' + i1 + ',' + ('2a9ec0b0-0' + '-' + i0) }; }), b: '2a9ec0b0-0' + '-' + i0 }; }) }
}`
,
{
nodeTransforms
:
[
addComponentBindLink
as
any
]
,
nodeTransforms
,
}
)
})
...
...
packages/uni-mp-compiler/__tests__/slot.fallback.spec.ts
0 → 100644
浏览文件 @
7bc2b65f
import
{
assert
,
miniProgram
}
from
'
./testUtils
'
const
options
=
{
miniProgram
:
{
...
miniProgram
,
slot
:
{
fallback
:
true
,
},
},
}
describe
(
'
compiler: transform slot
'
,
()
=>
{
test
(
'
basic
'
,
()
=>
{
assert
(
`<button><slot/></button>`
,
`<button><slot/></button>`
,
`(_ctx, _cache) => {
return {}
}`
,
options
)
})
test
(
'
fallback content
'
,
()
=>
{
assert
(
`<button><slot>Submit</slot></button>`
,
`<button><slot>Submit</slot></button>`
,
`(_ctx, _cache) => {
return {}
}`
,
options
)
})
test
(
'
names slots
'
,
()
=>
{
assert
(
`<button><slot name="text"/></button>`
,
`<button><slot name="text"/></button>`
,
`(_ctx, _cache) => {
return {}
}`
,
options
)
})
test
(
'
names slots with fallback content
'
,
()
=>
{
assert
(
`<button><slot name="text">Submit</slot></button>`
,
`<button><slot name="text">Submit</slot></button>`
,
`(_ctx, _cache) => {
return {}
}`
,
options
)
})
})
packages/uni-mp-compiler/src/template/codegen.ts
浏览文件 @
7bc2b65f
...
...
@@ -114,7 +114,8 @@ function genVFor(
function
genSlot
(
node
:
SlotOutletNode
,
context
:
TemplateCodegenContext
)
{
// 移除掉所有非name属性,即移除作用域插槽的绑定指令
node
.
props
=
node
.
props
.
filter
((
prop
)
=>
prop
.
name
===
'
name
'
)
if
(
!
node
.
children
.
length
)
{
if
(
!
node
.
children
.
length
||
context
.
slot
.
fallback
)
{
// 无后备内容或支持后备内容
return
genElement
(
node
,
context
)
}
const
children
=
node
.
children
.
slice
()
...
...
packages/uni-mp-qq/dist/uni.compiler.js
浏览文件 @
7bc2b65f
...
...
@@ -133,7 +133,7 @@ const options = {
extname
:
'
.qml
'
,
directive
:
'
qq:
'
,
compilerOptions
:
{
nodeTransforms
:
[
uniCliShared
.
addComponentBindLink
],
nodeTransforms
:
[
uniCliShared
.
createTransformComponentLink
(
uniCliShared
.
COMPONENT_BIND_LINK
)
],
},
},
style
:
{
...
...
packages/uni-mp-qq/src/compiler/options.ts
浏览文件 @
7bc2b65f
import
path
from
'
path
'
import
{
addComponentBindLink
}
from
'
@dcloudio/uni-cli-shared
'
import
{
COMPONENT_BIND_LINK
,
createTransformComponentLink
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
UniMiniProgramPluginOptions
}
from
'
@dcloudio/uni-mp-vite
'
import
source
from
'
./project.config.json
'
...
...
@@ -56,7 +59,7 @@ export const options: UniMiniProgramPluginOptions = {
extname
:
'
.qml
'
,
directive
:
'
qq:
'
,
compilerOptions
:
{
nodeTransforms
:
[
addComponentBindLink
],
nodeTransforms
:
[
createTransformComponentLink
(
COMPONENT_BIND_LINK
)
],
},
},
style
:
{
...
...
packages/uni-mp-toutiao/dist/uni.compiler.js
浏览文件 @
7bc2b65f
...
...
@@ -69,12 +69,12 @@ ${filter.code}
},
},
slot
:
{
fallback
:
fals
e
,
fallback
:
tru
e
,
},
extname
:
'
.ttml
'
,
directive
:
'
tt:
'
,
compilerOptions
:
{
nodeTransforms
:
[
uniCliShared
.
addComponentBindLink
],
nodeTransforms
:
[
uniCliShared
.
createTransformComponentLink
(
uniCliShared
.
COMPONENT_BIND_LINK
)
],
},
},
style
:
{
...
...
packages/uni-mp-toutiao/src/compiler/options.ts
浏览文件 @
7bc2b65f
import
path
from
'
path
'
import
{
addComponentBindLink
}
from
'
@dcloudio/uni-cli-shared
'
import
{
COMPONENT_BIND_LINK
,
createTransformComponentLink
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
UniMiniProgramPluginOptions
}
from
'
@dcloudio/uni-mp-vite
'
import
source
from
'
./project.config.json
'
...
...
@@ -44,12 +47,12 @@ ${filter.code}
},
},
slot
:
{
fallback
:
fals
e
,
fallback
:
tru
e
,
},
extname
:
'
.ttml
'
,
directive
:
'
tt:
'
,
compilerOptions
:
{
nodeTransforms
:
[
addComponentBindLink
],
nodeTransforms
:
[
createTransformComponentLink
(
COMPONENT_BIND_LINK
)
],
},
},
style
:
{
...
...
packages/uni-mp-vite/src/plugin/build.ts
浏览文件 @
7bc2b65f
...
...
@@ -11,6 +11,7 @@ import {
hasJsonFile
,
removeExt
,
resolveMainPathOnce
,
normalizeMiniProgramFilename
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
GetManualChunk
,
GetModuleInfo
}
from
'
rollup
'
import
{
...
...
@@ -57,10 +58,7 @@ export function buildOptions(): UserConfig['build'] {
parseVirtualComponentPath
(
id
)
)
}
const
filepath
=
path
.
relative
(
inputDir
,
id
)
return
normalizePath
(
filepath
.
replace
(
path
.
extname
(
filepath
),
'
.js
'
)
)
return
removeExt
(
normalizeMiniProgramFilename
(
id
,
inputDir
))
+
'
.js
'
}
return
'
[name].js
'
},
...
...
packages/uni-mp-weixin/dist/uni.compiler.js
浏览文件 @
7bc2b65f
...
...
@@ -117,7 +117,10 @@ ${filter.code}
extname
:
'
.wxml
'
,
directive
:
'
wx:
'
,
compilerOptions
:
{
nodeTransforms
:
[
uniCliShared
.
addComponentBindLink
],
isCustomElement
:
(
tag
)
=>
{
return
[
'
page-meta
'
,
'
navigation-bar
'
,
'
match-media
'
].
includes
(
tag
);
},
nodeTransforms
:
[
uniCliShared
.
createTransformComponentLink
(
uniCliShared
.
COMPONENT_BIND_LINK
)],
},
},
style
:
{
...
...
packages/uni-mp-weixin/src/compiler/options.ts
浏览文件 @
7bc2b65f
import
path
from
'
path
'
import
{
addComponentBindLink
}
from
'
@dcloudio/uni-cli-shared
'
import
{
COMPONENT_BIND_LINK
,
createTransformComponentLink
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
UniMiniProgramPluginOptions
}
from
'
@dcloudio/uni-mp-vite
'
import
source
from
'
./project.config.json
'
...
...
@@ -65,7 +68,10 @@ ${filter.code}
extname
:
'
.wxml
'
,
directive
:
'
wx:
'
,
compilerOptions
:
{
nodeTransforms
:
[
addComponentBindLink
],
isCustomElement
:
(
tag
)
=>
{
return
[
'
page-meta
'
,
'
navigation-bar
'
,
'
match-media
'
].
includes
(
tag
)
},
nodeTransforms
:
[
createTransformComponentLink
(
COMPONENT_BIND_LINK
)],
},
},
style
:
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录