@tamagui/static 1.13.2 → 1.13.4

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 (195) hide show
  1. package/dist/cjs/constants.js +1 -52
  2. package/dist/cjs/constants.js.map +2 -2
  3. package/dist/cjs/extractor/accessSafe.js +1 -52
  4. package/dist/cjs/extractor/accessSafe.js.map +2 -2
  5. package/dist/cjs/extractor/babelParse.js +1 -66
  6. package/dist/cjs/extractor/babelParse.js.map +2 -2
  7. package/dist/cjs/extractor/buildClassName.js +1 -99
  8. package/dist/cjs/extractor/buildClassName.js.map +2 -2
  9. package/dist/cjs/extractor/bundle.js +1 -126
  10. package/dist/cjs/extractor/bundle.js.map +2 -2
  11. package/dist/cjs/extractor/createEvaluator.js +1 -86
  12. package/dist/cjs/extractor/createEvaluator.js.map +2 -2
  13. package/dist/cjs/extractor/createExtractor.js +15 -1630
  14. package/dist/cjs/extractor/createExtractor.js.map +2 -2
  15. package/dist/cjs/extractor/ensureImportingConcat.js +1 -64
  16. package/dist/cjs/extractor/ensureImportingConcat.js.map +2 -2
  17. package/dist/cjs/extractor/evaluateAstNode.js +1 -130
  18. package/dist/cjs/extractor/evaluateAstNode.js.map +2 -2
  19. package/dist/cjs/extractor/extractHelpers.js +1 -207
  20. package/dist/cjs/extractor/extractHelpers.js.map +2 -2
  21. package/dist/cjs/extractor/extractMediaStyle.js +1 -193
  22. package/dist/cjs/extractor/extractMediaStyle.js.map +2 -2
  23. package/dist/cjs/extractor/extractToClassNames.js +13 -413
  24. package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
  25. package/dist/cjs/extractor/findTopmostFunction.js +1 -43
  26. package/dist/cjs/extractor/findTopmostFunction.js.map +2 -2
  27. package/dist/cjs/extractor/generatedUid.js +1 -59
  28. package/dist/cjs/extractor/generatedUid.js.map +2 -2
  29. package/dist/cjs/extractor/getPrefixLogs.js +1 -31
  30. package/dist/cjs/extractor/getPrefixLogs.js.map +2 -2
  31. package/dist/cjs/extractor/getPropValueFromAttributes.js +1 -89
  32. package/dist/cjs/extractor/getPropValueFromAttributes.js.map +2 -2
  33. package/dist/cjs/extractor/getSourceModule.js +1 -103
  34. package/dist/cjs/extractor/getSourceModule.js.map +2 -2
  35. package/dist/cjs/extractor/getStaticBindingsForScope.js +1 -225
  36. package/dist/cjs/extractor/getStaticBindingsForScope.js.map +2 -2
  37. package/dist/cjs/extractor/hoistClassNames.js +1 -74
  38. package/dist/cjs/extractor/hoistClassNames.js.map +2 -2
  39. package/dist/cjs/extractor/literalToAst.js +1 -115
  40. package/dist/cjs/extractor/literalToAst.js.map +2 -2
  41. package/dist/cjs/extractor/loadFile.js +2 -20
  42. package/dist/cjs/extractor/loadFile.js.map +2 -2
  43. package/dist/cjs/extractor/loadTamagui.js +15 -432
  44. package/dist/cjs/extractor/loadTamagui.js.map +2 -2
  45. package/dist/cjs/extractor/logLines.js +3 -43
  46. package/dist/cjs/extractor/logLines.js.map +2 -2
  47. package/dist/cjs/extractor/normalizeTernaries.js +1 -85
  48. package/dist/cjs/extractor/normalizeTernaries.js.map +2 -2
  49. package/dist/cjs/extractor/removeUnusedHooks.js +1 -109
  50. package/dist/cjs/extractor/removeUnusedHooks.js.map +2 -2
  51. package/dist/cjs/extractor/timer.js +1 -52
  52. package/dist/cjs/extractor/timer.js.map +2 -2
  53. package/dist/cjs/extractor/validHTMLAttributes.js +1 -126
  54. package/dist/cjs/extractor/validHTMLAttributes.js.map +2 -2
  55. package/dist/cjs/getPragmaOptions.js +2 -67
  56. package/dist/cjs/getPragmaOptions.js.map +2 -2
  57. package/dist/cjs/helpers/memoize.js +1 -45
  58. package/dist/cjs/helpers/memoize.js.map +2 -2
  59. package/dist/cjs/index.js +1 -42
  60. package/dist/cjs/index.js.map +2 -2
  61. package/dist/cjs/require.js +5 -81
  62. package/dist/cjs/require.js.map +2 -2
  63. package/dist/cjs/types.js +1 -16
  64. package/dist/cjs/types.js.map +2 -2
  65. package/dist/cjs/webpackPlugin.js +1 -34
  66. package/dist/cjs/webpackPlugin.js.map +2 -2
  67. package/dist/esm/constants.js +1 -14
  68. package/dist/esm/constants.js.map +2 -2
  69. package/dist/esm/constants.mjs +1 -14
  70. package/dist/esm/constants.mjs.map +2 -2
  71. package/dist/esm/extractor/accessSafe.js +1 -18
  72. package/dist/esm/extractor/accessSafe.js.map +2 -2
  73. package/dist/esm/extractor/accessSafe.mjs +1 -18
  74. package/dist/esm/extractor/accessSafe.mjs.map +2 -2
  75. package/dist/esm/extractor/babelParse.js +1 -31
  76. package/dist/esm/extractor/babelParse.js.map +2 -2
  77. package/dist/esm/extractor/babelParse.mjs +1 -31
  78. package/dist/esm/extractor/babelParse.mjs.map +2 -2
  79. package/dist/esm/extractor/buildClassName.js +1 -64
  80. package/dist/esm/extractor/buildClassName.js.map +2 -2
  81. package/dist/esm/extractor/buildClassName.mjs +1 -64
  82. package/dist/esm/extractor/buildClassName.mjs.map +2 -2
  83. package/dist/esm/extractor/bundle.js +1 -91
  84. package/dist/esm/extractor/bundle.js.map +2 -2
  85. package/dist/esm/extractor/bundle.mjs +1 -91
  86. package/dist/esm/extractor/bundle.mjs.map +2 -2
  87. package/dist/esm/extractor/createEvaluator.js +1 -51
  88. package/dist/esm/extractor/createEvaluator.js.map +2 -2
  89. package/dist/esm/extractor/createEvaluator.mjs +1 -51
  90. package/dist/esm/extractor/createEvaluator.mjs.map +2 -2
  91. package/dist/esm/extractor/createExtractor.js +15 -1613
  92. package/dist/esm/extractor/createExtractor.js.map +2 -2
  93. package/dist/esm/extractor/createExtractor.mjs +15 -1613
  94. package/dist/esm/extractor/createExtractor.mjs.map +2 -2
  95. package/dist/esm/extractor/ensureImportingConcat.js +1 -30
  96. package/dist/esm/extractor/ensureImportingConcat.js.map +2 -2
  97. package/dist/esm/extractor/ensureImportingConcat.mjs +1 -30
  98. package/dist/esm/extractor/ensureImportingConcat.mjs.map +2 -2
  99. package/dist/esm/extractor/evaluateAstNode.js +1 -96
  100. package/dist/esm/extractor/evaluateAstNode.js.map +2 -2
  101. package/dist/esm/extractor/evaluateAstNode.mjs +1 -96
  102. package/dist/esm/extractor/evaluateAstNode.mjs.map +2 -2
  103. package/dist/esm/extractor/extractHelpers.js +1 -161
  104. package/dist/esm/extractor/extractHelpers.js.map +2 -2
  105. package/dist/esm/extractor/extractHelpers.mjs +1 -161
  106. package/dist/esm/extractor/extractHelpers.mjs.map +2 -2
  107. package/dist/esm/extractor/extractMediaStyle.js +1 -158
  108. package/dist/esm/extractor/extractMediaStyle.js.map +2 -2
  109. package/dist/esm/extractor/extractMediaStyle.mjs +1 -158
  110. package/dist/esm/extractor/extractMediaStyle.mjs.map +2 -2
  111. package/dist/esm/extractor/extractToClassNames.js +13 -379
  112. package/dist/esm/extractor/extractToClassNames.js.map +2 -2
  113. package/dist/esm/extractor/extractToClassNames.mjs +13 -379
  114. package/dist/esm/extractor/extractToClassNames.mjs.map +2 -2
  115. package/dist/esm/extractor/findTopmostFunction.js +1 -19
  116. package/dist/esm/extractor/findTopmostFunction.js.map +2 -2
  117. package/dist/esm/extractor/findTopmostFunction.mjs +1 -19
  118. package/dist/esm/extractor/findTopmostFunction.mjs.map +2 -2
  119. package/dist/esm/extractor/generatedUid.js +1 -25
  120. package/dist/esm/extractor/generatedUid.js.map +2 -2
  121. package/dist/esm/extractor/generatedUid.mjs +1 -25
  122. package/dist/esm/extractor/generatedUid.mjs.map +2 -2
  123. package/dist/esm/extractor/getPrefixLogs.js +1 -7
  124. package/dist/esm/extractor/getPrefixLogs.js.map +2 -2
  125. package/dist/esm/extractor/getPrefixLogs.mjs +1 -7
  126. package/dist/esm/extractor/getPrefixLogs.mjs.map +2 -2
  127. package/dist/esm/extractor/getPropValueFromAttributes.js +1 -55
  128. package/dist/esm/extractor/getPropValueFromAttributes.js.map +2 -2
  129. package/dist/esm/extractor/getPropValueFromAttributes.mjs +1 -55
  130. package/dist/esm/extractor/getPropValueFromAttributes.mjs.map +2 -2
  131. package/dist/esm/extractor/getSourceModule.js +1 -69
  132. package/dist/esm/extractor/getSourceModule.js.map +2 -2
  133. package/dist/esm/extractor/getSourceModule.mjs +1 -69
  134. package/dist/esm/extractor/getSourceModule.mjs.map +2 -2
  135. package/dist/esm/extractor/getStaticBindingsForScope.js +1 -190
  136. package/dist/esm/extractor/getStaticBindingsForScope.js.map +2 -2
  137. package/dist/esm/extractor/getStaticBindingsForScope.mjs +1 -190
  138. package/dist/esm/extractor/getStaticBindingsForScope.mjs.map +2 -2
  139. package/dist/esm/extractor/hoistClassNames.js +1 -40
  140. package/dist/esm/extractor/hoistClassNames.js.map +2 -2
  141. package/dist/esm/extractor/hoistClassNames.mjs +1 -40
  142. package/dist/esm/extractor/hoistClassNames.mjs.map +2 -2
  143. package/dist/esm/extractor/literalToAst.js +1 -80
  144. package/dist/esm/extractor/literalToAst.js.map +2 -2
  145. package/dist/esm/extractor/literalToAst.mjs +1 -80
  146. package/dist/esm/extractor/literalToAst.mjs.map +2 -2
  147. package/dist/esm/extractor/loadFile.js +2 -19
  148. package/dist/esm/extractor/loadFile.js.map +2 -2
  149. package/dist/esm/extractor/loadFile.mjs +2 -19
  150. package/dist/esm/extractor/loadFile.mjs.map +2 -2
  151. package/dist/esm/extractor/loadTamagui.js +15 -396
  152. package/dist/esm/extractor/loadTamagui.js.map +2 -2
  153. package/dist/esm/extractor/loadTamagui.mjs +15 -396
  154. package/dist/esm/extractor/loadTamagui.mjs.map +2 -2
  155. package/dist/esm/extractor/logLines.js +3 -19
  156. package/dist/esm/extractor/logLines.js.map +2 -2
  157. package/dist/esm/extractor/logLines.mjs +3 -19
  158. package/dist/esm/extractor/logLines.mjs.map +2 -2
  159. package/dist/esm/extractor/normalizeTernaries.js +1 -51
  160. package/dist/esm/extractor/normalizeTernaries.js.map +2 -2
  161. package/dist/esm/extractor/normalizeTernaries.mjs +1 -51
  162. package/dist/esm/extractor/normalizeTernaries.mjs.map +2 -2
  163. package/dist/esm/extractor/removeUnusedHooks.js +1 -75
  164. package/dist/esm/extractor/removeUnusedHooks.js.map +2 -2
  165. package/dist/esm/extractor/removeUnusedHooks.mjs +1 -75
  166. package/dist/esm/extractor/removeUnusedHooks.mjs.map +2 -2
  167. package/dist/esm/extractor/timer.js +1 -28
  168. package/dist/esm/extractor/timer.js.map +2 -2
  169. package/dist/esm/extractor/timer.mjs +1 -28
  170. package/dist/esm/extractor/timer.mjs.map +2 -2
  171. package/dist/esm/extractor/validHTMLAttributes.js +1 -101
  172. package/dist/esm/extractor/validHTMLAttributes.js.map +2 -2
  173. package/dist/esm/extractor/validHTMLAttributes.mjs +1 -101
  174. package/dist/esm/extractor/validHTMLAttributes.mjs.map +2 -2
  175. package/dist/esm/getPragmaOptions.js +2 -43
  176. package/dist/esm/getPragmaOptions.js.map +2 -2
  177. package/dist/esm/getPragmaOptions.mjs +2 -43
  178. package/dist/esm/getPragmaOptions.mjs.map +2 -2
  179. package/dist/esm/helpers/memoize.js +1 -21
  180. package/dist/esm/helpers/memoize.js.map +2 -2
  181. package/dist/esm/helpers/memoize.mjs +1 -21
  182. package/dist/esm/helpers/memoize.mjs.map +2 -2
  183. package/dist/esm/index.js +1 -15
  184. package/dist/esm/index.js.map +2 -2
  185. package/dist/esm/index.mjs +1 -15
  186. package/dist/esm/index.mjs.map +2 -2
  187. package/dist/esm/require.js +5 -55
  188. package/dist/esm/require.js.map +2 -2
  189. package/dist/esm/require.mjs +5 -55
  190. package/dist/esm/require.mjs.map +2 -2
  191. package/dist/esm/webpackPlugin.js +1 -10
  192. package/dist/esm/webpackPlugin.js.map +2 -2
  193. package/dist/esm/webpackPlugin.mjs +1 -10
  194. package/dist/esm/webpackPlugin.mjs.map +2 -2
  195. package/package.json +14 -14
@@ -1,1614 +1,16 @@
1
- import { basename, relative } from "path";
2
- import traverse from "@babel/traverse";
3
- import * as t from "@babel/types";
4
- import {
5
- expandStyles,
6
- getSplitStyles,
7
- mediaQueryConfig,
8
- proxyThemeVariables,
9
- pseudoDescriptors
10
- } from "@tamagui/core-node";
11
- import { createDOMProps } from "react-native-web-internals";
12
- import { FAILED_EVAL } from "../constants.js";
13
- import { createEvaluator, createSafeEvaluator } from "./createEvaluator.js";
14
- import { evaluateAstNode } from "./evaluateAstNode.js";
15
- import {
16
- attrStr,
17
- findComponentName,
18
- getValidComponent,
19
- getValidImport,
20
- isPresent,
21
- isValidImport,
22
- objToStr
23
- } from "./extractHelpers.js";
24
- import { findTopmostFunction } from "./findTopmostFunction.js";
25
- import {
26
- cleanupBeforeExit,
27
- getStaticBindingsForScope
28
- } from "./getStaticBindingsForScope.js";
29
- import { literalToAst } from "./literalToAst.js";
30
- import { loadTamagui, loadTamaguiSync } from "./loadTamagui.js";
31
- import { logLines } from "./logLines.js";
32
- import { normalizeTernaries } from "./normalizeTernaries.js";
33
- import { removeUnusedHooks } from "./removeUnusedHooks.js";
34
- import { timer } from "./timer.js";
35
- import { validHTMLAttributes } from "./validHTMLAttributes.js";
36
- const UNTOUCHED_PROPS = {
37
- key: true,
38
- style: true,
39
- className: true
40
- };
41
- const INLINE_EXTRACTABLE = {
42
- ref: "ref",
43
- key: "key",
44
- ...process.env.TAMAGUI_TARGET === "web" && {
45
- onPress: "onClick",
46
- onHoverIn: "onMouseEnter",
47
- onHoverOut: "onMouseLeave",
48
- onPressIn: "onMouseDown",
49
- onPressOut: "onMouseUp"
50
- }
51
- };
52
- const validHooks = {
53
- useMedia: true,
54
- useTheme: true
55
- };
56
- const isAttr = (x) => x.type === "attr";
57
- const createTernary = (x) => x;
58
- let hasLoggedBaseInfo = false;
59
- function createExtractor({ logger = console } = { logger: console }) {
60
- if (!process.env.TAMAGUI_TARGET) {
61
- console.log('\u26A0\uFE0F Please set process.env.TAMAGUI_TARGET to either "web" or "native"');
62
- process.exit(1);
63
- }
64
- const shouldAddDebugProp = (
65
- // really basic disable this for next.js because it messes with ssr
66
- !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)
67
- );
68
- let projectInfo = null;
69
- function loadSync(props) {
70
- return projectInfo ||= loadTamaguiSync({
71
- config: props.config || "tamagui.config.ts",
72
- components: props.components || ["tamagui"]
73
- });
74
- }
75
- async function load(props) {
76
- return projectInfo ||= await loadTamagui({
77
- config: props.config || "tamagui.config.ts",
78
- components: props.components || ["tamagui"]
79
- });
80
- }
81
- return {
82
- options: {
83
- logger
84
- },
85
- cleanupBeforeExit,
86
- loadTamagui: load,
87
- loadTamaguiSync: loadSync,
88
- getTamagui() {
89
- return projectInfo == null ? void 0 : projectInfo.tamaguiConfig;
90
- },
91
- parseSync: (f, props) => {
92
- const projectInfo2 = loadSync(props);
93
- return parseWithConfig(projectInfo2, f, props);
94
- },
95
- parse: async (f, props) => {
96
- const projectInfo2 = await load(props);
97
- return parseWithConfig(projectInfo2, f, props);
98
- }
99
- };
100
- function parseWithConfig({ components, tamaguiConfig }, fileOrPath, options) {
101
- var _a;
102
- const {
103
- config = "tamagui.config.ts",
104
- importsWhitelist = ["constants.js"],
105
- evaluateVars = true,
106
- sourcePath = "",
107
- onExtractTag,
108
- onStyleRule,
109
- getFlattenedNode,
110
- disable,
111
- disableExtraction,
112
- disableExtractInlineMedia,
113
- disableExtractVariables,
114
- disableDebugAttr,
115
- disableExtractFoundComponents,
116
- includeExtensions = [".ts", ".tsx", ".jsx"],
117
- extractStyledDefinitions = false,
118
- prefixLogs,
119
- excludeProps,
120
- target,
121
- ...restProps
122
- } = options;
123
- let shouldPrintDebug = options.shouldPrintDebug || false;
124
- if (disable === true || Array.isArray(disable) && disable.includes(sourcePath)) {
125
- return null;
126
- }
127
- if (!components) {
128
- throw new Error(`Must provide components`);
129
- }
130
- if (sourcePath && includeExtensions && !includeExtensions.some((ext) => sourcePath.endsWith(ext))) {
131
- if (shouldPrintDebug) {
132
- logger.info(
133
- `Ignoring file due to includeExtensions: ${sourcePath}, includeExtensions: ${includeExtensions.join(
134
- ", "
135
- )}`
136
- );
137
- }
138
- return null;
139
- }
140
- function isValidStyleKey(name, staticConfig) {
141
- var _a2, _b;
142
- if (!projectInfo) {
143
- throw new Error(`Tamagui extractor not loaded yet`);
144
- }
145
- if (target === "native" && name[0] === "$" && mediaQueryConfig[name.slice(1)]) {
146
- return false;
147
- }
148
- return !!(!!((_a2 = staticConfig.validStyles) == null ? void 0 : _a2[name]) || !!pseudoDescriptors[name] || // dont disable variants or else you lose many things flattening
149
- ((_b = staticConfig.variants) == null ? void 0 : _b[name]) || (projectInfo == null ? void 0 : projectInfo.tamaguiConfig.shorthands[name]) || (name[0] === "$" ? !!mediaQueryConfig[name.slice(1)] : false));
150
- }
151
- const isTargetingHTML = target === "html";
152
- const ogDebug = shouldPrintDebug;
153
- const tm = timer();
154
- const propsWithFileInfo = {
155
- ...options,
156
- sourcePath,
157
- allLoadedComponents: [...components]
158
- };
159
- if (!hasLoggedBaseInfo) {
160
- hasLoggedBaseInfo = true;
161
- if (shouldPrintDebug) {
162
- logger.info(
163
- [
164
- "loaded components:",
165
- propsWithFileInfo.allLoadedComponents.map((comp) => Object.keys(comp.nameToInfo).join(", ")).join(", ")
166
- ].join(" ")
167
- );
168
- }
169
- if ((_a = process.env.DEBUG) == null ? void 0 : _a.startsWith("tamagui")) {
170
- const next = [...propsWithFileInfo.allLoadedComponents].map((info) => {
171
- const nameToInfo = { ...info.nameToInfo };
172
- for (const key in nameToInfo) {
173
- delete nameToInfo[key].staticConfig.validStyles;
174
- }
175
- return { ...info, nameToInfo };
176
- });
177
- logger.info(["loaded:", JSON.stringify(next, null, 2)].join("\n"));
178
- }
179
- }
180
- tm.mark("load-tamagui", !!shouldPrintDebug);
181
- const firstThemeName = Object.keys(tamaguiConfig.themes)[0];
182
- const firstTheme = tamaguiConfig.themes[firstThemeName];
183
- if (!firstTheme || typeof firstTheme !== "object") {
184
- console.error(`Missing theme, an error occurred when importing your config`);
185
- console.log(`Got config:`, tamaguiConfig);
186
- console.log(`Looking for theme:`, firstThemeName);
187
- process.exit(0);
188
- }
189
- const proxiedTheme = proxyThemeVariables(firstTheme);
190
- const themeAccessListeners = /* @__PURE__ */ new Set();
191
- const defaultTheme = new Proxy(proxiedTheme, {
192
- get(target2, key) {
193
- if (Reflect.has(target2, key)) {
194
- themeAccessListeners.forEach((cb) => cb(String(key)));
195
- }
196
- return Reflect.get(target2, key);
197
- }
198
- });
199
- const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
200
- if (Object.keys(components).length === 0) {
201
- console.warn(
202
- `Warning: Tamagui didn't find any valid components (DEBUG=tamagui for more)`
203
- );
204
- if (process.env.DEBUG === "tamagui") {
205
- console.log(`components`, Object.keys(components), components);
206
- }
207
- }
208
- if (shouldPrintDebug === "verbose") {
209
- logger.info(
210
- `allLoadedComponent modules ${propsWithFileInfo.allLoadedComponents.map((k) => k.moduleName).join(", ")}`
211
- );
212
- }
213
- let doesUseValidImport = false;
214
- let hasImportedTheme = false;
215
- const importDeclarations = [];
216
- for (const bodyPath of body) {
217
- if (bodyPath.type !== "ImportDeclaration")
218
- continue;
219
- const node = "node" in bodyPath ? bodyPath.node : bodyPath;
220
- const moduleName = node.source.value;
221
- const valid = isValidImport(propsWithFileInfo, moduleName);
222
- if (valid) {
223
- importDeclarations.push(node);
224
- }
225
- if (extractStyledDefinitions) {
226
- if (valid) {
227
- if (node.specifiers.some((specifier) => specifier.local.name === "styled")) {
228
- doesUseValidImport = true;
229
- break;
230
- }
231
- }
232
- }
233
- if (valid) {
234
- const names = node.specifiers.map((specifier) => specifier.local.name);
235
- const isValidComponent = names.some(
236
- (name) => Boolean(isValidImport(propsWithFileInfo, moduleName, name) || validHooks[name])
237
- );
238
- if (shouldPrintDebug === "verbose") {
239
- logger.info(
240
- `import ${names.join(
241
- ", "
242
- )} from ${moduleName} isValidComponent ${isValidComponent}`
243
- );
244
- }
245
- if (isValidComponent) {
246
- doesUseValidImport = true;
247
- break;
248
- }
249
- }
250
- }
251
- if (shouldPrintDebug) {
252
- logger.info(
253
- `file: ${sourcePath} ${JSON.stringify({ doesUseValidImport, hasImportedTheme })}`
254
- );
255
- }
256
- if (!doesUseValidImport) {
257
- return null;
258
- }
259
- function getValidImportedComponent(componentName) {
260
- const importDeclaration = importDeclarations.find(
261
- (dec) => dec.specifiers.some((spec) => spec.local.name === componentName)
262
- );
263
- if (!importDeclaration) {
264
- return null;
265
- }
266
- return getValidImport(
267
- propsWithFileInfo,
268
- importDeclaration.source.value,
269
- componentName
270
- );
271
- }
272
- tm.mark("import-check", !!shouldPrintDebug);
273
- let couldntParse = false;
274
- const modifiedComponents = /* @__PURE__ */ new Set();
275
- const bindingCache = {};
276
- const callTraverse = (a) => {
277
- return fileOrPath.type === "File" ? traverse(fileOrPath, a) : fileOrPath.traverse(a);
278
- };
279
- const shouldDisableExtraction = disableExtraction === true || Array.isArray(disableExtraction) && disableExtraction.includes(sourcePath);
280
- let programPath = null;
281
- const res = {
282
- styled: 0,
283
- flattened: 0,
284
- optimized: 0,
285
- modified: 0,
286
- found: 0
287
- };
288
- callTraverse({
289
- // @ts-ignore
290
- Program: {
291
- enter(path) {
292
- programPath = path;
293
- }
294
- },
295
- // styled() calls
296
- CallExpression(path) {
297
- var _a2;
298
- if (disable || shouldDisableExtraction || extractStyledDefinitions === false) {
299
- return;
300
- }
301
- if (!t.isIdentifier(path.node.callee) || path.node.callee.name !== "styled") {
302
- return;
303
- }
304
- const variableName = t.isVariableDeclarator(path.parent) && t.isIdentifier(path.parent.id) ? path.parent.id.name : "unknown";
305
- const parentNode = path.node.arguments[0];
306
- if (!t.isIdentifier(parentNode)) {
307
- return;
308
- }
309
- const parentName = parentNode.name;
310
- const definition = path.node.arguments[1];
311
- if (!parentName || !definition || !t.isObjectExpression(definition)) {
312
- return;
313
- }
314
- const Component = getValidImportedComponent(parentName);
315
- if (!Component) {
316
- return;
317
- }
318
- const componentSkipProps = /* @__PURE__ */ new Set([
319
- ...Component.staticConfig.inlineWhenUnflattened || [],
320
- ...Component.staticConfig.inlineProps || [],
321
- ...Component.staticConfig.deoptProps || [],
322
- // for now skip variants, will return to them
323
- "variants",
324
- "defaultVariants",
325
- // skip fontFamily its basically a "variant", important for theme use to be value always
326
- "fontFamily",
327
- "name",
328
- "focusStyle",
329
- "hoverStyle",
330
- "pressStyle"
331
- ]);
332
- const skipped = [];
333
- const styles = {};
334
- const staticNamespace = getStaticBindingsForScope(
335
- path.scope,
336
- importsWhitelist,
337
- sourcePath,
338
- bindingCache,
339
- shouldPrintDebug
340
- );
341
- const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
342
- props: propsWithFileInfo,
343
- staticNamespace,
344
- sourcePath,
345
- shouldPrintDebug
346
- });
347
- const attemptEvalSafe = createSafeEvaluator(attemptEval);
348
- for (const property of definition.properties) {
349
- if (!t.isObjectProperty(property) || !t.isIdentifier(property.key) || !isValidStyleKey(property.key.name, Component.staticConfig) || // skip variants
350
- ((_a2 = Component.staticConfig.variants) == null ? void 0 : _a2[property.key.name]) || componentSkipProps.has(property.key.name)) {
351
- skipped.push(property);
352
- continue;
353
- }
354
- const out2 = attemptEvalSafe(property.value);
355
- if (out2 === FAILED_EVAL) {
356
- skipped.push(property);
357
- } else {
358
- styles[property.key.name] = out2;
359
- }
360
- }
361
- const out = getSplitStyles(
362
- styles,
363
- Component.staticConfig,
364
- defaultTheme,
365
- {
366
- focus: false,
367
- hover: false,
368
- unmounted: true,
369
- press: false,
370
- pressIn: false,
371
- resolveVariablesAs: "variable",
372
- noClassNames: false
373
- },
374
- void 0,
375
- void 0,
376
- void 0,
377
- shouldPrintDebug
378
- );
379
- const classNames = {
380
- ...out.classNames
381
- };
382
- if (shouldPrintDebug) {
383
- logger.info([`Extracted styled(${variableName})
384
- `, JSON.stringify(styles, null, 2), "\n rulesToInsert:", out.rulesToInsert.flatMap((rule) => rule.rules).join("\n")].join(" "));
385
- }
386
- definition.properties = skipped;
387
- for (const cn in classNames) {
388
- if (componentSkipProps.has(cn)) {
389
- continue;
390
- }
391
- const val = classNames[cn];
392
- definition.properties.push(
393
- t.objectProperty(t.stringLiteral(cn), t.stringLiteral(val))
394
- );
395
- }
396
- if (out.rulesToInsert) {
397
- for (const { identifier, rules } of out.rulesToInsert) {
398
- onStyleRule == null ? void 0 : onStyleRule(identifier, rules);
399
- }
400
- }
401
- res.styled++;
402
- if (shouldPrintDebug) {
403
- logger.info(`Extracted styled(${variableName})`);
404
- }
405
- },
406
- JSXElement(traversePath) {
407
- var _a2;
408
- tm.mark("jsx-element", !!shouldPrintDebug);
409
- const node = traversePath.node.openingElement;
410
- const ogAttributes = node.attributes.map((attr) => ({ ...attr }));
411
- const componentName = findComponentName(traversePath.scope);
412
- const closingElement = traversePath.node.closingElement;
413
- if (t.isJSXMemberExpression(closingElement == null ? void 0 : closingElement.name) || !t.isJSXIdentifier(node.name)) {
414
- return;
415
- }
416
- const binding = traversePath.scope.getBinding(node.name.name);
417
- let modulePath = "";
418
- if (binding) {
419
- if (!t.isImportDeclaration(binding.path.parent)) {
420
- if (shouldPrintDebug) {
421
- logger.info(` - Binding not import declaration, skip`);
422
- }
423
- return;
424
- }
425
- modulePath = binding.path.parent.source.value;
426
- if (!isValidImport(propsWithFileInfo, modulePath, binding.identifier.name)) {
427
- if (shouldPrintDebug) {
428
- logger.info(
429
- ` - Binding not internal import or from components ${binding.identifier.name} in ${modulePath}`
430
- );
431
- }
432
- return;
433
- }
434
- }
435
- const component = getValidComponent(propsWithFileInfo, modulePath, node.name.name);
436
- if (!component || !component.staticConfig) {
437
- if (shouldPrintDebug) {
438
- logger.info(` - No Tamagui conf on this: ${node.name.name}`);
439
- }
440
- return;
441
- }
442
- const originalNodeName = node.name.name;
443
- res.found++;
444
- const filePath = `./${relative(process.cwd(), sourcePath)}`;
445
- const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
446
- const codePosition = `${filePath}:${lineNumbers}`;
447
- const debugPropValue = node.attributes.filter(
448
- (n) => t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && n.name.name === "debug"
449
- ).map((n) => {
450
- if (n.value === null)
451
- return true;
452
- if (t.isStringLiteral(n.value))
453
- return n.value.value;
454
- return false;
455
- })[0];
456
- if (debugPropValue) {
457
- shouldPrintDebug = debugPropValue;
458
- }
459
- if (shouldPrintDebug) {
460
- logger.info("\n");
461
- logger.info(
462
- `\x1B[33m%s\x1B[0m ${componentName} | ${codePosition} -------------------`
463
- );
464
- logger.info(["\x1B[1m", "\x1B[32m", `<${originalNodeName} />`, disableDebugAttr ? "" : "\u{1F41B}"].join(" "));
465
- }
466
- if (shouldAddDebugProp && !disableDebugAttr) {
467
- res.modified++;
468
- node.attributes.unshift(
469
- t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(node.name.name))
470
- );
471
- if (componentName) {
472
- node.attributes.unshift(
473
- t.jsxAttribute(t.jsxIdentifier("data-in"), t.stringLiteral(componentName))
474
- );
475
- }
476
- node.attributes.unshift(
477
- t.jsxAttribute(
478
- t.jsxIdentifier("data-at"),
479
- t.stringLiteral(`${basename(filePath)}:${lineNumbers}`)
480
- )
481
- );
482
- }
483
- if (shouldDisableExtraction) {
484
- return;
485
- }
486
- try {
487
- let evaluateAttribute2 = function(path) {
488
- const attribute = path.node;
489
- const attr = { type: "attr", value: attribute };
490
- if (t.isJSXSpreadAttribute(attribute)) {
491
- const arg = attribute.argument;
492
- const conditional = t.isConditionalExpression(arg) ? (
493
- // <YStack {...isSmall ? { color: 'red } : { color: 'blue }}
494
- [arg.test, arg.consequent, arg.alternate]
495
- ) : t.isLogicalExpression(arg) && arg.operator === "&&" ? (
496
- // <YStack {...isSmall && { color: 'red }}
497
- [arg.left, arg.right, null]
498
- ) : null;
499
- if (conditional) {
500
- const [test, alt, cons] = conditional;
501
- if (!test)
502
- throw new Error(`no test`);
503
- if ([alt, cons].some((side) => side && !isStaticObject2(side))) {
504
- if (shouldPrintDebug) {
505
- logger.info(`not extractable ${alt} ${cons}`);
506
- }
507
- return attr;
508
- }
509
- return [
510
- ...createTernariesFromObjectProperties2(test, alt) || [],
511
- ...cons && createTernariesFromObjectProperties2(
512
- t.unaryExpression("!", test),
513
- cons
514
- ) || []
515
- ].map((ternary) => ({
516
- type: "ternary",
517
- value: ternary
518
- }));
519
- }
520
- }
521
- if (t.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name !== "string") {
522
- if (shouldPrintDebug) {
523
- logger.info(" ! inlining, spread attr");
524
- }
525
- inlined.set(`${Math.random()}`, "spread");
526
- return attr;
527
- }
528
- const name = attribute.name.name;
529
- if (excludeProps == null ? void 0 : excludeProps.has(name)) {
530
- if (shouldPrintDebug) {
531
- logger.info([" excluding prop", name].join(" "));
532
- }
533
- return null;
534
- }
535
- if (inlineProps.has(name)) {
536
- inlined.set(name, name);
537
- if (shouldPrintDebug) {
538
- logger.info([" ! inlining, inline prop", name].join(" "));
539
- }
540
- return attr;
541
- }
542
- if (deoptProps.has(name)) {
543
- shouldDeopt = true;
544
- inlined.set(name, name);
545
- if (shouldPrintDebug) {
546
- logger.info([" ! inlining, deopted prop", name].join(" "));
547
- }
548
- return attr;
549
- }
550
- if (UNTOUCHED_PROPS[name]) {
551
- return attr;
552
- }
553
- if (INLINE_EXTRACTABLE[name]) {
554
- inlined.set(name, INLINE_EXTRACTABLE[name]);
555
- return attr;
556
- }
557
- if (name.startsWith("data-")) {
558
- return attr;
559
- }
560
- if (name[0] === "$" && t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
561
- const shortname = name.slice(1);
562
- if (mediaQueryConfig[shortname]) {
563
- if (target === "native") {
564
- shouldDeopt = true;
565
- }
566
- if (disableExtractInlineMedia) {
567
- return attr;
568
- }
569
- const expression = attribute.value.expression;
570
- if (!t.isJSXEmptyExpression(expression)) {
571
- const ternaries2 = createTernariesFromObjectProperties2(
572
- t.stringLiteral(shortname),
573
- expression,
574
- {
575
- inlineMediaQuery: shortname
576
- }
577
- );
578
- if (ternaries2) {
579
- return ternaries2.map((value2) => ({
580
- type: "ternary",
581
- value: value2
582
- }));
583
- }
584
- }
585
- }
586
- }
587
- const [value, valuePath] = (() => {
588
- if (t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
589
- return [attribute.value.expression, path.get("value")];
590
- } else {
591
- return [attribute.value, path.get("value")];
592
- }
593
- })();
594
- const remove = () => {
595
- Array.isArray(valuePath) ? valuePath.map((p) => p.remove()) : valuePath.remove();
596
- };
597
- if (name === "ref") {
598
- if (shouldPrintDebug) {
599
- logger.info([" ! inlining, ref", name].join(" "));
600
- }
601
- inlined.set("ref", "ref");
602
- return attr;
603
- }
604
- if (name === "tag") {
605
- return {
606
- type: "attr",
607
- value: path.node
608
- };
609
- }
610
- if (disableExtractVariables === true) {
611
- if (value) {
612
- if (value.type === "StringLiteral" && value.value[0] === "$") {
613
- if (shouldPrintDebug) {
614
- logger.info(
615
- [
616
- ` ! inlining, native disable extract: ${name} =`,
617
- value.value
618
- ].join(" ")
619
- );
620
- }
621
- inlined.set(name, true);
622
- return attr;
623
- }
624
- }
625
- }
626
- if (name === "theme") {
627
- inlined.set("theme", attr.value);
628
- return attr;
629
- }
630
- const styleValue = attemptEvalSafe(value);
631
- if (!variants[name] && !isValidStyleKey(name, staticConfig)) {
632
- let keys = [name];
633
- let out = null;
634
- out = staticConfig.propMapper(
635
- name,
636
- styleValue,
637
- defaultTheme,
638
- staticConfig.defaultProps,
639
- { resolveVariablesAs: "auto" },
640
- void 0,
641
- void 0,
642
- shouldPrintDebug
643
- );
644
- if (out) {
645
- if (!Array.isArray(out)) {
646
- logger.warn(`Error expected array but got`, out);
647
- couldntParse = true;
648
- shouldDeopt = true;
649
- } else {
650
- out = Object.fromEntries(out);
651
- keys = Object.keys(out);
652
- }
653
- }
654
- if (out) {
655
- if (isTargetingHTML) {
656
- out = createDOMProps(isTextView ? "span" : "div", out);
657
- delete out.className;
658
- }
659
- keys = Object.keys(out);
660
- }
661
- let didInline = false;
662
- const attributes = keys.map((key) => {
663
- const val = out[key];
664
- const isStyle = isValidStyleKey(key, staticConfig);
665
- if (isStyle) {
666
- return {
667
- type: "style",
668
- value: { [key]: styleValue },
669
- name: key,
670
- attr: path.node
671
- };
672
- }
673
- if (validHTMLAttributes[key] || key.startsWith("aria-") || key.startsWith("data-") || // this is debug stuff added by vite / new jsx transform
674
- key === "__source" || key === "__self") {
675
- return attr;
676
- }
677
- if (shouldPrintDebug) {
678
- logger.info(" ! inlining, non-static " + key);
679
- }
680
- didInline = true;
681
- inlined.set(key, val);
682
- return val;
683
- });
684
- if (didInline) {
685
- if (shouldPrintDebug) {
686
- logger.info(` bailing flattening due to attributes ${attributes}`);
687
- }
688
- return attr;
689
- }
690
- return attributes;
691
- }
692
- if (styleValue !== FAILED_EVAL) {
693
- if (inlineWhenUnflattened.has(name)) {
694
- inlineWhenUnflattenedOGVals[name] = { styleValue, attr };
695
- }
696
- if (isValidStyleKey(name, staticConfig)) {
697
- if (shouldPrintDebug) {
698
- logger.info(` style: ${name} = ${styleValue}`);
699
- }
700
- if (!(name in staticConfig.defaultProps)) {
701
- if (!hasSetOptimized) {
702
- res.optimized++;
703
- hasSetOptimized = true;
704
- }
705
- }
706
- return {
707
- type: "style",
708
- value: { [name]: styleValue },
709
- name,
710
- attr: path.node
711
- };
712
- } else {
713
- if (variants[name]) {
714
- variantValues.set(name, styleValue);
715
- }
716
- inlined.set(name, true);
717
- return attr;
718
- }
719
- }
720
- if (t.isBinaryExpression(value)) {
721
- if (shouldPrintDebug) {
722
- logger.info(` binary expression ${name} = ${value}`);
723
- }
724
- const { operator, left, right } = value;
725
- const lVal = attemptEvalSafe(left);
726
- const rVal = attemptEvalSafe(right);
727
- if (shouldPrintDebug) {
728
- logger.info(
729
- ` evalBinaryExpression lVal ${String(lVal)}, rVal ${String(rVal)}`
730
- );
731
- }
732
- if (lVal !== FAILED_EVAL && t.isConditionalExpression(right)) {
733
- const ternary = addBinaryConditional(operator, left, right);
734
- if (ternary)
735
- return ternary;
736
- }
737
- if (rVal !== FAILED_EVAL && t.isConditionalExpression(left)) {
738
- const ternary = addBinaryConditional(operator, right, left);
739
- if (ternary)
740
- return ternary;
741
- }
742
- if (shouldPrintDebug) {
743
- logger.info(` evalBinaryExpression cant extract`);
744
- }
745
- inlined.set(name, true);
746
- return attr;
747
- }
748
- const staticConditional = getStaticConditional(value);
749
- if (staticConditional) {
750
- if (shouldPrintDebug === "verbose") {
751
- logger.info(` static conditional ${name} ${value}`);
752
- }
753
- return { type: "ternary", value: staticConditional };
754
- }
755
- const staticLogical = getStaticLogical(value);
756
- if (staticLogical) {
757
- if (shouldPrintDebug === "verbose") {
758
- logger.info(` static ternary ${name} = ${value}`);
759
- }
760
- return { type: "ternary", value: staticLogical };
761
- }
762
- inlined.set(name, true);
763
- if (shouldPrintDebug) {
764
- logger.info(` ! inline no match ${name} ${value}`);
765
- }
766
- return attr;
767
- function addBinaryConditional(operator, staticExpr, cond) {
768
- if (getStaticConditional(cond)) {
769
- const alt = attemptEval(
770
- t.binaryExpression(operator, staticExpr, cond.alternate)
771
- );
772
- const cons = attemptEval(
773
- t.binaryExpression(operator, staticExpr, cond.consequent)
774
- );
775
- if (shouldPrintDebug) {
776
- logger.info([" binaryConditional", cond.test, cons, alt].join(" "));
777
- }
778
- return {
779
- type: "ternary",
780
- value: {
781
- test: cond.test,
782
- remove,
783
- alternate: { [name]: alt },
784
- consequent: { [name]: cons }
785
- }
786
- };
787
- }
788
- return null;
789
- }
790
- function getStaticConditional(value2) {
791
- if (t.isConditionalExpression(value2)) {
792
- try {
793
- const aVal = attemptEval(value2.alternate);
794
- const cVal = attemptEval(value2.consequent);
795
- if (shouldPrintDebug) {
796
- const type = value2.test.type;
797
- logger.info([" static ternary", type, cVal, aVal].join(" "));
798
- }
799
- return {
800
- test: value2.test,
801
- remove,
802
- consequent: { [name]: cVal },
803
- alternate: { [name]: aVal }
804
- };
805
- } catch (err) {
806
- if (shouldPrintDebug) {
807
- logger.info([" cant eval ternary", err.message].join(" "));
808
- }
809
- }
810
- }
811
- return null;
812
- }
813
- function getStaticLogical(value2) {
814
- if (t.isLogicalExpression(value2)) {
815
- if (value2.operator === "&&") {
816
- try {
817
- const val = attemptEval(value2.right);
818
- if (shouldPrintDebug) {
819
- logger.info([" staticLogical", value2.left, name, val].join(" "));
820
- }
821
- return {
822
- test: value2.left,
823
- remove,
824
- consequent: { [name]: val },
825
- alternate: null
826
- };
827
- } catch (err) {
828
- if (shouldPrintDebug) {
829
- logger.info([" cant static eval logical", err].join(" "));
830
- }
831
- }
832
- }
833
- }
834
- return null;
835
- }
836
- }, isStaticObject2 = function(obj) {
837
- return t.isObjectExpression(obj) && obj.properties.every((prop) => {
838
- if (!t.isObjectProperty(prop)) {
839
- logger.info(["not object prop", prop].join(" "));
840
- return false;
841
- }
842
- const propName = prop.key["name"];
843
- if (!isValidStyleKey(propName, staticConfig) && propName !== "tag") {
844
- if (shouldPrintDebug) {
845
- logger.info([" not a valid style prop!", propName].join(" "));
846
- }
847
- return false;
848
- }
849
- return true;
850
- });
851
- }, createTernariesFromObjectProperties2 = function(test, side, ternaryPartial = {}) {
852
- if (!side) {
853
- return null;
854
- }
855
- if (!isStaticObject2(side)) {
856
- throw new Error("not extractable");
857
- }
858
- return side.properties.flatMap((property) => {
859
- if (!t.isObjectProperty(property)) {
860
- throw new Error("expected object property");
861
- }
862
- if (t.isIdentifier(property.key)) {
863
- const key = property.key.name;
864
- const mediaQueryKey = key.slice(1);
865
- const isMediaQuery = key[0] === "$" && mediaQueryConfig[mediaQueryKey];
866
- if (isMediaQuery) {
867
- if (t.isExpression(property.value)) {
868
- const ternaries2 = createTernariesFromObjectProperties2(
869
- t.stringLiteral(mediaQueryKey),
870
- property.value,
871
- {
872
- inlineMediaQuery: mediaQueryKey
873
- }
874
- );
875
- if (ternaries2) {
876
- return ternaries2.map((value) => ({
877
- ...ternaryPartial,
878
- ...value,
879
- // ensure media query test stays on left side (see getMediaQueryTernary)
880
- test: t.logicalExpression("&&", value.test, test)
881
- }));
882
- } else {
883
- logger.info(["\u26A0\uFE0F no ternaries?", property].join(" "));
884
- }
885
- } else {
886
- logger.info(["\u26A0\uFE0F not expression", property].join(" "));
887
- }
888
- }
889
- }
890
- if (t.isConditionalExpression(property.value)) {
891
- const [truthy, falsy] = [
892
- t.objectExpression([
893
- t.objectProperty(property.key, property.value.consequent)
894
- ]),
895
- t.objectExpression([
896
- t.objectProperty(property.key, property.value.alternate)
897
- ])
898
- ].map((x) => attemptEval(x));
899
- return [
900
- createTernary({
901
- remove() {
902
- },
903
- ...ternaryPartial,
904
- test: t.logicalExpression("&&", test, property.value.test),
905
- consequent: truthy,
906
- alternate: null
907
- }),
908
- createTernary({
909
- ...ternaryPartial,
910
- test: t.logicalExpression(
911
- "&&",
912
- test,
913
- t.unaryExpression("!", property.value.test)
914
- ),
915
- consequent: falsy,
916
- alternate: null,
917
- remove() {
918
- }
919
- })
920
- ];
921
- }
922
- const obj = t.objectExpression([
923
- t.objectProperty(property.key, property.value)
924
- ]);
925
- const consequent = attemptEval(obj);
926
- return createTernary({
927
- remove() {
928
- },
929
- ...ternaryPartial,
930
- test,
931
- consequent,
932
- alternate: null
933
- });
934
- });
935
- }, splitVariants2 = function(style) {
936
- var _a3;
937
- const variants2 = {};
938
- const styles = {};
939
- for (const key in style) {
940
- if ((_a3 = staticConfig.variants) == null ? void 0 : _a3[key]) {
941
- variants2[key] = style[key];
942
- } else {
943
- styles[key] = style[key];
944
- }
945
- }
946
- return {
947
- variants: variants2,
948
- styles
949
- };
950
- }, expandStylesWithoutVariants2 = function(style) {
951
- const { variants: variants2, styles } = splitVariants2(style);
952
- return {
953
- ...expandStyles(styles),
954
- ...variants2
955
- };
956
- }, mergeStyles2 = function(prev2, next) {
957
- for (const key in next) {
958
- if (pseudoDescriptors[key]) {
959
- prev2[key] = prev2[key] || {};
960
- Object.assign(prev2[key], next[key]);
961
- } else {
962
- prev2[key] = next[key];
963
- }
964
- }
965
- };
966
- var evaluateAttribute = evaluateAttribute2, isStaticObject = isStaticObject2, createTernariesFromObjectProperties = createTernariesFromObjectProperties2, splitVariants = splitVariants2, expandStylesWithoutVariants = expandStylesWithoutVariants2, mergeStyles = mergeStyles2;
967
- const { staticConfig } = component;
968
- const variants = staticConfig.variants || {};
969
- const isTextView = staticConfig.isText || false;
970
- const validStyles = (staticConfig == null ? void 0 : staticConfig.validStyles) ?? {};
971
- let tagName = staticConfig.defaultProps.tag ?? (isTextView ? "span" : "div");
972
- traversePath.get("openingElement").get("attributes").forEach((path) => {
973
- const attr = path.node;
974
- if (t.isJSXSpreadAttribute(attr))
975
- return;
976
- if (attr.name.name !== "tag")
977
- return;
978
- const val = attr.value;
979
- if (!t.isStringLiteral(val))
980
- return;
981
- tagName = val.value;
982
- });
983
- const flatNode = getFlattenedNode == null ? void 0 : getFlattenedNode({ isTextView, tag: tagName });
984
- const inlineProps = /* @__PURE__ */ new Set([
985
- // adding some always inline props
986
- "dataSet",
987
- ...restProps.inlineProps || [],
988
- ...staticConfig.inlineProps || []
989
- ]);
990
- const deoptProps = /* @__PURE__ */ new Set([
991
- // always de-opt animation
992
- "animation",
993
- ...restProps.deoptProps || [],
994
- ...staticConfig.deoptProps || []
995
- ]);
996
- const inlineWhenUnflattened = /* @__PURE__ */ new Set([
997
- ...staticConfig.inlineWhenUnflattened || []
998
- ]);
999
- const staticNamespace = getStaticBindingsForScope(
1000
- traversePath.scope,
1001
- importsWhitelist,
1002
- sourcePath,
1003
- bindingCache,
1004
- shouldPrintDebug
1005
- );
1006
- const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
1007
- props: propsWithFileInfo,
1008
- staticNamespace,
1009
- sourcePath,
1010
- traversePath,
1011
- shouldPrintDebug
1012
- });
1013
- const attemptEvalSafe = createSafeEvaluator(attemptEval);
1014
- if (shouldPrintDebug) {
1015
- logger.info(` staticNamespace ${Object.keys(staticNamespace).join(", ")}`);
1016
- }
1017
- if (couldntParse) {
1018
- return;
1019
- }
1020
- tm.mark("jsx-element-flattened", !!shouldPrintDebug);
1021
- let attrs = [];
1022
- let shouldDeopt = false;
1023
- const inlined = /* @__PURE__ */ new Map();
1024
- const variantValues = /* @__PURE__ */ new Map();
1025
- let hasSetOptimized = false;
1026
- const inlineWhenUnflattenedOGVals = {};
1027
- attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
1028
- var _a3;
1029
- try {
1030
- const res2 = evaluateAttribute2(path);
1031
- tm.mark("jsx-element-evaluate-attr", !!shouldPrintDebug);
1032
- if (!res2) {
1033
- path.remove();
1034
- }
1035
- return res2;
1036
- } catch (err) {
1037
- if (shouldPrintDebug) {
1038
- logger.info(
1039
- [
1040
- "Recoverable error extracting attribute",
1041
- err.message,
1042
- shouldPrintDebug === "verbose" ? err.stack : ""
1043
- ].join(" ")
1044
- );
1045
- if (shouldPrintDebug === "verbose") {
1046
- logger.info(`node ${(_a3 = path.node) == null ? void 0 : _a3.type}`);
1047
- }
1048
- }
1049
- inlined.set(`${Math.random()}`, "spread");
1050
- return {
1051
- type: "attr",
1052
- value: path.node
1053
- };
1054
- }
1055
- }).flat(4).filter(isPresent);
1056
- if (shouldPrintDebug) {
1057
- logger.info(
1058
- [" - attrs (before):\n", logLines(attrs.map(attrStr).join(", "))].join(" ")
1059
- );
1060
- }
1061
- if (couldntParse || shouldDeopt) {
1062
- if (shouldPrintDebug) {
1063
- logger.info(
1064
- [` avoid optimizing:`, { couldntParse, shouldDeopt }].join(" ")
1065
- );
1066
- }
1067
- node.attributes = ogAttributes;
1068
- return;
1069
- }
1070
- const parentFn = findTopmostFunction(traversePath);
1071
- if (parentFn) {
1072
- modifiedComponents.add(parentFn);
1073
- }
1074
- let ternaries = [];
1075
- attrs = attrs.reduce((out, cur) => {
1076
- const next = attrs[attrs.indexOf(cur) + 1];
1077
- if (cur.type === "ternary") {
1078
- ternaries.push(cur.value);
1079
- }
1080
- if ((!next || next.type !== "ternary") && ternaries.length) {
1081
- const normalized = normalizeTernaries(ternaries).map(
1082
- ({ alternate, consequent, ...rest }) => {
1083
- return {
1084
- type: "ternary",
1085
- value: {
1086
- ...rest,
1087
- alternate: alternate || null,
1088
- consequent: consequent || null
1089
- }
1090
- };
1091
- }
1092
- );
1093
- try {
1094
- return [...out, ...normalized];
1095
- } finally {
1096
- if (shouldPrintDebug) {
1097
- logger.info(
1098
- ` normalizeTernaries (${ternaries.length} => ${normalized.length})`
1099
- );
1100
- }
1101
- ternaries = [];
1102
- }
1103
- }
1104
- if (cur.type === "ternary") {
1105
- return out;
1106
- }
1107
- out.push(cur);
1108
- return out;
1109
- }, []).flat();
1110
- const hasSpread = attrs.some(
1111
- (x) => x.type === "attr" && t.isJSXSpreadAttribute(x.value)
1112
- );
1113
- const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
1114
- const themeVal = inlined.get("theme");
1115
- if (target !== "native") {
1116
- inlined.delete("theme");
1117
- }
1118
- for (const [key] of [...inlined]) {
1119
- const isStaticObjectVariant = ((_a2 = staticConfig.variants) == null ? void 0 : _a2[key]) && variantValues.has(key);
1120
- if (INLINE_EXTRACTABLE[key] || isStaticObjectVariant) {
1121
- inlined.delete(key);
1122
- }
1123
- }
1124
- const canFlattenProps = inlined.size === 0;
1125
- let shouldFlatten = Boolean(
1126
- flatNode && !shouldDeopt && canFlattenProps && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true)
1127
- );
1128
- const shouldWrapTheme = shouldFlatten && themeVal;
1129
- const usedThemeKeys = /* @__PURE__ */ new Set();
1130
- if (disableExtractVariables) {
1131
- themeAccessListeners.add((key) => {
1132
- shouldFlatten = false;
1133
- usedThemeKeys.add(key);
1134
- if (shouldPrintDebug === "verbose") {
1135
- logger.info([" ! accessing theme key, avoid flatten", key].join(" "));
1136
- }
1137
- });
1138
- }
1139
- if (shouldPrintDebug) {
1140
- try {
1141
- logger.info([" flatten?", shouldFlatten, objToStr({ hasSpread, shouldDeopt, canFlattenProps, shouldWrapTheme, hasOnlyStringChildren }), "inlined", inlined.size, [...inlined]].join(" "));
1142
- } catch {
1143
- }
1144
- }
1145
- if (shouldFlatten && shouldWrapTheme) {
1146
- if (!programPath) {
1147
- console.warn(
1148
- `No program path found, avoiding importing flattening / importing theme in ${sourcePath}`
1149
- );
1150
- } else {
1151
- if (shouldPrintDebug) {
1152
- logger.info([" - wrapping theme", themeVal].join(" "));
1153
- }
1154
- attrs = attrs.filter(
1155
- (x) => x.type === "attr" && t.isJSXAttribute(x.value) && x.value.name.name === "theme" ? false : true
1156
- );
1157
- if (!hasImportedTheme) {
1158
- hasImportedTheme = true;
1159
- programPath.node.body.push(
1160
- t.importDeclaration(
1161
- [
1162
- t.importSpecifier(
1163
- t.identifier("_TamaguiTheme"),
1164
- t.identifier("Theme")
1165
- )
1166
- ],
1167
- t.stringLiteral("@tamagui/core")
1168
- )
1169
- );
1170
- }
1171
- traversePath.replaceWith(
1172
- t.jsxElement(
1173
- t.jsxOpeningElement(t.jsxIdentifier("_TamaguiTheme"), [
1174
- t.jsxAttribute(t.jsxIdentifier("name"), themeVal.value)
1175
- ]),
1176
- t.jsxClosingElement(t.jsxIdentifier("_TamaguiTheme")),
1177
- [traversePath.node]
1178
- )
1179
- );
1180
- }
1181
- }
1182
- if (shouldFlatten) {
1183
- const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap(
1184
- (key) => {
1185
- if (!isValidStyleKey(key, staticConfig)) {
1186
- return [];
1187
- }
1188
- const value = staticConfig.defaultProps[key];
1189
- const name = tamaguiConfig.shorthands[key] || key;
1190
- if (value === void 0) {
1191
- logger.warn(
1192
- `\u26A0\uFE0F Error evaluating default style for component, prop ${key} ${value}`
1193
- );
1194
- shouldDeopt = true;
1195
- return;
1196
- }
1197
- const attr = {
1198
- type: "style",
1199
- name,
1200
- value: { [name]: value }
1201
- };
1202
- return attr;
1203
- }
1204
- );
1205
- if (defaultStyleAttrs.length) {
1206
- attrs = [...defaultStyleAttrs, ...attrs];
1207
- }
1208
- }
1209
- if (shouldDeopt || !shouldFlatten) {
1210
- if (shouldPrintDebug) {
1211
- logger.info(`Deopting ${shouldDeopt} ${shouldFlatten}`);
1212
- }
1213
- node.attributes = ogAttributes;
1214
- return;
1215
- }
1216
- if (shouldPrintDebug) {
1217
- logger.info(
1218
- [" - attrs (flattened): \n", logLines(attrs.map(attrStr).join(", "))].join(
1219
- " "
1220
- )
1221
- );
1222
- }
1223
- const state = {
1224
- noClassNames: false,
1225
- focus: false,
1226
- hover: false,
1227
- unmounted: false,
1228
- // TODO match logic in createComponent
1229
- press: false,
1230
- pressIn: false
1231
- };
1232
- let foundStaticProps = {};
1233
- for (const key in attrs) {
1234
- const cur = attrs[key];
1235
- if (cur.type === "style") {
1236
- foundStaticProps = {
1237
- ...foundStaticProps,
1238
- ...expandStylesWithoutVariants2(cur.value)
1239
- };
1240
- continue;
1241
- }
1242
- if (cur.type === "attr") {
1243
- if (t.isJSXSpreadAttribute(cur.value)) {
1244
- continue;
1245
- }
1246
- if (!t.isJSXIdentifier(cur.value.name)) {
1247
- continue;
1248
- }
1249
- const key2 = cur.value.name.name;
1250
- const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
1251
- if (value !== FAILED_EVAL) {
1252
- foundStaticProps = {
1253
- ...foundStaticProps,
1254
- [key2]: value
1255
- };
1256
- }
1257
- }
1258
- }
1259
- const completeProps = {};
1260
- for (const key in staticConfig.defaultProps) {
1261
- if (!(key in foundStaticProps)) {
1262
- completeProps[key] = staticConfig.defaultProps[key];
1263
- }
1264
- }
1265
- for (const key in foundStaticProps) {
1266
- completeProps[key] = foundStaticProps[key];
1267
- }
1268
- attrs = attrs.reduce((acc, cur) => {
1269
- if (!cur)
1270
- return acc;
1271
- if (cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value)) {
1272
- if (shouldFlatten) {
1273
- const name = cur.value.name.name;
1274
- if (typeof name === "string") {
1275
- if (name === "tag") {
1276
- return acc;
1277
- }
1278
- if (variants[name] && variantValues.has(name)) {
1279
- let out = Object.fromEntries(
1280
- staticConfig.propMapper(
1281
- name,
1282
- variantValues.get(name),
1283
- defaultTheme,
1284
- completeProps,
1285
- { ...state, resolveVariablesAs: "auto" },
1286
- void 0,
1287
- void 0,
1288
- shouldPrintDebug
1289
- ) || []
1290
- );
1291
- if (out && isTargetingHTML) {
1292
- const cn = out.className;
1293
- out = createDOMProps(isTextView ? "span" : "div", out);
1294
- out.className = cn;
1295
- }
1296
- if (shouldPrintDebug) {
1297
- logger.info([" - expanded variant", name, out].join(" "));
1298
- }
1299
- for (const key2 in out) {
1300
- const value2 = out[key2];
1301
- if (isValidStyleKey(key2, staticConfig)) {
1302
- acc.push({
1303
- type: "style",
1304
- value: { [key2]: value2 },
1305
- name: key2,
1306
- attr: cur.value
1307
- });
1308
- } else {
1309
- acc.push({
1310
- type: "attr",
1311
- value: t.jsxAttribute(
1312
- t.jsxIdentifier(key2),
1313
- t.jsxExpressionContainer(
1314
- typeof value2 === "string" ? t.stringLiteral(value2) : literalToAst(value2)
1315
- )
1316
- )
1317
- });
1318
- }
1319
- }
1320
- }
1321
- }
1322
- }
1323
- }
1324
- if (cur.type !== "style") {
1325
- acc.push(cur);
1326
- return acc;
1327
- }
1328
- let key = Object.keys(cur.value)[0];
1329
- const value = cur.value[key];
1330
- const fullKey = tamaguiConfig.shorthands[key];
1331
- if (fullKey) {
1332
- cur.value = { [fullKey]: value };
1333
- key = fullKey;
1334
- }
1335
- if (disableExtractVariables) {
1336
- if (value[0] === "$" && (usedThemeKeys.has(key) || usedThemeKeys.has(fullKey))) {
1337
- if (shouldPrintDebug) {
1338
- logger.info([` keeping variable inline: ${key} =`, value].join(" "));
1339
- }
1340
- acc.push({
1341
- type: "attr",
1342
- value: t.jsxAttribute(
1343
- t.jsxIdentifier(key),
1344
- t.jsxExpressionContainer(t.stringLiteral(value))
1345
- )
1346
- });
1347
- return acc;
1348
- }
1349
- }
1350
- acc.push(cur);
1351
- return acc;
1352
- }, []);
1353
- tm.mark("jsx-element-expanded", !!shouldPrintDebug);
1354
- if (shouldPrintDebug) {
1355
- logger.info(
1356
- [" - attrs (expanded): \n", logLines(attrs.map(attrStr).join(", "))].join(
1357
- " "
1358
- )
1359
- );
1360
- }
1361
- let prev = null;
1362
- attrs = attrs.reduce((acc, cur) => {
1363
- if (cur.type === "style") {
1364
- const key = Object.keys(cur.value)[0];
1365
- const value = cur.value[key];
1366
- const shouldKeepOriginalAttr = (
1367
- // !isStyleAndAttr[key] &&
1368
- !shouldFlatten && // de-opt if non-style
1369
- !validStyles[key] && !pseudoDescriptors[key] && !(key.startsWith("data-") || key.startsWith("aria-"))
1370
- );
1371
- if (shouldKeepOriginalAttr) {
1372
- if (shouldPrintDebug) {
1373
- logger.info([" - keeping as non-style", key].join(" "));
1374
- }
1375
- prev = cur;
1376
- acc.push({
1377
- type: "attr",
1378
- value: t.jsxAttribute(
1379
- t.jsxIdentifier(key),
1380
- t.jsxExpressionContainer(
1381
- typeof value === "string" ? t.stringLiteral(value) : literalToAst(value)
1382
- )
1383
- )
1384
- });
1385
- acc.push(cur);
1386
- return acc;
1387
- }
1388
- if ((prev == null ? void 0 : prev.type) === "style") {
1389
- mergeStyles2(prev.value, cur.value);
1390
- return acc;
1391
- }
1392
- }
1393
- prev = cur;
1394
- acc.push(cur);
1395
- return acc;
1396
- }, []);
1397
- if (shouldPrintDebug) {
1398
- logger.info(
1399
- [
1400
- " - attrs (combined \u{1F500}): \n",
1401
- logLines(attrs.map(attrStr).join(", "))
1402
- ].join(" ")
1403
- );
1404
- logger.info(
1405
- [
1406
- " - defaultProps: \n",
1407
- logLines(objToStr(staticConfig.defaultProps))
1408
- ].join(" ")
1409
- );
1410
- logger.info([" - foundStaticProps: \n", logLines(objToStr(foundStaticProps))].join(" "));
1411
- logger.info(
1412
- [" - completeProps: \n", logLines(objToStr(completeProps))].join(" ")
1413
- );
1414
- }
1415
- const getStyles = (props, debugName = "") => {
1416
- if (!props || !Object.keys(props).length) {
1417
- if (shouldPrintDebug)
1418
- logger.info([" getStyles() no props"].join(" "));
1419
- return {};
1420
- }
1421
- if (excludeProps && !!excludeProps.size) {
1422
- for (const key in props) {
1423
- if (excludeProps.has(key)) {
1424
- if (shouldPrintDebug)
1425
- logger.info([" delete excluded", key].join(" "));
1426
- delete props[key];
1427
- }
1428
- }
1429
- }
1430
- try {
1431
- const out = getSplitStyles(
1432
- props,
1433
- staticConfig,
1434
- defaultTheme,
1435
- {
1436
- ...state,
1437
- fallbackProps: completeProps
1438
- },
1439
- void 0,
1440
- void 0,
1441
- void 0,
1442
- debugPropValue
1443
- );
1444
- const outStyle = {
1445
- ...out.style,
1446
- ...out.pseudos
1447
- };
1448
- if (shouldPrintDebug === "verbose") {
1449
- logger.info(` getStyles ${debugName} (props in): ${Object.keys(props)}`);
1450
- logger.info(` getStyles ${debugName} (outStyle): ${Object.keys(outStyle)}`);
1451
- }
1452
- return outStyle;
1453
- } catch (err) {
1454
- logger.info(["error", err.message, err.stack].join(" "));
1455
- return {};
1456
- }
1457
- };
1458
- const completeStyles = getStyles(completeProps, "completeStyles");
1459
- if (!completeStyles) {
1460
- throw new Error(`Impossible, no styles`);
1461
- }
1462
- let getStyleError = null;
1463
- for (const attr of attrs) {
1464
- try {
1465
- switch (attr.type) {
1466
- case "ternary": {
1467
- const a = getStyles(attr.value.alternate, "ternary.alternate");
1468
- const c = getStyles(attr.value.consequent, "ternary.consequent");
1469
- if (a)
1470
- attr.value.alternate = a;
1471
- if (c)
1472
- attr.value.consequent = c;
1473
- if (shouldPrintDebug)
1474
- logger.info([" => tern ", attrStr(attr)].join(" "));
1475
- continue;
1476
- }
1477
- case "style": {
1478
- const styles = getStyles(attr.value, "style");
1479
- if (styles) {
1480
- attr.value = styles;
1481
- }
1482
- if (shouldPrintDebug)
1483
- logger.info([" * styles (in)", logLines(objToStr(attr.value))].join(" "));
1484
- if (shouldPrintDebug)
1485
- logger.info([" * styles (out)", logLines(objToStr(styles))].join(" "));
1486
- continue;
1487
- }
1488
- }
1489
- } catch (err) {
1490
- getStyleError = err;
1491
- }
1492
- }
1493
- if (shouldPrintDebug) {
1494
- logger.info([" - attrs (ternaries/combined):\n", logLines(attrs.map(attrStr).join(", "))].join(" "));
1495
- }
1496
- tm.mark("jsx-element-styles", !!shouldPrintDebug);
1497
- if (getStyleError) {
1498
- logger.info([" \u26A0\uFE0F postprocessing error, deopt", getStyleError].join(" "));
1499
- node.attributes = ogAttributes;
1500
- return null;
1501
- }
1502
- const existingStyleKeys = /* @__PURE__ */ new Set();
1503
- for (let i = attrs.length - 1; i >= 0; i--) {
1504
- const attr = attrs[i];
1505
- if (shouldFlatten) {
1506
- if (attr.type === "attr") {
1507
- if (t.isJSXAttribute(attr.value)) {
1508
- if (t.isJSXIdentifier(attr.value.name)) {
1509
- const name = attr.value.name.name;
1510
- if (INLINE_EXTRACTABLE[name]) {
1511
- attr.value.name.name = INLINE_EXTRACTABLE[name];
1512
- }
1513
- }
1514
- }
1515
- }
1516
- }
1517
- if (attr.type === "style") {
1518
- for (const key in attr.value) {
1519
- if (existingStyleKeys.has(key)) {
1520
- if (shouldPrintDebug) {
1521
- logger.info([` >> delete existing ${key}`].join(" "));
1522
- }
1523
- delete attr.value[key];
1524
- } else {
1525
- existingStyleKeys.add(key);
1526
- }
1527
- }
1528
- }
1529
- }
1530
- if (!shouldFlatten) {
1531
- if (inlineWhenUnflattened.size) {
1532
- for (const [index, attr] of attrs.entries()) {
1533
- if (attr.type === "style") {
1534
- for (const key in attr.value) {
1535
- if (!inlineWhenUnflattened.has(key))
1536
- continue;
1537
- const val = inlineWhenUnflattenedOGVals[key];
1538
- if (val) {
1539
- delete attr.value[key];
1540
- attrs.splice(index - 1, 0, val.attr);
1541
- } else {
1542
- delete attr.value[key];
1543
- }
1544
- }
1545
- }
1546
- }
1547
- }
1548
- }
1549
- if (shouldFlatten) {
1550
- if (shouldPrintDebug) {
1551
- logger.info([" [\u2705] flattening", originalNodeName, flatNode].join(" "));
1552
- }
1553
- node.name.name = flatNode;
1554
- res.flattened++;
1555
- if (closingElement) {
1556
- closingElement.name.name = flatNode;
1557
- }
1558
- }
1559
- const isNativeNotFlat = !shouldFlatten && target === "native";
1560
- if (isNativeNotFlat) {
1561
- if (shouldPrintDebug) {
1562
- logger.info(`Disabled flattening except for simple cases on native for now`);
1563
- }
1564
- node.attributes = ogAttributes;
1565
- return null;
1566
- }
1567
- if (shouldPrintDebug) {
1568
- logger.info([` - inlined props (${inlined.size}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : ""].join(" "));
1569
- logger.info(` - shouldFlatten/isFlattened: ${shouldFlatten}`);
1570
- logger.info(` - attrs (end):
1571
- ${logLines(attrs.map(attrStr).join(", "))}`);
1572
- }
1573
- onExtractTag({
1574
- parserProps: propsWithFileInfo,
1575
- attrs,
1576
- node,
1577
- lineNumbers,
1578
- filePath,
1579
- attemptEval,
1580
- jsxPath: traversePath,
1581
- originalNodeName,
1582
- isFlattened: shouldFlatten,
1583
- programPath,
1584
- completeProps,
1585
- staticConfig
1586
- });
1587
- } catch (err) {
1588
- node.attributes = ogAttributes;
1589
- console.error(`err: ${err}`);
1590
- } finally {
1591
- if (debugPropValue) {
1592
- shouldPrintDebug = ogDebug;
1593
- }
1594
- }
1595
- }
1596
- });
1597
- tm.mark("jsx-done", !!shouldPrintDebug);
1598
- if (modifiedComponents.size) {
1599
- const all = Array.from(modifiedComponents);
1600
- if (shouldPrintDebug) {
1601
- logger.info(` [\u{1FA9D}] hook check ${all.length}`);
1602
- }
1603
- for (const comp of all) {
1604
- removeUnusedHooks(comp, shouldPrintDebug);
1605
- }
1606
- }
1607
- tm.done(shouldPrintDebug === "verbose");
1608
- return res;
1609
- }
1610
- }
1611
- export {
1612
- createExtractor
1613
- };
1
+ import{basename as Dt,relative as Ft}from"path";import Jt from"@babel/traverse";import*as s from"@babel/types";import{expandStyles as Xt,getSplitStyles as xt,mediaQueryConfig as be,proxyThemeVariables as _t,pseudoDescriptors as Ve}from"@tamagui/core-node";import{createDOMProps as bt}from"react-native-web-internals";import{FAILED_EVAL as oe}from"../constants.js";import{createEvaluator as ht,createSafeEvaluator as jt}from"./createEvaluator.js";import{evaluateAstNode as Et}from"./evaluateAstNode.js";import{attrStr as q,findComponentName as Wt,getValidComponent as Bt,getValidImport as Ut,isPresent as Gt,isValidImport as Me,objToStr as Q}from"./extractHelpers.js";import{findTopmostFunction as qt}from"./findTopmostFunction.js";import{cleanupBeforeExit as zt,getStaticBindingsForScope as St}from"./getStaticBindingsForScope.js";import{literalToAst as Tt}from"./literalToAst.js";import{loadTamagui as Rt,loadTamaguiSync as Ht}from"./loadTamagui.js";import{logLines as L}from"./logLines.js";import{normalizeTernaries as Kt}from"./normalizeTernaries.js";import{removeUnusedHooks as Qt}from"./removeUnusedHooks.js";import{timer as Yt}from"./timer.js";import{validHTMLAttributes as Zt}from"./validHTMLAttributes.js";const en={key:!0,style:!0,className:!0},re={ref:"ref",key:"key",...process.env.TAMAGUI_TARGET==="web"&&{onPress:"onClick",onHoverIn:"onMouseEnter",onHoverOut:"onMouseLeave",onPressIn:"onMouseDown",onPressOut:"onMouseUp"}},tn={useMedia:!0,useTheme:!0},Nn=o=>o.type==="attr",De=o=>o;let At=!1;function Cn({logger:o=console}={logger:console}){process.env.TAMAGUI_TARGET||(console.log('\u26A0\uFE0F Please set process.env.TAMAGUI_TARGET to either "web" or "native"'),process.exit(1));const $t=!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);let D=null;function Fe($){return D||=Ht({config:$.config||"tamagui.config.ts",components:$.components||["tamagui"]})}async function Je($){return D||=await Rt({config:$.config||"tamagui.config.ts",components:$.components||["tamagui"]})}return{options:{logger:o},cleanupBeforeExit:zt,loadTamagui:Je,loadTamaguiSync:Fe,getTamagui(){return D==null?void 0:D.tamaguiConfig},parseSync:($,N)=>{const V=Fe(N);return Xe(V,$,N)},parse:async($,N)=>{const V=await Je(N);return Xe(V,$,N)}};function Xe({components:$,tamaguiConfig:N},V,he){var Ye;const{config:nn="tamagui.config.ts",importsWhitelist:_e=["constants.js"],evaluateVars:We=!0,sourcePath:I="",onExtractTag:Pt,onStyleRule:je,getFlattenedNode:Ee,disable:ae,disableExtraction:Se,disableExtractInlineMedia:gt,disableExtractVariables:Te,disableDebugAttr:Be,disableExtractFoundComponents:sn,includeExtensions:Ae=[".ts",".tsx",".jsx"],extractStyledDefinitions:Ue=!1,prefixLogs:on,excludeProps:z,target:Y,...Ge}=he;let r=he.shouldPrintDebug||!1;if(ae===!0||Array.isArray(ae)&&ae.includes(I))return null;if(!$)throw new Error("Must provide components");if(I&&Ae&&!Ae.some(a=>I.endsWith(a)))return r&&o.info(`Ignoring file due to includeExtensions: ${I}, includeExtensions: ${Ae.join(", ")}`),null;function W(a,l){var m,j;if(!D)throw new Error("Tamagui extractor not loaded yet");return Y==="native"&&a[0]==="$"&&be[a.slice(1)]?!1:!!((m=l.validStyles)!=null&&m[a]||Ve[a]||(j=l.variants)!=null&&j[a]||D!=null&&D.tamaguiConfig.shorthands[a]||a[0]==="$"&&be[a.slice(1)])}const qe=Y==="html",It=r,F=Yt(),C={...he,sourcePath:I,allLoadedComponents:[...$]};if(!At&&(At=!0,r&&o.info(["loaded components:",C.allLoadedComponents.map(a=>Object.keys(a.nameToInfo).join(", ")).join(", ")].join(" ")),(Ye=process.env.DEBUG)!=null&&Ye.startsWith("tamagui"))){const a=[...C.allLoadedComponents].map(l=>{const m={...l.nameToInfo};for(const j in m)delete m[j].staticConfig.validStyles;return{...l,nameToInfo:m}});o.info(["loaded:",JSON.stringify(a,null,2)].join(`
2
+ `))}F.mark("load-tamagui",!!r);const ze=Object.keys(N.themes)[0],$e=N.themes[ze];(!$e||typeof $e!="object")&&(console.error("Missing theme, an error occurred when importing your config"),console.log("Got config:",N),console.log("Looking for theme:",ze),process.exit(0));const kt=_t($e),Re=new Set,le=new Proxy(kt,{get(a,l){return Reflect.has(a,l)&&Re.forEach(m=>m(String(l))),Reflect.get(a,l)}}),Ot=V.type==="Program"?V.get("body"):V.program.body;Object.keys($).length===0&&(console.warn("Warning: Tamagui didn't find any valid components (DEBUG=tamagui for more)"),process.env.DEBUG==="tamagui"&&console.log("components",Object.keys($),$)),r==="verbose"&&o.info(`allLoadedComponent modules ${C.allLoadedComponents.map(a=>a.moduleName).join(", ")}`);let fe=!1,Pe=!1;const He=[];for(const a of Ot){if(a.type!=="ImportDeclaration")continue;const l="node"in a?a.node:a,m=l.source.value,j=Me(C,m);if(j&&He.push(l),Ue&&j&&l.specifiers.some(S=>S.local.name==="styled")){fe=!0;break}if(j){const S=l.specifiers.map(O=>O.local.name),T=S.some(O=>Boolean(Me(C,m,O)||tn[O]));if(r==="verbose"&&o.info(`import ${S.join(", ")} from ${m} isValidComponent ${T}`),T){fe=!0;break}}}if(r&&o.info(`file: ${I} ${JSON.stringify({doesUseValidImport:fe,hasImportedTheme:Pe})}`),!fe)return null;function Nt(a){const l=He.find(m=>m.specifiers.some(j=>j.local.name===a));return l?Ut(C,l.source.value,a):null}F.mark("import-check",!!r);let ue=!1;const ge=new Set,Ke={},Ct=a=>V.type==="File"?Jt(V,a):V.traverse(a),Qe=Se===!0||Array.isArray(Se)&&Se.includes(I);let ce=null;const R={styled:0,flattened:0,optimized:0,modified:0,found:0};if(Ct({Program:{enter(a){ce=a}},CallExpression(a){var et;if(ae||Qe||Ue===!1||!s.isIdentifier(a.node.callee)||a.node.callee.name!=="styled")return;const l=s.isVariableDeclarator(a.parent)&&s.isIdentifier(a.parent.id)?a.parent.id.name:"unknown",m=a.node.arguments[0];if(!s.isIdentifier(m))return;const j=m.name,S=a.node.arguments[1];if(!j||!S||!s.isObjectExpression(S))return;const T=Nt(j);if(!T)return;const O=new Set([...T.staticConfig.inlineWhenUnflattened||[],...T.staticConfig.inlineProps||[],...T.staticConfig.deoptProps||[],"variants","defaultVariants","fontFamily","name","focusStyle","hoverStyle","pressStyle"]),B=[],U={},Z=St(a.scope,_e,I,Ke,r),ee=We?ht({props:C,staticNamespace:Z,sourcePath:I,shouldPrintDebug:r}):Et,Ie=jt(ee);for(const E of S.properties){if(!s.isObjectProperty(E)||!s.isIdentifier(E.key)||!W(E.key.name,T.staticConfig)||(et=T.staticConfig.variants)!=null&&et[E.key.name]||O.has(E.key.name)){B.push(E);continue}const H=Ie(E.value);H===oe?B.push(E):U[E.key.name]=H}const J=xt(U,T.staticConfig,le,{focus:!1,hover:!1,unmounted:!0,press:!1,pressIn:!1,resolveVariablesAs:"variable",noClassNames:!1},void 0,void 0,void 0,r),Ze={...J.classNames};r&&o.info([`Extracted styled(${l})
3
+ `,JSON.stringify(U,null,2),`
4
+ rulesToInsert:`,J.rulesToInsert.flatMap(E=>E.rules).join(`
5
+ `)].join(" ")),S.properties=B;for(const E in Ze){if(O.has(E))continue;const H=Ze[E];S.properties.push(s.objectProperty(s.stringLiteral(E),s.stringLiteral(H)))}if(J.rulesToInsert)for(const{identifier:E,rules:H}of J.rulesToInsert)je==null||je(E,H);R.styled++,r&&o.info(`Extracted styled(${l})`)},JSXElement(a){var tt;F.mark("jsx-element",!!r);const l=a.node.openingElement,m=l.attributes.map(f=>({...f})),j=Wt(a.scope),S=a.node.closingElement;if(s.isJSXMemberExpression(S==null?void 0:S.name)||!s.isJSXIdentifier(l.name))return;const T=a.scope.getBinding(l.name.name);let O="";if(T){if(!s.isImportDeclaration(T.path.parent)){r&&o.info(" - Binding not import declaration, skip");return}if(O=T.path.parent.source.value,!Me(C,O,T.identifier.name)){r&&o.info(` - Binding not internal import or from components ${T.identifier.name} in ${O}`);return}}const B=Bt(C,O,l.name.name);if(!B||!B.staticConfig){r&&o.info(` - No Tamagui conf on this: ${l.name.name}`);return}const U=l.name.name;R.found++;const Z=`./${Ft(process.cwd(),I)}`,ee=l.loc?l.loc.start.line+(l.loc.start.line!==l.loc.end.line?`-${l.loc.end.line}`:""):"",Ie=`${Z}:${ee}`,J=l.attributes.filter(f=>s.isJSXAttribute(f)&&s.isJSXIdentifier(f.name)&&f.name.name==="debug").map(f=>f.value===null?!0:s.isStringLiteral(f.value)?f.value.value:!1)[0];if(J&&(r=J),r&&(o.info(`
6
+ `),o.info(`\x1B[33m%s\x1B[0m ${j} | ${Ie} -------------------`),o.info(["\x1B[1m","\x1B[32m",`<${U} />`,Be?"":"\u{1F41B}"].join(" "))),$t&&!Be&&(R.modified++,l.attributes.unshift(s.jsxAttribute(s.jsxIdentifier("data-is"),s.stringLiteral(l.name.name))),j&&l.attributes.unshift(s.jsxAttribute(s.jsxIdentifier("data-in"),s.stringLiteral(j))),l.attributes.unshift(s.jsxAttribute(s.jsxIdentifier("data-at"),s.stringLiteral(`${Dt(Z)}:${ee}`)))),!Qe)try{let rt=function(t){const e=t.node,n={type:"attr",value:e};if(s.isJSXSpreadAttribute(e)){const c=e.argument,u=s.isConditionalExpression(c)?[c.test,c.consequent,c.alternate]:s.isLogicalExpression(c)&&c.operator==="&&"?[c.left,c.right,null]:null;if(u){const[y,A,v]=u;if(!y)throw new Error("no test");return[A,v].some(k=>k&&!Ne(k))?(r&&o.info(`not extractable ${A} ${v}`),n):[...te(y,A)||[],...v&&te(s.unaryExpression("!",y),v)||[]].map(k=>({type:"ternary",value:k}))}}if(s.isJSXSpreadAttribute(e)||!e.name||typeof e.name.name!="string")return r&&o.info(" ! inlining, spread attr"),b.set(`${Math.random()}`,"spread"),n;const i=e.name.name;if(z!=null&&z.has(i))return r&&o.info([" excluding prop",i].join(" ")),null;if(Lt.has(i))return b.set(i,i),r&&o.info([" ! inlining, inline prop",i].join(" ")),n;if(Vt.has(i))return w=!0,b.set(i,i),r&&o.info([" ! inlining, deopted prop",i].join(" ")),n;if(en[i])return n;if(re[i])return b.set(i,re[i]),n;if(i.startsWith("data-"))return n;if(i[0]==="$"&&s.isJSXExpressionContainer(e==null?void 0:e.value)){const c=i.slice(1);if(be[c]){if(Y==="native"&&(w=!0),gt)return n;const u=e.value.expression;if(!s.isJSXEmptyExpression(u)){const y=te(s.stringLiteral(c),u,{inlineMediaQuery:c});if(y)return y.map(A=>({type:"ternary",value:A}))}}}const[d,g]=(()=>s.isJSXExpressionContainer(e==null?void 0:e.value)?[e.value.expression,t.get("value")]:[e.value,t.get("value")])(),h=()=>{Array.isArray(g)?g.map(c=>c.remove()):g.remove()};if(i==="ref")return r&&o.info([" ! inlining, ref",i].join(" ")),b.set("ref","ref"),n;if(i==="tag")return{type:"attr",value:t.node};if(Te===!0&&d&&d.type==="StringLiteral"&&d.value[0]==="$")return r&&o.info([` ! inlining, native disable extract: ${i} =`,d.value].join(" ")),b.set(i,!0),n;if(i==="theme")return b.set("theme",n.value),n;const x=me(d);if(!ke[i]&&!W(i,f)){let c=[i],u=null;u=f.propMapper(i,x,le,f.defaultProps,{resolveVariablesAs:"auto"},void 0,void 0,r),u&&(Array.isArray(u)?(u=Object.fromEntries(u),c=Object.keys(u)):(o.warn("Error expected array but got",u),ue=!0,w=!0)),u&&(qe&&(u=bt(de?"span":"div",u),delete u.className),c=Object.keys(u));let y=!1;const A=c.map(v=>{const k=u[v];return W(v,f)?{type:"style",value:{[v]:x},name:v,attr:t.node}:Zt[v]||v.startsWith("aria-")||v.startsWith("data-")||v==="__source"||v==="__self"?n:(r&&o.info(" ! inlining, non-static "+v),y=!0,b.set(v,k),k)});return y?(r&&o.info(` bailing flattening due to attributes ${A}`),n):A}if(x!==oe)return Oe.has(i)&&(ot[i]={styleValue:x,attr:n}),W(i,f)?(r&&o.info(` style: ${i} = ${x}`),i in f.defaultProps||st||(R.optimized++,st=!0),{type:"style",value:{[i]:x},name:i,attr:t.node}):(ke[i]&&ye.set(i,x),b.set(i,!0),n);if(s.isBinaryExpression(d)){r&&o.info(` binary expression ${i} = ${d}`);const{operator:c,left:u,right:y}=d,A=me(u),v=me(y);if(r&&o.info(` evalBinaryExpression lVal ${String(A)}, rVal ${String(v)}`),A!==oe&&s.isConditionalExpression(y)){const k=se(c,u,y);if(k)return k}if(v!==oe&&s.isConditionalExpression(u)){const k=se(c,y,u);if(k)return k}return r&&o.info(" evalBinaryExpression cant extract"),b.set(i,!0),n}const M=vt(d);if(M)return r==="verbose"&&o.info(` static conditional ${i} ${d}`),{type:"ternary",value:M};const ie=Mt(d);if(ie)return r==="verbose"&&o.info(` static ternary ${i} = ${d}`),{type:"ternary",value:ie};return b.set(i,!0),r&&o.info(` ! inline no match ${i} ${d}`),n;function se(c,u,y){if(vt(y)){const A=X(s.binaryExpression(c,u,y.alternate)),v=X(s.binaryExpression(c,u,y.consequent));return r&&o.info([" binaryConditional",y.test,v,A].join(" ")),{type:"ternary",value:{test:y.test,remove:h,alternate:{[i]:A},consequent:{[i]:v}}}}return null}function vt(c){if(s.isConditionalExpression(c))try{const u=X(c.alternate),y=X(c.consequent);if(r){const A=c.test.type;o.info([" static ternary",A,y,u].join(" "))}return{test:c.test,remove:h,consequent:{[i]:y},alternate:{[i]:u}}}catch(u){r&&o.info([" cant eval ternary",u.message].join(" "))}return null}function Mt(c){if(s.isLogicalExpression(c)&&c.operator==="&&")try{const u=X(c.right);return r&&o.info([" staticLogical",c.left,i,u].join(" ")),{test:c.left,remove:h,consequent:{[i]:u},alternate:null}}catch(u){r&&o.info([" cant static eval logical",u].join(" "))}return null}},Ne=function(t){return s.isObjectExpression(t)&&t.properties.every(e=>{if(!s.isObjectProperty(e))return o.info(["not object prop",e].join(" ")),!1;const n=e.key.name;return!W(n,f)&&n!=="tag"?(r&&o.info([" not a valid style prop!",n].join(" ")),!1):!0})},te=function(t,e,n={}){if(!e)return null;if(!Ne(e))throw new Error("not extractable");return e.properties.flatMap(i=>{if(!s.isObjectProperty(i))throw new Error("expected object property");if(s.isIdentifier(i.key)){const h=i.key.name,x=h.slice(1);if(h[0]==="$"&&be[x])if(s.isExpression(i.value)){const ie=te(s.stringLiteral(x),i.value,{inlineMediaQuery:x});if(ie)return ie.map(se=>({...n,...se,test:s.logicalExpression("&&",se.test,t)}));o.info(["\u26A0\uFE0F no ternaries?",i].join(" "))}else o.info(["\u26A0\uFE0F not expression",i].join(" "))}if(s.isConditionalExpression(i.value)){const[h,x]=[s.objectExpression([s.objectProperty(i.key,i.value.consequent)]),s.objectExpression([s.objectProperty(i.key,i.value.alternate)])].map(M=>X(M));return[De({remove(){},...n,test:s.logicalExpression("&&",t,i.value.test),consequent:h,alternate:null}),De({...n,test:s.logicalExpression("&&",t,s.unaryExpression("!",i.value.test)),consequent:x,alternate:null,remove(){}})]}const d=s.objectExpression([s.objectProperty(i.key,i.value)]),g=X(d);return De({remove(){},...n,test:t,consequent:g,alternate:null})})},dt=function(t){var i;const e={},n={};for(const d in t)(i=f.variants)!=null&&i[d]?e[d]=t[d]:n[d]=t[d];return{variants:e,styles:n}},pt=function(t){const{variants:e,styles:n}=dt(t);return{...Xt(n),...e}},mt=function(t,e){for(const n in e)Ve[n]?(t[n]=t[n]||{},Object.assign(t[n],e[n])):t[n]=e[n]};var Ze=rt,et=Ne,E=te,H=dt,Ln=pt,Vn=mt;const{staticConfig:f}=B,ke=f.variants||{},de=f.isText||!1,wt=(f==null?void 0:f.validStyles)??{};let nt=f.defaultProps.tag??(de?"span":"div");a.get("openingElement").get("attributes").forEach(t=>{const e=t.node;if(s.isJSXSpreadAttribute(e)||e.name.name!=="tag")return;const n=e.value;s.isStringLiteral(n)&&(nt=n.value)});const pe=Ee==null?void 0:Ee({isTextView:de,tag:nt}),Lt=new Set(["dataSet",...Ge.inlineProps||[],...f.inlineProps||[]]),Vt=new Set(["animation",...Ge.deoptProps||[],...f.deoptProps||[]]),Oe=new Set([...f.inlineWhenUnflattened||[]]),it=St(a.scope,_e,I,Ke,r),X=We?ht({props:C,staticNamespace:it,sourcePath:I,traversePath:a,shouldPrintDebug:r}):Et,me=jt(X);if(r&&o.info(` staticNamespace ${Object.keys(it).join(", ")}`),ue)return;F.mark("jsx-element-flattened",!!r);let p=[],w=!1;const b=new Map,ye=new Map;let st=!1;const ot={};if(p=a.get("openingElement").get("attributes").flatMap(t=>{var e;try{const n=rt(t);return F.mark("jsx-element-evaluate-attr",!!r),n||t.remove(),n}catch(n){return r&&(o.info(["Recoverable error extracting attribute",n.message,r==="verbose"?n.stack:""].join(" ")),r==="verbose"&&o.info(`node ${(e=t.node)==null?void 0:e.type}`)),b.set(`${Math.random()}`,"spread"),{type:"attr",value:t.node}}}).flat(4).filter(Gt),r&&o.info([` - attrs (before):
7
+ `,L(p.map(q).join(", "))].join(" ")),ue||w){r&&o.info([" avoid optimizing:",{couldntParse:ue,shouldDeopt:w}].join(" ")),l.attributes=m;return}const at=qt(a);at&&ge.add(at);let ne=[];p=p.reduce((t,e)=>{const n=p[p.indexOf(e)+1];if(e.type==="ternary"&&ne.push(e.value),(!n||n.type!=="ternary")&&ne.length){const i=Kt(ne).map(({alternate:d,consequent:g,...h})=>({type:"ternary",value:{...h,alternate:d||null,consequent:g||null}}));try{return[...t,...i]}finally{r&&o.info(` normalizeTernaries (${ne.length} => ${i.length})`),ne=[]}}return e.type==="ternary"||t.push(e),t},[]).flat();const ve=p.some(t=>t.type==="attr"&&s.isJSXSpreadAttribute(t.value)),lt=!ve&&(l.selfClosing||a.node.children&&a.node.children.every(t=>t.type==="JSXText")),Ce=b.get("theme");Y!=="native"&&b.delete("theme");for(const[t]of[...b]){const e=((tt=f.variants)==null?void 0:tt[t])&&ye.has(t);(re[t]||e)&&b.delete(t)}const ft=b.size===0;let P=Boolean(pe&&!w&&ft&&!ve&&f.neverFlatten!==!0&&(f.neverFlatten==="jsx"?lt:!0));const ut=P&&Ce,we=new Set;if(Te&&Re.add(t=>{P=!1,we.add(t),r==="verbose"&&o.info([" ! accessing theme key, avoid flatten",t].join(" "))}),r)try{o.info([" flatten?",P,Q({hasSpread:ve,shouldDeopt:w,canFlattenProps:ft,shouldWrapTheme:ut,hasOnlyStringChildren:lt}),"inlined",b.size,[...b]].join(" "))}catch{}if(P&&ut&&(ce?(r&&o.info([" - wrapping theme",Ce].join(" ")),p=p.filter(t=>!(t.type==="attr"&&s.isJSXAttribute(t.value)&&t.value.name.name==="theme")),Pe||(Pe=!0,ce.node.body.push(s.importDeclaration([s.importSpecifier(s.identifier("_TamaguiTheme"),s.identifier("Theme"))],s.stringLiteral("@tamagui/core")))),a.replaceWith(s.jsxElement(s.jsxOpeningElement(s.jsxIdentifier("_TamaguiTheme"),[s.jsxAttribute(s.jsxIdentifier("name"),Ce.value)]),s.jsxClosingElement(s.jsxIdentifier("_TamaguiTheme")),[a.node]))):console.warn(`No program path found, avoiding importing flattening / importing theme in ${I}`)),P){const t=Object.keys(f.defaultProps).flatMap(e=>{if(!W(e,f))return[];const n=f.defaultProps[e],i=N.shorthands[e]||e;if(n===void 0){o.warn(`\u26A0\uFE0F Error evaluating default style for component, prop ${e} ${n}`),w=!0;return}return{type:"style",name:i,value:{[i]:n}}});t.length&&(p=[...t,...p])}if(w||!P){r&&o.info(`Deopting ${w} ${P}`),l.attributes=m;return}r&&o.info([` - attrs (flattened):
8
+ `,L(p.map(q).join(", "))].join(" "));const ct={noClassNames:!1,focus:!1,hover:!1,unmounted:!1,press:!1,pressIn:!1};let _={};for(const t in p){const e=p[t];if(e.type==="style"){_={..._,...pt(e.value)};continue}if(e.type==="attr"){if(s.isJSXSpreadAttribute(e.value)||!s.isJSXIdentifier(e.value.name))continue;const n=e.value.name.name,i=me(e.value.value||s.booleanLiteral(!0));i!==oe&&(_={..._,[n]:i})}}const G={};for(const t in f.defaultProps)t in _||(G[t]=f.defaultProps[t]);for(const t in _)G[t]=_[t];p=p.reduce((t,e)=>{if(!e)return t;if(e.type==="attr"&&!s.isJSXSpreadAttribute(e.value)&&P){const g=e.value.name.name;if(typeof g=="string"){if(g==="tag")return t;if(ke[g]&&ye.has(g)){let h=Object.fromEntries(f.propMapper(g,ye.get(g),le,G,{...ct,resolveVariablesAs:"auto"},void 0,void 0,r)||[]);if(h&&qe){const x=h.className;h=bt(de?"span":"div",h),h.className=x}r&&o.info([" - expanded variant",g,h].join(" "));for(const x in h){const M=h[x];W(x,f)?t.push({type:"style",value:{[x]:M},name:x,attr:e.value}):t.push({type:"attr",value:s.jsxAttribute(s.jsxIdentifier(x),s.jsxExpressionContainer(typeof M=="string"?s.stringLiteral(M):Tt(M)))})}}}}if(e.type!=="style")return t.push(e),t;let n=Object.keys(e.value)[0];const i=e.value[n],d=N.shorthands[n];return d&&(e.value={[d]:i},n=d),Te&&i[0]==="$"&&(we.has(n)||we.has(d))?(r&&o.info([` keeping variable inline: ${n} =`,i].join(" ")),t.push({type:"attr",value:s.jsxAttribute(s.jsxIdentifier(n),s.jsxExpressionContainer(s.stringLiteral(i)))}),t):(t.push(e),t)},[]),F.mark("jsx-element-expanded",!!r),r&&o.info([` - attrs (expanded):
9
+ `,L(p.map(q).join(", "))].join(" "));let K=null;p=p.reduce((t,e)=>{if(e.type==="style"){const n=Object.keys(e.value)[0],i=e.value[n];if(!P&&!wt[n]&&!Ve[n]&&!(n.startsWith("data-")||n.startsWith("aria-")))return r&&o.info([" - keeping as non-style",n].join(" ")),K=e,t.push({type:"attr",value:s.jsxAttribute(s.jsxIdentifier(n),s.jsxExpressionContainer(typeof i=="string"?s.stringLiteral(i):Tt(i)))}),t.push(e),t;if((K==null?void 0:K.type)==="style")return mt(K.value,e.value),t}return K=e,t.push(e),t},[]),r&&(o.info([` - attrs (combined \u{1F500}):
10
+ `,L(p.map(q).join(", "))].join(" ")),o.info([` - defaultProps:
11
+ `,L(Q(f.defaultProps))].join(" ")),o.info([` - foundStaticProps:
12
+ `,L(Q(_))].join(" ")),o.info([` - completeProps:
13
+ `,L(Q(G))].join(" ")));const xe=(t,e="")=>{if(!t||!Object.keys(t).length)return r&&o.info([" getStyles() no props"].join(" ")),{};if(z&&z.size)for(const n in t)z.has(n)&&(r&&o.info([" delete excluded",n].join(" ")),delete t[n]);try{const n=xt(t,f,le,{...ct,fallbackProps:G},void 0,void 0,void 0,J),i={...n.style,...n.pseudos};return r==="verbose"&&(o.info(` getStyles ${e} (props in): ${Object.keys(t)}`),o.info(` getStyles ${e} (outStyle): ${Object.keys(i)}`)),i}catch(n){return o.info(["error",n.message,n.stack].join(" ")),{}}};if(!xe(G,"completeStyles"))throw new Error("Impossible, no styles");let Le=null;for(const t of p)try{switch(t.type){case"ternary":{const e=xe(t.value.alternate,"ternary.alternate"),n=xe(t.value.consequent,"ternary.consequent");e&&(t.value.alternate=e),n&&(t.value.consequent=n),r&&o.info([" => tern ",q(t)].join(" "));continue}case"style":{const e=xe(t.value,"style");e&&(t.value=e),r&&o.info([" * styles (in)",L(Q(t.value))].join(" ")),r&&o.info([" * styles (out)",L(Q(e))].join(" "));continue}}}catch(e){Le=e}if(r&&o.info([` - attrs (ternaries/combined):
14
+ `,L(p.map(q).join(", "))].join(" ")),F.mark("jsx-element-styles",!!r),Le)return o.info([" \u26A0\uFE0F postprocessing error, deopt",Le].join(" ")),l.attributes=m,null;const yt=new Set;for(let t=p.length-1;t>=0;t--){const e=p[t];if(P&&e.type==="attr"&&s.isJSXAttribute(e.value)&&s.isJSXIdentifier(e.value.name)){const n=e.value.name.name;re[n]&&(e.value.name.name=re[n])}if(e.type==="style")for(const n in e.value)yt.has(n)?(r&&o.info([` >> delete existing ${n}`].join(" ")),delete e.value[n]):yt.add(n)}if(!P&&Oe.size){for(const[t,e]of p.entries())if(e.type==="style")for(const n in e.value){if(!Oe.has(n))continue;const i=ot[n];i?(delete e.value[n],p.splice(t-1,0,i.attr)):delete e.value[n]}}if(P&&(r&&o.info([" [\u2705] flattening",U,pe].join(" ")),l.name.name=pe,R.flattened++,S&&(S.name.name=pe)),!P&&Y==="native")return r&&o.info("Disabled flattening except for simple cases on native for now"),l.attributes=m,null;r&&(o.info([` - inlined props (${b.size}):`,w?" deopted":"",ve?" has spread":"",f.neverFlatten?"neverFlatten":""].join(" ")),o.info(` - shouldFlatten/isFlattened: ${P}`),o.info(` - attrs (end):
15
+ ${L(p.map(q).join(", "))}`)),Pt({parserProps:C,attrs:p,node:l,lineNumbers:ee,filePath:Z,attemptEval:X,jsxPath:a,originalNodeName:U,isFlattened:P,programPath:ce,completeProps:G,staticConfig:f})}catch(f){l.attributes=m,console.error(`err: ${f}`)}finally{J&&(r=It)}}}),F.mark("jsx-done",!!r),ge.size){const a=Array.from(ge);r&&o.info(` [\u{1FA9D}] hook check ${a.length}`);for(const l of a)Qt(l,r)}return F.done(r==="verbose"),R}}export{Cn as createExtractor};
1614
16
  //# sourceMappingURL=createExtractor.js.map