@tamagui/static 1.0.0-alpha.9 → 1.0.0-beta.147

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 (234) hide show
  1. package/README.md +3 -19
  2. package/dist/cjs/constants.js +36 -0
  3. package/dist/cjs/constants.js.map +7 -0
  4. package/dist/cjs/extractor/accessSafe.js +32 -0
  5. package/dist/cjs/extractor/accessSafe.js.map +7 -0
  6. package/dist/cjs/extractor/babelParse.js +51 -0
  7. package/dist/cjs/extractor/babelParse.js.map +7 -0
  8. package/dist/cjs/extractor/buildClassName.js +61 -0
  9. package/dist/cjs/extractor/buildClassName.js.map +7 -0
  10. package/dist/cjs/extractor/createEvaluator.js +73 -0
  11. package/dist/cjs/extractor/createEvaluator.js.map +7 -0
  12. package/dist/cjs/extractor/createExtractor.js +1170 -0
  13. package/dist/cjs/extractor/createExtractor.js.map +7 -0
  14. package/dist/cjs/extractor/ensureImportingConcat.js +45 -0
  15. package/dist/cjs/extractor/ensureImportingConcat.js.map +7 -0
  16. package/dist/cjs/extractor/evaluateAstNode.js +115 -0
  17. package/dist/cjs/extractor/evaluateAstNode.js.map +7 -0
  18. package/dist/cjs/extractor/extractHelpers.js +124 -0
  19. package/dist/cjs/extractor/extractHelpers.js.map +7 -0
  20. package/dist/cjs/extractor/extractMediaStyle.js +186 -0
  21. package/dist/cjs/extractor/extractMediaStyle.js.map +7 -0
  22. package/dist/cjs/extractor/extractToClassNames.js +322 -0
  23. package/dist/cjs/extractor/extractToClassNames.js.map +7 -0
  24. package/dist/cjs/extractor/findTopmostFunction.js +41 -0
  25. package/dist/cjs/extractor/findTopmostFunction.js.map +7 -0
  26. package/dist/cjs/extractor/generatedUid.js +49 -0
  27. package/dist/cjs/extractor/generatedUid.js.map +7 -0
  28. package/dist/cjs/extractor/getPrefixLogs.js +29 -0
  29. package/dist/cjs/extractor/getPrefixLogs.js.map +7 -0
  30. package/dist/cjs/extractor/getPropValueFromAttributes.js +70 -0
  31. package/dist/cjs/extractor/getPropValueFromAttributes.js.map +7 -0
  32. package/dist/cjs/extractor/getSourceModule.js +90 -0
  33. package/dist/cjs/extractor/getSourceModule.js.map +7 -0
  34. package/dist/cjs/extractor/getStaticBindingsForScope.js +149 -0
  35. package/dist/cjs/extractor/getStaticBindingsForScope.js.map +7 -0
  36. package/dist/cjs/extractor/hoistClassNames.js +65 -0
  37. package/dist/cjs/extractor/hoistClassNames.js.map +7 -0
  38. package/dist/cjs/extractor/literalToAst.js +114 -0
  39. package/dist/cjs/extractor/literalToAst.js.map +7 -0
  40. package/dist/cjs/extractor/loadTamagui.js +83 -0
  41. package/dist/cjs/extractor/loadTamagui.js.map +7 -0
  42. package/dist/cjs/extractor/logLines.js +40 -0
  43. package/dist/cjs/extractor/logLines.js.map +7 -0
  44. package/dist/cjs/extractor/normalizeTernaries.js +101 -0
  45. package/dist/cjs/extractor/normalizeTernaries.js.map +7 -0
  46. package/dist/cjs/extractor/removeUnusedHooks.js +100 -0
  47. package/dist/cjs/extractor/removeUnusedHooks.js.map +7 -0
  48. package/dist/cjs/extractor/validHTMLAttributes.js +71 -0
  49. package/dist/cjs/extractor/validHTMLAttributes.js.map +7 -0
  50. package/dist/cjs/index.js +34 -0
  51. package/dist/cjs/index.js.map +7 -0
  52. package/dist/cjs/patchReactNativeWeb.js +151 -0
  53. package/dist/cjs/patchReactNativeWeb.js.map +7 -0
  54. package/dist/cjs/types.js +16 -0
  55. package/dist/cjs/types.js.map +7 -0
  56. package/dist/{constants.js → esm/constants.js} +4 -0
  57. package/dist/{constants.js.map → esm/constants.js.map} +3 -3
  58. package/dist/{extractor → esm/extractor}/accessSafe.js +0 -0
  59. package/dist/{extractor → esm/extractor}/accessSafe.js.map +2 -2
  60. package/dist/{extractor → esm/extractor}/babelParse.js +0 -0
  61. package/dist/{extractor → esm/extractor}/babelParse.js.map +2 -2
  62. package/dist/{extractor → esm/extractor}/buildClassName.js +0 -0
  63. package/dist/{extractor → esm/extractor}/buildClassName.js.map +2 -2
  64. package/dist/{extractor → esm/extractor}/createEvaluator.js +3 -2
  65. package/dist/esm/extractor/createEvaluator.js.map +7 -0
  66. package/dist/esm/extractor/createExtractor.js +1121 -0
  67. package/dist/esm/extractor/createExtractor.js.map +7 -0
  68. package/dist/{extractor → esm/extractor}/ensureImportingConcat.js +1 -1
  69. package/dist/esm/extractor/ensureImportingConcat.js.map +7 -0
  70. package/dist/{extractor → esm/extractor}/evaluateAstNode.js +0 -0
  71. package/dist/esm/extractor/evaluateAstNode.js.map +7 -0
  72. package/dist/{extractor → esm/extractor}/extractHelpers.js +20 -11
  73. package/dist/esm/extractor/extractHelpers.js.map +7 -0
  74. package/dist/{extractor → esm/extractor}/extractMediaStyle.js +5 -4
  75. package/dist/esm/extractor/extractMediaStyle.js.map +7 -0
  76. package/dist/{extractor → esm/extractor}/extractToClassNames.js +97 -44
  77. package/dist/esm/extractor/extractToClassNames.js.map +7 -0
  78. package/dist/{extractor → esm/extractor}/findTopmostFunction.js +0 -0
  79. package/dist/{extractor → esm/extractor}/findTopmostFunction.js.map +2 -2
  80. package/dist/{extractor → esm/extractor}/generatedUid.js +0 -0
  81. package/dist/{extractor → esm/extractor}/generatedUid.js.map +2 -2
  82. package/dist/esm/extractor/getPrefixLogs.js +12 -0
  83. package/dist/esm/extractor/getPrefixLogs.js.map +7 -0
  84. package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js +0 -0
  85. package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js.map +2 -2
  86. package/dist/{extractor → esm/extractor}/getSourceModule.js +0 -0
  87. package/dist/{extractor → esm/extractor}/getSourceModule.js.map +2 -2
  88. package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js +0 -0
  89. package/dist/esm/extractor/getStaticBindingsForScope.js.map +7 -0
  90. package/dist/{extractor → esm/extractor}/hoistClassNames.js +0 -0
  91. package/dist/{extractor → esm/extractor}/hoistClassNames.js.map +2 -2
  92. package/dist/esm/extractor/literalToAst.js +80 -0
  93. package/dist/esm/extractor/literalToAst.js.map +7 -0
  94. package/dist/{extractor → esm/extractor}/loadTamagui.js +27 -3
  95. package/dist/esm/extractor/loadTamagui.js.map +7 -0
  96. package/dist/{extractor → esm/extractor}/logLines.js +8 -3
  97. package/dist/esm/extractor/logLines.js.map +7 -0
  98. package/dist/{extractor → esm/extractor}/normalizeTernaries.js +3 -2
  99. package/dist/esm/extractor/normalizeTernaries.js.map +7 -0
  100. package/dist/{extractor → esm/extractor}/removeUnusedHooks.js +5 -3
  101. package/dist/esm/extractor/removeUnusedHooks.js.map +7 -0
  102. package/dist/esm/extractor/validHTMLAttributes.js +52 -0
  103. package/dist/esm/extractor/validHTMLAttributes.js.map +7 -0
  104. package/dist/{index.js → esm/index.js} +0 -0
  105. package/dist/{index.js.map → esm/index.js.map} +1 -1
  106. package/dist/{patchReactNativeWeb.js → esm/patchReactNativeWeb.js} +37 -14
  107. package/dist/esm/patchReactNativeWeb.js.map +7 -0
  108. package/dist/{types.js → esm/types.js} +0 -0
  109. package/dist/{types.js.map → esm/types.js.map} +0 -0
  110. package/dist/jsx/constants.js +13 -0
  111. package/dist/jsx/extractor/accessSafe.js +10 -0
  112. package/dist/jsx/extractor/babelParse.js +29 -0
  113. package/dist/jsx/extractor/buildClassName.js +39 -0
  114. package/dist/jsx/extractor/createEvaluator.js +51 -0
  115. package/dist/jsx/extractor/createExtractor.js +1120 -0
  116. package/dist/jsx/extractor/ensureImportingConcat.js +23 -0
  117. package/dist/jsx/extractor/evaluateAstNode.js +93 -0
  118. package/dist/jsx/extractor/extractHelpers.js +102 -0
  119. package/dist/jsx/extractor/extractMediaStyle.js +151 -0
  120. package/dist/jsx/extractor/extractToClassNames.js +285 -0
  121. package/dist/jsx/extractor/findTopmostFunction.js +22 -0
  122. package/dist/jsx/extractor/generatedUid.js +27 -0
  123. package/dist/jsx/extractor/getPrefixLogs.js +11 -0
  124. package/dist/jsx/extractor/getPropValueFromAttributes.js +48 -0
  125. package/dist/jsx/extractor/getSourceModule.js +68 -0
  126. package/dist/jsx/extractor/getStaticBindingsForScope.js +127 -0
  127. package/dist/jsx/extractor/hoistClassNames.js +43 -0
  128. package/dist/jsx/extractor/literalToAst.js +79 -0
  129. package/dist/jsx/extractor/loadTamagui.js +64 -0
  130. package/dist/jsx/extractor/logLines.js +21 -0
  131. package/dist/jsx/extractor/normalizeTernaries.js +52 -0
  132. package/dist/jsx/extractor/removeUnusedHooks.js +79 -0
  133. package/dist/jsx/extractor/validHTMLAttributes.js +51 -0
  134. package/dist/jsx/index.js +13 -0
  135. package/{src/patchReactNativeWeb.ts → dist/jsx/patchReactNativeWeb.js} +65 -59
  136. package/dist/jsx/types.js +0 -0
  137. package/package.json +27 -24
  138. package/types/constants.d.ts +6 -0
  139. package/types/constants.d.ts.map +1 -0
  140. package/types/extractor/accessSafe.d.ts +3 -0
  141. package/types/extractor/accessSafe.d.ts.map +1 -0
  142. package/types/extractor/babelParse.d.ts +5 -0
  143. package/types/extractor/babelParse.d.ts.map +1 -0
  144. package/types/extractor/buildClassName.d.ts +4 -0
  145. package/types/extractor/buildClassName.d.ts.map +1 -0
  146. package/types/extractor/createEvaluator.d.ts +12 -0
  147. package/types/extractor/createEvaluator.d.ts.map +1 -0
  148. package/types/extractor/createExtractor.d.ts +27 -0
  149. package/types/extractor/createExtractor.d.ts.map +1 -0
  150. package/types/extractor/ensureImportingConcat.d.ts +4 -0
  151. package/types/extractor/ensureImportingConcat.d.ts.map +1 -0
  152. package/types/extractor/evaluateAstNode.d.ts +3 -0
  153. package/types/extractor/evaluateAstNode.d.ts.map +1 -0
  154. package/types/extractor/extractHelpers.d.ts +12 -0
  155. package/types/extractor/extractHelpers.d.ts.map +1 -0
  156. package/types/extractor/extractMediaStyle.d.ts +10 -0
  157. package/types/extractor/extractMediaStyle.d.ts.map +1 -0
  158. package/types/extractor/extractToClassNames.d.ts +23 -0
  159. package/types/extractor/extractToClassNames.d.ts.map +1 -0
  160. package/types/extractor/findTopmostFunction.d.ts +4 -0
  161. package/types/extractor/findTopmostFunction.d.ts.map +1 -0
  162. package/types/extractor/generatedUid.d.ts +5 -0
  163. package/types/extractor/generatedUid.d.ts.map +1 -0
  164. package/types/extractor/getPrefixLogs.d.ts +3 -0
  165. package/types/extractor/getPrefixLogs.d.ts.map +1 -0
  166. package/types/extractor/getPropValueFromAttributes.d.ts +3 -0
  167. package/types/extractor/getPropValueFromAttributes.d.ts.map +1 -0
  168. package/types/extractor/getSourceModule.d.ts +16 -0
  169. package/types/extractor/getSourceModule.d.ts.map +1 -0
  170. package/types/extractor/getStaticBindingsForScope.d.ts +4 -0
  171. package/types/extractor/getStaticBindingsForScope.d.ts.map +1 -0
  172. package/types/extractor/hoistClassNames.d.ts +6 -0
  173. package/types/extractor/hoistClassNames.d.ts.map +1 -0
  174. package/types/extractor/literalToAst.d.ts +4 -0
  175. package/types/extractor/literalToAst.d.ts.map +1 -0
  176. package/types/extractor/loadTamagui.d.ts +9 -0
  177. package/types/extractor/loadTamagui.d.ts.map +1 -0
  178. package/types/extractor/logLines.d.ts +2 -0
  179. package/types/extractor/logLines.d.ts.map +1 -0
  180. package/types/extractor/normalizeTernaries.d.ts +3 -0
  181. package/types/extractor/normalizeTernaries.d.ts.map +1 -0
  182. package/types/extractor/removeUnusedHooks.d.ts +3 -0
  183. package/types/extractor/removeUnusedHooks.d.ts.map +1 -0
  184. package/types/extractor/validHTMLAttributes.d.ts +49 -0
  185. package/types/extractor/validHTMLAttributes.d.ts.map +1 -0
  186. package/types/index.d.ts +8 -0
  187. package/types/index.d.ts.map +1 -0
  188. package/types/patchReactNativeWeb.d.ts +2 -0
  189. package/types/patchReactNativeWeb.d.ts.map +1 -0
  190. package/types/types.d.ts +85 -0
  191. package/types/types.d.ts.map +1 -0
  192. package/dist/extractor/createEvaluator.js.map +0 -7
  193. package/dist/extractor/createExtractor.js +0 -828
  194. package/dist/extractor/createExtractor.js.map +0 -7
  195. package/dist/extractor/ensureImportingConcat.js.map +0 -7
  196. package/dist/extractor/evaluateAstNode.js.map +0 -7
  197. package/dist/extractor/extractHelpers.js.map +0 -7
  198. package/dist/extractor/extractMediaStyle.js.map +0 -7
  199. package/dist/extractor/extractToClassNames.js.map +0 -7
  200. package/dist/extractor/getStaticBindingsForScope.js.map +0 -7
  201. package/dist/extractor/literalToAst.js +0 -34
  202. package/dist/extractor/literalToAst.js.map +0 -7
  203. package/dist/extractor/loadTamagui.js.map +0 -7
  204. package/dist/extractor/logLines.js.map +0 -7
  205. package/dist/extractor/normalizeTernaries.js.map +0 -7
  206. package/dist/extractor/removeUnusedHooks.js.map +0 -7
  207. package/dist/index.cjs +0 -2126
  208. package/dist/index.cjs.map +0 -7
  209. package/dist/patchReactNativeWeb.js.map +0 -7
  210. package/src/constants.ts +0 -10
  211. package/src/extractor/accessSafe.ts +0 -18
  212. package/src/extractor/babelParse.ts +0 -27
  213. package/src/extractor/buildClassName.ts +0 -61
  214. package/src/extractor/createEvaluator.ts +0 -68
  215. package/src/extractor/createExtractor.ts +0 -1138
  216. package/src/extractor/ensureImportingConcat.ts +0 -33
  217. package/src/extractor/evaluateAstNode.ts +0 -121
  218. package/src/extractor/extractHelpers.ts +0 -102
  219. package/src/extractor/extractMediaStyle.ts +0 -191
  220. package/src/extractor/extractToClassNames.ts +0 -323
  221. package/src/extractor/findTopmostFunction.ts +0 -22
  222. package/src/extractor/generatedUid.ts +0 -43
  223. package/src/extractor/getPropValueFromAttributes.ts +0 -92
  224. package/src/extractor/getSourceModule.ts +0 -101
  225. package/src/extractor/getStaticBindingsForScope.ts +0 -173
  226. package/src/extractor/hoistClassNames.ts +0 -45
  227. package/src/extractor/literalToAst.ts +0 -32
  228. package/src/extractor/loadTamagui.ts +0 -61
  229. package/src/extractor/logLines.ts +0 -11
  230. package/src/extractor/normalizeTernaries.ts +0 -60
  231. package/src/extractor/removeUnusedHooks.ts +0 -76
  232. package/src/index.ts +0 -9
  233. package/src/types.ts +0 -89
  234. package/types.d.ts +0 -219
@@ -0,0 +1,1121 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import traverse from "@babel/traverse";
4
+ import * as t from "@babel/types";
5
+ import {
6
+ getSplitStyles,
7
+ mediaQueryConfig,
8
+ pseudos,
9
+ rnw
10
+ } from "@tamagui/core-node";
11
+ import { difference, pick } from "lodash";
12
+ import { FAILED_EVAL } from "../constants";
13
+ import { createEvaluator, createSafeEvaluator } from "./createEvaluator";
14
+ import { evaluateAstNode } from "./evaluateAstNode";
15
+ import { attrStr, findComponentName, isInsideTamagui, isPresent, objToStr } from "./extractHelpers";
16
+ import { findTopmostFunction } from "./findTopmostFunction";
17
+ import { getStaticBindingsForScope } from "./getStaticBindingsForScope";
18
+ import { literalToAst } from "./literalToAst";
19
+ import { loadTamagui } from "./loadTamagui";
20
+ import { logLines } from "./logLines";
21
+ import { normalizeTernaries } from "./normalizeTernaries";
22
+ import { removeUnusedHooks } from "./removeUnusedHooks";
23
+ import { validHTMLAttributes } from "./validHTMLAttributes";
24
+ const UNTOUCHED_PROPS = {
25
+ key: true,
26
+ style: true,
27
+ className: true
28
+ };
29
+ const INLINE_EXTRACTABLE = {
30
+ ref: "ref",
31
+ key: "key",
32
+ onPress: "onClick",
33
+ onHoverIn: "onMouseEnter",
34
+ onHoverOut: "onMouseLeave",
35
+ onPressIn: "onMouseDown",
36
+ onPressOut: "onMouseUp"
37
+ };
38
+ const isAttr = /* @__PURE__ */ __name((x) => x.type === "attr", "isAttr");
39
+ const validHooks = {
40
+ useMedia: true,
41
+ useTheme: true
42
+ };
43
+ const createTernary = /* @__PURE__ */ __name((x) => x, "createTernary");
44
+ function createExtractor() {
45
+ if (!process.env.TAMAGUI_TARGET) {
46
+ console.log('\u26A0\uFE0F Please set process.env.TAMAGUI_TARGET to either "web" or "native"');
47
+ process.exit(1);
48
+ }
49
+ const shouldAddDebugProp = !process.env.npm_package_dependencies_next && process.env.TAMAGUI_TARGET !== "native" && process.env.IDENTIFY_TAGS !== "false" && (process.env.NODE_ENV === "development" || process.env.DEBUG || process.env.IDENTIFY_TAGS);
50
+ require("esbuild-register/dist/node").register({
51
+ target: "es2019",
52
+ format: "cjs"
53
+ });
54
+ let loadedTamaguiConfig;
55
+ let hasLogged = false;
56
+ return {
57
+ getTamagui() {
58
+ return loadedTamaguiConfig;
59
+ },
60
+ parse: (fileOrPath, {
61
+ config = "tamagui.config.ts",
62
+ importsWhitelist = ["constants.js"],
63
+ evaluateVars = true,
64
+ shouldPrintDebug = false,
65
+ sourcePath = "",
66
+ onExtractTag,
67
+ getFlattenedNode,
68
+ disable,
69
+ disableExtraction,
70
+ disableExtractInlineMedia,
71
+ disableExtractVariables,
72
+ disableDebugAttr,
73
+ prefixLogs,
74
+ excludeProps,
75
+ ...props
76
+ }) => {
77
+ if (disable) {
78
+ return null;
79
+ }
80
+ if (sourcePath === "") {
81
+ throw new Error(`Must provide a source file name`);
82
+ }
83
+ if (!Array.isArray(props.components)) {
84
+ throw new Error(`Must provide components array with list of Tamagui component modules`);
85
+ }
86
+ const { components, tamaguiConfig } = loadTamagui({
87
+ config,
88
+ components: props.components || ["tamagui"]
89
+ });
90
+ loadedTamaguiConfig = tamaguiConfig;
91
+ const defaultTheme = tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]];
92
+ const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
93
+ const isInternalImport = /* @__PURE__ */ __name((importStr) => {
94
+ return isInsideTamagui(sourcePath) && importStr[0] === ".";
95
+ }, "isInternalImport");
96
+ const validComponents = Object.keys(components).filter((key) => {
97
+ var _a;
98
+ return key[0].toUpperCase() === key[0] && !!((_a = components[key]) == null ? void 0 : _a.staticConfig);
99
+ }).reduce((obj, name) => {
100
+ obj[name] = components[name];
101
+ return obj;
102
+ }, {});
103
+ let doesUseValidImport = false;
104
+ let hasImportedTheme = false;
105
+ for (const bodyPath of body) {
106
+ if (bodyPath.type !== "ImportDeclaration")
107
+ continue;
108
+ const node = "node" in bodyPath ? bodyPath.node : bodyPath;
109
+ const from = node.source.value;
110
+ if (props.components.includes(from) || isInternalImport(from)) {
111
+ if (node.specifiers.some((specifier) => {
112
+ const name = specifier.local.name;
113
+ return validComponents[name] || validHooks[name];
114
+ })) {
115
+ doesUseValidImport = true;
116
+ break;
117
+ }
118
+ }
119
+ }
120
+ if (shouldPrintDebug) {
121
+ console.log(sourcePath, { doesUseValidImport });
122
+ }
123
+ if (!doesUseValidImport) {
124
+ return null;
125
+ }
126
+ let couldntParse = false;
127
+ const modifiedComponents = /* @__PURE__ */ new Set();
128
+ const bindingCache = {};
129
+ const callTraverse = /* @__PURE__ */ __name((a) => {
130
+ return fileOrPath.type === "File" ? traverse(fileOrPath, a) : fileOrPath.traverse(a);
131
+ }, "callTraverse");
132
+ let programPath;
133
+ const res = {
134
+ flattened: 0,
135
+ optimized: 0,
136
+ modified: 0,
137
+ found: 0
138
+ };
139
+ callTraverse({
140
+ Program: {
141
+ enter(path) {
142
+ programPath = path;
143
+ }
144
+ },
145
+ JSXElement(traversePath) {
146
+ var _a, _b, _c, _d, _e;
147
+ const node = traversePath.node.openingElement;
148
+ const ogAttributes = node.attributes;
149
+ const componentName = findComponentName(traversePath.scope);
150
+ const closingElement = traversePath.node.closingElement;
151
+ if (t.isJSXMemberExpression(closingElement == null ? void 0 : closingElement.name) || !t.isJSXIdentifier(node.name)) {
152
+ return;
153
+ }
154
+ const binding = traversePath.scope.getBinding(node.name.name);
155
+ if (binding) {
156
+ if (!t.isImportDeclaration(binding.path.parent)) {
157
+ return;
158
+ }
159
+ const source = binding.path.parent.source;
160
+ if (!props.components.includes(source.value) && !isInternalImport(source.value)) {
161
+ return;
162
+ }
163
+ if (!validComponents[binding.identifier.name]) {
164
+ return;
165
+ }
166
+ }
167
+ const component = validComponents[node.name.name];
168
+ if (!component || !component.staticConfig) {
169
+ return;
170
+ }
171
+ const originalNodeName = node.name.name;
172
+ res.found++;
173
+ const filePath = sourcePath.replace(process.cwd(), ".");
174
+ const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
175
+ const preName = componentName ? `${componentName}.` : "";
176
+ const tagId = `${preName}${node.name.name}@${filePath.replace("./", "")}:${lineNumbers}`;
177
+ const hasBooleanDebugTrue = node.attributes.some((n) => t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && n.name.name === "debug" && n.value === null);
178
+ if (hasBooleanDebugTrue) {
179
+ shouldPrintDebug = true;
180
+ }
181
+ try {
182
+ let isValidStyleKey = function(name) {
183
+ var _a2;
184
+ return !!(!!validStyles[name] || !!pseudos[name] || ((_a2 = staticConfig.variants) == null ? void 0 : _a2[name]) || tamaguiConfig.shorthands[name] || (name[0] === "$" ? !!mediaQueryConfig[name.slice(1)] : false));
185
+ }, evaluateAttribute = function(path) {
186
+ const attribute = path.node;
187
+ const attr = { type: "attr", value: attribute };
188
+ if (t.isJSXSpreadAttribute(attribute)) {
189
+ const arg = attribute.argument;
190
+ const conditional = t.isConditionalExpression(arg) ? [arg.test, arg.consequent, arg.alternate] : t.isLogicalExpression(arg) && arg.operator === "&&" ? [arg.left, arg.right, null] : null;
191
+ if (conditional) {
192
+ const [test, alt, cons] = conditional;
193
+ if (!test)
194
+ throw new Error(`no test`);
195
+ if ([alt, cons].some((side) => side && !isExtractable(side))) {
196
+ if (shouldPrintDebug) {
197
+ console.log("not extractable", alt, cons);
198
+ }
199
+ return attr;
200
+ }
201
+ return [
202
+ ...createTernariesFromObjectProperties(test, alt) || [],
203
+ ...cons && createTernariesFromObjectProperties(t.unaryExpression("!", test), cons) || []
204
+ ].map((ternary) => ({
205
+ type: "ternary",
206
+ value: ternary
207
+ }));
208
+ }
209
+ }
210
+ if (t.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name !== "string") {
211
+ if (shouldPrintDebug) {
212
+ console.log(" ! inlining, spread attr");
213
+ }
214
+ inlined.set(`${Math.random()}`, "spread");
215
+ return attr;
216
+ }
217
+ const name = attribute.name.name;
218
+ if (excludeProps == null ? void 0 : excludeProps.has(name)) {
219
+ if (shouldPrintDebug) {
220
+ console.log(" excluding prop", name);
221
+ }
222
+ return null;
223
+ }
224
+ if (inlineProps.has(name)) {
225
+ inlined.set(name, name);
226
+ if (shouldPrintDebug) {
227
+ console.log(" ! inlining, inline prop", name);
228
+ }
229
+ return attr;
230
+ }
231
+ if (deoptProps.has(name)) {
232
+ shouldDeopt = true;
233
+ inlined.set(name, name);
234
+ if (shouldPrintDebug) {
235
+ console.log(" ! inlining, deopted prop", name);
236
+ }
237
+ return attr;
238
+ }
239
+ if (UNTOUCHED_PROPS[name]) {
240
+ return attr;
241
+ }
242
+ if (INLINE_EXTRACTABLE[name]) {
243
+ inlined.set(name, INLINE_EXTRACTABLE[name]);
244
+ return attr;
245
+ }
246
+ if (name.startsWith("data-")) {
247
+ return attr;
248
+ }
249
+ if (name[0] === "$" && t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
250
+ if (disableExtractInlineMedia) {
251
+ return attr;
252
+ }
253
+ const shortname = name.slice(1);
254
+ if (mediaQueryConfig[shortname]) {
255
+ const expression = attribute.value.expression;
256
+ if (!t.isJSXEmptyExpression(expression)) {
257
+ const ternaries2 = createTernariesFromObjectProperties(t.stringLiteral(shortname), expression, {
258
+ inlineMediaQuery: shortname
259
+ });
260
+ if (ternaries2) {
261
+ return ternaries2.map((value2) => ({
262
+ type: "ternary",
263
+ value: value2
264
+ }));
265
+ }
266
+ }
267
+ }
268
+ }
269
+ const [value, valuePath] = (() => {
270
+ if (t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
271
+ return [attribute.value.expression, path.get("value")];
272
+ } else {
273
+ return [attribute.value, path.get("value")];
274
+ }
275
+ })();
276
+ const remove = /* @__PURE__ */ __name(() => {
277
+ Array.isArray(valuePath) ? valuePath.map((p) => p.remove()) : valuePath.remove();
278
+ }, "remove");
279
+ if (name === "ref") {
280
+ if (shouldPrintDebug) {
281
+ console.log(" ! inlining, ref", name);
282
+ }
283
+ inlined.set("ref", "ref");
284
+ return attr;
285
+ }
286
+ if (name === "tag") {
287
+ return {
288
+ type: "attr",
289
+ value: path.node
290
+ };
291
+ }
292
+ if (disableExtractVariables) {
293
+ if (value) {
294
+ if (value.type === "StringLiteral" && value.value[0] === "$") {
295
+ if (shouldPrintDebug) {
296
+ console.log(` ! inlining, native disable extract: ${name} =`, value.value);
297
+ }
298
+ inlined.set(name, true);
299
+ return attr;
300
+ }
301
+ }
302
+ }
303
+ const styleValue = attemptEvalSafe(value);
304
+ if (!isValidStyleKey(name)) {
305
+ let keys = [name];
306
+ let out = null;
307
+ if (staticConfig.propMapper) {
308
+ out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, "auto");
309
+ if (out) {
310
+ out = rnw.createDOMProps(isTextView ? "span" : "div", out);
311
+ delete out.className;
312
+ keys = Object.keys(out);
313
+ }
314
+ }
315
+ let didInline = false;
316
+ const attributes = keys.map((key) => {
317
+ const val = out[key];
318
+ if (key === "theme") {
319
+ inlined.set(key, val);
320
+ return attr;
321
+ }
322
+ if (isValidStyleKey(key)) {
323
+ return {
324
+ type: "style",
325
+ value: { [name]: styleValue },
326
+ name,
327
+ attr: path.node
328
+ };
329
+ }
330
+ if (validHTMLAttributes[key]) {
331
+ return attr;
332
+ }
333
+ if (shouldPrintDebug) {
334
+ console.log(" ! inlining, non-static", key);
335
+ }
336
+ didInline = true;
337
+ inlined.set(key, val);
338
+ return val;
339
+ });
340
+ if (didInline) {
341
+ if (shouldPrintDebug) {
342
+ console.log(" bailing flattening due to attributes", attributes);
343
+ }
344
+ return attr;
345
+ }
346
+ return attributes;
347
+ }
348
+ if (styleValue !== FAILED_EVAL) {
349
+ if (isValidStyleKey(name)) {
350
+ if (shouldPrintDebug) {
351
+ console.log(` style: ${name} =`, styleValue);
352
+ }
353
+ if (!(name in staticConfig.defaultProps)) {
354
+ if (!hasSetOptimized) {
355
+ res.optimized++;
356
+ hasSetOptimized = true;
357
+ }
358
+ }
359
+ return {
360
+ type: "style",
361
+ value: { [name]: styleValue },
362
+ name,
363
+ attr: path.node
364
+ };
365
+ } else {
366
+ inlined.set(name, true);
367
+ return attr;
368
+ }
369
+ }
370
+ if (t.isBinaryExpression(value)) {
371
+ if (shouldPrintDebug) {
372
+ console.log(` binary expression ${name} = `, value);
373
+ }
374
+ const { operator, left, right } = value;
375
+ const lVal = attemptEvalSafe(left);
376
+ const rVal = attemptEvalSafe(right);
377
+ if (shouldPrintDebug) {
378
+ console.log(` evalBinaryExpression lVal ${String(lVal)}, rVal ${String(rVal)}`);
379
+ }
380
+ if (lVal !== FAILED_EVAL && t.isConditionalExpression(right)) {
381
+ const ternary = addBinaryConditional(operator, left, right);
382
+ if (ternary)
383
+ return ternary;
384
+ }
385
+ if (rVal !== FAILED_EVAL && t.isConditionalExpression(left)) {
386
+ const ternary = addBinaryConditional(operator, right, left);
387
+ if (ternary)
388
+ return ternary;
389
+ }
390
+ if (shouldPrintDebug) {
391
+ console.log(` evalBinaryExpression cant extract`);
392
+ }
393
+ inlined.set(name, true);
394
+ return attr;
395
+ }
396
+ const staticConditional = getStaticConditional(value);
397
+ if (staticConditional) {
398
+ if (shouldPrintDebug) {
399
+ console.log(` static conditional ${name} = `, value);
400
+ }
401
+ return { type: "ternary", value: staticConditional };
402
+ }
403
+ const staticLogical = getStaticLogical(value);
404
+ if (staticLogical) {
405
+ if (shouldPrintDebug) {
406
+ console.log(` static ternary ${name} = `, value);
407
+ }
408
+ return { type: "ternary", value: staticLogical };
409
+ }
410
+ inlined.set(name, true);
411
+ if (shouldPrintDebug) {
412
+ console.log(` ! inline no match ${name}`, value);
413
+ }
414
+ return attr;
415
+ function addBinaryConditional(operator, staticExpr, cond) {
416
+ if (getStaticConditional(cond)) {
417
+ const alt = attemptEval(t.binaryExpression(operator, staticExpr, cond.alternate));
418
+ const cons = attemptEval(t.binaryExpression(operator, staticExpr, cond.consequent));
419
+ if (shouldPrintDebug) {
420
+ console.log(" binaryConditional", cond.test, cons, alt);
421
+ }
422
+ return {
423
+ type: "ternary",
424
+ value: {
425
+ test: cond.test,
426
+ remove,
427
+ alternate: { [name]: alt },
428
+ consequent: { [name]: cons }
429
+ }
430
+ };
431
+ }
432
+ return null;
433
+ }
434
+ __name(addBinaryConditional, "addBinaryConditional");
435
+ function getStaticConditional(value2) {
436
+ if (t.isConditionalExpression(value2)) {
437
+ try {
438
+ if (shouldPrintDebug) {
439
+ console.log("attempt", value2.alternate, value2.consequent);
440
+ }
441
+ const aVal = attemptEval(value2.alternate);
442
+ const cVal = attemptEval(value2.consequent);
443
+ if (shouldPrintDebug) {
444
+ const type = value2.test.type;
445
+ console.log(" static ternary", type, cVal, aVal);
446
+ }
447
+ return {
448
+ test: value2.test,
449
+ remove,
450
+ consequent: { [name]: cVal },
451
+ alternate: { [name]: aVal }
452
+ };
453
+ } catch (err) {
454
+ if (shouldPrintDebug) {
455
+ console.log(" cant eval ternary", err.message);
456
+ }
457
+ }
458
+ }
459
+ return null;
460
+ }
461
+ __name(getStaticConditional, "getStaticConditional");
462
+ function getStaticLogical(value2) {
463
+ if (t.isLogicalExpression(value2)) {
464
+ if (value2.operator === "&&") {
465
+ try {
466
+ const val = attemptEval(value2.right);
467
+ if (shouldPrintDebug) {
468
+ console.log(" staticLogical", value2.left, name, val);
469
+ }
470
+ return {
471
+ test: value2.left,
472
+ remove,
473
+ consequent: { [name]: val },
474
+ alternate: null
475
+ };
476
+ } catch (err) {
477
+ if (shouldPrintDebug) {
478
+ console.log(" cant static eval logical", err);
479
+ }
480
+ }
481
+ }
482
+ }
483
+ return null;
484
+ }
485
+ __name(getStaticLogical, "getStaticLogical");
486
+ }, isExtractable = function(obj) {
487
+ return t.isObjectExpression(obj) && obj.properties.every((prop) => {
488
+ if (!t.isObjectProperty(prop)) {
489
+ console.log("not object prop", prop);
490
+ return false;
491
+ }
492
+ const propName = prop.key["name"];
493
+ if (!isValidStyleKey(propName) && propName !== "tag") {
494
+ if (shouldPrintDebug) {
495
+ console.log(" not a valid style prop!", propName);
496
+ }
497
+ return false;
498
+ }
499
+ return true;
500
+ });
501
+ }, createTernariesFromObjectProperties = function(test, side, ternaryPartial = {}) {
502
+ if (!side) {
503
+ return null;
504
+ }
505
+ if (!isExtractable(side)) {
506
+ throw new Error("not extractable");
507
+ }
508
+ return side.properties.flatMap((property) => {
509
+ if (!t.isObjectProperty(property)) {
510
+ throw new Error("expected object property");
511
+ }
512
+ if (t.isIdentifier(property.key)) {
513
+ const key = property.key.name;
514
+ const mediaQueryKey = key.slice(1);
515
+ const isMediaQuery = key[0] === "$" && mediaQueryConfig[mediaQueryKey];
516
+ if (isMediaQuery) {
517
+ if (t.isExpression(property.value)) {
518
+ const ternaries2 = createTernariesFromObjectProperties(t.stringLiteral(mediaQueryKey), property.value, {
519
+ inlineMediaQuery: mediaQueryKey
520
+ });
521
+ if (ternaries2) {
522
+ return ternaries2.map((value) => ({
523
+ ...ternaryPartial,
524
+ ...value,
525
+ test: t.logicalExpression("&&", value.test, test)
526
+ }));
527
+ } else {
528
+ console.log("\u26A0\uFE0F no ternaries?", property);
529
+ }
530
+ } else {
531
+ console.log("\u26A0\uFE0F not expression", property);
532
+ }
533
+ }
534
+ }
535
+ if (t.isConditionalExpression(property.value)) {
536
+ const [truthy, falsy] = [
537
+ t.objectExpression([t.objectProperty(property.key, property.value.consequent)]),
538
+ t.objectExpression([t.objectProperty(property.key, property.value.alternate)])
539
+ ].map((x) => attemptEval(x));
540
+ return [
541
+ createTernary({
542
+ remove() {
543
+ },
544
+ ...ternaryPartial,
545
+ test: t.logicalExpression("&&", test, property.value.test),
546
+ consequent: truthy,
547
+ alternate: null
548
+ }),
549
+ createTernary({
550
+ ...ternaryPartial,
551
+ test: t.logicalExpression("&&", test, t.unaryExpression("!", property.value.test)),
552
+ consequent: falsy,
553
+ alternate: null,
554
+ remove() {
555
+ }
556
+ })
557
+ ];
558
+ }
559
+ const obj = t.objectExpression([t.objectProperty(property.key, property.value)]);
560
+ const consequent = attemptEval(obj);
561
+ return createTernary({
562
+ remove() {
563
+ },
564
+ ...ternaryPartial,
565
+ test,
566
+ consequent,
567
+ alternate: null
568
+ });
569
+ });
570
+ }, mergeStyles = function(prev2, next) {
571
+ for (const key in next) {
572
+ if (pseudos[key]) {
573
+ prev2[key] = prev2[key] || {};
574
+ Object.assign(prev2[key], next[key]);
575
+ } else {
576
+ prev2[key] = next[key];
577
+ }
578
+ }
579
+ };
580
+ __name(isValidStyleKey, "isValidStyleKey");
581
+ __name(evaluateAttribute, "evaluateAttribute");
582
+ __name(isExtractable, "isExtractable");
583
+ __name(createTernariesFromObjectProperties, "createTernariesFromObjectProperties");
584
+ __name(mergeStyles, "mergeStyles");
585
+ node.attributes.find((n) => t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && n.name.name === "debug" && n.value === null);
586
+ if (shouldPrintDebug) {
587
+ console.log(`
588
+ <${originalNodeName} /> (${tagId})`);
589
+ }
590
+ if (shouldAddDebugProp && !disableDebugAttr) {
591
+ res.modified++;
592
+ node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(tagId)));
593
+ }
594
+ const shouldLog = !hasLogged;
595
+ if (shouldLog) {
596
+ const prefix = " |";
597
+ console.log(prefixLogs || prefix, " total \xB7 optimized \xB7 flattened ");
598
+ hasLogged = true;
599
+ }
600
+ if (disableExtraction) {
601
+ return;
602
+ }
603
+ const { staticConfig } = component;
604
+ const isTextView = staticConfig.isText || false;
605
+ const validStyles = (_a = staticConfig == null ? void 0 : staticConfig.validStyles) != null ? _a : {};
606
+ let tagName = (_c = (_b = staticConfig.defaultProps) == null ? void 0 : _b.tag) != null ? _c : isTextView ? "span" : "div";
607
+ traversePath.get("openingElement").get("attributes").forEach((path) => {
608
+ const attr = path.node;
609
+ if (t.isJSXSpreadAttribute(attr))
610
+ return;
611
+ if (attr.name.name !== "tag")
612
+ return;
613
+ const val = attr.value;
614
+ if (!t.isStringLiteral(val))
615
+ return;
616
+ tagName = val.value;
617
+ });
618
+ const flatNode = getFlattenedNode({ isTextView, tag: tagName });
619
+ const inlineProps = /* @__PURE__ */ new Set([
620
+ ...props.inlineProps || [],
621
+ ...staticConfig.inlineProps || []
622
+ ]);
623
+ const deoptProps = /* @__PURE__ */ new Set([
624
+ "animation",
625
+ ...props.deoptProps || [],
626
+ ...staticConfig.deoptProps || []
627
+ ]);
628
+ const staticNamespace = getStaticBindingsForScope(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
629
+ const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
630
+ tamaguiConfig,
631
+ staticNamespace,
632
+ sourcePath,
633
+ traversePath,
634
+ shouldPrintDebug
635
+ });
636
+ const attemptEvalSafe = createSafeEvaluator(attemptEval);
637
+ if (shouldPrintDebug) {
638
+ console.log(" staticNamespace", Object.keys(staticNamespace).join(", "));
639
+ }
640
+ const flattenedAttrs = [];
641
+ traversePath.get("openingElement").get("attributes").forEach((path) => {
642
+ const attr = path.node;
643
+ if (!t.isJSXSpreadAttribute(attr)) {
644
+ flattenedAttrs.push(attr);
645
+ return;
646
+ }
647
+ let arg;
648
+ try {
649
+ arg = attemptEval(attr.argument);
650
+ } catch (e) {
651
+ if (shouldPrintDebug) {
652
+ console.log(" couldnt parse spread", e.message);
653
+ }
654
+ flattenedAttrs.push(attr);
655
+ return;
656
+ }
657
+ if (arg !== void 0) {
658
+ try {
659
+ if (typeof arg !== "object" || arg == null) {
660
+ if (shouldPrintDebug) {
661
+ console.log(" non object or null arg", arg);
662
+ }
663
+ flattenedAttrs.push(attr);
664
+ } else {
665
+ for (const k in arg) {
666
+ const value = arg[k];
667
+ if (!value && typeof value === "object") {
668
+ console.log("shouldnt we handle this?", k, value, arg);
669
+ continue;
670
+ }
671
+ flattenedAttrs.push(t.jsxAttribute(t.jsxIdentifier(k), t.jsxExpressionContainer(literalToAst(value))));
672
+ }
673
+ }
674
+ } catch (err) {
675
+ console.warn("cant parse spread, caught err", err);
676
+ couldntParse = true;
677
+ }
678
+ }
679
+ });
680
+ if (couldntParse) {
681
+ return;
682
+ }
683
+ node.attributes = flattenedAttrs;
684
+ if (staticConfig.defaultProps) {
685
+ for (const key in staticConfig.defaultProps) {
686
+ if (isValidStyleKey(key)) {
687
+ continue;
688
+ }
689
+ const serialize = require("babel-literal-to-ast");
690
+ const val = staticConfig.defaultProps[key];
691
+ try {
692
+ const serializedDefaultProp = serialize(val);
693
+ node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier(key), typeof val === "string" ? t.stringLiteral(val) : t.jsxExpressionContainer(serializedDefaultProp)));
694
+ } catch (err) {
695
+ console.warn(`\u26A0\uFE0F Error evaluating default prop for component ${node.name.name}, prop ${key}
696
+ error: ${err}
697
+ value:`, val, "\n defaultProps:", staticConfig.defaultProps);
698
+ }
699
+ }
700
+ }
701
+ let attrs = [];
702
+ let shouldDeopt = false;
703
+ const inlined = /* @__PURE__ */ new Map();
704
+ let hasSetOptimized = false;
705
+ attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
706
+ try {
707
+ const res2 = evaluateAttribute(path);
708
+ if (!res2) {
709
+ path.remove();
710
+ }
711
+ return res2;
712
+ } catch (err) {
713
+ if (shouldPrintDebug) {
714
+ console.log("Error extracting attribute", err.message, err.stack);
715
+ console.log("node", path.node);
716
+ }
717
+ return {
718
+ type: "attr",
719
+ value: path.node
720
+ };
721
+ }
722
+ }).flat(4).filter(isPresent);
723
+ if (shouldPrintDebug) {
724
+ console.log(" - attrs (before):\n", logLines(attrs.map(attrStr).join(", ")));
725
+ }
726
+ node.attributes = attrs.filter(isAttr).map((x) => x.value);
727
+ if (couldntParse || shouldDeopt) {
728
+ if (shouldPrintDebug) {
729
+ console.log(` avoid optimizing:`, { couldntParse, shouldDeopt });
730
+ }
731
+ node.attributes = ogAttributes;
732
+ return;
733
+ }
734
+ const parentFn = findTopmostFunction(traversePath);
735
+ if (parentFn) {
736
+ modifiedComponents.add(parentFn);
737
+ }
738
+ let ternaries = [];
739
+ attrs = attrs.reduce((out, cur) => {
740
+ const next = attrs[attrs.indexOf(cur) + 1];
741
+ if (cur.type === "ternary") {
742
+ ternaries.push(cur.value);
743
+ }
744
+ if ((!next || next.type !== "ternary") && ternaries.length) {
745
+ const normalized = normalizeTernaries(ternaries).map(({ alternate, consequent, ...rest }) => {
746
+ return {
747
+ type: "ternary",
748
+ value: {
749
+ ...rest,
750
+ alternate: alternate || null,
751
+ consequent: consequent || null
752
+ }
753
+ };
754
+ });
755
+ try {
756
+ return [...out, ...normalized];
757
+ } finally {
758
+ if (shouldPrintDebug) {
759
+ console.log(` normalizeTernaries (${ternaries.length} => ${normalized.length})`);
760
+ }
761
+ ternaries = [];
762
+ }
763
+ }
764
+ if (cur.type === "ternary") {
765
+ return out;
766
+ }
767
+ out.push(cur);
768
+ return out;
769
+ }, []).flat();
770
+ const completeStaticProps = {
771
+ ...Object.keys(attrs).reduce((acc, index) => {
772
+ const cur = attrs[index];
773
+ if (cur.type === "style") {
774
+ Object.assign(acc, cur.value);
775
+ }
776
+ if (cur.type === "attr") {
777
+ if (t.isJSXSpreadAttribute(cur.value)) {
778
+ return acc;
779
+ }
780
+ if (!t.isJSXIdentifier(cur.value.name)) {
781
+ return acc;
782
+ }
783
+ const key = cur.value.name.name;
784
+ const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
785
+ if (value === FAILED_EVAL) {
786
+ return acc;
787
+ }
788
+ acc[key] = value;
789
+ }
790
+ return acc;
791
+ }, {})
792
+ };
793
+ const hasSpread = node.attributes.some((x) => t.isJSXSpreadAttribute(x));
794
+ const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
795
+ const themeVal = inlined.get("theme");
796
+ inlined.delete("theme");
797
+ const allOtherPropsExtractable = [...inlined].every(([k, v]) => INLINE_EXTRACTABLE[k]);
798
+ const shouldWrapInnerTheme = allOtherPropsExtractable && !!(hasOnlyStringChildren && themeVal);
799
+ const canFlattenProps = inlined.size === 0 || shouldWrapInnerTheme || allOtherPropsExtractable;
800
+ let shouldFlatten = !shouldDeopt && canFlattenProps && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
801
+ if (shouldFlatten && shouldWrapInnerTheme) {
802
+ if (typeof themeVal !== "string") {
803
+ console.warn("??");
804
+ return;
805
+ }
806
+ if (shouldPrintDebug) {
807
+ console.log(" - wrapping theme", allOtherPropsExtractable, themeVal);
808
+ }
809
+ if (!hasImportedTheme) {
810
+ hasImportedTheme = true;
811
+ programPath.node.body.push(t.importDeclaration([t.importSpecifier(t.identifier("_TamaguiTheme"), t.identifier("Theme"))], t.stringLiteral("@tamagui/core")));
812
+ }
813
+ traversePath.replaceWith(t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier("_TamaguiTheme"), [
814
+ t.jsxAttribute(t.jsxIdentifier("name"), t.stringLiteral(`${themeVal}`))
815
+ ]), t.jsxClosingElement(t.jsxIdentifier("_TamaguiTheme")), [traversePath.node]));
816
+ }
817
+ if (shouldFlatten && staticConfig.defaultProps) {
818
+ const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap((key) => {
819
+ if (!isValidStyleKey(key)) {
820
+ return;
821
+ }
822
+ try {
823
+ const serialize = require("babel-literal-to-ast");
824
+ const val = staticConfig.defaultProps[key];
825
+ const value = serialize(val);
826
+ const name = tamaguiConfig.shorthands[key] || key;
827
+ return {
828
+ type: "style",
829
+ name,
830
+ value
831
+ };
832
+ } catch (err) {
833
+ console.warn(`\u26A0\uFE0F Error evaluating default style for component, prop ${key}
834
+ error: ${err}`);
835
+ shouldDeopt = true;
836
+ }
837
+ });
838
+ if (defaultStyleAttrs.length) {
839
+ attrs = [...defaultStyleAttrs, ...attrs];
840
+ }
841
+ }
842
+ if (shouldDeopt) {
843
+ node.attributes = ogAttributes;
844
+ return;
845
+ }
846
+ const ensureOverridden = {};
847
+ if (!shouldFlatten) {
848
+ for (const cur of attrs) {
849
+ if (cur.type === "style") {
850
+ for (const key in cur.value) {
851
+ const shouldEnsureOverridden = !!((_d = staticConfig.ensureOverriddenProp) == null ? void 0 : _d[key]);
852
+ const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
853
+ if (!isSetInAttrsAlready) {
854
+ const isVariant = !!((_e = staticConfig.variants) == null ? void 0 : _e[cur.name || ""]);
855
+ if (isVariant || shouldEnsureOverridden) {
856
+ ensureOverridden[key] = true;
857
+ }
858
+ }
859
+ }
860
+ }
861
+ }
862
+ }
863
+ if (shouldPrintDebug) {
864
+ console.log(" - attrs (flattened): \n", logLines(attrs.map(attrStr).join(", ")));
865
+ console.log(" - ensureOverriden:", Object.keys(ensureOverridden).join(", "));
866
+ }
867
+ attrs = attrs.reduce((acc, cur) => {
868
+ if (!cur) {
869
+ return acc;
870
+ }
871
+ if (cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value)) {
872
+ if (shouldFlatten) {
873
+ if (cur.value.name.name === "tag") {
874
+ return acc;
875
+ }
876
+ }
877
+ }
878
+ if (cur.type !== "style") {
879
+ acc.push(cur);
880
+ return acc;
881
+ }
882
+ let key = Object.keys(cur.value)[0];
883
+ const value = cur.value[key];
884
+ const fullKey = tamaguiConfig.shorthands[key];
885
+ if (fullKey) {
886
+ cur.value = { [fullKey]: value };
887
+ key = fullKey;
888
+ }
889
+ if (disableExtractVariables) {
890
+ if (value[0] === "$") {
891
+ if (shouldPrintDebug) {
892
+ console.log(` keeping variable inline: ${key} =`, value);
893
+ }
894
+ acc.push({
895
+ type: "attr",
896
+ value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.stringLiteral(value)))
897
+ });
898
+ return acc;
899
+ }
900
+ }
901
+ acc.push(cur);
902
+ return acc;
903
+ }, []);
904
+ if (shouldPrintDebug) {
905
+ console.log(" - attrs (expanded): \n", logLines(attrs.map(attrStr).join(", ")));
906
+ }
907
+ let prev = null;
908
+ attrs = attrs.reduce((acc, cur) => {
909
+ if (cur.type === "style") {
910
+ const key = Object.keys(cur.value)[0];
911
+ const value = cur.value[key];
912
+ const shouldKeepOriginalAttr = !shouldFlatten && !validStyles[key] && !pseudos[key] && !key.startsWith("data-");
913
+ if (shouldKeepOriginalAttr) {
914
+ if (shouldPrintDebug) {
915
+ console.log(" - keeping as non-style", key);
916
+ }
917
+ prev = cur;
918
+ acc.push({
919
+ type: "attr",
920
+ value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(typeof value === "string" ? t.stringLiteral(value) : literalToAst(value)))
921
+ });
922
+ acc.push(cur);
923
+ return acc;
924
+ }
925
+ if (ensureOverridden[key]) {
926
+ acc.push({
927
+ type: "attr",
928
+ value: cur.attr || t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.nullLiteral()))
929
+ });
930
+ }
931
+ if ((prev == null ? void 0 : prev.type) === "style") {
932
+ mergeStyles(prev.value, cur.value);
933
+ return acc;
934
+ }
935
+ }
936
+ prev = cur;
937
+ acc.push(cur);
938
+ return acc;
939
+ }, []);
940
+ if (shouldPrintDebug) {
941
+ console.log(" - attrs (combined \u{1F500}): \n", logLines(attrs.map(attrStr).join(", ")));
942
+ }
943
+ const completeProps = {
944
+ ...staticConfig.defaultProps,
945
+ ...completeStaticProps
946
+ };
947
+ const getStyles = /* @__PURE__ */ __name((props2, debugName = "") => {
948
+ if (!props2)
949
+ return;
950
+ if (!Object.keys(props2).length)
951
+ return;
952
+ if (excludeProps && !!excludeProps.size) {
953
+ for (const key in props2) {
954
+ if (excludeProps.has(key)) {
955
+ delete props2[key];
956
+ }
957
+ }
958
+ }
959
+ const out = getSplitStyles(props2, staticConfig, defaultTheme, {
960
+ noClassNames: true,
961
+ fallbackProps: completeProps,
962
+ focus: false,
963
+ hover: false,
964
+ mounted: true,
965
+ press: false,
966
+ pressIn: false
967
+ });
968
+ const outStyle = {
969
+ ...out.style,
970
+ ...out.pseudos
971
+ };
972
+ for (const key in outStyle) {
973
+ if (staticConfig.validStyles) {
974
+ if (!staticConfig.validStyles[key] && !pseudos[key]) {
975
+ delete outStyle[key];
976
+ }
977
+ }
978
+ }
979
+ if (shouldPrintDebug === "verbose") {
980
+ console.log(` getStyles ${debugName} (props):
981
+ `, logLines(objToStr(props2)));
982
+ console.log(` getStyles ${debugName} (out.viewProps):
983
+ `, logLines(objToStr(out.viewProps)));
984
+ console.log(` getStyles ${debugName} (out.style):
985
+ `, logLines(objToStr(outStyle || {}), true));
986
+ }
987
+ return outStyle;
988
+ }, "getStyles");
989
+ const completeStylesProcessed = getStyles(completeProps, "completeStylesProcessed");
990
+ if (!completeStylesProcessed) {
991
+ throw new Error(`Impossible, no styles`);
992
+ }
993
+ const stylesToAddToInitialGroup = shouldFlatten ? difference(Object.keys(completeStylesProcessed), Object.keys(completeStaticProps)) : [];
994
+ if (stylesToAddToInitialGroup.length) {
995
+ const toAdd = pick(completeStylesProcessed, ...stylesToAddToInitialGroup);
996
+ const firstGroup = attrs.find((x) => x.type === "style");
997
+ if (shouldPrintDebug) {
998
+ console.log(" toAdd", objToStr(toAdd));
999
+ }
1000
+ if (!firstGroup) {
1001
+ attrs.unshift({ type: "style", value: toAdd });
1002
+ } else {
1003
+ Object.assign(firstGroup.value, toAdd);
1004
+ }
1005
+ }
1006
+ if (shouldPrintDebug) {
1007
+ console.log(" -- stylesToAddToInitialGroup", stylesToAddToInitialGroup.join(", "), { shouldFlatten });
1008
+ console.log(" -- completeStaticProps:\n", logLines(objToStr(completeStaticProps)));
1009
+ console.log(" -- completeStylesProcessed:\n", logLines(objToStr(completeStylesProcessed)));
1010
+ }
1011
+ let getStyleError = null;
1012
+ for (const attr of attrs) {
1013
+ try {
1014
+ if (shouldPrintDebug)
1015
+ console.log(" *", attrStr(attr));
1016
+ switch (attr.type) {
1017
+ case "ternary":
1018
+ const a = getStyles(attr.value.alternate, "ternary.alternate");
1019
+ const c = getStyles(attr.value.consequent, "ternary.consequent");
1020
+ if (a)
1021
+ attr.value.alternate = a;
1022
+ if (c)
1023
+ attr.value.consequent = c;
1024
+ if (shouldPrintDebug)
1025
+ console.log(" => tern ", attrStr(attr));
1026
+ continue;
1027
+ case "style":
1028
+ const styles = getStyles(attr.value, "style");
1029
+ if (styles) {
1030
+ attr.value = Object.fromEntries(Object.keys(styles).map((k) => [k, completeStylesProcessed[k]]));
1031
+ } else {
1032
+ console.warn("?????????");
1033
+ }
1034
+ continue;
1035
+ }
1036
+ } catch (err) {
1037
+ getStyleError = err;
1038
+ }
1039
+ }
1040
+ if (getStyleError) {
1041
+ console.log(" \u26A0\uFE0F postprocessing error, deopt", getStyleError);
1042
+ node.attributes = ogAttributes;
1043
+ return node;
1044
+ }
1045
+ const existingStyleKeys = /* @__PURE__ */ new Set();
1046
+ for (let i = attrs.length - 1; i >= 0; i--) {
1047
+ const attr = attrs[i];
1048
+ if (shouldFlatten && canFlattenProps) {
1049
+ if (attr.type === "attr") {
1050
+ if (t.isJSXAttribute(attr.value)) {
1051
+ if (t.isJSXIdentifier(attr.value.name)) {
1052
+ const name = attr.value.name.name;
1053
+ if (INLINE_EXTRACTABLE[name]) {
1054
+ attr.value.name.name = INLINE_EXTRACTABLE[name];
1055
+ }
1056
+ }
1057
+ }
1058
+ }
1059
+ }
1060
+ if (attr.type === "style") {
1061
+ for (const key in attr.value) {
1062
+ if (existingStyleKeys.has(key)) {
1063
+ delete attr.value[key];
1064
+ } else {
1065
+ existingStyleKeys.add(key);
1066
+ }
1067
+ }
1068
+ }
1069
+ }
1070
+ if (shouldFlatten) {
1071
+ if (shouldPrintDebug) {
1072
+ console.log(" [\u2705] flattening", originalNodeName, flatNode);
1073
+ }
1074
+ node.name.name = flatNode;
1075
+ res.flattened++;
1076
+ if (closingElement) {
1077
+ closingElement.name.name = flatNode;
1078
+ }
1079
+ }
1080
+ if (shouldPrintDebug) {
1081
+ console.log(` \u274A\u274A inline props (${inlined.size}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : "");
1082
+ console.log(" - attrs (end):\n", logLines(attrs.map(attrStr).join(", ")));
1083
+ }
1084
+ onExtractTag({
1085
+ attrs,
1086
+ node,
1087
+ lineNumbers,
1088
+ filePath,
1089
+ attemptEval,
1090
+ jsxPath: traversePath,
1091
+ originalNodeName,
1092
+ isFlattened: shouldFlatten,
1093
+ programPath
1094
+ });
1095
+ } catch (err) {
1096
+ throw err;
1097
+ } finally {
1098
+ if (hasBooleanDebugTrue) {
1099
+ shouldPrintDebug = false;
1100
+ }
1101
+ }
1102
+ }
1103
+ });
1104
+ if (modifiedComponents.size) {
1105
+ const all = Array.from(modifiedComponents);
1106
+ if (shouldPrintDebug) {
1107
+ console.log(" [\u{1FA9D}] hook check", all.length);
1108
+ }
1109
+ for (const comp of all) {
1110
+ removeUnusedHooks(comp, shouldPrintDebug);
1111
+ }
1112
+ }
1113
+ return res;
1114
+ }
1115
+ };
1116
+ }
1117
+ __name(createExtractor, "createExtractor");
1118
+ export {
1119
+ createExtractor
1120
+ };
1121
+ //# sourceMappingURL=createExtractor.js.map