提交 b8016ef6 编写于 作者: fxy060608's avatar fxy060608

wip(mp): quickapp-webview

上级 4045d035
......@@ -5,6 +5,7 @@ declare namespace NodeJS {
interface ProcessEnv {
NODE_ENV: 'production' | 'development' | 'test'
UNI_PLATFORM: UniApp.PLATFORM
UNI_SUB_PLATFORM: 'quickapp-webview-huawei' | 'quickapp-webview-union'
UNI_INPUT_DIR: string
UNI_OUTPUT_DIR: string
UNI_CLI_CONTEXT: string
......
......@@ -18,7 +18,9 @@
},
"uni-app": {
"name": "uni-app-plus",
"apply": "app",
"apply": [
"app"
],
"main": "dist/index.js"
},
"license": "Apache-2.0",
......
......@@ -18,7 +18,9 @@
},
"uni-app": {
"name": "uni-cli-nvue",
"apply": "app",
"apply": [
"app"
],
"main": "dist/plugin.js"
},
"license": "Apache-2.0",
......
......@@ -18,7 +18,9 @@
},
"uni-app": {
"name": "uni-h5",
"apply": "h5",
"apply": [
"h5"
],
"main": "dist/index.js"
},
"license": "Apache-2.0",
......
......@@ -15,7 +15,7 @@ describe('mp-alipay: transform component', () => {
test(`match-media`, () => {
assert(
`<match-media/>`,
`<uni-match-media v-i="2a9ec0b0-0" onVI="__l"/>`,
`<uni-match-media u-i="2a9ec0b0-0" onVI="__l"/>`,
`(_ctx, _cache) => {
return {}
}`
......
......@@ -4,14 +4,14 @@ describe('mp-alipay: transform ref', () => {
test('without ref', () => {
assert(
`<custom/>`,
`<custom v-i="2a9ec0b0-0" onVI="__l"/>`,
`<custom u-i="2a9ec0b0-0" onVI="__l"/>`,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`<custom/><custom/><custom1/>`,
`<custom v-i="2a9ec0b0-0" onVI="__l"/><custom v-i="2a9ec0b0-1" onVI="__l"/><custom1 v-i="2a9ec0b0-2" onVI="__l"/>`,
`<custom u-i="2a9ec0b0-0" onVI="__l"/><custom u-i="2a9ec0b0-1" onVI="__l"/><custom1 u-i="2a9ec0b0-2" onVI="__l"/>`,
`(_ctx, _cache) => {
return {}
}`
......@@ -20,14 +20,14 @@ describe('mp-alipay: transform ref', () => {
test('static ref', () => {
assert(
`<custom ref="custom"/>`,
`<custom ref="__r" data-r="custom" v-i="2a9ec0b0-0" onVI="__l"/>`,
`<custom ref="__r" data-r="custom" u-i="2a9ec0b0-0" onVI="__l"/>`,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`<custom v-for="item in items" ref="custom"/>`,
`<custom a:for="{{a}}" a:for-item="item" ref="__r" data-r-i-f="custom" v-i="{{item.a}}" onVI="__l"/>`,
`<custom a:for="{{a}}" a:for-item="item" ref="__r" data-r-i-f="custom" u-i="{{item.a}}" onVI="__l"/>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }) }
}`
......@@ -36,14 +36,14 @@ describe('mp-alipay: transform ref', () => {
test('dynamic ref', () => {
assert(
`<custom :ref="custom"/>`,
`<custom ref="__r" data-r="{{a}}" v-i="2a9ec0b0-0" onVI="__l"/>`,
`<custom ref="__r" data-r="{{a}}" u-i="2a9ec0b0-0" onVI="__l"/>`,
`(_ctx, _cache) => {
return { a: _ctx.custom }
}`
)
assert(
`<custom v-for="item in items" :ref="custom"/>`,
`<custom a:for="{{a}}" a:for-item="item" ref="__r" data-r-i-f="{{b}}" v-i="{{item.a}}" onVI="__l"/>`,
`<custom a:for="{{a}}" a:for-item="item" ref="__r" data-r-i-f="{{b}}" u-i="{{item.a}}" onVI="__l"/>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }), b: _ctx.custom }
}`
......
......@@ -20,7 +20,7 @@ describe('mp-alipay: transform v-on', () => {
)
assert(
`<custom v-on:click="onClick"/>`,
`<custom onClick="{{a}}" v-i="2a9ec0b0-0" onVI="__l"/>`,
`<custom onClick="{{a}}" u-i="2a9ec0b0-0" onVI="__l"/>`,
`(_ctx, _cache) => {
return { a: _o(_ctx.onClick) }
}`
......
......@@ -4,14 +4,14 @@ describe('mp-alipay: transform v-slot', () => {
test('default slot', () => {
assert(
`<custom><template v-slot/></custom>`,
`<custom v-i="2a9ec0b0-0" onVI="__l"><view/></custom>`,
`<custom u-i="2a9ec0b0-0" onVI="__l"><view/></custom>`,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`<custom>test</custom>`,
`<custom v-i="2a9ec0b0-0" onVI="__l">test</custom>`,
`<custom u-i="2a9ec0b0-0" onVI="__l">test</custom>`,
`(_ctx, _cache) => {
return {}
}`
......@@ -20,16 +20,16 @@ describe('mp-alipay: transform v-slot', () => {
test('named slots', () => {
assert(
`<custom><template v-slot:header/><template v-slot:default/><template v-slot:footer/></custom>`,
`<custom v-i="2a9ec0b0-0" onVI="__l"><view slot="header"/><view slot="default"/><view slot="footer"/></custom>`,
`<custom u-i="2a9ec0b0-0" onVI="__l"><view slot="header"/><view slot="d"/><view slot="footer"/></custom>`,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`<unicloud-db v-slot:default="{data, loading, error, options}" collection=""><view v-if="error">{{error.message}}</view><view v-else></view></unicloud-db>`,
`<unicloud-db slot="default" collection="" v-i="2a9ec0b0-0" onVI="__l"><view a:for="{{a}}" a:for-item="v0" a:key="c" slot="{{v0.d}}"><view a:if="{{v0.a}}">{{v0.b}}</view><view a:else></view></view></unicloud-db>`,
`<unicloud-db slot="d" collection="" u-i="2a9ec0b0-0" onVI="__l"><view a:for="{{a}}" a:for-item="v0" a:key="c" slot="{{v0.d}}"><view a:if="{{v0.a}}">{{v0.b}}</view><view a:else></view></view></unicloud-db>`,
`(_ctx, _cache) => {
return { a: _w(({ data, loading, error, options }, s0, i0) => { return _e({ a: error }, error ? { b: _t(error.message) } : {}, { c: s0, d: i0 }); }, { name: 'default', vueId: '2a9ec0b0-0' }) }
return { a: _w(({ data, loading, error, options }, s0, i0) => { return _e({ a: error }, error ? { b: _t(error.message) } : {}, { c: s0, d: i0 }); }, { name: 'd', vueId: '2a9ec0b0-0' }) }
}`
)
})
......@@ -37,9 +37,9 @@ describe('mp-alipay: transform v-slot', () => {
test('scoped slots', () => {
assert(
`<custom><template v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>`,
`<custom v-i="2a9ec0b0-0" onVI="__l"><view slot="default"><view a:for="{{a}}" a:for-item="slotProps" a:key="b" slot="{{slotProps.c}}"><view>{{slotProps.a}}</view></view></view></custom>`,
`<custom u-i="2a9ec0b0-0" onVI="__l"><view a:for="{{a}}" a:for-item="slotProps" a:key="b" slot="{{slotProps.c}}"><view>{{slotProps.a}}</view></view></custom>`,
`(_ctx, _cache) => {
return { a: _w((slotProps, s0, i0) => { return { a: _t(slotProps.item), b: s0, c: i0 }; }, { name: 'default', vueId: '2a9ec0b0-0' }) }
return { a: _w((slotProps, s0, i0) => { return { a: _t(slotProps.item), b: s0, c: i0 }; }, { name: 'd', vueId: '2a9ec0b0-0' }) }
}`
)
})
......@@ -47,9 +47,9 @@ describe('mp-alipay: transform v-slot', () => {
test('scoped slots + scoped slots', () => {
assert(
`<custom><template v-slot:default="slotProps"><custom1><template v-slot:default="slotProps1">{{ slotProps.item }}{{ slotProps1.item }}</template></custom1></template></custom>`,
`<custom v-i="2a9ec0b0-0" onVI="__l"><view slot="default"><view a:for="{{a}}" a:for-item="slotProps" a:key="d" slot="{{slotProps.e}}"><custom1 v-i="{{slotProps.c}}" onVI="__l"><view slot="default"><view a:for="{{slotProps.a}}" a:for-item="slotProps1" a:key="b" slot="{{slotProps1.c}}">{{slotProps.b}}{{slotProps1.a}}</view></view></custom1></view></view></custom>`,
`<custom u-i="2a9ec0b0-0" onVI="__l"><view a:for="{{a}}" a:for-item="slotProps" a:key="d" slot="{{slotProps.e}}"><custom1 u-i="{{slotProps.c}}" onVI="__l"><view a:for="{{slotProps.a}}" a:for-item="slotProps1" a:key="b" slot="{{slotProps1.c}}">{{slotProps.b}}{{slotProps1.a}}</view></custom1></view></custom>`,
`(_ctx, _cache) => {
return { a: _w((slotProps, s0, i0) => { return { a: _w((slotProps1, s1, i1) => { return { a: _t(slotProps1.item), b: s1, c: i1 }; }, { name: 'default', vueId: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0' }), b: _t(slotProps.item), c: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0', d: s0, e: i0 }; }, { name: 'default', vueId: '2a9ec0b0-0' }) }
return { a: _w((slotProps, s0, i0) => { return { a: _w((slotProps1, s1, i1) => { return { a: _t(slotProps1.item), b: s1, c: i1 }; }, { name: 'd', vueId: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0' }), b: _t(slotProps.item), c: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0', d: s0, e: i0 }; }, { name: 'd', vueId: '2a9ec0b0-0' }) }
}`
)
})
......@@ -57,9 +57,9 @@ describe('mp-alipay: transform v-slot', () => {
test('v-if + scoped slots', () => {
assert(
`<custom><template v-if="ok" v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>`,
`<custom v-i="2a9ec0b0-0" onVI="__l"><view a:if="{{a}}" slot="default"><view a:for="{{b}}" a:for-item="slotProps" a:key="b" slot="{{slotProps.c}}"><view>{{slotProps.a}}</view></view></view></custom>`,
`<custom u-i="2a9ec0b0-0" onVI="__l"><block a:if="{{a}}"><view a:for="{{b}}" a:for-item="slotProps" a:key="b" slot="{{slotProps.c}}"><view>{{slotProps.a}}</view></view></block></custom>`,
`(_ctx, _cache) => {
return _e({ a: _ctx.ok }, _ctx.ok ? { b: _w((slotProps, s0, i0) => { return { a: _t(slotProps.item), b: s0, c: i0 }; }, { name: 'default', vueId: '2a9ec0b0-0' }) } : {})
return _e({ a: _ctx.ok }, _ctx.ok ? { b: _w((slotProps, s0, i0) => { return { a: _t(slotProps.item), b: s0, c: i0 }; }, { name: 'd', vueId: '2a9ec0b0-0' }) } : {})
}`
)
})
......@@ -67,9 +67,9 @@ describe('mp-alipay: transform v-slot', () => {
test('v-for + scoped slots', () => {
assert(
`<custom v-for="item in items"><template v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>`,
`<custom a:for="{{a}}" a:for-item="item" v-i="{{item.b}}" onVI="__l"><view slot="default"><view a:for="{{item.a}}" a:for-item="slotProps" a:key="b" slot="{{slotProps.c}}"><view>{{slotProps.a}}</view></view></view></custom>`,
`<custom a:for="{{a}}" a:for-item="item" u-i="{{item.b}}" onVI="__l"><view a:for="{{item.a}}" a:for-item="slotProps" a:key="b" slot="{{slotProps.c}}"><view>{{slotProps.a}}</view></view></custom>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _w((slotProps, s1, i1) => { return { a: _t(slotProps.item), b: s1, c: i1 }; }, { name: 'default', vueId: '2a9ec0b0-0' + '-' + i0 }), b: '2a9ec0b0-0' + '-' + i0 }; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _w((slotProps, s1, i1) => { return { a: _t(slotProps.item), b: s1, c: i1 }; }, { name: 'd', vueId: '2a9ec0b0-0' + '-' + i0 }), b: '2a9ec0b0-0' + '-' + i0 }; }) }
}`
)
})
......@@ -77,9 +77,9 @@ describe('mp-alipay: transform v-slot', () => {
test('v-for + v-for + scoped slots', () => {
assert(
`<view v-for="item in items"><custom v-for="item1 in item.list" :item="item1"><template v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom></view>`,
`<view a:for="{{a}}" a:for-item="item"><custom a:for="{{item.a}}" a:for-item="item1" item="{{item1.b}}" v-i="{{item1.c}}" onVI="__l"><view slot="default"><view a:for="{{item1.a}}" a:for-item="slotProps" a:key="b" slot="{{slotProps.c}}"><view>{{slotProps.a}}</view></view></view></custom></view>`,
`<view a:for="{{a}}" a:for-item="item"><custom a:for="{{item.a}}" a:for-item="item1" item="{{item1.b}}" u-i="{{item1.c}}" onVI="__l"><view a:for="{{item1.a}}" a:for-item="slotProps" a:key="b" slot="{{slotProps.c}}"><view>{{slotProps.a}}</view></view></custom></view>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _f(item.list, (item1, k1, i1) => { return { a: _w((slotProps, s2, i2) => { return { a: _t(slotProps.item), b: s2, c: i2 }; }, { name: 'default', vueId: '2a9ec0b0-0' + '-' + i0 + '-' + i1 }), b: item1, c: '2a9ec0b0-0' + '-' + i0 + '-' + i1 }; }) }; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _f(item.list, (item1, k1, i1) => { return { a: _w((slotProps, s2, i2) => { return { a: _t(slotProps.item), b: s2, c: i2 }; }, { name: 'd', vueId: '2a9ec0b0-0' + '-' + i0 + '-' + i1 }), b: item1, c: '2a9ec0b0-0' + '-' + i0 + '-' + i1 }; }) }; }) }
}`
)
})
......
......@@ -27,6 +27,8 @@ const invokeArrayFns = (fns, arg) => {
}
return ret;
};
// quickapp-webview 不能使用 default 作为插槽名称
const SLOT_DEFAULT_NAME = 'd';
// lifecycle
// App and Page
const ON_SHOW = 'onShow';
......@@ -171,6 +173,9 @@ function initBaseInstance(instance, options) {
else {
delete slots.default;
}
if (slots[SLOT_DEFAULT_NAME]) {
slots.default = true;
}
return slots;
}
},
......@@ -408,12 +413,12 @@ function normalizePropType(type, defaultValue) {
function initDefaultProps(isBehavior = false) {
const properties = {};
if (!isBehavior) {
properties.vI = {
properties.uI = {
type: null,
value: '',
};
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
properties.vS = {
properties.uS = {
type: null,
value: [],
observer: function (newVal) {
......@@ -894,7 +899,7 @@ function initComponentProps(rawProps) {
};
Object.keys(properties).forEach((key) => {
// vueSlots
if (key !== 'vS') {
if (key !== 'uS') {
props[key] = properties[key].value;
}
});
......@@ -905,7 +910,7 @@ function initVm(mpInstance, createComponent) {
return;
}
const properties = mpInstance.props;
initVueIds(properties.vI, mpInstance);
initVueIds(properties.uI, mpInstance);
const relationOptions = {
vuePid: mpInstance._$vuePid,
mpInstance,
......
......@@ -15,7 +15,9 @@
"uni-app": {
"name": "mp-alipay",
"title": "支付宝小程序",
"apply": "mp-alipay",
"apply": [
"mp-alipay"
],
"main": "dist/uni.compiler.js"
},
"gitHead": "7bcc3303c15141d377645a4995ce186f10ed6b78"
......
......@@ -38,7 +38,7 @@ function initComponentProps(rawProps: Record<string, any>) {
}
Object.keys(properties).forEach((key) => {
// vueSlots
if (key !== 'vS') {
if (key !== 'uS') {
props[key] = properties[key].value
}
})
......@@ -54,7 +54,7 @@ function initVm(
return
}
const properties = mpInstance.props
initVueIds(properties.vI, mpInstance as any)
initVueIds(properties.uI, mpInstance as any)
const relationOptions: RelationOptions = {
vuePid: mpInstance._$vuePid,
mpInstance,
......
......@@ -4,7 +4,7 @@ describe('mp-baidu: transform component', () => {
test(`match-media`, () => {
assert(
`<match-media/>`,
`<uni-match-media v-i="2a9ec0b0-0"/>`,
`<uni-match-media u-i="2a9ec0b0-0"/>`,
`(_ctx, _cache) => {
return {}
}`
......
......@@ -4,7 +4,7 @@ describe('mp-baidu: transform v-model', () => {
test(`component v-model`, () => {
assert(
`<Comp v-model="model" />`,
`<comp v-i="2a9ec0b0-0" eO="{{a}}" modelValue="{{b}}" bindupdateModelValue="__e"/>`,
`<comp u-i="2a9ec0b0-0" eO="{{a}}" modelValue="{{b}}" bindupdateModelValue="__e"/>`,
`(_ctx, _cache) => {
return { a: { 'updateModelValue': _o($event => _ctx.model = $event) }, b: _ctx.model }
}`
......@@ -13,7 +13,7 @@ describe('mp-baidu: transform v-model', () => {
test(`component v-model with cache`, () => {
assert(
`<Comp v-model="model" />`,
`<comp v-i="2a9ec0b0-0" eO="{{a}}" modelValue="{{b}}" bindupdateModelValue="__e"/>`,
`<comp u-i="2a9ec0b0-0" eO="{{a}}" modelValue="{{b}}" bindupdateModelValue="__e"/>`,
`(_ctx, _cache) => {
return { a: { 'updateModelValue': _o($event => _ctx.model = $event) }, b: _ctx.model }
}`,
......
......@@ -5,7 +5,7 @@ describe('mp-baidu: transform v-on', () => {
test(`built-in event`, () => {
assert(
`<custom @tap="tap"/>`,
`<custom bindtap="{{a}}" v-i="2a9ec0b0-0"/>`,
`<custom bindtap="{{a}}" u-i="2a9ec0b0-0"/>`,
`(_ctx, _cache) => {
return { a: _o(_ctx.tap) }
}`
......@@ -14,7 +14,7 @@ describe('mp-baidu: transform v-on', () => {
test(`custom event`, () => {
assert(
`<custom @click="click"/>`,
`<custom bindclick="__e" v-i="2a9ec0b0-0" eO="{{a}}"/>`,
`<custom bindclick="__e" u-i="2a9ec0b0-0" eO="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: { 'click': _o(_ctx.click) } }
}`
......@@ -23,7 +23,7 @@ describe('mp-baidu: transform v-on', () => {
test(`multi custom event`, () => {
assert(
`<custom @unmount="unmount" @custom-mount="mount();created();"/>`,
`<custom bindunmount="__e" bind:custom-mount="__e" v-i="2a9ec0b0-0" eO="{{a}}"/>`,
`<custom bindunmount="__e" bind:custom-mount="__e" u-i="2a9ec0b0-0" eO="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: { 'custom-mount': _o($event => { _ctx.mount(); _ctx.created(); }), 'unmount': _o(_ctx.unmount) } }
}`
......
......@@ -4,14 +4,14 @@ describe('compiler: transform v-slot', () => {
test('default slot', () => {
assert(
`<custom><template v-slot/></custom>`,
`<custom v-s="{{['default']}}" v-i="2a9ec0b0-0"><view/></custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0"><view/></custom>`,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`<custom>test</custom>`,
`<custom v-s="{{['default']}}" v-i="2a9ec0b0-0">test</custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0">test</custom>`,
`(_ctx, _cache) => {
return {}
}`
......@@ -20,16 +20,16 @@ describe('compiler: transform v-slot', () => {
test('named slots', () => {
assert(
`<custom><template v-slot:header/><template v-slot:default/><template v-slot:footer/></custom>`,
`<custom v-s="{{['header','default','footer']}}" v-i="2a9ec0b0-0"><view slot="header"/><view slot="default"/><view slot="footer"/></custom>`,
`<custom u-s="{{['header','d','footer']}}" u-i="2a9ec0b0-0"><view slot="header"/><view slot="d"/><view slot="footer"/></custom>`,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`<unicloud-db v-slot:default="{data, loading, error, options}" collection=""><view v-if="error">{{error.message}}</view><view v-else></view></unicloud-db>`,
`<unicloud-db v-s="{{['default']}}" slot="default" collection="" v-i="2a9ec0b0-0"><block s-for="v0 in a trackBy v0.a"><view s-if="{{v0.b}}">{{v0.c}}</view><view s-else></view></block></unicloud-db>`,
`<unicloud-db u-s="{{['d']}}" slot="d" collection="" u-i="2a9ec0b0-0"><block s-for="v0 in a trackBy v0.a"><view s-if="{{v0.b}}">{{v0.c}}</view><view s-else></view></block></unicloud-db>`,
`(_ctx, _cache) => {
return { a: _w(({ data, loading, error, options }, s0, i0) => { return _e({ a: s0, b: error }, error ? { c: _t(error.message) } : {}); }, { name: 'default', vueId: '2a9ec0b0-0' }) }
return { a: _w(({ data, loading, error, options }, s0, i0) => { return _e({ a: s0, b: error }, error ? { c: _t(error.message) } : {}); }, { name: 'd', vueId: '2a9ec0b0-0' }) }
}`
)
})
......@@ -37,9 +37,9 @@ describe('compiler: transform v-slot', () => {
test('scoped slots', () => {
assert(
`<custom><template v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>`,
`<custom v-s="{{['default']}}" v-i="2a9ec0b0-0"><view slot="default"><block s-for="slotProps in a trackBy slotProps.a"><view>{{slotProps.b}}</view></block></view></custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0"><view slot="d"><block s-for="slotProps in a trackBy slotProps.a"><view>{{slotProps.b}}</view></block></view></custom>`,
`(_ctx, _cache) => {
return { a: _w((slotProps, s0, i0) => { return { a: s0, b: _t(slotProps.item) }; }, { name: 'default', vueId: '2a9ec0b0-0' }) }
return { a: _w((slotProps, s0, i0) => { return { a: s0, b: _t(slotProps.item) }; }, { name: 'd', vueId: '2a9ec0b0-0' }) }
}`
)
})
......@@ -47,9 +47,9 @@ describe('compiler: transform v-slot', () => {
test('scoped slots + scoped slots', () => {
assert(
`<custom><template v-slot:default="slotProps"><custom1><template v-slot:default="slotProps1">{{ slotProps.item }}{{ slotProps1.item }}</template></custom1></template></custom>`,
`<custom v-s="{{['default']}}" v-i="2a9ec0b0-0"><view slot="default"><block s-for="slotProps in a trackBy slotProps.a"><custom1 v-s="{{['default']}}" v-i="{{slotProps.d}}"><view slot="default"><block s-for="slotProps1 in slotProps.b trackBy slotProps1.a">{{slotProps.c}}{{slotProps1.b}}</block></view></custom1></block></view></custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0"><view slot="d"><block s-for="slotProps in a trackBy slotProps.a"><custom1 u-s="{{['d']}}" u-i="{{slotProps.d}}"><view slot="d"><block s-for="slotProps1 in slotProps.b trackBy slotProps1.a">{{slotProps.c}}{{slotProps1.b}}</block></view></custom1></block></view></custom>`,
`(_ctx, _cache) => {
return { a: _w((slotProps, s0, i0) => { return { a: s0, b: _w((slotProps1, s1, i1) => { return { a: s1, b: _t(slotProps1.item) }; }, { name: 'default', vueId: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0' }), c: _t(slotProps.item), d: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0' }; }, { name: 'default', vueId: '2a9ec0b0-0' }) }
return { a: _w((slotProps, s0, i0) => { return { a: s0, b: _w((slotProps1, s1, i1) => { return { a: s1, b: _t(slotProps1.item) }; }, { name: 'd', vueId: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0' }), c: _t(slotProps.item), d: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0' }; }, { name: 'd', vueId: '2a9ec0b0-0' }) }
}`
)
})
......@@ -57,9 +57,9 @@ describe('compiler: transform v-slot', () => {
test('v-if + scoped slots', () => {
assert(
`<custom><template v-if="ok" v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>`,
`<custom v-s="{{['default']}}" v-i="2a9ec0b0-0"><view s-if="{{a}}" slot="default"><block s-for="slotProps in b trackBy slotProps.a"><view>{{slotProps.b}}</view></block></view></custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0"><view s-if="{{a}}" slot="d"><block s-for="slotProps in b trackBy slotProps.a"><view>{{slotProps.b}}</view></block></view></custom>`,
`(_ctx, _cache) => {
return _e({ a: _ctx.ok }, _ctx.ok ? { b: _w((slotProps, s0, i0) => { return { a: s0, b: _t(slotProps.item) }; }, { name: 'default', vueId: '2a9ec0b0-0' }) } : {})
return _e({ a: _ctx.ok }, _ctx.ok ? { b: _w((slotProps, s0, i0) => { return { a: s0, b: _t(slotProps.item) }; }, { name: 'd', vueId: '2a9ec0b0-0' }) } : {})
}`
)
})
......@@ -67,9 +67,9 @@ describe('compiler: transform v-slot', () => {
test('v-for + scoped slots', () => {
assert(
`<custom v-for="item in items"><template v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>`,
`<custom s-for="item in a" v-s="{{['default']}}" v-i="{{item.b}}"><view slot="default"><block s-for="slotProps in item.a trackBy slotProps.a"><view>{{slotProps.b}}</view></block></view></custom>`,
`<custom s-for="item in a" u-s="{{['d']}}" u-i="{{item.b}}"><view slot="d"><block s-for="slotProps in item.a trackBy slotProps.a"><view>{{slotProps.b}}</view></block></view></custom>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _w((slotProps, s1, i1) => { return { a: s1, b: _t(slotProps.item) }; }, { name: 'default', vueId: '2a9ec0b0-0' + '-' + i0 }), b: '2a9ec0b0-0' + '-' + i0 }; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _w((slotProps, s1, i1) => { return { a: s1, b: _t(slotProps.item) }; }, { name: 'd', vueId: '2a9ec0b0-0' + '-' + i0 }), b: '2a9ec0b0-0' + '-' + i0 }; }) }
}`
)
})
......@@ -77,9 +77,9 @@ describe('compiler: transform v-slot', () => {
test('v-for + v-for + scoped slots', () => {
assert(
`<view v-for="item in items"><custom v-for="item1 in item.list" :item="item1"><template v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom></view>`,
`<view s-for="item in a"><custom s-for="item1 in item.a" v-s="{{['default']}}" item="{{item1.b}}" v-i="{{item1.c}}"><view slot="default"><block s-for="slotProps in item1.a trackBy slotProps.a"><view>{{slotProps.b}}</view></block></view></custom></view>`,
`<view s-for="item in a"><custom s-for="item1 in item.a" u-s="{{['d']}}" item="{{item1.b}}" u-i="{{item1.c}}"><view slot="d"><block s-for="slotProps in item1.a trackBy slotProps.a"><view>{{slotProps.b}}</view></block></view></custom></view>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _f(item.list, (item1, k1, i1) => { return { a: _w((slotProps, s2, i2) => { return { a: s2, b: _t(slotProps.item) }; }, { name: 'default', vueId: '2a9ec0b0-0' + '-' + i0 + '-' + i1 }), b: item1, c: '2a9ec0b0-0' + '-' + i0 + '-' + i1 }; }) }; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _f(item.list, (item1, k1, i1) => { return { a: _w((slotProps, s2, i2) => { return { a: s2, b: _t(slotProps.item) }; }, { name: 'd', vueId: '2a9ec0b0-0' + '-' + i0 + '-' + i1 }), b: item1, c: '2a9ec0b0-0' + '-' + i0 + '-' + i1 }; }) }; }) }
}`
)
})
......
......@@ -27,6 +27,8 @@ const invokeArrayFns = (fns, arg) => {
}
return ret;
};
// quickapp-webview 不能使用 default 作为插槽名称
const SLOT_DEFAULT_NAME = 'd';
// lifecycle
// App and Page
const ON_SHOW = 'onShow';
......@@ -161,6 +163,9 @@ function initBaseInstance(instance, options) {
options.slots.forEach((name) => {
instance.slots[name] = true;
});
if (instance.slots[SLOT_DEFAULT_NAME]) {
instance.slots.default = true;
}
}
}
ctx.getOpenerEventChannel = function () {
......@@ -484,12 +489,12 @@ function initDefaultProps(isBehavior = false) {
value: '',
};
}
properties.vI = {
properties.uI = {
type: null,
value: '',
};
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
properties.vS = {
properties.uS = {
type: null,
value: [],
observer: function (newVal) {
......@@ -809,7 +814,7 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) {
return {
attached() {
const properties = this.properties;
initVueIds(properties.vI, this);
initVueIds(properties.uI, this);
const relationOptions = {
vuePid: this._$vuePid,
};
......@@ -824,7 +829,7 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) {
}, {
mpType: isMiniProgramPage ? 'page' : 'component',
mpInstance,
slots: properties.vS,
slots: properties.uS,
parentComponent: relationOptions.parent && relationOptions.parent.$,
onBeforeSetup(instance, options) {
initRefs(instance, mpInstance);
......
......@@ -19,7 +19,9 @@
"uni-app": {
"name": "mp-baidu",
"title": "百度小程序",
"apply": "mp-baidu",
"apply": [
"mp-baidu"
],
"main": "dist/uni.compiler.js"
},
"gitHead": "7bcc3303c15141d377645a4995ce186f10ed6b78"
......
......@@ -9,7 +9,7 @@ describe('compiler: transform component', () => {
test('component + component', () => {
assert(
`<custom><custom1/></custom>`,
`<custom v-s="{{['default']}}" v-i="2a9ec0b0-0" bind:__l="__l"><custom1 v-i="2a9ec0b0-1,2a9ec0b0-0" bind:__l="__l"/></custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0" bind:__l="__l"><custom1 u-i="2a9ec0b0-1,2a9ec0b0-0" bind:__l="__l"/></custom>`,
`(_ctx, _cache) => {
return {}
}`,
......@@ -21,7 +21,7 @@ describe('compiler: transform component', () => {
test('component + component + component', () => {
assert(
`<custom><custom1><custom2/><custom2/></custom1></custom>`,
`<custom v-s="{{['default']}}" v-i="2a9ec0b0-0" bind:__l="__l"><custom1 v-s="{{['default']}}" v-i="2a9ec0b0-1,2a9ec0b0-0" bind:__l="__l"><custom2 v-i="2a9ec0b0-2,2a9ec0b0-1" bind:__l="__l"/><custom2 v-i="2a9ec0b0-3,2a9ec0b0-1" bind:__l="__l"/></custom1></custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0" bind:__l="__l"><custom1 u-s="{{['d']}}" u-i="2a9ec0b0-1,2a9ec0b0-0" bind:__l="__l"><custom2 u-i="2a9ec0b0-2,2a9ec0b0-1" bind:__l="__l"/><custom2 u-i="2a9ec0b0-3,2a9ec0b0-1" bind:__l="__l"/></custom1></custom>`,
`(_ctx, _cache) => {
return {}
}`,
......@@ -33,7 +33,7 @@ describe('compiler: transform component', () => {
test('component with v-for', () => {
assert(
`<custom v-for="item in items"/>`,
`<custom wx:for="{{a}}" wx:for-item="item" v-i="{{item.a}}" bind:__l="__l"/>`,
`<custom wx:for="{{a}}" wx:for-item="item" u-i="{{item.a}}" bind:__l="__l"/>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }) }
}`,
......@@ -43,7 +43,7 @@ describe('compiler: transform component', () => {
)
assert(
`<custom v-for="(item,key,index) in items"/>`,
`<custom wx:for="{{a}}" wx:for-item="item" v-i="{{item.a}}" bind:__l="__l"/>`,
`<custom wx:for="{{a}}" wx:for-item="item" u-i="{{item.a}}" bind:__l="__l"/>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, key, index) => { return { a: '2a9ec0b0-0' + '-' + index }; }) }
}`,
......@@ -55,7 +55,7 @@ describe('compiler: transform component', () => {
test('component + component with v-for', () => {
assert(
`<custom><custom1 v-for="item in items"/></custom>`,
`<custom v-s="{{['default']}}" v-i="2a9ec0b0-0" bind:__l="__l"><custom1 wx:for="{{a}}" wx:for-item="item" v-i="{{item.a}}" bind:__l="__l"/></custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0" bind:__l="__l"><custom1 wx:for="{{a}}" wx:for-item="item" u-i="{{item.a}}" bind:__l="__l"/></custom>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0' }; }) }
}`,
......@@ -67,7 +67,7 @@ describe('compiler: transform component', () => {
test('component with v-for + component', () => {
assert(
`<custom v-for="item in items"><custom1/></custom>`,
`<custom wx:for="{{a}}" wx:for-item="item" v-s="{{['default']}}" v-i="{{item.b}}" bind:__l="__l"><custom1 v-i="{{item.a}}" bind:__l="__l"/></custom>`,
`<custom wx:for="{{a}}" wx:for-item="item" u-s="{{['d']}}" u-i="{{item.b}}" bind:__l="__l"><custom1 u-i="{{item.a}}" bind:__l="__l"/></custom>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-1' + '-' + i0 + ',' + ('2a9ec0b0-0' + '-' + i0), b: '2a9ec0b0-0' + '-' + i0 }; }) }
}`,
......@@ -79,7 +79,7 @@ describe('compiler: transform component', () => {
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" v-s="{{['default']}}" v-i="{{item.b}}" bind:__l="__l"><custom1 wx:for="{{item.a}}" wx:for-item="item1" v-i="{{item1.a}}" bind:__l="__l"/></custom>`,
`<custom wx:for="{{a}}" wx:for-item="item" u-s="{{['d']}}" u-i="{{item.b}}" bind:__l="__l"><custom1 wx:for="{{item.a}}" wx:for-item="item1" u-i="{{item1.a}}" bind:__l="__l"/></custom>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _f(item.items, (item1, k1, i1) => { return { a: '2a9ec0b0-1' + '-' + i0 + '-' + i1 + ',' + ('2a9ec0b0-0' + '-' + i0) }; }), b: '2a9ec0b0-0' + '-' + i0 }; }) }
}`,
......@@ -91,7 +91,7 @@ describe('compiler: transform component', () => {
test(`component with boolean attribute`, () => {
assert(
`<uni-collapse accordion/>`,
`<uni-collapse accordion="{{true}}" v-i="2a9ec0b0-0"/>`,
`<uni-collapse accordion="{{true}}" u-i="2a9ec0b0-0"/>`,
`(_ctx, _cache) => {
return {}
}`
......
......@@ -6,7 +6,7 @@ describe('compiler: transform ref', () => {
test('without ref', () => {
assert(
`<custom/>`,
`<custom v-i="2a9ec0b0-0"/>`,
`<custom u-i="2a9ec0b0-0"/>`,
`(_ctx, _cache) => {
return {}
}`,
......@@ -16,7 +16,7 @@ describe('compiler: transform ref', () => {
)
assert(
`<custom/><custom/><custom1/>`,
`<custom v-i="2a9ec0b0-0"/><custom v-i="2a9ec0b0-1"/><custom1 v-i="2a9ec0b0-2"/>`,
`<custom u-i="2a9ec0b0-0"/><custom u-i="2a9ec0b0-1"/><custom1 u-i="2a9ec0b0-2"/>`,
`(_ctx, _cache) => {
return {}
}`,
......@@ -28,7 +28,7 @@ describe('compiler: transform ref', () => {
test('static ref', () => {
assert(
`<custom ref="custom"/>`,
`<custom class="r" data-r="custom" v-i="2a9ec0b0-0"/>`,
`<custom class="r" data-r="custom" u-i="2a9ec0b0-0"/>`,
`(_ctx, _cache) => {
return {}
}`,
......@@ -38,7 +38,7 @@ describe('compiler: transform ref', () => {
)
assert(
`<custom v-for="item in items" ref="custom"/>`,
`<custom wx:for="{{a}}" wx:for-item="item" class="r-i-f" data-r="custom" v-i="{{item.a}}"/>`,
`<custom wx:for="{{a}}" wx:for-item="item" class="r-i-f" data-r="custom" u-i="{{item.a}}"/>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }) }
}`,
......@@ -50,7 +50,7 @@ describe('compiler: transform ref', () => {
test('dynamic ref', () => {
assert(
`<custom :ref="custom"/>`,
`<custom class="r" data-r="{{a}}" v-i="2a9ec0b0-0"/>`,
`<custom class="r" data-r="{{a}}" u-i="2a9ec0b0-0"/>`,
`(_ctx, _cache) => {
return { a: _ctx.custom }
}`,
......@@ -60,7 +60,7 @@ describe('compiler: transform ref', () => {
)
assert(
`<custom v-for="item in items" :ref="custom"/>`,
`<custom wx:for="{{a}}" wx:for-item="item" class="r-i-f" data-r="{{b}}" v-i="{{item.a}}"/>`,
`<custom wx:for="{{a}}" wx:for-item="item" class="r-i-f" data-r="{{b}}" u-i="{{item.a}}"/>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }), b: _ctx.custom }
}`,
......
......@@ -4,9 +4,9 @@ describe('compiler: transform scoped slots', () => {
test('basic', () => {
assert(
`<view><slot :item="item" :index="index"/></view>`,
`<view><slot name="default"/></view>`,
`<view><slot name="d"/></view>`,
`(_ctx, _cache) => {
return { a: _r("default", { item: _ctx.item, index: _ctx.index }) }
return { a: _r("d", { item: _ctx.item, index: _ctx.index }) }
}`
)
})
......
......@@ -13,7 +13,7 @@ describe('compiler: transform slot', () => {
test('fallback content', () => {
assert(
`<button><slot>Submit</slot></button>`,
`<button><block wx:if="{{$slots.default}}"><slot></slot></block><block wx:else>Submit</block></button>`,
`<button><block wx:if="{{$slots.d}}"><slot></slot></block><block wx:else>Submit</block></button>`,
`(_ctx, _cache) => {
return {}
}`
......@@ -42,7 +42,7 @@ describe('compiler: transform slot', () => {
`<slot v-for="(item,index) in items" :key="index"></slot>`,
`<slot wx:for="{{a}}" wx:for-item="item" name="{{item.a}}"></slot>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, index, i0) => { return { a: "default-" + i0, b: _r("default", { key: index }, i0) }; }) }
return { a: _f(_ctx.items, (item, index, i0) => { return { a: "d-" + i0, b: _r("d", { key: index }, i0) }; }) }
}`
)
})
......@@ -51,7 +51,7 @@ describe('compiler: transform slot', () => {
`<view v-for="(item,index) in items" :key="index"><slot v-for="(item1,index1) in item.list" :key="index1"></slot></view>`,
`<view wx:for="{{a}}" wx:for-item="item" wx:key="b"><slot wx:for="{{item.a}}" wx:for-item="item1" name="{{item1.a}}"></slot></view>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, index, i0) => { return { a: _f(item.list, (item1, index1, i1) => { return { a: "default-" + i0 + '-' + i1, b: _r("default", { key: index1 }, i0 + '-' + i1) }; }), b: index }; }) }
return { a: _f(_ctx.items, (item, index, i0) => { return { a: _f(item.list, (item1, index1, i1) => { return { a: "d-" + i0 + '-' + i1, b: _r("d", { key: index1 }, i0 + '-' + i1) }; }), b: index }; }) }
}`
)
})
......
......@@ -36,7 +36,7 @@ function assert(
}
assert(
`<template slot="left"/>`,
`<template v-for="item in items"><slot/></template>`,
`<slot wx:for="{{a}}" wx:for-item="item"></slot>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, index, i0) => { return { a: _r(\"default\", { key: index }) }; }) }
......
......@@ -4,7 +4,7 @@ describe('compiler: transform v-model', () => {
test(`component v-model`, () => {
assert(
`<Comp v-model="model" />`,
`<comp v-i="2a9ec0b0-0" modelValue="{{a}}" bindupdateModelValue="{{b}}"/>`,
`<comp u-i="2a9ec0b0-0" modelValue="{{a}}" bindupdateModelValue="{{b}}"/>`,
`(_ctx, _cache) => {
return { a: _ctx.model, b: _o($event => _ctx.model = $event) }
}`
......@@ -13,7 +13,7 @@ describe('compiler: transform v-model', () => {
test(`component v-model with cache`, () => {
assert(
`<Comp v-model="model" />`,
`<comp v-i="2a9ec0b0-0" modelValue="{{a}}" bindupdateModelValue="{{b}}"/>`,
`<comp u-i="2a9ec0b0-0" modelValue="{{a}}" bindupdateModelValue="{{b}}"/>`,
`(_ctx, _cache) => {
return { a: _ctx.model, b: _o($event => _ctx.model = $event) }
}`,
......
......@@ -27,7 +27,7 @@ describe('compiler: transform v-on', () => {
)
assert(
`<custom v-on:click="onClick"/>`,
`<custom bindclick="{{a}}" v-i="2a9ec0b0-0"/>`,
`<custom bindclick="{{a}}" u-i="2a9ec0b0-0"/>`,
`(_ctx, _cache) => {
return { a: _o(_ctx.onClick) }
}`
......
......@@ -4,14 +4,14 @@ describe('compiler: transform v-slot', () => {
test('default slot', () => {
assert(
`<custom><template v-slot/></custom>`,
`<custom v-s="{{['default']}}" v-i="2a9ec0b0-0"><view/></custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0"><view/></custom>`,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`<custom>test</custom>`,
`<custom v-s="{{['default']}}" v-i="2a9ec0b0-0">test</custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0">test</custom>`,
`(_ctx, _cache) => {
return {}
}`
......@@ -20,16 +20,16 @@ describe('compiler: transform v-slot', () => {
test('named slots', () => {
assert(
`<custom><template v-slot:header/><template v-slot:default/><template v-slot:footer/></custom>`,
`<custom v-s="{{['header','default','footer']}}" v-i="2a9ec0b0-0"><view slot="header"/><view slot="default"/><view slot="footer"/></custom>`,
`<custom u-s="{{['header','d','footer']}}" u-i="2a9ec0b0-0"><view slot="header"/><view slot="d"/><view slot="footer"/></custom>`,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`<unicloud-db v-slot:default="{data, loading, error, options}" collection=""><view v-if="error">{{error.message}}</view><view v-else></view></unicloud-db>`,
`<unicloud-db v-s="{{['default']}}" slot="default" collection="" v-i="2a9ec0b0-0"><view wx:for="{{a}}" wx:for-item="v0" wx:key="c" slot="{{v0.d}}"><view wx:if="{{v0.a}}">{{v0.b}}</view><view wx:else></view></view></unicloud-db>`,
`<unicloud-db u-s="{{['d']}}" slot="d" collection="" u-i="2a9ec0b0-0"><view wx:for="{{a}}" wx:for-item="v0" wx:key="c" slot="{{v0.d}}"><view wx:if="{{v0.a}}">{{v0.b}}</view><view wx:else></view></view></unicloud-db>`,
`(_ctx, _cache) => {
return { a: _w(({ data, loading, error, options }, s0, i0) => { return _e({ a: error }, error ? { b: _t(error.message) } : {}, { c: s0, d: i0 }); }, { name: 'default', vueId: '2a9ec0b0-0' }) }
return { a: _w(({ data, loading, error, options }, s0, i0) => { return _e({ a: error }, error ? { b: _t(error.message) } : {}, { c: s0, d: i0 }); }, { name: 'd', vueId: '2a9ec0b0-0' }) }
}`
)
})
......@@ -37,9 +37,9 @@ describe('compiler: transform v-slot', () => {
test('scoped slots', () => {
assert(
`<custom><template v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>`,
`<custom v-s="{{['default']}}" v-i="2a9ec0b0-0"><view slot="default"><view wx:for="{{a}}" wx:for-item="slotProps" wx:key="b" slot="{{slotProps.c}}"><view>{{slotProps.a}}</view></view></view></custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0"><view wx:for="{{a}}" wx:for-item="slotProps" wx:key="b" slot="{{slotProps.c}}"><view>{{slotProps.a}}</view></view></custom>`,
`(_ctx, _cache) => {
return { a: _w((slotProps, s0, i0) => { return { a: _t(slotProps.item), b: s0, c: i0 }; }, { name: 'default', vueId: '2a9ec0b0-0' }) }
return { a: _w((slotProps, s0, i0) => { return { a: _t(slotProps.item), b: s0, c: i0 }; }, { name: 'd', vueId: '2a9ec0b0-0' }) }
}`
)
})
......@@ -47,9 +47,9 @@ describe('compiler: transform v-slot', () => {
test('scoped slots + scoped slots', () => {
assert(
`<custom><template v-slot:default="slotProps"><custom1><template v-slot:default="slotProps1">{{ slotProps.item }}{{ slotProps1.item }}</template></custom1></template></custom>`,
`<custom v-s="{{['default']}}" v-i="2a9ec0b0-0"><view slot="default"><view wx:for="{{a}}" wx:for-item="slotProps" wx:key="d" slot="{{slotProps.e}}"><custom1 v-s="{{['default']}}" v-i="{{slotProps.c}}"><view slot="default"><view wx:for="{{slotProps.a}}" wx:for-item="slotProps1" wx:key="b" slot="{{slotProps1.c}}">{{slotProps.b}}{{slotProps1.a}}</view></view></custom1></view></view></custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0"><view wx:for="{{a}}" wx:for-item="slotProps" wx:key="d" slot="{{slotProps.e}}"><custom1 u-s="{{['d']}}" u-i="{{slotProps.c}}"><view wx:for="{{slotProps.a}}" wx:for-item="slotProps1" wx:key="b" slot="{{slotProps1.c}}">{{slotProps.b}}{{slotProps1.a}}</view></custom1></view></custom>`,
`(_ctx, _cache) => {
return { a: _w((slotProps, s0, i0) => { return { a: _w((slotProps1, s1, i1) => { return { a: _t(slotProps1.item), b: s1, c: i1 }; }, { name: 'default', vueId: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0' }), b: _t(slotProps.item), c: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0', d: s0, e: i0 }; }, { name: 'default', vueId: '2a9ec0b0-0' }) }
return { a: _w((slotProps, s0, i0) => { return { a: _w((slotProps1, s1, i1) => { return { a: _t(slotProps1.item), b: s1, c: i1 }; }, { name: 'd', vueId: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0' }), b: _t(slotProps.item), c: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0', d: s0, e: i0 }; }, { name: 'd', vueId: '2a9ec0b0-0' }) }
}`
)
})
......@@ -57,9 +57,9 @@ describe('compiler: transform v-slot', () => {
test('v-if + scoped slots', () => {
assert(
`<custom><template v-if="ok" v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>`,
`<custom v-s="{{['default']}}" v-i="2a9ec0b0-0"><view wx:if="{{a}}" slot="default"><view wx:for="{{b}}" wx:for-item="slotProps" wx:key="b" slot="{{slotProps.c}}"><view>{{slotProps.a}}</view></view></view></custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0"><block wx:if="{{a}}"><view wx:for="{{b}}" wx:for-item="slotProps" wx:key="b" slot="{{slotProps.c}}"><view>{{slotProps.a}}</view></view></block></custom>`,
`(_ctx, _cache) => {
return _e({ a: _ctx.ok }, _ctx.ok ? { b: _w((slotProps, s0, i0) => { return { a: _t(slotProps.item), b: s0, c: i0 }; }, { name: 'default', vueId: '2a9ec0b0-0' }) } : {})
return _e({ a: _ctx.ok }, _ctx.ok ? { b: _w((slotProps, s0, i0) => { return { a: _t(slotProps.item), b: s0, c: i0 }; }, { name: 'd', vueId: '2a9ec0b0-0' }) } : {})
}`
)
})
......@@ -67,9 +67,9 @@ describe('compiler: transform v-slot', () => {
test('v-for + scoped slots', () => {
assert(
`<custom v-for="item in items"><template v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>`,
`<custom wx:for="{{a}}" wx:for-item="item" v-s="{{['default']}}" v-i="{{item.b}}"><view slot="default"><view wx:for="{{item.a}}" wx:for-item="slotProps" wx:key="b" slot="{{slotProps.c}}"><view>{{slotProps.a}}</view></view></view></custom>`,
`<custom wx:for="{{a}}" wx:for-item="item" u-s="{{['d']}}" u-i="{{item.b}}"><view wx:for="{{item.a}}" wx:for-item="slotProps" wx:key="b" slot="{{slotProps.c}}"><view>{{slotProps.a}}</view></view></custom>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _w((slotProps, s1, i1) => { return { a: _t(slotProps.item), b: s1, c: i1 }; }, { name: 'default', vueId: '2a9ec0b0-0' + '-' + i0 }), b: '2a9ec0b0-0' + '-' + i0 }; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _w((slotProps, s1, i1) => { return { a: _t(slotProps.item), b: s1, c: i1 }; }, { name: 'd', vueId: '2a9ec0b0-0' + '-' + i0 }), b: '2a9ec0b0-0' + '-' + i0 }; }) }
}`
)
})
......@@ -77,9 +77,9 @@ describe('compiler: transform v-slot', () => {
test('v-for + v-for + scoped slots', () => {
assert(
`<view v-for="item in items"><custom v-for="item1 in item.list" :item="item1"><template v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom></view>`,
`<view wx:for="{{a}}" wx:for-item="item"><custom wx:for="{{item.a}}" wx:for-item="item1" v-s="{{['default']}}" item="{{item1.b}}" v-i="{{item1.c}}"><view slot="default"><view wx:for="{{item1.a}}" wx:for-item="slotProps" wx:key="b" slot="{{slotProps.c}}"><view>{{slotProps.a}}</view></view></view></custom></view>`,
`<view wx:for="{{a}}" wx:for-item="item"><custom wx:for="{{item.a}}" wx:for-item="item1" u-s="{{['d']}}" item="{{item1.b}}" u-i="{{item1.c}}"><view wx:for="{{item1.a}}" wx:for-item="slotProps" wx:key="b" slot="{{slotProps.c}}"><view>{{slotProps.a}}</view></view></custom></view>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _f(item.list, (item1, k1, i1) => { return { a: _w((slotProps, s2, i2) => { return { a: _t(slotProps.item), b: s2, c: i2 }; }, { name: 'default', vueId: '2a9ec0b0-0' + '-' + i0 + '-' + i1 }), b: item1, c: '2a9ec0b0-0' + '-' + i0 + '-' + i1 }; }) }; }) }
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _f(item.list, (item1, k1, i1) => { return { a: _w((slotProps, s2, i2) => { return { a: _t(slotProps.item), b: s2, c: i2 }; }, { name: 'd', vueId: '2a9ec0b0-0' + '-' + i0 + '-' + i1 }), b: item1, c: '2a9ec0b0-0' + '-' + i0 + '-' + i1 }; }) }; }) }
}`
)
})
......
import { hyphenate } from '@vue/shared'
import { SLOT_DEFAULT_NAME } from '@dcloudio/uni-shared'
import {
formatMiniProgramEvent,
MiniProgramCompilerOptions,
......@@ -23,6 +24,7 @@ import { genExpr } from '../codegen'
import { ForElementNode, isForElementNode } from '../transforms/vFor'
import { IfElementNode, isIfElementNode } from '../transforms/vIf'
import { findSlotName } from '../transforms/vSlot'
import { renameSlot } from '../transforms/utils'
interface TemplateCodegenContext {
code: string
directive: string
......@@ -146,7 +148,7 @@ function genSlot(node: SlotOutletNode, context: TemplateCodegenContext) {
`$slots.` +
(nameProp?.type === NodeTypes.ATTRIBUTE && nameProp.value?.content
? nameProp.value.content
: 'default'),
: SLOT_DEFAULT_NAME),
context
)
push(`>`)
......@@ -234,6 +236,17 @@ function genElement(node: ElementNode, context: TemplateCodegenContext) {
tag = 'block'
}
}
// 无用的 block
if (
tag === 'block' &&
props.length === 0 &&
!isIfElementNode(node) &&
!isForElementNode(node)
) {
return children.forEach((node) => {
genNode(node, context)
})
}
if (node.tagType === ElementTypes.COMPONENT) {
tag = hyphenate(tag)
}
......@@ -315,7 +328,7 @@ function genDirectiveNode(
) {
if (prop.name === 'slot') {
if (prop.arg) {
push(` slot="${(prop.arg as SimpleExpressionNode).content}"`)
push(` slot="${renameSlot((prop.arg as SimpleExpressionNode).content)}"`)
}
} else if (prop.name === 'show') {
push(` hidden="{{!${(prop.exp as SimpleExpressionNode).content}}}"`)
......
......@@ -13,19 +13,20 @@ import {
SimpleExpressionNode,
SlotOutletNode,
} from '@vue/compiler-core'
import { camelize } from '@vue/shared'
import { camelize, isString } from '@vue/shared'
import { SLOT_DEFAULT_NAME } from '@dcloudio/uni-shared'
import { RENDER_SLOT } from '../runtimeHelpers'
import { genExpr } from '../codegen'
import { isVForScope, TransformContext } from '../transform'
import { processProps } from './transformElement'
import { rewriteExpression } from './utils'
import { renameSlot, rewriteExpression } from './utils'
import {
createAttributeNode,
createBindDirectiveNode,
} from '@dcloudio/uni-cli-shared'
export function rewriteSlot(node: SlotOutletNode, context: TransformContext) {
let slotName: string | ExpressionNode = `"default"`
let slotName: string | ExpressionNode = `"${SLOT_DEFAULT_NAME}"`
let hasOtherDir = false
const nonNameProps: (AttributeNode | DirectiveNode)[] = []
const { props } = node
......@@ -76,7 +77,7 @@ export function rewriteSlot(node: SlotOutletNode, context: TransformContext) {
rewriteExpression(
createCompoundExpression([
context.helperString(RENDER_SLOT) + '(',
slotName,
renameSlot(isString(slotName) ? slotName : genExpr(slotName)),
',',
`{${properties.join(',')}}`,
`${slotKey ? ',' + slotKey : ''}`,
......@@ -105,13 +106,13 @@ function transformScopedSlotKey(
createBindDirectiveNode(
'name',
rewriteExpression(
createSimpleExpression('"default-"+' + slotKey),
createSimpleExpression(`"${SLOT_DEFAULT_NAME}-"+` + slotKey),
context
).content
)
)
} else {
props.push(createAttributeNode('name', 'default'))
props.push(createAttributeNode('name', SLOT_DEFAULT_NAME))
}
}
return slotKey
......
......@@ -13,6 +13,7 @@ import {
SpreadElement,
stringLiteral,
} from '@babel/types'
import { SLOT_DEFAULT_NAME } from '@dcloudio/uni-shared'
import {
createSimpleExpression,
ExpressionNode,
......@@ -26,11 +27,15 @@ import { isUndefined, parseExpr } from '../ast'
import { genBabelExpr, genExpr } from '../codegen'
import { CodegenScope } from '../options'
import { isVForScope, isVIfScope, TransformContext } from '../transform'
export const ATTR_VUE_ID = 'v-i'
export const ATTR_VUE_SLOTS = 'v-s'
// v-i,v-s 不能在 quickapp-webview 中使用,估计是内部处理成了指令之类的
export const ATTR_VUE_ID = 'u-i'
export const ATTR_VUE_SLOTS = 'u-s'
export const SCOPED_SLOT_IDENTIFIER = '__SCOPED_SLOT__'
export function renameSlot(name: string) {
return name === 'default' ? SLOT_DEFAULT_NAME : name
}
export function rewriteSpreadElement(
name: symbol,
expr: SpreadElement,
......
......@@ -25,6 +25,7 @@ import {
TemplateChildNode,
TemplateNode,
} from '@vue/compiler-core'
import { SLOT_DEFAULT_NAME } from '@dcloudio/uni-shared'
import {
createBindDirectiveNode,
isUserComponent,
......@@ -37,6 +38,7 @@ import { isVForScope, NodeTransform, TransformContext } from '../transform'
import {
ATTR_VUE_ID,
ATTR_VUE_SLOTS,
renameSlot,
rewriteExpressionWithoutProperty,
SCOPED_SLOT_IDENTIFIER,
} from './utils'
......@@ -85,12 +87,12 @@ export const transformSlot: NodeTransform = (node, context) => {
}
}
if (implicitDefaultChildren.length) {
slots.add('default')
slots.add(SLOT_DEFAULT_NAME)
}
if (onComponentSlot) {
// <unicloud-db v-slot:default="{data, loading, error, options}"/>
// => <unicloud-db collection=""><template v-slot:default="{data, loading, error, options}"/></unicloud-db>
slots.add('default')
slots.add(SLOT_DEFAULT_NAME)
const templateNode = createTemplateNode(
onComponentSlot,
implicitDefaultChildren
......@@ -103,7 +105,7 @@ export const transformSlot: NodeTransform = (node, context) => {
node.props.unshift(
createBindDirectiveNode(
ATTR_VUE_SLOTS,
`[${[...slots].map((name) => `'${name}'`).join(',')}]`
`[${[...slots].map((name) => `'${renameSlot(name)}'`).join(',')}]`
)
)
}
......@@ -137,6 +139,13 @@ function transformTemplateSlotElement(
context
),
]
if (context.miniProgram.slot.dynamicSlotNames) {
// 已经在 vFor 中补充 slot,故需要移除 slotTemplate 中的
const index = slotTemplate.props.indexOf(slotDir)
if (index > -1) {
slotTemplate.props.splice(index, 1)
}
}
// v-slot="slotProps" => v-slot 避免 transformIdentifier 生成 slotProps 的变量声明
slotDir.exp = undefined
return slotName
......@@ -161,7 +170,7 @@ function createTemplateNode(
export function findSlotName(slotDir: DirectiveNode) {
if (!slotDir.arg) {
return 'default'
return SLOT_DEFAULT_NAME
}
if (isStaticExp(slotDir.arg)) {
return slotDir.arg.content
......@@ -233,9 +242,11 @@ const slotNameRE = /\('(.*)',/
*/
function findCurrentSlotName(source: ExpressionNode) {
return stringLiteral(
((source as CompoundExpressionNode).children[1] as string).match(
slotNameRE
)![1]
renameSlot(
((source as CompoundExpressionNode).children[1] as string).match(
slotNameRE
)![1]
)
)
}
......
import { EventChannel, invokeArrayFns } from '@dcloudio/uni-shared'
import {
EventChannel,
invokeArrayFns,
SLOT_DEFAULT_NAME,
} from '@dcloudio/uni-shared'
import { capitalize, hasOwn, isArray } from '@vue/shared'
import { ComponentPublicInstance, ComponentInternalInstance } from 'vue'
import { getEventChannel } from '../../api/protocols/navigateTo'
......@@ -76,6 +80,9 @@ export function initBaseInstance(
} else {
delete slots.default
}
if (slots[SLOT_DEFAULT_NAME]) {
slots.default = true
}
return slots
}
},
......@@ -86,6 +93,9 @@ export function initBaseInstance(
options.slots.forEach((name) => {
instance.slots[name] = true as any
})
if (instance.slots[SLOT_DEFAULT_NAME]) {
instance.slots.default = true as any
}
}
}
......
......@@ -68,12 +68,12 @@ function initDefaultProps(isBehavior: boolean = false) {
value: '',
}
}
properties.vI = {
properties.uI = {
type: null, // 均不指定类型,避免 property received type-uncompatible value 警告
value: '',
}
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
properties.vS = {
properties.uS = {
type: null,
value: [],
observer: function (this: MPComponentInstance, newVal) {
......
......@@ -4,7 +4,7 @@ describe('mp-kuaishou: transform v-model', () => {
test(`component v-model`, () => {
assert(
`<Comp v-model="model" />`,
`<comp v-i="2a9ec0b0-0" bind:__l="__l" eO="{{a}}" modelValue="{{b}}" bindupdateModelValue="__e"/>`,
`<comp u-i="2a9ec0b0-0" bind:__l="__l" eO="{{a}}" modelValue="{{b}}" bindupdateModelValue="__e"/>`,
`(_ctx, _cache) => {
return { a: { 'updateModelValue': _o($event => _ctx.model = $event) }, b: _ctx.model }
}`
......@@ -13,7 +13,7 @@ describe('mp-kuaishou: transform v-model', () => {
test(`component v-model with cache`, () => {
assert(
`<Comp v-model="model" />`,
`<comp v-i="2a9ec0b0-0" bind:__l="__l" eO="{{a}}" modelValue="{{b}}" bindupdateModelValue="__e"/>`,
`<comp u-i="2a9ec0b0-0" bind:__l="__l" eO="{{a}}" modelValue="{{b}}" bindupdateModelValue="__e"/>`,
`(_ctx, _cache) => {
return { a: { 'updateModelValue': _o($event => _ctx.model = $event) }, b: _ctx.model }
}`,
......
......@@ -25,7 +25,7 @@ describe('mp-kuaishou: transform v-on', () => {
test(`built-in event`, () => {
assert(
`<custom @tap="tap"/>`,
`<custom bindtap="{{a}}" v-i="2a9ec0b0-0" bind:__l="__l"/>`,
`<custom bindtap="{{a}}" u-i="2a9ec0b0-0" bind:__l="__l"/>`,
`(_ctx, _cache) => {
return { a: _o(_ctx.tap) }
}`
......@@ -34,7 +34,7 @@ describe('mp-kuaishou: transform v-on', () => {
test(`custom event`, () => {
assert(
`<custom @click="click"/>`,
`<custom bindclick="__e" v-i="2a9ec0b0-0" bind:__l="__l" eO="{{a}}"/>`,
`<custom bindclick="__e" u-i="2a9ec0b0-0" bind:__l="__l" eO="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: { 'click': _o(_ctx.click) } }
}`
......@@ -43,7 +43,7 @@ describe('mp-kuaishou: transform v-on', () => {
test(`multi custom event`, () => {
assert(
`<custom @unmount="unmount" @custom-mount="mount();created();"/>`,
`<custom bindunmount="__e" bind:custom-mount="__e" v-i="2a9ec0b0-0" bind:__l="__l" eO="{{a}}"/>`,
`<custom bindunmount="__e" bind:custom-mount="__e" u-i="2a9ec0b0-0" bind:__l="__l" eO="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: { 'custom-mount': _o($event => { _ctx.mount(); _ctx.created(); }), 'unmount': _o(_ctx.unmount) } }
}`
......
......@@ -27,6 +27,8 @@ const invokeArrayFns = (fns, arg) => {
}
return ret;
};
// quickapp-webview 不能使用 default 作为插槽名称
const SLOT_DEFAULT_NAME = 'd';
// lifecycle
// App and Page
const ON_SHOW = 'onShow';
......@@ -161,6 +163,9 @@ function initBaseInstance(instance, options) {
options.slots.forEach((name) => {
instance.slots[name] = true;
});
if (instance.slots[SLOT_DEFAULT_NAME]) {
instance.slots.default = true;
}
}
}
ctx.getOpenerEventChannel = function () {
......@@ -473,12 +478,12 @@ function initDefaultProps(isBehavior = false) {
value: '',
};
}
properties.vI = {
properties.uI = {
type: null,
value: '',
};
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
properties.vS = {
properties.uS = {
type: null,
value: [],
observer: function (newVal) {
......@@ -741,7 +746,7 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) {
return {
attached() {
const properties = this.properties;
initVueIds(properties.vI, this);
initVueIds(properties.uI, this);
const relationOptions = {
vuePid: this._$vuePid,
};
......@@ -756,7 +761,7 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) {
}, {
mpType: isMiniProgramPage ? 'page' : 'component',
mpInstance,
slots: properties.vS,
slots: properties.uS,
parentComponent: relationOptions.parent && relationOptions.parent.$,
onBeforeSetup(instance, options) {
initRefs(instance, mpInstance);
......
......@@ -15,7 +15,9 @@
"uni-app": {
"name": "mp-kuaishou",
"title": "快手小程序",
"apply": "mp-kuaishou",
"apply": [
"mp-kuaishou"
],
"main": "dist/uni.compiler.js"
},
"gitHead": "7bcc3303c15141d377645a4995ce186f10ed6b78"
......
......@@ -138,6 +138,9 @@ const uniMiniProgramToutiaoPlugin = {
},
};
options.template.slot.fallbackContent = false;
// 飞书不支持:
// <view tt:for="{{items}}" tt:for-item="item" tt:key="id" slot="{{item.slot}}">{{item.text}}</view>
options.template.slot.dynamicSlotNames = false;
var index = [uniMiniProgramToutiaoPlugin, ...initMiniProgramPlugin__default["default"](options)];
module.exports = index;
......@@ -27,6 +27,8 @@ const invokeArrayFns = (fns, arg) => {
}
return ret;
};
// quickapp-webview 不能使用 default 作为插槽名称
const SLOT_DEFAULT_NAME = 'd';
// lifecycle
// App and Page
const ON_SHOW = 'onShow';
......@@ -157,6 +159,9 @@ function initBaseInstance(instance, options) {
options.slots.forEach((name) => {
instance.slots[name] = true;
});
if (instance.slots[SLOT_DEFAULT_NAME]) {
instance.slots.default = true;
}
}
}
ctx.getOpenerEventChannel = function () {
......@@ -443,12 +448,12 @@ function normalizePropType(type, defaultValue) {
function initDefaultProps(isBehavior = false) {
const properties = {};
if (!isBehavior) {
properties.vI = {
properties.uI = {
type: null,
value: '',
};
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
properties.vS = {
properties.uS = {
type: null,
value: [],
observer: function (newVal) {
......@@ -799,7 +804,7 @@ function initInjections(instance) {
function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
function attached() {
const properties = this.properties;
initVueIds(properties.vI, this);
initVueIds(properties.uI, this);
const relationOptions = {
vuePid: this._$vuePid,
};
......@@ -816,7 +821,7 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
}, {
mpType,
mpInstance,
slots: properties.vS,
slots: properties.uS,
parentComponent: relationOptions.parent && relationOptions.parent.$,
onBeforeSetup(instance, options) {
initRefs(instance, mpInstance);
......
......@@ -15,7 +15,9 @@
"uni-app": {
"name": "mp-lark",
"title": "飞书小程序",
"apply": "mp-lark",
"apply": [
"mp-lark"
],
"main": "dist/uni.compiler.js"
},
"gitHead": "7bcc3303c15141d377645a4995ce186f10ed6b78"
......
......@@ -20,5 +20,7 @@ const uniMiniProgramToutiaoPlugin: Plugin = {
}
options.template.slot.fallbackContent = false
// 飞书不支持:
// <view tt:for="{{items}}" tt:for-item="item" tt:key="id" slot="{{item.slot}}">{{item.text}}</view>
options.template.slot.dynamicSlotNames = false
export default [uniMiniProgramToutiaoPlugin, ...initMiniProgramPlugin(options)]
......@@ -2,8 +2,8 @@
"setting": {
"urlCheck": false,
"es6": true,
"postcss": false,
"minified": false,
"postcss": true,
"minified": true,
"newFeature": true
},
"appid": "testAppId",
......
......@@ -4,7 +4,7 @@ describe('mp-baidu: transform component', () => {
test(`match-media`, () => {
assert(
`<match-media/>`,
`<uni-match-media v-i="2a9ec0b0-0" bind:__l="__l"/>`,
`<uni-match-media u-i="2a9ec0b0-0" bind:__l="__l"/>`,
`(_ctx, _cache) => {
return {}
}`
......
......@@ -27,6 +27,8 @@ const invokeArrayFns = (fns, arg) => {
}
return ret;
};
// quickapp-webview 不能使用 default 作为插槽名称
const SLOT_DEFAULT_NAME = 'd';
// lifecycle
// App and Page
const ON_SHOW = 'onShow';
......@@ -157,6 +159,9 @@ function initBaseInstance(instance, options) {
options.slots.forEach((name) => {
instance.slots[name] = true;
});
if (instance.slots[SLOT_DEFAULT_NAME]) {
instance.slots.default = true;
}
}
}
ctx.getOpenerEventChannel = function () {
......@@ -435,12 +440,12 @@ function normalizePropType(type, defaultValue) {
function initDefaultProps(isBehavior = false) {
const properties = {};
if (!isBehavior) {
properties.vI = {
properties.uI = {
type: null,
value: '',
};
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
properties.vS = {
properties.uS = {
type: null,
value: [],
observer: function (newVal) {
......@@ -703,7 +708,7 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) {
return {
attached() {
const properties = this.properties;
initVueIds(properties.vI, this);
initVueIds(properties.uI, this);
const relationOptions = {
vuePid: this._$vuePid,
};
......@@ -718,7 +723,7 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) {
}, {
mpType: isMiniProgramPage ? 'page' : 'component',
mpInstance,
slots: properties.vS,
slots: properties.uS,
parentComponent: relationOptions.parent && relationOptions.parent.$,
onBeforeSetup(instance, options) {
initRefs(instance, mpInstance);
......
......@@ -15,7 +15,9 @@
"uni-app": {
"name": "mp-qq",
"title": "QQ小程序",
"apply": "mp-qq",
"apply": [
"mp-qq"
],
"main": "dist/uni.compiler.js"
},
"gitHead": "7bcc3303c15141d377645a4995ce186f10ed6b78"
......
......@@ -4,7 +4,7 @@ describe('mp-baidu: transform component', () => {
test(`match-media`, () => {
assert(
`<match-media/>`,
`<uni-match-media v-i="2a9ec0b0-0" bind:__l="__l"/>`,
`<uni-match-media u-i="2a9ec0b0-0" bind:__l="__l"/>`,
`(_ctx, _cache) => {
return {}
}`
......
......@@ -27,6 +27,8 @@ const invokeArrayFns = (fns, arg) => {
}
return ret;
};
// quickapp-webview 不能使用 default 作为插槽名称
const SLOT_DEFAULT_NAME = 'd';
// lifecycle
// App and Page
const ON_SHOW = 'onShow';
......@@ -157,6 +159,9 @@ function initBaseInstance(instance, options) {
options.slots.forEach((name) => {
instance.slots[name] = true;
});
if (instance.slots[SLOT_DEFAULT_NAME]) {
instance.slots.default = true;
}
}
}
ctx.getOpenerEventChannel = function () {
......@@ -438,12 +443,12 @@ function normalizePropType(type, defaultValue) {
function initDefaultProps(isBehavior = false) {
const properties = {};
if (!isBehavior) {
properties.vI = {
properties.uI = {
type: null,
value: '',
};
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
properties.vS = {
properties.uS = {
type: null,
value: [],
observer: function (newVal) {
......@@ -799,7 +804,7 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
}
function attached() {
const properties = this.properties;
initVueIds(properties.vI, this);
initVueIds(properties.uI, this);
const relationOptions = {
vuePid: this._$vuePid,
};
......@@ -816,7 +821,7 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
}, {
mpType,
mpInstance,
slots: properties.vS,
slots: properties.uS,
parentComponent: relationOptions.parent && relationOptions.parent.$,
onBeforeSetup(instance, options) {
initRefs(instance, mpInstance);
......
......@@ -15,7 +15,9 @@
"uni-app": {
"name": "mp-toutiao",
"title": "字节跳动小程序",
"apply": "mp-toutiao",
"apply": [
"mp-toutiao"
],
"main": "dist/uni.compiler.js"
},
"gitHead": "7bcc3303c15141d377645a4995ce186f10ed6b78"
......
......@@ -32,7 +32,7 @@ export function initLifetimes({
}
function attached(this: MPComponentInstance) {
const properties = this.properties
initVueIds(properties.vI, this)
initVueIds(properties.uI, this)
const relationOptions: RelationOptions = {
vuePid: this._$vuePid,
}
......@@ -53,7 +53,7 @@ export function initLifetimes({
{
mpType,
mpInstance,
slots: properties.vS, // vueSlots
slots: properties.uS, // vueSlots
parentComponent: relationOptions.parent && relationOptions.parent.$,
onBeforeSetup(
instance: ComponentInternalInstance,
......
......@@ -31,6 +31,11 @@ export interface UniMiniProgramPluginOptions {
windowOptionsMap?: Record<string, string>
tabBarOptionsMap?: Record<string, string>
tabBarItemOptionsMap?: Record<string, string>
formatAppJson?: (
appJson: Record<string, any>,
manifestJson: Record<string, any>,
pagesJson: Record<string, any>
) => void
}
app: {
darkmode: boolean
......
import path from 'path'
import { Plugin } from 'vite'
import { hasOwn } from '@vue/shared'
import {
defineUniManifestJsonPlugin,
getLocaleFiles,
......@@ -27,23 +27,28 @@ export function uniManifestJsonPlugin(
})
if (options.project) {
const template = options.project.source
let projectname = path.basename(inputDir)
if (projectname === 'src') {
projectname = path.basename(path.dirname(inputDir))
}
template.projectname = projectname
// TODO condition
if (process.env.UNI_AUTOMATOR_WS_ENDPOINT) {
if (!template.setting) {
template.setting = {}
if (hasOwn(template, 'appid')) {
let projectname = path.basename(inputDir)
if (projectname === 'src') {
projectname = path.basename(path.dirname(inputDir))
}
template.projectname = projectname
// TODO condition
if (process.env.UNI_AUTOMATOR_WS_ENDPOINT) {
if (!template.setting) {
template.setting = {}
}
template.setting.urlCheck = false
}
template.setting.urlCheck = false
projectJson = parseMiniProgramProjectJson(
code,
process.env.UNI_PLATFORM,
{ template }
)
} else {
// 无需解析,直接拷贝,如 quickapp-webview
projectJson = template
}
projectJson = parseMiniProgramProjectJson(
code,
process.env.UNI_PLATFORM,
{ template }
)
}
return {
......
......@@ -61,7 +61,9 @@ export function uniPagesJsonPlugin(
resolvedConfig,
nvuePages.map((pagePath) => pagePath + options.style.extname)
)
if (options.json?.formatAppJson) {
options.json.formatAppJson(appJson, manifestJson, pageJsons)
}
addMiniProgramAppJson(appJson)
Object.keys(pageJsons).forEach((name) => {
addMiniProgramPageJson(name, pageJsons[name])
......
......@@ -5018,7 +5018,7 @@ function vFor(source, renderItem) {
function renderSlot(name, props = {}, key) {
const instance = getCurrentInstance();
const vueIds = instance.attrs.vI;
const vueIds = instance.attrs.uI;
if (!vueIds) {
return;
}
......
......@@ -8,7 +8,7 @@ export function renderSlot(
key?: string | number
) {
const instance = getCurrentInstance() as ComponentInternalInstance
const vueIds = instance.attrs.vI as string
const vueIds = instance.attrs.uI as string
if (!vueIds) {
return
}
......
......@@ -27,6 +27,8 @@ const invokeArrayFns = (fns, arg) => {
}
return ret;
};
// quickapp-webview 不能使用 default 作为插槽名称
const SLOT_DEFAULT_NAME = 'd';
// lifecycle
// App and Page
const ON_SHOW = 'onShow';
......@@ -94,6 +96,9 @@ function initBaseInstance(instance, options) {
options.slots.forEach((name) => {
instance.slots[name] = true;
});
if (instance.slots[SLOT_DEFAULT_NAME]) {
instance.slots.default = true;
}
}
}
ctx.getOpenerEventChannel = function () {
......@@ -375,12 +380,12 @@ function normalizePropType(type, defaultValue) {
function initDefaultProps(isBehavior = false) {
const properties = {};
if (!isBehavior) {
properties.vI = {
properties.uI = {
type: null,
value: '',
};
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
properties.vS = {
properties.uS = {
type: null,
value: [],
observer: function (newVal) {
......@@ -643,7 +648,7 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) {
return {
attached() {
const properties = this.properties;
initVueIds(properties.vI, this);
initVueIds(properties.uI, this);
const relationOptions = {
vuePid: this._$vuePid,
};
......@@ -658,7 +663,7 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions, }) {
}, {
mpType: isMiniProgramPage ? 'page' : 'component',
mpInstance,
slots: properties.vS,
slots: properties.uS,
parentComponent: relationOptions.parent && relationOptions.parent.$,
onBeforeSetup(instance, options) {
initRefs(instance, mpInstance);
......
......@@ -19,7 +19,9 @@
"uni-app": {
"name": "mp-weixin",
"title": "微信小程序",
"apply": "mp-weixin",
"apply": [
"mp-weixin"
],
"main": "dist/uni.compiler.js"
},
"gitHead": "7bcc3303c15141d377645a4995ce186f10ed6b78"
......
......@@ -26,7 +26,7 @@ export function initLifetimes({
return {
attached(this: MPComponentInstance) {
const properties = this.properties
initVueIds(properties.vI, this)
initVueIds(properties.uI, this)
const relationOptions: RelationOptions = {
vuePid: this._$vuePid,
}
......@@ -44,7 +44,7 @@ export function initLifetimes({
{
mpType: isMiniProgramPage ? 'page' : 'component',
mpInstance,
slots: properties.vS, // vueSlots
slots: properties.uS, // vueSlots
parentComponent: relationOptions.parent && relationOptions.parent.$,
onBeforeSetup(
instance: ComponentInternalInstance,
......
{
"input": {
"src/runtime/index.ts": "dist/uni.mp.esm.js",
"src/api/index.ts": "dist/uni.api.esm.js"
},
"alias": {
"entries": [
{
"find": "@dcloudio/uni-platform",
"replacement": "packages/uni-quickapp-webview/src/platform/index.ts"
},
{
"find": "@dcloudio/uni-mp-platform",
"replacement": "packages/uni-mp-core/src/platform/index.ts"
}
[
{
"input": {
"src/compiler/index.ts": "dist/uni.compiler.js"
},
"output": {
"format": "cjs"
},
"external": [
"@vue/compiler-core",
"@dcloudio/uni-shared",
"@dcloudio/uni-cli-shared",
"@dcloudio/uni-mp-vite",
"@dcloudio/uni-mp-compiler"
]
},
"replacements": {
"__GLOBAL__": "qa",
"__PLATFORM__": "\"quickapp-webview\"",
"__PLATFORM_TITLE__": "快应用(Webview)版"
},
"external": ["@dcloudio/uni-i18n", "@vue/shared", "vue"]
}
{
"input": {
"src/runtime/index.ts": "dist/uni.mp.esm.js",
"src/api/index.ts": "dist/uni.api.esm.js"
},
"alias": {
"entries": [
{
"find": "@dcloudio/uni-platform",
"replacement": "packages/uni-quickapp-webview/src/platform/index.ts"
},
{
"find": "@dcloudio/uni-mp-platform",
"replacement": "packages/uni-mp-core/src/platform/index.ts"
}
]
},
"replacements": {
"__GLOBAL__": "qa",
"__PLATFORM__": "\"quickapp-webview\"",
"__PLATFORM_TITLE__": "快应用(Webview)版"
},
"external": ["@dcloudio/uni-i18n", "@vue/shared", "vue"]
}
]
'use strict';
var uniCliShared = require('@dcloudio/uni-cli-shared');
var initMiniProgramPlugin = require('@dcloudio/uni-mp-vite');
var path = require('path');
var uniShared = require('@dcloudio/uni-shared');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var initMiniProgramPlugin__default = /*#__PURE__*/_interopDefaultLegacy(initMiniProgramPlugin);
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
var compilerOptions$1 = {
target: "es6",
module: "commonjs"
};
var source = {
compilerOptions: compilerOptions$1
};
/**
* Make a map and return a function for checking if a key
* is in that map.
* IMPORTANT: all calls of this function must be prefixed with
* \/\*#\_\_PURE\_\_\*\/
* So that rollup can tree-shake them if necessary.
*/
(process.env.NODE_ENV !== 'production')
? Object.freeze({})
: {};
(process.env.NODE_ENV !== 'production') ? Object.freeze([]) : [];
const extend = Object.assign;
const hasOwnProperty = Object.prototype.hasOwnProperty;
const hasOwn = (val, key) => hasOwnProperty.call(val, key);
const properties = ['name', 'versionName', 'versionCode'];
function formatAppJson(_appJson, manifestJson, _pagesJson) {
const appJson = _appJson;
// 华为IDE V3.0.2+ 需要此属性,否则无法导入
appJson.appType = 'webapp';
appJson.minPlatformVersion = 1070;
properties.forEach((name) => {
if (hasOwn(manifestJson, name)) {
appJson[name] = manifestJson[name];
}
});
if (!appJson.name) {
const inputDir = process.env.UNI_INPUT_DIR;
let projectname = path__default["default"].basename(inputDir);
if (projectname === 'src') {
projectname = path__default["default"].basename(path__default["default"].dirname(inputDir));
}
appJson.name = projectname;
}
if (!appJson.package) {
appJson.package = appJson.name;
}
if (manifestJson['quickapp-webview']) {
extend(appJson, manifestJson['quickapp-webview']);
}
if (process.env.UNI_SUB_PLATFORM &&
manifestJson[process.env.UNI_SUB_PLATFORM]) {
extend(appJson, manifestJson[process.env.UNI_SUB_PLATFORM]);
}
if (!appJson.package) {
console.warn('manifest.json->quickapp-webview 缺少 package 配置');
}
if (!appJson.icon) {
console.warn('manifest.json->quickapp-webview 缺少 icon 配置');
}
}
const compilerOptions = {
isNativeTag: uniShared.isNativeTag,
isCustomElement: uniShared.isCustomElement,
nodeTransforms: [uniCliShared.transformRef, uniCliShared.transformComponentLink],
};
const miniProgram = {
class: {
array: true,
},
slot: {
fallbackContent: true,
dynamicSlotNames: true,
},
directive: 'qa:',
};
const projectConfigFilename = 'jsconfig.json';
const options = {
vite: {
inject: {
uni: [path__default["default"].resolve(__dirname, 'uni.api.esm.js'), 'default'],
},
alias: {
'uni-mp-runtime': path__default["default"].resolve(__dirname, 'uni.mp.esm.js'),
},
copyOptions: {},
},
global: 'qa',
app: {
darkmode: false,
subpackages: true,
},
json: {
formatAppJson,
},
template: Object.assign(Object.assign({}, miniProgram), { filter: {
extname: '.qjs',
lang: 'qjs',
generate(filter, filename) {
if (filename) {
return `<qjs src="${filename}.qjs" module="${filter.name}"/>`;
}
return `<qjs module="${filter.name}">
${filter.code}
</qjs>`;
},
}, extname: '.qxml', compilerOptions }),
style: {
extname: '.css',
},
project: {
filename: projectConfigFilename,
source,
},
};
const uniQuickappWebviewPlugin = {
name: 'vite:uni-quickapp-webview',
config() {
return {
define: {
__VUE_CREATED_DEFERRED__: true,
},
build: {
// css 中不支持引用本地资源
assetsInlineLimit: uniCliShared.ASSETS_INLINE_LIMIT,
},
};
},
};
var index = [uniQuickappWebviewPlugin, ...initMiniProgramPlugin__default["default"](options)];
module.exports = index;
......@@ -27,6 +27,8 @@ const invokeArrayFns = (fns, arg) => {
}
return ret;
};
// quickapp-webview 不能使用 default 作为插槽名称
const SLOT_DEFAULT_NAME = 'd';
// lifecycle
// App and Page
const ON_SHOW = 'onShow';
......@@ -157,6 +159,9 @@ function initBaseInstance(instance, options) {
options.slots.forEach((name) => {
instance.slots[name] = true;
});
if (instance.slots[SLOT_DEFAULT_NAME]) {
instance.slots.default = true;
}
}
}
ctx.getOpenerEventChannel = function () {
......@@ -416,12 +421,12 @@ function normalizePropType(type, defaultValue) {
function initDefaultProps(isBehavior = false) {
const properties = {};
if (!isBehavior) {
properties.vI = {
properties.uI = {
type: null,
value: '',
};
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
properties.vS = {
properties.uS = {
type: null,
value: [],
observer: function (newVal) {
......@@ -768,7 +773,7 @@ function initInjections(instance) {
function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
function attached() {
const properties = this.properties;
initVueIds(properties.vI, this);
initVueIds(properties.uI, this);
const relationOptions = {
vuePid: this._$vuePid,
};
......@@ -785,7 +790,7 @@ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
}, {
mpType,
mpInstance,
slots: properties.vS,
slots: properties.uS,
parentComponent: relationOptions.parent && relationOptions.parent.$,
onBeforeSetup(instance, options) {
initRefs(instance, mpInstance);
......
......@@ -14,7 +14,11 @@
"license": "Apache-2.0",
"uni-app": {
"name": "quickapp-webview",
"title": "快应用(Webview)版"
"title": "快应用(Webview)版",
"apply": [
"quickapp-webview"
],
"main": "dist/uni.compiler.js"
},
"gitHead": "7bcc3303c15141d377645a4995ce186f10ed6b78"
}
import { Plugin } from 'vite'
import { ASSETS_INLINE_LIMIT } from '@dcloudio/uni-cli-shared'
import initMiniProgramPlugin from '@dcloudio/uni-mp-vite'
import { options } from './options'
const uniQuickappWebviewPlugin: Plugin = {
name: 'vite:uni-quickapp-webview',
config() {
return {
define: {
__VUE_CREATED_DEFERRED__: true,
},
build: {
// css 中不支持引用本地资源
assetsInlineLimit: ASSETS_INLINE_LIMIT,
},
}
},
}
export default [uniQuickappWebviewPlugin, ...initMiniProgramPlugin(options)]
{
"compilerOptions": {
"target": "es6",
"module": "commonjs"
}
}
\ No newline at end of file
import path from 'path'
import type { CompilerOptions } from '@vue/compiler-core'
import { isNativeTag, isCustomElement } from '@dcloudio/uni-shared'
import {
MiniProgramCompilerOptions,
transformComponentLink,
transformRef,
} from '@dcloudio/uni-cli-shared'
import { UniMiniProgramPluginOptions } from '@dcloudio/uni-mp-vite'
import source from './jsconfig.json'
import { formatAppJson } from './utils'
export const compilerOptions: CompilerOptions = {
isNativeTag,
isCustomElement,
nodeTransforms: [transformRef, transformComponentLink],
}
export const miniProgram: MiniProgramCompilerOptions = {
class: {
array: true,
},
slot: {
fallbackContent: true,
dynamicSlotNames: true,
},
directive: 'qa:',
}
const projectConfigFilename = 'jsconfig.json'
export const options: UniMiniProgramPluginOptions = {
vite: {
inject: {
uni: [path.resolve(__dirname, 'uni.api.esm.js'), 'default'],
},
alias: {
'uni-mp-runtime': path.resolve(__dirname, 'uni.mp.esm.js'),
},
copyOptions: {},
},
global: 'qa',
app: {
darkmode: false,
subpackages: true,
},
json: {
formatAppJson,
},
template: {
/* eslint-disable no-restricted-syntax */
...miniProgram,
filter: {
extname: '.qjs',
lang: 'qjs',
generate(filter, filename) {
if (filename) {
return `<qjs src="${filename}.qjs" module="${filter.name}"/>`
}
return `<qjs module="${filter.name}">
${filter.code}
</qjs>`
},
},
extname: '.qxml',
compilerOptions,
},
style: {
extname: '.css',
},
project: {
filename: projectConfigFilename,
source,
},
}
{
"description": "项目配置文件。",
"packOptions": {
"ignore": []
},
"setting": {
"urlCheck": false,
"es6": true,
"postcss": false,
"minified": false,
"newFeature": true
},
"compileType": "miniprogram",
"libVersion": "",
"appid": "touristappid",
"projectname": "",
"condition": {
"search": {
"current": -1,
"list": []
},
"conversation": {
"current": -1,
"list": []
},
"game": {
"current": -1,
"list": []
},
"miniprogram": {
"current": -1,
"list": []
}
}
}
import path from 'path'
import { extend, hasOwn } from '@vue/shared'
interface AppJson {
appType: 'webapp'
minPlatformVersion: 1070
name: string
package: string
versionName: string
versionCode: string
}
const properties = ['name', 'versionName', 'versionCode']
export function formatAppJson(
_appJson: Record<string, any>,
manifestJson: Record<string, any>,
_pagesJson: Record<string, any>
) {
const appJson = _appJson as AppJson & Record<string, any>
// 华为IDE V3.0.2+ 需要此属性,否则无法导入
appJson.appType = 'webapp'
appJson.minPlatformVersion = 1070
properties.forEach((name) => {
if (hasOwn(manifestJson, name)) {
appJson[name] = manifestJson[name]
}
})
if (!appJson.name) {
const inputDir = process.env.UNI_INPUT_DIR
let projectname = path.basename(inputDir)
if (projectname === 'src') {
projectname = path.basename(path.dirname(inputDir))
}
appJson.name = projectname
}
if (!appJson.package) {
appJson.package = appJson.name
}
if (manifestJson['quickapp-webview']) {
extend(appJson, manifestJson['quickapp-webview'])
}
if (
process.env.UNI_SUB_PLATFORM &&
manifestJson[process.env.UNI_SUB_PLATFORM]
) {
extend(appJson, manifestJson[process.env.UNI_SUB_PLATFORM])
}
if (!appJson.package) {
console.warn('manifest.json->quickapp-webview 缺少 package 配置')
}
if (!appJson.icon) {
console.warn('manifest.json->quickapp-webview 缺少 icon 配置')
}
}
import { ComponentPublicInstance } from 'vue'
import { MPComponentInstance } from '@dcloudio/uni-mp-core'
import {
......@@ -23,7 +24,7 @@ export function initRelation(mpInstance: MPComponentInstance) {
// triggerEvent 后,接收事件时机特别晚,已经到了 ready 之后
const nodeId = mpInstance.nodeId + ''
const webviewId = (mpInstance as any).pageinstance.__pageId__ + ''
instances[webviewId + '_' + nodeId] = mpInstance.$vm
instances[webviewId + '_' + nodeId] = mpInstance.$vm!
mpInstance.triggerEvent('__l', {
nodeId,
webviewId,
......@@ -38,13 +39,19 @@ export function handleLink(
detail: RelationOptions
}
) {
const vm = instances[webviewId + '_' + nodeId]
const vm = instances[webviewId + '_' + nodeId] as ComponentPublicInstance & {
_$childVues?: [Function, Function][]
}
if (!vm) {
return
}
let parentVm = instances[webviewId + '_' + vm.$scope.ownerId]
let parentVm = instances[
webviewId + '_' + (vm.$scope as any).ownerId
] as ComponentPublicInstance & {
_$childVues?: [Function, Function][]
}
if (!parentVm) {
parentVm = this.$vm
parentVm = this.$vm!
}
vm.$.parent = parentVm.$
......@@ -53,7 +60,7 @@ export function handleLink(
if (__VUE_OPTIONS_API__) {
;(parentVm as any).$children.push(vm)
const parent = parentVm.$ as any
vm.$.provides = parent
;(vm.$ as any).provides = parent
? parent.provides
: Object.create(parent.appContext.provides)
initInjections(vm)
......@@ -64,8 +71,8 @@ export function handleLink(
const mountedVm = function () {
// 处理当前 vm 子
if (vm._$childVues) {
vm._$childVues.forEach(([createdVm]: Function[]) => createdVm())
vm._$childVues.forEach(([, mountedVm]: Function[]) => mountedVm())
vm._$childVues.forEach(([createdVm]) => createdVm())
vm._$childVues.forEach(([, mountedVm]) => mountedVm())
delete vm._$childVues
}
vm.$callHook('mounted')
......
......@@ -973,6 +973,8 @@ const NAVBAR_HEIGHT = 44;
const TABBAR_HEIGHT = 50;
const ON_REACH_BOTTOM_DISTANCE = 50;
const RESPONSIVE_MIN_WIDTH = 768;
// quickapp-webview 不能使用 default 作为插槽名称
const SLOT_DEFAULT_NAME = 'd';
const COMPONENT_NAME_PREFIX = 'VUni';
const I18N_JSON_DELIMITERS = ['%', '%'];
const PRIMARY_COLOR = '#007aff';
......@@ -1207,6 +1209,7 @@ exports.RENDERJS_MODULES = RENDERJS_MODULES;
exports.RESPONSIVE_MIN_WIDTH = RESPONSIVE_MIN_WIDTH;
exports.SCHEME_RE = SCHEME_RE;
exports.SELECTED_COLOR = SELECTED_COLOR;
exports.SLOT_DEFAULT_NAME = SLOT_DEFAULT_NAME;
exports.TABBAR_HEIGHT = TABBAR_HEIGHT;
exports.TAGS = TAGS;
exports.UNI_SSR = UNI_SSR;
......
......@@ -460,6 +460,8 @@ number,
string | number
];
export declare const SLOT_DEFAULT_NAME = "d";
export declare function stringifyQuery(obj?: Record<string, any>, encodeStr?: typeof encodeURIComponent): string;
export declare const TABBAR_HEIGHT = 50;
......
......@@ -969,6 +969,8 @@ const NAVBAR_HEIGHT = 44;
const TABBAR_HEIGHT = 50;
const ON_REACH_BOTTOM_DISTANCE = 50;
const RESPONSIVE_MIN_WIDTH = 768;
// quickapp-webview 不能使用 default 作为插槽名称
const SLOT_DEFAULT_NAME = 'd';
const COMPONENT_NAME_PREFIX = 'VUni';
const I18N_JSON_DELIMITERS = ['%', '%'];
const PRIMARY_COLOR = '#007aff';
......@@ -1130,4 +1132,4 @@ function getEnvLocale() {
return (lang && lang.replace(/[.:].*/, '')) || 'en';
}
export { ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_CREATE, ACTION_TYPE_EVENT, ACTION_TYPE_INSERT, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_REMOVE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ATTR_CHANGE_PREFIX, ATTR_CLASS, ATTR_INNER_HTML, ATTR_STYLE, ATTR_TEXT_CONTENT, ATTR_V_OWNER_ID, ATTR_V_RENDERJS, ATTR_V_SHOW, BACKGROUND_COLOR, BUILT_IN_TAGS, COMPONENT_NAME_PREFIX, COMPONENT_PREFIX, COMPONENT_SELECTOR_PREFIX, DATA_RE, EventChannel, EventModifierFlags, I18N_JSON_DELIMITERS, JSON_PROTOCOL, LINEFEED, NAVBAR_HEIGHT, NODE_TYPE_COMMENT, NODE_TYPE_ELEMENT, NODE_TYPE_PAGE, NODE_TYPE_TEXT, ON_ADD_TO_FAVORITES, ON_APP_ENTER_BACKGROUND, ON_APP_ENTER_FOREGROUND, ON_BACK_PRESS, ON_ERROR, ON_HIDE, ON_KEYBOARD_HEIGHT_CHANGE, ON_LAUNCH, ON_LOAD, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_PAGE_NOT_FOUND, ON_PAGE_SCROLL, ON_PULL_DOWN_REFRESH, ON_REACH_BOTTOM, ON_REACH_BOTTOM_DISTANCE, ON_READY, ON_RESIZE, ON_SHARE_APP_MESSAGE, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, ON_THEME_CHANGE, ON_UNHANDLE_REJECTION, ON_UNLOAD, ON_WEB_INVOKE_APP_SERVICE, ON_WXS_INVOKE_CALL_METHOD, PLUS_RE, PRIMARY_COLOR, RENDERJS_MODULES, RESPONSIVE_MIN_WIDTH, SCHEME_RE, SELECTED_COLOR, TABBAR_HEIGHT, TAGS, UNI_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR_STORE, UNI_SSR_TITLE, UniBaseNode, UniCommentNode, UniElement, UniEvent, UniInputElement, UniLifecycleHooks, UniNode, UniTextAreaElement, UniTextNode, WEB_INVOKE_APPSERVICE, WXS_MODULES, WXS_PROTOCOL, addFont, cache, cacheStringFunction, callOptions, createRpx2Unit, createUniEvent, debounce, decode, decodedQuery, defaultMiniProgramRpx2Unit, defaultRpx2Unit, formatAppLog, formatDateTime, formatLog, getCustomDataset, getDataByPath, getEnvLocale, getLen, getValueByDataPath, initCustomDataset, invokeArrayFns, isBuiltInComponent, isComponentTag, isCustomElement, isH5CustomElement, isH5NativeTag, isNativeTag, isRootHook, normalizeDataset, normalizeEventType, normalizeTarget, once, parseEventName, parseQuery, parseUrl, passive, plusReady, removeLeadingSlash, resolveOwnerEl, resolveOwnerVm, sanitise, scrollTo, stringifyQuery, updateElementStyle };
export { ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_CREATE, ACTION_TYPE_EVENT, ACTION_TYPE_INSERT, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_REMOVE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ATTR_CHANGE_PREFIX, ATTR_CLASS, ATTR_INNER_HTML, ATTR_STYLE, ATTR_TEXT_CONTENT, ATTR_V_OWNER_ID, ATTR_V_RENDERJS, ATTR_V_SHOW, BACKGROUND_COLOR, BUILT_IN_TAGS, COMPONENT_NAME_PREFIX, COMPONENT_PREFIX, COMPONENT_SELECTOR_PREFIX, DATA_RE, EventChannel, EventModifierFlags, I18N_JSON_DELIMITERS, JSON_PROTOCOL, LINEFEED, NAVBAR_HEIGHT, NODE_TYPE_COMMENT, NODE_TYPE_ELEMENT, NODE_TYPE_PAGE, NODE_TYPE_TEXT, ON_ADD_TO_FAVORITES, ON_APP_ENTER_BACKGROUND, ON_APP_ENTER_FOREGROUND, ON_BACK_PRESS, ON_ERROR, ON_HIDE, ON_KEYBOARD_HEIGHT_CHANGE, ON_LAUNCH, ON_LOAD, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_PAGE_NOT_FOUND, ON_PAGE_SCROLL, ON_PULL_DOWN_REFRESH, ON_REACH_BOTTOM, ON_REACH_BOTTOM_DISTANCE, ON_READY, ON_RESIZE, ON_SHARE_APP_MESSAGE, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, ON_THEME_CHANGE, ON_UNHANDLE_REJECTION, ON_UNLOAD, ON_WEB_INVOKE_APP_SERVICE, ON_WXS_INVOKE_CALL_METHOD, PLUS_RE, PRIMARY_COLOR, RENDERJS_MODULES, RESPONSIVE_MIN_WIDTH, SCHEME_RE, SELECTED_COLOR, SLOT_DEFAULT_NAME, TABBAR_HEIGHT, TAGS, UNI_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR_STORE, UNI_SSR_TITLE, UniBaseNode, UniCommentNode, UniElement, UniEvent, UniInputElement, UniLifecycleHooks, UniNode, UniTextAreaElement, UniTextNode, WEB_INVOKE_APPSERVICE, WXS_MODULES, WXS_PROTOCOL, addFont, cache, cacheStringFunction, callOptions, createRpx2Unit, createUniEvent, debounce, decode, decodedQuery, defaultMiniProgramRpx2Unit, defaultRpx2Unit, formatAppLog, formatDateTime, formatLog, getCustomDataset, getDataByPath, getEnvLocale, getLen, getValueByDataPath, initCustomDataset, invokeArrayFns, isBuiltInComponent, isComponentTag, isCustomElement, isH5CustomElement, isH5NativeTag, isNativeTag, isRootHook, normalizeDataset, normalizeEventType, normalizeTarget, once, parseEventName, parseQuery, parseUrl, passive, plusReady, removeLeadingSlash, resolveOwnerEl, resolveOwnerVm, sanitise, scrollTo, stringifyQuery, updateElementStyle };
......@@ -4,6 +4,9 @@ export const TABBAR_HEIGHT = 50
export const ON_REACH_BOTTOM_DISTANCE = 50
export const RESPONSIVE_MIN_WIDTH = 768
// quickapp-webview 不能使用 default 作为插槽名称
export const SLOT_DEFAULT_NAME = 'd'
export const COMPONENT_NAME_PREFIX = 'VUni'
export const I18N_JSON_DELIMITERS: [string, string] = ['%', '%']
......
......@@ -17,6 +17,7 @@ export const PLATFORMS = [
'mp-lark',
'mp-toutiao',
'mp-weixin',
'quickapp-webview',
'quickapp-webview-huawei',
'quickapp-webview-union',
]
......@@ -59,6 +60,14 @@ export function initEnv(type: 'dev' | 'build', options: CliOptions) {
if (options.platform === 'app-plus') {
options.platform = 'app'
}
if (
options.platform === 'quickapp-webview-huawei' ||
options.platform === 'quickapp-webview-union'
) {
process.env.UNI_SUB_PLATFORM = options.platform
options.platform = 'quickapp-webview'
}
process.env.UNI_PLATFORM = options.platform as UniApp.PLATFORM
process.env.VITE_ROOT_DIR = process.env.UNI_INPUT_DIR || process.cwd()
......@@ -74,7 +83,7 @@ export function initEnv(type: 'dev' | 'build', options: CliOptions) {
process.cwd(),
'dist',
process.env.NODE_ENV === 'production' ? 'build' : 'dev',
process.env.UNI_PLATFORM
process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM
)
}
process.env.UNI_OUTPUT_DIR = (options as BuildOptions).outDir!
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册