@tamagui/static 1.0.0-beta.179 → 1.0.0-beta.181

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