diff --git a/packages/vue-output-target/__tests__/generate-vue-components.spec.ts b/packages/vue-output-target/__tests__/generate-vue-components.spec.ts index e6010b01..b05c1496 100644 --- a/packages/vue-output-target/__tests__/generate-vue-components.spec.ts +++ b/packages/vue-output-target/__tests__/generate-vue-components.spec.ts @@ -1,4 +1,5 @@ import { createComponentDefinition } from '../src/generate-vue-component'; +import { ComponentModelConfig } from '../src/types'; describe('createComponentDefinition', () => { @@ -211,4 +212,43 @@ export const MyComponent = /*@__PURE__*/ defineContainer ]); `); }); + + it('should not conflict with the component which starts with same tag name', () => { + const componentConfig: ComponentModelConfig[] = [ + { + elements: 'my-list-item', + event: 'selectedIndexChange', + targetAttr: 'selectedIndex' + } + ]; + const generateComponentDefinition = createComponentDefinition('Components', componentConfig); + const listItemOutput = generateComponentDefinition({ + properties: [], + tagName: 'my-list-item', + methods: [], + events: [], + }); + const listOutput = generateComponentDefinition({ + properties: [], + tagName: 'my-list', + methods: [], + events: [], + }); + + expect(listItemOutput).toEqual(` +export const MyListItem = /*@__PURE__*/ defineContainer('my-list-item', undefined, [], +'selectedIndex', 'selectedIndexChange'); +`); + + expect(listOutput).toEqual(` +export const MyList = /*@__PURE__*/ defineContainer('my-list', undefined); +`); + +expect(listOutput).not.toEqual(` +export const MyList = /*@__PURE__*/ defineContainer('my-list', undefined, [], +'selectedIndex', 'selectedIndexChange'); +`); + + }); + }); diff --git a/packages/vue-output-target/src/generate-vue-component.ts b/packages/vue-output-target/src/generate-vue-component.ts index 968ea3b0..f1d4d1c5 100644 --- a/packages/vue-output-target/src/generate-vue-component.ts +++ b/packages/vue-output-target/src/generate-vue-component.ts @@ -26,7 +26,13 @@ export const createComponentDefinition = ( let templateString = ` export const ${tagNameAsPascal} = /*@__PURE__*/ defineContainer<${importTypes}.${tagNameAsPascal}>('${cmpMeta.tagName}', ${importAs}`; - const findModel = componentModelConfig && componentModelConfig.find(config => config.elements.includes(cmpMeta.tagName)); + const findModel = + componentModelConfig && + componentModelConfig.find((config) => + Array.isArray(config.elements) + ? config.elements.includes(cmpMeta.tagName) + : config.elements === cmpMeta.tagName, + ); if (props.length > 0) { templateString += `, [