Skip to content

Commit b8710ca

Browse files
authored
Merge branch 'main' into fix-slots-level
2 parents 2bd661d + 6608bb3 commit b8710ca

File tree

7 files changed

+697
-6
lines changed

7 files changed

+697
-6
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { BindingTypes, type RootNode } from '@vue/compiler-dom'
22
import { type CompilerOptions, compile as _compile } from '../src'
33

4+
// TODO This is a temporary test case for initial implementation.
5+
// Remove it once we have more comprehensive tests.
6+
// DO NOT ADD MORE TESTS HERE.
7+
48
function compile(template: string | RootNode, options: CompilerOptions = {}) {
59
let { code } = _compile(template, {
610
...options,

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ export function render(_ctx) {
3030
}"
3131
`;
3232

33+
exports[`compiler: v-for > function params w/ prefixIdentifiers: false 1`] = `
34+
"import { renderEffect as _renderEffect, setText as _setText, createFor as _createFor, template as _template } from 'vue/vapor';
35+
const t0 = _template("<div></div>")
36+
37+
export function render(_ctx) {
38+
const n0 = _createFor(() => (items), ([item, __, k]) => {
39+
const n2 = t0()
40+
_renderEffect(() => _setText(n2, item))
41+
return n2
42+
}, (item, __, k) => (k))
43+
return n0
44+
}"
45+
`;
46+
3347
exports[`compiler: v-for > multi effect 1`] = `
3448
"import { renderEffect as _renderEffect, setDynamicProp as _setDynamicProp, createFor as _createFor, template as _template } from 'vue/vapor';
3549
const t0 = _template("<div></div>")

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,17 @@ describe('compiler: v-for', () => {
223223
index: undefined,
224224
})
225225
})
226+
227+
test('function params w/ prefixIdentifiers: false', () => {
228+
const { code } = compileWithVFor(
229+
`<div v-for="(item, , k) of items" :key="k">{{ item }}</div>`,
230+
{
231+
prefixIdentifiers: false,
232+
},
233+
)
234+
235+
expect(code).contains(`_createFor(() => (items), ([item, __, k]) => {`)
236+
expect(code).contain(`_setText(n2, item)`)
237+
expect(code).matchSnapshot()
238+
})
226239
})

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,18 @@ export function genFor(
4242
}
4343

4444
const [depth, exitScope] = context.enterScope()
45-
const propsName = `_ctx${depth}`
45+
let propsName: string
4646
const idMap: Record<string, string | null> = {}
47-
Array.from(idsOfValue).forEach(
48-
(id, idIndex) => (idMap[id] = `${propsName}[${idIndex}]`),
49-
)
50-
if (rawKey) idMap[rawKey] = `${propsName}[${idsOfValue.size}]`
51-
if (rawIndex) idMap[rawIndex] = `${propsName}[${idsOfValue.size + 1}]`
47+
if (context.options.prefixIdentifiers) {
48+
propsName = `_ctx${depth}`
49+
Array.from(idsOfValue).forEach(
50+
(id, idIndex) => (idMap[id] = `${propsName}[${idIndex}]`),
51+
)
52+
if (rawKey) idMap[rawKey] = `${propsName}[${idsOfValue.size}]`
53+
if (rawIndex) idMap[rawIndex] = `${propsName}[${idsOfValue.size + 1}]`
54+
} else {
55+
propsName = `[${[rawValue || ((rawKey || rawIndex) && '_'), rawKey || (rawIndex && '__'), rawIndex].filter(Boolean).join(', ')}]`
56+
}
5257

5358
let blockFn = context.withId(
5459
() => genBlock(render, context, [propsName]),

packages/runtime-vapor/__tests__/apiCreateVaporApp.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,16 @@ describe('api: createVaporApp', () => {
332332
expect(window.performance.getEntries()).lengthOf(0)
333333
})
334334
})
335+
336+
test('config.globalProperty', () => {
337+
const { app, mount, html } = define({
338+
render() {
339+
const instance = getCurrentInstance()!
340+
return createTextNode([instance.appContext.config.globalProperties.msg])
341+
},
342+
}).create()
343+
app.config.globalProperties.msg = 'hello world'
344+
mount()
345+
expect(html()).toBe('hello world')
346+
})
335347
})

0 commit comments

Comments
 (0)