Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vue): fixes model conflict between two components start with start with same tag #215

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createComponentDefinition } from '../src/generate-vue-component';
import { ComponentModelConfig } from '../src/types';

describe('createComponentDefinition', () => {

Expand Down Expand Up @@ -211,4 +212,43 @@ export const MyComponent = /*@__PURE__*/ defineContainer<Components.MyComponent>
]);
`);
});

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<Components.MyListItem>('my-list-item', undefined, [],
'selectedIndex', 'selectedIndexChange');
`);

expect(listOutput).toEqual(`
export const MyList = /*@__PURE__*/ defineContainer<Components.MyList>('my-list', undefined);
`);

expect(listOutput).not.toEqual(`
export const MyList = /*@__PURE__*/ defineContainer<Components.MyList>('my-list', undefined, [],
'selectedIndex', 'selectedIndexChange');
`);

});

});
8 changes: 7 additions & 1 deletion packages/vue-output-target/src/generate-vue-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 += `, [
Expand Down