MCPcopy Create free account
hub / github.com/kuma-ui/kuma-ui / processCSS

Function processCSS

packages/babel-plugin/src/processCSS.ts:21–71  ·  view source on GitHub ↗
(
  nodePath: NodePath<types.Program>,
  t: typeof types,
  template: typeof Template,
  importedStyleFunctions: Record<string, string>,
)

Source from the content-addressed store, hash-verified

19 * @param {Record<string, string>} importedStyleFunctions - An object containing the imported styled functions.
20 */
21export function processCSS(
22 nodePath: NodePath<types.Program>,
23 t: typeof types,
24 template: typeof Template,
25 importedStyleFunctions: Record<string, string>,
26) {
27 nodePath.traverse({
28 CallExpression(path) {
29 const { node } = path;
30 const isCSS =
31 t.isIdentifier(node.callee) &&
32 node.callee.name === importedStyleFunctions["css"];
33 if (!isCSS) return;
34 if (
35 !(
36 node.arguments.length === 1 && t.isObjectExpression(node.arguments[0])
37 )
38 ) {
39 // `css` can be called without arguments.
40 // In such a case, it returns an empty string at runtime, as no styles are applied.
41 path.replaceWith(t.stringLiteral(""));
42 return;
43 }
44 const styleObject = extractStylePropsFromObjectExpression(
45 path,
46 node.arguments[0],
47 );
48 const convertedPseudoProps: SystemStyle["pseudo"] = Object.entries(
49 styleObject.pseudoProps,
50 ).map(([pseudoKey, pseudoValue]) => {
51 const pseudoStyle = all(pseudoValue);
52 return {
53 key: normalizePseudo(pseudoKey),
54 base: pseudoStyle.base,
55 responsive: pseudoStyle.media,
56 };
57 });
58
59 const style: SystemStyle = {
60 base: all(styleObject.styledProps).base,
61 responsive: all(styleObject.styledProps).media,
62 pseudo: convertedPseudoProps,
63 };
64
65 // Add the style rule to the sheet and get the generated class name.
66 const className = sheet.addRule(style);
67 path.replaceWith(t.stringLiteral(className));
68 return;
69 },
70 });
71}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected