From 8a3403f8a0b92735513a16eaf7e17ee430c665cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BA=9A=E7=90=AA?= Date: Thu, 2 Jan 2025 16:01:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(mp):=20=E4=BF=AE=E5=A4=8DvirtualHostId?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=94=99=E8=AF=AF=E3=80=81=E5=87=8F=E5=B0=8F?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E4=BA=A7=E7=89=A9=E4=BD=93=E7=A7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mergeVirtualHostAttributes.spec.ts | 100 +++++++++--------- .../__tests__/uniElement.spec.ts | 8 +- .../uni-mp-compiler/src/runtimeHelpers.ts | 2 + .../src/transforms/transformId.ts | 73 +++---------- .../src/transforms/transformUniElement.ts | 37 +++++-- packages/uni-mp-vue/src/helpers/id.ts | 37 +++++-- packages/uni-mp-vue/src/helpers/index.ts | 4 +- 7 files changed, 129 insertions(+), 132 deletions(-) diff --git a/packages/uni-mp-compiler/__tests__/mergeVirtualHostAttributes.spec.ts b/packages/uni-mp-compiler/__tests__/mergeVirtualHostAttributes.spec.ts index 5814dea8271..da9eab9913d 100644 --- a/packages/uni-mp-compiler/__tests__/mergeVirtualHostAttributes.spec.ts +++ b/packages/uni-mp-compiler/__tests__/mergeVirtualHostAttributes.spec.ts @@ -18,17 +18,17 @@ describe('complier: options with mergeVirtualHostAttributes', () => { test('root node with mergeVirtualHostAttributes', () => { assert( ``, - ``, + ``, `(_ctx, _cache) => { - return {} + return { a: _gei(_ctx, '') } }`, options ) assert( ``, - ``, + ``, `(_ctx, _cache) => { - return {} + return { a: _gei(_ctx, '') } }`, options ) @@ -36,7 +36,7 @@ describe('complier: options with mergeVirtualHostAttributes', () => { ``, ``, `(_ctx, _cache) => { - const __returned__ = { a: _sei('r0-2a9ec0b0', 'image', 'img'), b: _s(_ses('r0-2a9ec0b0')), c: _sei(_ctx.virtualHostId !== '' ? _ctx.virtualHostId : 'r1-2a9ec0b0', 'view', 'page'), d: _s(_ses(_ctx.virtualHostId !== '' ? _ctx.virtualHostId : 'r1-2a9ec0b0')) } + const __returned__ = { a: _sei('r0-2a9ec0b0', 'image', 'img'), b: _s(_ses('r0-2a9ec0b0')), c: _sei(_gei(_ctx, '', 'r1-2a9ec0b0'), 'view', 'page'), d: _s(_ses(_gei(_ctx, '', 'r1-2a9ec0b0'))) } return __returned__ }`, optionsX @@ -45,25 +45,25 @@ describe('complier: options with mergeVirtualHostAttributes', () => { test('root node style with mergeVirtualHostAttributes', () => { assert( ``, - ``, + ``, `(_ctx, _cache) => { - return {} + return { a: _gei(_ctx, '') } }`, options ) assert( ``, - ``, + ``, `(_ctx, _cache) => { - return { a: _s(_ctx.style) } + return { a: _s(_ctx.style), b: _gei(_ctx, '') } }`, options ) assert( ``, - ``, + ``, `(_ctx, _cache) => { - return { a: _s(_ctx.style) } + return { a: _s(_ctx.style), b: _gei(_ctx, '') } }`, options ) @@ -71,25 +71,25 @@ describe('complier: options with mergeVirtualHostAttributes', () => { test('root node class with mergeVirtualHostAttributes', () => { assert( ``, - ``, + ``, `(_ctx, _cache) => { - return {} + return { a: _gei(_ctx, '') } }`, options ) assert( ``, - ``, + ``, `(_ctx, _cache) => { - return { a: _n(_ctx.class1) } + return { a: _n(_ctx.class1), b: _gei(_ctx, '') } }`, options ) assert( ``, - ``, + ``, `(_ctx, _cache) => { - return { a: _n(_ctx.class1) } + return { a: _n(_ctx.class1), b: _gei(_ctx, '') } }`, options ) @@ -97,41 +97,41 @@ describe('complier: options with mergeVirtualHostAttributes', () => { test('root node hidden with mergeVirtualHostAttributes', () => { assert( ``, - ``, + ``, `(_ctx, _cache) => { - return { a: _ctx.hidden } + return { a: _ctx.hidden, b: _gei(_ctx, '') } }`, options ) assert( ``, - ``, + ``, `(_ctx, _cache) => { - return { a: !_ctx.show } + return { a: !_ctx.show, b: _gei(_ctx, '') } }`, options ) assert( ``, - ``, + ``, `(_ctx, _cache) => { - return {} + return { a: _gei(_ctx, '') } }`, options ) assert( ``, - ``, + ``, `(_ctx, _cache) => { - return {} + return { a: _gei(_ctx, '') } }`, options ) assert( ``, - ``, + ``, `(_ctx, _cache) => { - return { a: _ctx.show } + return { a: _ctx.show, b: _gei(_ctx, '') } }`, options ) @@ -139,25 +139,25 @@ describe('complier: options with mergeVirtualHostAttributes', () => { test('root node id with mergeVirtualHostAttributes', () => { assert( ``, - ``, + ``, `(_ctx, _cache) => { - return { a: 'id' in _ctx.$.type.props } + return { a: _gei(_ctx, 'id1') } }`, options ) assert( ``, - ``, + ``, `(_ctx, _cache) => { - return { a: _ctx.id1, b: 'id' in _ctx.$.type.props } + return { a: _gei(_ctx, _ctx.id1) } }`, options ) assert( ``, - ``, + ``, `(_ctx, _cache) => { - return { a: 'id' in _ctx.$.type.props } + return { a: _gei(_ctx, 'id1') } }`, options ) @@ -165,7 +165,7 @@ describe('complier: options with mergeVirtualHostAttributes', () => { ``, ``, `(_ctx, _cache) => { - const __returned__ = { a: _sei('id' in _ctx.$.type.props || _ctx.virtualHostId === '' ? _ctx.id1 : _ctx.virtualHostId, 'view'), b: _s(_ses('id' in _ctx.$.type.props || _ctx.virtualHostId === '' ? _ctx.id1 : _ctx.virtualHostId)) } + const __returned__ = { a: _sei(_gei(_ctx, _ctx.id1), 'view'), b: _s(_ses(_gei(_ctx, _ctx.id1))) } return __returned__ }`, optionsX @@ -174,7 +174,7 @@ describe('complier: options with mergeVirtualHostAttributes', () => { ``, ``, `(_ctx, _cache) => { - const __returned__ = { a: _sei('r0-2a9ec0b0', 'image', 'img'), b: _s(_ses('r0-2a9ec0b0')), c: _sei('id' in _ctx.$.type.props || _ctx.virtualHostId === '' ? 'page' : _ctx.virtualHostId, 'view'), d: _s(_ses('id' in _ctx.$.type.props || _ctx.virtualHostId === '' ? 'page' : _ctx.virtualHostId)) } + const __returned__ = { a: _sei('r0-2a9ec0b0', 'image', 'img'), b: _s(_ses('r0-2a9ec0b0')), c: _sei(_gei(_ctx, 'page'), 'view'), d: _s(_ses(_gei(_ctx, 'page'))) } return __returned__ }`, optionsX @@ -183,7 +183,7 @@ describe('complier: options with mergeVirtualHostAttributes', () => { ``, ``, `(_ctx, _cache) => { - const __returned__ = { a: _sei('r0-2a9ec0b0', 'image', 'img'), b: _s(_ses('r0-2a9ec0b0')), c: _sei(('id' in _ctx.$.type.props || _ctx.virtualHostId === '' ? 'page' : _ctx.virtualHostId) !== '' ? 'id' in _ctx.$.type.props || _ctx.virtualHostId === '' ? 'page' : _ctx.virtualHostId : 'r1-2a9ec0b0', 'view', 'page'), d: _s(_ses(('id' in _ctx.$.type.props || _ctx.virtualHostId === '' ? 'page' : _ctx.virtualHostId) !== '' ? 'id' in _ctx.$.type.props || _ctx.virtualHostId === '' ? 'page' : _ctx.virtualHostId : 'r1-2a9ec0b0')) } + const __returned__ = { a: _sei('r0-2a9ec0b0', 'image', 'img'), b: _s(_ses('r0-2a9ec0b0')), c: _sei(_gei(_ctx, 'page', 'r1-2a9ec0b0'), 'view', 'page'), d: _s(_ses(_gei(_ctx, 'page', 'r1-2a9ec0b0'))) } return __returned__ }`, optionsX @@ -192,57 +192,57 @@ describe('complier: options with mergeVirtualHostAttributes', () => { test('user component attrs with mergeVirtualHostAttributes', () => { assert( ``, - ``, + ``, `(_ctx, _cache) => { - return {} + return { a: _gei(_ctx, '') } }`, options ) assert( ``, - ``, + ``, `(_ctx, _cache) => { - return { a: _ctx.show } + return { a: _ctx.show, b: _gei(_ctx, '') } }`, options ) assert( ``, - ``, + ``, `(_ctx, _cache) => { - return { a: _p({ id: 'i' }) } + return { a: _p({ id: 'i' }), b: _gei(_ctx, '') } }`, options ) assert( ``, - ``, + ``, `(_ctx, _cache) => { - return { a: _ctx.i, b: _p({ id: _ctx.i }) } + return { a: _ctx.i, b: _p({ id: _ctx.i }), c: _gei(_ctx, '') } }`, options ) assert( ``, - ``, + ``, `(_ctx, _cache) => { - return { a: _ctx.show } + return { a: _ctx.show, b: _gei(_ctx, '') } }`, options ) assert( ``, - ``, + ``, `(_ctx, _cache) => { - return {} + return { a: _gei(_ctx, '') } }`, options ) assert( ``, - ``, + ``, `(_ctx, _cache) => { - return {} + return { a: _gei(_ctx, '') } }`, options ) diff --git a/packages/uni-mp-compiler/__tests__/uniElement.spec.ts b/packages/uni-mp-compiler/__tests__/uniElement.spec.ts index 4add6a38fe8..75dfc87d582 100644 --- a/packages/uni-mp-compiler/__tests__/uniElement.spec.ts +++ b/packages/uni-mp-compiler/__tests__/uniElement.spec.ts @@ -25,7 +25,7 @@ describe('compiler: transform UniElement.style.setProperty', () => { ``, `