10000 test: add test · vuejs/core@c39c463 · GitHub
[go: up one dir, main page]

Skip to content

Commit c39c463

Browse files
committed
test: add test
1 parent 73bb298 commit c39c463

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3+
exports[`compiler: v-show transform > on component 1`] = `
4+
"import { resolveComponent as _resolveComponent, createComponentWithFallback as _createComponentWithFallback, applyVShow as _applyVShow } from 'vue';
5+
6+
export function render(_ctx) {
7+
const _component_Comp = _resolveComponent("Comp")
8+
const n0 = _createComponentWithFallback(_component_Comp, null, null, true)
9+
_applyVShow(n0, () => (_ctx.foo))
10+
return n0
11+
}"
12+
`;
13+
314
exports[`compiler: v-show transform > simple expression 1`] = `
415
"import { applyVShow as _applyVShow, template as _template } from 'vue';
516
const t0 = _template("<div></div>", true)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ describe('compiler: v-show transform', () => {
2626
}),
2727
)
2828
})
29+
30+
test('on component', () => {
31+
const { code } = compileWithVShow(`<Comp v-show="foo"/>`)
32+
expect(code).toMatchSnapshot()
33+
})
2934
})

packages/compiler-vapor/src/transform.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class TransformContext<T extends AllNode = AllNode> {
147147
isStaticExpression(e, this.root.options.bindingMetadata),
148148
)
149149
) {
150-
return this.registerOperation(...operations)
150+
return operations.forEach(op => this.registerOperation(op))
151151
}
152152

153153
this.block.expressions.push(...expressions)
@@ -172,12 +172,12 @@ export class TransformContext<T extends AllNode = AllNode> {
172172
}
173173
}
174174

175-
registerOperation(...node: OperationNode[]): void {
176-
this.block.operation.push(...node)
177-
}
178-
179-
registerOperationAt(node: OperationNode, index: number): void {
180-
this.block.operation.splice(index, 0, node)
175+
registerOperation(node: OperationNode, index?: number): void {
176+
if (index !== undefined) {
177+
this.block.operation.splice(index, 0, node)
178+
} else {
179+
this.block.operation.push(node)
180+
}
181181
}
182182

183183
create<T extends TemplateChildNode>(

packages/compiler-vapor/src/transforms/transformElement.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,15 @@ function transformComponentElement(
136136
once: context.inVOnce,
137137
dynamic: dynamicComponent,
138138
}
139-
const hasVShow = findDir(node, 'show')
140-
if (hasVShow) {
141-
const showOperationIndex = context.block.operation.findIndex(
139+
140+
// ensure v-show is handled after the component is created
141+
let showOperationIndex
142+
i 781C f (findDir(node, 'show')) {
143+
showOperationIndex = context.block.operation.findIndex(
142144
op => op.type === IRNodeTypes.DIRECTIVE && op.name === 'show',
143145
)
144-
context.registerOperationAt(op, showOperationIndex)
145-
} else {
146-
context.registerOperation(op)
147146
}
147+
context.registerOperation(op, showOperationIndex)
148148
context.slots = []
149149
}
150150

0 commit comments

Comments
 (0)
0