Skip to content

Commit 8b2d6a3

Browse files
committed
test: update tests and snapshots for helper prefixing
1 parent 51317af commit 8b2d6a3

22 files changed

+293
-257
lines changed

packages/compiler-core/__tests__/__snapshots__/codegen.spec.ts.snap

+15-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export function render() {
2727
const _ctx = this
2828
const _cache = _ctx.$cache
2929
return _cache[1] || (
30-
setBlockTracking(-1),
30+
_setBlockTracking(-1),
3131
_cache[1] = foo,
32-
setBlockTracking(1),
32+
_setBlockTracking(1),
3333
_cache[1]
3434
)
3535
}"
@@ -126,7 +126,7 @@ return function render() {
126126
`;
127127

128128
exports[`compiler: codegen function mode preamble w/ prefixIdentifiers: true 1`] = `
129-
"const { createVNode, resolveDirective } = Vue
129+
"const { createVNode: _createVNode, resolveDirective: _resolveDirective } = Vue
130130
131131
return function render() {
132132
const _ctx = this
@@ -165,8 +165,20 @@ return function render() {
165165
`;
166166

167167
exports[`compiler: codegen module mode preamble 1`] = `
168+
"import { createVNode as _createVNode, resolveDirective as _resolveDirective } from \\"vue\\"
169+
170+
export function render() {
171+
const _ctx = this
172+
return null
173+
}"
174+
`;
175+
176+
exports[`compiler: codegen module mode preamble w/ optimizeBindings: true 1`] = `
168177
"import { createVNode, resolveDirective } from \\"vue\\"
169178
179+
// Binding optimization for webpack code-split
180+
const _createVNode = createVNode, _resolveDirective = resolveDirective
181+
170182
export function render() {
171183
const _ctx = this
172184
return null

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

+18-18
Original file line numberDiff line numberDiff line change
@@ -26,43 +26,43 @@ return function render() {
2626
`;
2727

2828
exports[`compiler: integration tests function mode w/ prefixIdentifiers: true 1`] = `
29-
"const { toDisplayString, createVNode, openBlock, createBlock, createCommentVNode, Fragment, renderList, createTextVNode } = Vue
29+
"const { toDisplayString: _toDisplayString, createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock, createCommentVNode: _createCommentVNode, Fragment: _Fragment, renderList: _renderList, createTextVNode: _createTextVNode } = Vue
3030
3131
return function render() {
3232
const _ctx = this
33-
return (openBlock(), createBlock(\\"div\\", {
33+
return (_openBlock(), _createBlock(\\"div\\", {
3434
id: \\"foo\\",
3535
class: _ctx.bar.baz
3636
}, [
37-
createTextVNode(toDisplayString(_ctx.world.burn()) + \\" \\", 1 /* TEXT */),
38-
(openBlock(), (_ctx.ok)
39-
? createBlock(\\"div\\", { key: 0 }, \\"yes\\")
40-
: createBlock(Fragment, { key: 1 }, [\\"no\\"])),
41-
(openBlock(false), createBlock(Fragment, null, renderList(_ctx.list, (value, index) => {
42-
return (openBlock(), createBlock(\\"div\\", null, [
43-
createVNode(\\"span\\", null, toDisplayString(value + index), 1 /* TEXT */)
37+
_createTextVNode(_toDisplayString(_ctx.world.burn()) + \\" \\", 1 /* TEXT */),
38+
(_openBlock(), (_ctx.ok)
39+
? _createBlock(\\"div\\", { key: 0 }, \\"yes\\")
40+
: _createBlock(_Fragment, { key: 1 }, [\\"no\\"])),
41+
(_openBlock(false), _createBlock(_Fragment, null, _renderList(_ctx.list, (value, index) => {
42+
return (_openBlock(), _createBlock(\\"div\\", null, [
43+
_createVNode(\\"span\\", null, _toDisplayString(value + index), 1 /* TEXT */)
4444
]))
4545
}), 256 /* UNKEYED_FRAGMENT */))
4646
], 2 /* CLASS */))
4747
}"
4848
`;
4949

5050
exports[`compiler: integration tests module mode 1`] = `
51-
"import { toDisplayString, createVNode, openBlock, createBlock, createCommentVNode, Fragment, renderList, createTextVNode } from \\"vue\\"
51+
"import { toDisplayString as _toDisplayString, createVNode as _createVNode, openBlock as _openBlock, createBlock as _createBlock, createCommentVNode as _createCommentVNode, Fragment as _Fragment, renderList as _renderList, createTextVNode as _createTextVNode } from \\"vue\\"
5252
5353
export function render() {
5454
const _ctx = this
55-
return (openBlock(), createBlock(\\"div\\", {
55+
return (_openBlock(), _createBlock(\\"div\\", {
5656
id: \\"foo\\",
5757
class: _ctx.bar.baz
5858
}, [
59-
createTextVNode(toDisplayString(_ctx.world.burn()) + \\" \\", 1 /* TEXT */),
60-
(openBlock(), (_ctx.ok)
61-
? createBlock(\\"div\\", { key: 0 }, \\"yes\\")
62-
: createBlock(Fragment, { key: 1 }, [\\"no\\"])),
63-
(openBlock(false), createBlock(Fragment, null, renderList(_ctx.list, (value, index) => {
64-
return (openBlock(), createBlock(\\"div\\", null, [
65-
createVNode(\\"span\\", null, toDisplayString(value + index), 1 /* TEXT */)
59+
_createTextVNode(_toDisplayString(_ctx.world.burn()) + \\" \\", 1 /* TEXT */),
60+
(_openBlock(), (_ctx.ok)
61+
? _createBlock(\\"div\\", { key: 0 }, \\"yes\\")
62+
: _createBlock(_Fragment, { key: 1 }, [\\"no\\"])),
63+
(_openBlock(false), _createBlock(_Fragment, null, _renderList(_ctx.list, (value, index) => {
64+
return (_openBlock(), _createBlock(\\"div\\", null, [
65+
_createVNode(\\"span\\", null, _toDisplayString(value + index), 1 /* TEXT */)
6666
]))
6767
}), 256 /* UNKEYED_FRAGMENT */))
6868
], 2 /* CLASS */))
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`scopeId compiler support should push scopeId for hoisted nodes 1`] = `
4-
"import { createVNode, createBlock, openBlock, withScopeId, pushScopeId, popScopeId } from \\"vue\\"
5-
const withId = withScopeId(\\"test\\")
4+
"import { createVNode as _createVNode, createBlock as _createBlock, openBlock as _openBlock, withScopeId as _withScopeId, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from \\"vue\\"
5+
const _withId = _withScopeId(\\"test\\")
66
7-
pushScopeId(\\"test\\")
8-
const _hoisted_1 = createVNode(\\"div\\", null, \\"hello\\")
9-
const _hoisted_2 = createVNode(\\"div\\", null, \\"world\\")
10-
popScopeId()
7+
_pushScopeId(\\"test\\")
8+
const _hoisted_1 = _createVNode(\\"div\\", null, \\"hello\\")
9+
const _hoisted_2 = _createVNode(\\"div\\", null, \\"world\\")
10+
_popScopeId()
1111
12-
export const render = withId(function render() {
12+
export const render = _withId(function render() {
1313
const _ctx = this
14-
return (openBlock(), createBlock(\\"div\\", null, [
14+
return (_openBlock(), _createBlock(\\"div\\", null, [
1515
_hoisted_1,
1616
_hoisted_2
1717
]))
1818
})"
1919
`;
2020

2121
exports[`scopeId compiler support should wrap default slot 1`] = `
22-
"import { createVNode, resolveComponent, createBlock, openBlock, withScopeId } from \\"vue\\"
23-
const withId = withScopeId(\\"test\\")
22+
"import { createVNode as _createVNode, resolveComponent as _resolveComponent, createBlock as _createBlock, openBlock as _openBlock, withScopeId as _withScopeId } from \\"vue\\"
23+
const _withId = _withScopeId(\\"test\\")
2424
25-
export const render = withId(function render() {
25+
export const render = _withId(function render() {
2626
const _ctx = this
27-
const _component_Child = resolveComponent(\\"Child\\")
27+
const _component_Child = _resolveComponent(\\"Child\\")
2828
29-
return (openBlock(), createBlock(_component_Child, null, {
30-
default: withId(() => [
31-
createVNode(\\"div\\")
29+
return (_openBlock(), _createBlock(_component_Child, null, {
30+
default: _withId(() => [
31+
_createVNode(\\"div\\")
3232
]),
3333
_compiled: true
3434
}))
3535
})"
3636
`;
3737

3838
exports[`scopeId compiler support should wrap dynamic slots 1`] = `
39-
"import { createVNode, resolveComponent, renderList, createSlots, createBlock, openBlock, withScopeId } from \\"vue\\"
40-
const withId = withScopeId(\\"test\\")
39+
"import { createVNode as _createVNode, resolveComponent as _resolveComponent, renderList as _renderList, createSlots as _createSlots, createBlock as _createBlock, openBlock as _openBlock, withScopeId as _withScopeId } from \\"vue\\"
40+
const _withId = _withScopeId(\\"test\\")
4141
42-
export const render = withId(function render() {
42+
export const render = _withId(function render() {
4343
const _ctx = this
44-
const _component_Child = resolveComponent(\\"Child\\")
44+
const _component_Child = _resolveComponent(\\"Child\\")
4545
46-
return (openBlock(), createBlock(_component_Child, null, createSlots({ _compiled: true }, [
46+
return (_openBlock(), _createBlock(_component_Child, null, _createSlots({ _compiled: true }, [
4747
(_ctx.ok)
4848
? {
4949
name: \\"foo\\",
50-
fn: withId(() => [
51-
createVNode(\\"div\\")
50+
fn: _withId(() => [
51+
_createVNode(\\"div\\")
5252
])
5353
}
5454
: undefined,
55-
renderList(_ctx.list, (i) => {
55+
_renderList(_ctx.list, (i) => {
5656
return {
5757
name: i,
58-
fn: withId(() => [
59-
createVNode(\\"div\\")
58+
fn: _withId(() => [
59+
_createVNode(\\"div\\")
6060
])
6161
}
6262
})
@@ -65,31 +65,31 @@ export const render = withId(function render() {
6565
`;
6666

6767
exports[`scopeId compiler support should wrap named slots 1`] = `
68-
"import { toDisplayString, createTextVNode, createVNode, resolveComponent, createBlock, openBlock, withScopeId } from \\"vue\\"
69-
const withId = withScopeId(\\"test\\")
68+
"import { toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, createVNode as _createVNode, resolveComponent as _resolveComponent, createBlock as _createBlock, openBlock as _openBlock, withScopeId as _withScopeId } from \\"vue\\"
69+
const _withId = _withScopeId(\\"test\\")
7070
71-
export const render = withId(function render() {
71+
export const render = _withId(function render() {
7272
const _ctx = this
73-
const _component_Child = resolveComponent(\\"Child\\")
73+
const _component_Child = _resolveComponent(\\"Child\\")
7474
75-
return (openBlock(), createBlock(_component_Child, null, {
76-
foo: withId(({ msg }) => [
77-
createTextVNode(toDisplayString(msg), 1 /* TEXT */)
75+
return (_openBlock(), _createBlock(_component_Child, null, {
76+
foo: _withId(({ msg }) => [
77+
_createTextVNode(_toDisplayString(msg), 1 /* TEXT */)
7878
]),
79-
bar: withId(() => [
80-
createVNode(\\"div\\")
79+
bar: _withId(() => [
80+
_createVNode(\\"div\\")
8181
]),
8282
_compiled: true
8383
}))
8484
})"
8585
`;
8686

8787
exports[`scopeId compiler support should wrap render function 1`] = `
88-
"import { createVNode, createBlock, openBlock, withScopeId } from \\"vue\\"
89-
const withId = withScopeId(\\"test\\")
88+
"import { createVNode as _createVNode, createBlock as _createBlock, openBlock as _openBlock, withScopeId as _withScopeId } from \\"vue\\"
89+
const _withId = _withScopeId(\\"test\\")
9090
91-
export const render = withId(function render() {
91+
export const render = _withId(function render() {
9292
const _ctx = this
93-
return (openBlock(), createBlock(\\"div\\"))
93+
return (_openBlock(), _createBlock(\\"div\\"))
9494
})"
9595
`;

packages/compiler-core/__tests__/codegen.spec.ts

+27-3
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,33 @@ describe('compiler: codegen', () => {
5454
helpers: [CREATE_VNODE, RESOLVE_DIRECTIVE]
5555
})
5656
const { code } = generate(root, { mode: 'module' })
57+
expect(code).toMatch(
58+
`import { ${helperNameMap[CREATE_VNODE]} as _${
59+
helperNameMap[CREATE_VNODE]
60+
}, ${helperNameMap[RESOLVE_DIRECTIVE]} as _${
61+
helperNameMap[RESOLVE_DIRECTIVE]
62+
} } from "vue"`
63+
)
64+
expect(code).toMatchSnapshot()
65+
})
66+
67+
test('module mode preamble w/ optimizeBindings: true', () => {
68+
const root = createRoot({
69+
helpers: [CREATE_VNODE, RESOLVE_DIRECTIVE]
70+
})
71+
const { code } = generate(root, { mode: 'module', optimizeBindings: true })
5772
expect(code).toMatch(
5873
`import { ${helperNameMap[CREATE_VNODE]}, ${
5974
helperNameMap[RESOLVE_DIRECTIVE]
6075
} } from "vue"`
6176
)
77+
expect(code).toMatch(
78+
`const _${helperNameMap[CREATE_VNODE]} = ${
79+
helperNameMap[CREATE_VNODE]
80+
}, _${helperNameMap[RESOLVE_DIRECTIVE]} = ${
81+
helperNameMap[RESOLVE_DIRECTIVE]
82+
}`
83+
)
6284
expect(code).toMatchSnapshot()
6385
})
6486

@@ -88,7 +110,9 @@ describe('compiler: codegen', () => {
88110
})
89111
expect(code).not.toMatch(`const _Vue = Vue`)
90112
expect(code).toMatch(
91-
`const { ${helperNameMap[CREATE_VNODE]}, ${
113+
`const { ${helperNameMap[CREATE_VNODE]}: _${
114+
helperNameMap[CREATE_VNODE]
115+
}, ${helperNameMap[RESOLVE_DIRECTIVE]}: _${
92116
helperNameMap[RESOLVE_DIRECTIVE]
93117
} } = Vue`
94118
)
@@ -415,9 +439,9 @@ describe('compiler: codegen', () => {
415439
expect(code).toMatch(
416440
`
417441
_cache[1] || (
418-
setBlockTracking(-1),
442+
_setBlockTracking(-1),
419443
_cache[1] = foo,
420-
setBlockTracking(1),
444+
_setBlockTracking(1),
421445
_cache[1]
422446
)
423447
`.trim()

packages/compiler-core/__tests__/scopeId.spec.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ describe('scopeId compiler support', () => {
1818
scopeId: 'test'
1919
})
2020
expect(ast.helpers).toContain(WITH_SCOPE_ID)
21-
expect(code).toMatch(`const withId = withScopeId("test")`)
22-
expect(code).toMatch(`export const render = withId(function render() {`)
21+
expect(code).toMatch(`const _withId = _withScopeId("test")`)
22+
expect(code).toMatch(`export const render = _withId(function render() {`)
2323
expect(code).toMatchSnapshot()
2424
})
2525

@@ -28,7 +28,7 @@ describe('scopeId compiler support', () => {
2828
mode: 'module',
2929
scopeId: 'test'
3030
})
31-
expect(code).toMatch(`default: withId(() => [`)
31+
expect(code).toMatch(`default: _withId(() => [`)
3232
expect(code).toMatchSnapshot()
3333
})
3434

@@ -44,8 +44,8 @@ describe('scopeId compiler support', () => {
4444
scopeId: 'test'
4545
}
4646
)
47-
expect(code).toMatch(`foo: withId(({ msg }) => [`)
48-
expect(code).toMatch(`bar: withId(() => [`)
47+
expect(code).toMatch(`foo: _withId(({ msg }) => [`)
48+
expect(code).toMatch(`bar: _withId(() => [`)
4949
expect(code).toMatchSnapshot()
5050
})
5151

@@ -61,8 +61,8 @@ describe('scopeId compiler support', () => {
6161
scopeId: 'test'
6262
}
6363
)
64-
expect(code).toMatch(/name: "foo",\s+fn: withId\(/)
65-
expect(code).toMatch(/name: i,\s+fn: withId\(/)
64+
expect(code).toMatch(/name: "foo",\s+fn: _withId\(/)
65+
expect(code).toMatch(/name: i,\s+fn: _withId\(/)
6666
expect(code).toMatchSnapshot()
6767
})
6868

@@ -80,10 +80,10 @@ describe('scopeId compiler support', () => {
8080
expect(ast.hoists.length).toBe(2)
8181
expect(code).toMatch(
8282
[
83-
`pushScopeId("test")`,
84-
`const _hoisted_1 = createVNode("div", null, "hello")`,
85-
`const _hoisted_2 = createVNode("div", null, "world")`,
86-
`popScopeId()`
83+
`_pushScopeId("test")`,
84+
`const _hoisted_1 = _createVNode("div", null, "hello")`,
85+
`const _hoisted_2 = _createVNode("div", null, "world")`,
86+
`_popScopeId()`
8787
].join('\n')
8888
)
8989
expect(code).toMatchSnapshot()

packages/compiler-core/__tests__/transforms/__snapshots__/hoistStatic.spec.ts.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,14 @@ return function render() {
208208
`;
209209
210210
exports[`compiler: hoistStatic transform prefixIdentifiers should NOT hoist elements with cached handlers 1`] = `
211-
"import { createVNode, createBlock, openBlock } from \\"vue\\"
211+
"import { createVNode as _createVNode, createBlock as _createBlock, openBlock as _openBlock } from \\"vue\\"
212212
213213
export function render() {
214214
const _ctx = this
215215
const _cache = _ctx.$cache
216-
return (openBlock(), createBlock(\\"div\\", null, [
217-
createVNode(\\"div\\", null, [
218-
createVNode(\\"div\\", {
216+
return (_openBlock(), _createBlock(\\"div\\", null, [
217+
_createVNode(\\"div\\", null, [
218+
_createVNode(\\"div\\", {
219219
onClick: _cache[1] || (_cache[1] = $event => (_ctx.foo($event)))
220220
})
221221
])

packages/compiler-core/__tests__/transforms/__snapshots__/transformText.spec.ts.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ return function render() {
9191
`;
9292
9393
exports[`compiler: transform text with prefixIdentifiers: true 1`] = `
94-
"const { toDisplayString } = Vue
94+
"const { toDisplayString: _toDisplayString } = Vue
9595
9696
return function render() {
9797
const _ctx = this
98-
return toDisplayString(_ctx.foo) + \\" bar \\" + toDisplayString(_ctx.baz + _ctx.qux)
98+
return _toDisplayString(_ctx.foo) + \\" bar \\" + _toDisplayString(_ctx.baz + _ctx.qux)
9999
}"
100100
`;

0 commit comments

Comments
 (0)