@tamagui/static 1.0.1-beta.140 → 1.0.1-beta.143

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 (206) hide show
  1. package/dist/cjs/constants.js +0 -0
  2. package/dist/cjs/constants.js.map +0 -0
  3. package/dist/cjs/extractor/accessSafe.js +0 -0
  4. package/dist/cjs/extractor/accessSafe.js.map +0 -0
  5. package/dist/cjs/extractor/babelParse.js +0 -0
  6. package/dist/cjs/extractor/babelParse.js.map +0 -0
  7. package/dist/cjs/extractor/buildClassName.js +0 -0
  8. package/dist/cjs/extractor/buildClassName.js.map +0 -0
  9. package/dist/cjs/extractor/createEvaluator.js +0 -0
  10. package/dist/cjs/extractor/createEvaluator.js.map +2 -2
  11. package/dist/cjs/extractor/createExtractor.js +1138 -1106
  12. package/dist/cjs/extractor/createExtractor.js.map +2 -2
  13. package/dist/cjs/extractor/ensureImportingConcat.js +0 -0
  14. package/dist/cjs/extractor/ensureImportingConcat.js.map +0 -0
  15. package/dist/cjs/extractor/evaluateAstNode.js +0 -0
  16. package/dist/cjs/extractor/evaluateAstNode.js.map +0 -0
  17. package/dist/cjs/extractor/extractHelpers.js +0 -0
  18. package/dist/cjs/extractor/extractHelpers.js.map +0 -0
  19. package/dist/cjs/extractor/extractMediaStyle.js +0 -0
  20. package/dist/cjs/extractor/extractMediaStyle.js.map +0 -0
  21. package/dist/cjs/extractor/extractToClassNames.js +4 -4
  22. package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
  23. package/dist/cjs/extractor/findTopmostFunction.js +0 -0
  24. package/dist/cjs/extractor/findTopmostFunction.js.map +0 -0
  25. package/dist/cjs/extractor/generatedUid.js +0 -0
  26. package/dist/cjs/extractor/generatedUid.js.map +0 -0
  27. package/dist/cjs/extractor/getPrefixLogs.js +0 -0
  28. package/dist/cjs/extractor/getPrefixLogs.js.map +0 -0
  29. package/dist/cjs/extractor/getPropValueFromAttributes.js +0 -0
  30. package/dist/cjs/extractor/getPropValueFromAttributes.js.map +0 -0
  31. package/dist/cjs/extractor/getSourceModule.js +0 -0
  32. package/dist/cjs/extractor/getSourceModule.js.map +0 -0
  33. package/dist/cjs/extractor/getStaticBindingsForScope.js +18 -2
  34. package/dist/cjs/extractor/getStaticBindingsForScope.js.map +2 -2
  35. package/dist/cjs/extractor/hoistClassNames.js +0 -0
  36. package/dist/cjs/extractor/hoistClassNames.js.map +0 -0
  37. package/dist/cjs/extractor/literalToAst.js +0 -0
  38. package/dist/cjs/extractor/literalToAst.js.map +0 -0
  39. package/dist/cjs/extractor/loadFile.js +0 -0
  40. package/dist/cjs/extractor/loadFile.js.map +0 -0
  41. package/dist/cjs/extractor/loadTamagui.js +205 -28
  42. package/dist/cjs/extractor/loadTamagui.js.map +2 -2
  43. package/dist/cjs/extractor/logLines.js +0 -0
  44. package/dist/cjs/extractor/logLines.js.map +0 -0
  45. package/dist/cjs/extractor/normalizeTernaries.js +0 -0
  46. package/dist/cjs/extractor/normalizeTernaries.js.map +0 -0
  47. package/dist/cjs/extractor/removeUnusedHooks.js +0 -0
  48. package/dist/cjs/extractor/removeUnusedHooks.js.map +0 -0
  49. package/dist/cjs/extractor/timer.js +8 -1
  50. package/dist/cjs/extractor/timer.js.map +2 -2
  51. package/dist/cjs/extractor/validHTMLAttributes.js +0 -0
  52. package/dist/cjs/extractor/validHTMLAttributes.js.map +0 -0
  53. package/dist/cjs/getPragmaOptions.js +68 -0
  54. package/dist/cjs/getPragmaOptions.js.map +7 -0
  55. package/dist/cjs/index.js +1 -0
  56. package/dist/cjs/index.js.map +2 -2
  57. package/dist/cjs/require.js +1 -20
  58. package/dist/cjs/require.js.map +2 -2
  59. package/dist/cjs/types.js +0 -0
  60. package/dist/cjs/types.js.map +1 -1
  61. package/dist/cjs/webpackPlugin.js +35 -0
  62. package/dist/cjs/webpackPlugin.js.map +7 -0
  63. package/dist/esm/constants.js +0 -0
  64. package/dist/esm/constants.js.map +0 -0
  65. package/dist/esm/extractor/accessSafe.js +0 -0
  66. package/dist/esm/extractor/accessSafe.js.map +0 -0
  67. package/dist/esm/extractor/babelParse.js +0 -0
  68. package/dist/esm/extractor/babelParse.js.map +0 -0
  69. package/dist/esm/extractor/buildClassName.js +0 -0
  70. package/dist/esm/extractor/buildClassName.js.map +0 -0
  71. package/dist/esm/extractor/createEvaluator.js +0 -0
  72. package/dist/esm/extractor/createEvaluator.js.map +2 -2
  73. package/dist/esm/extractor/createExtractor.js +1140 -1108
  74. package/dist/esm/extractor/createExtractor.js.map +2 -2
  75. package/dist/esm/extractor/ensureImportingConcat.js +0 -0
  76. package/dist/esm/extractor/ensureImportingConcat.js.map +0 -0
  77. package/dist/esm/extractor/evaluateAstNode.js +0 -0
  78. package/dist/esm/extractor/evaluateAstNode.js.map +0 -0
  79. package/dist/esm/extractor/extractHelpers.js +0 -0
  80. package/dist/esm/extractor/extractHelpers.js.map +0 -0
  81. package/dist/esm/extractor/extractMediaStyle.js +0 -0
  82. package/dist/esm/extractor/extractMediaStyle.js.map +0 -0
  83. package/dist/esm/extractor/extractToClassNames.js +4 -4
  84. package/dist/esm/extractor/extractToClassNames.js.map +2 -2
  85. package/dist/esm/extractor/findTopmostFunction.js +0 -0
  86. package/dist/esm/extractor/findTopmostFunction.js.map +0 -0
  87. package/dist/esm/extractor/generatedUid.js +0 -0
  88. package/dist/esm/extractor/generatedUid.js.map +0 -0
  89. package/dist/esm/extractor/getPrefixLogs.js +0 -0
  90. package/dist/esm/extractor/getPrefixLogs.js.map +0 -0
  91. package/dist/esm/extractor/getPropValueFromAttributes.js +0 -0
  92. package/dist/esm/extractor/getPropValueFromAttributes.js.map +0 -0
  93. package/dist/esm/extractor/getSourceModule.js +0 -0
  94. package/dist/esm/extractor/getSourceModule.js.map +0 -0
  95. package/dist/esm/extractor/getStaticBindingsForScope.js +17 -2
  96. package/dist/esm/extractor/getStaticBindingsForScope.js.map +2 -2
  97. package/dist/esm/extractor/hoistClassNames.js +0 -0
  98. package/dist/esm/extractor/hoistClassNames.js.map +0 -0
  99. package/dist/esm/extractor/literalToAst.js +0 -0
  100. package/dist/esm/extractor/literalToAst.js.map +0 -0
  101. package/dist/esm/extractor/loadFile.js +0 -0
  102. package/dist/esm/extractor/loadFile.js.map +0 -0
  103. package/dist/esm/extractor/loadTamagui.js +201 -28
  104. package/dist/esm/extractor/loadTamagui.js.map +2 -2
  105. package/dist/esm/extractor/logLines.js +0 -0
  106. package/dist/esm/extractor/logLines.js.map +0 -0
  107. package/dist/esm/extractor/normalizeTernaries.js +0 -0
  108. package/dist/esm/extractor/normalizeTernaries.js.map +0 -0
  109. package/dist/esm/extractor/removeUnusedHooks.js +0 -0
  110. package/dist/esm/extractor/removeUnusedHooks.js.map +0 -0
  111. package/dist/esm/extractor/timer.js +8 -1
  112. package/dist/esm/extractor/timer.js.map +2 -2
  113. package/dist/esm/extractor/validHTMLAttributes.js +0 -0
  114. package/dist/esm/extractor/validHTMLAttributes.js.map +0 -0
  115. package/dist/esm/getPragmaOptions.js +44 -0
  116. package/dist/esm/getPragmaOptions.js.map +7 -0
  117. package/dist/esm/index.js +1 -0
  118. package/dist/esm/index.js.map +2 -2
  119. package/dist/esm/require.js +2 -21
  120. package/dist/esm/require.js.map +2 -2
  121. package/dist/esm/types.js +0 -0
  122. package/dist/esm/types.js.map +0 -0
  123. package/dist/esm/webpackPlugin.js +11 -0
  124. package/dist/esm/webpackPlugin.js.map +7 -0
  125. package/dist/jsx/constants.js +1 -2
  126. package/dist/jsx/constants.js.map +1 -1
  127. package/dist/jsx/extractor/accessSafe.js +0 -0
  128. package/dist/jsx/extractor/accessSafe.js.map +0 -0
  129. package/dist/jsx/extractor/babelParse.js +0 -0
  130. package/dist/jsx/extractor/babelParse.js.map +0 -0
  131. package/dist/jsx/extractor/buildClassName.js +0 -0
  132. package/dist/jsx/extractor/buildClassName.js.map +0 -0
  133. package/dist/jsx/extractor/createEvaluator.js +0 -0
  134. package/dist/jsx/extractor/createEvaluator.js.map +2 -2
  135. package/dist/jsx/extractor/createExtractor.js +1133 -1108
  136. package/dist/jsx/extractor/createExtractor.js.map +2 -2
  137. package/dist/jsx/extractor/ensureImportingConcat.js +0 -0
  138. package/dist/jsx/extractor/ensureImportingConcat.js.map +0 -0
  139. package/dist/jsx/extractor/evaluateAstNode.js +0 -0
  140. package/dist/jsx/extractor/evaluateAstNode.js.map +0 -0
  141. package/dist/jsx/extractor/extractHelpers.js +3 -5
  142. package/dist/jsx/extractor/extractHelpers.js.map +1 -1
  143. package/dist/jsx/extractor/extractMediaStyle.js +2 -3
  144. package/dist/jsx/extractor/extractMediaStyle.js.map +1 -1
  145. package/dist/jsx/extractor/extractToClassNames.js +7 -10
  146. package/dist/jsx/extractor/extractToClassNames.js.map +2 -2
  147. package/dist/jsx/extractor/findTopmostFunction.js +0 -0
  148. package/dist/jsx/extractor/findTopmostFunction.js.map +0 -0
  149. package/dist/jsx/extractor/generatedUid.js +0 -0
  150. package/dist/jsx/extractor/generatedUid.js.map +0 -0
  151. package/dist/jsx/extractor/getPrefixLogs.js +1 -2
  152. package/dist/jsx/extractor/getPrefixLogs.js.map +1 -1
  153. package/dist/jsx/extractor/getPropValueFromAttributes.js +0 -0
  154. package/dist/jsx/extractor/getPropValueFromAttributes.js.map +0 -0
  155. package/dist/jsx/extractor/getSourceModule.js +0 -0
  156. package/dist/jsx/extractor/getSourceModule.js.map +0 -0
  157. package/dist/jsx/extractor/getStaticBindingsForScope.js +17 -2
  158. package/dist/jsx/extractor/getStaticBindingsForScope.js.map +2 -2
  159. package/dist/jsx/extractor/hoistClassNames.js +0 -0
  160. package/dist/jsx/extractor/hoistClassNames.js.map +0 -0
  161. package/dist/jsx/extractor/literalToAst.js +1 -1
  162. package/dist/jsx/extractor/literalToAst.js.map +1 -1
  163. package/dist/jsx/extractor/loadFile.js +3 -4
  164. package/dist/jsx/extractor/loadFile.js.map +1 -1
  165. package/dist/jsx/extractor/loadTamagui.js +199 -28
  166. package/dist/jsx/extractor/loadTamagui.js.map +2 -2
  167. package/dist/jsx/extractor/logLines.js +0 -0
  168. package/dist/jsx/extractor/logLines.js.map +0 -0
  169. package/dist/jsx/extractor/normalizeTernaries.js +2 -3
  170. package/dist/jsx/extractor/normalizeTernaries.js.map +1 -1
  171. package/dist/jsx/extractor/removeUnusedHooks.js +3 -5
  172. package/dist/jsx/extractor/removeUnusedHooks.js.map +1 -1
  173. package/dist/jsx/extractor/timer.js +8 -1
  174. package/dist/jsx/extractor/timer.js.map +2 -2
  175. package/dist/jsx/extractor/validHTMLAttributes.js +0 -0
  176. package/dist/jsx/extractor/validHTMLAttributes.js.map +0 -0
  177. package/dist/jsx/getPragmaOptions.js +43 -0
  178. package/dist/jsx/getPragmaOptions.js.map +7 -0
  179. package/dist/jsx/index.js +1 -0
  180. package/dist/jsx/index.js.map +2 -2
  181. package/dist/jsx/require.js +2 -21
  182. package/dist/jsx/require.js.map +2 -2
  183. package/dist/jsx/types.js +0 -0
  184. package/dist/jsx/types.js.map +0 -0
  185. package/dist/jsx/webpackPlugin.js +11 -0
  186. package/dist/jsx/webpackPlugin.js.map +7 -0
  187. package/package.json +20 -17
  188. package/src/extractor/createEvaluator.ts +2 -0
  189. package/src/extractor/createExtractor.ts +1592 -1532
  190. package/src/extractor/extractToClassNames.ts +25 -10
  191. package/src/extractor/getStaticBindingsForScope.ts +22 -5
  192. package/src/extractor/loadTamagui.ts +250 -32
  193. package/src/extractor/timer.ts +12 -1
  194. package/src/getPragmaOptions.ts +52 -0
  195. package/src/index.ts +2 -0
  196. package/src/require.ts +29 -24
  197. package/src/types.ts +16 -0
  198. package/src/webpackPlugin.ts +9 -0
  199. package/types/extractor/createExtractor.d.ts +22 -6
  200. package/types/extractor/extractToClassNames.d.ts +1 -1
  201. package/types/extractor/getStaticBindingsForScope.d.ts +1 -0
  202. package/types/extractor/loadTamagui.d.ts +5 -3
  203. package/types/getPragmaOptions.d.ts +9 -0
  204. package/types/index.d.ts +1 -0
  205. package/types/types.d.ts +13 -0
  206. package/types/webpackPlugin.d.ts +4 -0
@@ -15,9 +15,9 @@ import { createEvaluator, createSafeEvaluator } from "./createEvaluator";
15
15
  import { evaluateAstNode } from "./evaluateAstNode";
16
16
  import { attrStr, findComponentName, isInsideTamagui, isPresent, objToStr } from "./extractHelpers";
17
17
  import { findTopmostFunction } from "./findTopmostFunction";
18
- import { getStaticBindingsForScope } from "./getStaticBindingsForScope";
18
+ import { cleanupBeforeExit, getStaticBindingsForScope } from "./getStaticBindingsForScope";
19
19
  import { literalToAst } from "./literalToAst";
20
- import { loadTamagui } from "./loadTamagui";
20
+ import { loadTamagui, loadTamaguiSync } from "./loadTamagui";
21
21
  import { logLines } from "./logLines";
22
22
  import { normalizeTernaries } from "./normalizeTernaries";
23
23
  import { removeUnusedHooks } from "./removeUnusedHooks";
@@ -39,1302 +39,1327 @@ const INLINE_EXTRACTABLE = {
39
39
  onPressOut: "onMouseUp"
40
40
  }
41
41
  };
42
- const isAttr = (x) => x.type === "attr";
43
42
  const validHooks = {
44
43
  useMedia: true,
45
44
  useTheme: true
46
45
  };
46
+ const isAttr = (x) => x.type === "attr";
47
47
  const createTernary = (x) => x;
48
- function createExtractor() {
48
+ function createExtractor({ logger = console } = { logger: console }) {
49
49
  if (!process.env.TAMAGUI_TARGET) {
50
50
  console.log('\u26A0\uFE0F Please set process.env.TAMAGUI_TARGET to either "web" or "native"');
51
51
  process.exit(1);
52
52
  }
53
53
  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);
54
- let loadedTamaguiConfig;
55
- let hasLogged = false;
56
- function isValidStyleKey(name, staticConfig) {
57
- var _a, _b;
58
- return !!(!!((_a = staticConfig.validStyles) == null ? void 0 : _a[name]) || !!pseudoDescriptors[name] || ((_b = staticConfig.variants) == null ? void 0 : _b[name]) || loadedTamaguiConfig.shorthands[name] || (name[0] === "$" ? !!mediaQueryConfig[name.slice(1)] : false));
54
+ let projectInfo = null;
55
+ function loadSync(props) {
56
+ return projectInfo || (projectInfo = loadTamaguiSync({
57
+ config: props.config || "tamagui.config.ts",
58
+ components: props.components || ["tamagui"]
59
+ }));
60
+ }
61
+ async function load(props) {
62
+ return projectInfo || (projectInfo = await loadTamagui({
63
+ config: props.config || "tamagui.config.ts",
64
+ components: props.components || ["tamagui"]
65
+ }));
59
66
  }
60
67
  return {
68
+ options: {
69
+ logger
70
+ },
71
+ cleanupBeforeExit,
72
+ loadTamagui: load,
73
+ loadTamaguiSync: loadSync,
61
74
  getTamagui() {
62
- return loadedTamaguiConfig;
75
+ return projectInfo?.tamaguiConfig;
63
76
  },
64
- parse: (fileOrPath, {
65
- config = "tamagui.config.ts",
66
- importsWhitelist = ["constants.js"],
67
- evaluateVars = true,
68
- shouldPrintDebug = false,
69
- sourcePath = "",
70
- onExtractTag,
71
- onStyleRule,
72
- getFlattenedNode,
73
- disable,
74
- disableExtraction,
75
- disableExtractInlineMedia,
76
- disableExtractVariables,
77
- disableDebugAttr,
78
- extractStyledDefinitions = false,
79
- prefixLogs,
80
- excludeProps,
81
- target,
82
- ...props
83
- }) => {
84
- if (disable) {
85
- return null;
86
- }
87
- if (sourcePath === "") {
88
- throw new Error(`Must provide a source file name`);
89
- }
90
- if (!Array.isArray(props.components)) {
91
- throw new Error(`Must provide components array with list of Tamagui component modules`);
92
- }
93
- const isTargetingHTML = target === "html";
94
- const ogDebug = shouldPrintDebug;
95
- const tm = timer();
96
- const { components, tamaguiConfig } = loadTamagui({
97
- config,
98
- components: props.components || ["tamagui"]
99
- });
100
- if (shouldPrintDebug === "verbose") {
101
- console.log("tamagui.config.ts:", { components, config });
102
- }
103
- tm.mark("load-tamagui", shouldPrintDebug === "verbose");
104
- loadedTamaguiConfig = tamaguiConfig;
105
- const proxiedTheme = proxyThemeVariables(tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]]);
106
- const themeAccessListeners = /* @__PURE__ */ new Set();
107
- const defaultTheme = new Proxy(proxiedTheme, {
108
- get(target2, key) {
109
- if (key[0] === "$") {
110
- themeAccessListeners.forEach((cb) => cb(String(key)));
111
- }
112
- return Reflect.get(target2, key);
77
+ parseSync: (f, props) => {
78
+ const projectInfo2 = loadSync(props);
79
+ return parseWithConfig(projectInfo2, f, props);
80
+ },
81
+ parse: async (f, props) => {
82
+ const projectInfo2 = await load(props);
83
+ return parseWithConfig(projectInfo2, f, props);
84
+ }
85
+ };
86
+ function isValidStyleKey(name, staticConfig) {
87
+ if (!projectInfo) {
88
+ throw new Error(`Tamagui extractor not loaded yet`);
89
+ }
90
+ return !!(!!staticConfig.validStyles?.[name] || !!pseudoDescriptors[name] || staticConfig.variants?.[name] || projectInfo?.tamaguiConfig.shorthands[name] || (name[0] === "$" ? !!mediaQueryConfig[name.slice(1)] : false));
91
+ }
92
+ function parseWithConfig({ components, tamaguiConfig }, fileOrPath, {
93
+ config = "tamagui.config.ts",
94
+ importsWhitelist = ["constants.js"],
95
+ evaluateVars = true,
96
+ shouldPrintDebug = false,
97
+ sourcePath = "",
98
+ onExtractTag,
99
+ onStyleRule,
100
+ getFlattenedNode,
101
+ disable,
102
+ disableExtraction,
103
+ disableExtractInlineMedia,
104
+ disableExtractVariables,
105
+ disableDebugAttr,
106
+ extractStyledDefinitions = false,
107
+ prefixLogs,
108
+ excludeProps,
109
+ target,
110
+ ...props
111
+ }) {
112
+ if (disable) {
113
+ return null;
114
+ }
115
+ if (sourcePath === "") {
116
+ throw new Error(`Must provide a source file name`);
117
+ }
118
+ if (!components) {
119
+ throw new Error(`Must provide components`);
120
+ }
121
+ const isTargetingHTML = target === "html";
122
+ const ogDebug = shouldPrintDebug;
123
+ const tm = timer();
124
+ if (shouldPrintDebug === "verbose") {
125
+ console.log("tamagui.config.ts:", { components, config });
126
+ }
127
+ tm.mark("load-tamagui", !!shouldPrintDebug);
128
+ const proxiedTheme = proxyThemeVariables(tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]]);
129
+ const themeAccessListeners = /* @__PURE__ */ new Set();
130
+ const defaultTheme = new Proxy(proxiedTheme, {
131
+ get(target2, key) {
132
+ if (key[0] === "$") {
133
+ themeAccessListeners.forEach((cb) => cb(String(key)));
113
134
  }
114
- });
115
- const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
116
- const isInternalImport = (importStr) => {
117
- return isInsideTamagui(sourcePath) && importStr[0] === ".";
118
- };
119
- const validComponents = Object.keys(components).filter((key) => {
120
- var _a;
121
- return key[0].toUpperCase() === key[0] && !!((_a = components[key]) == null ? void 0 : _a.staticConfig);
122
- }).reduce((obj, name) => {
123
- obj[name] = components[name];
124
- return obj;
125
- }, {});
126
- if (shouldPrintDebug === "verbose") {
127
- console.log("validComponents", Object.keys(validComponents));
135
+ return Reflect.get(target2, key);
128
136
  }
129
- let doesUseValidImport = false;
130
- let hasImportedTheme = false;
131
- for (const bodyPath of body) {
132
- if (bodyPath.type !== "ImportDeclaration")
133
- continue;
134
- const node = "node" in bodyPath ? bodyPath.node : bodyPath;
135
- const from = node.source.value;
136
- if (extractStyledDefinitions) {
137
- if (from === "@tamagui/core" || from === "tamagui") {
138
- if (node.specifiers.some((specifier) => {
139
- return specifier.local.name === "styled";
140
- })) {
141
- doesUseValidImport = true;
142
- break;
143
- }
144
- }
145
- }
146
- const isValidImport = props.components.includes(from) || isInternalImport(from);
137
+ });
138
+ const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
139
+ const isInternalImport = (importStr) => {
140
+ return isInsideTamagui(sourcePath) && importStr[0] === ".";
141
+ };
142
+ const validComponents = Object.keys(components).filter((key) => key[0].toUpperCase() === key[0] && !!components[key]?.staticConfig).reduce((obj, name) => {
143
+ obj[name] = components[name];
144
+ return obj;
145
+ }, {});
146
+ if (shouldPrintDebug === "verbose") {
147
+ logger.info(`validComponents ${Object.keys(validComponents).join(", ")}`);
148
+ }
149
+ let doesUseValidImport = false;
150
+ let hasImportedTheme = 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
+ const isValidImport = props.components.includes(from) || isInternalImport(from) || from === "@tamagui/core" || from === "tamagui";
157
+ if (extractStyledDefinitions) {
147
158
  if (isValidImport) {
148
- const isValidComponent = node.specifiers.some((specifier) => {
149
- const name = specifier.local.name;
150
- return !!(validComponents[name] || validHooks[name]);
151
- });
152
- if (shouldPrintDebug === "verbose") {
153
- console.log("import from", from, { isValidComponent });
154
- }
155
- if (isValidComponent) {
159
+ if (node.specifiers.some((specifier) => {
160
+ return specifier.local.name === "styled";
161
+ })) {
156
162
  doesUseValidImport = true;
157
163
  break;
158
164
  }
159
165
  }
160
166
  }
161
- if (shouldPrintDebug) {
162
- console.log(sourcePath, { doesUseValidImport });
163
- }
164
- if (!doesUseValidImport) {
165
- return null;
167
+ if (isValidImport) {
168
+ const isValidComponent = node.specifiers.some((specifier) => {
169
+ const name = specifier.local.name;
170
+ return !!(validComponents[name] || validHooks[name]);
171
+ });
172
+ if (shouldPrintDebug === "verbose") {
173
+ logger.info(`import from ${from} isValidComponent ${isValidComponent}`);
174
+ }
175
+ if (isValidComponent) {
176
+ doesUseValidImport = true;
177
+ break;
178
+ }
166
179
  }
167
- tm.mark("import-check", shouldPrintDebug === "verbose");
168
- let couldntParse = false;
169
- const modifiedComponents = /* @__PURE__ */ new Set();
170
- const bindingCache = {};
171
- const callTraverse = (a) => {
172
- return fileOrPath.type === "File" ? traverse(fileOrPath, a) : fileOrPath.traverse(a);
173
- };
174
- let programPath;
175
- const res = {
176
- styled: 0,
177
- flattened: 0,
178
- optimized: 0,
179
- modified: 0,
180
- found: 0
181
- };
182
- callTraverse({
183
- Program: {
184
- enter(path) {
185
- programPath = path;
186
- }
187
- },
188
- CallExpression(path) {
189
- var _a;
190
- if (disable || disableExtraction || extractStyledDefinitions === false) {
191
- return;
192
- }
193
- if (!t.isIdentifier(path.node.callee) || path.node.callee.name !== "styled") {
194
- return;
195
- }
196
- const name = t.isVariableDeclarator(path.parent) && t.isIdentifier(path.parent.id) ? path.parent.id.name : "unknown";
197
- const definition = path.node.arguments[1];
198
- if (!name || !definition || !t.isObjectExpression(definition)) {
199
- return;
200
- }
201
- const Component = validComponents[name];
202
- if (!Component) {
203
- if (shouldPrintDebug) {
204
- console.log(`Didn't recognize styled(${name}), ${name} isn't in design system provided to tamagui.config.ts`);
205
- }
206
- return;
180
+ }
181
+ if (shouldPrintDebug) {
182
+ logger.info(`source: ${sourcePath} doesUseValidImport ${doesUseValidImport}`);
183
+ }
184
+ if (!doesUseValidImport) {
185
+ return null;
186
+ }
187
+ tm.mark("import-check", !!shouldPrintDebug);
188
+ let couldntParse = false;
189
+ const modifiedComponents = /* @__PURE__ */ new Set();
190
+ const bindingCache = {};
191
+ const callTraverse = (a) => {
192
+ return fileOrPath.type === "File" ? traverse(fileOrPath, a) : fileOrPath.traverse(a);
193
+ };
194
+ let programPath;
195
+ const res = {
196
+ styled: 0,
197
+ flattened: 0,
198
+ optimized: 0,
199
+ modified: 0,
200
+ found: 0
201
+ };
202
+ callTraverse({
203
+ Program: {
204
+ enter(path) {
205
+ programPath = path;
206
+ }
207
+ },
208
+ CallExpression(path) {
209
+ if (disable || disableExtraction || extractStyledDefinitions === false) {
210
+ return;
211
+ }
212
+ if (!t.isIdentifier(path.node.callee) || path.node.callee.name !== "styled") {
213
+ return;
214
+ }
215
+ const name = t.isVariableDeclarator(path.parent) && t.isIdentifier(path.parent.id) ? path.parent.id.name : "unknown";
216
+ const definition = path.node.arguments[1];
217
+ if (!name || !definition || !t.isObjectExpression(definition)) {
218
+ return;
219
+ }
220
+ let Component = validComponents[name];
221
+ if (!Component) {
222
+ if (shouldPrintDebug) {
223
+ logger.info(`Didn't recognize styled(${name}), ${name} isn't in design system provided to tamagui.config.ts. Will attempt to build isolated and analyze.. ${programPath}`);
207
224
  }
208
- const componentSkipProps = /* @__PURE__ */ new Set([
209
- ...Component.staticConfig.inlineWhenUnflattened || [],
210
- ...Component.staticConfig.inlineProps || [],
211
- ...Component.staticConfig.deoptProps || [],
212
- "variants",
213
- "defaultVariants",
214
- "fontFamily",
215
- "name"
216
- ]);
217
- const skipped = [];
218
- const styles = {};
219
- const staticNamespace = getStaticBindingsForScope(path.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
220
- const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
221
- tamaguiConfig,
222
- staticNamespace,
223
- sourcePath,
224
- shouldPrintDebug
225
+ const out2 = loadTamaguiSync({
226
+ components: [sourcePath]
225
227
  });
226
- const attemptEvalSafe = createSafeEvaluator(attemptEval);
227
- for (const property of definition.properties) {
228
- if (!t.isObjectProperty(property) || !t.isIdentifier(property.key) || !isValidStyleKey(property.key.name, Component.staticConfig) || ((_a = Component.staticConfig.variants) == null ? void 0 : _a[property.key.name]) || componentSkipProps.has(property.key.name)) {
229
- skipped.push(property);
230
- continue;
231
- }
232
- const out2 = attemptEvalSafe(property.value);
233
- if (out2 === FAILED_EVAL) {
234
- skipped.push(property);
235
- } else {
236
- styles[property.key.name] = out2;
237
- }
228
+ if (out2.components?.[name]) {
229
+ Object.assign(validComponents, out2.components);
238
230
  }
239
- const out = getSplitStyles(styles, Component.staticConfig, defaultTheme, {
240
- focus: false,
241
- hover: false,
242
- mounted: false,
243
- press: false,
244
- pressIn: false,
245
- resolveVariablesAs: "variable"
246
- });
247
- const classNames = {
248
- ...out.classNames
249
- };
250
- const atomics = getStylesAtomic(out.style);
231
+ Component = validComponents[name];
251
232
  if (shouldPrintDebug) {
252
- console.log("Exctacting styled()", styles, out, "to", atomics);
233
+ logger.info([`Loaded`, Object.keys(out2.components).join(", "), !!Component].join(" "));
253
234
  }
254
- for (const atomic of atomics) {
255
- out.rulesToInsert = out.rulesToInsert || [];
256
- out.rulesToInsert.push(atomic);
257
- classNames[atomic.property] = atomic.identifier;
235
+ }
236
+ if (!Component) {
237
+ return;
238
+ }
239
+ const componentSkipProps = /* @__PURE__ */ new Set([
240
+ ...Component.staticConfig.inlineWhenUnflattened || [],
241
+ ...Component.staticConfig.inlineProps || [],
242
+ ...Component.staticConfig.deoptProps || [],
243
+ "variants",
244
+ "defaultVariants",
245
+ "fontFamily",
246
+ "name"
247
+ ]);
248
+ const skipped = [];
249
+ const styles = {};
250
+ const staticNamespace = getStaticBindingsForScope(path.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
251
+ const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
252
+ tamaguiConfig,
253
+ staticNamespace,
254
+ sourcePath,
255
+ shouldPrintDebug
256
+ });
257
+ const attemptEvalSafe = createSafeEvaluator(attemptEval);
258
+ for (const property of definition.properties) {
259
+ if (!t.isObjectProperty(property) || !t.isIdentifier(property.key) || !isValidStyleKey(property.key.name, Component.staticConfig) || Component.staticConfig.variants?.[property.key.name] || componentSkipProps.has(property.key.name)) {
260
+ skipped.push(property);
261
+ continue;
258
262
  }
259
- definition.properties = skipped;
260
- for (const cn in classNames) {
261
- if (componentSkipProps.has(cn)) {
262
- continue;
263
- }
264
- const val = classNames[cn];
265
- definition.properties.push(t.objectProperty(t.stringLiteral(cn), t.stringLiteral(val)));
263
+ const out2 = attemptEvalSafe(property.value);
264
+ if (out2 === FAILED_EVAL) {
265
+ skipped.push(property);
266
+ } else {
267
+ styles[property.key.name] = out2;
266
268
  }
267
- if (out.rulesToInsert) {
268
- for (const { identifier, rules } of out.rulesToInsert) {
269
- onStyleRule == null ? void 0 : onStyleRule(identifier, rules);
270
- }
269
+ }
270
+ const out = getSplitStyles(styles, Component.staticConfig, defaultTheme, {
271
+ focus: false,
272
+ hover: false,
273
+ mounted: false,
274
+ press: false,
275
+ pressIn: false,
276
+ resolveVariablesAs: "variable"
277
+ });
278
+ const classNames = {
279
+ ...out.classNames
280
+ };
281
+ const atomics = getStylesAtomic(out.style);
282
+ for (const atomic of atomics) {
283
+ out.rulesToInsert = out.rulesToInsert || [];
284
+ out.rulesToInsert.push(atomic);
285
+ classNames[atomic.property] = atomic.identifier;
286
+ }
287
+ if (shouldPrintDebug) {
288
+ logger.info([`Extracted styled(${name})
289
+ `, JSON.stringify(styles, null, 2), "\n=>\n", out.rulesToInsert.flatMap((rule) => rule.rules).join("\n")].join(" "));
290
+ }
291
+ definition.properties = skipped;
292
+ for (const cn in classNames) {
293
+ if (componentSkipProps.has(cn)) {
294
+ continue;
271
295
  }
272
- res.styled++;
273
- if (shouldPrintDebug) {
274
- console.log(`Extracted styled(${name}) props:`, styles);
296
+ const val = classNames[cn];
297
+ definition.properties.push(t.objectProperty(t.stringLiteral(cn), t.stringLiteral(val)));
298
+ }
299
+ if (out.rulesToInsert) {
300
+ for (const { identifier, rules } of out.rulesToInsert) {
301
+ onStyleRule?.(identifier, rules);
275
302
  }
276
- },
277
- JSXElement(traversePath) {
278
- var _a, _b, _c, _d, _e;
279
- tm.mark("jsx-element", shouldPrintDebug === "verbose");
280
- const node = traversePath.node.openingElement;
281
- const ogAttributes = node.attributes;
282
- const componentName = findComponentName(traversePath.scope);
283
- const closingElement = traversePath.node.closingElement;
284
- if (t.isJSXMemberExpression(closingElement == null ? void 0 : closingElement.name) || !t.isJSXIdentifier(node.name)) {
303
+ }
304
+ res.styled++;
305
+ if (shouldPrintDebug) {
306
+ logger.info(`Extracted styled(${name})`);
307
+ }
308
+ },
309
+ JSXElement(traversePath) {
310
+ tm.mark("jsx-element", !!shouldPrintDebug);
311
+ const node = traversePath.node.openingElement;
312
+ const ogAttributes = node.attributes;
313
+ const componentName = findComponentName(traversePath.scope);
314
+ const closingElement = traversePath.node.closingElement;
315
+ if (t.isJSXMemberExpression(closingElement?.name) || !t.isJSXIdentifier(node.name)) {
316
+ return;
317
+ }
318
+ const binding = traversePath.scope.getBinding(node.name.name);
319
+ if (binding) {
320
+ if (!t.isImportDeclaration(binding.path.parent)) {
285
321
  return;
286
322
  }
287
- const binding = traversePath.scope.getBinding(node.name.name);
288
- if (binding) {
289
- if (!t.isImportDeclaration(binding.path.parent)) {
290
- return;
291
- }
292
- const source = binding.path.parent.source;
293
- if (!props.components.includes(source.value) && !isInternalImport(source.value)) {
294
- return;
295
- }
296
- if (!validComponents[binding.identifier.name]) {
297
- return;
298
- }
299
- }
300
- const component = validComponents[node.name.name];
301
- if (!component || !component.staticConfig) {
323
+ const source = binding.path.parent.source;
324
+ if (!props.components.includes(source.value) && !isInternalImport(source.value)) {
302
325
  return;
303
326
  }
304
- const originalNodeName = node.name.name;
305
- res.found++;
306
- const filePath = `./${relative(process.cwd(), sourcePath)}`;
307
- const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
308
- const codePosition = `${filePath}:${lineNumbers}`;
309
- const debugPropValue = node.attributes.filter((n) => t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && n.name.name === "debug").map((n) => {
310
- if (n.value === null)
311
- return true;
312
- if (t.isStringLiteral(n.value))
313
- return n.value.value;
314
- return false;
315
- })[0];
316
- if (debugPropValue) {
317
- shouldPrintDebug = debugPropValue;
318
- }
319
- if (shouldPrintDebug) {
320
- console.log("\n");
321
- console.log("\x1B[33m%s\x1B[0m", `${componentName} | ${codePosition} -------------------`);
322
- console.log("\x1B[1m", "\x1B[32m", `<${originalNodeName} />`, disableDebugAttr ? "" : "\u{1F41B}");
323
- }
324
- if (shouldAddDebugProp && !disableDebugAttr) {
325
- res.modified++;
326
- node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(node.name.name)));
327
- if (componentName) {
328
- node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-in"), t.stringLiteral(componentName)));
329
- }
330
- node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-at"), t.stringLiteral(`${basename(filePath)}:${lineNumbers}`)));
331
- }
332
- const shouldLog = !hasLogged;
333
- if (shouldLog) {
334
- console.log(` 1\uFE0F\u20E3 Inline optimized 2\uFE0F\u20E3 Inline flattened 3\uFE0F\u20E3 styled() extracted`);
335
- const prefix = " |";
336
- console.log(prefixLogs || prefix, " total \xB7 1\uFE0F\u20E3 \xB7 2\uFE0F\u20E3 \xB7 3\uFE0F\u20E3");
337
- hasLogged = true;
338
- }
339
- if (disableExtraction) {
327
+ if (!validComponents[binding.identifier.name]) {
340
328
  return;
341
329
  }
342
- try {
343
- let evaluateAttribute2 = function(path) {
344
- const attribute = path.node;
345
- const attr = { type: "attr", value: attribute };
346
- if (t.isJSXSpreadAttribute(attribute)) {
347
- const arg = attribute.argument;
348
- const conditional = t.isConditionalExpression(arg) ? [arg.test, arg.consequent, arg.alternate] : t.isLogicalExpression(arg) && arg.operator === "&&" ? [arg.left, arg.right, null] : null;
349
- if (conditional) {
350
- const [test, alt, cons] = conditional;
351
- if (!test)
352
- throw new Error(`no test`);
353
- if ([alt, cons].some((side) => side && !isExtractable2(side))) {
354
- if (shouldPrintDebug) {
355
- console.log("not extractable", alt, cons);
356
- }
357
- return attr;
330
+ }
331
+ const component = validComponents[node.name.name];
332
+ if (!component || !component.staticConfig) {
333
+ return;
334
+ }
335
+ const originalNodeName = node.name.name;
336
+ res.found++;
337
+ const filePath = `./${relative(process.cwd(), sourcePath)}`;
338
+ const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
339
+ const codePosition = `${filePath}:${lineNumbers}`;
340
+ const debugPropValue = node.attributes.filter((n) => t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && n.name.name === "debug").map((n) => {
341
+ if (n.value === null)
342
+ return true;
343
+ if (t.isStringLiteral(n.value))
344
+ return n.value.value;
345
+ return false;
346
+ })[0];
347
+ if (debugPropValue) {
348
+ shouldPrintDebug = debugPropValue;
349
+ }
350
+ if (shouldPrintDebug) {
351
+ logger.info("\n");
352
+ logger.info(`\x1B[33m%s\x1B[0m ${componentName} | ${codePosition} -------------------`);
353
+ logger.info(["\x1B[1m", "\x1B[32m", `<${originalNodeName} />`, disableDebugAttr ? "" : "\u{1F41B}"].join(" "));
354
+ }
355
+ if (shouldAddDebugProp && !disableDebugAttr) {
356
+ res.modified++;
357
+ node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(node.name.name)));
358
+ if (componentName) {
359
+ node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-in"), t.stringLiteral(componentName)));
360
+ }
361
+ node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-at"), t.stringLiteral(`${basename(filePath)}:${lineNumbers}`)));
362
+ }
363
+ if (disableExtraction) {
364
+ return;
365
+ }
366
+ try {
367
+ let evaluateAttribute2 = function(path) {
368
+ const attribute = path.node;
369
+ const attr = { type: "attr", value: attribute };
370
+ if (t.isJSXSpreadAttribute(attribute)) {
371
+ const arg = attribute.argument;
372
+ const conditional = t.isConditionalExpression(arg) ? [arg.test, arg.consequent, arg.alternate] : t.isLogicalExpression(arg) && arg.operator === "&&" ? [arg.left, arg.right, null] : null;
373
+ if (conditional) {
374
+ const [test, alt, cons] = conditional;
375
+ if (!test)
376
+ throw new Error(`no test`);
377
+ if ([alt, cons].some((side) => side && !isExtractable2(side))) {
378
+ if (shouldPrintDebug) {
379
+ logger.info(`not extractable ${alt} ${cons}`);
358
380
  }
359
- return [
360
- ...createTernariesFromObjectProperties2(test, alt) || [],
361
- ...cons && createTernariesFromObjectProperties2(t.unaryExpression("!", test), cons) || []
362
- ].map((ternary) => ({
363
- type: "ternary",
364
- value: ternary
365
- }));
366
- }
367
- }
368
- if (t.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name !== "string") {
369
- if (shouldPrintDebug) {
370
- console.log(" ! inlining, spread attr");
371
- }
372
- inlined.set(`${Math.random()}`, "spread");
373
- return attr;
374
- }
375
- const name = attribute.name.name;
376
- if (excludeProps == null ? void 0 : excludeProps.has(name)) {
377
- if (shouldPrintDebug) {
378
- console.log(" excluding prop", name);
381
+ return attr;
379
382
  }
380
- return null;
383
+ return [
384
+ ...createTernariesFromObjectProperties2(test, alt) || [],
385
+ ...cons && createTernariesFromObjectProperties2(t.unaryExpression("!", test), cons) || []
386
+ ].map((ternary) => ({
387
+ type: "ternary",
388
+ value: ternary
389
+ }));
381
390
  }
382
- if (inlineProps.has(name)) {
383
- inlined.set(name, name);
384
- if (shouldPrintDebug) {
385
- console.log(" ! inlining, inline prop", name);
386
- }
387
- return attr;
391
+ }
392
+ if (t.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name !== "string") {
393
+ if (shouldPrintDebug) {
394
+ logger.info(" ! inlining, spread attr");
388
395
  }
389
- if (deoptProps.has(name)) {
390
- shouldDeopt = true;
391
- inlined.set(name, name);
392
- if (shouldPrintDebug) {
393
- console.log(" ! inlining, deopted prop", name);
394
- }
395
- return attr;
396
+ inlined.set(`${Math.random()}`, "spread");
397
+ return attr;
398
+ }
399
+ const name = attribute.name.name;
400
+ if (excludeProps?.has(name)) {
401
+ if (shouldPrintDebug) {
402
+ logger.info([" excluding prop", name].join(" "));
396
403
  }
397
- if (UNTOUCHED_PROPS[name]) {
398
- return attr;
404
+ return null;
405
+ }
406
+ if (inlineProps.has(name)) {
407
+ inlined.set(name, name);
408
+ if (shouldPrintDebug) {
409
+ logger.info([" ! inlining, inline prop", name].join(" "));
399
410
  }
400
- if (INLINE_EXTRACTABLE[name]) {
401
- inlined.set(name, INLINE_EXTRACTABLE[name]);
402
- return attr;
411
+ return attr;
412
+ }
413
+ if (deoptProps.has(name)) {
414
+ shouldDeopt = true;
415
+ inlined.set(name, name);
416
+ if (shouldPrintDebug) {
417
+ logger.info([" ! inlining, deopted prop", name].join(" "));
403
418
  }
404
- if (name.startsWith("data-")) {
419
+ return attr;
420
+ }
421
+ if (UNTOUCHED_PROPS[name]) {
422
+ return attr;
423
+ }
424
+ if (INLINE_EXTRACTABLE[name]) {
425
+ inlined.set(name, INLINE_EXTRACTABLE[name]);
426
+ return attr;
427
+ }
428
+ if (name.startsWith("data-")) {
429
+ return attr;
430
+ }
431
+ if (name[0] === "$" && t.isJSXExpressionContainer(attribute?.value)) {
432
+ if (disableExtractInlineMedia) {
405
433
  return attr;
406
434
  }
407
- if (name[0] === "$" && t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
408
- if (disableExtractInlineMedia) {
409
- return attr;
410
- }
411
- const shortname = name.slice(1);
412
- if (mediaQueryConfig[shortname]) {
413
- const expression = attribute.value.expression;
414
- if (!t.isJSXEmptyExpression(expression)) {
415
- const ternaries2 = createTernariesFromObjectProperties2(t.stringLiteral(shortname), expression, {
416
- inlineMediaQuery: shortname
417
- });
418
- if (ternaries2) {
419
- return ternaries2.map((value2) => ({
420
- type: "ternary",
421
- value: value2
422
- }));
423
- }
435
+ const shortname = name.slice(1);
436
+ if (mediaQueryConfig[shortname]) {
437
+ const expression = attribute.value.expression;
438
+ if (!t.isJSXEmptyExpression(expression)) {
439
+ const ternaries2 = createTernariesFromObjectProperties2(t.stringLiteral(shortname), expression, {
440
+ inlineMediaQuery: shortname
441
+ });
442
+ if (ternaries2) {
443
+ return ternaries2.map((value2) => ({
444
+ type: "ternary",
445
+ value: value2
446
+ }));
424
447
  }
425
448
  }
426
449
  }
427
- const [value, valuePath] = (() => {
428
- if (t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
429
- return [attribute.value.expression, path.get("value")];
430
- } else {
431
- return [attribute.value, path.get("value")];
432
- }
433
- })();
434
- const remove = () => {
435
- Array.isArray(valuePath) ? valuePath.map((p) => p.remove()) : valuePath.remove();
436
- };
437
- if (name === "ref") {
438
- if (shouldPrintDebug) {
439
- console.log(" ! inlining, ref", name);
440
- }
441
- inlined.set("ref", "ref");
442
- return attr;
450
+ }
451
+ const [value, valuePath] = (() => {
452
+ if (t.isJSXExpressionContainer(attribute?.value)) {
453
+ return [attribute.value.expression, path.get("value")];
454
+ } else {
455
+ return [attribute.value, path.get("value")];
443
456
  }
444
- if (name === "tag") {
445
- return {
446
- type: "attr",
447
- value: path.node
448
- };
457
+ })();
458
+ const remove = () => {
459
+ Array.isArray(valuePath) ? valuePath.map((p) => p.remove()) : valuePath.remove();
460
+ };
461
+ if (name === "ref") {
462
+ if (shouldPrintDebug) {
463
+ logger.info([" ! inlining, ref", name].join(" "));
449
464
  }
450
- if (disableExtractVariables) {
451
- if (value) {
452
- if (value.type === "StringLiteral" && value.value[0] === "$") {
453
- if (shouldPrintDebug) {
454
- console.log(` ! inlining, native disable extract: ${name} =`, value.value);
455
- }
456
- inlined.set(name, true);
457
- return attr;
465
+ inlined.set("ref", "ref");
466
+ return attr;
467
+ }
468
+ if (name === "tag") {
469
+ return {
470
+ type: "attr",
471
+ value: path.node
472
+ };
473
+ }
474
+ if (disableExtractVariables) {
475
+ if (value) {
476
+ if (value.type === "StringLiteral" && value.value[0] === "$") {
477
+ if (shouldPrintDebug) {
478
+ logger.info([` ! inlining, native disable extract: ${name} =`, value.value].join(" "));
458
479
  }
480
+ inlined.set(name, true);
481
+ return attr;
459
482
  }
460
483
  }
461
- if (name === "theme") {
462
- inlined.set("theme", attr.value);
463
- return attr;
464
- }
465
- const styleValue = attemptEvalSafe(value);
466
- if (!variants[name] && !isValidStyleKey(name, staticConfig)) {
467
- let keys = [name];
468
- let out = null;
469
- out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, { resolveVariablesAs: "auto" }, void 0, void 0, shouldPrintDebug);
470
- if (out) {
471
- if (!Array.isArray(out)) {
472
- console.warn(`Error expected array but got`, out);
473
- couldntParse = true;
474
- shouldDeopt = true;
475
- } else {
476
- out = Object.fromEntries(out);
477
- keys = Object.keys(out);
478
- }
479
- }
480
- if (out) {
481
- if (isTargetingHTML) {
482
- out = createDOMProps(isTextView ? "span" : "div", out);
483
- delete out.className;
484
- }
484
+ }
485
+ if (name === "theme") {
486
+ inlined.set("theme", attr.value);
487
+ return attr;
488
+ }
489
+ const styleValue = attemptEvalSafe(value);
490
+ if (!variants[name] && !isValidStyleKey(name, staticConfig)) {
491
+ let keys = [name];
492
+ let out = null;
493
+ out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, { resolveVariablesAs: "auto" }, void 0, void 0, shouldPrintDebug);
494
+ if (out) {
495
+ if (!Array.isArray(out)) {
496
+ logger.warn(`Error expected array but got`, out);
497
+ couldntParse = true;
498
+ shouldDeopt = true;
499
+ } else {
500
+ out = Object.fromEntries(out);
485
501
  keys = Object.keys(out);
486
502
  }
487
- let didInline = false;
488
- const attributes = keys.map((key) => {
489
- const val = out[key];
490
- if (isValidStyleKey(key, staticConfig)) {
491
- return {
492
- type: "style",
493
- value: { [key]: styleValue },
494
- name: key,
495
- attr: path.node
496
- };
497
- }
498
- if (validHTMLAttributes[key] || key.startsWith("aria-") || key.startsWith("data-")) {
499
- return attr;
500
- }
501
- if (shouldPrintDebug) {
502
- console.log(" ! inlining, non-static", key);
503
- }
504
- didInline = true;
505
- inlined.set(key, val);
506
- return val;
507
- });
508
- if (didInline) {
509
- if (shouldPrintDebug) {
510
- console.log(" bailing flattening due to attributes", attributes);
511
- }
512
- return attr;
513
- }
514
- return attributes;
515
503
  }
516
- if (styleValue !== FAILED_EVAL) {
517
- if (inlineWhenUnflattened.has(name)) {
518
- inlineWhenUnflattenedOGVals[name] = { styleValue, attr };
504
+ if (out) {
505
+ if (isTargetingHTML) {
506
+ out = createDOMProps(isTextView ? "span" : "div", out);
507
+ delete out.className;
519
508
  }
520
- if (isValidStyleKey(name, staticConfig)) {
521
- if (shouldPrintDebug) {
522
- console.log(` style: ${name} =`, styleValue);
523
- }
524
- if (!(name in staticConfig.defaultProps)) {
525
- if (!hasSetOptimized) {
526
- res.optimized++;
527
- hasSetOptimized = true;
528
- }
529
- }
509
+ keys = Object.keys(out);
510
+ }
511
+ let didInline = false;
512
+ const attributes = keys.map((key) => {
513
+ const val = out[key];
514
+ if (isValidStyleKey(key, staticConfig)) {
530
515
  return {
531
516
  type: "style",
532
- value: { [name]: styleValue },
533
- name,
517
+ value: { [key]: styleValue },
518
+ name: key,
534
519
  attr: path.node
535
520
  };
536
- } else {
537
- if (variants[name]) {
538
- variantValues.set(name, styleValue);
539
- }
540
- inlined.set(name, true);
521
+ }
522
+ if (validHTMLAttributes[key] || key.startsWith("aria-") || key.startsWith("data-")) {
541
523
  return attr;
542
524
  }
543
- }
544
- if (t.isBinaryExpression(value)) {
545
525
  if (shouldPrintDebug) {
546
- console.log(` binary expression ${name} = `, value);
526
+ logger.info(" ! inlining, non-static " + key);
547
527
  }
548
- const { operator, left, right } = value;
549
- const lVal = attemptEvalSafe(left);
550
- const rVal = attemptEvalSafe(right);
528
+ didInline = true;
529
+ inlined.set(key, val);
530
+ return val;
531
+ });
532
+ if (didInline) {
551
533
  if (shouldPrintDebug) {
552
- console.log(` evalBinaryExpression lVal ${String(lVal)}, rVal ${String(rVal)}`);
534
+ logger.info(` bailing flattening due to attributes ${attributes}`);
553
535
  }
554
- if (lVal !== FAILED_EVAL && t.isConditionalExpression(right)) {
555
- const ternary = addBinaryConditional(operator, left, right);
556
- if (ternary)
557
- return ternary;
536
+ return attr;
537
+ }
538
+ return attributes;
539
+ }
540
+ if (styleValue !== FAILED_EVAL) {
541
+ if (inlineWhenUnflattened.has(name)) {
542
+ inlineWhenUnflattenedOGVals[name] = { styleValue, attr };
543
+ }
544
+ if (isValidStyleKey(name, staticConfig)) {
545
+ if (shouldPrintDebug) {
546
+ logger.info(` style: ${name} = ${styleValue}`);
558
547
  }
559
- if (rVal !== FAILED_EVAL && t.isConditionalExpression(left)) {
560
- const ternary = addBinaryConditional(operator, right, left);
561
- if (ternary)
562
- return ternary;
548
+ if (!(name in staticConfig.defaultProps)) {
549
+ if (!hasSetOptimized) {
550
+ res.optimized++;
551
+ hasSetOptimized = true;
552
+ }
563
553
  }
564
- if (shouldPrintDebug) {
565
- console.log(` evalBinaryExpression cant extract`);
554
+ return {
555
+ type: "style",
556
+ value: { [name]: styleValue },
557
+ name,
558
+ attr: path.node
559
+ };
560
+ } else {
561
+ if (variants[name]) {
562
+ variantValues.set(name, styleValue);
566
563
  }
567
564
  inlined.set(name, true);
568
565
  return attr;
569
566
  }
570
- const staticConditional = getStaticConditional(value);
571
- if (staticConditional) {
572
- if (shouldPrintDebug === "verbose") {
573
- console.log(` static conditional ${name}`, value);
574
- }
575
- return { type: "ternary", value: staticConditional };
567
+ }
568
+ if (t.isBinaryExpression(value)) {
569
+ if (shouldPrintDebug) {
570
+ logger.info(` binary expression ${name} = ${value}`);
576
571
  }
577
- const staticLogical = getStaticLogical(value);
578
- if (staticLogical) {
579
- if (shouldPrintDebug === "verbose") {
580
- console.log(` static ternary ${name} = `, value);
581
- }
582
- return { type: "ternary", value: staticLogical };
572
+ const { operator, left, right } = value;
573
+ const lVal = attemptEvalSafe(left);
574
+ const rVal = attemptEvalSafe(right);
575
+ if (shouldPrintDebug) {
576
+ logger.info(` evalBinaryExpression lVal ${String(lVal)}, rVal ${String(rVal)}`);
577
+ }
578
+ if (lVal !== FAILED_EVAL && t.isConditionalExpression(right)) {
579
+ const ternary = addBinaryConditional(operator, left, right);
580
+ if (ternary)
581
+ return ternary;
582
+ }
583
+ if (rVal !== FAILED_EVAL && t.isConditionalExpression(left)) {
584
+ const ternary = addBinaryConditional(operator, right, left);
585
+ if (ternary)
586
+ return ternary;
583
587
  }
584
- inlined.set(name, true);
585
588
  if (shouldPrintDebug) {
586
- console.log(` ! inline no match ${name}`, value);
589
+ logger.info(` evalBinaryExpression cant extract`);
587
590
  }
591
+ inlined.set(name, true);
588
592
  return attr;
589
- function addBinaryConditional(operator, staticExpr, cond) {
590
- if (getStaticConditional(cond)) {
591
- const alt = attemptEval(t.binaryExpression(operator, staticExpr, cond.alternate));
592
- const cons = attemptEval(t.binaryExpression(operator, staticExpr, cond.consequent));
593
+ }
594
+ const staticConditional = getStaticConditional(value);
595
+ if (staticConditional) {
596
+ if (shouldPrintDebug === "verbose") {
597
+ logger.info(` static conditional ${name} ${value}`);
598
+ }
599
+ return { type: "ternary", value: staticConditional };
600
+ }
601
+ const staticLogical = getStaticLogical(value);
602
+ if (staticLogical) {
603
+ if (shouldPrintDebug === "verbose") {
604
+ logger.info(` static ternary ${name} = ${value}`);
605
+ }
606
+ return { type: "ternary", value: staticLogical };
607
+ }
608
+ inlined.set(name, true);
609
+ if (shouldPrintDebug) {
610
+ logger.info(` ! inline no match ${name} ${value}`);
611
+ }
612
+ return attr;
613
+ function addBinaryConditional(operator, staticExpr, cond) {
614
+ if (getStaticConditional(cond)) {
615
+ const alt = attemptEval(t.binaryExpression(operator, staticExpr, cond.alternate));
616
+ const cons = attemptEval(t.binaryExpression(operator, staticExpr, cond.consequent));
617
+ if (shouldPrintDebug) {
618
+ logger.info([" binaryConditional", cond.test, cons, alt].join(" "));
619
+ }
620
+ return {
621
+ type: "ternary",
622
+ value: {
623
+ test: cond.test,
624
+ remove,
625
+ alternate: { [name]: alt },
626
+ consequent: { [name]: cons }
627
+ }
628
+ };
629
+ }
630
+ return null;
631
+ }
632
+ function getStaticConditional(value2) {
633
+ if (t.isConditionalExpression(value2)) {
634
+ try {
635
+ const aVal = attemptEval(value2.alternate);
636
+ const cVal = attemptEval(value2.consequent);
593
637
  if (shouldPrintDebug) {
594
- console.log(" binaryConditional", cond.test, cons, alt);
638
+ const type = value2.test.type;
639
+ logger.info([" static ternary", type, cVal, aVal].join(" "));
595
640
  }
596
641
  return {
597
- type: "ternary",
598
- value: {
599
- test: cond.test,
600
- remove,
601
- alternate: { [name]: alt },
602
- consequent: { [name]: cons }
603
- }
642
+ test: value2.test,
643
+ remove,
644
+ consequent: { [name]: cVal },
645
+ alternate: { [name]: aVal }
604
646
  };
647
+ } catch (err) {
648
+ if (shouldPrintDebug) {
649
+ logger.info([" cant eval ternary", err.message].join(" "));
650
+ }
605
651
  }
606
- return null;
607
652
  }
608
- function getStaticConditional(value2) {
609
- if (t.isConditionalExpression(value2)) {
653
+ return null;
654
+ }
655
+ function getStaticLogical(value2) {
656
+ if (t.isLogicalExpression(value2)) {
657
+ if (value2.operator === "&&") {
610
658
  try {
611
- const aVal = attemptEval(value2.alternate);
612
- const cVal = attemptEval(value2.consequent);
659
+ const val = attemptEval(value2.right);
613
660
  if (shouldPrintDebug) {
614
- const type = value2.test.type;
615
- console.log(" static ternary", type, cVal, aVal);
661
+ logger.info([" staticLogical", value2.left, name, val].join(" "));
616
662
  }
617
663
  return {
618
- test: value2.test,
664
+ test: value2.left,
619
665
  remove,
620
- consequent: { [name]: cVal },
621
- alternate: { [name]: aVal }
666
+ consequent: { [name]: val },
667
+ alternate: null
622
668
  };
623
669
  } catch (err) {
624
670
  if (shouldPrintDebug) {
625
- console.log(" cant eval ternary", err.message);
671
+ logger.info([" cant static eval logical", err].join(" "));
626
672
  }
627
673
  }
628
674
  }
629
- return null;
630
675
  }
631
- function getStaticLogical(value2) {
632
- if (t.isLogicalExpression(value2)) {
633
- if (value2.operator === "&&") {
634
- try {
635
- const val = attemptEval(value2.right);
636
- if (shouldPrintDebug) {
637
- console.log(" staticLogical", value2.left, name, val);
638
- }
639
- return {
640
- test: value2.left,
641
- remove,
642
- consequent: { [name]: val },
643
- alternate: null
644
- };
645
- } catch (err) {
646
- if (shouldPrintDebug) {
647
- console.log(" cant static eval logical", err);
648
- }
649
- }
650
- }
651
- }
652
- return null;
676
+ return null;
677
+ }
678
+ }, isExtractable2 = function(obj) {
679
+ return t.isObjectExpression(obj) && obj.properties.every((prop) => {
680
+ if (!t.isObjectProperty(prop)) {
681
+ logger.info(["not object prop", prop].join(" "));
682
+ return false;
653
683
  }
654
- }, isExtractable2 = function(obj) {
655
- return t.isObjectExpression(obj) && obj.properties.every((prop) => {
656
- if (!t.isObjectProperty(prop)) {
657
- console.log("not object prop", prop);
658
- return false;
659
- }
660
- const propName = prop.key["name"];
661
- if (!isValidStyleKey(propName, staticConfig) && propName !== "tag") {
662
- if (shouldPrintDebug) {
663
- console.log(" not a valid style prop!", propName);
664
- }
665
- return false;
684
+ const propName = prop.key["name"];
685
+ if (!isValidStyleKey(propName, staticConfig) && propName !== "tag") {
686
+ if (shouldPrintDebug) {
687
+ logger.info([" not a valid style prop!", propName].join(" "));
666
688
  }
667
- return true;
668
- });
669
- }, createTernariesFromObjectProperties2 = function(test, side, ternaryPartial = {}) {
670
- if (!side) {
671
- return null;
689
+ return false;
672
690
  }
673
- if (!isExtractable2(side)) {
674
- throw new Error("not extractable");
691
+ return true;
692
+ });
693
+ }, createTernariesFromObjectProperties2 = function(test, side, ternaryPartial = {}) {
694
+ if (!side) {
695
+ return null;
696
+ }
697
+ if (!isExtractable2(side)) {
698
+ throw new Error("not extractable");
699
+ }
700
+ return side.properties.flatMap((property) => {
701
+ if (!t.isObjectProperty(property)) {
702
+ throw new Error("expected object property");
675
703
  }
676
- return side.properties.flatMap((property) => {
677
- if (!t.isObjectProperty(property)) {
678
- throw new Error("expected object property");
679
- }
680
- if (t.isIdentifier(property.key)) {
681
- const key = property.key.name;
682
- const mediaQueryKey = key.slice(1);
683
- const isMediaQuery = key[0] === "$" && mediaQueryConfig[mediaQueryKey];
684
- if (isMediaQuery) {
685
- if (t.isExpression(property.value)) {
686
- const ternaries2 = createTernariesFromObjectProperties2(t.stringLiteral(mediaQueryKey), property.value, {
687
- inlineMediaQuery: mediaQueryKey
688
- });
689
- if (ternaries2) {
690
- return ternaries2.map((value) => ({
691
- ...ternaryPartial,
692
- ...value,
693
- test: t.logicalExpression("&&", value.test, test)
694
- }));
695
- } else {
696
- console.log("\u26A0\uFE0F no ternaries?", property);
697
- }
704
+ if (t.isIdentifier(property.key)) {
705
+ const key = property.key.name;
706
+ const mediaQueryKey = key.slice(1);
707
+ const isMediaQuery = key[0] === "$" && mediaQueryConfig[mediaQueryKey];
708
+ if (isMediaQuery) {
709
+ if (t.isExpression(property.value)) {
710
+ const ternaries2 = createTernariesFromObjectProperties2(t.stringLiteral(mediaQueryKey), property.value, {
711
+ inlineMediaQuery: mediaQueryKey
712
+ });
713
+ if (ternaries2) {
714
+ return ternaries2.map((value) => ({
715
+ ...ternaryPartial,
716
+ ...value,
717
+ test: t.logicalExpression("&&", value.test, test)
718
+ }));
698
719
  } else {
699
- console.log("\u26A0\uFE0F not expression", property);
720
+ logger.info(["\u26A0\uFE0F no ternaries?", property].join(" "));
700
721
  }
722
+ } else {
723
+ logger.info(["\u26A0\uFE0F not expression", property].join(" "));
701
724
  }
702
725
  }
703
- if (t.isConditionalExpression(property.value)) {
704
- const [truthy, falsy] = [
705
- t.objectExpression([t.objectProperty(property.key, property.value.consequent)]),
706
- t.objectExpression([t.objectProperty(property.key, property.value.alternate)])
707
- ].map((x) => attemptEval(x));
708
- return [
709
- createTernary({
710
- remove() {
711
- },
712
- ...ternaryPartial,
713
- test: t.logicalExpression("&&", test, property.value.test),
714
- consequent: truthy,
715
- alternate: null
716
- }),
717
- createTernary({
718
- ...ternaryPartial,
719
- test: t.logicalExpression("&&", test, t.unaryExpression("!", property.value.test)),
720
- consequent: falsy,
721
- alternate: null,
722
- remove() {
723
- }
724
- })
725
- ];
726
- }
727
- const obj = t.objectExpression([t.objectProperty(property.key, property.value)]);
728
- const consequent = attemptEval(obj);
729
- return createTernary({
730
- remove() {
731
- },
732
- ...ternaryPartial,
733
- test,
734
- consequent,
735
- alternate: null
736
- });
737
- });
738
- }, splitVariants2 = function(style) {
739
- var _a2;
740
- const variants2 = {};
741
- const styles = {};
742
- for (const key in style) {
743
- if ((_a2 = staticConfig.variants) == null ? void 0 : _a2[key]) {
744
- variants2[key] = style[key];
745
- } else {
746
- styles[key] = style[key];
747
- }
748
726
  }
749
- return {
750
- variants: variants2,
751
- styles
752
- };
753
- }, expandStylesWithoutVariants2 = function(style) {
754
- const { variants: variants2, styles } = splitVariants2(style);
755
- return {
756
- ...expandStyles(styles),
757
- ...variants2
758
- };
759
- }, mergeStyles2 = function(prev2, nextIn) {
760
- const next = expandStylesWithoutVariants2(nextIn);
761
- for (const key in next) {
762
- if (pseudoDescriptors[key]) {
763
- prev2[key] = prev2[key] || {};
764
- if (shouldPrintDebug) {
765
- if (!next[key] || !prev2[key]) {
766
- console.log("warn: missing", key, prev2, next);
727
+ if (t.isConditionalExpression(property.value)) {
728
+ const [truthy, falsy] = [
729
+ t.objectExpression([t.objectProperty(property.key, property.value.consequent)]),
730
+ t.objectExpression([t.objectProperty(property.key, property.value.alternate)])
731
+ ].map((x) => attemptEval(x));
732
+ return [
733
+ createTernary({
734
+ remove() {
735
+ },
736
+ ...ternaryPartial,
737
+ test: t.logicalExpression("&&", test, property.value.test),
738
+ consequent: truthy,
739
+ alternate: null
740
+ }),
741
+ createTernary({
742
+ ...ternaryPartial,
743
+ test: t.logicalExpression("&&", test, t.unaryExpression("!", property.value.test)),
744
+ consequent: falsy,
745
+ alternate: null,
746
+ remove() {
767
747
  }
768
- }
769
- Object.assign(prev2[key], next[key]);
770
- } else {
771
- prev2[key] = next[key];
772
- }
748
+ })
749
+ ];
773
750
  }
774
- };
775
- var evaluateAttribute = evaluateAttribute2, isExtractable = isExtractable2, createTernariesFromObjectProperties = createTernariesFromObjectProperties2, splitVariants = splitVariants2, expandStylesWithoutVariants = expandStylesWithoutVariants2, mergeStyles = mergeStyles2;
776
- const { staticConfig } = component;
777
- const variants = staticConfig.variants || {};
778
- const isTextView = staticConfig.isText || false;
779
- const validStyles = (_a = staticConfig == null ? void 0 : staticConfig.validStyles) != null ? _a : {};
780
- let tagName = (_b = staticConfig.defaultProps.tag) != null ? _b : isTextView ? "span" : "div";
781
- traversePath.get("openingElement").get("attributes").forEach((path) => {
782
- const attr = path.node;
783
- if (t.isJSXSpreadAttribute(attr))
784
- return;
785
- if (attr.name.name !== "tag")
786
- return;
787
- const val = attr.value;
788
- if (!t.isStringLiteral(val))
789
- return;
790
- tagName = val.value;
791
- });
792
- const flatNode = getFlattenedNode({ isTextView, tag: tagName });
793
- const inlineProps = /* @__PURE__ */ new Set([
794
- ...props.inlineProps || [],
795
- ...staticConfig.inlineProps || []
796
- ]);
797
- const deoptProps = /* @__PURE__ */ new Set([
798
- "animation",
799
- ...props.deoptProps || [],
800
- ...staticConfig.deoptProps || []
801
- ]);
802
- const inlineWhenUnflattened = /* @__PURE__ */ new Set([...staticConfig.inlineWhenUnflattened || []]);
803
- const staticNamespace = getStaticBindingsForScope(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
804
- const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
805
- tamaguiConfig,
806
- staticNamespace,
807
- sourcePath,
808
- traversePath,
809
- shouldPrintDebug
751
+ const obj = t.objectExpression([t.objectProperty(property.key, property.value)]);
752
+ const consequent = attemptEval(obj);
753
+ return createTernary({
754
+ remove() {
755
+ },
756
+ ...ternaryPartial,
757
+ test,
758
+ consequent,
759
+ alternate: null
760
+ });
810
761
  });
811
- const attemptEvalSafe = createSafeEvaluator(attemptEval);
812
- if (shouldPrintDebug) {
813
- console.log(" staticNamespace", Object.keys(staticNamespace).join(", "));
814
- }
815
- const flattenedAttrs = [];
816
- traversePath.get("openingElement").get("attributes").forEach((path) => {
817
- const attr = path.node;
818
- if (!t.isJSXSpreadAttribute(attr)) {
819
- flattenedAttrs.push(attr);
820
- return;
762
+ }, splitVariants2 = function(style) {
763
+ const variants2 = {};
764
+ const styles = {};
765
+ for (const key in style) {
766
+ if (staticConfig.variants?.[key]) {
767
+ variants2[key] = style[key];
768
+ } else {
769
+ styles[key] = style[key];
821
770
  }
822
- let arg;
823
- try {
824
- arg = attemptEval(attr.argument);
825
- } catch (e) {
771
+ }
772
+ return {
773
+ variants: variants2,
774
+ styles
775
+ };
776
+ }, expandStylesWithoutVariants2 = function(style) {
777
+ const { variants: variants2, styles } = splitVariants2(style);
778
+ return {
779
+ ...expandStyles(styles),
780
+ ...variants2
781
+ };
782
+ }, mergeStyles2 = function(prev2, nextIn) {
783
+ const next = expandStylesWithoutVariants2(nextIn);
784
+ for (const key in next) {
785
+ if (pseudoDescriptors[key]) {
786
+ prev2[key] = prev2[key] || {};
826
787
  if (shouldPrintDebug) {
827
- console.log(" couldnt parse spread", e.message);
828
- }
829
- flattenedAttrs.push(attr);
830
- return;
831
- }
832
- if (arg !== void 0) {
833
- try {
834
- if (typeof arg !== "object" || arg == null) {
835
- if (shouldPrintDebug) {
836
- console.log(" non object or null arg", arg);
837
- }
838
- flattenedAttrs.push(attr);
839
- } else {
840
- for (const k in arg) {
841
- const value = arg[k];
842
- if (!value && typeof value === "object") {
843
- console.log("shouldnt we handle this?", k, value, arg);
844
- continue;
845
- }
846
- flattenedAttrs.push(t.jsxAttribute(t.jsxIdentifier(k), t.jsxExpressionContainer(literalToAst(value))));
847
- }
788
+ if (!next[key] || !prev2[key]) {
789
+ logger.info(["warn: missing", key, prev2, next].join(" "));
848
790
  }
849
- } catch (err) {
850
- console.warn("cant parse spread, caught err", err);
851
- couldntParse = true;
852
791
  }
792
+ Object.assign(prev2[key], next[key]);
793
+ } else {
794
+ prev2[key] = next[key];
853
795
  }
854
- });
855
- if (couldntParse) {
856
- return;
857
796
  }
858
- tm.mark("jsx-element-flattened", shouldPrintDebug === "verbose");
859
- node.attributes = flattenedAttrs;
860
- let attrs = [];
861
- let shouldDeopt = false;
862
- const inlined = /* @__PURE__ */ new Map();
863
- const variantValues = /* @__PURE__ */ new Map();
864
- let hasSetOptimized = false;
865
- const inlineWhenUnflattenedOGVals = {};
866
- attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
867
- try {
868
- const res2 = evaluateAttribute2(path);
869
- tm.mark("jsx-element-evaluate-attr", shouldPrintDebug === "verbose");
870
- if (!res2) {
871
- path.remove();
872
- }
873
- return res2;
874
- } catch (err) {
875
- if (shouldPrintDebug) {
876
- console.log("Error extracting attribute", err.message, err.stack);
877
- console.log("node", path.node);
878
- }
879
- inlined.set(`${Math.random()}`, "spread");
880
- return {
881
- type: "attr",
882
- value: path.node
883
- };
884
- }
885
- }).flat(4).filter(isPresent);
886
- if (shouldPrintDebug) {
887
- console.log(" - attrs (before):\n", logLines(attrs.map(attrStr).join(", ")));
797
+ };
798
+ var evaluateAttribute = evaluateAttribute2, isExtractable = isExtractable2, createTernariesFromObjectProperties = createTernariesFromObjectProperties2, splitVariants = splitVariants2, expandStylesWithoutVariants = expandStylesWithoutVariants2, mergeStyles = mergeStyles2;
799
+ const { staticConfig } = component;
800
+ const variants = staticConfig.variants || {};
801
+ const isTextView = staticConfig.isText || false;
802
+ const validStyles = staticConfig?.validStyles ?? {};
803
+ let tagName = staticConfig.defaultProps.tag ?? (isTextView ? "span" : "div");
804
+ traversePath.get("openingElement").get("attributes").forEach((path) => {
805
+ const attr = path.node;
806
+ if (t.isJSXSpreadAttribute(attr))
807
+ return;
808
+ if (attr.name.name !== "tag")
809
+ return;
810
+ const val = attr.value;
811
+ if (!t.isStringLiteral(val))
812
+ return;
813
+ tagName = val.value;
814
+ });
815
+ const flatNode = getFlattenedNode({ isTextView, tag: tagName });
816
+ const inlineProps = /* @__PURE__ */ new Set([
817
+ ...props.inlineProps || [],
818
+ ...staticConfig.inlineProps || []
819
+ ]);
820
+ const deoptProps = /* @__PURE__ */ new Set([
821
+ "animation",
822
+ ...props.deoptProps || [],
823
+ ...staticConfig.deoptProps || []
824
+ ]);
825
+ const inlineWhenUnflattened = /* @__PURE__ */ new Set([...staticConfig.inlineWhenUnflattened || []]);
826
+ const staticNamespace = getStaticBindingsForScope(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
827
+ const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
828
+ tamaguiConfig,
829
+ staticNamespace,
830
+ sourcePath,
831
+ traversePath,
832
+ shouldPrintDebug
833
+ });
834
+ const attemptEvalSafe = createSafeEvaluator(attemptEval);
835
+ if (shouldPrintDebug) {
836
+ logger.info(` staticNamespace ${Object.keys(staticNamespace).join(", ")}`);
837
+ }
838
+ const flattenedAttrs = [];
839
+ traversePath.get("openingElement").get("attributes").forEach((path) => {
840
+ const attr = path.node;
841
+ if (!t.isJSXSpreadAttribute(attr)) {
842
+ flattenedAttrs.push(attr);
843
+ return;
888
844
  }
889
- node.attributes = attrs.filter(isAttr).map((x) => x.value);
890
- if (couldntParse || shouldDeopt) {
845
+ let arg;
846
+ try {
847
+ arg = attemptEval(attr.argument);
848
+ } catch (e) {
891
849
  if (shouldPrintDebug) {
892
- console.log(` avoid optimizing:`, { couldntParse, shouldDeopt });
850
+ logger.info([" couldnt parse spread", e.message].join(" "));
893
851
  }
894
- node.attributes = ogAttributes;
852
+ flattenedAttrs.push(attr);
895
853
  return;
896
854
  }
897
- const parentFn = findTopmostFunction(traversePath);
898
- if (parentFn) {
899
- modifiedComponents.add(parentFn);
900
- }
901
- let ternaries = [];
902
- attrs = attrs.reduce((out, cur) => {
903
- const next = attrs[attrs.indexOf(cur) + 1];
904
- if (cur.type === "ternary") {
905
- ternaries.push(cur.value);
906
- }
907
- if ((!next || next.type !== "ternary") && ternaries.length) {
908
- const normalized = normalizeTernaries(ternaries).map(({ alternate, consequent, ...rest }) => {
909
- return {
910
- type: "ternary",
911
- value: {
912
- ...rest,
913
- alternate: alternate || null,
914
- consequent: consequent || null
915
- }
916
- };
917
- });
918
- try {
919
- return [...out, ...normalized];
920
- } finally {
855
+ if (arg !== void 0) {
856
+ try {
857
+ if (typeof arg !== "object" || arg == null) {
921
858
  if (shouldPrintDebug) {
922
- console.log(` normalizeTernaries (${ternaries.length} => ${normalized.length})`);
859
+ logger.info([" non object or null arg", arg].join(" "));
860
+ }
861
+ flattenedAttrs.push(attr);
862
+ } else {
863
+ for (const k in arg) {
864
+ const value = arg[k];
865
+ if (!value && typeof value === "object") {
866
+ logger.error(["Unhandled null prop", k, value, arg].join(" "));
867
+ continue;
868
+ }
869
+ flattenedAttrs.push(t.jsxAttribute(t.jsxIdentifier(k), t.jsxExpressionContainer(literalToAst(value))));
923
870
  }
924
- ternaries = [];
925
871
  }
872
+ } catch (err) {
873
+ logger.warn(`cant parse spread, caught err ${err}`);
874
+ couldntParse = true;
926
875
  }
927
- if (cur.type === "ternary") {
928
- return out;
876
+ }
877
+ });
878
+ if (couldntParse) {
879
+ return;
880
+ }
881
+ tm.mark("jsx-element-flattened", !!shouldPrintDebug);
882
+ node.attributes = flattenedAttrs;
883
+ let attrs = [];
884
+ let shouldDeopt = false;
885
+ const inlined = /* @__PURE__ */ new Map();
886
+ const variantValues = /* @__PURE__ */ new Map();
887
+ let hasSetOptimized = false;
888
+ const inlineWhenUnflattenedOGVals = {};
889
+ attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
890
+ try {
891
+ const res2 = evaluateAttribute2(path);
892
+ tm.mark("jsx-element-evaluate-attr", !!shouldPrintDebug);
893
+ if (!res2) {
894
+ path.remove();
929
895
  }
930
- out.push(cur);
931
- return out;
932
- }, []).flat();
933
- const hasSpread = node.attributes.some((x) => t.isJSXSpreadAttribute(x));
934
- const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
935
- const themeVal = inlined.get("theme");
936
- inlined.delete("theme");
937
- for (const [key] of [...inlined]) {
938
- const isExtractableVariant = ((_c = staticConfig.variants) == null ? void 0 : _c[key]) && variantValues.has(key);
939
- if (INLINE_EXTRACTABLE[key] || isExtractableVariant) {
940
- inlined.delete(key);
896
+ return res2;
897
+ } catch (err) {
898
+ if (shouldPrintDebug) {
899
+ logger.info(["Error extracting attribute", err.message, err.stack].join(" "));
900
+ logger.info(`node ${path.node}`);
941
901
  }
902
+ inlined.set(`${Math.random()}`, "spread");
903
+ return {
904
+ type: "attr",
905
+ value: path.node
906
+ };
942
907
  }
943
- const canFlattenProps = inlined.size === 0;
944
- let shouldFlatten = !shouldDeopt && canFlattenProps && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
945
- const shouldWrapTheme = shouldFlatten && themeVal;
946
- if (disableExtractVariables) {
947
- themeAccessListeners.add((key) => {
948
- shouldFlatten = false;
908
+ }).flat(4).filter(isPresent);
909
+ if (shouldPrintDebug) {
910
+ logger.info([" - attrs (before):\n", logLines(attrs.map(attrStr).join(", "))].join(" "));
911
+ }
912
+ node.attributes = attrs.filter(isAttr).map((x) => x.value);
913
+ if (couldntParse || shouldDeopt) {
914
+ if (shouldPrintDebug) {
915
+ logger.info([` avoid optimizing:`, { couldntParse, shouldDeopt }].join(" "));
916
+ }
917
+ node.attributes = ogAttributes;
918
+ return;
919
+ }
920
+ const parentFn = findTopmostFunction(traversePath);
921
+ if (parentFn) {
922
+ modifiedComponents.add(parentFn);
923
+ }
924
+ let ternaries = [];
925
+ attrs = attrs.reduce((out, cur) => {
926
+ const next = attrs[attrs.indexOf(cur) + 1];
927
+ if (cur.type === "ternary") {
928
+ ternaries.push(cur.value);
929
+ }
930
+ if ((!next || next.type !== "ternary") && ternaries.length) {
931
+ const normalized = normalizeTernaries(ternaries).map(({ alternate, consequent, ...rest }) => {
932
+ return {
933
+ type: "ternary",
934
+ value: {
935
+ ...rest,
936
+ alternate: alternate || null,
937
+ consequent: consequent || null
938
+ }
939
+ };
940
+ });
941
+ try {
942
+ return [...out, ...normalized];
943
+ } finally {
949
944
  if (shouldPrintDebug) {
950
- console.log(" ! accessing theme key, avoid flatten", key);
945
+ logger.info(` normalizeTernaries (${ternaries.length} => ${normalized.length})`);
951
946
  }
952
- });
947
+ ternaries = [];
948
+ }
953
949
  }
954
- if (shouldPrintDebug) {
955
- console.log(" - flatten?", objToStr({ hasSpread, shouldDeopt, shouldFlatten, canFlattenProps, shouldWrapTheme, hasOnlyStringChildren }), "inlined", [...inlined]);
950
+ if (cur.type === "ternary") {
951
+ return out;
956
952
  }
957
- if (shouldFlatten && shouldWrapTheme) {
953
+ out.push(cur);
954
+ return out;
955
+ }, []).flat();
956
+ const hasSpread = node.attributes.some((x) => t.isJSXSpreadAttribute(x));
957
+ const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
958
+ const themeVal = inlined.get("theme");
959
+ inlined.delete("theme");
960
+ for (const [key] of [...inlined]) {
961
+ const isExtractableVariant = staticConfig.variants?.[key] && variantValues.has(key);
962
+ if (INLINE_EXTRACTABLE[key] || isExtractableVariant) {
963
+ inlined.delete(key);
964
+ }
965
+ }
966
+ const canFlattenProps = inlined.size === 0;
967
+ let shouldFlatten = !shouldDeopt && canFlattenProps && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
968
+ const shouldWrapTheme = shouldFlatten && themeVal;
969
+ if (disableExtractVariables) {
970
+ themeAccessListeners.add((key) => {
971
+ shouldFlatten = false;
958
972
  if (shouldPrintDebug) {
959
- console.log(" - wrapping theme", themeVal);
960
- }
961
- attrs = attrs.filter((x) => x.type === "attr" && t.isJSXAttribute(x.value) && x.value.name.name === "theme" ? false : true);
962
- if (!hasImportedTheme) {
963
- hasImportedTheme = true;
964
- programPath.node.body.push(t.importDeclaration([t.importSpecifier(t.identifier("_TamaguiTheme"), t.identifier("Theme"))], t.stringLiteral("@tamagui/core")));
973
+ logger.info([" ! accessing theme key, avoid flatten", key].join(" "));
965
974
  }
966
- traversePath.replaceWith(t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier("_TamaguiTheme"), [
967
- t.jsxAttribute(t.jsxIdentifier("name"), themeVal.value)
968
- ]), t.jsxClosingElement(t.jsxIdentifier("_TamaguiTheme")), [traversePath.node]));
975
+ });
976
+ }
977
+ if (shouldPrintDebug) {
978
+ logger.info([" - flatten?", objToStr({ hasSpread, shouldDeopt, shouldFlatten, canFlattenProps, shouldWrapTheme, hasOnlyStringChildren }), "inlined", [...inlined]].join(" "));
979
+ }
980
+ if (shouldFlatten && shouldWrapTheme) {
981
+ if (shouldPrintDebug) {
982
+ logger.info([" - wrapping theme", themeVal].join(" "));
969
983
  }
970
- if (shouldFlatten) {
971
- const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap((key) => {
972
- if (!isValidStyleKey(key, staticConfig)) {
973
- return [];
974
- }
975
- const value = staticConfig.defaultProps[key];
976
- const name = tamaguiConfig.shorthands[key] || key;
977
- if (value === void 0) {
978
- console.warn(`\u26A0\uFE0F Error evaluating default style for component, prop ${key} ${value}`);
979
- shouldDeopt = true;
980
- return;
981
- }
982
- const attr = {
983
- type: "style",
984
- name,
985
- value: { [name]: value }
986
- };
987
- return attr;
988
- });
989
- if (defaultStyleAttrs.length) {
990
- attrs = [...defaultStyleAttrs, ...attrs];
991
- }
984
+ attrs = attrs.filter((x) => x.type === "attr" && t.isJSXAttribute(x.value) && x.value.name.name === "theme" ? false : true);
985
+ if (!hasImportedTheme) {
986
+ hasImportedTheme = true;
987
+ programPath.node.body.push(t.importDeclaration([t.importSpecifier(t.identifier("_TamaguiTheme"), t.identifier("Theme"))], t.stringLiteral("@tamagui/core")));
992
988
  }
993
- if (shouldDeopt) {
994
- node.attributes = ogAttributes;
995
- return;
989
+ traversePath.replaceWith(t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier("_TamaguiTheme"), [
990
+ t.jsxAttribute(t.jsxIdentifier("name"), themeVal.value)
991
+ ]), t.jsxClosingElement(t.jsxIdentifier("_TamaguiTheme")), [traversePath.node]));
992
+ }
993
+ if (shouldFlatten) {
994
+ const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap((key) => {
995
+ if (!isValidStyleKey(key, staticConfig)) {
996
+ return [];
997
+ }
998
+ const value = staticConfig.defaultProps[key];
999
+ const name = tamaguiConfig.shorthands[key] || key;
1000
+ if (value === void 0) {
1001
+ logger.warn(`\u26A0\uFE0F Error evaluating default style for component, prop ${key} ${value}`);
1002
+ shouldDeopt = true;
1003
+ return;
1004
+ }
1005
+ const attr = {
1006
+ type: "style",
1007
+ name,
1008
+ value: { [name]: value }
1009
+ };
1010
+ return attr;
1011
+ });
1012
+ if (defaultStyleAttrs.length) {
1013
+ attrs = [...defaultStyleAttrs, ...attrs];
996
1014
  }
997
- const ensureOverridden = {};
998
- if (!shouldFlatten) {
999
- for (const cur of attrs) {
1000
- if (cur.type === "style") {
1001
- for (const key in cur.value) {
1002
- const shouldEnsureOverridden = !!((_d = staticConfig.ensureOverriddenProp) == null ? void 0 : _d[key]);
1003
- const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
1004
- if (!isSetInAttrsAlready) {
1005
- const isVariant = !!((_e = staticConfig.variants) == null ? void 0 : _e[cur.name || ""]);
1006
- if (isVariant || shouldEnsureOverridden) {
1007
- ensureOverridden[key] = true;
1008
- }
1015
+ }
1016
+ if (shouldDeopt) {
1017
+ node.attributes = ogAttributes;
1018
+ return;
1019
+ }
1020
+ const ensureOverridden = {};
1021
+ if (!shouldFlatten) {
1022
+ for (const cur of attrs) {
1023
+ if (cur.type === "style") {
1024
+ for (const key in cur.value) {
1025
+ const shouldEnsureOverridden = !!staticConfig.ensureOverriddenProp?.[key];
1026
+ const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
1027
+ if (!isSetInAttrsAlready) {
1028
+ const isVariant = !!staticConfig.variants?.[cur.name || ""];
1029
+ if (isVariant || shouldEnsureOverridden) {
1030
+ ensureOverridden[key] = true;
1009
1031
  }
1010
1032
  }
1011
1033
  }
1012
1034
  }
1013
1035
  }
1014
- if (shouldPrintDebug) {
1015
- console.log(" - attrs (flattened): \n", logLines(attrs.map(attrStr).join(", ")));
1016
- console.log(" - ensureOverriden:", Object.keys(ensureOverridden).join(", "));
1036
+ }
1037
+ if (shouldPrintDebug) {
1038
+ logger.info([" - attrs (flattened): \n", logLines(attrs.map(attrStr).join(", "))].join(" "));
1039
+ logger.info([" - ensureOverriden:", Object.keys(ensureOverridden).join(", ")].join(" "));
1040
+ }
1041
+ const state = {
1042
+ noClassNames: false,
1043
+ focus: false,
1044
+ hover: false,
1045
+ mounted: true,
1046
+ press: false,
1047
+ pressIn: false
1048
+ };
1049
+ let foundStaticProps = {};
1050
+ for (const key in attrs) {
1051
+ const cur = attrs[key];
1052
+ if (cur.type === "style") {
1053
+ foundStaticProps = {
1054
+ ...foundStaticProps,
1055
+ ...expandStylesWithoutVariants2(cur.value)
1056
+ };
1057
+ continue;
1017
1058
  }
1018
- const state = {
1019
- noClassNames: false,
1020
- focus: false,
1021
- hover: false,
1022
- mounted: true,
1023
- press: false,
1024
- pressIn: false
1025
- };
1026
- let foundStaticProps = {};
1027
- for (const key in attrs) {
1028
- const cur = attrs[key];
1029
- if (cur.type === "style") {
1030
- foundStaticProps = {
1031
- ...foundStaticProps,
1032
- ...expandStylesWithoutVariants2(cur.value)
1033
- };
1059
+ if (cur.type === "attr") {
1060
+ if (t.isJSXSpreadAttribute(cur.value)) {
1034
1061
  continue;
1035
1062
  }
1036
- if (cur.type === "attr") {
1037
- if (t.isJSXSpreadAttribute(cur.value)) {
1038
- continue;
1039
- }
1040
- if (!t.isJSXIdentifier(cur.value.name)) {
1041
- continue;
1042
- }
1043
- const key2 = cur.value.name.name;
1044
- const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
1045
- if (value !== FAILED_EVAL) {
1046
- foundStaticProps = {
1047
- ...foundStaticProps,
1048
- [key2]: value
1049
- };
1050
- }
1063
+ if (!t.isJSXIdentifier(cur.value.name)) {
1064
+ continue;
1051
1065
  }
1052
- }
1053
- const completeProps = {};
1054
- for (const key in staticConfig.defaultProps) {
1055
- if (!(key in foundStaticProps)) {
1056
- completeProps[key] = staticConfig.defaultProps[key];
1066
+ const key2 = cur.value.name.name;
1067
+ const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
1068
+ if (value !== FAILED_EVAL) {
1069
+ foundStaticProps = {
1070
+ ...foundStaticProps,
1071
+ [key2]: value
1072
+ };
1057
1073
  }
1058
1074
  }
1059
- for (const key in foundStaticProps) {
1060
- completeProps[key] = foundStaticProps[key];
1075
+ }
1076
+ const completeProps = {};
1077
+ for (const key in staticConfig.defaultProps) {
1078
+ if (!(key in foundStaticProps)) {
1079
+ completeProps[key] = staticConfig.defaultProps[key];
1061
1080
  }
1062
- attrs = attrs.reduce((acc, cur) => {
1063
- if (!cur)
1064
- return acc;
1065
- if (cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value)) {
1066
- if (shouldFlatten) {
1067
- const name = cur.value.name.name;
1068
- if (typeof name === "string") {
1069
- if (name === "tag") {
1070
- return acc;
1081
+ }
1082
+ for (const key in foundStaticProps) {
1083
+ completeProps[key] = foundStaticProps[key];
1084
+ }
1085
+ attrs = attrs.reduce((acc, cur) => {
1086
+ if (!cur)
1087
+ return acc;
1088
+ if (cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value)) {
1089
+ if (shouldFlatten) {
1090
+ const name = cur.value.name.name;
1091
+ if (typeof name === "string") {
1092
+ if (name === "tag") {
1093
+ return acc;
1094
+ }
1095
+ if (variants[name] && variantValues.has(name)) {
1096
+ let out = Object.fromEntries(staticConfig.propMapper(name, variantValues.get(name), defaultTheme, completeProps, { ...state, resolveVariablesAs: "auto" }, void 0, void 0, shouldPrintDebug) || []);
1097
+ if (out && isTargetingHTML) {
1098
+ const cn = out.className;
1099
+ out = createDOMProps(isTextView ? "span" : "div", out);
1100
+ out.className = cn;
1071
1101
  }
1072
- if (variants[name] && variantValues.has(name)) {
1073
- let out = Object.fromEntries(staticConfig.propMapper(name, variantValues.get(name), defaultTheme, completeProps, { ...state, resolveVariablesAs: "auto" }, void 0, void 0, shouldPrintDebug) || []);
1074
- if (out && isTargetingHTML) {
1075
- const cn = out.className;
1076
- out = createDOMProps(isTextView ? "span" : "div", out);
1077
- out.className = cn;
1078
- }
1079
- if (shouldPrintDebug) {
1080
- console.log(" - expanded variant", name, out);
1081
- }
1082
- for (const key2 in out) {
1083
- const value2 = out[key2];
1084
- if (isValidStyleKey(key2, staticConfig)) {
1085
- acc.push({
1086
- type: "style",
1087
- value: { [key2]: value2 },
1088
- name: key2,
1089
- attr: cur.value
1090
- });
1091
- } else {
1092
- acc.push({
1093
- type: "attr",
1094
- value: t.jsxAttribute(t.jsxIdentifier(key2), t.jsxExpressionContainer(typeof value2 === "string" ? t.stringLiteral(value2) : literalToAst(value2)))
1095
- });
1096
- }
1102
+ if (shouldPrintDebug) {
1103
+ logger.info([" - expanded variant", name, out].join(" "));
1104
+ }
1105
+ for (const key2 in out) {
1106
+ const value2 = out[key2];
1107
+ if (isValidStyleKey(key2, staticConfig)) {
1108
+ acc.push({
1109
+ type: "style",
1110
+ value: { [key2]: value2 },
1111
+ name: key2,
1112
+ attr: cur.value
1113
+ });
1114
+ } else {
1115
+ acc.push({
1116
+ type: "attr",
1117
+ value: t.jsxAttribute(t.jsxIdentifier(key2), t.jsxExpressionContainer(typeof value2 === "string" ? t.stringLiteral(value2) : literalToAst(value2)))
1118
+ });
1097
1119
  }
1098
1120
  }
1099
1121
  }
1100
1122
  }
1101
1123
  }
1102
- if (cur.type !== "style") {
1103
- acc.push(cur);
1104
- return acc;
1105
- }
1106
- let key = Object.keys(cur.value)[0];
1107
- const value = cur.value[key];
1108
- const fullKey = tamaguiConfig.shorthands[key];
1109
- if (fullKey) {
1110
- cur.value = { [fullKey]: value };
1111
- key = fullKey;
1112
- }
1113
- if (disableExtractVariables) {
1114
- if (value[0] === "$") {
1115
- if (shouldPrintDebug) {
1116
- console.log(` keeping variable inline: ${key} =`, value);
1117
- }
1118
- acc.push({
1119
- type: "attr",
1120
- value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.stringLiteral(value)))
1121
- });
1122
- return acc;
1123
- }
1124
- }
1124
+ }
1125
+ if (cur.type !== "style") {
1125
1126
  acc.push(cur);
1126
1127
  return acc;
1127
- }, []);
1128
- tm.mark("jsx-element-expanded", shouldPrintDebug === "verbose");
1129
- if (shouldPrintDebug) {
1130
- console.log(" - attrs (expanded): \n", logLines(attrs.map(attrStr).join(", ")));
1131
1128
  }
1132
- let prev = null;
1133
- attrs = attrs.reduce((acc, cur) => {
1134
- if (cur.type === "style") {
1135
- const key = Object.keys(cur.value)[0];
1136
- const value = cur.value[key];
1137
- const shouldKeepOriginalAttr = !shouldFlatten && !validStyles[key] && !pseudoDescriptors[key] && !key.startsWith("data-");
1138
- if (shouldKeepOriginalAttr) {
1139
- if (shouldPrintDebug) {
1140
- console.log(" - keeping as non-style", key);
1141
- }
1142
- prev = cur;
1143
- acc.push({
1144
- type: "attr",
1145
- value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(typeof value === "string" ? t.stringLiteral(value) : literalToAst(value)))
1146
- });
1147
- acc.push(cur);
1148
- return acc;
1149
- }
1150
- if (ensureOverridden[key]) {
1151
- acc.push({
1152
- type: "attr",
1153
- value: cur.attr || t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.nullLiteral()))
1154
- });
1155
- }
1156
- if ((prev == null ? void 0 : prev.type) === "style") {
1157
- mergeStyles2(prev.value, cur.value);
1158
- return acc;
1129
+ let key = Object.keys(cur.value)[0];
1130
+ const value = cur.value[key];
1131
+ const fullKey = tamaguiConfig.shorthands[key];
1132
+ if (fullKey) {
1133
+ cur.value = { [fullKey]: value };
1134
+ key = fullKey;
1135
+ }
1136
+ if (disableExtractVariables) {
1137
+ if (value[0] === "$") {
1138
+ if (shouldPrintDebug) {
1139
+ logger.info([` keeping variable inline: ${key} =`, value].join(" "));
1159
1140
  }
1141
+ acc.push({
1142
+ type: "attr",
1143
+ value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.stringLiteral(value)))
1144
+ });
1145
+ return acc;
1160
1146
  }
1161
- prev = cur;
1162
- acc.push(cur);
1163
- return acc;
1164
- }, []);
1165
- if (shouldPrintDebug) {
1166
- console.log(" - attrs (combined \u{1F500}): \n", logLines(attrs.map(attrStr).join(", ")));
1167
- console.log(" - defaultProps: \n", logLines(objToStr(staticConfig.defaultProps)));
1168
- console.log(" - foundStaticProps: \n", logLines(objToStr(foundStaticProps)));
1169
- console.log(" - completeProps: \n", logLines(objToStr(completeProps)));
1170
1147
  }
1171
- const getStyles = (props2, debugName = "") => {
1172
- if (!props2 || !Object.keys(props2).length) {
1173
- if (shouldPrintDebug)
1174
- console.log(" getStyles() no props");
1175
- return {};
1176
- }
1177
- if (excludeProps && !!excludeProps.size) {
1178
- for (const key in props2) {
1179
- if (excludeProps.has(key)) {
1180
- if (shouldPrintDebug)
1181
- console.log(" delete excluded", key);
1182
- delete props2[key];
1183
- }
1148
+ acc.push(cur);
1149
+ return acc;
1150
+ }, []);
1151
+ tm.mark("jsx-element-expanded", !!shouldPrintDebug);
1152
+ if (shouldPrintDebug) {
1153
+ logger.info([" - attrs (expanded): \n", logLines(attrs.map(attrStr).join(", "))].join(" "));
1154
+ }
1155
+ let prev = null;
1156
+ attrs = attrs.reduce((acc, cur) => {
1157
+ if (cur.type === "style") {
1158
+ const key = Object.keys(cur.value)[0];
1159
+ const value = cur.value[key];
1160
+ const shouldKeepOriginalAttr = !shouldFlatten && !validStyles[key] && !pseudoDescriptors[key] && !key.startsWith("data-");
1161
+ if (shouldKeepOriginalAttr) {
1162
+ if (shouldPrintDebug) {
1163
+ logger.info([" - keeping as non-style", key].join(" "));
1184
1164
  }
1165
+ prev = cur;
1166
+ acc.push({
1167
+ type: "attr",
1168
+ value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(typeof value === "string" ? t.stringLiteral(value) : literalToAst(value)))
1169
+ });
1170
+ acc.push(cur);
1171
+ return acc;
1185
1172
  }
1186
- try {
1187
- const out = getSplitStyles(props2, staticConfig, defaultTheme, {
1188
- ...state,
1189
- fallbackProps: completeProps
1190
- }, void 0, props2["debug"]);
1191
- const outStyle = {
1192
- ...out.style,
1193
- ...out.pseudos
1194
- };
1195
- return outStyle;
1196
- } catch (err) {
1197
- console.log("error", err.message, err.stack);
1198
- return {};
1173
+ if (ensureOverridden[key]) {
1174
+ acc.push({
1175
+ type: "attr",
1176
+ value: cur.attr || t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.nullLiteral()))
1177
+ });
1178
+ }
1179
+ if (prev?.type === "style") {
1180
+ mergeStyles2(prev.value, cur.value);
1181
+ return acc;
1199
1182
  }
1200
- };
1201
- const completeStyles = getStyles(completeProps, "completeStyles");
1202
- if (!completeStyles) {
1203
- throw new Error(`Impossible, no styles`);
1204
1183
  }
1205
- let getStyleError = null;
1206
- for (const attr of attrs) {
1207
- try {
1208
- switch (attr.type) {
1209
- case "ternary":
1210
- const a = getStyles(attr.value.alternate, "ternary.alternate");
1211
- const c = getStyles(attr.value.consequent, "ternary.consequent");
1212
- if (a)
1213
- attr.value.alternate = a;
1214
- if (c)
1215
- attr.value.consequent = c;
1216
- if (shouldPrintDebug)
1217
- console.log(" => tern ", attrStr(attr));
1218
- continue;
1219
- case "style":
1220
- const styles = getStyles(attr.value, "style");
1221
- if (styles) {
1222
- attr.value = styles;
1223
- }
1224
- if (shouldPrintDebug)
1225
- console.log(" * styles (in)", logLines(objToStr(attr.value)));
1226
- if (shouldPrintDebug)
1227
- console.log(" * styles (out)", logLines(objToStr(styles)));
1228
- continue;
1184
+ prev = cur;
1185
+ acc.push(cur);
1186
+ return acc;
1187
+ }, []);
1188
+ if (shouldPrintDebug) {
1189
+ logger.info([" - attrs (combined \u{1F500}): \n", logLines(attrs.map(attrStr).join(", "))].join(" "));
1190
+ logger.info([" - defaultProps: \n", logLines(objToStr(staticConfig.defaultProps))].join(" "));
1191
+ logger.info([" - foundStaticProps: \n", logLines(objToStr(foundStaticProps))].join(" "));
1192
+ logger.info([" - completeProps: \n", logLines(objToStr(completeProps))].join(" "));
1193
+ }
1194
+ const getStyles = (props2, debugName = "") => {
1195
+ if (!props2 || !Object.keys(props2).length) {
1196
+ if (shouldPrintDebug)
1197
+ logger.info([" getStyles() no props"].join(" "));
1198
+ return {};
1199
+ }
1200
+ if (excludeProps && !!excludeProps.size) {
1201
+ for (const key in props2) {
1202
+ if (excludeProps.has(key)) {
1203
+ if (shouldPrintDebug)
1204
+ logger.info([" delete excluded", key].join(" "));
1205
+ delete props2[key];
1229
1206
  }
1230
- } catch (err) {
1231
- getStyleError = err;
1232
1207
  }
1233
1208
  }
1234
- if (shouldPrintDebug) {
1235
- console.log(" - attrs (ternaries/combined):\n", logLines(attrs.map(attrStr).join(", ")));
1236
- }
1237
- tm.mark("jsx-element-styles", shouldPrintDebug === "verbose");
1238
- if (getStyleError) {
1239
- console.log(" \u26A0\uFE0F postprocessing error, deopt", getStyleError);
1240
- node.attributes = ogAttributes;
1241
- return node;
1209
+ try {
1210
+ const out = getSplitStyles(props2, staticConfig, defaultTheme, {
1211
+ ...state,
1212
+ fallbackProps: completeProps
1213
+ }, void 0, props2["debug"]);
1214
+ const outStyle = {
1215
+ ...out.style,
1216
+ ...out.pseudos
1217
+ };
1218
+ return outStyle;
1219
+ } catch (err) {
1220
+ logger.info(["error", err.message, err.stack].join(" "));
1221
+ return {};
1242
1222
  }
1243
- const existingStyleKeys = /* @__PURE__ */ new Set();
1244
- for (let i = attrs.length - 1; i >= 0; i--) {
1245
- const attr = attrs[i];
1246
- if (shouldFlatten) {
1247
- if (attr.type === "attr") {
1248
- if (t.isJSXAttribute(attr.value)) {
1249
- if (t.isJSXIdentifier(attr.value.name)) {
1250
- const name = attr.value.name.name;
1251
- if (INLINE_EXTRACTABLE[name]) {
1252
- attr.value.name.name = INLINE_EXTRACTABLE[name];
1253
- }
1254
- }
1223
+ };
1224
+ const completeStyles = getStyles(completeProps, "completeStyles");
1225
+ if (!completeStyles) {
1226
+ throw new Error(`Impossible, no styles`);
1227
+ }
1228
+ let getStyleError = null;
1229
+ for (const attr of attrs) {
1230
+ try {
1231
+ switch (attr.type) {
1232
+ case "ternary": {
1233
+ const a = getStyles(attr.value.alternate, "ternary.alternate");
1234
+ const c = getStyles(attr.value.consequent, "ternary.consequent");
1235
+ if (a)
1236
+ attr.value.alternate = a;
1237
+ if (c)
1238
+ attr.value.consequent = c;
1239
+ if (shouldPrintDebug)
1240
+ logger.info([" => tern ", attrStr(attr)].join(" "));
1241
+ continue;
1242
+ }
1243
+ case "style": {
1244
+ const styles = getStyles(attr.value, "style");
1245
+ if (styles) {
1246
+ attr.value = styles;
1255
1247
  }
1248
+ if (shouldPrintDebug)
1249
+ logger.info([" * styles (in)", logLines(objToStr(attr.value))].join(" "));
1250
+ if (shouldPrintDebug)
1251
+ logger.info([" * styles (out)", logLines(objToStr(styles))].join(" "));
1252
+ continue;
1256
1253
  }
1257
1254
  }
1258
- if (attr.type === "style") {
1259
- for (const key in attr.value) {
1260
- if (existingStyleKeys.has(key)) {
1261
- if (shouldPrintDebug) {
1262
- console.log(" >> delete existing", key);
1255
+ } catch (err) {
1256
+ getStyleError = err;
1257
+ }
1258
+ }
1259
+ if (shouldPrintDebug) {
1260
+ logger.info([" - attrs (ternaries/combined):\n", logLines(attrs.map(attrStr).join(", "))].join(" "));
1261
+ }
1262
+ tm.mark("jsx-element-styles", !!shouldPrintDebug);
1263
+ if (getStyleError) {
1264
+ logger.info([" \u26A0\uFE0F postprocessing error, deopt", getStyleError].join(" "));
1265
+ node.attributes = ogAttributes;
1266
+ return node;
1267
+ }
1268
+ const existingStyleKeys = /* @__PURE__ */ new Set();
1269
+ for (let i = attrs.length - 1; i >= 0; i--) {
1270
+ const attr = attrs[i];
1271
+ if (shouldFlatten) {
1272
+ if (attr.type === "attr") {
1273
+ if (t.isJSXAttribute(attr.value)) {
1274
+ if (t.isJSXIdentifier(attr.value.name)) {
1275
+ const name = attr.value.name.name;
1276
+ if (INLINE_EXTRACTABLE[name]) {
1277
+ attr.value.name.name = INLINE_EXTRACTABLE[name];
1263
1278
  }
1264
- delete attr.value[key];
1265
- } else {
1266
- existingStyleKeys.add(key);
1267
1279
  }
1268
1280
  }
1269
1281
  }
1270
1282
  }
1271
- if (!shouldFlatten) {
1272
- if (inlineWhenUnflattened.size) {
1273
- for (const [index, attr] of attrs.entries()) {
1274
- if (attr.type === "style") {
1275
- for (const key in attr.value) {
1276
- if (!inlineWhenUnflattened.has(key))
1277
- continue;
1278
- const val = inlineWhenUnflattenedOGVals[key];
1279
- if (val) {
1280
- delete attr.value[key];
1281
- attrs.splice(index - 1, 0, val.attr);
1282
- } else {
1283
- delete attr.value[key];
1284
- }
1285
- }
1283
+ if (attr.type === "style") {
1284
+ for (const key in attr.value) {
1285
+ if (existingStyleKeys.has(key)) {
1286
+ if (shouldPrintDebug) {
1287
+ logger.info([` >> delete existing ${key}`].join(" "));
1286
1288
  }
1289
+ delete attr.value[key];
1290
+ } else {
1291
+ existingStyleKeys.add(key);
1287
1292
  }
1288
1293
  }
1289
1294
  }
1290
- if (shouldFlatten) {
1291
- if (shouldPrintDebug) {
1292
- console.log(" [\u2705] flattening", originalNodeName, flatNode);
1293
- }
1294
- node.name.name = flatNode;
1295
- res.flattened++;
1296
- if (closingElement) {
1297
- closingElement.name.name = flatNode;
1295
+ }
1296
+ if (!shouldFlatten) {
1297
+ if (inlineWhenUnflattened.size) {
1298
+ for (const [index, attr] of attrs.entries()) {
1299
+ if (attr.type === "style") {
1300
+ for (const key in attr.value) {
1301
+ if (!inlineWhenUnflattened.has(key))
1302
+ continue;
1303
+ const val = inlineWhenUnflattenedOGVals[key];
1304
+ if (val) {
1305
+ delete attr.value[key];
1306
+ attrs.splice(index - 1, 0, val.attr);
1307
+ } else {
1308
+ delete attr.value[key];
1309
+ }
1310
+ }
1311
+ }
1298
1312
  }
1299
1313
  }
1314
+ }
1315
+ if (shouldFlatten) {
1300
1316
  if (shouldPrintDebug) {
1301
- console.log(` \u274A\u274A inline props (${inlined.size}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : "");
1302
- console.log(" - attrs (end):\n", logLines(attrs.map(attrStr).join(", ")));
1317
+ logger.info([" [\u2705] flattening", originalNodeName, flatNode].join(" "));
1303
1318
  }
1304
- onExtractTag({
1305
- attrs,
1306
- node,
1307
- lineNumbers,
1308
- filePath,
1309
- attemptEval,
1310
- jsxPath: traversePath,
1311
- originalNodeName,
1312
- isFlattened: shouldFlatten,
1313
- programPath,
1314
- completeProps,
1315
- staticConfig
1316
- });
1317
- } finally {
1318
- if (debugPropValue) {
1319
- shouldPrintDebug = ogDebug;
1319
+ node.name.name = flatNode;
1320
+ res.flattened++;
1321
+ if (closingElement) {
1322
+ closingElement.name.name = flatNode;
1320
1323
  }
1321
1324
  }
1325
+ if (shouldPrintDebug) {
1326
+ logger.info([` \u274A\u274A inline props (${inlined.size}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : ""].join(" "));
1327
+ logger.info(` - attrs (end):
1328
+ ${logLines(attrs.map(attrStr).join(", "))}`);
1329
+ }
1330
+ onExtractTag({
1331
+ attrs,
1332
+ node,
1333
+ lineNumbers,
1334
+ filePath,
1335
+ attemptEval,
1336
+ jsxPath: traversePath,
1337
+ originalNodeName,
1338
+ isFlattened: shouldFlatten,
1339
+ programPath,
1340
+ completeProps,
1341
+ staticConfig
1342
+ });
1343
+ } finally {
1344
+ if (debugPropValue) {
1345
+ shouldPrintDebug = ogDebug;
1346
+ }
1322
1347
  }
1323
- });
1324
- tm.mark("jsx-done", shouldPrintDebug === "verbose");
1325
- if (modifiedComponents.size) {
1326
- const all = Array.from(modifiedComponents);
1327
- if (shouldPrintDebug) {
1328
- console.log(" [\u{1FA9D}] hook check", all.length);
1329
- }
1330
- for (const comp of all) {
1331
- removeUnusedHooks(comp, shouldPrintDebug);
1332
- }
1333
1348
  }
1334
- tm.done(shouldPrintDebug === "verbose");
1335
- return res;
1349
+ });
1350
+ tm.mark("jsx-done", !!shouldPrintDebug);
1351
+ if (modifiedComponents.size) {
1352
+ const all = Array.from(modifiedComponents);
1353
+ if (shouldPrintDebug) {
1354
+ logger.info(` [\u{1FA9D}] hook check ${all.length}`);
1355
+ }
1356
+ for (const comp of all) {
1357
+ removeUnusedHooks(comp, shouldPrintDebug);
1358
+ }
1336
1359
  }
1337
- };
1360
+ tm.done(shouldPrintDebug === "verbose");
1361
+ return res;
1362
+ }
1338
1363
  }
1339
1364
  export {
1340
1365
  createExtractor