wip: rename key to $key

This commit is contained in:
daiwei 2025-03-07 15:25:46 +08:00
parent 9ffa5acfb0
commit 05d9f53c08
6 changed files with 11 additions and 10 deletions

View File

@ -37,7 +37,7 @@ describe('compiler: transition', () => {
expect(code).toMatchSnapshot() expect(code).toMatchSnapshot()
// n2 should have a key // n2 should have a key
expect(code).contains('n2.key = 2') expect(code).contains('n2.$key = 2')
}) })
test('work with dynamic keyed children', () => { test('work with dynamic keyed children', () => {
@ -50,6 +50,6 @@ describe('compiler: transition', () => {
expect(code).toMatchSnapshot() expect(code).toMatchSnapshot()
expect(code).contains('_createKeyedFragment(() => _ctx.key') expect(code).contains('_createKeyedFragment(() => _ctx.key')
// should preserve key // should preserve key
expect(code).contains('n0.key = _ctx.key') expect(code).contains('n0.$key = _ctx.key')
}) })
}) })

View File

@ -24,7 +24,7 @@ export function render(_ctx) {
"default": () => { "default": () => {
return _createKeyedFragment(() => _ctx.key, () => { return _createKeyedFragment(() => _ctx.key, () => {
const n0 = t0() const n0 = t0()
n0.key = _ctx.key n0.$key = _ctx.key
return n0 return n0
}) })
} }
@ -42,7 +42,7 @@ export function render(_ctx) {
"default": () => { "default": () => {
const n0 = _createIf(() => (_ctx.show), () => { const n0 = _createIf(() => (_ctx.show), () => {
const n2 = t0() const n2 = t0()
n2.key = 2 n2.$key = 2
return n2 return n2
}) })
return n0 return n0

View File

@ -61,7 +61,7 @@ export function genBlockContent(
const keyValue = key const keyValue = key
? genExpression(key, context) ? genExpression(key, context)
: JSON.stringify(child.id) : JSON.stringify(child.id)
push(NEWLINE, `n${child.id}.key = `, ...keyValue) push(NEWLINE, `n${child.id}.$key = `, ...keyValue)
} }
} }

View File

@ -20,7 +20,7 @@ import {
} from './components/Transition' } from './components/Transition'
export interface TransitionOptions { export interface TransitionOptions {
key?: any $key?: any
$transition?: VaporTransitionHooks $transition?: VaporTransitionHooks
} }
@ -39,7 +39,7 @@ export type Block = TransitionBlock | VaporComponentInstance | Block[]
export type BlockFn = (...args: any[]) => Block export type BlockFn = (...args: any[]) => Block
export class VaporFragment implements TransitionOptions { export class VaporFragment implements TransitionOptions {
key?: any $key?: any
$transition?: VaporTransitionHooks | undefined $transition?: VaporTransitionHooks | undefined
nodes: Block nodes: Block
anchor?: Node anchor?: Node

View File

@ -101,7 +101,7 @@ function resolveTransitionHooks(
postClone?: (hooks: TransitionHooks) => void, postClone?: (hooks: TransitionHooks) => void,
): VaporTransitionHooks { ): VaporTransitionHooks {
const context = getTransitionHooksContext( const context = getTransitionHooksContext(
String(block.key), String(block.$key),
props, props,
state, state,
instance, instance,
@ -181,7 +181,7 @@ export function applyTransitionLeaveHooks(
earlyRemove, earlyRemove,
delayedLeave, delayedLeave,
) => { ) => {
state.leavingNodes.set(String(leavingBlock.key), leavingBlock) state.leavingNodes.set(String(leavingBlock.$key), leavingBlock)
// early removal callback // early removal callback
block[leaveCbKey] = () => { block[leaveCbKey] = () => {
earlyRemove() earlyRemove()
@ -210,7 +210,7 @@ export function findTransitionBlock(block: Block): TransitionBlock | undefined {
if (block instanceof Element) child = block if (block instanceof Element) child = block
} else if (isVaporComponent(block)) { } else if (isVaporComponent(block)) {
child = findTransitionBlock(block.block) child = findTransitionBlock(block.block)
if (child && child.key === undefined) child.key = block.type.__name if (child && child.$key === undefined) child.$key = block.type.__name
} else if (Array.isArray(block)) { } else if (Array.isArray(block)) {
child = block[0] as TransitionBlock child = block[0] as TransitionBlock
let hasFound = false let hasFound = false

View File

@ -268,6 +268,7 @@ export function optimizePropertyLookup(): void {
isOptimized = true isOptimized = true
const proto = Element.prototype as any const proto = Element.prototype as any
proto.$transition = undefined proto.$transition = undefined
proto.$key = undefined
proto.$evtclick = undefined proto.$evtclick = undefined
proto.$root = false proto.$root = false
proto.$html = proto.$html =