|
@@ -9,6 +9,7 @@ import {
|
|
|
transformVFor,
|
|
transformVFor,
|
|
|
transformVIf,
|
|
transformVIf,
|
|
|
transformVOn,
|
|
transformVOn,
|
|
|
|
|
+ transformVSlot,
|
|
|
} from '../../src'
|
|
} from '../../src'
|
|
|
import {
|
|
import {
|
|
|
type BindingMetadata,
|
|
type BindingMetadata,
|
|
@@ -30,6 +31,21 @@ const compileWithElementTransform = makeCompile({
|
|
|
},
|
|
},
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+const compileWithElementAndSlotTransform = makeCompile({
|
|
|
|
|
+ nodeTransforms: [
|
|
|
|
|
+ transformVIf,
|
|
|
|
|
+ transformVFor,
|
|
|
|
|
+ transformElement,
|
|
|
|
|
+ transformVSlot,
|
|
|
|
|
+ transformText,
|
|
|
|
|
+ transformChildren,
|
|
|
|
|
+ ],
|
|
|
|
|
+ directiveTransforms: {
|
|
|
|
|
+ bind: transformVBind,
|
|
|
|
|
+ on: transformVOn,
|
|
|
|
|
+ },
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
describe('compiler: element transform', () => {
|
|
describe('compiler: element transform', () => {
|
|
|
describe('component', () => {
|
|
describe('component', () => {
|
|
|
test('create single-use asset component with inline resolve', () => {
|
|
test('create single-use asset component with inline resolve', () => {
|
|
@@ -73,6 +89,34 @@ describe('compiler: element transform', () => {
|
|
|
expect(helpers).not.toContain('createAssetComponent')
|
|
expect(helpers).not.toContain('createAssetComponent')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ test('hoist asset component also used in component slot', () => {
|
|
|
|
|
+ const { code, helpers } = compileWithElementAndSlotTransform(
|
|
|
|
|
+ `<Child /><Parent><Child /></Parent>`,
|
|
|
|
|
+ )
|
|
|
|
|
+ expect(code).toMatchSnapshot()
|
|
|
|
|
+ expect(code).toContain(
|
|
|
|
|
+ 'const _component_Child = _resolveComponent("Child")',
|
|
|
|
|
+ )
|
|
|
|
|
+ expect(code).toContain('_createComponentWithFallback(_component_Child)')
|
|
|
|
|
+ expect(code).not.toContain('_createAssetComponent("Child"')
|
|
|
|
|
+ expect(helpers).toContain('resolveComponent')
|
|
|
|
|
+ expect(helpers).toContain('createComponentWithFallback')
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ test('hoist asset component also used in conditional component slot', () => {
|
|
|
|
|
+ const { code, helpers } = compileWithElementAndSlotTransform(
|
|
|
|
|
+ `<Child /><Parent><template #default><Child v-if="ok" /></template></Parent>`,
|
|
|
|
|
+ )
|
|
|
|
|
+ expect(code).toMatchSnapshot()
|
|
|
|
|
+ expect(code).toContain(
|
|
|
|
|
+ 'const _component_Child = _resolveComponent("Child")',
|
|
|
|
|
+ )
|
|
|
|
|
+ expect(code).toContain('_createComponentWithFallback(_component_Child)')
|
|
|
|
|
+ expect(code).not.toContain('_createAssetComponent("Child"')
|
|
|
|
|
+ expect(helpers).toContain('resolveComponent')
|
|
|
|
|
+ expect(helpers).toContain('createComponentWithFallback')
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
test('resolve implicitly self-referencing component', () => {
|
|
test('resolve implicitly self-referencing component', () => {
|
|
|
const { code, helpers } = compileWithElementTransform(`<Example/>`, {
|
|
const { code, helpers } = compileWithElementTransform(`<Example/>`, {
|
|
|
filename: `/foo/bar/Example.vue?vue&type=template`,
|
|
filename: `/foo/bar/Example.vue?vue&type=template`,
|