Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yangkaifeng
uni-app
提交
f338a300
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,体验更适合开发者的 AI 搜索 >>
提交
f338a300
编写于
10月 27, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(mp): mp-baidu
上级
7c0ef648
变更
40
隐藏空白更改
内联
并排
Showing
40 changed file
with
321 addition
and
105 deletion
+321
-105
packages/uni-app-plus/dist/uni-app-view.umd.js
packages/uni-app-plus/dist/uni-app-view.umd.js
+3
-3
packages/uni-app-vite/package.json
packages/uni-app-vite/package.json
+1
-2
packages/uni-cli-nvue/package.json
packages/uni-cli-nvue/package.json
+1
-2
packages/uni-cli-shared/package.json
packages/uni-cli-shared/package.json
+1
-2
packages/uni-cli-shared/src/filter.ts
packages/uni-cli-shared/src/filter.ts
+10
-13
packages/uni-cli-shared/src/mp/template.ts
packages/uni-cli-shared/src/mp/template.ts
+1
-1
packages/uni-h5-vite/package.json
packages/uni-h5-vite/package.json
+1
-2
packages/uni-h5/dist/uni-h5.cjs.js
packages/uni-h5/dist/uni-h5.cjs.js
+6
-1
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+6
-1
packages/uni-mp-alipay/dist/uni.mp.esm.js
packages/uni-mp-alipay/dist/uni.mp.esm.js
+4
-2
packages/uni-mp-baidu/__tests__/testUtils.ts
packages/uni-mp-baidu/__tests__/testUtils.ts
+2
-0
packages/uni-mp-baidu/__tests__/vModel.spec.ts
packages/uni-mp-baidu/__tests__/vModel.spec.ts
+50
-0
packages/uni-mp-baidu/__tests__/vOn.spec.ts
packages/uni-mp-baidu/__tests__/vOn.spec.ts
+2
-2
packages/uni-mp-baidu/dist/uni.compiler.js
packages/uni-mp-baidu/dist/uni.compiler.js
+35
-9
packages/uni-mp-baidu/dist/uni.mp.esm.js
packages/uni-mp-baidu/dist/uni.mp.esm.js
+21
-4
packages/uni-mp-baidu/src/plugin/index.ts
packages/uni-mp-baidu/src/plugin/index.ts
+3
-1
packages/uni-mp-baidu/src/plugin/transforms/vModel.ts
packages/uni-mp-baidu/src/plugin/transforms/vModel.ts
+38
-0
packages/uni-mp-baidu/src/plugin/transforms/vOn.ts
packages/uni-mp-baidu/src/plugin/transforms/vOn.ts
+19
-7
packages/uni-mp-baidu/src/runtime/parseComponentOptions.ts
packages/uni-mp-baidu/src/runtime/parseComponentOptions.ts
+4
-8
packages/uni-mp-compiler/package.json
packages/uni-mp-compiler/package.json
+1
-3
packages/uni-mp-compiler/src/index.ts
packages/uni-mp-compiler/src/index.ts
+1
-0
packages/uni-mp-compiler/src/transforms/transformElement.ts
packages/uni-mp-compiler/src/transforms/transformElement.ts
+14
-4
packages/uni-mp-compiler/src/transforms/vModel.ts
packages/uni-mp-compiler/src/transforms/vModel.ts
+26
-13
packages/uni-mp-core/src/runtime/componentInstance/index.ts
packages/uni-mp-core/src/runtime/componentInstance/index.ts
+7
-2
packages/uni-mp-core/src/runtime/componentProps.ts
packages/uni-mp-core/src/runtime/componentProps.ts
+8
-0
packages/uni-mp-core/src/runtime/polyfill.ts
packages/uni-mp-core/src/runtime/polyfill.ts
+5
-1
packages/uni-mp-kuaishou/dist/uni.mp.esm.js
packages/uni-mp-kuaishou/dist/uni.mp.esm.js
+4
-2
packages/uni-mp-qq/dist/uni.compiler.js
packages/uni-mp-qq/dist/uni.compiler.js
+4
-0
packages/uni-mp-qq/dist/uni.mp.esm.js
packages/uni-mp-qq/dist/uni.mp.esm.js
+4
-2
packages/uni-mp-qq/src/plugin/index.ts
packages/uni-mp-qq/src/plugin/index.ts
+4
-0
packages/uni-mp-toutiao/dist/uni.mp.esm.js
packages/uni-mp-toutiao/dist/uni.mp.esm.js
+4
-2
packages/uni-mp-vite/package.json
packages/uni-mp-vite/package.json
+1
-2
packages/uni-mp-vite/src/index.ts
packages/uni-mp-vite/src/index.ts
+1
-1
packages/uni-mp-vite/src/plugin/build.ts
packages/uni-mp-vite/src/plugin/build.ts
+2
-1
packages/uni-mp-vite/src/plugins/renderjs.ts
packages/uni-mp-vite/src/plugins/renderjs.ts
+10
-6
packages/uni-mp-weixin/dist/uni.compiler.js
packages/uni-mp-weixin/dist/uni.compiler.js
+4
-0
packages/uni-mp-weixin/dist/uni.mp.esm.js
packages/uni-mp-weixin/dist/uni.mp.esm.js
+4
-2
packages/uni-mp-weixin/src/plugin/index.ts
packages/uni-mp-weixin/src/plugin/index.ts
+4
-0
packages/uni-quickapp-webview/dist/uni.mp.esm.js
packages/uni-quickapp-webview/dist/uni.mp.esm.js
+4
-2
packages/vite-plugin-uni/package.json
packages/vite-plugin-uni/package.json
+1
-2
未找到文件。
packages/uni-app-plus/dist/uni-app-view.umd.js
浏览文件 @
f338a300
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
packages/uni-app-vite/package.json
浏览文件 @
f338a300
...
...
@@ -5,8 +5,7 @@
"main"
:
"dist/index.js"
,
"types"
:
"dist/index.d.ts"
,
"files"
:
[
"dist/**/*.js"
,
"dist/**/*.d.ts"
,
"dist"
,
"lib"
],
"repository"
:
{
...
...
packages/uni-cli-nvue/package.json
浏览文件 @
f338a300
...
...
@@ -5,8 +5,7 @@
"main"
:
"dist/index.js"
,
"types"
:
"dist/index.d.ts"
,
"files"
:
[
"dist/**/*.js"
,
"dist/**/*.d.ts"
,
"dist"
,
"lib"
],
"repository"
:
{
...
...
packages/uni-cli-shared/package.json
浏览文件 @
f338a300
...
...
@@ -5,8 +5,7 @@
"main"
:
"dist/index.js"
,
"types"
:
"dist/index.d.ts"
,
"files"
:
[
"dist/**/*.js"
,
"dist/**/*.d.ts"
,
"dist"
,
"lib"
],
"repository"
:
{
...
...
packages/uni-cli-shared/src/filter.ts
浏览文件 @
f338a300
...
...
@@ -4,28 +4,25 @@ const WXS_RE = /vue&type=wxs/
export
function
isWxs
(
id
:
string
)
{
return
WXS_RE
.
test
(
id
)
}
const
SJS_RE
=
/vue&type=sjs/
export
function
isSjs
(
id
:
string
)
{
return
SJS_RE
.
test
(
id
)
}
const
RENDERJS_RE
=
/vue&type=renderjs/
export
function
isRenderjs
(
id
:
string
)
{
return
RENDERJS_RE
.
test
(
id
)
}
type
FilterType
=
'
wxs
'
|
'
renderjs
'
|
'
sjs
'
export
function
parseRenderjs
(
id
:
string
)
{
if
(
isWxs
(
id
))
{
if
(
isWxs
(
id
)
||
isRenderjs
(
id
)
||
isSjs
(
id
)
)
{
const
{
query
,
filename
}
=
parseVueRequest
(
id
)
return
{
type
:
'
wxs
'
,
type
:
query
.
type
as
FilterType
,
name
:
(
query
as
any
).
name
as
string
,
filename
,
}
as
const
}
if
(
isRenderjs
(
id
))
{
const
{
query
,
filename
}
=
parseVueRequest
(
id
)
return
{
type
:
'
renderjs
'
,
name
:
(
query
as
any
).
name
as
string
,
filename
,
}
as
const
}
}
return
{
type
:
''
,
...
...
@@ -34,7 +31,7 @@ export function parseRenderjs(id: string) {
}
as
const
}
export
function
missingModuleName
(
type
:
'
wxs
'
|
'
renderjs
'
,
code
:
string
)
{
export
function
missingModuleName
(
type
:
FilterType
,
code
:
string
)
{
return
`<script module="missing module name" lang="
${
type
}
">
${
code
}
</script>`
...
...
packages/uni-cli-shared/src/mp/template.ts
浏览文件 @
f338a300
...
...
@@ -25,7 +25,7 @@ export interface MiniProgramCompilerOptions {
}
export
interface
MiniProgramFilterOptions
{
id
:
string
type
:
'
wxs
'
type
:
string
name
:
string
src
?:
string
code
:
string
...
...
packages/uni-h5-vite/package.json
浏览文件 @
f338a300
...
...
@@ -5,8 +5,7 @@
"main"
:
"dist/index.js"
,
"types"
:
"dist/index.d.ts"
,
"files"
:
[
"dist/**/*.js"
,
"dist/**/*.d.ts"
,
"dist"
,
"lib"
],
"repository"
:
{
...
...
packages/uni-h5/dist/uni-h5.cjs.js
浏览文件 @
f338a300
...
...
@@ -5023,6 +5023,11 @@ function decodeEntities(htmlString) {
return
wrap
.
innerText
||
wrap
.
textContent
;
});
}
function
normlizeValue
(
tagName
,
name
,
value
)
{
if
(
tagName
===
"
img
"
&&
name
===
"
src
"
)
return
getRealPath
(
value
);
return
value
;
}
function
parseNodes
(
nodes
,
parentNode
,
scopeId
)
{
nodes
.
forEach
(
function
(
node
)
{
if
(
!
shared
.
isPlainObject
(
node
))
{
...
...
@@ -5054,7 +5059,7 @@ function parseNodes(nodes, parentNode, scopeId) {
break
;
default
:
if
(
tagAttrs
.
indexOf
(
name
)
!==
-
1
)
{
elem
.
setAttribute
(
name
,
value
);
elem
.
setAttribute
(
name
,
normlizeValue
(
tagName
,
name
,
value
)
);
}
}
});
...
...
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
f338a300
...
...
@@ -11467,6 +11467,11 @@ function decodeEntities(htmlString) {
return wrap.innerText || wrap.textContent;
});
}
function normlizeValue(tagName, name, value) {
if (tagName === "img" && name === "src")
return getRealPath(value);
return value;
}
function parseNodes(nodes, parentNode, scopeId) {
nodes.forEach(function(node) {
if (!isPlainObject(node)) {
...
...
@@ -11498,7 +11503,7 @@ function parseNodes(nodes, parentNode, scopeId) {
break;
default:
if (tagAttrs.indexOf(name) !== -1) {
elem.setAttribute(name,
value
);
elem.setAttribute(name,
normlizeValue(tagName, name, value)
);
}
}
});
...
...
packages/uni-mp-alipay/dist/uni.mp.esm.js
浏览文件 @
f338a300
...
...
@@ -131,8 +131,10 @@ const MP_METHODS = [
];
function
createEmitFn
(
oldEmit
,
ctx
)
{
return
function
emit
(
event
,
...
args
)
{
if
(
ctx
.
$scope
&&
event
)
{
ctx
.
$scope
.
triggerEvent
(
event
,
{
__args__
:
args
});
const
scope
=
ctx
.
$scope
;
if
(
scope
&&
event
)
{
const
detail
=
{
__args__
:
args
};
scope
.
triggerEvent
(
event
,
detail
);
}
{
const
vnode
=
this
.
$
.
vnode
;
...
...
packages/uni-mp-baidu/__tests__/testUtils.ts
浏览文件 @
f338a300
...
...
@@ -2,6 +2,7 @@ import { isCustomElement, isNativeTag } from '@dcloudio/uni-shared'
import
{
compile
,
CompilerOptions
}
from
'
@dcloudio/uni-mp-compiler
'
import
{
transformFor
}
from
'
../src/plugin/transforms/vFor
'
import
{
transformOn
}
from
'
../src/plugin/transforms/vOn
'
import
{
transformModel
}
from
'
../src/plugin/transforms/vModel
'
export
function
assert
(
template
:
string
,
...
...
@@ -22,6 +23,7 @@ export function assert(
nodeTransforms
:
[
transformFor
],
directiveTransforms
:
{
on
:
transformOn
,
model
:
transformModel
,
},
miniProgram
:
{
slot
:
{
...
...
packages/uni-mp-baidu/__tests__/vModel.spec.ts
0 → 100644
浏览文件 @
f338a300
import
{
assert
}
from
'
./testUtils
'
describe
(
'
mp-baidu: transform v-model
'
,
()
=>
{
test
(
`component v-model`
,
()
=>
{
assert
(
`<Comp v-model="model" />`
,
`<comp v-i="2a9ec0b0-0" eO="{{a}}" modelValue="{{b}}" bindupdateModelValue="__e"/>`
,
`(_ctx, _cache) => {
return { a: { 'updateModelValue': _o($event => _ctx.model = $event) }, b: _ctx.model }
}`
)
})
test
(
`component v-model with cache`
,
()
=>
{
assert
(
`<Comp v-model="model" />`
,
`<comp v-i="2a9ec0b0-0" eO="{{a}}" modelValue="{{b}}" bindupdateModelValue="__e"/>`
,
`(_ctx, _cache) => {
return { a: { 'updateModelValue': _o($event => _ctx.model = $event) }, b: _ctx.model }
}`
,
{
cacheHandlers
:
true
,
}
)
})
test
(
`input,textarea v-model`
,
()
=>
{
assert
(
`<input v-model="model" />`
,
`<input value="{{a}}" bindinput="{{b}}"/>`
,
`(_ctx, _cache) => {
return { a: _ctx.model, b: _o($event => _ctx.model = $event.detail.value) }
}`
)
assert
(
`<textarea v-model="model" />`
,
`<textarea value="{{a}}" bindinput="{{b}}"/>`
,
`(_ctx, _cache) => {
return { a: _ctx.model, b: _o($event => _ctx.model = $event.detail.value) }
}`
)
})
test
(
`input v-model + v-on`
,
()
=>
{
assert
(
`<input @input="input" v-model="model" />`
,
`<input bindinput="{{a}}" value="{{b}}"/>`
,
`(_ctx, _cache) => {
return { a: _o([$event => _ctx.model = $event.detail.value, _ctx.input]), b: _ctx.model }
}`
)
})
})
packages/uni-mp-baidu/__tests__/vOn.spec.ts
浏览文件 @
f338a300
...
...
@@ -14,7 +14,7 @@ describe('mp-baidu: transform v-on', () => {
test
(
`custom event`
,
()
=>
{
assert
(
`<custom @click="click"/>`
,
`<custom bindclick="__e" v-i="2a9ec0b0-0"
data-e-o
="{{a}}"/>`
,
`<custom bindclick="__e" v-i="2a9ec0b0-0"
eO
="{{a}}"/>`
,
`(_ctx, _cache) => {
return { a: { 'click': _o(_ctx.click) } }
}`
...
...
@@ -23,7 +23,7 @@ describe('mp-baidu: transform v-on', () => {
test
(
`multi custom event`
,
()
=>
{
assert
(
`<custom @unmount="unmount" @custom-mount="mount();created();"/>`
,
`<custom bindunmount="__e" bind:custom-mount="__e" v-i="2a9ec0b0-0"
data-e-o
="{{a}}"/>`
,
`<custom bindunmount="__e" bind:custom-mount="__e" v-i="2a9ec0b0-0"
eO
="{{a}}"/>`
,
`(_ctx, _cache) => {
return { a: { 'custom-mount': _o($event => { _ctx.mount(); _ctx.created(); }), 'unmount': _o(_ctx.unmount) } }
}`
...
...
packages/uni-mp-baidu/dist/uni.compiler.js
浏览文件 @
f338a300
...
...
@@ -68,20 +68,25 @@ const transformOn = (dir, node, context, augmentor) => {
!
uniMpCompiler
.
isUserComponent
(
node
,
context
))
{
return
res
;
}
// data-event-opts
const
opts
=
compilerCore
.
findProp
(
node
,
ATTR_DATA_EVENT_OPTS
,
true
);
const
value
=
res
.
props
[
0
].
value
;
res
.
props
[
0
].
value
=
compilerCore
.
createSimpleExpression
(
'
__e
'
,
true
);
res
.
props
[
0
].
value
=
createCustomEventExpr
();
addEventOpts
(
arg
.
content
,
value
,
node
);
return
res
;
};
function
createCustomEventExpr
()
{
return
compilerCore
.
createSimpleExpression
(
'
__e
'
,
true
);
}
function
addEventOpts
(
event
,
value
,
node
)
{
const
opts
=
compilerCore
.
findProp
(
node
,
ATTR_DATA_EVENT_OPTS
,
true
);
if
(
!
opts
)
{
node
.
props
.
push
(
createDataEventOptsProp
(
arg
.
cont
ent
,
value
));
node
.
props
.
push
(
createDataEventOptsProp
(
ev
ent
,
value
));
}
else
{
const
children
=
opts
.
exp
.
children
;
children
.
splice
(
children
.
length
-
2
,
0
,
createDataEventOptsProperty
(
arg
.
cont
ent
,
value
));
children
.
splice
(
children
.
length
-
2
,
0
,
createDataEventOptsProperty
(
ev
ent
,
value
));
}
return
res
;
};
const
ATTR_DATA_EVENT_OPTS
=
'
data-e-o
'
;
}
const
ATTR_DATA_EVENT_OPTS
=
'
eO
'
;
function
createDataEventOptsProperty
(
event
,
exp
)
{
return
compilerCore
.
createCompoundExpression
([
`'
${
event
}
'`
,
'
:
'
,
exp
,
'
,
'
]);
}
...
...
@@ -117,6 +122,26 @@ function isCustomEvent(name) {
return
!
builtInEvents
.
includes
(
name
);
}
/**
* 百度小程序的自定义组件,不支持动态事件绑定,故 v-model 也需要调整
* @param dir
* @param node
* @param context
* @param augmentor
* @returns
*/
const
transformModel
=
(
dir
,
node
,
context
,
augmentor
)
=>
{
const
res
=
uniMpCompiler
.
transformModel
(
dir
,
node
,
context
,
augmentor
);
const
props
=
res
.
props
;
if
(
props
.
length
<
2
||
!
uniMpCompiler
.
isUserComponent
(
node
,
context
))
{
return
res
;
}
const
{
arg
,
exp
}
=
props
[
1
];
addEventOpts
(
arg
.
content
,
exp
,
node
);
props
[
1
].
exp
=
createCustomEventExpr
();
return
res
;
};
const
uniMiniProgramBaiduPlugin
=
{
name
:
'
vite:uni-mp-baidu
'
,
config
()
{
...
...
@@ -154,7 +179,7 @@ const options = {
},
template
:
{
filter
:
{
extname
:
'
.s
wan
'
,
extname
:
'
.s
js
'
,
lang
:
'
sjs
'
,
generate
(
filter
,
filename
)
{
if
(
filename
)
{
...
...
@@ -174,6 +199,7 @@ ${filter.code}
nodeTransforms
:
[
transformFor
],
directiveTransforms
:
{
on
:
transformOn
,
model
:
transformModel
,
},
},
},
...
...
packages/uni-mp-baidu/dist/uni.mp.esm.js
浏览文件 @
f338a300
...
...
@@ -129,8 +129,13 @@ const MP_METHODS = [
];
function
createEmitFn
(
oldEmit
,
ctx
)
{
return
function
emit
(
event
,
...
args
)
{
if
(
ctx
.
$scope
&&
event
)
{
ctx
.
$scope
.
triggerEvent
(
event
,
{
__args__
:
args
});
const
scope
=
ctx
.
$scope
;
if
(
scope
&&
event
)
{
const
detail
=
{
__args__
:
args
};
{
detail
.
__ins__
=
scope
;
}
scope
.
triggerEvent
(
event
,
detail
);
}
return
oldEmit
.
apply
(
this
,
[
event
,
...
args
]);
};
...
...
@@ -433,6 +438,14 @@ function createObserver(name) {
function
initDefaultProps
(
isBehavior
=
false
)
{
const
properties
=
{};
if
(
!
isBehavior
)
{
{
// 百度小程序自定义组件不支持绑定动态事件,动态dataset,故通过props传递事件信息
// event-opts
properties
.
eO
=
{
type
:
null
,
value
:
''
,
};
}
properties
.
vI
=
{
type
:
null
,
value
:
''
,
...
...
@@ -693,6 +706,9 @@ Page = function (options) {
initHook
(
ON_LOAD
,
options
);
return
MPPage
(
options
);
};
{
Page
.
after
=
MPPage
.
after
;
}
Component
=
function
(
options
)
{
initHook
(
'
created
'
,
options
);
return
MPComponent
(
options
);
...
...
@@ -871,11 +887,12 @@ function parse$1(componentOptions) {
__l
:
methods
.
__l
,
};
delete
methods
.
__l
;
// 百度小程序自定义组件,不支持绑定动态事件,故由 __e 分发
methods
.
__e
=
handleCustomEvent
;
}
function
handleCustomEvent
(
event
)
{
const
{
type
,
target
:
{
dataset
:
{
eO
:
eventOpts
},
},
}
=
event
;
const
methodName
=
(
eventOpts
||
{})[
type
];
const
{
type
,
detail
:
{
__ins__
},
}
=
event
;
const
methodName
=
(
__ins__
.
properties
.
eO
||
{})[
type
];
if
(
!
methodName
)
{
return
console
.
warn
(
type
+
'
not found
'
);
}
...
...
packages/uni-mp-baidu/src/plugin/index.ts
浏览文件 @
f338a300
...
...
@@ -7,6 +7,7 @@ import initMiniProgramPlugin, {
import
source
from
'
./project.swan.json
'
import
{
transformFor
}
from
'
./transforms/vFor
'
import
{
transformOn
}
from
'
./transforms/vOn
'
import
{
transformModel
}
from
'
./transforms/vModel
'
const
uniMiniProgramBaiduPlugin
:
Plugin
=
{
name
:
'
vite:uni-mp-baidu
'
,
...
...
@@ -49,7 +50,7 @@ const options: UniMiniProgramPluginOptions = {
},
template
:
{
filter
:
{
extname
:
'
.s
wan
'
,
extname
:
'
.s
js
'
,
lang
:
'
sjs
'
,
generate
(
filter
,
filename
)
{
if
(
filename
)
{
...
...
@@ -69,6 +70,7 @@ ${filter.code}
nodeTransforms
:
[
transformFor
],
directiveTransforms
:
{
on
:
transformOn
,
model
:
transformModel
,
},
},
},
...
...
packages/uni-mp-baidu/src/plugin/transforms/vModel.ts
0 → 100644
浏览文件 @
f338a300
import
{
DirectiveNode
,
DirectiveTransform
,
isUserComponent
,
SimpleExpressionNode
,
transformModel
as
baseTransformModel
,
}
from
'
@dcloudio/uni-mp-compiler
'
import
{
ComponentNode
}
from
'
@vue/compiler-core
'
import
{
addEventOpts
,
createCustomEventExpr
}
from
'
./vOn
'
/**
* 百度小程序的自定义组件,不支持动态事件绑定,故 v-model 也需要调整
* @param dir
* @param node
* @param context
* @param augmentor
* @returns
*/
export
const
transformModel
:
DirectiveTransform
=
(
dir
,
node
,
context
,
augmentor
)
=>
{
const
res
=
baseTransformModel
(
dir
,
node
,
context
,
augmentor
)
const
props
=
res
.
props
as
unknown
as
DirectiveNode
[]
if
(
props
.
length
<
2
||
!
isUserComponent
(
node
,
context
))
{
return
res
}
const
{
arg
,
exp
}
=
props
[
1
]
addEventOpts
(
(
arg
as
SimpleExpressionNode
).
content
,
exp
as
SimpleExpressionNode
,
node
as
ComponentNode
)
props
[
1
].
exp
=
createCustomEventExpr
()
return
res
}
packages/uni-mp-baidu/src/plugin/transforms/vOn.ts
浏览文件 @
f338a300
...
...
@@ -13,6 +13,7 @@ import {
createSimpleExpression
,
createCompoundExpression
,
CompoundExpressionNode
,
ComponentNode
,
}
from
'
@vue/compiler-core
'
/**
* 百度小程序的自定义组件,不支持动态事件绑定,故转换为静态事件 + dataset
...
...
@@ -40,24 +41,35 @@ export const transformOn: DirectiveTransform = (
)
{
return
res
}
// data-event-opts
const
opts
=
findProp
(
node
,
ATTR_DATA_EVENT_OPTS
,
true
)
as
DirectiveNode
const
value
=
res
.
props
[
0
].
value
as
ExpressionNode
res
.
props
[
0
].
value
=
createSimpleExpression
(
'
__e
'
,
true
)
res
.
props
[
0
].
value
=
createCustomEventExpr
()
addEventOpts
(
arg
.
content
,
value
,
node
)
return
res
}
export
function
createCustomEventExpr
()
{
return
createSimpleExpression
(
'
__e
'
,
true
)
}
export
function
addEventOpts
(
event
:
string
,
value
:
ExpressionNode
,
node
:
ComponentNode
)
{
const
opts
=
findProp
(
node
,
ATTR_DATA_EVENT_OPTS
,
true
)
as
DirectiveNode
if
(
!
opts
)
{
node
.
props
.
push
(
createDataEventOptsProp
(
arg
.
cont
ent
,
value
))
node
.
props
.
push
(
createDataEventOptsProp
(
ev
ent
,
value
))
}
else
{
const
children
=
(
opts
.
exp
as
CompoundExpressionNode
).
children
children
.
splice
(
children
.
length
-
2
,
0
,
createDataEventOptsProperty
(
arg
.
cont
ent
,
value
)
createDataEventOptsProperty
(
ev
ent
,
value
)
)
}
return
res
}
const
ATTR_DATA_EVENT_OPTS
=
'
data-e-o
'
const
ATTR_DATA_EVENT_OPTS
=
'
eO
'
function
createDataEventOptsProperty
(
event
:
string
,
exp
:
ExpressionNode
)
{
return
createCompoundExpression
([
`'
${
event
}
'`
,
'
:
'
,
exp
,
'
,
'
])
...
...
packages/uni-mp-baidu/src/runtime/parseComponentOptions.ts
浏览文件 @
f338a300
...
...
@@ -10,7 +10,6 @@ import {
fixSetDataStart
,
fixSetDataEnd
,
}
from
'
../../../uni-mp-weixin/src/runtime/fixSetData
'
import
{
ComponentPublicInstance
}
from
'
vue
'
export
{
handleLink
,
initLifetimes
}
from
'
@dcloudio/uni-mp-weixin
'
...
...
@@ -84,7 +83,7 @@ export function parse(componentOptions: MPComponentOptions) {
__l
:
methods
.
__l
,
}
delete
methods
.
__l
// 百度小程序自定义组件,不支持绑定动态事件,故由 __e 分发
methods
.
__e
=
handleCustomEvent
}
...
...
@@ -92,19 +91,16 @@ function handleCustomEvent(
this
:
MPComponentInstance
,
event
:
{
type
:
string
target
:
{
dataset
:
{
eO
:
{
[
name
:
string
]:
string
}
}
}
detail
:
{
__
args__
:
any
[]
__
ins__
:
MPComponentInstance
&
{
eO
:
Record
<
string
,
string
>
}
}
}
)
{
const
{
type
,
target
:
{
dataset
:
{
eO
:
eventOpts
},
},
detail
:
{
__ins__
},
}
=
event
const
methodName
=
(
eventOpts
||
{})[
type
]
const
methodName
=
(
__ins__
.
properties
.
eO
||
{})[
type
]
if
(
!
methodName
)
{
return
console
.
warn
(
type
+
'
not found
'
)
}
...
...
packages/uni-mp-compiler/package.json
浏览文件 @
f338a300
...
...
@@ -5,9 +5,7 @@
"main"
:
"dist/index.js"
,
"types"
:
"dist/index.d.ts"
,
"files"
:
[
"dist/**/*.js"
,
"dist/**/*.json"
,
"dist/**/*.d.ts"
,
"dist"
,
"lib"
],
"repository"
:
{
...
...
packages/uni-mp-compiler/src/index.ts
浏览文件 @
f338a300
...
...
@@ -24,6 +24,7 @@ export { genExpr } from './codegen'
export
{
isForElementNode
}
from
'
./transforms/vFor
'
export
{
isUserComponent
}
from
'
./transforms/utils
'
export
{
transformOn
}
from
'
./transforms/vOn
'
export
{
transformModel
}
from
'
./transforms/vModel
'
export
*
from
'
./runtimeHelpers
'
export
function
parse
(
template
:
string
,
options
:
ParserOptions
=
{}):
RootNode
{
...
...
packages/uni-mp-compiler/src/transforms/transformElement.ts
浏览文件 @
f338a300
...
...
@@ -25,6 +25,7 @@ import { createMPCompilerError, MPErrorCodes } from '../errors'
import
{
BindingComponentTypes
,
DirectiveTransform
,
NodeTransform
,
TransformContext
,
}
from
'
../transform
'
...
...
@@ -274,7 +275,7 @@ export function processProps(
}
const
directiveTransform
=
context
.
directiveTransforms
[
name
]
if
(
directiveTransform
)
{
if
(
name
!==
'
model
'
&&
directiveTransform
)
{
const
{
props
}
=
directiveTransform
(
prop
,
node
,
context
as
any
)
if
(
props
.
length
)
{
prop
.
exp
=
props
[
0
].
value
as
ExpressionNode
...
...
@@ -282,16 +283,25 @@ export function processProps(
}
}
}
processVModel
(
node
,
context
)
const
transformVModel
=
(
context
.
directiveTransforms
.
model
||
transformModel
)
as
unknown
as
DirectiveTransform
processVModel
(
node
,
transformVModel
,
context
)
}
function
processVModel
(
node
:
ElementNode
,
context
:
TransformContext
)
{
function
processVModel
(
node
:
ElementNode
,
transformVModel
:
DirectiveTransform
,
context
:
TransformContext
)
{
const
{
props
}
=
node
const
dirs
:
DirectiveNode
[]
=
[]
for
(
let
i
=
0
;
i
<
props
.
length
;
i
++
)
{
const
prop
=
props
[
i
]
if
(
prop
.
type
===
NodeTypes
.
DIRECTIVE
&&
prop
.
name
===
'
model
'
)
{
dirs
.
push
(...
transformModel
(
prop
,
node
,
context
))
dirs
.
push
(
...(
transformVModel
(
prop
,
node
,
context
as
any
)
.
props
as
unknown
as
DirectiveNode
[])
)
props
.
splice
(
i
,
1
)
i
--
}
...
...
packages/uni-mp-compiler/src/transforms/vModel.ts
浏览文件 @
f338a300
...
...
@@ -9,6 +9,8 @@ import {
ExpressionNode
,
AttributeNode
,
createCompoundExpression
,
DirectiveTransform
,
TransformContext
as
VueTransformContext
,
}
from
'
@vue/compiler-core
'
import
{
DOMErrorCodes
,
createDOMCompilerError
}
from
'
@vue/compiler-dom
'
import
{
camelize
}
from
'
@vue/shared
'
...
...
@@ -16,17 +18,22 @@ import { V_ON } from '..'
import
{
createBindDirectiveNode
,
createOnDirectiveNode
}
from
'
../ast
'
import
{
genExpr
}
from
'
../codegen
'
import
{
TransformContext
}
from
'
../transform
'
import
{
DirectiveTransformResult
}
from
'
./transformElement
'
import
{
wrapperVOn
}
from
'
./vOn
'
export
const
transformModel
=
(
export
const
transformModel
:
DirectiveTransform
=
(
dir
:
DirectiveNode
,
node
:
ElementNode
,
context
:
TransformContext
_context
:
Vue
TransformContext
)
=>
{
const
baseResult
=
baseTransform
(
dir
,
node
,
context
as
any
)
const
context
=
_context
as
unknown
as
TransformContext
const
baseResult
=
baseTransform
(
dir
,
node
,
_context
)
// base transform has errors OR component v-model (only need props)
if
(
!
baseResult
.
props
.
length
||
node
.
tagType
===
ElementTypes
.
COMPONENT
)
{
return
transformComponentVModel
(
baseResult
.
props
,
context
)
return
transformComponentVModel
(
baseResult
.
props
,
context
)
as
unknown
as
DirectiveTransformResult
}
if
(
dir
.
arg
)
{
...
...
@@ -62,7 +69,11 @@ export const transformModel = (
)
}
return
transformElementVModel
(
baseResult
.
props
,
node
,
context
)
return
transformElementVModel
(
baseResult
.
props
,
node
,
context
)
as
unknown
as
DirectiveTransformResult
}
function
findInputDirectiveNode
(
props
:
(
AttributeNode
|
DirectiveNode
)[])
{
...
...
@@ -79,7 +90,7 @@ function transformElementVModel(
props
:
Property
[],
node
:
ElementNode
,
context
:
TransformContext
)
:
DirectiveNode
[]
{
)
{
const
dirs
=
transformVModel
(
props
,
context
,
{
binding
:
'
value
'
,
event
:
'
input
'
,
...
...
@@ -95,7 +106,7 @@ function transformElementVModel(
dirs
.
length
=
1
}
}
return
dirs
return
{
props
:
dirs
}
}
function
parseVOn
(
exp
:
ExpressionNode
,
context
:
TransformContext
)
{
...
...
@@ -122,12 +133,14 @@ function combineVOn(
function
transformComponentVModel
(
props
:
Property
[],
context
:
TransformContext
):
DirectiveNode
[]
{
return
transformVModel
(
props
,
context
,
{
formatEventCode
(
code
)
{
return
code
},
})
)
{
return
{
props
:
transformVModel
(
props
,
context
,
{
formatEventCode
(
code
)
{
return
code
},
}),
}
}
function
transformVModel
(
...
...
packages/uni-mp-core/src/runtime/componentInstance/index.ts
浏览文件 @
f338a300
...
...
@@ -17,8 +17,13 @@ function createEmitFn(oldEmit: Function, ctx: Record<string, any>) {
event
:
string
,
...
args
:
any
[]
)
{
if
(
ctx
.
$scope
&&
event
)
{
;(
ctx
.
$scope
as
any
).
triggerEvent
(
event
,
{
__args__
:
args
})
const
scope
=
ctx
.
$scope
as
MPComponentInstance
if
(
scope
&&
event
)
{
const
detail
:
Record
<
string
,
any
>
=
{
__args__
:
args
}
if
(
__PLATFORM__
===
'
mp-baidu
'
)
{
detail
.
__ins__
=
scope
}
scope
.
triggerEvent
(
event
,
detail
)
}
if
(
__PLATFORM__
===
'
mp-alipay
'
)
{
const
vnode
=
this
.
$
.
vnode
...
...
packages/uni-mp-core/src/runtime/componentProps.ts
浏览文件 @
f338a300
...
...
@@ -37,6 +37,14 @@ function createObserver(name: string) {
function
initDefaultProps
(
isBehavior
:
boolean
=
false
)
{
const
properties
:
Component
.
PropertyOption
=
{}
if
(
!
isBehavior
)
{
if
(
__PLATFORM__
===
'
mp-baidu
'
)
{
// 百度小程序自定义组件不支持绑定动态事件,动态dataset,故通过props传递事件信息
// event-opts
properties
.
eO
=
{
type
:
null
,
value
:
''
,
}
}
properties
.
vI
=
{
type
:
null
,
// 均不指定类型,避免 property received type-uncompatible value 警告
value
:
''
,
...
...
packages/uni-mp-core/src/runtime/polyfill.ts
浏览文件 @
f338a300
...
...
@@ -36,7 +36,11 @@ Page = function (options) {
initHook
(
ON_LOAD
,
options
)
return
MPPage
(
options
)
}
if
(
__PLATFORM__
===
'
mp-baidu
'
)
{
// 补充after,否则百度报:Cannot read property 'historyStack' of undefined
// https://smartprogram.baidu.com/forum/topic/show/153894
;(
Page
as
any
).
after
=
(
MPPage
as
any
).
after
}
Component
=
function
(
options
)
{
initHook
(
'
created
'
,
options
)
return
MPComponent
(
options
)
...
...
packages/uni-mp-kuaishou/dist/uni.mp.esm.js
浏览文件 @
f338a300
...
...
@@ -129,8 +129,10 @@ const MP_METHODS = [
];
function
createEmitFn
(
oldEmit
,
ctx
)
{
return
function
emit
(
event
,
...
args
)
{
if
(
ctx
.
$scope
&&
event
)
{
ctx
.
$scope
.
triggerEvent
(
event
,
{
__args__
:
args
});
const
scope
=
ctx
.
$scope
;
if
(
scope
&&
event
)
{
const
detail
=
{
__args__
:
args
};
scope
.
triggerEvent
(
event
,
detail
);
}
return
oldEmit
.
apply
(
this
,
[
event
,
...
args
]);
};
...
...
packages/uni-mp-qq/dist/uni.compiler.js
浏览文件 @
f338a300
...
...
@@ -89,6 +89,10 @@ const uniMiniProgramQQPlugin = {
define
:
{
__VUE_CREATED_DEFERRED__
:
false
,
},
build
:
{
// css 中不支持引用本地资源
assetsInlineLimit
:
40
*
1024
,
// 40kb
},
};
},
writeBundle
(
_
,
bundle
)
{
...
...
packages/uni-mp-qq/dist/uni.mp.esm.js
浏览文件 @
f338a300
...
...
@@ -129,8 +129,10 @@ const MP_METHODS = [
];
function
createEmitFn
(
oldEmit
,
ctx
)
{
return
function
emit
(
event
,
...
args
)
{
if
(
ctx
.
$scope
&&
event
)
{
ctx
.
$scope
.
triggerEvent
(
event
,
{
__args__
:
args
});
const
scope
=
ctx
.
$scope
;
if
(
scope
&&
event
)
{
const
detail
=
{
__args__
:
args
};
scope
.
triggerEvent
(
event
,
detail
);
}
return
oldEmit
.
apply
(
this
,
[
event
,
...
args
]);
};
...
...
packages/uni-mp-qq/src/plugin/index.ts
浏览文件 @
f338a300
...
...
@@ -14,6 +14,10 @@ const uniMiniProgramQQPlugin: Plugin = {
define
:
{
__VUE_CREATED_DEFERRED__
:
false
,
},
build
:
{
// css 中不支持引用本地资源
assetsInlineLimit
:
40
*
1024
,
// 40kb
},
}
},
writeBundle
(
_
,
bundle
)
{
...
...
packages/uni-mp-toutiao/dist/uni.mp.esm.js
浏览文件 @
f338a300
...
...
@@ -129,8 +129,10 @@ const MP_METHODS = [
];
function
createEmitFn
(
oldEmit
,
ctx
)
{
return
function
emit
(
event
,
...
args
)
{
if
(
ctx
.
$scope
&&
event
)
{
ctx
.
$scope
.
triggerEvent
(
event
,
{
__args__
:
args
});
const
scope
=
ctx
.
$scope
;
if
(
scope
&&
event
)
{
const
detail
=
{
__args__
:
args
};
scope
.
triggerEvent
(
event
,
detail
);
}
return
oldEmit
.
apply
(
this
,
[
event
,
...
args
]);
};
...
...
packages/uni-mp-vite/package.json
浏览文件 @
f338a300
...
...
@@ -5,8 +5,7 @@
"main"
:
"dist/index.js"
,
"types"
:
"dist/index.d.ts"
,
"files"
:
[
"dist/**/*.js"
,
"dist/**/*.d.ts"
,
"dist"
,
"lib"
],
"repository"
:
{
...
...
packages/uni-mp-vite/src/index.ts
浏览文件 @
f338a300
...
...
@@ -21,7 +21,7 @@ export default (options: UniMiniProgramPluginOptions) => {
uniPagesJsonPlugin
(
options
),
uniEntryPlugin
(
options
),
uniViteInjectPlugin
(
extend
({},
options
.
vite
.
inject
,
initProvide
())),
uniRenderjsPlugin
(),
uniRenderjsPlugin
(
{
lang
:
options
.
template
.
filter
?.
lang
}
),
uniMiniProgramPlugin
(
options
),
(
options
:
{
vueOptions
?:
{
script
?:
Partial
<
SFCScriptCompileOptions
>
}
...
...
packages/uni-mp-vite/src/plugin/build.ts
浏览文件 @
f338a300
...
...
@@ -33,7 +33,8 @@ export function buildOptions(): UserConfig['build'] {
// sourcemap: 'inline', // TODO
// target: ['chrome53'], // 由小程序自己启用 es6 编译
emptyOutDir
:
false
,
// 不清空输出目录,否则会影响自定义的一些文件输出,比如wxml
assetsInlineLimit
:
40
*
1024
,
// 40kb
// 由各个小程序控制,目前已知百度支持本地路径,其他不支持
// assetsInlineLimit: 0, // 40kb
lib
:
{
entry
:
resolveMainPathOnce
(
inputDir
),
formats
:
[
'
cjs
'
],
...
...
packages/uni-mp-vite/src/plugins/renderjs.ts
浏览文件 @
f338a300
...
...
@@ -15,7 +15,11 @@ export function getFiltersCache(resolvedConfig: ResolvedConfig) {
return
filtersCache
.
get
(
resolvedConfig
)
||
[]
}
export
function
uniRenderjsPlugin
():
Plugin
{
const
defaultCode
=
{
code
:
'
export default {}
'
,
}
export
function
uniRenderjsPlugin
({
lang
}:
{
lang
?:
string
}):
Plugin
{
let
resolvedConfig
:
ResolvedConfig
return
{
name
:
'
vite:uni-mp-renderjs
'
,
...
...
@@ -31,10 +35,12 @@ export function uniRenderjsPlugin(): Plugin {
return
}
debugRenderjs
(
id
)
if
(
type
!==
lang
)
{
return
defaultCode
}
if
(
!
name
)
{
this
.
error
(
missingModuleName
(
type
,
code
))
}
if
(
type
===
'
wxs
'
)
{
}
else
{
filtersCache
.
get
(
resolvedConfig
)
!
.
push
({
id
,
type
,
...
...
@@ -42,9 +48,7 @@ export function uniRenderjsPlugin(): Plugin {
code
,
})
}
return
{
code
:
'
export default {}
'
,
}
return
defaultCode
},
}
}
packages/uni-mp-weixin/dist/uni.compiler.js
浏览文件 @
f338a300
...
...
@@ -63,6 +63,10 @@ const uniMiniProgramWeixinPlugin = {
define
:
{
__VUE_CREATED_DEFERRED__
:
false
,
},
build
:
{
// css 中不支持引用本地资源
assetsInlineLimit
:
40
*
1024
,
// 40kb
},
};
},
};
...
...
packages/uni-mp-weixin/dist/uni.mp.esm.js
浏览文件 @
f338a300
...
...
@@ -66,8 +66,10 @@ const MP_METHODS = [
];
function
createEmitFn
(
oldEmit
,
ctx
)
{
return
function
emit
(
event
,
...
args
)
{
if
(
ctx
.
$scope
&&
event
)
{
ctx
.
$scope
.
triggerEvent
(
event
,
{
__args__
:
args
});
const
scope
=
ctx
.
$scope
;
if
(
scope
&&
event
)
{
const
detail
=
{
__args__
:
args
};
scope
.
triggerEvent
(
event
,
detail
);
}
return
oldEmit
.
apply
(
this
,
[
event
,
...
args
]);
};
...
...
packages/uni-mp-weixin/src/plugin/index.ts
浏览文件 @
f338a300
...
...
@@ -13,6 +13,10 @@ const uniMiniProgramWeixinPlugin: Plugin = {
define
:
{
__VUE_CREATED_DEFERRED__
:
false
,
},
build
:
{
// css 中不支持引用本地资源
assetsInlineLimit
:
40
*
1024
,
// 40kb
},
}
},
}
...
...
packages/uni-quickapp-webview/dist/uni.mp.esm.js
浏览文件 @
f338a300
...
...
@@ -129,8 +129,10 @@ const MP_METHODS = [
];
function
createEmitFn
(
oldEmit
,
ctx
)
{
return
function
emit
(
event
,
...
args
)
{
if
(
ctx
.
$scope
&&
event
)
{
ctx
.
$scope
.
triggerEvent
(
event
,
{
__args__
:
args
});
const
scope
=
ctx
.
$scope
;
if
(
scope
&&
event
)
{
const
detail
=
{
__args__
:
args
};
scope
.
triggerEvent
(
event
,
detail
);
}
return
oldEmit
.
apply
(
this
,
[
event
,
...
args
]);
};
...
...
packages/vite-plugin-uni/package.json
浏览文件 @
f338a300
...
...
@@ -8,8 +8,7 @@
"main"
:
"dist/index.js"
,
"types"
:
"dist/index.d.ts"
,
"files"
:
[
"dist/**/*.js"
,
"dist/**/*.d.ts"
,
"dist"
,
"lib"
],
"repository"
:
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录