Skip to content

fix(generator): change order of cleanup of the overrides #82

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

Open
wants to merge 3 commits into
base: master
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
6 changes: 6 additions & 0 deletions scripts/generateWrappers/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ const Vivid3ComponentsExtraPropertiesMap = {
name: 'value',
type: { text: 'string' }
}
],
DataGridCell: [
{
name: 'ariaSelected',
type: { text: 'boolean | undefined' }
}
]
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/generateWrappers/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ const renderComponentV3 = prefix => classDeclaration => language => componentCla
const componentName = getClassName(classDeclaration)
const componentTagName = `${componentPrefix}-${camel2kebab(componentName)}`
const events = [...(classDeclaration.events?.map(({ name }) => name) || []), ...(ComponentsEventsMapV3[componentClassName] || [])]
const properties = (classDeclaration.members?.filter(({ privacy = 'public', kind, readonly }) => kind === 'field' && privacy === 'public' && readonly !== true) || [])
.concat(Vivid3ComponentsExtraPropertiesMap[componentName] || [])
const properties = (Vivid3ComponentsExtraPropertiesMap[componentName] || [])
.concat(classDeclaration.members?.filter(({ privacy = 'public', kind, readonly }) => kind === 'field' && privacy === 'public' && readonly !== true) || [])
const attributes = classDeclaration.attributes?.filter(({ fieldName }) => properties.find(({ name }) => fieldName === name)) || []
const propertyNames = properties.map(({ name }) => `'${name}'`)
const props = [
Expand Down
43 changes: 43 additions & 0 deletions scripts/generateWrappers/generator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,49 @@ describe("generator", () => {
`);
});

it("should add extra props from Vivid3ComponentsExtraPropertiesMap", async () => {
function replaceComponentWithOverridable() {
const newData = JSON.parse(JSON.stringify(MOCK_DATA));
newData.modules[0].declarations[1].name = 'DataGridCell'
return newData;
}
setTokenTemplateMock(TemplateToken.PROPS);
const newData = replaceComponentWithOverridable();

await generateWrappersV3InstanceTS({ elements: newData });

const content = fs.outputFile.mock.calls[0][1];
expect(content).toMatchInlineSnapshot(`
" onChange?: (event: SyntheticEvent) => void,
\\"ariaSelected\\"?: any /* boolean | undefined */,
\\"field1\\"?: any /* AccordionExpandMode */,
\\"field2\\"?: string | null,
\\"activeItemIndex\\"?: number"
`);
});

it("should override default props with extra props from Vivid3ComponentsExtraPropertiesMap", async () => {
function replaceComponentWithOverridable() {
const newData = JSON.parse(JSON.stringify(MOCK_DATA));
newData.modules[0].declarations[1].name = 'DataGridCell'
newData.modules[0].declarations[1].members[0].name = 'ariaSelected'
newData.modules[0].declarations[1].attributes[0].name = 'ariaSelected'
return newData;
}
setTokenTemplateMock(TemplateToken.PROPS);
const newData = replaceComponentWithOverridable();

await generateWrappersV3InstanceTS({ elements: newData });

const content = fs.outputFile.mock.calls[0][1];
expect(content).toMatchInlineSnapshot(`
" onChange?: (event: SyntheticEvent) => void,
\\"ariaSelected\\"?: any /* boolean | undefined */,
\\"field2\\"?: string | null,
\\"activeItemIndex\\"?: number"
`);
});

it("should replace component registration for DataGridRow with empty string", async () => {
setTokenTemplateMock(`
import { register<% component-name %> } from '@vonage/vivid'
Expand Down