(
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
inputComponent: DefineComponent<{}, {}, any, any, any, any>,
options?: MountingOptions<any> & Record<string, any>
)
| 70 | |
| 71 | // implementation |
| 72 | export function createInstance( |
| 73 | // eslint-disable-next-line @typescript-eslint/no-empty-object-type |
| 74 | inputComponent: DefineComponent<{}, {}, any, any, any, any>, |
| 75 | options?: MountingOptions<any> & Record<string, any> |
| 76 | ) { |
| 77 | // normalize the incoming component |
| 78 | const originalComponent = unwrapLegacyVueExtendComponent(inputComponent) |
| 79 | let component: ConcreteComponent |
| 80 | const instanceOptions = getInstanceOptions(options ?? {}) |
| 81 | |
| 82 | const rootComponents: CreateStubComponentsTransformerConfig['rootComponents'] = |
| 83 | {} |
| 84 | |
| 85 | if ( |
| 86 | isFunctionalComponent(originalComponent) || |
| 87 | isLegacyFunctionalComponent(originalComponent) |
| 88 | ) { |
| 89 | component = defineComponent({ |
| 90 | compatConfig: { |
| 91 | MODE: 3, |
| 92 | INSTANCE_LISTENERS: false, |
| 93 | INSTANCE_ATTRS_CLASS_STYLE: false, |
| 94 | COMPONENT_FUNCTIONAL: isLegacyFunctionalComponent(originalComponent) |
| 95 | ? 'suppress-warning' |
| 96 | : false |
| 97 | }, |
| 98 | props: originalComponent.props || {}, |
| 99 | setup: |
| 100 | (props, { attrs, slots }) => |
| 101 | () => |
| 102 | h(originalComponent, { ...props, ...attrs }, slots), |
| 103 | ...instanceOptions |
| 104 | }) |
| 105 | rootComponents.functional = originalComponent |
| 106 | } else if (isObjectComponent(originalComponent)) { |
| 107 | component = { ...originalComponent, ...instanceOptions } |
| 108 | } else { |
| 109 | component = originalComponent |
| 110 | } |
| 111 | |
| 112 | rootComponents.component = component |
| 113 | // We've just replaced our component with its copy |
| 114 | // Let's register it as a stub so user can find it |
| 115 | registerStub({ source: originalComponent, stub: component }) |
| 116 | |
| 117 | function slotToFunction(slot: Slot) { |
| 118 | switch (typeof slot) { |
| 119 | case 'function': |
| 120 | return slot |
| 121 | case 'object': |
| 122 | return () => h(slot) |
| 123 | case 'string': |
| 124 | return processSlot(slot) |
| 125 | default: |
| 126 | throw Error(`Invalid slot received.`) |
| 127 | } |
| 128 | } |
| 129 |
no test coverage detected
searching dependent graphs…