Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
5b70a108
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,发现更多精彩内容 >>
提交
5b70a108
编写于
10月 14, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(mp): add directive option
上级
e3ac1ea3
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
31 addition
and
13 deletion
+31
-13
packages/uni-mp-compiler/__tests__/test.spec.ts
packages/uni-mp-compiler/__tests__/test.spec.ts
+1
-0
packages/uni-mp-compiler/__tests__/testUtils.ts
packages/uni-mp-compiler/__tests__/testUtils.ts
+1
-0
packages/uni-mp-compiler/__tests__/vBind.spec.ts
packages/uni-mp-compiler/__tests__/vBind.spec.ts
+8
-0
packages/uni-mp-compiler/src/compile.ts
packages/uni-mp-compiler/src/compile.ts
+1
-0
packages/uni-mp-compiler/src/options.ts
packages/uni-mp-compiler/src/options.ts
+2
-0
packages/uni-mp-compiler/src/template/codegen.ts
packages/uni-mp-compiler/src/template/codegen.ts
+14
-12
packages/uni-mp-vite/src/plugin/index.ts
packages/uni-mp-vite/src/plugin/index.ts
+2
-1
packages/uni-mp-vite/src/plugin/uni/index.ts
packages/uni-mp-vite/src/plugin/uni/index.ts
+1
-0
packages/uni-mp-weixin/src/plugin/index.ts
packages/uni-mp-weixin/src/plugin/index.ts
+1
-0
未找到文件。
packages/uni-mp-compiler/__tests__/test.spec.ts
浏览文件 @
5b70a108
...
...
@@ -14,6 +14,7 @@ function assert(
prefixIdentifiers
:
true
,
inline
:
true
,
miniProgram
:
{
directive
:
'
wx:
'
,
emitFile
({
source
})
{
console
.
log
(
source
)
// expect(source).toBe(templateCode)
...
...
packages/uni-mp-compiler/__tests__/testUtils.ts
浏览文件 @
5b70a108
...
...
@@ -15,6 +15,7 @@ export function assert(
prefixIdentifiers
:
true
,
inline
:
true
,
miniProgram
:
{
directive
:
'
wx:
'
,
emitFile
({
source
})
{
// console.log(source)
if
(
!
options
.
onError
)
{
...
...
packages/uni-mp-compiler/__tests__/vBind.spec.ts
浏览文件 @
5b70a108
...
...
@@ -30,6 +30,7 @@ describe('compiler: transform v-bind', () => {
onError
,
filename
:
'
foo.vue
'
,
miniProgram
:
{
directive
:
'
wx:
'
,
emitFile
({
source
})
{
expect
(
source
).
toBe
(
`<view/>`
)
return
''
...
...
@@ -53,6 +54,7 @@ describe('compiler: transform v-bind', () => {
onError
,
filename
:
'
foo.vue
'
,
miniProgram
:
{
directive
:
'
wx:
'
,
emitFile
({
source
})
{
expect
(
source
).
toBe
(
`<view/>`
)
return
''
...
...
@@ -123,6 +125,7 @@ describe('compiler: transform v-bind', () => {
prefixIdentifiers
:
false
,
filename
:
'
foo.vue
'
,
miniProgram
:
{
directive
:
'
wx:
'
,
emitFile
({
source
})
{
expect
(
source
).
toBe
(
`<view/>`
)
return
''
...
...
@@ -151,6 +154,7 @@ describe('compiler: transform v-bind', () => {
prefixIdentifiers
:
true
,
filename
:
'
foo.vue
'
,
miniProgram
:
{
directive
:
'
wx:
'
,
emitFile
({
source
})
{
expect
(
source
).
toBe
(
`<view/>`
)
return
''
...
...
@@ -197,6 +201,7 @@ describe('compiler: transform v-bind', () => {
filename
:
'
foo.vue
'
,
prefixIdentifiers
:
false
,
miniProgram
:
{
directive
:
'
wx:
'
,
emitFile
({
source
})
{
expect
(
source
).
toBe
(
`<view/>`
)
return
''
...
...
@@ -225,6 +230,7 @@ describe('compiler: transform v-bind', () => {
prefixIdentifiers
:
true
,
filename
:
'
foo.vue
'
,
miniProgram
:
{
directive
:
'
wx:
'
,
emitFile
({
source
})
{
expect
(
source
).
toBe
(
`<view/>`
)
return
''
...
...
@@ -252,6 +258,7 @@ describe('compiler: transform v-bind', () => {
onWarn
,
filename
:
'
foo.vue
'
,
miniProgram
:
{
directive
:
'
wx:
'
,
emitFile
({
source
})
{
expect
(
source
).
toBe
(
`<view fooBar="{{a}}"/>`
)
return
''
...
...
@@ -279,6 +286,7 @@ describe('compiler: transform v-bind', () => {
onWarn
,
filename
:
'
foo.vue
'
,
miniProgram
:
{
directive
:
'
wx:
'
,
emitFile
({
source
})
{
expect
(
source
).
toBe
(
`<view foo-bar="{{a}}"/>`
)
return
''
...
...
packages/uni-mp-compiler/src/compile.ts
浏览文件 @
5b70a108
...
...
@@ -60,6 +60,7 @@ export function baseCompile(template: string, options: CompilerOptions = {}) {
if
(
options
.
filename
&&
options
.
miniProgram
?.
emitFile
)
{
genTemplate
(
ast
,
{
filename
:
options
.
filename
,
directive
:
options
.
miniProgram
.
directive
,
emitFile
:
options
.
miniProgram
.
emitFile
,
})
}
...
...
packages/uni-mp-compiler/src/options.ts
浏览文件 @
5b70a108
...
...
@@ -63,12 +63,14 @@ export interface CodegenOptions extends SharedTransformCodegenOptions {
runtimeModuleName
?:
string
runtimeGlobalName
?:
string
miniProgram
?:
{
directive
:
string
emitFile
?:
(
emittedFile
:
EmittedFile
)
=>
string
}
}
export
interface
TemplateCodegenOptions
{
filename
:
string
directive
:
string
emitFile
:
(
emittedFile
:
EmittedFile
)
=>
string
}
...
...
packages/uni-mp-compiler/src/template/codegen.ts
浏览文件 @
5b70a108
...
...
@@ -17,15 +17,17 @@ import { isForElementNode, VForOptions } from '../transforms/vFor'
import
{
IfElementNode
,
isIfElementNode
}
from
'
../transforms/vIf
'
interface
TemplateCodegenContext
{
code
:
string
directive
:
string
push
(
code
:
string
):
void
}
export
function
generate
(
{
children
}:
RootNode
,
{
emitFile
,
filename
}:
TemplateCodegenOptions
{
emitFile
,
filename
,
directive
}:
TemplateCodegenOptions
)
{
const
context
:
TemplateCodegenContext
=
{
code
:
''
,
directive
,
push
(
code
)
{
context
.
code
+=
code
},
...
...
@@ -62,32 +64,32 @@ function genExpression(node: ExpressionNode, { push }: TemplateCodegenContext) {
push
(
`{{
${
genExpr
(
node
)}
}}`
)
}
function
genVIf
(
exp
:
string
,
{
push
}:
TemplateCodegenContext
)
{
push
(
`
wx:
if="{{
${
exp
}
}}"`
)
function
genVIf
(
exp
:
string
,
{
push
,
directive
}:
TemplateCodegenContext
)
{
push
(
`
${
directive
}
if="{{
${
exp
}
}}"`
)
}
function
genVElseIf
(
exp
:
string
,
{
push
}:
TemplateCodegenContext
)
{
push
(
`
wx:
elif="{{
${
exp
}
}}"`
)
function
genVElseIf
(
exp
:
string
,
{
push
,
directive
}:
TemplateCodegenContext
)
{
push
(
`
${
directive
}
elif="{{
${
exp
}
}}"`
)
}
function
genVElse
({
push
}:
TemplateCodegenContext
)
{
push
(
`
wx:
else`
)
function
genVElse
({
push
,
directive
}:
TemplateCodegenContext
)
{
push
(
`
${
directive
}
else`
)
}
function
genVFor
(
{
sourceAlias
,
valueAlias
,
keyAlias
}:
VForOptions
,
node
:
ElementNode
,
{
push
}:
TemplateCodegenContext
{
push
,
directive
}:
TemplateCodegenContext
)
{
push
(
`
wx:
for="{{
${
sourceAlias
}
}}"`
)
push
(
`
${
directive
}
for="{{
${
sourceAlias
}
}}"`
)
if
(
valueAlias
)
{
push
(
`
wx:
for-item="
${
valueAlias
}
"`
)
push
(
`
${
directive
}
for-item="
${
valueAlias
}
"`
)
}
if
(
keyAlias
)
{
push
(
`
wx:
for-index="
${
keyAlias
}
"`
)
push
(
`
${
directive
}
for-index="
${
keyAlias
}
"`
)
}
const
keyProp
=
findProp
(
node
,
'
key
'
,
true
)
if
(
keyProp
)
{
const
key
=
((
keyProp
as
DirectiveNode
).
exp
as
SimpleExpressionNode
).
content
push
(
`
wx:
key="
${
key
.
includes
(
'
.
'
)
?
key
.
split
(
'
.
'
)[
1
]
:
key
}
"`
)
push
(
`
${
directive
}
key="
${
key
.
includes
(
'
.
'
)
?
key
.
split
(
'
.
'
)[
1
]
:
key
}
"`
)
node
.
props
.
splice
(
node
.
props
.
indexOf
(
keyProp
),
1
)
}
}
...
...
packages/uni-mp-vite/src/plugin/index.ts
浏览文件 @
5b70a108
...
...
@@ -32,6 +32,7 @@ export interface UniMiniProgramPluginOptions {
}
template
:
{
extname
:
string
directive
:
string
}
style
:
{
extname
:
string
...
...
@@ -75,7 +76,7 @@ export function uniMiniProgramPlugin(
name
:
'
vite:uni-mp
'
,
uni
:
uniOptions
({
copyOptions
,
miniProgram
:
{
emitFile
},
miniProgram
:
{
directive
:
template
.
directive
,
emitFile
},
}),
config
()
{
return
{
...
...
packages/uni-mp-vite/src/plugin/uni/index.ts
浏览文件 @
5b70a108
...
...
@@ -14,6 +14,7 @@ export function uniOptions({
}:
{
copyOptions
:
CopyOptions
miniProgram
:
{
directive
:
string
emitFile
?:
(
emittedFile
:
EmittedFile
)
=>
string
}
}):
UniVitePlugin
[
'
uni
'
]
{
...
...
packages/uni-mp-weixin/src/plugin/index.ts
浏览文件 @
5b70a108
...
...
@@ -56,6 +56,7 @@ const options: UniMiniProgramPluginOptions = {
},
template
:
{
extname
:
'
.wxml
'
,
directive
:
'
wx:
'
,
},
style
:
{
extname
:
'
.wxss
'
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录