@tamagui/static 1.0.1-beta.141 → 1.0.1-beta.142

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