From feb6cc74cdc61b608b1a52e221c233d510362446 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Wed, 8 Dec 2021 14:23:23 +0800 Subject: [PATCH] fix(mp): transform props without special attributes (#3055) --- packages/uni-mp-compiler/__tests__/component.spec.ts | 6 +++--- packages/uni-mp-compiler/__tests__/vFor.spec.ts | 8 ++++---- .../uni-mp-compiler/src/transforms/transformComponent.ts | 2 ++ .../uni-mp-compiler/src/transforms/transformIdentifier.ts | 6 ------ 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/packages/uni-mp-compiler/__tests__/component.spec.ts b/packages/uni-mp-compiler/__tests__/component.spec.ts index 659e16e52..c8deb0856 100644 --- a/packages/uni-mp-compiler/__tests__/component.spec.ts +++ b/packages/uni-mp-compiler/__tests__/component.spec.ts @@ -99,10 +99,10 @@ describe('compiler: transform component', () => { }) test(`component with props`, () => { assert( - ``, - ``, + ``, + ``, `(_ctx, _cache) => { - return { a: _ctx.b, b: _ctx.d, c: _n(_ctx.f), d: _s(_ctx.h), e: _o(_ctx.i), f: _ctx.o, g: _o($event => _ctx.j = $event), h: _o($event => _ctx.k = $event), i: _p({ ['prop-a']: 'l', ['prop-b']: _ctx.m, first: _ctx.j, last: _ctx.k }) } + return { a: _ctx.b, b: _ctx.d, c: _n(_ctx.f), d: _s(_ctx.h), e: _o(_ctx.i), f: _ctx.o, g: _ctx.r, h: _ctx.t, i: _o($event => _ctx.j = $event), j: _o($event => _ctx.k = $event), k: _p({ ['prop-a']: 'l', ['prop-b']: _ctx.m, first: _ctx.j, last: _ctx.k }) } }` ) }) diff --git a/packages/uni-mp-compiler/__tests__/vFor.spec.ts b/packages/uni-mp-compiler/__tests__/vFor.spec.ts index 02fa19437..0d21865c1 100644 --- a/packages/uni-mp-compiler/__tests__/vFor.spec.ts +++ b/packages/uni-mp-compiler/__tests__/vFor.spec.ts @@ -186,18 +186,18 @@ describe(`compiler: v-for`, () => { test(`keyed v-for`, () => { assert( ``, - ``, + ``, `(_ctx, _cache) => { - return { a: _f(_ctx.items, (item, k0, i0) => { return {}; }) } + return { a: _f(_ctx.items, (item, k0, i0) => { return { a: item }; }) } }` ) }) test(`keyed template v-for`, () => { assert( ``, - `hello`, + `hello`, `(_ctx, _cache) => { - return { a: _f(_ctx.items, (item, k0, i0) => { return {}; }) } + return { a: _f(_ctx.items, (item, k0, i0) => { return { a: item }; }) } }` ) }) diff --git a/packages/uni-mp-compiler/src/transforms/transformComponent.ts b/packages/uni-mp-compiler/src/transforms/transformComponent.ts index 02164e33f..97eeb1372 100644 --- a/packages/uni-mp-compiler/src/transforms/transformComponent.ts +++ b/packages/uni-mp-compiler/src/transforms/transformComponent.ts @@ -103,6 +103,8 @@ function isComponentProp(name: string) { 'onVI', 'ref', 'slot', + 'key', + 'is', ].includes(name) ) { return false diff --git a/packages/uni-mp-compiler/src/transforms/transformIdentifier.ts b/packages/uni-mp-compiler/src/transforms/transformIdentifier.ts index 2b0214e1f..7986f3143 100644 --- a/packages/uni-mp-compiler/src/transforms/transformIdentifier.ts +++ b/packages/uni-mp-compiler/src/transforms/transformIdentifier.ts @@ -6,9 +6,7 @@ import { } from '@vue/compiler-core' import { NodeTransform } from '../transform' -import { isForElementNode } from './vFor' import { ATTR_VUE_SLOTS, rewriteExpression } from './utils' -import { isSelfKey, rewriteSelfKey } from './transformKey' import { findStaticClassIndex, isClassBinding, @@ -44,8 +42,6 @@ export const transformIdentifier: NodeTransform = (node, context) => { } else if (isSlotOutlet(node)) { rewriteSlot(node, context) } else if (node.type === NodeTypes.ELEMENT) { - const vFor = isForElementNode(node) && node.vFor - let hasClassBinding = false let hasStyleBinding = false @@ -78,8 +74,6 @@ export const transformIdentifier: NodeTransform = (node, context) => { if (exp) { if (isBuiltIn(dir)) { // noop - } else if (isSelfKey(dir, vFor)) { - rewriteSelfKey(dir) } else if (isClassBinding(dir)) { hasClassBinding = true rewriteClass(i, dir, props, context) -- GitLab