@tamagui/static 1.0.0-beta.230 → 1.0.0-canary.204

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