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

Add reexports. #529

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
Expand Up @@ -49,6 +49,7 @@ export {
it("generates component with model", () => {
//#region EXPECTED
const EXPECTED = `
export { ReexportewdMember, OtherReexportedMember } from "widget-gackage-name/DX/WIDGET/PATH";
Igggr marked this conversation as resolved.
Show resolved Hide resolved
import WIDGET from "widget-gackage-name/DX/WIDGET/PATH";
import { BASE_COMPONENT } from "./BASE_COMPONENT_PATH";

Expand Down Expand Up @@ -89,7 +90,8 @@ export {
name: "CONFIG_COMPONENT",
path: "./CONFIG_COMPONENT_PATH"
},
hasModel: true
hasModel: true,
reexports: [ "ReexportewdMember", "OtherReexportedMember"]
Igggr marked this conversation as resolved.
Show resolved Hide resolved
}, "widget-gackage-name")
).toBe(EXPECTED);
});
Expand Down
11 changes: 11 additions & 0 deletions packages/devextreme-vue-generator/src/component-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface IComponent {
hasExplicitTypes?: boolean;
nestedComponents?: INestedComponent[];
expectedChildren?: Record<string, IExpectedChild>;
reexports?: string[];
}

interface INestedComponent {
Expand Down Expand Up @@ -104,6 +105,7 @@ function generate(component: IComponent, widgetsPackage: string = "devextreme"):
nestedComponents,
defaultExport: component.name,
namedExports,
reexports: component.reexports,
expectedChildren: formatExpectedChildren(component.expectedChildren),
widgetsPackage
};
Expand Down Expand Up @@ -159,13 +161,22 @@ const renderComponent: (model: {
expectedChildren?: IExpectedChildModel[];
defaultExport: string;
namedExports: string[];
reexports?: string[];
widgetsPackage: string;

}) => string = createTempate(
`<#? it.hasExplicitTypes #>` +
`export { ExplicitTypes } from "<#= it.widgetsPackage #>/<#= it.widgetImport.path #>";\n` +
`<#?#>` +

`<#? it.reexports?.filter(n => n != 'default')?.length #>` +
`export {\n <#= it.reexports.filter(n => n != 'default').join(',\\n ') #>,\n} from "<#= it.widgetsPackage #>/<#= it.widgetImport.path #>";\n` +
`<#?#>` +

`<#? !it.defaultExport && it.reexports?.includes('default') #>` +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no test for this case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided not to add test - but delete this line. Widget themself will always be default export.

`export default from "<#= it.widgetsPackage #>/<#= it.widgetImport.path #>";\n` +
`<#?#>` +

`import <#= it.widgetImport.name #><#? it.props #>, { Properties }<#?#> from "<#= it.widgetsPackage #>/<#= it.widgetImport.path #>";\n` +
`<#~ it.namedImports :namedImport #>` +
`import { <#= namedImport.name #> } from "<#= namedImport.path #>";\n` +
Expand Down
1 change: 1 addition & 0 deletions packages/devextreme-vue-generator/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ function mapWidget(
props: getProps(raw.options, customTypeHash),
hasModel: !!raw.isEditor,
hasExplicitTypes: !!raw.optionsTypeParams?.length,
reexports: raw.reexports,
nestedComponents: raw.complexOptions
? raw.complexOptions.map((o) => mapNestedComponent(o, customTypeHash))
: undefined,
Expand Down