Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c763388

Browse files
authored
fix(compiler-vapor): preserve :is prop on normal components (#14491)
1 parent 178b77f commit c763388

3 files changed

Lines changed: 65 additions & 7 deletions

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,16 @@ export function render(_ctx) {
409409
}"
410410
`;
411411
412+
exports[`compiler: element transform > dynamic component > component keeps both :is and is props 1`] = `
413+
"import { createComponent as _createComponent } from 'vue';
414+
415+
export function render(_ctx, $props, $emit, $attrs, $slots) {
416+
const n0 = _createComponent(_ctx.Comp, { is: () => ("Parent") })
417+
const n1 = _createComponent(_ctx.Comp, { is: () => ("Parent") })
418+
return [n0, n1]
419+
}"
420+
`;
421+
412422
exports[`compiler: element transform > dynamic component > dynamic binding 1`] = `
413423
"import { createDynamicComponent as _createDynamicComponent } from 'vue';
414424
@@ -427,6 +437,16 @@ export function render(_ctx) {
427437
}"
428438
`;
429439
440+
exports[`compiler: element transform > dynamic component > normal component with dynamic :is prop 1`] = `
441+
"import { resolveComponent as _resolveComponent, createComponentWithFallback as _createComponentWithFallback } from 'vue';
442+
443+
export function render(_ctx) {
444+
const _component_custom_input = _resolveComponent("custom-input")
445+
const n0 = _createComponentWithFallback(_component_custom_input, { is: () => ("foo") }, null, true)
446+
return n0
447+
}"
448+
`;
449+
430450
exports[`compiler: element transform > dynamic component > normal component with is prop 1`] = `
431451
"import { resolveComponent as _resolveComponent, createComponentWithFallback as _createComponentWithFallback } from 'vue';
432452

‎packages/compiler-vapor/__tests__/transforms/transformElement.spec.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,45 @@ describe('compiler: element transform', () => {
573573
props: [[{ key: { content: 'is' }, values: [{ content: 'foo' }] }]],
574574
})
575575
})
576+
577+
test('normal component with dynamic :is prop', () => {
578+
const { code, ir, helpers } = compileWithElementTransform(
579+
`<custom-input :is="'foo'" />`,
580+
{
581+
isNativeTag: () => false,
582+
},
583+
)
584+
expect(code).toMatchSnapshot()
585+
expect(helpers).toContain('resolveComponent')
586+
expect(helpers).not.toContain('resolveDynamicComponent')
587+
expect(code).toContain(
588+
'_createComponentWithFallback(_component_custom_input, { is: () => ("foo") }, null, true)',
589+
)
590+
expect(ir.block.dynamic.children[0].operation).toMatchObject({
591+
type: IRNodeTypes.CREATE_COMPONENT_NODE,
592+
tag: 'custom-input',
593+
asset: true,
594+
root: true,
595+
props: [[{ key: { content: 'is' } }]],
596+
})
597+
})
598+
599+
test('component keeps both :is and is props', () => {
600+
const { code } = compileWithElementTransform(
601+
`<Comp :is="'Parent'" /><Comp is="Parent" />`,
602+
{
603+
bindingMetadata: {
604+
Comp: BindingTypes.SETUP_CONST,
605+
},
606+
},
607+
)
608+
expect(code).toMatchSnapshot()
609+
expect(
610+
code.match(
611+
/_createComponent\(_ctx\.Comp, \{ is: \(\) => \("Parent"\) \}\)/g,
612+
)?.length,
613+
).toBe(2)
614+
})
576615
})
577616

578617
test('checkbox with static indeterminate', () => {

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -477,14 +477,13 @@ export function buildProps(
477477
}
478478
}
479479

480-
// exclude `is` prop for <component>
480+
// exclude `is` prop only for <component>
481481
if (
482-
(isDynamicComponent &&
483-
prop.type === NodeTypes.ATTRIBUTE &&
484-
prop.name === 'is') ||
485-
(prop.type === NodeTypes.DIRECTIVE &&
486-
prop.name === 'bind' &&
487-
isStaticArgOf(prop.arg, 'is'))
482+
isDynamicComponent &&
483+
((prop.type === NodeTypes.ATTRIBUTE && prop.name === 'is') ||
484+
(prop.type === NodeTypes.DIRECTIVE &&
485+
prop.name === 'bind' &&
486+
isStaticArgOf(prop.arg, 'is')))
488487
) {
489488
continue
490489
}

0 commit comments

Comments
 (0)