Skip to content

Commit

Permalink
wip: add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 committed Dec 4, 2024
1 parent 26bb79d commit 72e6b81
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/compiler-vapor/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class CodegenContext {
currentRenderEffect: IREffect | undefined = undefined
renderEffectSeemNames: Record<string, number> = Object.create(null)
shouldGenEffectDeps = (): boolean => {
// only need to generate effect deps when it's not nested in v-once or v-for
return !!(
this.currentRenderEffect &&
!this.currentRenderEffect.inVOnce &&
Expand Down
3 changes: 3 additions & 0 deletions packages/compiler-vapor/src/generators/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ export function genEffect(
const { varNamesToDeclare, conditions } = currentRenderEffect!
const operationsExps = genOperations(operations, context)

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

const newlineCount = operationsExps.filter(frag => frag === NEWLINE).length
if (newlineCount > 1) {
// multiline early return condition: if (_foo === _ctx.foo && _bar === _ctx.bar) return
const condition: CodeFragment[] =
conditions.length > 0
? [NEWLINE, `if(`, ...conditions.join(' && '), `) return`]
Expand All @@ -118,6 +120,7 @@ export function genEffect(
'})',
)
} else {
// single line early return condition: _foo !== _ctx.foo && _bar !== _ctx.bar &&
const condition: CodeFragment[] =
conditions.length > 0 ? [...conditions.join(' && '), ' && '] : []
push(...condition, ...operationsExps.filter(frag => frag !== NEWLINE), ')')
Expand Down
7 changes: 5 additions & 2 deletions packages/compiler-vapor/src/generators/prop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,14 @@ function processValue(
const { currentRenderEffect, renderEffectSeemNames } = context
const { varNamesToDeclare, varNamesOverwritten, conditions, operations } =
currentRenderEffect!

// for multiple values the early return condition should be `if (_foo === _ctx.foo) return`
const oper = operations.length === 1 ? '!==' : '==='
for (let frag of values) {
for (const frag of values) {
if (!isArray(frag)) continue

let [newName, , , rawName] = frag
// [code, newlineIndex, loc, name] -> [(_name = code), newlineIndex, loc, name]
const [newName, , , rawName] = frag
if (rawName) {
let name = rawName.replace(/[^\w]/g, '_')
if (varNamesOverwritten.has(name)) continue
Expand Down

0 comments on commit 72e6b81

Please sign in to comment.