@tamagui/static 1.0.0-beta.187 → 1.0.0-beta.2

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