@tamagui/static 1.0.0-alpha.6 → 1.0.0-alpha.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/dist/cjs/constants.js +43 -0
  2. package/dist/cjs/constants.js.map +7 -0
  3. package/dist/cjs/extractor/accessSafe.js +39 -0
  4. package/dist/cjs/extractor/accessSafe.js.map +7 -0
  5. package/dist/cjs/extractor/babelParse.js +58 -0
  6. package/dist/cjs/extractor/babelParse.js.map +7 -0
  7. package/dist/cjs/extractor/buildClassName.js +68 -0
  8. package/dist/cjs/extractor/buildClassName.js.map +7 -0
  9. package/dist/cjs/extractor/createEvaluator.js +79 -0
  10. package/dist/cjs/extractor/createEvaluator.js.map +7 -0
  11. package/dist/cjs/extractor/createExtractor.js +988 -0
  12. package/dist/cjs/extractor/createExtractor.js.map +7 -0
  13. package/dist/cjs/extractor/ensureImportingConcat.js +52 -0
  14. package/dist/cjs/extractor/ensureImportingConcat.js.map +7 -0
  15. package/dist/cjs/extractor/evaluateAstNode.js +122 -0
  16. package/dist/cjs/extractor/evaluateAstNode.js.map +7 -0
  17. package/dist/cjs/extractor/extractHelpers.js +134 -0
  18. package/dist/cjs/extractor/extractHelpers.js.map +7 -0
  19. package/dist/cjs/extractor/extractMediaStyle.js +193 -0
  20. package/dist/cjs/extractor/extractMediaStyle.js.map +7 -0
  21. package/dist/cjs/extractor/extractToClassNames.js +295 -0
  22. package/dist/cjs/extractor/extractToClassNames.js.map +7 -0
  23. package/dist/cjs/extractor/findTopmostFunction.js +46 -0
  24. package/dist/cjs/extractor/findTopmostFunction.js.map +7 -0
  25. package/dist/cjs/extractor/generatedUid.js +56 -0
  26. package/dist/cjs/extractor/generatedUid.js.map +7 -0
  27. package/dist/cjs/extractor/getPropValueFromAttributes.js +77 -0
  28. package/dist/cjs/extractor/getPropValueFromAttributes.js.map +7 -0
  29. package/dist/cjs/extractor/getSourceModule.js +97 -0
  30. package/dist/cjs/extractor/getSourceModule.js.map +7 -0
  31. package/dist/cjs/extractor/getStaticBindingsForScope.js +156 -0
  32. package/dist/cjs/extractor/getStaticBindingsForScope.js.map +7 -0
  33. package/dist/cjs/extractor/hoistClassNames.js +72 -0
  34. package/dist/cjs/extractor/hoistClassNames.js.map +7 -0
  35. package/dist/cjs/extractor/literalToAst.js +121 -0
  36. package/dist/cjs/extractor/literalToAst.js.map +7 -0
  37. package/dist/cjs/extractor/loadTamagui.js +70 -0
  38. package/dist/cjs/extractor/loadTamagui.js.map +7 -0
  39. package/dist/cjs/extractor/logLines.js +40 -0
  40. package/dist/cjs/extractor/logLines.js.map +7 -0
  41. package/dist/cjs/extractor/normalizeTernaries.js +108 -0
  42. package/dist/cjs/extractor/normalizeTernaries.js.map +7 -0
  43. package/dist/cjs/extractor/removeUnusedHooks.js +107 -0
  44. package/dist/cjs/extractor/removeUnusedHooks.js.map +7 -0
  45. package/dist/cjs/index.js +38 -0
  46. package/dist/cjs/index.js.map +7 -0
  47. package/dist/cjs/patchReactNativeWeb.js +157 -0
  48. package/dist/cjs/patchReactNativeWeb.js.map +7 -0
  49. package/dist/cjs/types.js +21 -0
  50. package/dist/cjs/types.js.map +7 -0
  51. package/dist/{constants.js → esm/constants.js} +4 -0
  52. package/dist/{constants.js.map → esm/constants.js.map} +3 -3
  53. package/dist/{extractor → esm/extractor}/accessSafe.js +0 -0
  54. package/dist/{extractor → esm/extractor}/accessSafe.js.map +1 -1
  55. package/dist/{extractor → esm/extractor}/babelParse.js +0 -0
  56. package/dist/{extractor → esm/extractor}/babelParse.js.map +1 -1
  57. package/dist/{extractor → esm/extractor}/buildClassName.js +0 -0
  58. package/dist/{extractor → esm/extractor}/buildClassName.js.map +1 -1
  59. package/dist/{extractor → esm/extractor}/createEvaluator.js +1 -1
  60. package/dist/esm/extractor/createEvaluator.js.map +7 -0
  61. package/dist/{extractor → esm/extractor}/createExtractor.js +189 -79
  62. package/dist/esm/extractor/createExtractor.js.map +7 -0
  63. package/dist/{extractor → esm/extractor}/ensureImportingConcat.js +1 -1
  64. package/dist/esm/extractor/ensureImportingConcat.js.map +7 -0
  65. package/dist/{extractor → esm/extractor}/evaluateAstNode.js +0 -0
  66. package/dist/{extractor → esm/extractor}/evaluateAstNode.js.map +1 -1
  67. package/dist/{extractor → esm/extractor}/extractHelpers.js +25 -9
  68. package/dist/esm/extractor/extractHelpers.js.map +7 -0
  69. package/dist/{extractor → esm/extractor}/extractMediaStyle.js +3 -2
  70. package/dist/{extractor → esm/extractor}/extractMediaStyle.js.map +3 -3
  71. package/dist/{extractor → esm/extractor}/extractToClassNames.js +41 -24
  72. package/dist/esm/extractor/extractToClassNames.js.map +7 -0
  73. package/dist/{extractor → esm/extractor}/findTopmostFunction.js +0 -0
  74. package/dist/{extractor → esm/extractor}/findTopmostFunction.js.map +1 -1
  75. package/dist/{extractor → esm/extractor}/generatedUid.js +0 -0
  76. package/dist/{extractor → esm/extractor}/generatedUid.js.map +1 -1
  77. package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js +0 -0
  78. package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js.map +1 -1
  79. package/dist/{extractor → esm/extractor}/getSourceModule.js +0 -0
  80. package/dist/{extractor → esm/extractor}/getSourceModule.js.map +1 -1
  81. package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js +0 -0
  82. package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js.map +1 -1
  83. package/dist/{extractor → esm/extractor}/hoistClassNames.js +0 -0
  84. package/dist/{extractor → esm/extractor}/hoistClassNames.js.map +1 -1
  85. package/dist/esm/extractor/literalToAst.js +80 -0
  86. package/dist/esm/extractor/literalToAst.js.map +7 -0
  87. package/dist/{extractor → esm/extractor}/loadTamagui.js +8 -2
  88. package/dist/esm/extractor/loadTamagui.js.map +7 -0
  89. package/dist/esm/extractor/logLines.js +17 -0
  90. package/dist/esm/extractor/logLines.js.map +7 -0
  91. package/dist/{extractor → esm/extractor}/normalizeTernaries.js +3 -2
  92. package/dist/{extractor → esm/extractor}/normalizeTernaries.js.map +2 -2
  93. package/dist/{extractor → esm/extractor}/removeUnusedHooks.js +5 -3
  94. package/dist/{extractor → esm/extractor}/removeUnusedHooks.js.map +2 -2
  95. package/dist/{index.js → esm/index.js} +0 -0
  96. package/dist/{index.js.map → esm/index.js.map} +1 -1
  97. package/dist/{patchReactNativeWeb.js → esm/patchReactNativeWeb.js} +22 -0
  98. package/dist/esm/patchReactNativeWeb.js.map +7 -0
  99. package/dist/{types.js → esm/types.js} +0 -0
  100. package/dist/{types.js.map → esm/types.js.map} +0 -0
  101. package/dist/jsx/constants.js +13 -0
  102. package/dist/jsx/extractor/accessSafe.js +10 -0
  103. package/dist/jsx/extractor/babelParse.js +29 -0
  104. package/dist/jsx/extractor/buildClassName.js +39 -0
  105. package/dist/jsx/extractor/createEvaluator.js +50 -0
  106. package/dist/jsx/extractor/createExtractor.js +928 -0
  107. package/dist/jsx/extractor/ensureImportingConcat.js +23 -0
  108. package/dist/jsx/extractor/evaluateAstNode.js +93 -0
  109. package/dist/jsx/extractor/extractHelpers.js +109 -0
  110. package/dist/jsx/extractor/extractMediaStyle.js +151 -0
  111. package/dist/jsx/extractor/extractToClassNames.js +251 -0
  112. package/dist/jsx/extractor/findTopmostFunction.js +22 -0
  113. package/dist/jsx/extractor/generatedUid.js +27 -0
  114. package/dist/jsx/extractor/getPropValueFromAttributes.js +48 -0
  115. package/dist/jsx/extractor/getSourceModule.js +68 -0
  116. package/dist/jsx/extractor/getStaticBindingsForScope.js +127 -0
  117. package/dist/jsx/extractor/hoistClassNames.js +43 -0
  118. package/dist/jsx/extractor/literalToAst.js +79 -0
  119. package/dist/jsx/extractor/loadTamagui.js +46 -0
  120. package/dist/jsx/extractor/logLines.js +16 -0
  121. package/dist/jsx/extractor/normalizeTernaries.js +52 -0
  122. package/dist/jsx/extractor/removeUnusedHooks.js +79 -0
  123. package/dist/jsx/index.js +13 -0
  124. package/dist/jsx/patchReactNativeWeb.js +128 -0
  125. package/dist/jsx/types.js +0 -0
  126. package/package.json +27 -19
  127. package/types/constants.d.ts +6 -0
  128. package/types/constants.d.ts.map +1 -0
  129. package/types/extractor/accessSafe.d.ts +3 -0
  130. package/types/extractor/accessSafe.d.ts.map +1 -0
  131. package/types/extractor/babelParse.d.ts +5 -0
  132. package/types/extractor/babelParse.d.ts.map +1 -0
  133. package/types/extractor/buildClassName.d.ts +4 -0
  134. package/types/extractor/buildClassName.d.ts.map +1 -0
  135. package/types/extractor/createEvaluator.d.ts +12 -0
  136. package/types/extractor/createEvaluator.d.ts.map +1 -0
  137. package/types/extractor/createExtractor.d.ts +33 -0
  138. package/types/extractor/createExtractor.d.ts.map +1 -0
  139. package/types/extractor/ensureImportingConcat.d.ts +4 -0
  140. package/types/extractor/ensureImportingConcat.d.ts.map +1 -0
  141. package/types/extractor/evaluateAstNode.d.ts +3 -0
  142. package/types/extractor/evaluateAstNode.d.ts.map +1 -0
  143. package/types/extractor/extractHelpers.d.ts +12 -0
  144. package/types/extractor/extractHelpers.d.ts.map +1 -0
  145. package/types/extractor/extractMediaStyle.d.ts +10 -0
  146. package/types/extractor/extractMediaStyle.d.ts.map +1 -0
  147. package/types/extractor/extractToClassNames.d.ts +21 -0
  148. package/types/extractor/extractToClassNames.d.ts.map +1 -0
  149. package/types/extractor/findTopmostFunction.d.ts +4 -0
  150. package/types/extractor/findTopmostFunction.d.ts.map +1 -0
  151. package/types/extractor/generatedUid.d.ts +5 -0
  152. package/types/extractor/generatedUid.d.ts.map +1 -0
  153. package/types/extractor/getPropValueFromAttributes.d.ts +3 -0
  154. package/types/extractor/getPropValueFromAttributes.d.ts.map +1 -0
  155. package/types/extractor/getSourceModule.d.ts +16 -0
  156. package/types/extractor/getSourceModule.d.ts.map +1 -0
  157. package/types/extractor/getStaticBindingsForScope.d.ts +4 -0
  158. package/types/extractor/getStaticBindingsForScope.d.ts.map +1 -0
  159. package/types/extractor/hoistClassNames.d.ts +6 -0
  160. package/types/extractor/hoistClassNames.d.ts.map +1 -0
  161. package/types/extractor/literalToAst.d.ts +4 -0
  162. package/types/extractor/literalToAst.d.ts.map +1 -0
  163. package/types/extractor/loadTamagui.d.ts +9 -0
  164. package/types/extractor/loadTamagui.d.ts.map +1 -0
  165. package/types/extractor/logLines.d.ts +2 -0
  166. package/types/extractor/logLines.d.ts.map +1 -0
  167. package/types/extractor/normalizeTernaries.d.ts +3 -0
  168. package/types/extractor/normalizeTernaries.d.ts.map +1 -0
  169. package/types/extractor/removeUnusedHooks.d.ts +3 -0
  170. package/types/extractor/removeUnusedHooks.d.ts.map +1 -0
  171. package/types/index.d.ts +8 -0
  172. package/types/index.d.ts.map +1 -0
  173. package/types/patchReactNativeWeb.d.ts +2 -0
  174. package/types/patchReactNativeWeb.d.ts.map +1 -0
  175. package/types/types.d.ts +79 -0
  176. package/types/types.d.ts.map +1 -0
  177. package/dist/extractor/createEvaluator.js.map +0 -7
  178. package/dist/extractor/createExtractor.js.map +0 -7
  179. package/dist/extractor/ensureImportingConcat.js.map +0 -7
  180. package/dist/extractor/extractHelpers.js.map +0 -7
  181. package/dist/extractor/extractToClassNames.js.map +0 -7
  182. package/dist/extractor/literalToAst.js +0 -34
  183. package/dist/extractor/literalToAst.js.map +0 -7
  184. package/dist/extractor/loadTamagui.js.map +0 -7
  185. package/dist/index.cjs +0 -2107
  186. package/dist/index.cjs.map +0 -7
  187. package/dist/patchReactNativeWeb.js.map +0 -7
  188. package/src/constants.ts +0 -10
  189. package/src/extractor/accessSafe.ts +0 -18
  190. package/src/extractor/babelParse.ts +0 -27
  191. package/src/extractor/buildClassName.ts +0 -61
  192. package/src/extractor/createEvaluator.ts +0 -68
  193. package/src/extractor/createExtractor.ts +0 -1132
  194. package/src/extractor/ensureImportingConcat.ts +0 -33
  195. package/src/extractor/evaluateAstNode.ts +0 -121
  196. package/src/extractor/extractHelpers.ts +0 -102
  197. package/src/extractor/extractMediaStyle.ts +0 -191
  198. package/src/extractor/extractToClassNames.ts +0 -326
  199. package/src/extractor/findTopmostFunction.ts +0 -22
  200. package/src/extractor/generatedUid.ts +0 -43
  201. package/src/extractor/getPropValueFromAttributes.ts +0 -92
  202. package/src/extractor/getSourceModule.ts +0 -101
  203. package/src/extractor/getStaticBindingsForScope.ts +0 -173
  204. package/src/extractor/hoistClassNames.ts +0 -45
  205. package/src/extractor/literalToAst.ts +0 -32
  206. package/src/extractor/loadTamagui.ts +0 -61
  207. package/src/extractor/normalizeTernaries.ts +0 -60
  208. package/src/extractor/removeUnusedHooks.ts +0 -76
  209. package/src/index.ts +0 -9
  210. package/src/patchReactNativeWeb.ts +0 -123
  211. package/src/types.ts +0 -83
  212. package/types.d.ts +0 -215
@@ -0,0 +1,23 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import * as t from "@babel/types";
4
+ import { CONCAT_CLASSNAME_IMPORT } from "../constants";
5
+ const importConcatPkg = "@tamagui/helpers";
6
+ function ensureImportingConcat(path) {
7
+ const bodyPath = path.get("body");
8
+ const imported = bodyPath.find((x) => x.isImportDeclaration() && x.node.source.value === importConcatPkg);
9
+ const importSpecifier = t.importSpecifier(t.identifier(CONCAT_CLASSNAME_IMPORT), t.identifier(CONCAT_CLASSNAME_IMPORT));
10
+ if (!imported) {
11
+ path.node.body.push(t.importDeclaration([importSpecifier], t.stringLiteral(importConcatPkg)));
12
+ return;
13
+ }
14
+ const specifiers = imported.node.specifiers;
15
+ const alreadyImported = specifiers.some((x) => t.isImportSpecifier(x) && t.isIdentifier(x.imported) && x.imported.name === CONCAT_CLASSNAME_IMPORT);
16
+ if (!alreadyImported) {
17
+ specifiers.push(t.importSpecifier(t.identifier(CONCAT_CLASSNAME_IMPORT), t.identifier(CONCAT_CLASSNAME_IMPORT)));
18
+ }
19
+ }
20
+ __name(ensureImportingConcat, "ensureImportingConcat");
21
+ export {
22
+ ensureImportingConcat
23
+ };
@@ -0,0 +1,93 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import * as t from "@babel/types";
4
+ function evaluateAstNode(exprNode, evalFn, shouldPrintDebug) {
5
+ if (exprNode === void 0) {
6
+ return void 0;
7
+ }
8
+ if (exprNode === null) {
9
+ return true;
10
+ }
11
+ if (t.isJSXExpressionContainer(exprNode)) {
12
+ return evaluateAstNode(exprNode.expression);
13
+ }
14
+ if (t.isObjectExpression(exprNode)) {
15
+ const ret = {};
16
+ for (let idx = -1, len = exprNode.properties.length; ++idx < len; ) {
17
+ const value = exprNode.properties[idx];
18
+ if (!t.isObjectProperty(value)) {
19
+ throw new Error("evaluateAstNode can only evaluate object properties");
20
+ }
21
+ let key;
22
+ if (value.computed) {
23
+ if (typeof evalFn !== "function") {
24
+ throw new Error("evaluateAstNode does not support computed keys unless an eval function is provided");
25
+ }
26
+ key = evaluateAstNode(value.key, evalFn);
27
+ } else if (t.isIdentifier(value.key)) {
28
+ key = value.key.name;
29
+ } else if (t.isStringLiteral(value.key) || t.isNumericLiteral(value.key)) {
30
+ key = value.key.value;
31
+ } else {
32
+ throw new Error("Unsupported key type: " + value.key.type);
33
+ }
34
+ if (typeof key !== "string" && typeof key !== "number") {
35
+ throw new Error("key must be either a string or a number");
36
+ }
37
+ ret[key] = evaluateAstNode(value.value, evalFn);
38
+ }
39
+ return ret;
40
+ }
41
+ if (t.isArrayExpression(exprNode)) {
42
+ return exprNode.elements.map((x) => {
43
+ return evaluateAstNode(x, evalFn);
44
+ });
45
+ }
46
+ if (t.isUnaryExpression(exprNode) && exprNode.operator === "-") {
47
+ const ret = evaluateAstNode(exprNode.argument, evalFn);
48
+ if (ret == null) {
49
+ return null;
50
+ }
51
+ return -ret;
52
+ }
53
+ if (t.isTemplateLiteral(exprNode)) {
54
+ if (typeof evalFn !== "function") {
55
+ throw new Error("evaluateAstNode does not support template literals unless an eval function is provided");
56
+ }
57
+ let ret = "";
58
+ for (let idx = -1, len = exprNode.quasis.length; ++idx < len; ) {
59
+ const quasi = exprNode.quasis[idx];
60
+ const expr = exprNode.expressions[idx];
61
+ ret += quasi.value.raw;
62
+ if (expr) {
63
+ ret += evaluateAstNode(expr, evalFn);
64
+ }
65
+ }
66
+ return ret;
67
+ }
68
+ if (t.isNullLiteral(exprNode)) {
69
+ return null;
70
+ }
71
+ if (t.isNumericLiteral(exprNode) || t.isStringLiteral(exprNode) || t.isBooleanLiteral(exprNode)) {
72
+ return exprNode.value;
73
+ }
74
+ if (t.isBinaryExpression(exprNode)) {
75
+ if (exprNode.operator === "+") {
76
+ return evaluateAstNode(exprNode.left, evalFn) + evaluateAstNode(exprNode.right, evalFn);
77
+ } else if (exprNode.operator === "-") {
78
+ return evaluateAstNode(exprNode.left, evalFn) - evaluateAstNode(exprNode.right, evalFn);
79
+ } else if (exprNode.operator === "*") {
80
+ return evaluateAstNode(exprNode.left, evalFn) * evaluateAstNode(exprNode.right, evalFn);
81
+ } else if (exprNode.operator === "/") {
82
+ return evaluateAstNode(exprNode.left, evalFn) / evaluateAstNode(exprNode.right, evalFn);
83
+ }
84
+ }
85
+ if (typeof evalFn !== "function") {
86
+ throw new Error("evaluateAstNode does not support non-literal values unless an eval function is provided");
87
+ }
88
+ return evalFn(exprNode);
89
+ }
90
+ __name(evaluateAstNode, "evaluateAstNode");
91
+ export {
92
+ evaluateAstNode
93
+ };
@@ -0,0 +1,109 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import * as t from "@babel/types";
4
+ import { astToLiteral } from "./literalToAst";
5
+ function isPresent(input) {
6
+ return input != null;
7
+ }
8
+ __name(isPresent, "isPresent");
9
+ function isSimpleSpread(node) {
10
+ return t.isIdentifier(node.argument) || t.isMemberExpression(node.argument);
11
+ }
12
+ __name(isSimpleSpread, "isSimpleSpread");
13
+ const attrStr = /* @__PURE__ */ __name((attr) => {
14
+ return attr.type === "attr" ? getNameAttr(attr.value) : attr.type === "ternary" ? `...${ternaryStr(attr.value)}` : `${attr.type}(${objToStr(attr.value)})`;
15
+ }, "attrStr");
16
+ const objToStr = /* @__PURE__ */ __name((obj) => {
17
+ return Object.entries(obj).map(([k, v]) => {
18
+ var _a;
19
+ return `${k}:${Array.isArray(v) ? `[...]` : v && typeof v === "object" ? `{${objToStr(v)}}` : (_a = astToLiteral(v)) != null ? _a : JSON.stringify(v)}`;
20
+ }).join(", ");
21
+ }, "objToStr");
22
+ const getNameAttr = /* @__PURE__ */ __name((attr) => {
23
+ if (t.isJSXSpreadAttribute(attr)) {
24
+ return `...${attr.argument["name"]}`;
25
+ }
26
+ return "name" in attr ? attr.name.name : `unknown-${attr["type"]}`;
27
+ }, "getNameAttr");
28
+ const ternaryStr = /* @__PURE__ */ __name((x) => {
29
+ var _a;
30
+ const conditional = t.isIdentifier(x.test) ? x.test.name : t.isMemberExpression(x.test) ? [x.test.object["name"], x.test.property["name"]] : (_a = astToLiteral(x.test)) != null ? _a : [
31
+ x.test["type"],
32
+ astToLiteral(x.test["left"]),
33
+ x.test["operator"],
34
+ astToLiteral(x.test["right"]),
35
+ x.test["value"],
36
+ x.test["name"]
37
+ ].filter((x2) => typeof x2 !== "undefined").join(" ");
38
+ return [
39
+ "ternary(",
40
+ conditional,
41
+ x.consequent ? ` ? ${objToStr(x.consequent)}` : " ? \u{1F6AB}",
42
+ x.alternate ? ` : ${objToStr(x.alternate)}` : " : \u{1F6AB}",
43
+ ")"
44
+ ].flat().join("");
45
+ }, "ternaryStr");
46
+ function findComponentName(scope) {
47
+ var _a;
48
+ let componentName = "";
49
+ let cur = scope.path;
50
+ while (cur.parentPath && !t.isProgram(cur.parentPath.parent)) {
51
+ cur = cur.parentPath;
52
+ }
53
+ let node = cur.parent;
54
+ if (t.isExportNamedDeclaration(node)) {
55
+ node = node.declaration;
56
+ }
57
+ if (t.isVariableDeclaration(node)) {
58
+ const [dec] = node.declarations;
59
+ if (t.isVariableDeclarator(dec) && t.isIdentifier(dec.id)) {
60
+ return dec.id.name;
61
+ }
62
+ }
63
+ if (t.isFunctionDeclaration(node)) {
64
+ return (_a = node.id) == null ? void 0 : _a.name;
65
+ }
66
+ return componentName;
67
+ }
68
+ __name(findComponentName, "findComponentName");
69
+ function isValidThemeHook(jsxPath, n, sourcePath) {
70
+ var _a;
71
+ if (!t.isIdentifier(n.object) || !t.isIdentifier(n.property))
72
+ return false;
73
+ const bindings = jsxPath.scope.getAllBindings();
74
+ const binding = bindings[n.object.name];
75
+ if (!(binding == null ? void 0 : binding.path))
76
+ return false;
77
+ if (!binding.path.isVariableDeclarator())
78
+ return false;
79
+ const init = binding.path.node.init;
80
+ if (!t.isCallExpression(init))
81
+ return false;
82
+ if (!t.isIdentifier(init.callee))
83
+ return false;
84
+ if (init.callee.name !== "useTheme")
85
+ return false;
86
+ const importNode = (_a = binding.scope.getBinding("useTheme")) == null ? void 0 : _a.path.parent;
87
+ if (!t.isImportDeclaration(importNode))
88
+ return false;
89
+ if (importNode.source.value !== "tamagui") {
90
+ if (!isInsideTamagui(sourcePath)) {
91
+ return false;
92
+ }
93
+ }
94
+ return true;
95
+ }
96
+ __name(isValidThemeHook, "isValidThemeHook");
97
+ const isInsideTamagui = /* @__PURE__ */ __name((srcName) => {
98
+ return srcName.includes("/dist/jsx") || srcName.includes("/core/src");
99
+ }, "isInsideTamagui");
100
+ export {
101
+ attrStr,
102
+ findComponentName,
103
+ isInsideTamagui,
104
+ isPresent,
105
+ isSimpleSpread,
106
+ isValidThemeHook,
107
+ objToStr,
108
+ ternaryStr
109
+ };
@@ -0,0 +1,151 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import * as t from "@babel/types";
4
+ import { getStylesAtomic, mediaObjectToString } from "@tamagui/core-node";
5
+ import { MEDIA_SEP } from "../constants";
6
+ import { isInsideTamagui, isPresent } from "./extractHelpers";
7
+ function extractMediaStyle(ternary, jsxPath, tamaguiConfig, sourcePath, importance = 0, shouldPrintDebug = false) {
8
+ const mt = getMediaQueryTernary(ternary, jsxPath, sourcePath);
9
+ if (!mt) {
10
+ return null;
11
+ }
12
+ const { key } = mt;
13
+ const mq = tamaguiConfig.media[key];
14
+ if (!mq) {
15
+ console.error(`Media query "${key}" not found: ${Object.keys(tamaguiConfig.media)}`);
16
+ return null;
17
+ }
18
+ const getStyleObj = /* @__PURE__ */ __name((styleObj, negate = false) => {
19
+ return styleObj ? { styleObj, negate } : null;
20
+ }, "getStyleObj");
21
+ const styleOpts = [
22
+ getStyleObj(ternary.consequent, false),
23
+ getStyleObj(ternary.alternate, true)
24
+ ].filter(isPresent);
25
+ if (shouldPrintDebug && !styleOpts.length) {
26
+ console.log(" media query, no styles?");
27
+ return null;
28
+ }
29
+ const mediaKeys = Object.keys(tamaguiConfig.media);
30
+ const mediaKeyPrecendence = mediaKeys.reduce((acc, cur, i) => {
31
+ acc[cur] = new Array(importance + 1).fill(":root").join("");
32
+ return acc;
33
+ }, {});
34
+ let mediaStyles = [];
35
+ for (const { styleObj, negate } of styleOpts) {
36
+ const styles = getStylesAtomic(styleObj);
37
+ const singleMediaStyles = styles.map((style) => {
38
+ const negKey = negate ? "0" : "";
39
+ const ogPrefix = style.identifier.slice(0, style.identifier.indexOf("-") + 1);
40
+ const identifier = `${style.identifier.replace(ogPrefix, `${ogPrefix}${MEDIA_SEP}${key}${negKey}${MEDIA_SEP}`)}`;
41
+ const className = `.${identifier}`;
42
+ const mediaSelector = mediaObjectToString(tamaguiConfig.media[key]);
43
+ const screenStr = negate ? "not all" : "screen";
44
+ const mediaQuery = `${screenStr} and ${mediaSelector}`;
45
+ const precendencePrefix = mediaKeyPrecendence[key];
46
+ const styleInner = style.rules[0].replace(style.identifier, identifier);
47
+ let styleRule = "";
48
+ if (styleInner.includes("@media")) {
49
+ styleRule = styleInner.replace("{", ` and ${mediaQuery} {`);
50
+ } else {
51
+ styleRule = `@media ${mediaQuery} { ${precendencePrefix} ${styleInner} }`;
52
+ }
53
+ return {
54
+ ...style,
55
+ identifier,
56
+ className,
57
+ rules: [styleRule]
58
+ };
59
+ });
60
+ if (shouldPrintDebug) {
61
+ console.log(" media styles:", importance, singleMediaStyles.map((x) => x.identifier).join(", "));
62
+ }
63
+ mediaStyles = [...mediaStyles, ...singleMediaStyles];
64
+ }
65
+ ternary.remove();
66
+ return { mediaStyles, ternaryWithoutMedia: mt.ternaryWithoutMedia };
67
+ }
68
+ __name(extractMediaStyle, "extractMediaStyle");
69
+ function getMediaQueryTernary(ternary, jsxPath, sourcePath) {
70
+ if (t.isLogicalExpression(ternary.test) && ternary.test.operator === "&&") {
71
+ const mediaLeft = getMediaInfoFromExpression(ternary.test.left, jsxPath, sourcePath, ternary.inlineMediaQuery);
72
+ if (mediaLeft) {
73
+ return {
74
+ ...mediaLeft,
75
+ ternaryWithoutMedia: {
76
+ ...ternary,
77
+ test: ternary.test.right
78
+ }
79
+ };
80
+ }
81
+ }
82
+ const result = getMediaInfoFromExpression(ternary.test, jsxPath, sourcePath, ternary.inlineMediaQuery);
83
+ if (result) {
84
+ return {
85
+ ...result,
86
+ ternaryWithoutMedia: null
87
+ };
88
+ }
89
+ return null;
90
+ }
91
+ __name(getMediaQueryTernary, "getMediaQueryTernary");
92
+ function getMediaInfoFromExpression(test, jsxPath, sourcePath, inlineMediaQuery) {
93
+ var _a, _b, _c;
94
+ if (inlineMediaQuery) {
95
+ return {
96
+ key: inlineMediaQuery,
97
+ bindingName: inlineMediaQuery
98
+ };
99
+ }
100
+ if (t.isMemberExpression(test) && t.isIdentifier(test.object) && t.isIdentifier(test.property)) {
101
+ const name = test.object["name"];
102
+ const key = test.property["name"];
103
+ const bindings = jsxPath.scope.getAllBindings();
104
+ const binding = bindings[name];
105
+ if (!binding)
106
+ return false;
107
+ const bindingNode = (_a = binding.path) == null ? void 0 : _a.node;
108
+ if (!t.isVariableDeclarator(bindingNode) || !bindingNode.init)
109
+ return false;
110
+ if (!isValidMediaCall(jsxPath, bindingNode.init, sourcePath))
111
+ return false;
112
+ return { key, bindingName: name };
113
+ }
114
+ if (t.isIdentifier(test)) {
115
+ const key = test.name;
116
+ const node = (_c = (_b = jsxPath.scope.getBinding(test.name)) == null ? void 0 : _b.path) == null ? void 0 : _c.node;
117
+ if (!t.isVariableDeclarator(node))
118
+ return false;
119
+ if (!node.init || !isValidMediaCall(jsxPath, node.init, sourcePath))
120
+ return false;
121
+ return { key, bindingName: key };
122
+ }
123
+ return null;
124
+ }
125
+ __name(getMediaInfoFromExpression, "getMediaInfoFromExpression");
126
+ function isValidMediaCall(jsxPath, init, sourcePath) {
127
+ if (!t.isCallExpression(init))
128
+ return false;
129
+ if (!t.isIdentifier(init.callee))
130
+ return false;
131
+ if (init.callee.name !== "useMedia")
132
+ return false;
133
+ const bindings = jsxPath.scope.getAllBindings();
134
+ const mediaBinding = bindings["useMedia"];
135
+ if (!mediaBinding)
136
+ return false;
137
+ const useMediaImport = mediaBinding.path.parent;
138
+ if (!t.isImportDeclaration(useMediaImport))
139
+ return false;
140
+ if (useMediaImport.source.value !== "tamagui") {
141
+ if (!isInsideTamagui(sourcePath)) {
142
+ return false;
143
+ }
144
+ }
145
+ return true;
146
+ }
147
+ __name(isValidMediaCall, "isValidMediaCall");
148
+ export {
149
+ extractMediaStyle,
150
+ isValidMediaCall
151
+ };
@@ -0,0 +1,251 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import * as path from "path";
4
+ import { basename } from "path";
5
+ import * as util from "util";
6
+ import generate from "@babel/generator";
7
+ import * as t from "@babel/types";
8
+ import { getStylesAtomic } from "@tamagui/core-node";
9
+ import { concatClassName } from "@tamagui/helpers";
10
+ import invariant from "invariant";
11
+ import { getRemainingRequest } from "loader-utils";
12
+ import { CONCAT_CLASSNAME_IMPORT } from "../constants";
13
+ import { babelParse } from "./babelParse";
14
+ import { buildClassName } from "./buildClassName";
15
+ import { ensureImportingConcat } from "./ensureImportingConcat";
16
+ import { isSimpleSpread } from "./extractHelpers";
17
+ import { extractMediaStyle } from "./extractMediaStyle";
18
+ import { hoistClassNames } from "./hoistClassNames";
19
+ import { logLines } from "./logLines";
20
+ const mergeStyleGroups = {
21
+ shadowOpacity: true,
22
+ shadowRadius: true,
23
+ shadowColor: true,
24
+ shadowOffset: true
25
+ };
26
+ function extractToClassNames({
27
+ loader,
28
+ extractor,
29
+ source,
30
+ sourcePath,
31
+ options,
32
+ shouldPrintDebug,
33
+ threaded,
34
+ cssPath
35
+ }) {
36
+ var _a;
37
+ if (typeof source !== "string") {
38
+ throw new Error("`source` must be a string of javascript");
39
+ }
40
+ invariant(typeof sourcePath === "string" && path.isAbsolute(sourcePath), "`sourcePath` must be an absolute path to a .js file");
41
+ const shouldLogTiming = (_a = options.logTimings) != null ? _a : true;
42
+ const start = Date.now();
43
+ const mem = shouldLogTiming ? process.memoryUsage() : null;
44
+ let ast;
45
+ try {
46
+ ast = babelParse(source);
47
+ } catch (err) {
48
+ console.error("babel parse error:", sourcePath);
49
+ throw err;
50
+ }
51
+ const cssMap = /* @__PURE__ */ new Map();
52
+ const existingHoists = {};
53
+ let hasFlattened = false;
54
+ const res = extractor.parse(ast, {
55
+ sourcePath,
56
+ shouldPrintDebug,
57
+ ...options,
58
+ getFlattenedNode: ({ tag }) => {
59
+ hasFlattened = true;
60
+ return tag;
61
+ },
62
+ onExtractTag: ({
63
+ attrs,
64
+ node,
65
+ attemptEval,
66
+ jsxPath,
67
+ originalNodeName,
68
+ filePath,
69
+ lineNumbers,
70
+ programPath
71
+ }) => {
72
+ let finalClassNames = [];
73
+ let finalAttrs = [];
74
+ let finalStyles = [];
75
+ const viewStyles = {};
76
+ for (const attr of attrs) {
77
+ if (attr.type === "style") {
78
+ Object.assign(viewStyles, attr.value);
79
+ }
80
+ }
81
+ const ensureNeededPrevStyle = /* @__PURE__ */ __name((style) => {
82
+ var _a2;
83
+ const keys = Object.keys(style);
84
+ if (!keys.some((key) => mergeStyleGroups[key])) {
85
+ return style;
86
+ }
87
+ for (const k in mergeStyleGroups) {
88
+ if (k in viewStyles) {
89
+ style[k] = (_a2 = style[k]) != null ? _a2 : viewStyles[k];
90
+ }
91
+ }
92
+ return style;
93
+ }, "ensureNeededPrevStyle");
94
+ const addStyles = /* @__PURE__ */ __name((style) => {
95
+ if (!style)
96
+ return [];
97
+ const styleWithPrev = ensureNeededPrevStyle(style);
98
+ const res2 = getStylesAtomic(styleWithPrev);
99
+ if (res2.length) {
100
+ finalStyles = [...finalStyles, ...res2];
101
+ }
102
+ return res2;
103
+ }, "addStyles");
104
+ let lastMediaImportance = 1;
105
+ for (const attr of attrs) {
106
+ switch (attr.type) {
107
+ case "style":
108
+ const styles2 = addStyles(attr.value);
109
+ const newClassNames = concatClassName(styles2.map((x) => x.identifier).join(" "));
110
+ const existing = finalClassNames.find((x) => x.type == "StringLiteral");
111
+ if (existing) {
112
+ existing.value = `${existing.value} ${newClassNames}`;
113
+ } else {
114
+ finalClassNames = [...finalClassNames, t.stringLiteral(newClassNames)];
115
+ }
116
+ if (shouldPrintDebug) {
117
+ console.log(" classnames (after)\n", logLines(finalClassNames.map((x) => x["value"]).join(" ")));
118
+ }
119
+ break;
120
+ case "attr":
121
+ const val = attr.value;
122
+ if (t.isJSXSpreadAttribute(val)) {
123
+ if (isSimpleSpread(val)) {
124
+ finalClassNames.push(t.logicalExpression("&&", val.argument, t.memberExpression(val.argument, t.identifier("className"))));
125
+ }
126
+ } else if (val.name.name === "className") {
127
+ const value = val.value;
128
+ if (value) {
129
+ try {
130
+ const evaluatedValue = attemptEval(value);
131
+ finalClassNames.push(t.stringLiteral(evaluatedValue));
132
+ } catch (e) {
133
+ finalClassNames.push(value["expression"]);
134
+ }
135
+ }
136
+ continue;
137
+ }
138
+ finalAttrs.push(val);
139
+ break;
140
+ case "ternary":
141
+ const mediaExtraction = extractMediaStyle(attr.value, jsxPath, extractor.getTamagui(), sourcePath, lastMediaImportance, shouldPrintDebug);
142
+ if (shouldPrintDebug) {
143
+ console.log("ternary (mediaExtraction)", mediaExtraction);
144
+ }
145
+ if (mediaExtraction) {
146
+ lastMediaImportance++;
147
+ finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles];
148
+ finalClassNames = [
149
+ ...finalClassNames,
150
+ ...mediaExtraction.mediaStyles.map((x) => t.stringLiteral(x.identifier))
151
+ ];
152
+ if (!mediaExtraction.ternaryWithoutMedia) {
153
+ continue;
154
+ }
155
+ }
156
+ const isMedia = !!(mediaExtraction == null ? void 0 : mediaExtraction.ternaryWithoutMedia);
157
+ const ternary = (mediaExtraction == null ? void 0 : mediaExtraction.ternaryWithoutMedia) || attr.value;
158
+ const consInfo = isMedia ? mediaExtraction.mediaStyles : addStyles(ternary.consequent);
159
+ const altInfo = isMedia ? [] : addStyles(ternary.alternate);
160
+ const cCN = consInfo.map((x) => x.identifier).join(" ");
161
+ const aCN = altInfo.map((x) => x.identifier).join(" ");
162
+ if (consInfo.length && altInfo.length) {
163
+ finalClassNames.push(t.conditionalExpression(ternary.test, t.stringLiteral(cCN), t.stringLiteral(aCN)));
164
+ } else {
165
+ finalClassNames.push(t.conditionalExpression(ternary.test, t.stringLiteral(" " + cCN), t.stringLiteral(" " + aCN)));
166
+ }
167
+ break;
168
+ }
169
+ }
170
+ node.attributes = finalAttrs;
171
+ if (finalClassNames.length) {
172
+ const names = buildClassName(finalClassNames);
173
+ const nameExpr = names ? hoistClassNames(jsxPath, existingHoists, names) : null;
174
+ let expr = nameExpr;
175
+ if (nameExpr && !t.isIdentifier(nameExpr)) {
176
+ if (!hasFlattened) {
177
+ } else {
178
+ ensureImportingConcat(programPath);
179
+ const simpleSpreads = attrs.filter((x) => t.isJSXSpreadAttribute(x.value) && isSimpleSpread(x.value));
180
+ expr = t.callExpression(t.identifier(CONCAT_CLASSNAME_IMPORT), [
181
+ expr,
182
+ ...simpleSpreads.map((val) => val.value["argument"])
183
+ ]);
184
+ }
185
+ }
186
+ node.attributes.push(t.jsxAttribute(t.jsxIdentifier("className"), t.jsxExpressionContainer(expr)));
187
+ }
188
+ const comment = util.format("/* %s:%s (%s) */", filePath, lineNumbers, originalNodeName);
189
+ for (const { className, rules } of finalStyles) {
190
+ if (cssMap.has(className)) {
191
+ if (comment) {
192
+ const val = cssMap.get(className);
193
+ val.commentTexts.push(comment);
194
+ cssMap.set(className, val);
195
+ }
196
+ } else if (rules.length) {
197
+ if (rules.length > 1) {
198
+ console.log(" rules error", { rules });
199
+ throw new Error(`Shouldn't have more than one rule`);
200
+ }
201
+ cssMap.set(className, {
202
+ css: rules[0],
203
+ commentTexts: [comment]
204
+ });
205
+ }
206
+ }
207
+ }
208
+ });
209
+ if (!res || !res.modified && !res.optimized && !res.flattened) {
210
+ if (shouldPrintDebug) {
211
+ console.log("no res or none modified", res);
212
+ }
213
+ return null;
214
+ }
215
+ const styles = Array.from(cssMap.values()).map((x) => x.css).join("\n").trim();
216
+ if (styles) {
217
+ const cssQuery = threaded ? `cssData=${Buffer.from(styles).toString("base64")}` : `cssPath=${cssPath}`;
218
+ const remReq = getRemainingRequest(loader);
219
+ const importPath = `${cssPath}!=!tamagui-loader?${cssQuery}!${remReq}`;
220
+ ast.program.body.unshift(t.importDeclaration([], t.stringLiteral(importPath)));
221
+ }
222
+ const result = generate(ast, {
223
+ concise: false,
224
+ filename: sourcePath,
225
+ retainLines: false,
226
+ sourceFileName: sourcePath,
227
+ sourceMaps: true
228
+ }, source);
229
+ if (shouldPrintDebug) {
230
+ console.log("\n -------- output code ------- \n\n", result.code.split("\n").filter((x) => !x.startsWith("//")).join("\n"));
231
+ console.log("\n -------- output style -------- \n\n", styles);
232
+ }
233
+ if (shouldLogTiming) {
234
+ const memUsed = mem ? Math.round((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204 * 10) / 10 : 0;
235
+ const timing = `${Date.now() - start}`.padStart(3);
236
+ const path2 = basename(sourcePath).padStart(40);
237
+ const numOptimized = `${res.optimized}`.padStart(4);
238
+ const memory = memUsed > 10 ? `used ${memUsed}MB` : "";
239
+ console.log(` \u{1F95A} ${path2} ${timing}ms \u05C1\xB7 ${numOptimized} optimized \xB7 ${res.flattened} flattened ${memory}`);
240
+ }
241
+ return {
242
+ ast,
243
+ styles,
244
+ js: result.code,
245
+ map: result.map
246
+ };
247
+ }
248
+ __name(extractToClassNames, "extractToClassNames");
249
+ export {
250
+ extractToClassNames
251
+ };
@@ -0,0 +1,22 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ function findTopmostFunction(jsxPath) {
4
+ const isFunction = /* @__PURE__ */ __name((path) => path.isArrowFunctionExpression() || path.isFunctionDeclaration() || path.isFunctionExpression(), "isFunction");
5
+ let compFn = jsxPath.findParent(isFunction);
6
+ while (compFn) {
7
+ const parent = compFn.findParent(isFunction);
8
+ if (parent) {
9
+ compFn = parent;
10
+ } else {
11
+ break;
12
+ }
13
+ }
14
+ if (!compFn) {
15
+ return null;
16
+ }
17
+ return compFn;
18
+ }
19
+ __name(findTopmostFunction, "findTopmostFunction");
20
+ export {
21
+ findTopmostFunction
22
+ };
@@ -0,0 +1,27 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import * as t from "@babel/types";
4
+ import invariant from "invariant";
5
+ function generateUid(scope, name) {
6
+ invariant(typeof scope === "object", "generateUid expects a scope object as its first parameter");
7
+ invariant(typeof name === "string" && name !== "", "generateUid expects a valid name as its second parameter");
8
+ name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
9
+ let uid;
10
+ let i = 0;
11
+ do {
12
+ if (i > 1) {
13
+ uid = name + i;
14
+ } else {
15
+ uid = name;
16
+ }
17
+ i++;
18
+ } while (scope.hasLabel(uid) || scope.hasBinding(uid) || scope.hasGlobal(uid) || scope.hasReference(uid));
19
+ const program = scope.getProgramParent();
20
+ program.references[uid] = true;
21
+ program.uids[uid] = true;
22
+ return uid;
23
+ }
24
+ __name(generateUid, "generateUid");
25
+ export {
26
+ generateUid
27
+ };