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