Skip to content

Commit cb9631f

Browse files
committed
chore: add test
1 parent ba93961 commit cb9631f

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export function render(_ctx) {
180180
`;
181181
182182
exports[`compile > dynamic root nodes and interpolation 1`] = `
183-
"import { child as _child, toDisplayString as _toDisplayString, setText as _setText, setProp as _setProp, renderEffect as _renderEffect, delegateEvents as _delegateEvents, template as _template } from 'vue';
183+
"import { child as _child, setProp as _setProp, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, delegateEvents as _delegateEvents, template as _template } from 'vue';
184184
const t0 = _template("<button> </button>", true)
185185
_delegateEvents("click")
186186
@@ -190,13 +190,48 @@ export function render(_ctx) {
190190
n0.$evtclick = e => _ctx.handleClick(e)
191191
_renderEffect(() => {
192192
const _count = _ctx.count
193-
_setText(x0, _toDisplayString(_count) + "foo" + _toDisplayString(_count) + "foo" + _toDisplayString(_count))
194193
_setProp(n0, "id", _count)
194+
_setText(x0, _toDisplayString(_count) + "foo" + _toDisplayString(_count) + "foo" + _toDisplayString(_count))
195+
})
196+
return n0
197+
}"
198+
`;
199+
200+
exports[`compile > execution order > basic 1`] = `
201+
"import { child as _child, setProp as _setProp, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue';
202+
const t0 = _template("<div> </div>", true)
203+
204+
export function render(_ctx) {
205+
const n0 = t0()
206+
const x0 = _child(n0)
207+
_renderEffect(() => {
208+
_setProp(n0, "id", _ctx.foo)
209+
_setText(x0, _toDisplayString(_ctx.bar))
195210
})
196211
return n0
197212
}"
198213
`;
199214
215+
exports[`compile > execution order > with v-once 1`] = `
216+
"import { child as _child, next as _next, nthChild as _nthChild, toDisplayString as _toDisplayString, setText as _setText, setProp as _setProp, renderEffect as _renderEffect, template as _template } from 'vue';
217+
const t0 = _template("<div><span> </span> <br> </div>", true)
218+
219+
export function render(_ctx) {
220+
const n3 = t0()
221+
const n0 = _child(n3)
222+
const n1 = _next(n0)
223+
const n2 = _nthChild(n3, 3)
224+
const x0 = _child(n0)
225+
_setText(x0, _toDisplayString(_ctx.foo))
226+
_renderEffect(() => {
227+
_setProp(n3, "id", _ctx.foo)
228+
_setText(n1, " " + _toDisplayString(_ctx.bar))
229+
_setText(n2, " " + _toDisplayString(_ctx.baz))
230+
})
231+
return n3
232+
}"
233+
`;
234+
200235
exports[`compile > expression parsing > interpolation 1`] = `
201236
"
202237
const n0 = t0()

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,21 @@ describe('compile', () => {
220220
expect(code).matchSnapshot()
221221
})
222222
})
223+
224+
describe('execution order', () => {
225+
test('basic', () => {
226+
const code = compile(`<div :id="foo">{{ bar }}</div>`)
227+
expect(code).matchSnapshot()
228+
})
229+
test('with v-once', () => {
230+
const code = compile(
231+
`<div :id="foo">
232+
<span v-once>{{ foo }}</span>
233+
{{ bar }}<br>
234+
{{ baz }}
235+
</div>`,
236+
)
237+
expect(code).matchSnapshot()
238+
})
239+
})
223240
})

packages/compiler-vapor/src/compile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ export function getBaseTransformPreset(): TransformPreset {
8181
transformVFor,
8282
transformSlotOutlet,
8383
transformTemplateRef,
84-
transformText,
8584
transformElement,
85+
transformText,
8686
transformVSlot,
8787
transformComment,
8888
transformChildren,

packages/compiler-vapor/src/transform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class TransformContext<T extends AllNode = AllNode> {
138138
registerEffect(
139139
expressions: SimpleExpressionNode[],
140140
operation: OperationNode | OperationNode[],
141-
getIndex: () => number = () => this.block.effect.length,
141+
getIndex = (): number => this.block.effect.length,
142142
): void {
143143
const operations = [operation].flat()
144144
expressions = expressions.filter(exp => !isConstantExpression(exp))

0 commit comments

Comments
 (0)