Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yangkaifeng
uni-app
提交
0ae56fc0
U
uni-app
项目概览
yangkaifeng
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
3
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,发现更多精彩内容 >>
提交
0ae56fc0
编写于
11月 24, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mp): component with v-show
上级
3672ac6f
变更
19
显示空白变更内容
内联
并排
Showing
19 changed file
with
109 addition
and
21 deletion
+109
-21
packages/uni-cli-shared/src/mp/constants.ts
packages/uni-cli-shared/src/mp/constants.ts
+2
-0
packages/uni-cli-shared/src/mp/template.ts
packages/uni-cli-shared/src/mp/template.ts
+6
-0
packages/uni-cli-shared/src/vue/utils.ts
packages/uni-cli-shared/src/vue/utils.ts
+3
-1
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+9
-12
packages/uni-mp-compiler/src/compile.ts
packages/uni-mp-compiler/src/compile.ts
+3
-0
packages/uni-mp-compiler/src/options.ts
packages/uni-mp-compiler/src/options.ts
+1
-0
packages/uni-mp-compiler/src/template/codegen.ts
packages/uni-mp-compiler/src/template/codegen.ts
+22
-6
packages/uni-mp-lark/dist/uni.compiler.js
packages/uni-mp-lark/dist/uni.compiler.js
+3
-0
packages/uni-mp-qq/__tests__/component.spec.ts
packages/uni-mp-qq/__tests__/component.spec.ts
+9
-0
packages/uni-mp-qq/dist/uni.compiler.js
packages/uni-mp-qq/dist/uni.compiler.js
+3
-0
packages/uni-mp-qq/src/compiler/options.ts
packages/uni-mp-qq/src/compiler/options.ts
+4
-0
packages/uni-mp-toutiao/__tests__/component.spec.ts
packages/uni-mp-toutiao/__tests__/component.spec.ts
+9
-0
packages/uni-mp-toutiao/dist/uni.compiler.js
packages/uni-mp-toutiao/dist/uni.compiler.js
+3
-0
packages/uni-mp-toutiao/src/compiler/options.ts
packages/uni-mp-toutiao/src/compiler/options.ts
+4
-0
packages/uni-mp-vite/src/plugin/configResolved.ts
packages/uni-mp-vite/src/plugin/configResolved.ts
+10
-2
packages/uni-mp-vite/src/plugin/index.ts
packages/uni-mp-vite/src/plugin/index.ts
+2
-0
packages/uni-mp-weixin/__tests__/component.spec.ts
packages/uni-mp-weixin/__tests__/component.spec.ts
+9
-0
packages/uni-mp-weixin/dist/uni.compiler.js
packages/uni-mp-weixin/dist/uni.compiler.js
+3
-0
packages/uni-mp-weixin/src/compiler/options.ts
packages/uni-mp-weixin/src/compiler/options.ts
+4
-0
未找到文件。
packages/uni-cli-shared/src/mp/constants.ts
浏览文件 @
0ae56fc0
export
const
COMPONENT_ON_LINK
=
'
onVI
'
export
const
COMPONENT_ON_LINK
=
'
onVI
'
export
const
COMPONENT_BIND_LINK
=
'
__l
'
export
const
COMPONENT_BIND_LINK
=
'
__l
'
export
const
COMPONENT_CUSTOM_HIDDEN
=
'
data-c-h
'
export
const
COMPONENT_CUSTOM_HIDDEN_BIND
=
'
bind:-
'
+
COMPONENT_CUSTOM_HIDDEN
packages/uni-cli-shared/src/mp/template.ts
浏览文件 @
0ae56fc0
...
@@ -39,6 +39,12 @@ export interface MiniProgramCompilerOptions {
...
@@ -39,6 +39,12 @@ export interface MiniProgramCompilerOptions {
filter
?:
{
filter
?:
{
lang
:
string
lang
:
string
}
}
component
?:
{
/**
* 自定义组件自定义 hidden 属性用于实现 v-show
*/
vShow
:
string
}
directive
:
str
ing
directive
:
str
ing
emitFile
?:
(
emittedFile
:
EmittedAsset
)
=>
string
emitFile
?:
(
emittedFile
:
EmittedAsset
)
=>
string
}
}
...
...
packages/uni-cli-shared/src/vue/utils.ts
浏览文件 @
0ae56fc0
...
@@ -23,7 +23,9 @@ export const VUE_REF_IN_FOR = 'r-i-f'
...
@@ -23,7 +23,9 @@ export const VUE_REF_IN_FOR = 'r-i-f'
export
function
isUserComponent
(
export
function
isUserComponent
(
node
:
RootNode
|
TemplateChildNode
,
node
:
RootNode
|
TemplateChildNode
,
context
:
TransformContext
context
:
{
isBuiltInComponent
:
TransformContext
[
'
isBuiltInComponent
'
]
}
):
node
is
ComponentNode
{
):
node
is
ComponentNode
{
return
(
return
(
node
.
type
===
NodeTypes
.
ELEMENT
&&
node
.
type
===
NodeTypes
.
ELEMENT
&&
...
...
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
0ae56fc0
...
@@ -16784,10 +16784,9 @@ const chooseFile = /* @__PURE__ */ defineAsyncApi(API_CHOOSE_FILE, ({
...
@@ -16784,10 +16784,9 @@ const chooseFile = /* @__PURE__ */ defineAsyncApi(API_CHOOSE_FILE, ({
};
};
resolve(res);
resolve(res);
});
});
if (getInteractStatus()) {
fileInput.click();
fileInput.click();
} else
{
if (!getInteractStatus())
{
reject
(t2("uni.chooseFile.notUserActivation"));
console.warn
(t2("uni.chooseFile.notUserActivation"));
}
}
}, ChooseFileProtocol, ChooseFileOptions);
}, ChooseFileProtocol, ChooseFileOptions);
let imageInput = null;
let imageInput = null;
...
@@ -16835,10 +16834,9 @@ const chooseImage = /* @__PURE__ */ defineAsyncApi(API_CHOOSE_IMAGE, ({
...
@@ -16835,10 +16834,9 @@ const chooseImage = /* @__PURE__ */ defineAsyncApi(API_CHOOSE_IMAGE, ({
};
};
resolve(res);
resolve(res);
});
});
if (getInteractStatus()) {
imageInput.click();
imageInput.click();
} else
{
if (!getInteractStatus())
{
reject
(t2("uni.chooseFile.notUserActivation"));
console.warn
(t2("uni.chooseFile.notUserActivation"));
}
}
}, ChooseImageProtocol, ChooseImageOptions);
}, ChooseImageProtocol, ChooseImageOptions);
let index$c = 0;
let index$c = 0;
...
@@ -17135,10 +17133,9 @@ const chooseVideo = /* @__PURE__ */ defineAsyncApi(API_CHOOSE_VIDEO, ({ sourceTy
...
@@ -17135,10 +17133,9 @@ const chooseVideo = /* @__PURE__ */ defineAsyncApi(API_CHOOSE_VIDEO, ({ sourceTy
resolve(callbackResult);
resolve(callbackResult);
}
}
});
});
if (getInteractStatus()) {
videoInput.click();
videoInput.click();
} else
{
if (!getInteractStatus())
{
reject
(t2("uni.chooseFile.notUserActivation"));
console.warn
(t2("uni.chooseFile.notUserActivation"));
}
}
}, ChooseVideoProtocol, ChooseVideoOptions);
}, ChooseVideoProtocol, ChooseVideoOptions);
const request = /* @__PURE__ */ defineTaskApi(API_REQUEST, ({
const request = /* @__PURE__ */ defineTaskApi(API_REQUEST, ({
...
...
packages/uni-mp-compiler/src/compile.ts
浏览文件 @
0ae56fc0
...
@@ -100,6 +100,7 @@ export function baseCompile(template: string, options: CompilerOptions = {}) {
...
@@ -100,6 +100,7 @@ export function baseCompile(template: string, options: CompilerOptions = {}) {
event
,
event
,
slot
,
slot
,
lazyElement
,
lazyElement
,
component
,
}
=
options
.
miniProgram
}
=
options
.
miniProgram
genTemplate
(
ast
,
{
genTemplate
(
ast
,
{
class
:
clazz
,
class
:
clazz
,
...
@@ -110,6 +111,8 @@ export function baseCompile(template: string, options: CompilerOptions = {}) {
...
@@ -110,6 +111,8 @@ export function baseCompile(template: string, options: CompilerOptions = {}) {
event
,
event
,
slot
,
slot
,
lazyElement
,
lazyElement
,
component
,
isBuiltInComponent
:
context
.
isBuiltInComponent
,
})
})
}
}
...
...
packages/uni-mp-compiler/src/options.ts
浏览文件 @
0ae56fc0
...
@@ -100,6 +100,7 @@ export interface TemplateCodegenOptions
...
@@ -100,6 +100,7 @@ export interface TemplateCodegenOptions
extends
Omit
<
MiniProgramCompilerOptions
,
'
filter
'
>
{
extends
Omit
<
MiniProgramCompilerOptions
,
'
filter
'
>
{
scopeId
?:
string
|
null
scopeId
?:
string
|
null
filename
:
string
filename
:
string
isBuiltInComponent
:
Required
<
TransformOptions
>
[
'
isBuiltInComponent
'
]
}
}
export
type
CompilerOptions
=
ParserOptions
&
TransformOptions
&
CodegenOptions
export
type
CompilerOptions
=
ParserOptions
&
TransformOptions
&
CodegenOptions
packages/uni-mp-compiler/src/template/codegen.ts
浏览文件 @
0ae56fc0
...
@@ -3,6 +3,7 @@ import { SLOT_DEFAULT_NAME, dynamicSlotName } from '@dcloudio/uni-shared'
...
@@ -3,6 +3,7 @@ import { SLOT_DEFAULT_NAME, dynamicSlotName } from '@dcloudio/uni-shared'
import
{
import
{
formatMiniProgramEvent
,
formatMiniProgramEvent
,
isElementNode
,
isElementNode
,
isUserComponent
,
MiniProgramCompilerOptions
,
MiniProgramCompilerOptions
,
}
from
'
@dcloudio/uni-cli-shared
'
}
from
'
@dcloudio/uni-cli-shared
'
import
{
import
{
...
@@ -25,6 +26,7 @@ import { genExpr } from '../codegen'
...
@@ -25,6 +26,7 @@ import { genExpr } from '../codegen'
import
{
ForElementNode
,
isForElementNode
}
from
'
../transforms/vFor
'
import
{
ForElementNode
,
isForElementNode
}
from
'
../transforms/vFor
'
import
{
IfElementNode
,
isIfElementNode
}
from
'
../transforms/vIf
'
import
{
IfElementNode
,
isIfElementNode
}
from
'
../transforms/vIf
'
import
{
findSlotName
}
from
'
../transforms/vSlot
'
import
{
findSlotName
}
from
'
../transforms/vSlot
'
import
{
TransformContext
}
from
'
../transform
'
interface
TemplateCodegenContext
{
interface
TemplateCodegenContext
{
code
:
string
code
:
string
directive
:
string
directive
:
string
...
@@ -32,6 +34,8 @@ interface TemplateCodegenContext {
...
@@ -32,6 +34,8 @@ interface TemplateCodegenContext {
event
:
MiniProgramCompilerOptions
[
'
event
'
]
event
:
MiniProgramCompilerOptions
[
'
event
'
]
slot
:
MiniProgramCompilerOptions
[
'
slot
'
]
slot
:
MiniProgramCompilerOptions
[
'
slot
'
]
lazyElement
:
MiniProgramCompilerOptions
[
'
lazyElement
'
]
lazyElement
:
MiniProgramCompilerOptions
[
'
lazyElement
'
]
component
:
MiniProgramCompilerOptions
[
'
component
'
]
isBuiltInComponent
:
TransformContext
[
'
isBuiltInComponent
'
]
push
(
code
:
string
):
void
push
(
code
:
string
):
void
}
}
...
@@ -45,6 +49,8 @@ export function generate(
...
@@ -45,6 +49,8 @@ export function generate(
filename
,
filename
,
directive
,
directive
,
lazyElement
,
lazyElement
,
isBuiltInComponent
,
component
,
}:
TemplateCodegenOptions
}:
TemplateCodegenOptions
)
{
)
{
const
context
:
TemplateCodegenContext
=
{
const
context
:
TemplateCodegenContext
=
{
...
@@ -54,6 +60,8 @@ export function generate(
...
@@ -54,6 +60,8 @@ export function generate(
scopeId
,
scopeId
,
directive
,
directive
,
lazyElement
,
lazyElement
,
component
,
isBuiltInComponent
,
push
(
code
)
{
push
(
code
)
{
context
.
code
+=
code
context
.
code
+=
code
},
},
...
@@ -266,7 +274,7 @@ function genElement(node: ElementNode, context: TemplateCodegenContext) {
...
@@ -266,7 +274,7 @@ function genElement(node: ElementNode, context: TemplateCodegenContext) {
genNode
(
node
,
context
)
genNode
(
node
,
context
)
})
})
}
}
if
(
node
.
tagType
===
ElementTypes
.
COMPONENT
)
{
if
(
isUserComponent
(
node
,
context
)
)
{
tag
=
hyphenate
(
tag
)
tag
=
hyphenate
(
tag
)
}
}
const
{
push
}
=
context
const
{
push
}
=
context
...
@@ -333,7 +341,7 @@ export function genElementProps(
...
@@ -333,7 +341,7 @@ export function genElementProps(
if
(
name
===
'
on
'
)
{
if
(
name
===
'
on
'
)
{
genOn
(
prop
,
node
,
context
)
genOn
(
prop
,
node
,
context
)
}
else
{
}
else
{
genDirectiveNode
(
prop
,
context
)
genDirectiveNode
(
prop
,
node
,
context
)
}
}
}
}
})
})
...
@@ -341,7 +349,7 @@ export function genElementProps(
...
@@ -341,7 +349,7 @@ export function genElementProps(
function
genOn
(
function
genOn
(
prop
:
DirectiveNode
,
prop
:
DirectiveNode
,
node
:
ElementNode
,
node
:
ElementNode
,
{
push
,
event
}:
TemplateCodegenContext
{
push
,
event
,
isBuiltInComponent
}:
TemplateCodegenContext
)
{
)
{
const
arg
=
(
prop
.
arg
as
SimpleExpressionNode
).
content
const
arg
=
(
prop
.
arg
as
SimpleExpressionNode
).
content
const
exp
=
prop
.
exp
as
SimpleExpressionNode
const
exp
=
prop
.
exp
as
SimpleExpressionNode
...
@@ -349,7 +357,7 @@ function genOn(
...
@@ -349,7 +357,7 @@ function genOn(
const
name
=
(
event
?.
format
||
formatMiniProgramEvent
)(
arg
,
{
const
name
=
(
event
?.
format
||
formatMiniProgramEvent
)(
arg
,
{
isCatch
:
modifiers
.
includes
(
'
stop
'
)
||
modifiers
.
includes
(
'
prevent
'
),
isCatch
:
modifiers
.
includes
(
'
stop
'
)
||
modifiers
.
includes
(
'
prevent
'
),
isCapture
:
modifiers
.
includes
(
'
capture
'
),
isCapture
:
modifiers
.
includes
(
'
capture
'
),
isComponent
:
node
.
tagType
===
ElementTypes
.
COMPONENT
,
isComponent
:
isUserComponent
(
node
,
{
isBuiltInComponent
})
,
})
})
if
(
exp
.
isStatic
)
{
if
(
exp
.
isStatic
)
{
push
(
`
${
name
}
="
${
exp
.
content
}
"`
)
push
(
`
${
name
}
="
${
exp
.
content
}
"`
)
...
@@ -360,8 +368,10 @@ function genOn(
...
@@ -360,8 +368,10 @@ function genOn(
function
genDirectiveNode
(
function
genDirectiveNode
(
prop
:
DirectiveNode
,
prop
:
DirectiveNode
,
{
push
}:
TemplateCodegenContext
node
:
ElementNode
,
context
:
TemplateCodegenContext
)
{
)
{
const
{
push
,
component
}
=
context
if
(
prop
.
name
===
'
slot
'
)
{
if
(
prop
.
name
===
'
slot
'
)
{
if
(
prop
.
arg
)
{
if
(
prop
.
arg
)
{
const
arg
=
prop
.
arg
as
SimpleExpressionNode
const
arg
=
prop
.
arg
as
SimpleExpressionNode
...
@@ -375,7 +385,13 @@ function genDirectiveNode(
...
@@ -375,7 +385,13 @@ function genDirectiveNode(
)
)
}
}
}
else
if
(
prop
.
name
===
'
show
'
)
{
}
else
if
(
prop
.
name
===
'
show
'
)
{
push
(
` hidden="{{!
${(
prop
.
exp
as
SimpleExpressionNode
).
content
}
}}"`
)
let
hiddenPropName
=
'
hidden
'
if
(
isUserComponent
(
node
,
context
)
&&
component
&&
component
.
vShow
)
{
hiddenPropName
=
component
.
vShow
}
push
(
`
${
hiddenPropName
}
="{{!
${(
prop
.
exp
as
SimpleExpressionNode
).
content
}
}}"`
)
}
else
if
(
prop
.
arg
&&
prop
.
exp
)
{
}
else
if
(
prop
.
arg
&&
prop
.
exp
)
{
const
arg
=
(
prop
.
arg
as
SimpleExpressionNode
).
content
const
arg
=
(
prop
.
arg
as
SimpleExpressionNode
).
content
const
exp
=
(
prop
.
exp
as
SimpleExpressionNode
).
content
const
exp
=
(
prop
.
exp
as
SimpleExpressionNode
).
content
...
...
packages/uni-mp-lark/dist/uni.compiler.js
浏览文件 @
0ae56fc0
...
@@ -81,6 +81,9 @@ const miniProgram = {
...
@@ -81,6 +81,9 @@ const miniProgram = {
dynamicSlotNames
:
true
,
dynamicSlotNames
:
true
,
},
},
directive
:
'
tt:
'
,
directive
:
'
tt:
'
,
component
:
{
vShow
:
uniCliShared
.
COMPONENT_CUSTOM_HIDDEN_BIND
,
},
};
};
const
options
=
{
const
options
=
{
vite
:
{
vite
:
{
...
...
packages/uni-mp-qq/__tests__/component.spec.ts
浏览文件 @
0ae56fc0
import
{
assert
}
from
'
./testUtils
'
import
{
assert
}
from
'
./testUtils
'
describe
(
'
mp-baidu: transform component
'
,
()
=>
{
describe
(
'
mp-baidu: transform component
'
,
()
=>
{
test
(
`component with v-show`
,
()
=>
{
assert
(
`<custom v-show="ok"/>`
,
`<custom data-c-h="{{!a}}" u-i="2a9ec0b0-0" bind:__l="__l"/>`
,
`(_ctx, _cache) => {
return { a: _ctx.ok }
}`
)
})
test
(
`match-media`
,
()
=>
{
test
(
`match-media`
,
()
=>
{
assert
(
assert
(
`<match-media/>`
,
`<match-media/>`
,
...
...
packages/uni-mp-qq/dist/uni.compiler.js
浏览文件 @
0ae56fc0
...
@@ -99,6 +99,9 @@ const miniProgram = {
...
@@ -99,6 +99,9 @@ const miniProgram = {
dynamicSlotNames
:
true
,
dynamicSlotNames
:
true
,
},
},
directive
:
'
qq:
'
,
directive
:
'
qq:
'
,
component
:
{
vShow
:
uniCliShared
.
COMPONENT_CUSTOM_HIDDEN
,
},
};
};
const
options
=
{
const
options
=
{
vite
:
{
vite
:
{
...
...
packages/uni-mp-qq/src/compiler/options.ts
浏览文件 @
0ae56fc0
import
path
from
'
path
'
import
path
from
'
path
'
import
type
{
CompilerOptions
}
from
'
@vue/compiler-core
'
import
type
{
CompilerOptions
}
from
'
@vue/compiler-core
'
import
{
import
{
COMPONENT_CUSTOM_HIDDEN
,
MiniProgramCompilerOptions
,
MiniProgramCompilerOptions
,
transformComponentLink
,
transformComponentLink
,
transformMatchMedia
,
transformMatchMedia
,
...
@@ -29,6 +30,9 @@ export const miniProgram: MiniProgramCompilerOptions = {
...
@@ -29,6 +30,9 @@ export const miniProgram: MiniProgramCompilerOptions = {
dynamicSlotNames
:
true
,
dynamicSlotNames
:
true
,
},
},
directive
:
'
qq:
'
,
directive
:
'
qq:
'
,
component
:
{
vShow
:
COMPONENT_CUSTOM_HIDDEN
,
},
}
}
export
const
options
:
UniMiniProgramPluginOptions
=
{
export
const
options
:
UniMiniProgramPluginOptions
=
{
...
...
packages/uni-mp-toutiao/__tests__/component.spec.ts
浏览文件 @
0ae56fc0
import
{
assert
}
from
'
./testUtils
'
import
{
assert
}
from
'
./testUtils
'
describe
(
'
mp-baidu: transform component
'
,
()
=>
{
describe
(
'
mp-baidu: transform component
'
,
()
=>
{
test
(
`component with v-show`
,
()
=>
{
assert
(
`<custom v-show="ok"/>`
,
`<custom bind:-data-c-h="{{!a}}" u-i="2a9ec0b0-0" bind:__l="__l"/>`
,
`(_ctx, _cache) => {
return { a: _ctx.ok }
}`
)
})
test
(
`match-media`
,
()
=>
{
test
(
`match-media`
,
()
=>
{
assert
(
assert
(
`<match-media/>`
,
`<match-media/>`
,
...
...
packages/uni-mp-toutiao/dist/uni.compiler.js
浏览文件 @
0ae56fc0
...
@@ -81,6 +81,9 @@ const miniProgram = {
...
@@ -81,6 +81,9 @@ const miniProgram = {
dynamicSlotNames
:
true
,
dynamicSlotNames
:
true
,
},
},
directive
:
'
tt:
'
,
directive
:
'
tt:
'
,
component
:
{
vShow
:
uniCliShared
.
COMPONENT_CUSTOM_HIDDEN_BIND
,
},
};
};
const
options
=
{
const
options
=
{
vite
:
{
vite
:
{
...
...
packages/uni-mp-toutiao/src/compiler/options.ts
浏览文件 @
0ae56fc0
import
path
from
'
path
'
import
path
from
'
path
'
import
type
{
CompilerOptions
}
from
'
@vue/compiler-core
'
import
type
{
CompilerOptions
}
from
'
@vue/compiler-core
'
import
{
import
{
COMPONENT_CUSTOM_HIDDEN_BIND
,
MiniProgramCompilerOptions
,
MiniProgramCompilerOptions
,
transformComponentLink
,
transformComponentLink
,
transformMatchMedia
,
transformMatchMedia
,
...
@@ -32,6 +33,9 @@ export const miniProgram: MiniProgramCompilerOptions = {
...
@@ -32,6 +33,9 @@ export const miniProgram: MiniProgramCompilerOptions = {
dynamicSlotNames
:
true
,
dynamicSlotNames
:
true
,
},
},
directive
:
'
tt:
'
,
directive
:
'
tt:
'
,
component
:
{
vShow
:
COMPONENT_CUSTOM_HIDDEN_BIND
,
},
}
}
export
const
options
:
UniMiniProgramPluginOptions
=
{
export
const
options
:
UniMiniProgramPluginOptions
=
{
...
...
packages/uni-mp-vite/src/plugin/configResolved.ts
浏览文件 @
0ae56fc0
...
@@ -24,9 +24,12 @@ import {
...
@@ -24,9 +24,12 @@ import {
const
debugNVueCss
=
debug
(
'
vite:uni:nvue-css
'
)
const
debugNVueCss
=
debug
(
'
vite:uni:nvue-css
'
)
const
cssVars
=
`page{--status-bar-height:25px;--top-window-height:0px;--window-top:0px;--window-bottom:0px;--window-left:0px;--window-right:0px;--window-magin:0px}`
const
cssVars
=
`page{--status-bar-height:25px;--top-window-height:0px;--window-top:0px;--window-bottom:0px;--window-left:0px;--window-right:0px;--window-magin:0px}`
const
shadowCss
=
`page::after{position:fixed;content:'';left:-1000px;top:-1000px;-webkit-animation:shadow-preload .1s;-webkit-animation-delay:3s;animation:shadow-preload .1s;animation-delay:3s}@-webkit-keyframes shadow-preload{0%{background-image:url(https://cdn.dcloud.net.cn/img/shadow-grey.png)}100%{background-image:url(https://cdn.dcloud.net.cn/img/shadow-grey.png)}}@keyframes shadow-preload{0%{background-image:url(https://cdn.dcloud.net.cn/img/shadow-grey.png)}100%{background-image:url(https://cdn.dcloud.net.cn/img/shadow-grey.png)}}`
const
shadowCss
=
`page::after{position:fixed;content:'';left:-1000px;top:-1000px;-webkit-animation:shadow-preload .1s;-webkit-animation-delay:3s;animation:shadow-preload .1s;animation-delay:3s}@-webkit-keyframes shadow-preload{0%{background-image:url(https://cdn.dcloud.net.cn/img/shadow-grey.png)}100%{background-image:url(https://cdn.dcloud.net.cn/img/shadow-grey.png)}}@keyframes shadow-preload{0%{background-image:url(https://cdn.dcloud.net.cn/img/shadow-grey.png)}100%{background-image:url(https://cdn.dcloud.net.cn/img/shadow-grey.png)}}`
const
genComponentCustomHiddenCss
=
(
name
:
string
)
=>
`[
${
name
.
replace
(
'
:
'
,
''
)}
="true"]{display: none !important;}`
export
function
createConfigResolved
({
export
function
createConfigResolved
({
style
:
{
extname
},
style
:
{
extname
},
template
:
{
component
},
}:
UniMiniProgramPluginOptions
):
Plugin
[
'
configResolved
'
]
{
}:
UniMiniProgramPluginOptions
):
Plugin
[
'
configResolved
'
]
{
function
normalizeCssChunkFilename
(
id
:
string
,
extname
:
string
)
{
function
normalizeCssChunkFilename
(
id
:
string
,
extname
:
string
)
{
return
(
return
(
...
@@ -54,10 +57,15 @@ export function createConfigResolved({
...
@@ -54,10 +57,15 @@ export function createConfigResolved({
chunkCssCode
(
filename
,
cssCode
)
{
chunkCssCode
(
filename
,
cssCode
)
{
cssCode
=
transformScopedCss
(
cssCode
)
cssCode
=
transformScopedCss
(
cssCode
)
if
(
filename
===
'
app
'
+
extname
)
{
if
(
filename
===
'
app
'
+
extname
)
{
const
componentCustomHiddenCss
=
(
component
&&
component
.
vShow
&&
genComponentCustomHiddenCss
(
component
.
vShow
))
||
''
if
(
config
.
isProduction
)
{
if
(
config
.
isProduction
)
{
return
cssCode
+
shadowCss
+
cssVars
return
cssCode
+
shadowCss
+
cssVars
+
componentCustomHiddenCss
}
else
{
}
else
{
return
cssCode
+
cssVars
return
cssCode
+
cssVars
+
componentCustomHiddenCss
}
}
}
}
...
...
packages/uni-mp-vite/src/plugin/index.ts
浏览文件 @
0ae56fc0
...
@@ -57,6 +57,7 @@ export interface UniMiniProgramPluginOptions {
...
@@ -57,6 +57,7 @@ export interface UniMiniProgramPluginOptions {
class
:
MiniProgramCompilerOptions
[
'
class
'
]
class
:
MiniProgramCompilerOptions
[
'
class
'
]
slot
:
MiniProgramCompilerOptions
[
'
slot
'
]
slot
:
MiniProgramCompilerOptions
[
'
slot
'
]
lazyElement
?:
MiniProgramCompilerOptions
[
'
lazyElement
'
]
lazyElement
?:
MiniProgramCompilerOptions
[
'
lazyElement
'
]
component
?:
MiniProgramCompilerOptions
[
'
component
'
]
customElements
?:
string
[]
customElements
?:
string
[]
filter
?:
{
filter
?:
{
lang
:
string
lang
:
string
...
@@ -96,6 +97,7 @@ export function uniMiniProgramPlugin(
...
@@ -96,6 +97,7 @@ export function uniMiniProgramPlugin(
filter
:
template
.
filter
?
{
lang
:
template
.
filter
.
lang
}
:
undefined
,
filter
:
template
.
filter
?
{
lang
:
template
.
filter
.
lang
}
:
undefined
,
directive
:
template
.
directive
,
directive
:
template
.
directive
,
lazyElement
:
template
.
lazyElement
,
lazyElement
:
template
.
lazyElement
,
component
:
template
.
component
,
emitFile
,
emitFile
,
slot
:
template
.
slot
,
slot
:
template
.
slot
,
},
},
...
...
packages/uni-mp-weixin/__tests__/component.spec.ts
浏览文件 @
0ae56fc0
import
{
assert
}
from
'
./testUtils
'
import
{
assert
}
from
'
./testUtils
'
import
{
customElements
}
from
'
../src/compiler/options
'
import
{
customElements
}
from
'
../src/compiler/options
'
describe
(
'
mp-weixin: transform component
'
,
()
=>
{
describe
(
'
mp-weixin: transform component
'
,
()
=>
{
test
(
`component with v-show`
,
()
=>
{
assert
(
`<custom v-show="ok"/>`
,
`<custom data-c-h="{{!a}}" u-i="2a9ec0b0-0" bind:__l="__l"/>`
,
`(_ctx, _cache) => {
return { a: _ctx.ok }
}`
)
})
test
(
`built-in component`
,
()
=>
{
test
(
`built-in component`
,
()
=>
{
const
code
=
customElements
.
map
((
tag
)
=>
`<
${
tag
}
/>`
).
join
(
''
)
const
code
=
customElements
.
map
((
tag
)
=>
`<
${
tag
}
/>`
).
join
(
''
)
assert
(
assert
(
...
...
packages/uni-mp-weixin/dist/uni.compiler.js
浏览文件 @
0ae56fc0
...
@@ -75,6 +75,9 @@ const miniProgram = {
...
@@ -75,6 +75,9 @@ const miniProgram = {
canvas
:
[{
name
:
'
bind
'
,
arg
:
[
'
canvas-id
'
,
'
id
'
]
}],
canvas
:
[{
name
:
'
bind
'
,
arg
:
[
'
canvas-id
'
,
'
id
'
]
}],
editor
:
[{
name
:
'
on
'
,
arg
:
[
'
ready
'
]
}],
editor
:
[{
name
:
'
on
'
,
arg
:
[
'
ready
'
]
}],
},
},
component
:
{
vShow
:
uniCliShared
.
COMPONENT_CUSTOM_HIDDEN
,
},
};
};
const
projectConfigFilename
=
'
project.config.json
'
;
const
projectConfigFilename
=
'
project.config.json
'
;
const
options
=
{
const
options
=
{
...
...
packages/uni-mp-weixin/src/compiler/options.ts
浏览文件 @
0ae56fc0
import
path
from
'
path
'
import
path
from
'
path
'
import
type
{
CompilerOptions
}
from
'
@vue/compiler-core
'
import
type
{
CompilerOptions
}
from
'
@vue/compiler-core
'
import
{
import
{
COMPONENT_CUSTOM_HIDDEN
,
MiniProgramCompilerOptions
,
MiniProgramCompilerOptions
,
transformComponentLink
,
transformComponentLink
,
transformRef
,
transformRef
,
...
@@ -28,6 +29,9 @@ export const miniProgram: MiniProgramCompilerOptions = {
...
@@ -28,6 +29,9 @@ export const miniProgram: MiniProgramCompilerOptions = {
canvas
:
[{
name
:
'
bind
'
,
arg
:
[
'
canvas-id
'
,
'
id
'
]
}],
canvas
:
[{
name
:
'
bind
'
,
arg
:
[
'
canvas-id
'
,
'
id
'
]
}],
editor
:
[{
name
:
'
on
'
,
arg
:
[
'
ready
'
]
}],
editor
:
[{
name
:
'
on
'
,
arg
:
[
'
ready
'
]
}],
},
},
component
:
{
vShow
:
COMPONENT_CUSTOM_HIDDEN
,
},
}
}
const
projectConfigFilename
=
'
project.config.json
'
const
projectConfigFilename
=
'
project.config.json
'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录