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()
// n2 should have a key
expect(code).contains('n2.key = 2')
expect(code).contains('n2.$key = 2')
})
test('work with dynamic keyed children', () => {
@ -50,6 +50,6 @@ describe('compiler: transition', () => {
expect(code).toMatchSnapshot()
expect(code).contains('_createKeyedFragment(() => _ctx.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": () => {
return _createKeyedFragment(() => _ctx.key, () => {
const n0 = t0()
n0.key = _ctx.key
n0.$key = _ctx.key
return n0
})
}
@ -42,7 +42,7 @@ export function render(_ctx) {
"default": () => {
const n0 = _createIf(() => (_ctx.show), () => {
const n2 = t0()
n2.key = 2
n2.$key = 2
return n2
})
return n0

View File

@ -61,7 +61,7 @@ export function genBlockContent(
const keyValue = key
? genExpression(key, context)
: 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'
export interface TransitionOptions {
key?: any
$key?: any
$transition?: VaporTransitionHooks
}
@ -39,7 +39,7 @@ export type Block = TransitionBlock | VaporComponentInstance | Block[]
export type BlockFn = (...args: any[]) => Block
export class VaporFragment implements TransitionOptions {
key?: any
$key?: any
$transition?: VaporTransitionHooks | undefined
nodes: Block
anchor?: Node

View File

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

View File

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