in src/code-generator.ts [146:196]
value: getAstPropValue(props[name], name, customProps),
}),
);
}
});
return hooks;
};
export const getAstImport = (
identifiers: string[],
source: string,
defaultIdentifier?: string,
) => {
return t.importDeclaration(
[
...(defaultIdentifier
? [t.importDefaultSpecifier(t.identifier(defaultIdentifier))]
: []),
...identifiers.map((identifier) =>
t.importSpecifier(t.identifier(identifier), t.identifier(identifier)),
),
],
t.stringLiteral(source),
);
};
export const getAstJsxElement = (
name: string,
attrs: (t.JSXAttribute | null)[],
children: TJsxChild[],
) => {
const isSelfClosing = children.length === 0;
return t.jsxElement(
t.jsxOpeningElement(
t.jsxIdentifier(name),
attrs.filter((attr) => !!attr) as t.JSXAttribute[],
isSelfClosing,
),
isSelfClosing ? null : t.jsxClosingElement(t.jsxIdentifier(name)),
children,
true,
);
};
export const addToImportList = (
importList: TImportsConfig,
imports: TImportsConfig,
) => {
for (const [importFrom, importNames] of Object.entries(imports)) {
if (!importList.hasOwnProperty(importFrom)) {
importList[importFrom] = {