@tamagui/static 1.0.0-beta.202 → 1.0.0-beta.203

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