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

Commit 84adc78

Browse files
committed
wip: fix incorrect condition
1 parent c1a3688 commit 84adc78

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ exports[`compile > expression parsing > v-bind 1`] = `
207207
const n0 = t0()
208208
_setInheritAttrs(true)
209209
let _key_value, _foo;
210-
_renderEffect(() => _key_value !== key.value && _foo !== _unref(foo) && _setDynamicProps(n0, [{ [(_key_value = key.value)+1]: (_foo = _unref(foo))[key.value+1]() }], true))
210+
_renderEffect(() => (_key_value !== key.value || _foo !== _unref(foo)) && _setDynamicProps(n0, [{ [(_key_value = key.value)+1]: (_foo = _unref(foo))[key.value+1]() }], true))
211211
return n0
212212
})()"
213213
`;

packages/compiler-vapor/__tests__/compile.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ describe('compile', () => {
195195
expect(code).matchSnapshot()
196196
expect(code).contains('key.value+1')
197197
expect(code).contains(
198-
'_key_value !== key.value && _foo !== _unref(foo) && _setDynamicProps(n0, [{ [(_key_value = key.value)+1]: (_foo = _unref(foo))[key.value+1]() }], true)',
198+
'(_key_value !== key.value || _foo !== _unref(foo)) && _setDynamicProps(n0, [{ [(_key_value = key.value)+1]: (_foo = _unref(foo))[key.value+1]() }], true)',
199199
)
200200
})
201201

packages/compiler-vapor/__tests__/transforms/__snapshots__/vBind.spec.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export function render(_ctx) {
100100
const n0 = t0()
101101
_setInheritAttrs(true)
102102
let _foo, _id;
103-
_renderEffect(() => _foo !== _ctx.foo && _id !== _ctx.id && _setDynamicProps(n0, [{ [_camelize((_foo = _ctx.foo))]: (_id = _ctx.id) }], true))
103+
_renderEffect(() => (_foo !== _ctx.foo || _id !== _ctx.id) && _setDynamicProps(n0, [{ [_camelize((_foo = _ctx.foo))]: (_id = _ctx.id) }], true))
104104
return n0
105105
}"
106106
`;
@@ -217,7 +217,7 @@ export function render(_ctx) {
217217
const n0 = t0()
218218
_setInheritAttrs(true)
219219
let _fooBar, _id;
220-
_renderEffect(() => _fooBar !== _ctx.fooBar && _id !== _ctx.id && _setDynamicProps(n0, [{ ["." + (_fooBar = _ctx.fooBar)]: (_id = _ctx.id) }], true))
220+
_renderEffect(() => (_fooBar !== _ctx.fooBar || _id !== _ctx.id) && _setDynamicProps(n0, [{ ["." + (_fooBar = _ctx.fooBar)]: (_id = _ctx.id) }], true))
221221
return n0
222222
}"
223223
`;
@@ -469,7 +469,7 @@ export function render(_ctx) {
469469
const n0 = t0()
470470
_setInheritAttrs(true)
471471
let _id, _title;
472-
_renderEffect(() => _id !== _ctx.id && _title !== _ctx.title && _setDynamicProps(n0, [{ [(_id = _ctx.id)]: _ctx.id, [(_title = _ctx.title)]: _ctx.title }], true))
472+
_renderEffect(() => (_id !== _ctx.id || _title !== _ctx.title) && _setDynamicProps(n0, [{ [(_id = _ctx.id)]: _ctx.id, [(_title = _ctx.title)]: _ctx.title }], true))
473473
return n0
474474
}"
475475
`;

packages/compiler-vapor/__tests__/transforms/vBind.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ describe('compiler v-bind', () => {
177177
],
178178
})
179179
expect(code).contains(
180-
'_id !== _ctx.id && _title !== _ctx.title && _setDynamicProps(n0, [{ [(_id = _ctx.id)]: _ctx.id, [(_title = _ctx.title)]: _ctx.title }], true)',
180+
'(_id !== _ctx.id || _title !== _ctx.title) && _setDynamicProps(n0, [{ [(_id = _ctx.id)]: _ctx.id, [(_title = _ctx.title)]: _ctx.title }], true)',
181181
)
182182
})
183183

@@ -351,7 +351,7 @@ describe('compiler v-bind', () => {
351351
expect(code).matchSnapshot()
352352
expect(code).contains('renderEffect')
353353
expect(code).contains(
354-
`_foo !== _ctx.foo && _id !== _ctx.id && _setDynamicProps(n0, [{ [_camelize((_foo = _ctx.foo))]: (_id = _ctx.id) }], true)`,
354+
`(_foo !== _ctx.foo || _id !== _ctx.id) && _setDynamicProps(n0, [{ [_camelize((_foo = _ctx.foo))]: (_id = _ctx.id) }], true)`,
355355
)
356356
})
357357

@@ -436,7 +436,7 @@ describe('compiler v-bind', () => {
436436
})
437437
expect(code).contains('renderEffect')
438438
expect(code).contains(
439-
`_fooBar !== _ctx.fooBar && _id !== _ctx.id && _setDynamicProps(n0, [{ ["." + (_fooBar = _ctx.fooBar)]: (_id = _ctx.id) }], true)`,
439+
`(_fooBar !== _ctx.fooBar || _id !== _ctx.id) && _setDynamicProps(n0, [{ ["." + (_fooBar = _ctx.fooBar)]: (_id = _ctx.id) }], true)`,
440440
)
441441
})
442442

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,17 @@ export function genEffect(
120120
'})',
121121
)
122122
} else {
123-
// single line early return condition: _foo !== _ctx.foo && _bar !== _ctx.bar &&
123+
// single line early return condition: _foo !== _ctx.foo || _bar !== _ctx.bar &&
124+
const multiple = conditions.length > 1
124125
const condition: CodeFragment[] =
125-
conditions.length > 0 ? [...conditions.join(' && '), ' && '] : []
126+
conditions.length > 0
127+
? [
128+
multiple ? `(` : undefined,
129+
...conditions.join(' || '),
130+
multiple ? `)` : undefined,
131+
' && ',
132+
]
133+
: []
126134
push(...condition, ...operationsExps.filter(frag => frag !== NEWLINE), ')')
127135
}
128136

0 commit comments

Comments
 (0)