Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 72e6b81

Browse files
committed
wip: add comments
1 parent 26bb79d commit 72e6b81

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

packages/compiler-vapor/src/generate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export class CodegenContext {
3838
currentRenderEffect: IREffect | undefined = undefined
3939
renderEffectSeemNames: Record<string, number> = Object.create(null)
4040
shouldGenEffectDeps = (): boolean => {
41+
// only need to generate effect deps when it's not nested in v-once or v-for
4142
return !!(
4243
this.currentRenderEffect &&
4344
!this.currentRenderEffect.inVOnce &&

packages/compiler-vapor/src/generators/operation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,14 @@ export function genEffect(
9898
const { varNamesToDeclare, conditions } = currentRenderEffect!
9999
const operationsExps = genOperations(operations, context)
100100

101+
// declare variables: let _foo, _bar
101102
if (varNamesToDeclare.size) {
102103
frag.splice(1, 0, `let ${[...varNamesToDeclare].join(', ')};`, NEWLINE)
103104
}
104105

105106
const newlineCount = operationsExps.filter(frag => frag === NEWLINE).length
106107
if (newlineCount > 1) {
108+
// multiline early return condition: if (_foo === _ctx.foo && _bar === _ctx.bar) return
107109
const condition: CodeFragment[] =
108110
conditions.length > 0
109111
? [NEWLINE, `if(`, ...conditions.join(' && '), `) return`]
@@ -118,6 +120,7 @@ export function genEffect(
118120
'})',
119121
)
120122
} else {
123+
// single line early return condition: _foo !== _ctx.foo && _bar !== _ctx.bar &&
121124
const condition: CodeFragment[] =
122125
conditions.length > 0 ? [...conditions.join(' && '), ' && '] : []
123126
push(...condition, ...operationsExps.filter(frag => frag !== NEWLINE), ')')

packages/compiler-vapor/src/generators/prop.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,14 @@ function processValue(
266266
const { currentRenderEffect, renderEffectSeemNames } = context
267267
const { varNamesToDeclare, varNamesOverwritten, conditions, operations } =
268268
currentRenderEffect!
269+
270+
// for multiple values the early return condition should be `if (_foo === _ctx.foo) return`
269271
const oper = operations.length === 1 ? '!==' : '==='
270-
for (let frag of values) {
272+
for (const frag of values) {
271273
if (!isArray(frag)) continue
272274

273-
let [newName, , , rawName] = frag
275+
// [code, newlineIndex, loc, name] -> [(_name = code), newlineIndex, loc, name]
276+
const [newName, , , rawName] = frag
274277
if (rawName) {
275278
let name = rawName.replace(/[^\w]/g, '_')
276279
if (varNamesOverwritten.has(name)) continue

0 commit comments

Comments
 (0)