diff --git a/packages/uni-app-plus/dist/uni-app-service.es.js b/packages/uni-app-plus/dist/uni-app-service.es.js
index f493a59e1a535b35bce5f6d32d08e6375b2d12b9..8ba4b7ed2e2d82f963bf08a4559c5f75fc72f04e 100644
--- a/packages/uni-app-plus/dist/uni-app-service.es.js
+++ b/packages/uni-app-plus/dist/uni-app-service.es.js
@@ -946,7 +946,7 @@ var serviceContext = (function (vue) {
res.errMsg = normalizeErrMsg$1(res.errMsg, name);
isFunction(beforeAll) && beforeAll(res);
if (res.errMsg === name + ':ok') {
- isFunction(beforeSuccess) && beforeSuccess(res);
+ isFunction(beforeSuccess) && beforeSuccess(res, args);
hasSuccess && success(res);
}
else {
@@ -1767,6 +1767,25 @@ var serviceContext = (function (vue) {
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 name = 'uni.scanCode.';
const keys = ['title', 'album', 'fail', 'flash.on', 'flash.off'];
@@ -4477,7 +4496,37 @@ var serviceContext = (function (vue) {
const API_ADD_PHONE_CONTACT = 'addPhoneContact';
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_OFF_ACCELEROMETER = 'offAccelerometer';
@@ -6802,7 +6851,7 @@ var serviceContext = (function (vue) {
const clipboard = requireNativePlugin('clipboard');
clipboard.setString(options.data);
resolve();
- });
+ }, SetClipboardDataProtocol, SetClipboardDataOptions);
const API_ON_NETWORK_STATUS_CHANGE = 'onNetworkStatusChange';
function networkListener() {
diff --git a/packages/uni-h5/dist/uni-h5.cjs.js b/packages/uni-h5/dist/uni-h5.cjs.js
index eeeb58d7e95a2fcde10919510ca55e54fac5ac77..2a2c5d003e71b516d6aafbe8b91916e69b0aa79c 100644
--- a/packages/uni-h5/dist/uni-h5.cjs.js
+++ b/packages/uni-h5/dist/uni-h5.cjs.js
@@ -1128,7 +1128,7 @@ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } =
res.errMsg = normalizeErrMsg$1(res.errMsg, name);
shared.isFunction(beforeAll) && beforeAll(res);
if (res.errMsg === name + ":ok") {
- shared.isFunction(beforeSuccess) && beforeSuccess(res);
+ shared.isFunction(beforeSuccess) && beforeSuccess(res, args);
hasSuccess && success(res);
} else {
hasFail && fail(res);
diff --git a/packages/uni-h5/dist/uni-h5.es.js b/packages/uni-h5/dist/uni-h5.es.js
index 5c71848122c6b593085acbe297c81801759c07ef..16b08e31979c0e5a9dbacff9c1a37c47b4e417c8 100644
--- a/packages/uni-h5/dist/uni-h5.es.js
+++ b/packages/uni-h5/dist/uni-h5.es.js
@@ -2407,7 +2407,7 @@ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } =
res.errMsg = normalizeErrMsg$1(res.errMsg, name);
isFunction(beforeAll) && beforeAll(res);
if (res.errMsg === name + ":ok") {
- isFunction(beforeSuccess) && beforeSuccess(res);
+ isFunction(beforeSuccess) && beforeSuccess(res, args);
hasSuccess && success(res);
} else {
hasFail && fail(res);
diff --git a/packages/uni-mp-compiler/__tests__/codegen.spec.ts b/packages/uni-mp-compiler/__tests__/codegen.spec.ts
index 3f681d15487527a2fd611b6123fcf0d376550441..b8c221595538ae6aceea6dcce55b9b240d8a3b5e 100644
--- a/packages/uni-mp-compiler/__tests__/codegen.spec.ts
+++ b/packages/uni-mp-compiler/__tests__/codegen.spec.ts
@@ -8,7 +8,7 @@ describe('compiler: codegen', () => {
`import { vOn as _vOn, vFor as _vFor } from "vue"
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 }
)
@@ -21,7 +21,7 @@ export function render(_ctx, _cache) {
`import { vOn as _vOn, vFor as _vFor } from "vue"
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' }
)
@@ -37,7 +37,7 @@ return function render(_ctx, _cache) {
with (_ctx) {
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 }
@@ -50,7 +50,7 @@ return function render(_ctx, _cache) {
`const { vOn: _vOn, vFor: _vFor } = Vue
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' }
)
diff --git a/packages/uni-mp-compiler/__tests__/component.spec.ts b/packages/uni-mp-compiler/__tests__/component.spec.ts
index 54190261d63e017d60ec49d238b1e9f531b8a698..8884f419f1aa27cea79178258e23ea86c702a116 100644
--- a/packages/uni-mp-compiler/__tests__/component.spec.ts
+++ b/packages/uni-mp-compiler/__tests__/component.spec.ts
@@ -2,12 +2,94 @@ import { addComponentBindLink } from '@dcloudio/uni-cli-shared'
import { assert } from './testUtils'
describe('compiler: transform component', () => {
- test('basic', () => {
+ // test('basic', () => {
+ // assert(
+ // ``,
+ // ``,
+ // `(_ctx, _cache) => {
+ // return {}
+ // }`,
+ // {
+ // nodeTransforms: [addComponentBindLink as any],
+ // }
+ // )
+ // })
+ test('component + component', () => {
assert(
- ``,
- ``,
+ ``,
+ ``,
`(_ctx, _cache) => {
return {}
+}`,
+ {
+ nodeTransforms: [addComponentBindLink as any],
+ }
+ )
+ })
+ test('component + component + component', () => {
+ assert(
+ ``,
+ ``,
+ `(_ctx, _cache) => {
+ return {}
+}`,
+ {
+ nodeTransforms: [addComponentBindLink as any],
+ }
+ )
+ })
+ test('component with v-for', () => {
+ assert(
+ ``,
+ ``,
+ `(_ctx, _cache) => {
+ return { a: _vFor(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }) }
+}`,
+ {
+ nodeTransforms: [addComponentBindLink as any],
+ }
+ )
+ assert(
+ ``,
+ ``,
+ `(_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(
+ ``,
+ ``,
+ `(_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(
+ ``,
+ ``,
+ `(_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(
+ ``,
+ ``,
+ `(_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],
diff --git a/packages/uni-mp-compiler/__tests__/ref.spec.ts b/packages/uni-mp-compiler/__tests__/ref.spec.ts
index 55d1432d9f0556aa7a89d9ab134099d590bab868..2022c5be2ebcb87c50de525b5ca9410af4250c13 100644
--- a/packages/uni-mp-compiler/__tests__/ref.spec.ts
+++ b/packages/uni-mp-compiler/__tests__/ref.spec.ts
@@ -4,14 +4,14 @@ describe('compiler: transform ref', () => {
test('vue-ref', () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return {}
}`
)
assert(
- ``,
- ``,
+ ``,
+ ``,
`(_ctx, _cache) => {
return {}
}`
@@ -20,16 +20,16 @@ describe('compiler: transform ref', () => {
test('vue-ref-in-for', () => {
assert(
``,
- ``,
+ ``,
`(_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', () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return {}
}`
@@ -38,7 +38,7 @@ describe('compiler: transform ref', () => {
test('dynamic ref', () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return { a: _ctx.custom }
}`
diff --git a/packages/uni-mp-compiler/__tests__/scope.spec.ts b/packages/uni-mp-compiler/__tests__/scope.spec.ts
index fb225d0a4f9aaa2ebcbb2ffcea684d731c70d457..5232b715d0b1a090766850722eb9827e83b8591c 100644
--- a/packages/uni-mp-compiler/__tests__/scope.spec.ts
+++ b/packages/uni-mp-compiler/__tests__/scope.spec.ts
@@ -6,7 +6,7 @@ describe('compiler: scope', () => {
`{{item.title}}`,
`{{item.a}}`,
`(_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', () => {
`{{item.title}}{{handle(foo)}}{{item.id}}{{item1.title}}`,
`{{item.a}}{{b}}{{item.c}}{{item1.a}}`,
`(_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(
``,
``,
`(_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(
``,
``,
`(_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', () => {
``,
``,
`(_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', () => {
``,
``,
`(_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 }
}`
)
})
diff --git a/packages/uni-mp-compiler/__tests__/vFor.spec.ts b/packages/uni-mp-compiler/__tests__/vFor.spec.ts
index 57fa2747d9854538020b4dc218cce986d2362f37..9e226c073503608fd1b723f353cedcc1e21d4f56 100644
--- a/packages/uni-mp-compiler/__tests__/vFor.spec.ts
+++ b/packages/uni-mp-compiler/__tests__/vFor.spec.ts
@@ -29,7 +29,7 @@ describe(`compiler: v-for`, () => {
``,
``,
`(_ctx, _cache) => {
- return { a: _vFor(5, index => { return {}; }) }
+ return { a: _vFor(5, (index, k0, i0) => { return {}; }) }
}`
)
})
@@ -38,7 +38,7 @@ describe(`compiler: v-for`, () => {
``,
``,
`(_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`, () => {
``,
``,
`(_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`, () => {
``,
``,
`(_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`, () => {
``,
``,
`(_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`, () => {
``,
``,
`(_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`, () => {
``,
``,
`(_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`, () => {
``,
``,
`(_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`, () => {
``,
``,
`(_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`, () => {
``,
``,
`(_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`, () => {
``,
``,
`(_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`, () => {
`hello`,
`hello`,
`(_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`, () => {
``,
``,
`(_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`, () => {
``,
``,
`(_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`, () => {
``,
``,
`(_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`, () => {
``,
``,
`(_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`, () => {
`hello`,
`hello`,
`(_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`, () => {
``,
``,
`(_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`, () => {
``,
``,
`(_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`, () => {
`test`,
`test`,
`(_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`, () => {
`test`,
`test`,
`(_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`, () => {
`test`,
`test`,
`(_ctx, _cache) => {
- return { a: _vFor(_ctx.items, item => { return {}; }) }
+ return { a: _vFor(_ctx.items, (item, k0, i0) => { return {}; }) }
}`
)
})
diff --git a/packages/uni-mp-compiler/__tests__/vModel.spec.ts b/packages/uni-mp-compiler/__tests__/vModel.spec.ts
index 8f16af191c508b4d2993aa3e354310f1f13bdef5..af14891ebb42c464c03d6746f33112176744af66 100644
--- a/packages/uni-mp-compiler/__tests__/vModel.spec.ts
+++ b/packages/uni-mp-compiler/__tests__/vModel.spec.ts
@@ -4,7 +4,7 @@ describe('compiler: transform v-model', () => {
test(`component v-model`, () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return { a: _ctx.model, b: _vOn($event => _ctx.model = $event) }
}`
@@ -13,7 +13,7 @@ describe('compiler: transform v-model', () => {
test(`component v-model with cache`, () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return { a: _ctx.model, b: _vOn($event => _ctx.model = $event) }
}`,
diff --git a/packages/uni-mp-compiler/__tests__/vSlot.spec.ts b/packages/uni-mp-compiler/__tests__/vSlot.spec.ts
index 0075be5f0d90f0a6d47d247819a56edc4529ac17..a323faa8b59b7f8dd46dca754dcd28039cdb80fa 100644
--- a/packages/uni-mp-compiler/__tests__/vSlot.spec.ts
+++ b/packages/uni-mp-compiler/__tests__/vSlot.spec.ts
@@ -4,14 +4,14 @@ describe('compiler: transform v-slot', () => {
test('default slot', () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`test`,
- `test`,
+ `test`,
`(_ctx, _cache) => {
return {}
}`
@@ -20,7 +20,7 @@ describe('compiler: transform v-slot', () => {
test('named slots', () => {
assert(
``,
- ``,
+ ``,
`(_ctx, _cache) => {
return {}
}`
@@ -30,7 +30,7 @@ describe('compiler: transform v-slot', () => {
test('scoped slots', () => {
assert(
`{{ slotProps.item }}`,
- `{{a}}`,
+ `{{a}}`,
`(_ctx, _cache) => {
return { a: _toDisplayString(_ctx.slotProps.item), b: slotProps }
}`
diff --git a/packages/uni-mp-compiler/src/compile.ts b/packages/uni-mp-compiler/src/compile.ts
index 46a68b7f83b5bd4ce67cba55f71269f48fec245b..9f8d3142be8c31a442e65d4017f7d29f47e02805 100644
--- a/packages/uni-mp-compiler/src/compile.ts
+++ b/packages/uni-mp-compiler/src/compile.ts
@@ -13,6 +13,7 @@ import { generate as genTemplate } from './template/codegen'
import { transformOn } from './transforms/vOn'
import { transformElement } from './transforms/transformElement'
import { transformBind } from './transforms/vBind'
+import { transformComponent } from './transforms/transformComponent'
export type TransformPreset = [
NodeTransform[],
@@ -31,6 +32,7 @@ export function getBaseTransformPreset({
nodeTransforms.push(transformIdentifier)
}
nodeTransforms.push(transformElement)
+ nodeTransforms.push(transformComponent)
if (prefixIdentifiers) {
nodeTransforms.push(transformExpression)
}
diff --git a/packages/uni-mp-compiler/src/transform.ts b/packages/uni-mp-compiler/src/transform.ts
index c8e8a7dc4cb9ef7d55215d010709c43c03ca7f50..126074e79bb1230424c65bf235f5f494dc8f631b 100644
--- a/packages/uni-mp-compiler/src/transform.ts
+++ b/packages/uni-mp-compiler/src/transform.ts
@@ -90,6 +90,8 @@ export interface TransformContext
}
scope: CodegenRootScope
currentScope: CodegenScope
+ currentVueId: string
+ vueIds: string[]
inVOnce: boolean
helper(name: T): T
removeHelper(name: T): void
@@ -264,6 +266,7 @@ export function createTransformContext(
)
}
+ const vueIds: string[] = []
const identifiers = Object.create(null)
const scopes: CodegenScope[] = [rootScope]
const nameMatch = filename.replace(/\?.*$/, '').match(/([^/\\]+)\.\w+$/)
@@ -304,6 +307,10 @@ export function createTransformContext(
return scopes[scopes.length - 1]
},
currentNode: root,
+ vueIds,
+ get currentVueId() {
+ return vueIds[vueIds.length - 1]
+ },
inVOnce: false,
// methods
popScope() {
diff --git a/packages/uni-mp-compiler/src/transforms/transformComponent.ts b/packages/uni-mp-compiler/src/transforms/transformComponent.ts
new file mode 100644
index 0000000000000000000000000000000000000000..f76a5c1a33ba3d60e189e5ed04366ed67f43895b
--- /dev/null
+++ b/packages/uni-mp-compiler/src/transforms/transformComponent.ts
@@ -0,0 +1,73 @@
+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'
+ )
+}
diff --git a/packages/uni-mp-compiler/src/transforms/transformElement.ts b/packages/uni-mp-compiler/src/transforms/transformElement.ts
index 00240e3b1699352e960e917a2d9b0c0bcb1ad3bd..a5e93d9ef926425b92fcde61e2aa87652a650cc2 100644
--- a/packages/uni-mp-compiler/src/transforms/transformElement.ts
+++ b/packages/uni-mp-compiler/src/transforms/transformElement.ts
@@ -66,7 +66,7 @@ function createClassAttribute(clazz: string): AttributeNode {
return createAttributeNode('class', clazz)
}
-function addStaticClass(node: ElementNode, clazz: string) {
+export function addStaticClass(node: ElementNode, clazz: string) {
const classProp = node.props.find(
(prop) => prop.type === NodeTypes.ATTRIBUTE && prop.name === 'class'
) as AttributeNode | undefined
@@ -89,25 +89,10 @@ function addScopeId(node: ElementNode, scopeId: string) {
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) {
const { tag } = node
if (context.bindingComponents[tag]) {
- return addVueRef(node, context)
+ return
}
// 1. dynamic component
@@ -136,9 +121,6 @@ function processComponent(node: ComponentNode, context: TransformContext) {
)
}
- addVueId(node, context)
- addVueRef(node, context)
-
// 3. user component (from setup bindings)
const fromSetup = resolveSetupReference(tag, context)
if (fromSetup) {
diff --git a/packages/uni-mp-compiler/src/transforms/transformIdentifier.ts b/packages/uni-mp-compiler/src/transforms/transformIdentifier.ts
index 91c591b306f046dc663823f87160e982a58a9141..f6234ada18ab92eddbf0bf4719e147aaad51ca51 100644
--- a/packages/uni-mp-compiler/src/transforms/transformIdentifier.ts
+++ b/packages/uni-mp-compiler/src/transforms/transformIdentifier.ts
@@ -1,5 +1,6 @@
import {
createCompoundExpression,
+ DirectiveNode,
NodeTypes,
TO_DISPLAY_STRING,
} from '@vue/compiler-core'
@@ -49,7 +50,9 @@ export const transformIdentifier: NodeTransform = (node, context) => {
}
const exp = dir.exp
if (exp) {
- if (isSelfKey(dir, vFor)) {
+ if (isBuiltIn(dir)) {
+ // noop
+ } else if (isSelfKey(dir, vFor)) {
rewriteSelfKey(dir)
} else if (isClassBinding(dir)) {
hasClassBinding = true
@@ -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)
+ // )
+}
diff --git a/packages/uni-mp-compiler/src/transforms/vFor.ts b/packages/uni-mp-compiler/src/transforms/vFor.ts
index 81d5dc967308a370cfb4a99f9471443cab915710..7ccc130b73680816243729a21ba463d48e584e69 100644
--- a/packages/uni-mp-compiler/src/transforms/vFor.ts
+++ b/packages/uni-mp-compiler/src/transforms/vFor.ts
@@ -30,16 +30,16 @@ import { rewriteExpression } from './utils'
export type VForOptions = Omit & {
sourceExpr?: Expression
- sourceAlias?: string
- valueCode?: string
- valueExpr?: Identifier | Pattern | RestElement
- valueAlias?: string
- keyCode?: string
- keyExpr?: Identifier | Pattern | RestElement
- keyAlias?: string
- indexCode?: string
- indexExpr?: Identifier | Pattern | RestElement
- indexAlias?: string
+ sourceAlias: string
+ valueCode: string
+ valueExpr: Identifier | Pattern | RestElement
+ valueAlias: string
+ keyCode: string
+ keyExpr: Identifier | Pattern | RestElement
+ keyAlias: string
+ indexCode: string
+ indexExpr: Identifier | Pattern | RestElement
+ indexAlias: string
}
export type ForElementNode = ElementNode & {
@@ -73,31 +73,26 @@ export const transformFor = createStructuralDirectiveTransform(
const { addIdentifiers, removeIdentifiers } = context
const { source, value, key, index } = parseResult
if (context.prefixIdentifiers) {
- value && addIdentifiers(value)
- key && addIdentifiers(key)
- index && addIdentifiers(index)
+ addIdentifiers(value)
+ addIdentifiers(key)
+ addIdentifiers(index)
}
const { currentScope: parentScope, scopes, popScope } = context
const sourceExpr = parseExpr(source, context)
- const valueCode = value && genExpr(value)
- const valueExpr = valueCode
- ? parseParam(valueCode, context, value)
- : undefined
- const valueAlias =
- (valueExpr && parseAlias(valueExpr, valueCode!, 'v' + scopes.vFor)) ||
- 'v' + scopes.vFor
- const keyCode = key && genExpr(key)
- const keyExpr = keyCode ? parseParam(keyCode, context, key) : undefined
- const keyAlias = keyExpr && parseAlias(keyExpr, keyCode!, 'k' + 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 valueCode = genExpr(value)
+
+ const valueExpr = parseParam(valueCode, context, value)
+ const valueAlias = parseAlias(valueExpr, valueCode, 'v' + scopes.vFor)
+ const keyCode = genExpr(key)
+ const keyExpr = parseParam(keyCode, context, key)
+ const keyAlias = parseAlias(keyExpr, keyCode, 'k' + scopes.vFor)
+ const indexCode = genExpr(index)
+ const indexExpr = parseParam(indexCode, context, index)
+ const indexAlias = parseAlias(indexExpr, indexCode, 'i' + scopes.vFor)
const vForData: VForOptions = {
source,
sourceExpr,
+ sourceAlias: '',
value,
valueCode,
valueExpr,
@@ -172,12 +167,12 @@ function clearExpr(expr: Expression) {
function parseAlias(
babelExpr: Identifier | Pattern | RestElement,
exprCode: string,
- defaultAlias: string
+ fallback: string
) {
if (isIdentifier(babelExpr)) {
return exprCode
}
- return defaultAlias
+ return fallback
}
function findVForLocals({ value, key, index }: ForParseResult) {
@@ -209,9 +204,9 @@ const stripParensRE = /^\(|\)$/g
export interface ForParseResult {
source: ExpressionNode
- value: ExpressionNode | undefined
- key: ExpressionNode | undefined
- index: ExpressionNode | undefined
+ value: ExpressionNode
+ key: ExpressionNode
+ index: ExpressionNode
tagType: ElementTypes
}
@@ -232,9 +227,9 @@ export function parseForExpression(
RHS.trim(),
exp.indexOf(RHS, LHS.length)
),
- value: undefined,
- key: undefined,
- index: undefined,
+ value: createSimpleExpression('v' + context.scopes.vFor),
+ key: createSimpleExpression('k' + context.scopes.vFor),
+ index: createSimpleExpression('i' + context.scopes.vFor),
tagType: ElementTypes.ELEMENT,
}
if (context.prefixIdentifiers) {
diff --git a/packages/uni-mp-vue/dist/vue.runtime.esm.js b/packages/uni-mp-vue/dist/vue.runtime.esm.js
index 775ab5728aa5def753d84c0680ad16714a2e335e..fae1d4d28188289edc690fa235c390c45bd0786b 100644
--- a/packages/uni-mp-vue/dist/vue.runtime.esm.js
+++ b/packages/uni-mp-vue/dist/vue.runtime.esm.js
@@ -4960,7 +4960,7 @@ function vFor(source, renderItem) {
if (isArray(source) || isString(source)) {
ret = new Array(source.length);
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') {
@@ -4970,12 +4970,12 @@ function vFor(source, renderItem) {
}
ret = new Array(source);
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)) {
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 {
const keys = Object.keys(source);
@@ -5014,6 +5014,7 @@ function vOn(value) {
}
function createInvoker(initialValue, instance) {
const invoker = (e) => {
+ patchMPEvent(e);
let args = [e];
if (e.detail && e.detail.__args__) {
args = e.detail.__args__;
@@ -5023,6 +5024,12 @@ function createInvoker(initialValue, instance) {
invoker.value = initialValue;
return invoker;
}
+function patchMPEvent(e) {
+ if (e.type && e.target) {
+ e.stopPropagation = () => { };
+ e.preventDefault = () => { };
+ }
+}
function patchStopImmediatePropagation(e, value) {
if (isArray(value)) {
const originalStop = e.stopImmediatePropagation;
diff --git a/packages/uni-mp-vue/src/helpers/vFor.ts b/packages/uni-mp-vue/src/helpers/vFor.ts
index a349453b685d8e54da7292d36d6a9c8a6cede5a8..ea06b7f75689033e1d7877085e38462f2712722b 100644
--- a/packages/uni-mp-vue/src/helpers/vFor.ts
+++ b/packages/uni-mp-vue/src/helpers/vFor.ts
@@ -59,7 +59,7 @@ export function vFor(
if (isArray(source) || isString(source)) {
ret = new Array(source.length)
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') {
if (__DEV__ && !Number.isInteger(source)) {
@@ -68,12 +68,12 @@ export function vFor(
}
ret = new Array(source)
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)) {
if (source[Symbol.iterator as any]) {
ret = Array.from(source as Iterable, (item, i) =>
- renderItem(item, i, undefined)
+ renderItem(item, i, i)
)
} else {
const keys = Object.keys(source)
diff --git a/packages/uni-mp-vue/src/helpers/vOn.ts b/packages/uni-mp-vue/src/helpers/vOn.ts
index 87f24c5168c0c6124e9a8f4e107aaec36ef2af41..9580766ba1de060ada6f611a1fb30554f0e6cfcd 100644
--- a/packages/uni-mp-vue/src/helpers/vOn.ts
+++ b/packages/uni-mp-vue/src/helpers/vOn.ts
@@ -49,6 +49,7 @@ function createInvoker(
instance: ComponentInternalInstance | null
) {
const invoker: Invoker = (e: Event) => {
+ patchMPEvent(e)
let args: unknown[] = [e]
if ((e as MPEvent).detail && (e as MPEvent).detail.__args__) {
args = (e as MPEvent).detail.__args__!
@@ -64,6 +65,13 @@ function createInvoker(
return invoker
}
+function patchMPEvent(e: Event) {
+ if (e.type && e.target) {
+ e.stopPropagation = () => {}
+ e.preventDefault = () => {}
+ }
+}
+
function patchStopImmediatePropagation(
e: Event,
value: EventValue
diff --git a/packages/uni-mp-weixin/dist/uni.compiler.js b/packages/uni-mp-weixin/dist/uni.compiler.js
index 66f285a557d0532d92c5f5106c50d7a6776efdf4..c4ae9b5d295d937230068c7580c1cdd01d88bc01 100644
--- a/packages/uni-mp-weixin/dist/uni.compiler.js
+++ b/packages/uni-mp-weixin/dist/uni.compiler.js
@@ -61,7 +61,7 @@ const uniMiniProgramWeixinPlugin = {
config() {
return {
define: {
- __VUE_CREATED_DEFERRED__: JSON.stringify('false'),
+ __VUE_CREATED_DEFERRED__: false,
},
};
},
diff --git a/packages/uni-mp-weixin/src/plugin/index.ts b/packages/uni-mp-weixin/src/plugin/index.ts
index 5a1af6710fb13ed904000ff0da7d22bfe97fdf2d..d27e13b318b91455ab1fa98365c4f7cf62df6662 100644
--- a/packages/uni-mp-weixin/src/plugin/index.ts
+++ b/packages/uni-mp-weixin/src/plugin/index.ts
@@ -11,7 +11,7 @@ const uniMiniProgramWeixinPlugin: Plugin = {
config() {
return {
define: {
- __VUE_CREATED_DEFERRED__: JSON.stringify('false'),
+ __VUE_CREATED_DEFERRED__: false,
},
}
},