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

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 (209) 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 +952 -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 +124 -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 +291 -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 +62 -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 +151 -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 +6 -4
  68. package/dist/{extractor → esm/extractor}/extractHelpers.js.map +3 -3
  69. package/dist/{extractor → esm/extractor}/extractMediaStyle.js +3 -2
  70. package/dist/{extractor → esm/extractor}/extractMediaStyle.js.map +2 -2
  71. package/dist/{extractor → esm/extractor}/extractToClassNames.js +35 -22
  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/{extractor → esm/extractor}/literalToAst.js +0 -0
  86. package/dist/{extractor → esm/extractor}/literalToAst.js.map +1 -1
  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 +890 -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 +95 -0
  110. package/dist/jsx/extractor/extractMediaStyle.js +151 -0
  111. package/dist/jsx/extractor/extractToClassNames.js +247 -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 +33 -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 +3 -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/extractToClassNames.js.map +0 -7
  181. package/dist/extractor/loadTamagui.js.map +0 -7
  182. package/dist/index.cjs +0 -2107
  183. package/dist/index.cjs.map +0 -7
  184. package/dist/patchReactNativeWeb.js.map +0 -7
  185. package/src/constants.ts +0 -10
  186. package/src/extractor/accessSafe.ts +0 -18
  187. package/src/extractor/babelParse.ts +0 -27
  188. package/src/extractor/buildClassName.ts +0 -61
  189. package/src/extractor/createEvaluator.ts +0 -68
  190. package/src/extractor/createExtractor.ts +0 -1132
  191. package/src/extractor/ensureImportingConcat.ts +0 -33
  192. package/src/extractor/evaluateAstNode.ts +0 -121
  193. package/src/extractor/extractHelpers.ts +0 -102
  194. package/src/extractor/extractMediaStyle.ts +0 -191
  195. package/src/extractor/extractToClassNames.ts +0 -326
  196. package/src/extractor/findTopmostFunction.ts +0 -22
  197. package/src/extractor/generatedUid.ts +0 -43
  198. package/src/extractor/getPropValueFromAttributes.ts +0 -92
  199. package/src/extractor/getSourceModule.ts +0 -101
  200. package/src/extractor/getStaticBindingsForScope.ts +0 -173
  201. package/src/extractor/hoistClassNames.ts +0 -45
  202. package/src/extractor/literalToAst.ts +0 -32
  203. package/src/extractor/loadTamagui.ts +0 -61
  204. package/src/extractor/normalizeTernaries.ts +0 -60
  205. package/src/extractor/removeUnusedHooks.ts +0 -76
  206. package/src/index.ts +0 -9
  207. package/src/patchReactNativeWeb.ts +0 -123
  208. package/src/types.ts +0 -83
  209. package/types.d.ts +0 -215
@@ -0,0 +1,890 @@
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 { mediaQueryConfig, postProcessStyles, pseudos } from "@tamagui/core-node";
6
+ import { stylePropsTransform } from "@tamagui/helpers";
7
+ import { difference, pick } from "lodash";
8
+ import { FAILED_EVAL } from "../constants";
9
+ import { createEvaluator, createSafeEvaluator } from "./createEvaluator";
10
+ import { evaluateAstNode } from "./evaluateAstNode";
11
+ import { attrStr, findComponentName, isInsideTamagui, isPresent, objToStr } from "./extractHelpers";
12
+ import { findTopmostFunction } from "./findTopmostFunction";
13
+ import { getStaticBindingsForScope } from "./getStaticBindingsForScope";
14
+ import { literalToAst } from "./literalToAst";
15
+ import { loadTamagui } from "./loadTamagui";
16
+ import { logLines } from "./logLines";
17
+ import { normalizeTernaries } from "./normalizeTernaries";
18
+ import { removeUnusedHooks } from "./removeUnusedHooks";
19
+ const UNTOUCHED_PROPS = {
20
+ key: true,
21
+ style: true,
22
+ className: true
23
+ };
24
+ const isAttr = /* @__PURE__ */ __name((x) => x.type === "attr", "isAttr");
25
+ const validHooks = {
26
+ useMedia: true,
27
+ useTheme: true
28
+ };
29
+ const createTernary = /* @__PURE__ */ __name((x) => x, "createTernary");
30
+ function createExtractor() {
31
+ 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);
32
+ require("esbuild-register/dist/node").register({
33
+ target: "es2019",
34
+ format: "cjs"
35
+ });
36
+ let loadedTamaguiConfig;
37
+ let hasLogged = false;
38
+ return {
39
+ getTamagui() {
40
+ return loadedTamaguiConfig;
41
+ },
42
+ parse: (fileOrPath, {
43
+ config = "tamagui.config.ts",
44
+ importsWhitelist = ["constants.js"],
45
+ evaluateVars = true,
46
+ shouldPrintDebug = false,
47
+ sourcePath = "",
48
+ onExtractTag,
49
+ getFlattenedNode,
50
+ disableExtraction,
51
+ disableExtractInlineMedia,
52
+ disableExtractVariables,
53
+ disableDebugAttr,
54
+ ...props
55
+ }) => {
56
+ if (sourcePath === "") {
57
+ throw new Error(`Must provide a source file name`);
58
+ }
59
+ if (!Array.isArray(props.components)) {
60
+ throw new Error(`Must provide components array with list of Tamagui component modules`);
61
+ }
62
+ const { components, tamaguiConfig } = loadTamagui({
63
+ config,
64
+ components: props.components || ["tamagui"]
65
+ });
66
+ loadedTamaguiConfig = tamaguiConfig;
67
+ const defaultTheme = tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]];
68
+ const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
69
+ const isInternalImport = /* @__PURE__ */ __name((importStr) => {
70
+ return isInsideTamagui(sourcePath) && importStr[0] === ".";
71
+ }, "isInternalImport");
72
+ const validComponents = Object.keys(components).filter((key) => {
73
+ var _a;
74
+ return key[0].toUpperCase() === key[0] && !!((_a = components[key]) == null ? void 0 : _a.staticConfig);
75
+ }).reduce((obj, name) => {
76
+ obj[name] = components[name];
77
+ return obj;
78
+ }, {});
79
+ let doesUseValidImport = false;
80
+ for (const bodyPath of body) {
81
+ if (bodyPath.type !== "ImportDeclaration")
82
+ continue;
83
+ const node = "node" in bodyPath ? bodyPath.node : bodyPath;
84
+ const from = node.source.value;
85
+ if (props.components.includes(from) || isInternalImport(from)) {
86
+ if (node.specifiers.some((specifier) => {
87
+ const name = specifier.local.name;
88
+ return validComponents[name] || validHooks[name];
89
+ })) {
90
+ doesUseValidImport = true;
91
+ break;
92
+ }
93
+ }
94
+ }
95
+ if (shouldPrintDebug) {
96
+ console.log(sourcePath, { doesUseValidImport });
97
+ }
98
+ if (!doesUseValidImport) {
99
+ return null;
100
+ }
101
+ let couldntParse = false;
102
+ const modifiedComponents = /* @__PURE__ */ new Set();
103
+ const bindingCache = {};
104
+ const callTraverse = /* @__PURE__ */ __name((a) => {
105
+ return fileOrPath.type === "File" ? traverse(fileOrPath, a) : fileOrPath.traverse(a);
106
+ }, "callTraverse");
107
+ let programPath;
108
+ const res = {
109
+ flattened: 0,
110
+ optimized: 0,
111
+ modified: 0
112
+ };
113
+ callTraverse({
114
+ Program: {
115
+ enter(path) {
116
+ programPath = path;
117
+ }
118
+ },
119
+ JSXElement(traversePath) {
120
+ var _a, _b, _c, _d, _e, _f;
121
+ const node = traversePath.node.openingElement;
122
+ const ogAttributes = node.attributes;
123
+ const componentName = findComponentName(traversePath.scope);
124
+ const closingElement = traversePath.node.closingElement;
125
+ if (t.isJSXMemberExpression(closingElement == null ? void 0 : closingElement.name) || !t.isJSXIdentifier(node.name)) {
126
+ return;
127
+ }
128
+ const binding = traversePath.scope.getBinding(node.name.name);
129
+ if (binding) {
130
+ if (!t.isImportDeclaration(binding.path.parent)) {
131
+ return;
132
+ }
133
+ const source = binding.path.parent.source;
134
+ if (!props.components.includes(source.value) && !isInternalImport(source.value)) {
135
+ return;
136
+ }
137
+ if (!validComponents[binding.identifier.name]) {
138
+ return;
139
+ }
140
+ }
141
+ const component = validComponents[node.name.name];
142
+ if (!component || !component.staticConfig) {
143
+ return;
144
+ }
145
+ const originalNodeName = node.name.name;
146
+ if (shouldPrintDebug) {
147
+ console.log(`
148
+ <${originalNodeName} />`);
149
+ }
150
+ const filePath = sourcePath.replace(process.cwd(), ".");
151
+ const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
152
+ if (shouldAddDebugProp && !disableDebugAttr) {
153
+ const preName = componentName ? `${componentName}:` : "";
154
+ res.modified++;
155
+ node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(` ${preName}${node.name.name} ${filePath.replace("./", "")}:${lineNumbers} `)));
156
+ }
157
+ if (disableExtraction) {
158
+ if (!hasLogged) {
159
+ console.log("\u{1F95A} Tamagui disableExtraction set: no CSS or optimizations will be run");
160
+ hasLogged = true;
161
+ }
162
+ return;
163
+ }
164
+ const { staticConfig } = component;
165
+ const isTextView = staticConfig.isText || false;
166
+ const validStyles = (_a = staticConfig == null ? void 0 : staticConfig.validStyles) != null ? _a : {};
167
+ let tagName = (_c = (_b = staticConfig.defaultProps) == null ? void 0 : _b.tag) != null ? _c : isTextView ? "span" : "div";
168
+ traversePath.get("openingElement").get("attributes").forEach((path) => {
169
+ const attr = path.node;
170
+ if (t.isJSXSpreadAttribute(attr))
171
+ return;
172
+ if (attr.name.name !== "tag")
173
+ return;
174
+ const val = attr.value;
175
+ if (!t.isStringLiteral(val))
176
+ return;
177
+ tagName = val.value;
178
+ });
179
+ const flatNode = getFlattenedNode({ isTextView, tag: tagName });
180
+ const deoptProps = /* @__PURE__ */ new Set([
181
+ ...(_d = props.deoptProps) != null ? _d : [],
182
+ ...(_e = staticConfig.deoptProps) != null ? _e : []
183
+ ]);
184
+ const excludeProps = new Set((_f = props.excludeProps) != null ? _f : []);
185
+ const isExcludedProp = /* @__PURE__ */ __name((name) => {
186
+ const res2 = excludeProps.has(name);
187
+ if (res2 && shouldPrintDebug)
188
+ console.log(` excluding ${name}`);
189
+ return res2;
190
+ }, "isExcludedProp");
191
+ const isDeoptedProp = /* @__PURE__ */ __name((name) => {
192
+ const res2 = deoptProps.has(name);
193
+ if (res2 && shouldPrintDebug)
194
+ console.log(` deopting ${name}`);
195
+ return res2;
196
+ }, "isDeoptedProp");
197
+ const staticNamespace = getStaticBindingsForScope(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
198
+ const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
199
+ tamaguiConfig,
200
+ staticNamespace,
201
+ sourcePath,
202
+ traversePath,
203
+ shouldPrintDebug
204
+ });
205
+ const attemptEvalSafe = createSafeEvaluator(attemptEval);
206
+ if (shouldPrintDebug) {
207
+ console.log(" staticNamespace", Object.keys(staticNamespace).join(", "));
208
+ }
209
+ const flattenedAttrs = [];
210
+ traversePath.get("openingElement").get("attributes").forEach((path) => {
211
+ const attr = path.node;
212
+ if (!t.isJSXSpreadAttribute(attr)) {
213
+ flattenedAttrs.push(attr);
214
+ return;
215
+ }
216
+ let arg;
217
+ try {
218
+ arg = attemptEval(attr.argument);
219
+ } catch (e) {
220
+ if (shouldPrintDebug) {
221
+ console.log(" couldnt parse spread", e.message);
222
+ }
223
+ flattenedAttrs.push(attr);
224
+ return;
225
+ }
226
+ if (typeof arg !== "undefined") {
227
+ try {
228
+ if (typeof arg !== "object" || arg == null) {
229
+ if (shouldPrintDebug) {
230
+ console.log(" non object or null arg", arg);
231
+ }
232
+ flattenedAttrs.push(attr);
233
+ } else {
234
+ for (const k in arg) {
235
+ const value = arg[k];
236
+ if (!value && typeof value === "object") {
237
+ console.log("shouldnt we handle this?", k, value, arg);
238
+ continue;
239
+ }
240
+ flattenedAttrs.push(t.jsxAttribute(t.jsxIdentifier(k), t.jsxExpressionContainer(literalToAst(value))));
241
+ }
242
+ }
243
+ } catch (err) {
244
+ console.warn("cant parse spread, caught err", err);
245
+ couldntParse = true;
246
+ }
247
+ }
248
+ });
249
+ if (couldntParse) {
250
+ return;
251
+ }
252
+ node.attributes = flattenedAttrs;
253
+ if (staticConfig.defaultProps) {
254
+ for (const key in staticConfig.defaultProps) {
255
+ if (key === "StyleSheet") {
256
+ continue;
257
+ }
258
+ const serialize = require("babel-literal-to-ast");
259
+ const val = staticConfig.defaultProps[key];
260
+ try {
261
+ const serializedDefaultProp = serialize(val);
262
+ node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier(key), typeof val === "string" ? t.stringLiteral(val) : t.jsxExpressionContainer(serializedDefaultProp)));
263
+ } catch (err) {
264
+ console.warn(`\u26A0\uFE0F Error evaluating default prop for component ${node.name.name}, prop ${key}
265
+ error: ${err}
266
+ value:`, val, "\n defaultProps:", staticConfig.defaultProps);
267
+ }
268
+ }
269
+ }
270
+ let attrs = [];
271
+ let shouldDeopt = false;
272
+ let inlinePropCount = 0;
273
+ let isFlattened = false;
274
+ attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
275
+ try {
276
+ const res2 = evaluateAttribute(path);
277
+ if (!res2) {
278
+ path.remove();
279
+ }
280
+ return res2;
281
+ } catch (err) {
282
+ if (shouldPrintDebug) {
283
+ console.log("Error extracting attribute", err.message, err.stack);
284
+ console.log("node", path.node);
285
+ }
286
+ return {
287
+ type: "attr",
288
+ value: path.node
289
+ };
290
+ }
291
+ }).flat(4).filter(isPresent);
292
+ if (shouldPrintDebug) {
293
+ console.log(" - attrs (before):\n", logLines(attrs.map(attrStr).join(", ")));
294
+ }
295
+ function isStaticAttributeName(name) {
296
+ var _a2, _b2;
297
+ return !!(!!validStyles[name] || ((_a2 = staticConfig.validPropsExtra) == null ? void 0 : _a2[name]) || !!pseudos[name] || ((_b2 = staticConfig.variants) == null ? void 0 : _b2[name]) || tamaguiConfig.shorthands[name] || (name[0] === "$" ? !!mediaQueryConfig[name.slice(1)] : false));
298
+ }
299
+ __name(isStaticAttributeName, "isStaticAttributeName");
300
+ function isExtractable(obj) {
301
+ return t.isObjectExpression(obj) && obj.properties.every((prop) => {
302
+ if (!t.isObjectProperty(prop)) {
303
+ console.log("not object prop", prop);
304
+ return false;
305
+ }
306
+ const propName = prop.key["name"];
307
+ if (!isStaticAttributeName(propName) && propName !== "tag") {
308
+ if (shouldPrintDebug) {
309
+ console.log(" not a valid style prop!", propName);
310
+ }
311
+ return false;
312
+ }
313
+ return true;
314
+ });
315
+ }
316
+ __name(isExtractable, "isExtractable");
317
+ function createTernariesFromObjectProperties(test, side, ternaryPartial = {}) {
318
+ if (!side) {
319
+ return null;
320
+ }
321
+ if (!isExtractable(side)) {
322
+ throw new Error("not extractable");
323
+ }
324
+ return side.properties.flatMap((property) => {
325
+ if (!t.isObjectProperty(property)) {
326
+ throw new Error("expected object property");
327
+ }
328
+ if (t.isConditionalExpression(property.value)) {
329
+ const [truthy, falsy] = [
330
+ t.objectExpression([t.objectProperty(property.key, property.value.consequent)]),
331
+ t.objectExpression([t.objectProperty(property.key, property.value.alternate)])
332
+ ].map((x) => attemptEval(x));
333
+ return [
334
+ createTernary({
335
+ remove() {
336
+ },
337
+ ...ternaryPartial,
338
+ test: t.logicalExpression("&&", test, property.value.test),
339
+ consequent: truthy,
340
+ alternate: null
341
+ }),
342
+ createTernary({
343
+ ...ternaryPartial,
344
+ test: t.logicalExpression("&&", test, t.unaryExpression("!", property.value.test)),
345
+ consequent: falsy,
346
+ alternate: null,
347
+ remove() {
348
+ }
349
+ })
350
+ ];
351
+ }
352
+ const obj = t.objectExpression([t.objectProperty(property.key, property.value)]);
353
+ const consequent = attemptEval(obj);
354
+ return createTernary({
355
+ remove() {
356
+ },
357
+ ...ternaryPartial,
358
+ test,
359
+ consequent,
360
+ alternate: null
361
+ });
362
+ });
363
+ }
364
+ __name(createTernariesFromObjectProperties, "createTernariesFromObjectProperties");
365
+ function evaluateAttribute(path) {
366
+ const attribute = path.node;
367
+ const attr = { type: "attr", value: attribute };
368
+ if (t.isJSXSpreadAttribute(attribute)) {
369
+ const arg = attribute.argument;
370
+ const conditional = t.isConditionalExpression(arg) ? [arg.test, arg.consequent, arg.alternate] : t.isLogicalExpression(arg) && arg.operator === "&&" ? [arg.left, arg.right, null] : null;
371
+ if (conditional) {
372
+ const [test, alt, cons] = conditional;
373
+ if (!test)
374
+ throw new Error(`no test`);
375
+ if ([alt, cons].some((side) => side && !isExtractable(side))) {
376
+ if (shouldPrintDebug) {
377
+ console.log("not extractable", alt, cons);
378
+ }
379
+ return attr;
380
+ }
381
+ return [
382
+ ...createTernariesFromObjectProperties(test, alt) || [],
383
+ ...cons && createTernariesFromObjectProperties(t.unaryExpression("!", test), cons) || []
384
+ ].map((ternary) => ({
385
+ type: "ternary",
386
+ value: ternary
387
+ }));
388
+ }
389
+ }
390
+ if (t.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name !== "string") {
391
+ inlinePropCount++;
392
+ return attr;
393
+ }
394
+ const name = attribute.name.name;
395
+ if (isExcludedProp(name)) {
396
+ return null;
397
+ }
398
+ if (isDeoptedProp(name)) {
399
+ if (shouldPrintDebug) {
400
+ console.log(" ! inlining, deopt prop", name);
401
+ }
402
+ inlinePropCount++;
403
+ return attr;
404
+ }
405
+ if (UNTOUCHED_PROPS[name]) {
406
+ return attr;
407
+ }
408
+ if (name[0] === "$" && t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
409
+ if (disableExtractInlineMedia) {
410
+ return attr;
411
+ }
412
+ const shortname = name.slice(1);
413
+ if (mediaQueryConfig[shortname]) {
414
+ const expression = attribute.value.expression;
415
+ if (!t.isJSXEmptyExpression(expression)) {
416
+ const ternaries2 = createTernariesFromObjectProperties(t.stringLiteral(shortname), expression, {
417
+ inlineMediaQuery: shortname
418
+ });
419
+ if (ternaries2) {
420
+ return ternaries2.map((value2) => ({
421
+ type: "ternary",
422
+ value: value2
423
+ }));
424
+ }
425
+ }
426
+ }
427
+ }
428
+ const [value, valuePath] = (() => {
429
+ if (t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
430
+ return [attribute.value.expression, path.get("value")];
431
+ } else {
432
+ return [attribute.value, path.get("value")];
433
+ }
434
+ })();
435
+ const remove = /* @__PURE__ */ __name(() => {
436
+ Array.isArray(valuePath) ? valuePath.map((p) => p.remove()) : valuePath.remove();
437
+ }, "remove");
438
+ if (name === "ref") {
439
+ if (shouldPrintDebug) {
440
+ console.log(" ! inlining, ref", name);
441
+ }
442
+ inlinePropCount++;
443
+ return attr;
444
+ }
445
+ if (name === "tag") {
446
+ return {
447
+ type: "attr",
448
+ value: path.node
449
+ };
450
+ }
451
+ if (disableExtractVariables) {
452
+ if (value) {
453
+ if (value.type === "StringLiteral" && value.value[0] === "$") {
454
+ if (shouldPrintDebug) {
455
+ console.log(` native, disable extract: ${name} =`, value.value);
456
+ }
457
+ inlinePropCount++;
458
+ return attr;
459
+ }
460
+ }
461
+ }
462
+ const styleValue = attemptEvalSafe(value);
463
+ if (!isStaticAttributeName(name)) {
464
+ let keys = [name];
465
+ if (staticConfig.propMapper) {
466
+ const out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps);
467
+ if (out) {
468
+ keys = Object.keys(out);
469
+ }
470
+ }
471
+ for (const key of keys) {
472
+ if (!isStaticAttributeName(key)) {
473
+ inlinePropCount++;
474
+ }
475
+ }
476
+ if (inlinePropCount) {
477
+ return attr;
478
+ }
479
+ }
480
+ if (styleValue !== FAILED_EVAL) {
481
+ if (shouldPrintDebug) {
482
+ console.log(` style: ${name} =`, styleValue);
483
+ }
484
+ return {
485
+ type: "style",
486
+ value: { [name]: styleValue },
487
+ name,
488
+ attr: path.node
489
+ };
490
+ }
491
+ if (t.isBinaryExpression(value)) {
492
+ if (shouldPrintDebug) {
493
+ console.log(` binary expression ${name} = `, value);
494
+ }
495
+ const { operator, left, right } = value;
496
+ const lVal = attemptEvalSafe(left);
497
+ const rVal = attemptEvalSafe(right);
498
+ if (shouldPrintDebug) {
499
+ console.log(` evalBinaryExpression lVal ${String(lVal)}, rVal ${String(rVal)}`);
500
+ }
501
+ if (lVal !== FAILED_EVAL && t.isConditionalExpression(right)) {
502
+ const ternary = addBinaryConditional(operator, left, right);
503
+ if (ternary)
504
+ return ternary;
505
+ }
506
+ if (rVal !== FAILED_EVAL && t.isConditionalExpression(left)) {
507
+ const ternary = addBinaryConditional(operator, right, left);
508
+ if (ternary)
509
+ return ternary;
510
+ }
511
+ if (shouldPrintDebug) {
512
+ console.log(` evalBinaryExpression cant extract`);
513
+ }
514
+ inlinePropCount++;
515
+ return attr;
516
+ }
517
+ const staticConditional = getStaticConditional(value);
518
+ if (staticConditional) {
519
+ if (shouldPrintDebug) {
520
+ console.log(` static conditional ${name} = `, value);
521
+ }
522
+ return { type: "ternary", value: staticConditional };
523
+ }
524
+ const staticLogical = getStaticLogical(value);
525
+ if (staticLogical) {
526
+ if (shouldPrintDebug) {
527
+ console.log(` static ternary ${name} = `, value);
528
+ }
529
+ return { type: "ternary", value: staticLogical };
530
+ }
531
+ if (shouldPrintDebug) {
532
+ console.log(" ! inline prop via no match", name, value.type);
533
+ }
534
+ inlinePropCount++;
535
+ if (shouldPrintDebug) {
536
+ console.log(` inlining ${name} = `, value);
537
+ }
538
+ return attr;
539
+ function addBinaryConditional(operator, staticExpr, cond) {
540
+ if (getStaticConditional(cond)) {
541
+ const alt = attemptEval(t.binaryExpression(operator, staticExpr, cond.alternate));
542
+ const cons = attemptEval(t.binaryExpression(operator, staticExpr, cond.consequent));
543
+ if (shouldPrintDebug) {
544
+ console.log(" binaryConditional", cond.test, cons, alt);
545
+ }
546
+ return {
547
+ type: "ternary",
548
+ value: {
549
+ test: cond.test,
550
+ remove,
551
+ alternate: { [name]: alt },
552
+ consequent: { [name]: cons }
553
+ }
554
+ };
555
+ }
556
+ return null;
557
+ }
558
+ __name(addBinaryConditional, "addBinaryConditional");
559
+ function getStaticConditional(value2) {
560
+ if (t.isConditionalExpression(value2)) {
561
+ try {
562
+ if (shouldPrintDebug) {
563
+ console.log("attempt", value2.alternate, value2.consequent);
564
+ }
565
+ const aVal = attemptEval(value2.alternate);
566
+ const cVal = attemptEval(value2.consequent);
567
+ if (shouldPrintDebug) {
568
+ const type = value2.test.type;
569
+ console.log(" static ternary", type, cVal, aVal);
570
+ }
571
+ return {
572
+ test: value2.test,
573
+ remove,
574
+ consequent: { [name]: cVal },
575
+ alternate: { [name]: aVal }
576
+ };
577
+ } catch (err) {
578
+ if (shouldPrintDebug) {
579
+ console.log(" cant eval ternary", err.message);
580
+ }
581
+ }
582
+ }
583
+ return null;
584
+ }
585
+ __name(getStaticConditional, "getStaticConditional");
586
+ function getStaticLogical(value2) {
587
+ if (t.isLogicalExpression(value2)) {
588
+ if (value2.operator === "&&") {
589
+ try {
590
+ const val = attemptEval(value2.right);
591
+ if (shouldPrintDebug) {
592
+ console.log(" staticLogical", value2.left, name, val);
593
+ }
594
+ return {
595
+ test: value2.left,
596
+ remove,
597
+ consequent: { [name]: val },
598
+ alternate: null
599
+ };
600
+ } catch (err) {
601
+ if (shouldPrintDebug) {
602
+ console.log(" cant static eval logical", err);
603
+ }
604
+ }
605
+ }
606
+ }
607
+ return null;
608
+ }
609
+ __name(getStaticLogical, "getStaticLogical");
610
+ }
611
+ __name(evaluateAttribute, "evaluateAttribute");
612
+ node.attributes = attrs.filter(isAttr).map((x) => x.value);
613
+ if (couldntParse) {
614
+ if (shouldPrintDebug) {
615
+ console.log(` cancel:`, { couldntParse, shouldDeopt });
616
+ }
617
+ node.attributes = ogAttributes;
618
+ return;
619
+ }
620
+ const parentFn = findTopmostFunction(traversePath);
621
+ if (parentFn) {
622
+ modifiedComponents.add(parentFn);
623
+ }
624
+ let ternaries = [];
625
+ attrs = attrs.reduce((out, cur) => {
626
+ const next = attrs[attrs.indexOf(cur) + 1];
627
+ if (cur.type === "ternary") {
628
+ ternaries.push(cur.value);
629
+ }
630
+ if ((!next || next.type !== "ternary") && ternaries.length) {
631
+ const normalized = normalizeTernaries(ternaries).map(({ alternate, consequent, ...rest }) => {
632
+ return {
633
+ type: "ternary",
634
+ value: {
635
+ ...rest,
636
+ alternate: alternate || null,
637
+ consequent: consequent || null
638
+ }
639
+ };
640
+ });
641
+ try {
642
+ return [...out, ...normalized];
643
+ } finally {
644
+ if (shouldPrintDebug) {
645
+ console.log(` normalizeTernaries (${ternaries.length} => ${normalized.length})`);
646
+ }
647
+ ternaries = [];
648
+ }
649
+ }
650
+ if (cur.type === "ternary") {
651
+ return out;
652
+ }
653
+ out.push(cur);
654
+ return out;
655
+ }, []).flat();
656
+ const completeStaticProps = {
657
+ ...Object.keys(attrs).reduce((acc, index) => {
658
+ const cur = attrs[index];
659
+ if (cur.type === "style") {
660
+ Object.assign(acc, cur.value);
661
+ }
662
+ if (cur.type === "attr") {
663
+ if (t.isJSXSpreadAttribute(cur.value)) {
664
+ return acc;
665
+ }
666
+ if (!t.isJSXIdentifier(cur.value.name)) {
667
+ return acc;
668
+ }
669
+ const key = cur.value.name.name;
670
+ const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
671
+ if (value === FAILED_EVAL) {
672
+ return acc;
673
+ }
674
+ acc[key] = value;
675
+ }
676
+ return acc;
677
+ }, {})
678
+ };
679
+ const hasSpread = node.attributes.some((x) => t.isJSXSpreadAttribute(x));
680
+ const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
681
+ const shouldFlatten = !shouldDeopt && inlinePropCount === 0 && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
682
+ if (!shouldFlatten) {
683
+ attrs = attrs.reduce((acc, cur) => {
684
+ var _a2, _b2;
685
+ if (cur.type === "style") {
686
+ for (const key in cur.value) {
687
+ const shouldEnsureOverridden = !!((_a2 = staticConfig.ensureOverriddenProp) == null ? void 0 : _a2[key]);
688
+ const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
689
+ if (!isSetInAttrsAlready) {
690
+ const isVariant = !!((_b2 = staticConfig.variants) == null ? void 0 : _b2[cur.name || ""]);
691
+ if (isVariant || shouldEnsureOverridden) {
692
+ acc.push({
693
+ type: "attr",
694
+ value: cur.attr || t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.nullLiteral()))
695
+ });
696
+ }
697
+ }
698
+ }
699
+ }
700
+ acc.push(cur);
701
+ return acc;
702
+ }, []);
703
+ }
704
+ if (shouldPrintDebug) {
705
+ console.log(" - attrs (flattened): \n", logLines(attrs.map(attrStr).join(", ")));
706
+ }
707
+ attrs = attrs.reduce((acc, cur) => {
708
+ if (cur.type === "style") {
709
+ let key = Object.keys(cur.value)[0];
710
+ let value = cur.value[key];
711
+ const nonShortKey = tamaguiConfig.shorthands[key];
712
+ if (nonShortKey) {
713
+ cur.value = { [nonShortKey]: value };
714
+ key = nonShortKey;
715
+ }
716
+ if (!shouldFlatten && stylePropsTransform[key] || !validStyles[key] && !pseudos[key] && !key.startsWith("data-")) {
717
+ acc.push({
718
+ type: "attr",
719
+ value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(typeof value === "string" ? t.stringLiteral(value) : literalToAst(value)))
720
+ });
721
+ return acc;
722
+ }
723
+ if (disableExtractVariables) {
724
+ if (value[0] === "$") {
725
+ if (shouldPrintDebug) {
726
+ console.log(` keeping variable inline: ${key} =`, value);
727
+ }
728
+ acc.push({
729
+ type: "attr",
730
+ value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.stringLiteral(value)))
731
+ });
732
+ return acc;
733
+ }
734
+ }
735
+ }
736
+ acc.push(cur);
737
+ return acc;
738
+ }, []);
739
+ if (shouldPrintDebug) {
740
+ console.log(" - attrs (evaluated): \n", logLines(attrs.map(attrStr).join(", ")));
741
+ }
742
+ let prev = null;
743
+ attrs = attrs.reduce((acc, cur) => {
744
+ if (cur.type === "style") {
745
+ if ((prev == null ? void 0 : prev.type) === "style") {
746
+ Object.assign(prev.value, cur.value);
747
+ return acc;
748
+ }
749
+ }
750
+ acc.push(cur);
751
+ prev = cur;
752
+ return acc;
753
+ }, []);
754
+ if (shouldPrintDebug) {
755
+ console.log(" - attrs (combined \u{1F500}): \n", logLines(attrs.map(attrStr).join(", ")));
756
+ }
757
+ const getStyles = /* @__PURE__ */ __name((props2) => {
758
+ var _a2;
759
+ if (!props2)
760
+ return;
761
+ if (!!excludeProps.size) {
762
+ for (const key in props2) {
763
+ if (isExcludedProp(key))
764
+ delete props2[key];
765
+ }
766
+ }
767
+ const out = postProcessStyles(props2, staticConfig, defaultTheme);
768
+ const next = (_a2 = out == null ? void 0 : out.style) != null ? _a2 : props2;
769
+ if (shouldPrintDebug) {
770
+ console.log(" -- viewProps:\n", logLines(objToStr(out.viewProps)));
771
+ console.log(" -- props:\n", logLines(objToStr(props2)));
772
+ console.log(" -- next:\n", logLines(objToStr(next)));
773
+ }
774
+ for (const key in next) {
775
+ if (staticConfig.validStyles) {
776
+ if (!staticConfig.validStyles[key] && !pseudos[key]) {
777
+ delete next[key];
778
+ }
779
+ }
780
+ }
781
+ return next;
782
+ }, "getStyles");
783
+ const completeStylesProcessed = getStyles({
784
+ ...staticConfig.defaultProps,
785
+ ...completeStaticProps
786
+ });
787
+ const stylesToAddToInitialGroup = difference(Object.keys(completeStylesProcessed), Object.keys(completeStaticProps));
788
+ if (stylesToAddToInitialGroup.length) {
789
+ const toAdd = pick(completeStylesProcessed, ...stylesToAddToInitialGroup);
790
+ const firstGroup = attrs.find((x) => x.type === "style");
791
+ if (shouldPrintDebug) {
792
+ console.log(" toAdd", objToStr(toAdd));
793
+ }
794
+ if (!firstGroup) {
795
+ attrs.unshift({ type: "style", value: toAdd });
796
+ } else {
797
+ Object.assign(firstGroup.value, toAdd);
798
+ }
799
+ }
800
+ if (shouldPrintDebug) {
801
+ console.log(" completeStaticProps\n", logLines(objToStr(completeStaticProps)));
802
+ console.log(" completeStylesProcessed\n", logLines(objToStr(completeStylesProcessed)));
803
+ }
804
+ let getStyleError = null;
805
+ for (const attr of attrs) {
806
+ try {
807
+ switch (attr.type) {
808
+ case "ternary":
809
+ const a = getStyles(attr.value.alternate);
810
+ const c = getStyles(attr.value.consequent);
811
+ attr.value.alternate = a;
812
+ attr.value.consequent = c;
813
+ if (shouldPrintDebug)
814
+ console.log(" => tern ", attrStr(attr));
815
+ continue;
816
+ case "style":
817
+ for (const keyIn in attr.value) {
818
+ const [key, value] = (() => {
819
+ var _a2;
820
+ if (keyIn in stylePropsTransform) {
821
+ return ["transform", completeStylesProcessed["transform"]];
822
+ } else {
823
+ return [keyIn, (_a2 = completeStylesProcessed[keyIn]) != null ? _a2 : attr.value[keyIn]];
824
+ }
825
+ })();
826
+ if (shouldPrintDebug)
827
+ console.log("style", { keyIn, key, value });
828
+ delete attr.value[keyIn];
829
+ attr.value[key] = value;
830
+ }
831
+ continue;
832
+ }
833
+ } catch (err) {
834
+ getStyleError = err;
835
+ }
836
+ }
837
+ if (getStyleError) {
838
+ console.log(" \u26A0\uFE0F postprocessing error, deopt", getStyleError);
839
+ node.attributes = ogAttributes;
840
+ return node;
841
+ }
842
+ if (shouldPrintDebug) {
843
+ console.log(" - attrs (after):\n", logLines(attrs.map(attrStr).join(", ")));
844
+ }
845
+ if (shouldFlatten) {
846
+ if (shouldPrintDebug) {
847
+ console.log(" [\u2705] flattening", originalNodeName, flatNode);
848
+ }
849
+ isFlattened = true;
850
+ node.name.name = flatNode;
851
+ res.flattened++;
852
+ if (closingElement) {
853
+ closingElement.name.name = flatNode;
854
+ }
855
+ }
856
+ if (shouldPrintDebug) {
857
+ console.log(" [\u274A] inline props ", inlinePropCount, shouldDeopt ? " deopted" : "", hasSpread ? " spread" : "", "!flatten", staticConfig.neverFlatten);
858
+ console.log(" - attrs (end):\n", logLines(attrs.map(attrStr).join(", ")));
859
+ }
860
+ res.optimized++;
861
+ onExtractTag({
862
+ attrs,
863
+ node,
864
+ lineNumbers,
865
+ filePath,
866
+ attemptEval,
867
+ jsxPath: traversePath,
868
+ originalNodeName,
869
+ isFlattened,
870
+ programPath
871
+ });
872
+ }
873
+ });
874
+ if (modifiedComponents.size) {
875
+ const all = Array.from(modifiedComponents);
876
+ if (shouldPrintDebug) {
877
+ console.log(" [\u{1FA9D}] hook check", all.length);
878
+ }
879
+ for (const comp of all) {
880
+ removeUnusedHooks(comp, shouldPrintDebug);
881
+ }
882
+ }
883
+ return res;
884
+ }
885
+ };
886
+ }
887
+ __name(createExtractor, "createExtractor");
888
+ export {
889
+ createExtractor
890
+ };