Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yangkaifeng
uni-app
提交
2f0369be
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,发现更多精彩内容 >>
提交
2f0369be
编写于
10月 22, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(mp): add vue-id
上级
6b953f31
变更
21
隐藏空白更改
内联
并排
Showing
21 changed file
with
337 addition
and
119 deletion
+337
-119
packages/uni-app-plus/dist/uni-app-service.es.js
packages/uni-app-plus/dist/uni-app-service.es.js
+52
-3
packages/uni-h5/dist/uni-h5.cjs.js
packages/uni-h5/dist/uni-h5.cjs.js
+1
-1
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+1
-1
packages/uni-mp-compiler/__tests__/codegen.spec.ts
packages/uni-mp-compiler/__tests__/codegen.spec.ts
+4
-4
packages/uni-mp-compiler/__tests__/component.spec.ts
packages/uni-mp-compiler/__tests__/component.spec.ts
+85
-3
packages/uni-mp-compiler/__tests__/ref.spec.ts
packages/uni-mp-compiler/__tests__/ref.spec.ts
+7
-7
packages/uni-mp-compiler/__tests__/scope.spec.ts
packages/uni-mp-compiler/__tests__/scope.spec.ts
+6
-6
packages/uni-mp-compiler/__tests__/vFor.spec.ts
packages/uni-mp-compiler/__tests__/vFor.spec.ts
+22
-22
packages/uni-mp-compiler/__tests__/vModel.spec.ts
packages/uni-mp-compiler/__tests__/vModel.spec.ts
+2
-2
packages/uni-mp-compiler/__tests__/vSlot.spec.ts
packages/uni-mp-compiler/__tests__/vSlot.spec.ts
+4
-4
packages/uni-mp-compiler/src/compile.ts
packages/uni-mp-compiler/src/compile.ts
+2
-0
packages/uni-mp-compiler/src/transform.ts
packages/uni-mp-compiler/src/transform.ts
+7
-0
packages/uni-mp-compiler/src/transforms/transformComponent.ts
...ages/uni-mp-compiler/src/transforms/transformComponent.ts
+73
-0
packages/uni-mp-compiler/src/transforms/transformElement.ts
packages/uni-mp-compiler/src/transforms/transformElement.ts
+2
-20
packages/uni-mp-compiler/src/transforms/transformIdentifier.ts
...ges/uni-mp-compiler/src/transforms/transformIdentifier.ts
+14
-1
packages/uni-mp-compiler/src/transforms/vFor.ts
packages/uni-mp-compiler/src/transforms/vFor.ts
+32
-37
packages/uni-mp-vue/dist/vue.runtime.esm.js
packages/uni-mp-vue/dist/vue.runtime.esm.js
+10
-3
packages/uni-mp-vue/src/helpers/vFor.ts
packages/uni-mp-vue/src/helpers/vFor.ts
+3
-3
packages/uni-mp-vue/src/helpers/vOn.ts
packages/uni-mp-vue/src/helpers/vOn.ts
+8
-0
packages/uni-mp-weixin/dist/uni.compiler.js
packages/uni-mp-weixin/dist/uni.compiler.js
+1
-1
packages/uni-mp-weixin/src/plugin/index.ts
packages/uni-mp-weixin/src/plugin/index.ts
+1
-1
未找到文件。
packages/uni-app-plus/dist/uni-app-service.es.js
浏览文件 @
2f0369be
...
@@ -946,7 +946,7 @@ var serviceContext = (function (vue) {
...
@@ -946,7 +946,7 @@ var serviceContext = (function (vue) {
res.errMsg = normalizeErrMsg$1(res.errMsg, name);
res.errMsg = normalizeErrMsg$1(res.errMsg, name);
isFunction(beforeAll) && beforeAll(res);
isFunction(beforeAll) && beforeAll(res);
if (res.errMsg === name + ':ok') {
if (res.errMsg === name + ':ok') {
isFunction(beforeSuccess) && beforeSuccess(res);
isFunction(beforeSuccess) && beforeSuccess(res
, args
);
hasSuccess && success(res);
hasSuccess && success(res);
}
}
else {
else {
...
@@ -1767,6 +1767,25 @@ var serviceContext = (function (vue) {
...
@@ -1767,6 +1767,25 @@ var serviceContext = (function (vue) {
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['取消', '從相冊選擇', '拍攝']), false);
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['取消', '從相冊選擇', '拍攝']), false);
}
}
});
});
const initI18nSetClipboardDataMsgsOnce = /*#__PURE__*/ once(() => {
const name = 'uni.setClipboardData.';
const keys = ['success'];
{
useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Content copied']), false);
}
{
useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ['Contenido copiado']), false);
}
{
useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ['Contenu copié']), false);
}
{
useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ['内容已复制']), false);
}
{
useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['內容已復制']), false);
}
});
const initI18nScanCodeMsgsOnce = /*#__PURE__*/ once(() => {
const initI18nScanCodeMsgsOnce = /*#__PURE__*/ once(() => {
const name = 'uni.scanCode.';
const name = 'uni.scanCode.';
const keys = ['title', 'album', 'fail', 'flash.on', 'flash.off'];
const keys = ['title', 'album', 'fail', 'flash.on', 'flash.off'];
...
@@ -4477,7 +4496,37 @@ var serviceContext = (function (vue) {
...
@@ -4477,7 +4496,37 @@ var serviceContext = (function (vue) {
const API_ADD_PHONE_CONTACT = 'addPhoneContact';
const API_ADD_PHONE_CONTACT = 'addPhoneContact';
const API_GET_CLIPBOARD_DATA = 'getClipboardData';
const API_GET_CLIPBOARD_DATA = 'getClipboardData';
const API_SET_CLIPBOARD_DATA = 'setClipboardData';
const API_SET_CLIPBOARD_DATA = 'setClipboardData';
const SetClipboardDataOptions = {
formatArgs: {
showToast: true,
},
beforeInvoke() {
initI18nSetClipboardDataMsgsOnce();
},
beforeSuccess(res, params) {
if (!params.showToast)
return;
const { t } = useI18n();
const title = t('uni.setClipboardData.success');
if (title) {
uni.showToast({
title: title,
icon: 'success',
mask: false,
});
}
},
};
const SetClipboardDataProtocol = {
data: {
type: String,
required: true,
},
showToast: {
type: Boolean,
},
};
const API_ON_ACCELEROMETER = 'onAccelerometer';
const API_ON_ACCELEROMETER = 'onAccelerometer';
const API_OFF_ACCELEROMETER = 'offAccelerometer';
const API_OFF_ACCELEROMETER = 'offAccelerometer';
...
@@ -6802,7 +6851,7 @@ var serviceContext = (function (vue) {
...
@@ -6802,7 +6851,7 @@ var serviceContext = (function (vue) {
const clipboard = requireNativePlugin('clipboard');
const clipboard = requireNativePlugin('clipboard');
clipboard.setString(options.data);
clipboard.setString(options.data);
resolve();
resolve();
});
}
, SetClipboardDataProtocol, SetClipboardDataOptions
);
const API_ON_NETWORK_STATUS_CHANGE = 'onNetworkStatusChange';
const API_ON_NETWORK_STATUS_CHANGE = 'onNetworkStatusChange';
function networkListener() {
function networkListener() {
...
...
packages/uni-h5/dist/uni-h5.cjs.js
浏览文件 @
2f0369be
...
@@ -1128,7 +1128,7 @@ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } =
...
@@ -1128,7 +1128,7 @@ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } =
res
.
errMsg
=
normalizeErrMsg$1
(
res
.
errMsg
,
name
);
res
.
errMsg
=
normalizeErrMsg$1
(
res
.
errMsg
,
name
);
shared
.
isFunction
(
beforeAll
)
&&
beforeAll
(
res
);
shared
.
isFunction
(
beforeAll
)
&&
beforeAll
(
res
);
if
(
res
.
errMsg
===
name
+
"
:ok
"
)
{
if
(
res
.
errMsg
===
name
+
"
:ok
"
)
{
shared
.
isFunction
(
beforeSuccess
)
&&
beforeSuccess
(
res
);
shared
.
isFunction
(
beforeSuccess
)
&&
beforeSuccess
(
res
,
args
);
hasSuccess
&&
success
(
res
);
hasSuccess
&&
success
(
res
);
}
else
{
}
else
{
hasFail
&&
fail
(
res
);
hasFail
&&
fail
(
res
);
...
...
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
2f0369be
...
@@ -2407,7 +2407,7 @@ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } =
...
@@ -2407,7 +2407,7 @@ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } =
res.errMsg = normalizeErrMsg$1(res.errMsg, name);
res.errMsg = normalizeErrMsg$1(res.errMsg, name);
isFunction(beforeAll) && beforeAll(res);
isFunction(beforeAll) && beforeAll(res);
if (res.errMsg === name + ":ok") {
if (res.errMsg === name + ":ok") {
isFunction(beforeSuccess) && beforeSuccess(res);
isFunction(beforeSuccess) && beforeSuccess(res
, args
);
hasSuccess && success(res);
hasSuccess && success(res);
} else {
} else {
hasFail && fail(res);
hasFail && fail(res);
...
...
packages/uni-mp-compiler/__tests__/codegen.spec.ts
浏览文件 @
2f0369be
...
@@ -8,7 +8,7 @@ describe('compiler: codegen', () => {
...
@@ -8,7 +8,7 @@ describe('compiler: codegen', () => {
`import { vOn as _vOn, vFor as _vFor } from "vue"
`import { vOn as _vOn, vFor as _vFor } from "vue"
export function render(_ctx, _cache) {
export function render(_ctx, _cache) {
return { a: _vFor(_ctx.items,
item
=> { return {}; }), b: _vOn(_ctx.onClick) }
return { a: _vFor(_ctx.items,
(item, k0, i0)
=> { return {}; }), b: _vOn(_ctx.onClick) }
}`
,
}`
,
{
inline
:
false
,
mode
:
'
module
'
,
prefixIdentifiers
:
false
}
{
inline
:
false
,
mode
:
'
module
'
,
prefixIdentifiers
:
false
}
)
)
...
@@ -21,7 +21,7 @@ export function render(_ctx, _cache) {
...
@@ -21,7 +21,7 @@ export function render(_ctx, _cache) {
`import { vOn as _vOn, vFor as _vFor } from "vue"
`import { vOn as _vOn, vFor as _vFor } from "vue"
export function render(_ctx, _cache) {
export function render(_ctx, _cache) {
return { a: _vFor(_ctx.items,
item
=> { return {}; }), b: _vOn(_ctx.onClick) }
return { a: _vFor(_ctx.items,
(item, k0, i0)
=> { return {}; }), b: _vOn(_ctx.onClick) }
}`
,
}`
,
{
inline
:
false
,
mode
:
'
module
'
}
{
inline
:
false
,
mode
:
'
module
'
}
)
)
...
@@ -37,7 +37,7 @@ return function render(_ctx, _cache) {
...
@@ -37,7 +37,7 @@ return function render(_ctx, _cache) {
with (_ctx) {
with (_ctx) {
const { vOn: _vOn, vFor: _vFor } = _Vue
const { vOn: _vOn, vFor: _vFor } = _Vue
return { a: _vFor(items,
item
=> { return {}; }), b: _vOn(onClick) }
return { a: _vFor(items,
(item, k0, i0)
=> { return {}; }), b: _vOn(onClick) }
}
}
}`
,
}`
,
{
inline
:
false
,
mode
:
'
function
'
,
prefixIdentifiers
:
false
}
{
inline
:
false
,
mode
:
'
function
'
,
prefixIdentifiers
:
false
}
...
@@ -50,7 +50,7 @@ return function render(_ctx, _cache) {
...
@@ -50,7 +50,7 @@ return function render(_ctx, _cache) {
`const { vOn: _vOn, vFor: _vFor } = Vue
`const { vOn: _vOn, vFor: _vFor } = Vue
return function render(_ctx, _cache) {
return function render(_ctx, _cache) {
return { a: _vFor(_ctx.items,
item
=> { return {}; }), b: _vOn(_ctx.onClick) }
return { a: _vFor(_ctx.items,
(item, k0, i0)
=> { return {}; }), b: _vOn(_ctx.onClick) }
}`
,
}`
,
{
inline
:
false
,
mode
:
'
function
'
}
{
inline
:
false
,
mode
:
'
function
'
}
)
)
...
...
packages/uni-mp-compiler/__tests__/component.spec.ts
浏览文件 @
2f0369be
...
@@ -2,12 +2,94 @@ import { addComponentBindLink } from '@dcloudio/uni-cli-shared'
...
@@ -2,12 +2,94 @@ import { addComponentBindLink } from '@dcloudio/uni-cli-shared'
import
{
assert
}
from
'
./testUtils
'
import
{
assert
}
from
'
./testUtils
'
describe
(
'
compiler: transform component
'
,
()
=>
{
describe
(
'
compiler: transform component
'
,
()
=>
{
test
(
'
basic
'
,
()
=>
{
// test('basic', () => {
// assert(
// `<custom/>`,
// `<custom class="vue-ref" vue-id="2a9ec0b0-0" bind:__l="__l"/>`,
// `(_ctx, _cache) => {
// return {}
// }`,
// {
// nodeTransforms: [addComponentBindLink as any],
// }
// )
// })
test
(
'
component + component
'
,
()
=>
{
assert
(
assert
(
`<custom
/
>`
,
`<custom
><custom1/></custom
>`
,
`<custom
class="vue-ref" bind:__l="__l"/
>`
,
`<custom
vue-slots="{{['default']}}" class="vue-ref" vue-id="2a9ec0b0-0" bind:__l="__l"><custom1 class="vue-ref" vue-id="2a9ec0b0-1,2a9ec0b0-0" bind:__l="__l"/></custom
>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return {}
return {}
}`
,
{
nodeTransforms
:
[
addComponentBindLink
as
any
],
}
)
})
test
(
'
component + component + component
'
,
()
=>
{
assert
(
`<custom><custom1><custom2/><custom2/></custom1></custom>`
,
`<custom vue-slots="{{['default']}}" class="vue-ref" vue-id="2a9ec0b0-0" bind:__l="__l"><custom1 vue-slots="{{['default']}}" class="vue-ref" vue-id="2a9ec0b0-1,2a9ec0b0-0" bind:__l="__l"><custom2 class="vue-ref" vue-id="2a9ec0b0-2,2a9ec0b0-1" bind:__l="__l"/><custom2 class="vue-ref" vue-id="2a9ec0b0-3,2a9ec0b0-1" bind:__l="__l"/></custom1></custom>`
,
`(_ctx, _cache) => {
return {}
}`
,
{
nodeTransforms
:
[
addComponentBindLink
as
any
],
}
)
})
test
(
'
component with v-for
'
,
()
=>
{
assert
(
`<custom v-for="item in items"/>`
,
`<custom wx:for="{{a}}" wx:for-item="item" class="vue-ref-in-for" vue-id="{{item.a}}" bind:__l="__l"/>`
,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }) }
}`
,
{
nodeTransforms
:
[
addComponentBindLink
as
any
],
}
)
assert
(
`<custom v-for="(item,key,index) in items"/>`
,
`<custom wx:for="{{a}}" wx:for-item="item" class="vue-ref-in-for" vue-id="{{item.a}}" bind:__l="__l"/>`
,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, key, index) => { return { a: '2a9ec0b0-0' + '-' + index }; }) }
}`
,
{
nodeTransforms
:
[
addComponentBindLink
as
any
],
}
)
})
test
(
'
component + component with v-for
'
,
()
=>
{
assert
(
`<custom><custom1 v-for="item in items"/></custom>`
,
`<custom vue-slots="{{['default']}}" class="vue-ref" vue-id="2a9ec0b0-0" bind:__l="__l"><custom1 wx:for="{{a}}" wx:for-item="item" class="vue-ref-in-for" vue-id="{{item.a}}" bind:__l="__l"/></custom>`
,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0' }; }) }
}`
,
{
nodeTransforms
:
[
addComponentBindLink
as
any
],
}
)
})
test
(
'
component with v-for + component
'
,
()
=>
{
assert
(
`<custom v-for="item in items"><custom1/></custom>`
,
`<custom wx:for="{{a}}" wx:for-item="item" vue-slots="{{['default']}}" class="vue-ref-in-for" vue-id="{{item.b}}" bind:__l="__l"><custom1 class="vue-ref-in-for" vue-id="{{item.a}}" bind:__l="__l"/></custom>`
,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-1' + '-' + i0 + ',' + ('2a9ec0b0-0' + '-' + i0), b: '2a9ec0b0-0' + '-' + i0 }; }) }
}`
,
{
nodeTransforms
:
[
addComponentBindLink
as
any
],
}
)
})
test
(
'
component with v-for + component with v-for
'
,
()
=>
{
assert
(
`<custom v-for="item in items"><custom1 v-for="item1 in item.items"/></custom>`
,
`<custom wx:for="{{a}}" wx:for-item="item" vue-slots="{{['default']}}" class="vue-ref-in-for" vue-id="{{item.b}}" bind:__l="__l"><custom1 wx:for="{{item.a}}" wx:for-item="item1" class="vue-ref-in-for" vue-id="{{item1.a}}" bind:__l="__l"/></custom>`
,
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: _vFor(item.items, (item1, k1, i1) => { return { a: '2a9ec0b0-1' + '-' + i0 + '-' + i1 + ',' + ('2a9ec0b0-0' + '-' + i0) }; }), b: '2a9ec0b0-0' + '-' + i0 }; }) }
}`
,
}`
,
{
{
nodeTransforms
:
[
addComponentBindLink
as
any
],
nodeTransforms
:
[
addComponentBindLink
as
any
],
...
...
packages/uni-mp-compiler/__tests__/ref.spec.ts
浏览文件 @
2f0369be
...
@@ -4,14 +4,14 @@ describe('compiler: transform ref', () => {
...
@@ -4,14 +4,14 @@ describe('compiler: transform ref', () => {
test
(
'
vue-ref
'
,
()
=>
{
test
(
'
vue-ref
'
,
()
=>
{
assert
(
assert
(
`<custom/>`
,
`<custom/>`
,
`<custom class="vue-ref"/>`
,
`<custom class="vue-ref"
vue-id="2a9ec0b0-0"
/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return {}
return {}
}`
}`
)
)
assert
(
assert
(
`<custom/><custom/>`
,
`<custom/><custom/>
<custom1/>
`
,
`<custom class="vue-ref"
/><custom class="vue-ref
"/>`
,
`<custom class="vue-ref"
vue-id="2a9ec0b0-0"/><custom class="vue-ref" vue-id="2a9ec0b0-1"/><custom1 class="vue-ref" vue-id="2a9ec0b0-2
"/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return {}
return {}
}`
}`
...
@@ -20,16 +20,16 @@ describe('compiler: transform ref', () => {
...
@@ -20,16 +20,16 @@ describe('compiler: transform ref', () => {
test
(
'
vue-ref-in-for
'
,
()
=>
{
test
(
'
vue-ref-in-for
'
,
()
=>
{
assert
(
assert
(
`<custom v-for="item in items"/>`
,
`<custom v-for="item in items"/>`
,
`<custom wx:for="{{a}}" wx:for-item="item" class="vue-ref-in-for"/>`
,
`<custom wx:for="{{a}}" wx:for-item="item" class="vue-ref-in-for"
vue-id="{{item.a}}"
/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items,
item => { return {
}; }) }
return { a: _vFor(_ctx.items,
(item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0
}; }) }
}`
}`
)
)
})
})
test
(
'
static ref
'
,
()
=>
{
test
(
'
static ref
'
,
()
=>
{
assert
(
assert
(
`<custom ref="custom"/>`
,
`<custom ref="custom"/>`
,
`<custom class="vue-ref" data-ref="custom"/>`
,
`<custom class="vue-ref" data-ref="custom"
vue-id="2a9ec0b0-0"
/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return {}
return {}
}`
}`
...
@@ -38,7 +38,7 @@ describe('compiler: transform ref', () => {
...
@@ -38,7 +38,7 @@ describe('compiler: transform ref', () => {
test
(
'
dynamic ref
'
,
()
=>
{
test
(
'
dynamic ref
'
,
()
=>
{
assert
(
assert
(
`<custom :ref="custom"/>`
,
`<custom :ref="custom"/>`
,
`<custom class="vue-ref" data-ref="{{a}}"/>`
,
`<custom class="vue-ref" data-ref="{{a}}"
vue-id="2a9ec0b0-0"
/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _ctx.custom }
return { a: _ctx.custom }
}`
}`
...
...
packages/uni-mp-compiler/__tests__/scope.spec.ts
浏览文件 @
2f0369be
...
@@ -6,7 +6,7 @@ describe('compiler: scope', () => {
...
@@ -6,7 +6,7 @@ describe('compiler: scope', () => {
`<view v-for="item in items" :key="item.id" :class="{red: item.isRed}" @longpress="longpress" @click="onClick(item)">{{item.title}}</view>`
,
`<view v-for="item in items" :key="item.id" :class="{red: item.isRed}" @longpress="longpress" @click="onClick(item)">{{item.title}}</view>`
,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="b" class="{{[item.c && 'red']}}" bindlongpress="{{b}}" bindtap="{{item.d}}">{{item.a}}</view>`
,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="b" class="{{[item.c && 'red']}}" bindlongpress="{{b}}" bindtap="{{item.d}}">{{item.a}}</view>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items,
item
=> { return { a: _toDisplayString(item.title), b: item.id, c: item.isRed, d: _vOn($event => _ctx.onClick(item)) }; }), b: _vOn(_ctx.longpress) }
return { a: _vFor(_ctx.items,
(item, k0, i0)
=> { return { a: _toDisplayString(item.title), b: item.id, c: item.isRed, d: _vOn($event => _ctx.onClick(item)) }; }), b: _vOn(_ctx.longpress) }
}`
}`
)
)
})
})
...
@@ -15,21 +15,21 @@ describe('compiler: scope', () => {
...
@@ -15,21 +15,21 @@ describe('compiler: scope', () => {
`<view v-for="item in items" :key="item.id">{{item.title}}{{handle(foo)}}<view v-for="item1 in item.list" :key="item1.id" @click="onClick(item)" @longpress="longpress(item1)">{{item.id}}{{item1.title}}</view></view>`
,
`<view v-for="item in items" :key="item.id">{{item.title}}{{handle(foo)}}<view v-for="item1 in item.list" :key="item1.id" @click="onClick(item)" @longpress="longpress(item1)">{{item.id}}{{item1.title}}</view></view>`
,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="e">{{item.a}}{{b}}<view wx:for="{{item.b}}" wx:for-item="item1" wx:key="b" bindtap="{{item.d}}" bindlongpress="{{item1.c}}">{{item.c}}{{item1.a}}</view></view>`
,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="e">{{item.a}}{{b}}<view wx:for="{{item.b}}" wx:for-item="item1" wx:key="b" bindtap="{{item.d}}" bindlongpress="{{item1.c}}">{{item.c}}{{item1.a}}</view></view>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items,
item => { return { a: _toDisplayString(item.title), b: _vFor(item.list, item1
=> { return { a: _toDisplayString(item1.title), b: item1.id, c: _vOn($event => _ctx.longpress(item1)) }; }), c: _toDisplayString(item.id), d: _vOn($event => _ctx.onClick(item)), e: item.id }; }), b: _toDisplayString(_ctx.handle(_ctx.foo)) }
return { a: _vFor(_ctx.items,
(item, k0, i0) => { return { a: _toDisplayString(item.title), b: _vFor(item.list, (item1, k1, i1)
=> { return { a: _toDisplayString(item1.title), b: item1.id, c: _vOn($event => _ctx.longpress(item1)) }; }), c: _toDisplayString(item.id), d: _vOn($event => _ctx.onClick(item)), e: item.id }; }), b: _toDisplayString(_ctx.handle(_ctx.foo)) }
}`
}`
)
)
assert
(
assert
(
`<view v-for="item in items"><view v-for="item1 in item1" :data-id="item.id" :data-title="item1.title"/></view>`
,
`<view v-for="item in items"><view v-for="item1 in item1" :data-id="item.id" :data-title="item1.title"/></view>`
,
`<view wx:for="{{a}}" wx:for-item="item"><view wx:for="{{b}}" wx:for-item="item1" data-id="{{item.a}}" data-title="{{item1.a}}"/></view>`
,
`<view wx:for="{{a}}" wx:for-item="item"><view wx:for="{{b}}" wx:for-item="item1" data-id="{{item.a}}" data-title="{{item1.a}}"/></view>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items,
item => { return { a: item.id }; }), b: _vFor(_ctx.item1, item1
=> { return { a: item1.title }; }) }
return { a: _vFor(_ctx.items,
(item, k0, i0) => { return { a: item.id }; }), b: _vFor(_ctx.item1, (item1, k1, i1)
=> { return { a: item1.title }; }) }
}`
}`
)
)
assert
(
assert
(
`<view v-for="(item,weekIndex) in weeks" :key="weekIndex" :data-id="item.id"><view v-for="(weeks,weeksIndex) in item" :key="weeksIndex" :data-id="weeks.id"/></view>`
,
`<view v-for="(item,weekIndex) in weeks" :key="weekIndex" :data-id="item.id"><view v-for="(weeks,weeksIndex) in item" :key="weeksIndex" :data-id="weeks.id"/></view>`
,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="b" data-id="{{item.c}}"><view wx:for="{{item.a}}" wx:for-item="weeks" wx:key="a" data-id="{{weeks.b}}"/></view>`
,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="b" data-id="{{item.c}}"><view wx:for="{{item.a}}" wx:for-item="weeks" wx:key="a" data-id="{{weeks.b}}"/></view>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.weeks, (item, weekIndex
) => { return { a: _vFor(item, (weeks, weeksIndex
) => { return { a: weeksIndex, b: weeks.id }; }), b: weekIndex, c: item.id }; }) }
return { a: _vFor(_ctx.weeks, (item, weekIndex
, i0) => { return { a: _vFor(item, (weeks, weeksIndex, i1
) => { return { a: weeksIndex, b: weeks.id }; }), b: weekIndex, c: item.id }; }) }
}`
}`
)
)
})
})
...
@@ -38,7 +38,7 @@ describe('compiler: scope', () => {
...
@@ -38,7 +38,7 @@ describe('compiler: scope', () => {
`<view v-for="item in items"><view v-if="true" :data-id="id"></view></view>`
,
`<view v-for="item in items"><view v-if="true" :data-id="id"></view></view>`
,
`<view wx:for="{{a}}" wx:for-item="item"><view wx:if="{{true}}" data-id="{{item.a}}"></view></view>`
,
`<view wx:for="{{a}}" wx:for-item="item"><view wx:if="{{true}}" data-id="{{item.a}}"></view></view>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items,
item
=> { return { ...(true ? { a: _ctx.id } : {}) }; }) }
return { a: _vFor(_ctx.items,
(item, k0, i0)
=> { return { ...(true ? { a: _ctx.id } : {}) }; }) }
}`
}`
)
)
})
})
...
@@ -56,7 +56,7 @@ describe('compiler: scope', () => {
...
@@ -56,7 +56,7 @@ describe('compiler: scope', () => {
`<view v-if="ok"><view v-for="item in items" :key="item.id" :data-title="item.title" :data-foo="foo" @click="onClick"/></view><view v-else-if="ok1"><view v-for="item in items" :key="item.id" :data-title="item.title" :data-foo="foo" @click="onClick"/></view><view v-else><view v-for="item in items" :key="item.id" :data-title="item.title" :data-foo="foo" @click="onClick"/></view>`
,
`<view v-if="ok"><view v-for="item in items" :key="item.id" :data-title="item.title" :data-foo="foo" @click="onClick"/></view><view v-else-if="ok1"><view v-for="item in items" :key="item.id" :data-title="item.title" :data-foo="foo" @click="onClick"/></view><view v-else><view v-for="item in items" :key="item.id" :data-title="item.title" :data-foo="foo" @click="onClick"/></view>`
,
`<view wx:if="{{a}}"><view wx:for="{{b}}" wx:for-item="item" wx:key="a" data-title="{{item.b}}" data-foo="{{c}}" bindtap="{{d}}"/></view><view wx:elif="{{e}}"><view wx:for="{{f}}" wx:for-item="item" wx:key="a" data-title="{{item.b}}" data-foo="{{g}}" bindtap="{{h}}"/></view><view wx:else><view wx:for="{{i}}" wx:for-item="item" wx:key="a" data-title="{{item.b}}" data-foo="{{j}}" bindtap="{{k}}"/></view>`
,
`<view wx:if="{{a}}"><view wx:for="{{b}}" wx:for-item="item" wx:key="a" data-title="{{item.b}}" data-foo="{{c}}" bindtap="{{d}}"/></view><view wx:elif="{{e}}"><view wx:for="{{f}}" wx:for-item="item" wx:key="a" data-title="{{item.b}}" data-foo="{{g}}" bindtap="{{h}}"/></view><view wx:else><view wx:for="{{i}}" wx:for-item="item" wx:key="a" data-title="{{item.b}}" data-foo="{{j}}" bindtap="{{k}}"/></view>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _ctx.ok, ...(_ctx.ok ? { b: _vFor(_ctx.items,
item => { return { a: item.id, b: item.title }; }), c: _ctx.foo, d: _vOn(_ctx.onClick) } : _ctx.ok1 ? { f: _vFor(_ctx.items, item => { return { a: item.id, b: item.title }; }), g: _ctx.foo, h: _vOn(_ctx.onClick) } : { i: _vFor(_ctx.items, item
=> { return { a: item.id, b: item.title }; }), j: _ctx.foo, k: _vOn(_ctx.onClick) }), e: _ctx.ok1 }
return { a: _ctx.ok, ...(_ctx.ok ? { b: _vFor(_ctx.items,
(item, k0, i0) => { return { a: item.id, b: item.title }; }), c: _ctx.foo, d: _vOn(_ctx.onClick) } : _ctx.ok1 ? { f: _vFor(_ctx.items, (item, k0, i0) => { return { a: item.id, b: item.title }; }), g: _ctx.foo, h: _vOn(_ctx.onClick) } : { i: _vFor(_ctx.items, (item, k0, i0)
=> { return { a: item.id, b: item.title }; }), j: _ctx.foo, k: _vOn(_ctx.onClick) }), e: _ctx.ok1 }
}`
}`
)
)
})
})
...
...
packages/uni-mp-compiler/__tests__/vFor.spec.ts
浏览文件 @
2f0369be
...
@@ -29,7 +29,7 @@ describe(`compiler: v-for`, () => {
...
@@ -29,7 +29,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="index in 5" />`
,
`<view v-for="index in 5" />`
,
`<view wx:for="{{a}}" wx:for-item="index"/>`
,
`<view wx:for="{{a}}" wx:for-item="index"/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(5,
index
=> { return {}; }) }
return { a: _vFor(5,
(index, k0, i0)
=> { return {}; }) }
}`
}`
)
)
})
})
...
@@ -38,7 +38,7 @@ describe(`compiler: v-for`, () => {
...
@@ -38,7 +38,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="(item) in items" />`
,
`<view v-for="(item) in items" />`
,
`<view wx:for="{{a}}" wx:for-item="item"/>`
,
`<view wx:for="{{a}}" wx:for-item="item"/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items,
item
=> { return {}; }) }
return { a: _vFor(_ctx.items,
(item, k0, i0)
=> { return {}; }) }
}`
}`
)
)
})
})
...
@@ -47,7 +47,7 @@ describe(`compiler: v-for`, () => {
...
@@ -47,7 +47,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="({ id, value }) in items" />`
,
`<view v-for="({ id, value }) in items" />`
,
`<view wx:for="{{a}}" wx:for-item="v0"/>`
,
`<view wx:for="{{a}}" wx:for-item="v0"/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, ({ id, value }) => { return {}; }) }
return { a: _vFor(_ctx.items, ({ id, value }
, k0, i0
) => { return {}; }) }
}`
}`
)
)
})
})
...
@@ -56,7 +56,7 @@ describe(`compiler: v-for`, () => {
...
@@ -56,7 +56,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="([ id, value ]) in items" />`
,
`<view v-for="([ id, value ]) in items" />`
,
`<view wx:for="{{a}}" wx:for-item="v0"/>`
,
`<view wx:for="{{a}}" wx:for-item="v0"/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, ([id, value]) => { return {}; }) }
return { a: _vFor(_ctx.items, ([id, value]
, k0, i0
) => { return {}; }) }
}`
}`
)
)
})
})
...
@@ -65,7 +65,7 @@ describe(`compiler: v-for`, () => {
...
@@ -65,7 +65,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="(item, key) in items" />`
,
`<view v-for="(item, key) in items" />`
,
`<view wx:for="{{a}}" wx:for-item="item"/>`
,
`<view wx:for="{{a}}" wx:for-item="item"/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, key) => { return {}; }) }
return { a: _vFor(_ctx.items, (item, key
, i0
) => { return {}; }) }
}`
}`
)
)
})
})
...
@@ -83,7 +83,7 @@ describe(`compiler: v-for`, () => {
...
@@ -83,7 +83,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="(value,,index) in items" />`
,
`<view v-for="(value,,index) in items" />`
,
`<view wx:for="{{a}}" wx:for-item="value"/>`
,
`<view wx:for="{{a}}" wx:for-item="value"/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (value,
__
, index) => { return {}; }) }
return { a: _vFor(_ctx.items, (value,
k0
, index) => { return {}; }) }
}`
}`
)
)
})
})
...
@@ -92,7 +92,7 @@ describe(`compiler: v-for`, () => {
...
@@ -92,7 +92,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="(,,index) in items" />`
,
`<view v-for="(,,index) in items" />`
,
`<view wx:for="{{a}}" wx:for-item="v0"/>`
,
`<view wx:for="{{a}}" wx:for-item="v0"/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (
_, __
, index) => { return {}; }) }
return { a: _vFor(_ctx.items, (
v0, k0
, index) => { return {}; }) }
}`
}`
)
)
})
})
...
@@ -101,7 +101,7 @@ describe(`compiler: v-for`, () => {
...
@@ -101,7 +101,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="item in items" />`
,
`<view v-for="item in items" />`
,
`<view wx:for="{{a}}" wx:for-item="item"/>`
,
`<view wx:for="{{a}}" wx:for-item="item"/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items,
item
=> { return {}; }) }
return { a: _vFor(_ctx.items,
(item, k0, i0)
=> { return {}; }) }
}`
}`
)
)
})
})
...
@@ -110,7 +110,7 @@ describe(`compiler: v-for`, () => {
...
@@ -110,7 +110,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="item, key in items" />`
,
`<view v-for="item, key in items" />`
,
`<view wx:for="{{a}}" wx:for-item="item"/>`
,
`<view wx:for="{{a}}" wx:for-item="item"/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (item, key) => { return {}; }) }
return { a: _vFor(_ctx.items, (item, key
, i0
) => { return {}; }) }
}`
}`
)
)
})
})
...
@@ -128,7 +128,7 @@ describe(`compiler: v-for`, () => {
...
@@ -128,7 +128,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="value, , index in items" />`
,
`<view v-for="value, , index in items" />`
,
`<view wx:for="{{a}}" wx:for-item="value"/>`
,
`<view wx:for="{{a}}" wx:for-item="value"/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (value,
__
, index) => { return {}; }) }
return { a: _vFor(_ctx.items, (value,
k0
, index) => { return {}; }) }
}`
}`
)
)
})
})
...
@@ -137,7 +137,7 @@ describe(`compiler: v-for`, () => {
...
@@ -137,7 +137,7 @@ describe(`compiler: v-for`, () => {
`<view v-for=", , index in items" />`
,
`<view v-for=", , index in items" />`
,
`<view wx:for="{{a}}" wx:for-item="v0"/>`
,
`<view wx:for="{{a}}" wx:for-item="v0"/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items, (
_, __
, index) => { return {}; }) }
return { a: _vFor(_ctx.items, (
v0, k0
, index) => { return {}; }) }
}`
}`
)
)
})
})
...
@@ -146,7 +146,7 @@ describe(`compiler: v-for`, () => {
...
@@ -146,7 +146,7 @@ describe(`compiler: v-for`, () => {
`<template v-for="item in items">hello<view/></template>`
,
`<template v-for="item in items">hello<view/></template>`
,
`<block wx:for="{{a}}" wx:for-item="item">hello<view/></block>`
,
`<block wx:for="{{a}}" wx:for-item="item">hello<view/></block>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items,
item
=> { return {}; }) }
return { a: _vFor(_ctx.items,
(item, k0, i0)
=> { return {}; }) }
}`
}`
)
)
})
})
...
@@ -155,7 +155,7 @@ describe(`compiler: v-for`, () => {
...
@@ -155,7 +155,7 @@ describe(`compiler: v-for`, () => {
`<template v-for="item in items"><slot/></template>`
,
`<template v-for="item in items"><slot/></template>`
,
`<block wx:for="{{a}}" wx:for-item="item"><slot/></block>`
,
`<block wx:for="{{a}}" wx:for-item="item"><slot/></block>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items,
item
=> { return {}; }) }
return { a: _vFor(_ctx.items,
(item, k0, i0)
=> { return {}; }) }
}`
}`
)
)
})
})
...
@@ -165,7 +165,7 @@ describe(`compiler: v-for`, () => {
...
@@ -165,7 +165,7 @@ describe(`compiler: v-for`, () => {
`<template v-for="item in items" :key="item.id"><view :id="item.id" /></template>`
,
`<template v-for="item in items" :key="item.id"><view :id="item.id" /></template>`
,
`<block wx:for="{{a}}" wx:for-item="item" wx:key="b"><view id="{{item.a}}"/></block>`
,
`<block wx:for="{{a}}" wx:for-item="item" wx:key="b"><view id="{{item.a}}"/></block>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items,
item
=> { return { a: item.id, b: item.id }; }) }
return { a: _vFor(_ctx.items,
(item, k0, i0)
=> { return { a: item.id, b: item.id }; }) }
}`
}`
)
)
})
})
...
@@ -174,7 +174,7 @@ describe(`compiler: v-for`, () => {
...
@@ -174,7 +174,7 @@ describe(`compiler: v-for`, () => {
`<slot v-for="item in items"></slot>`
,
`<slot v-for="item in items"></slot>`
,
`<slot wx:for="{{a}}" wx:for-item="item"></slot>`
,
`<slot wx:for="{{a}}" wx:for-item="item"></slot>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items,
item
=> { return {}; }) }
return { a: _vFor(_ctx.items,
(item, k0, i0)
=> { return {}; }) }
}`
}`
)
)
})
})
...
@@ -183,7 +183,7 @@ describe(`compiler: v-for`, () => {
...
@@ -183,7 +183,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="(item) in items" :key="item" />`
,
`<view v-for="(item) in items" :key="item" />`
,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="*this"/>`
,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="*this"/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items,
item
=> { return {}; }) }
return { a: _vFor(_ctx.items,
(item, k0, i0)
=> { return {}; }) }
}`
}`
)
)
})
})
...
@@ -192,7 +192,7 @@ describe(`compiler: v-for`, () => {
...
@@ -192,7 +192,7 @@ describe(`compiler: v-for`, () => {
`<template v-for="item in items" :key="item">hello<view/></template>`
,
`<template v-for="item in items" :key="item">hello<view/></template>`
,
`<block wx:for="{{a}}" wx:for-item="item" wx:key="*this">hello<view/></block>`
,
`<block wx:for="{{a}}" wx:for-item="item" wx:key="*this">hello<view/></block>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items,
item
=> { return {}; }) }
return { a: _vFor(_ctx.items,
(item, k0, i0)
=> { return {}; }) }
}`
}`
)
)
})
})
...
@@ -201,7 +201,7 @@ describe(`compiler: v-for`, () => {
...
@@ -201,7 +201,7 @@ describe(`compiler: v-for`, () => {
`<view v-if="ok" v-for="i in list"/>`
,
`<view v-if="ok" v-for="i in list"/>`
,
`<view wx:if="{{a}}" wx:for="{{b}}" wx:for-item="i"/>`
,
`<view wx:if="{{a}}" wx:for="{{b}}" wx:for-item="i"/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _ctx.ok, ...(_ctx.ok ? { b: _vFor(_ctx.list,
i
=> { return {}; }) } : {}) }
return { a: _ctx.ok, ...(_ctx.ok ? { b: _vFor(_ctx.list,
(i, k0, i0)
=> { return {}; }) } : {}) }
}`
}`
)
)
})
})
...
@@ -211,7 +211,7 @@ describe(`compiler: v-for`, () => {
...
@@ -211,7 +211,7 @@ describe(`compiler: v-for`, () => {
`<template v-if="ok" v-for="i in list"/>`
,
`<template v-if="ok" v-for="i in list"/>`
,
`<block wx:if="{{a}}" wx:for="{{b}}" wx:for-item="i"/>`
,
`<block wx:if="{{a}}" wx:for="{{b}}" wx:for-item="i"/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _ctx.ok, ...(_ctx.ok ? { b: _vFor(_ctx.list,
i
=> { return {}; }) } : {}) }
return { a: _ctx.ok, ...(_ctx.ok ? { b: _vFor(_ctx.list,
(i, k0, i0)
=> { return {}; }) } : {}) }
}`
}`
)
)
})
})
...
@@ -615,7 +615,7 @@ describe(`compiler: v-for`, () => {
...
@@ -615,7 +615,7 @@ describe(`compiler: v-for`, () => {
`<view v-for="item in items" :key="itemKey(item)">test</view>`
,
`<view v-for="item in items" :key="itemKey(item)">test</view>`
,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="a">test</view>`
,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="a">test</view>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items,
item
=> { return { a: _ctx.itemKey(item) }; }) }
return { a: _vFor(_ctx.items,
(item, k0, i0)
=> { return { a: _ctx.itemKey(item) }; }) }
}`
}`
)
)
})
})
...
@@ -626,7 +626,7 @@ describe(`compiler: v-for`, () => {
...
@@ -626,7 +626,7 @@ describe(`compiler: v-for`, () => {
`<template v-for="item in items" :key="itemKey(item)">test</template>`
,
`<template v-for="item in items" :key="itemKey(item)">test</template>`
,
`<block wx:for="{{a}}" wx:for-item="item" wx:key="a">test</block>`
,
`<block wx:for="{{a}}" wx:for-item="item" wx:key="a">test</block>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items,
item
=> { return { a: _ctx.itemKey(item) }; }) }
return { a: _vFor(_ctx.items,
(item, k0, i0)
=> { return { a: _ctx.itemKey(item) }; }) }
}`
}`
)
)
})
})
...
@@ -636,7 +636,7 @@ describe(`compiler: v-for`, () => {
...
@@ -636,7 +636,7 @@ describe(`compiler: v-for`, () => {
`<template v-for="item in items" key="key">test</template>`
,
`<template v-for="item in items" key="key">test</template>`
,
`<block wx:for="{{a}}" wx:for-item="item" key="key">test</block>`
,
`<block wx:for="{{a}}" wx:for-item="item" key="key">test</block>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _vFor(_ctx.items,
item
=> { return {}; }) }
return { a: _vFor(_ctx.items,
(item, k0, i0)
=> { return {}; }) }
}`
}`
)
)
})
})
...
...
packages/uni-mp-compiler/__tests__/vModel.spec.ts
浏览文件 @
2f0369be
...
@@ -4,7 +4,7 @@ describe('compiler: transform v-model', () => {
...
@@ -4,7 +4,7 @@ describe('compiler: transform v-model', () => {
test
(
`component v-model`
,
()
=>
{
test
(
`component v-model`
,
()
=>
{
assert
(
assert
(
`<Comp v-model="model" />`
,
`<Comp v-model="model" />`
,
`<comp class="vue-ref" modelValue="{{a}}" bindupdateModelValue="{{b}}"/>`
,
`<comp class="vue-ref"
vue-id="2a9ec0b0-0"
modelValue="{{a}}" bindupdateModelValue="{{b}}"/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _ctx.model, b: _vOn($event => _ctx.model = $event) }
return { a: _ctx.model, b: _vOn($event => _ctx.model = $event) }
}`
}`
...
@@ -13,7 +13,7 @@ describe('compiler: transform v-model', () => {
...
@@ -13,7 +13,7 @@ describe('compiler: transform v-model', () => {
test
(
`component v-model with cache`
,
()
=>
{
test
(
`component v-model with cache`
,
()
=>
{
assert
(
assert
(
`<Comp v-model="model" />`
,
`<Comp v-model="model" />`
,
`<comp class="vue-ref" modelValue="{{a}}" bindupdateModelValue="{{b}}"/>`
,
`<comp class="vue-ref"
vue-id="2a9ec0b0-0"
modelValue="{{a}}" bindupdateModelValue="{{b}}"/>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _ctx.model, b: _vOn($event => _ctx.model = $event) }
return { a: _ctx.model, b: _vOn($event => _ctx.model = $event) }
}`
,
}`
,
...
...
packages/uni-mp-compiler/__tests__/vSlot.spec.ts
浏览文件 @
2f0369be
...
@@ -4,14 +4,14 @@ describe('compiler: transform v-slot', () => {
...
@@ -4,14 +4,14 @@ describe('compiler: transform v-slot', () => {
test
(
'
default slot
'
,
()
=>
{
test
(
'
default slot
'
,
()
=>
{
assert
(
assert
(
`<custom><template v-slot/></custom>`
,
`<custom><template v-slot/></custom>`
,
`<custom vue-slots="{{['default']}}" class="vue-ref"><view /></custom>`
,
`<custom vue-slots="{{['default']}}" class="vue-ref"
vue-id="2a9ec0b0-0"
><view /></custom>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return {}
return {}
}`
}`
)
)
assert
(
assert
(
`<custom>test</custom>`
,
`<custom>test</custom>`
,
`<custom vue-slots="{{['default']}}" class="vue-ref">test</custom>`
,
`<custom vue-slots="{{['default']}}" class="vue-ref"
vue-id="2a9ec0b0-0"
>test</custom>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return {}
return {}
}`
}`
...
@@ -20,7 +20,7 @@ describe('compiler: transform v-slot', () => {
...
@@ -20,7 +20,7 @@ describe('compiler: transform v-slot', () => {
test
(
'
named slots
'
,
()
=>
{
test
(
'
named slots
'
,
()
=>
{
assert
(
assert
(
`<custom><template v-slot:header/><template v-slot:default/><template v-slot:footer/></custom>`
,
`<custom><template v-slot:header/><template v-slot:default/><template v-slot:footer/></custom>`
,
`<custom vue-slots="{{['header','default','footer']}}" class="vue-ref"><view slot="header"/><view slot="default"/><view slot="footer"/></custom>`
,
`<custom vue-slots="{{['header','default','footer']}}" class="vue-ref"
vue-id="2a9ec0b0-0"
><view slot="header"/><view slot="default"/><view slot="footer"/></custom>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return {}
return {}
}`
}`
...
@@ -30,7 +30,7 @@ describe('compiler: transform v-slot', () => {
...
@@ -30,7 +30,7 @@ describe('compiler: transform v-slot', () => {
test
(
'
scoped slots
'
,
()
=>
{
test
(
'
scoped slots
'
,
()
=>
{
assert
(
assert
(
`<custom><template v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>`
,
`<custom><template v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>`
,
`<custom vue-slots="{{['default']}}" class="vue-ref"><view slot="default"><view>{{a}}</view></view></custom>`
,
`<custom vue-slots="{{['default']}}" class="vue-ref"
vue-id="2a9ec0b0-0"
><view slot="default"><view>{{a}}</view></view></custom>`
,
`(_ctx, _cache) => {
`(_ctx, _cache) => {
return { a: _toDisplayString(_ctx.slotProps.item), b: slotProps }
return { a: _toDisplayString(_ctx.slotProps.item), b: slotProps }
}`
}`
...
...
packages/uni-mp-compiler/src/compile.ts
浏览文件 @
2f0369be
...
@@ -13,6 +13,7 @@ import { generate as genTemplate } from './template/codegen'
...
@@ -13,6 +13,7 @@ import { generate as genTemplate } from './template/codegen'
import
{
transformOn
}
from
'
./transforms/vOn
'
import
{
transformOn
}
from
'
./transforms/vOn
'
import
{
transformElement
}
from
'
./transforms/transformElement
'
import
{
transformElement
}
from
'
./transforms/transformElement
'
import
{
transformBind
}
from
'
./transforms/vBind
'
import
{
transformBind
}
from
'
./transforms/vBind
'
import
{
transformComponent
}
from
'
./transforms/transformComponent
'
export
type
TransformPreset
=
[
export
type
TransformPreset
=
[
NodeTransform
[],
NodeTransform
[],
...
@@ -31,6 +32,7 @@ export function getBaseTransformPreset({
...
@@ -31,6 +32,7 @@ export function getBaseTransformPreset({
nodeTransforms
.
push
(
transformIdentifier
)
nodeTransforms
.
push
(
transformIdentifier
)
}
}
nodeTransforms
.
push
(
transformElement
)
nodeTransforms
.
push
(
transformElement
)
nodeTransforms
.
push
(
transformComponent
)
if
(
prefixIdentifiers
)
{
if
(
prefixIdentifiers
)
{
nodeTransforms
.
push
(
transformExpression
)
nodeTransforms
.
push
(
transformExpression
)
}
}
...
...
packages/uni-mp-compiler/src/transform.ts
浏览文件 @
2f0369be
...
@@ -90,6 +90,8 @@ export interface TransformContext
...
@@ -90,6 +90,8 @@ export interface TransformContext
}
}
scope
:
CodegenRootScope
scope
:
CodegenRootScope
currentScope
:
CodegenScope
currentScope
:
CodegenScope
currentVueId
:
string
vueIds
:
string
[]
inVOnce
:
boolean
inVOnce
:
boolean
helper
<
T
extends
symbol
>
(
name
:
T
):
T
helper
<
T
extends
symbol
>
(
name
:
T
):
T
removeHelper
<
T
extends
symbol
>
(
name
:
T
):
void
removeHelper
<
T
extends
symbol
>
(
name
:
T
):
void
...
@@ -264,6 +266,7 @@ export function createTransformContext(
...
@@ -264,6 +266,7 @@ export function createTransformContext(
)
)
}
}
const
vueIds
:
string
[]
=
[]
const
identifiers
=
Object
.
create
(
null
)
const
identifiers
=
Object
.
create
(
null
)
const
scopes
:
CodegenScope
[]
=
[
rootScope
]
const
scopes
:
CodegenScope
[]
=
[
rootScope
]
const
nameMatch
=
filename
.
replace
(
/
\?
.*$/
,
''
).
match
(
/
([^/\\]
+
)\.\w
+$/
)
const
nameMatch
=
filename
.
replace
(
/
\?
.*$/
,
''
).
match
(
/
([^/\\]
+
)\.\w
+$/
)
...
@@ -304,6 +307,10 @@ export function createTransformContext(
...
@@ -304,6 +307,10 @@ export function createTransformContext(
return
scopes
[
scopes
.
length
-
1
]
return
scopes
[
scopes
.
length
-
1
]
},
},
currentNode
:
root
,
currentNode
:
root
,
vueIds
,
get
currentVueId
()
{
return
vueIds
[
vueIds
.
length
-
1
]
},
inVOnce
:
false
,
inVOnce
:
false
,
// methods
// methods
popScope
()
{
popScope
()
{
...
...
packages/uni-mp-compiler/src/transforms/transformComponent.ts
0 → 100644
浏览文件 @
2f0369be
import
{
ComponentNode
,
ElementTypes
,
isCoreComponent
,
NodeTypes
,
}
from
'
@vue/compiler-core
'
import
{
isComponentTag
}
from
'
@dcloudio/uni-shared
'
import
{
isVForScope
,
NodeTransform
,
TransformContext
}
from
'
../transform
'
import
{
createAttributeNode
,
createBindDirectiveNode
}
from
'
../ast
'
import
{
addStaticClass
}
from
'
./transformElement
'
export
const
transformComponent
:
NodeTransform
=
(
node
,
context
)
=>
{
const
isComponent
=
node
.
type
===
NodeTypes
.
ELEMENT
&&
node
.
tagType
===
ElementTypes
.
COMPONENT
&&
!
isComponentTag
(
node
.
tag
)
&&
!
isCoreComponent
(
node
.
tag
)
&&
!
context
.
isBuiltInComponent
(
node
.
tag
)
if
(
!
isComponent
)
{
return
}
addVueRef
(
node
,
context
)
addVueId
(
node
,
context
)
return
function
postTransformComponent
()
{
context
.
vueIds
.
pop
()
}
}
function
addVueId
(
node
:
ComponentNode
,
context
:
TransformContext
)
{
let
{
vueId
,
scopes
,
currentScope
,
currentVueId
}
=
context
if
(
!
vueId
)
{
return
}
vueId
=
vueId
+
'
-
'
+
scopes
.
vueId
++
const
indexs
:
string
[]
=
[]
while
(
currentScope
)
{
if
(
isVForScope
(
currentScope
))
{
indexs
.
push
(
`+'-'+
${
currentScope
.
indexAlias
}
`
)
}
currentScope
=
currentScope
.
parent
!
}
const
inFor
=
!!
indexs
.
length
if
(
inFor
)
{
vueId
=
`'
${
vueId
}
'`
+
indexs
.
reverse
().
join
(
''
)
}
context
.
vueIds
.
push
(
vueId
)
let
value
=
vueId
if
(
currentVueId
)
{
const
isParentDynamic
=
currentVueId
.
includes
(
'
+
'
)
const
isCurrentDynamic
=
vueId
.
includes
(
'
+
'
)
if
(
isParentDynamic
||
isCurrentDynamic
)
{
value
=
`(
${
vueId
}
)+','+(
${
isParentDynamic
?
currentVueId
:
`'
${
currentVueId
}
'`
}
)`
}
else
{
value
=
vueId
+
'
,
'
+
currentVueId
}
}
if
(
value
.
includes
(
'
+
'
))
{
return
node
.
props
.
push
(
createBindDirectiveNode
(
'
vue-id
'
,
value
))
}
return
node
.
props
.
push
(
createAttributeNode
(
'
vue-id
'
,
value
))
}
function
addVueRef
(
node
:
ComponentNode
,
context
:
TransformContext
)
{
return
addStaticClass
(
node
,
context
.
scopes
.
vFor
?
'
vue-ref-in-for
'
:
'
vue-ref
'
)
}
packages/uni-mp-compiler/src/transforms/transformElement.ts
浏览文件 @
2f0369be
...
@@ -66,7 +66,7 @@ function createClassAttribute(clazz: string): AttributeNode {
...
@@ -66,7 +66,7 @@ function createClassAttribute(clazz: string): AttributeNode {
return
createAttributeNode
(
'
class
'
,
clazz
)
return
createAttributeNode
(
'
class
'
,
clazz
)
}
}
function
addStaticClass
(
node
:
ElementNode
,
clazz
:
string
)
{
export
function
addStaticClass
(
node
:
ElementNode
,
clazz
:
string
)
{
const
classProp
=
node
.
props
.
find
(
const
classProp
=
node
.
props
.
find
(
(
prop
)
=>
prop
.
type
===
NodeTypes
.
ATTRIBUTE
&&
prop
.
name
===
'
class
'
(
prop
)
=>
prop
.
type
===
NodeTypes
.
ATTRIBUTE
&&
prop
.
name
===
'
class
'
)
as
AttributeNode
|
undefined
)
as
AttributeNode
|
undefined
...
@@ -89,25 +89,10 @@ function addScopeId(node: ElementNode, scopeId: string) {
...
@@ -89,25 +89,10 @@ function addScopeId(node: ElementNode, scopeId: string) {
return
addStaticClass
(
node
,
scopeId
)
return
addStaticClass
(
node
,
scopeId
)
}
}
function
addVueId
(
node
:
ComponentNode
,
context
:
TransformContext
)
{
let
{
vueId
,
scopes
}
=
context
if
(
!
vueId
)
{
return
}
return
vueId
+
'
-
'
+
scopes
.
vueId
++
}
function
addVueRef
(
node
:
ComponentNode
,
context
:
TransformContext
)
{
return
addStaticClass
(
node
,
context
.
scopes
.
vFor
?
'
vue-ref-in-for
'
:
'
vue-ref
'
)
}
function
processComponent
(
node
:
ComponentNode
,
context
:
TransformContext
)
{
function
processComponent
(
node
:
ComponentNode
,
context
:
TransformContext
)
{
const
{
tag
}
=
node
const
{
tag
}
=
node
if
(
context
.
bindingComponents
[
tag
])
{
if
(
context
.
bindingComponents
[
tag
])
{
return
addVueRef
(
node
,
context
)
return
}
}
// 1. dynamic component
// 1. dynamic component
...
@@ -136,9 +121,6 @@ function processComponent(node: ComponentNode, context: TransformContext) {
...
@@ -136,9 +121,6 @@ function processComponent(node: ComponentNode, context: TransformContext) {
)
)
}
}
addVueId
(
node
,
context
)
addVueRef
(
node
,
context
)
// 3. user component (from setup bindings)
// 3. user component (from setup bindings)
const
fromSetup
=
resolveSetupReference
(
tag
,
context
)
const
fromSetup
=
resolveSetupReference
(
tag
,
context
)
if
(
fromSetup
)
{
if
(
fromSetup
)
{
...
...
packages/uni-mp-compiler/src/transforms/transformIdentifier.ts
浏览文件 @
2f0369be
import
{
import
{
createCompoundExpression
,
createCompoundExpression
,
DirectiveNode
,
NodeTypes
,
NodeTypes
,
TO_DISPLAY_STRING
,
TO_DISPLAY_STRING
,
}
from
'
@vue/compiler-core
'
}
from
'
@vue/compiler-core
'
...
@@ -49,7 +50,9 @@ export const transformIdentifier: NodeTransform = (node, context) => {
...
@@ -49,7 +50,9 @@ export const transformIdentifier: NodeTransform = (node, context) => {
}
}
const
exp
=
dir
.
exp
const
exp
=
dir
.
exp
if
(
exp
)
{
if
(
exp
)
{
if
(
isSelfKey
(
dir
,
vFor
))
{
if
(
isBuiltIn
(
dir
))
{
// noop
}
else
if
(
isSelfKey
(
dir
,
vFor
))
{
rewriteSelfKey
(
dir
)
rewriteSelfKey
(
dir
)
}
else
if
(
isClassBinding
(
dir
))
{
}
else
if
(
isClassBinding
(
dir
))
{
hasClassBinding
=
true
hasClassBinding
=
true
...
@@ -78,3 +81,13 @@ export const transformIdentifier: NodeTransform = (node, context) => {
...
@@ -78,3 +81,13 @@ export const transformIdentifier: NodeTransform = (node, context) => {
}
}
}
}
}
}
// const builtInProps = ['vue-id']
function
isBuiltIn
(
_dir
:
DirectiveNode
)
{
return
false
// return (
// arg?.type === NodeTypes.SIMPLE_EXPRESSION &&
// builtInProps.includes(arg.content)
// )
}
packages/uni-mp-compiler/src/transforms/vFor.ts
浏览文件 @
2f0369be
...
@@ -30,16 +30,16 @@ import { rewriteExpression } from './utils'
...
@@ -30,16 +30,16 @@ import { rewriteExpression } from './utils'
export
type
VForOptions
=
Omit
<
ForParseResult
,
'
tagType
'
>
&
{
export
type
VForOptions
=
Omit
<
ForParseResult
,
'
tagType
'
>
&
{
sourceExpr
?:
Expression
sourceExpr
?:
Expression
sourceAlias
?
:
string
sourceAlias
:
string
valueCode
?
:
string
valueCode
:
string
valueExpr
?
:
Identifier
|
Pattern
|
RestElement
valueExpr
:
Identifier
|
Pattern
|
RestElement
valueAlias
?
:
string
valueAlias
:
string
keyCode
?
:
string
keyCode
:
string
keyExpr
?
:
Identifier
|
Pattern
|
RestElement
keyExpr
:
Identifier
|
Pattern
|
RestElement
keyAlias
?
:
string
keyAlias
:
string
indexCode
?
:
string
indexCode
:
string
indexExpr
?
:
Identifier
|
Pattern
|
RestElement
indexExpr
:
Identifier
|
Pattern
|
RestElement
indexAlias
?
:
string
indexAlias
:
string
}
}
export
type
ForElementNode
=
ElementNode
&
{
export
type
ForElementNode
=
ElementNode
&
{
...
@@ -73,31 +73,26 @@ export const transformFor = createStructuralDirectiveTransform(
...
@@ -73,31 +73,26 @@ export const transformFor = createStructuralDirectiveTransform(
const
{
addIdentifiers
,
removeIdentifiers
}
=
context
const
{
addIdentifiers
,
removeIdentifiers
}
=
context
const
{
source
,
value
,
key
,
index
}
=
parseResult
const
{
source
,
value
,
key
,
index
}
=
parseResult
if
(
context
.
prefixIdentifiers
)
{
if
(
context
.
prefixIdentifiers
)
{
value
&&
addIdentifiers
(
value
)
addIdentifiers
(
value
)
key
&&
addIdentifiers
(
key
)
addIdentifiers
(
key
)
index
&&
addIdentifiers
(
index
)
addIdentifiers
(
index
)
}
}
const
{
currentScope
:
parentScope
,
scopes
,
popScope
}
=
context
const
{
currentScope
:
parentScope
,
scopes
,
popScope
}
=
context
const
sourceExpr
=
parseExpr
(
source
,
context
)
const
sourceExpr
=
parseExpr
(
source
,
context
)
const
valueCode
=
value
&&
genExpr
(
value
)
const
valueCode
=
genExpr
(
value
)
const
valueExpr
=
valueCode
?
parseParam
(
valueCode
,
context
,
value
)
const
valueExpr
=
parseParam
(
valueCode
,
context
,
value
)
:
undefined
const
valueAlias
=
parseAlias
(
valueExpr
,
valueCode
,
'
v
'
+
scopes
.
vFor
)
const
valueAlias
=
const
keyCode
=
genExpr
(
key
)
(
valueExpr
&&
parseAlias
(
valueExpr
,
valueCode
!
,
'
v
'
+
scopes
.
vFor
))
||
const
keyExpr
=
parseParam
(
keyCode
,
context
,
key
)
'
v
'
+
scopes
.
vFor
const
keyAlias
=
parseAlias
(
keyExpr
,
keyCode
,
'
k
'
+
scopes
.
vFor
)
const
keyCode
=
key
&&
genExpr
(
key
)
const
indexCode
=
genExpr
(
index
)
const
keyExpr
=
keyCode
?
parseParam
(
keyCode
,
context
,
key
)
:
undefined
const
indexExpr
=
parseParam
(
indexCode
,
context
,
index
)
const
keyAlias
=
keyExpr
&&
parseAlias
(
keyExpr
,
keyCode
!
,
'
k
'
+
scopes
.
vFor
)
const
indexAlias
=
parseAlias
(
indexExpr
,
indexCode
,
'
i
'
+
scopes
.
vFor
)
const
indexCode
=
index
&&
genExpr
(
index
)
const
indexExpr
=
indexCode
?
parseParam
(
indexCode
,
context
,
index
)
:
undefined
const
indexAlias
=
indexExpr
&&
parseAlias
(
indexExpr
,
indexCode
!
,
'
i
'
+
scopes
.
vFor
)
const
vForData
:
VForOptions
=
{
const
vForData
:
VForOptions
=
{
source
,
source
,
sourceExpr
,
sourceExpr
,
sourceAlias
:
''
,
value
,
value
,
valueCode
,
valueCode
,
valueExpr
,
valueExpr
,
...
@@ -172,12 +167,12 @@ function clearExpr(expr: Expression) {
...
@@ -172,12 +167,12 @@ function clearExpr(expr: Expression) {
function
parseAlias
(
function
parseAlias
(
babelExpr
:
Identifier
|
Pattern
|
RestElement
,
babelExpr
:
Identifier
|
Pattern
|
RestElement
,
exprCode
:
string
,
exprCode
:
string
,
defaultAlias
:
string
fallback
:
string
)
{
)
{
if
(
isIdentifier
(
babelExpr
))
{
if
(
isIdentifier
(
babelExpr
))
{
return
exprCode
return
exprCode
}
}
return
defaultAlias
return
fallback
}
}
function
findVForLocals
({
value
,
key
,
index
}:
ForParseResult
)
{
function
findVForLocals
({
value
,
key
,
index
}:
ForParseResult
)
{
...
@@ -209,9 +204,9 @@ const stripParensRE = /^\(|\)$/g
...
@@ -209,9 +204,9 @@ const stripParensRE = /^\(|\)$/g
export
interface
ForParseResult
{
export
interface
ForParseResult
{
source
:
ExpressionNode
source
:
ExpressionNode
value
:
ExpressionNode
|
undefined
value
:
ExpressionNode
key
:
ExpressionNode
|
undefined
key
:
ExpressionNode
index
:
ExpressionNode
|
undefined
index
:
ExpressionNode
tagType
:
ElementTypes
tagType
:
ElementTypes
}
}
...
@@ -232,9 +227,9 @@ export function parseForExpression(
...
@@ -232,9 +227,9 @@ export function parseForExpression(
RHS
.
trim
(),
RHS
.
trim
(),
exp
.
indexOf
(
RHS
,
LHS
.
length
)
exp
.
indexOf
(
RHS
,
LHS
.
length
)
),
),
value
:
undefined
,
value
:
createSimpleExpression
(
'
v
'
+
context
.
scopes
.
vFor
)
,
key
:
undefined
,
key
:
createSimpleExpression
(
'
k
'
+
context
.
scopes
.
vFor
)
,
index
:
undefined
,
index
:
createSimpleExpression
(
'
i
'
+
context
.
scopes
.
vFor
)
,
tagType
:
ElementTypes
.
ELEMENT
,
tagType
:
ElementTypes
.
ELEMENT
,
}
}
if
(
context
.
prefixIdentifiers
)
{
if
(
context
.
prefixIdentifiers
)
{
...
...
packages/uni-mp-vue/dist/vue.runtime.esm.js
浏览文件 @
2f0369be
...
@@ -4960,7 +4960,7 @@ function vFor(source, renderItem) {
...
@@ -4960,7 +4960,7 @@ function vFor(source, renderItem) {
if
(
isArray
(
source
)
||
isString
(
source
))
{
if
(
isArray
(
source
)
||
isString
(
source
))
{
ret
=
new
Array
(
source
.
length
);
ret
=
new
Array
(
source
.
length
);
for
(
let
i
=
0
,
l
=
source
.
length
;
i
<
l
;
i
++
)
{
for
(
let
i
=
0
,
l
=
source
.
length
;
i
<
l
;
i
++
)
{
ret
[
i
]
=
renderItem
(
source
[
i
],
i
,
undefined
);
ret
[
i
]
=
renderItem
(
source
[
i
],
i
,
i
);
}
}
}
}
else
if
(
typeof
source
===
'
number
'
)
{
else
if
(
typeof
source
===
'
number
'
)
{
...
@@ -4970,12 +4970,12 @@ function vFor(source, renderItem) {
...
@@ -4970,12 +4970,12 @@ function vFor(source, renderItem) {
}
}
ret
=
new
Array
(
source
);
ret
=
new
Array
(
source
);
for
(
let
i
=
0
;
i
<
source
;
i
++
)
{
for
(
let
i
=
0
;
i
<
source
;
i
++
)
{
ret
[
i
]
=
renderItem
(
i
+
1
,
i
,
undefined
);
ret
[
i
]
=
renderItem
(
i
+
1
,
i
,
i
);
}
}
}
}
else
if
(
isObject
(
source
))
{
else
if
(
isObject
(
source
))
{
if
(
source
[
Symbol
.
iterator
])
{
if
(
source
[
Symbol
.
iterator
])
{
ret
=
Array
.
from
(
source
,
(
item
,
i
)
=>
renderItem
(
item
,
i
,
undefined
));
ret
=
Array
.
from
(
source
,
(
item
,
i
)
=>
renderItem
(
item
,
i
,
i
));
}
}
else
{
else
{
const
keys
=
Object
.
keys
(
source
);
const
keys
=
Object
.
keys
(
source
);
...
@@ -5014,6 +5014,7 @@ function vOn(value) {
...
@@ -5014,6 +5014,7 @@ function vOn(value) {
}
}
function
createInvoker
(
initialValue
,
instance
)
{
function
createInvoker
(
initialValue
,
instance
)
{
const
invoker
=
(
e
)
=>
{
const
invoker
=
(
e
)
=>
{
patchMPEvent
(
e
);
let
args
=
[
e
];
let
args
=
[
e
];
if
(
e
.
detail
&&
e
.
detail
.
__args__
)
{
if
(
e
.
detail
&&
e
.
detail
.
__args__
)
{
args
=
e
.
detail
.
__args__
;
args
=
e
.
detail
.
__args__
;
...
@@ -5023,6 +5024,12 @@ function createInvoker(initialValue, instance) {
...
@@ -5023,6 +5024,12 @@ function createInvoker(initialValue, instance) {
invoker
.
value
=
initialValue
;
invoker
.
value
=
initialValue
;
return
invoker
;
return
invoker
;
}
}
function
patchMPEvent
(
e
)
{
if
(
e
.
type
&&
e
.
target
)
{
e
.
stopPropagation
=
()
=>
{
};
e
.
preventDefault
=
()
=>
{
};
}
}
function
patchStopImmediatePropagation
(
e
,
value
)
{
function
patchStopImmediatePropagation
(
e
,
value
)
{
if
(
isArray
(
value
))
{
if
(
isArray
(
value
))
{
const
originalStop
=
e
.
stopImmediatePropagation
;
const
originalStop
=
e
.
stopImmediatePropagation
;
...
...
packages/uni-mp-vue/src/helpers/vFor.ts
浏览文件 @
2f0369be
...
@@ -59,7 +59,7 @@ export function vFor(
...
@@ -59,7 +59,7 @@ export function vFor(
if
(
isArray
(
source
)
||
isString
(
source
))
{
if
(
isArray
(
source
)
||
isString
(
source
))
{
ret
=
new
Array
(
source
.
length
)
ret
=
new
Array
(
source
.
length
)
for
(
let
i
=
0
,
l
=
source
.
length
;
i
<
l
;
i
++
)
{
for
(
let
i
=
0
,
l
=
source
.
length
;
i
<
l
;
i
++
)
{
ret
[
i
]
=
renderItem
(
source
[
i
],
i
,
undefined
)
ret
[
i
]
=
renderItem
(
source
[
i
],
i
,
i
)
}
}
}
else
if
(
typeof
source
===
'
number
'
)
{
}
else
if
(
typeof
source
===
'
number
'
)
{
if
(
__DEV__
&&
!
Number
.
isInteger
(
source
))
{
if
(
__DEV__
&&
!
Number
.
isInteger
(
source
))
{
...
@@ -68,12 +68,12 @@ export function vFor(
...
@@ -68,12 +68,12 @@ export function vFor(
}
}
ret
=
new
Array
(
source
)
ret
=
new
Array
(
source
)
for
(
let
i
=
0
;
i
<
source
;
i
++
)
{
for
(
let
i
=
0
;
i
<
source
;
i
++
)
{
ret
[
i
]
=
renderItem
(
i
+
1
,
i
,
undefined
)
ret
[
i
]
=
renderItem
(
i
+
1
,
i
,
i
)
}
}
}
else
if
(
isObject
(
source
))
{
}
else
if
(
isObject
(
source
))
{
if
(
source
[
Symbol
.
iterator
as
any
])
{
if
(
source
[
Symbol
.
iterator
as
any
])
{
ret
=
Array
.
from
(
source
as
Iterable
<
any
>
,
(
item
,
i
)
=>
ret
=
Array
.
from
(
source
as
Iterable
<
any
>
,
(
item
,
i
)
=>
renderItem
(
item
,
i
,
undefined
)
renderItem
(
item
,
i
,
i
)
)
)
}
else
{
}
else
{
const
keys
=
Object
.
keys
(
source
)
const
keys
=
Object
.
keys
(
source
)
...
...
packages/uni-mp-vue/src/helpers/vOn.ts
浏览文件 @
2f0369be
...
@@ -49,6 +49,7 @@ function createInvoker(
...
@@ -49,6 +49,7 @@ function createInvoker(
instance
:
ComponentInternalInstance
|
null
instance
:
ComponentInternalInstance
|
null
)
{
)
{
const
invoker
:
Invoker
=
(
e
:
Event
)
=>
{
const
invoker
:
Invoker
=
(
e
:
Event
)
=>
{
patchMPEvent
(
e
)
let
args
:
unknown
[]
=
[
e
]
let
args
:
unknown
[]
=
[
e
]
if
((
e
as
MPEvent
).
detail
&&
(
e
as
MPEvent
).
detail
.
__args__
)
{
if
((
e
as
MPEvent
).
detail
&&
(
e
as
MPEvent
).
detail
.
__args__
)
{
args
=
(
e
as
MPEvent
).
detail
.
__args__
!
args
=
(
e
as
MPEvent
).
detail
.
__args__
!
...
@@ -64,6 +65,13 @@ function createInvoker(
...
@@ -64,6 +65,13 @@ function createInvoker(
return
invoker
return
invoker
}
}
function
patchMPEvent
(
e
:
Event
)
{
if
(
e
.
type
&&
e
.
target
)
{
e
.
stopPropagation
=
()
=>
{}
e
.
preventDefault
=
()
=>
{}
}
}
function
patchStopImmediatePropagation
(
function
patchStopImmediatePropagation
(
e
:
Event
,
e
:
Event
,
value
:
EventValue
value
:
EventValue
...
...
packages/uni-mp-weixin/dist/uni.compiler.js
浏览文件 @
2f0369be
...
@@ -61,7 +61,7 @@ const uniMiniProgramWeixinPlugin = {
...
@@ -61,7 +61,7 @@ const uniMiniProgramWeixinPlugin = {
config
()
{
config
()
{
return
{
return
{
define
:
{
define
:
{
__VUE_CREATED_DEFERRED__
:
JSON
.
stringify
(
'
false
'
)
,
__VUE_CREATED_DEFERRED__
:
false
,
},
},
};
};
},
},
...
...
packages/uni-mp-weixin/src/plugin/index.ts
浏览文件 @
2f0369be
...
@@ -11,7 +11,7 @@ const uniMiniProgramWeixinPlugin: Plugin = {
...
@@ -11,7 +11,7 @@ const uniMiniProgramWeixinPlugin: Plugin = {
config
()
{
config
()
{
return
{
return
{
define
:
{
define
:
{
__VUE_CREATED_DEFERRED__
:
JSON
.
stringify
(
'
false
'
)
,
__VUE_CREATED_DEFERRED__
:
false
,
},
},
}
}
},
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录