@tamagui/static 1.0.0-beta.153 → 1.0.0-beta.16

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 (70) hide show
  1. package/README.md +1 -5
  2. package/dist/cjs/constants.js +8 -0
  3. package/dist/cjs/extractor/accessSafe.js +4 -0
  4. package/dist/cjs/extractor/babelParse.js +5 -0
  5. package/dist/cjs/extractor/babelParse.js.map +2 -2
  6. package/dist/cjs/extractor/buildClassName.js +4 -0
  7. package/dist/cjs/extractor/createEvaluator.js +5 -0
  8. package/dist/cjs/extractor/createExtractor.js +150 -99
  9. package/dist/cjs/extractor/createExtractor.js.map +2 -2
  10. package/dist/cjs/extractor/ensureImportingConcat.js +4 -0
  11. package/dist/cjs/extractor/evaluateAstNode.js +4 -0
  12. package/dist/cjs/extractor/extractHelpers.js +11 -0
  13. package/dist/cjs/extractor/extractMediaStyle.js +5 -0
  14. package/dist/cjs/extractor/extractMediaStyle.js.map +2 -2
  15. package/dist/cjs/extractor/extractToClassNames.js +19 -8
  16. package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
  17. package/dist/cjs/extractor/findTopmostFunction.js +4 -0
  18. package/dist/cjs/extractor/generatedUid.js +4 -0
  19. package/dist/cjs/extractor/getPrefixLogs.js +4 -0
  20. package/dist/cjs/extractor/getPropValueFromAttributes.js +4 -0
  21. package/dist/cjs/extractor/getSourceModule.js +4 -0
  22. package/dist/cjs/extractor/getStaticBindingsForScope.js +14 -1
  23. package/dist/cjs/extractor/getStaticBindingsForScope.js.map +2 -2
  24. package/dist/cjs/extractor/hoistClassNames.js +4 -0
  25. package/dist/cjs/extractor/literalToAst.js +5 -0
  26. package/dist/cjs/extractor/loadTamagui.js +69 -46
  27. package/dist/cjs/extractor/loadTamagui.js.map +2 -2
  28. package/dist/cjs/extractor/logLines.js +4 -0
  29. package/dist/cjs/extractor/normalizeTernaries.js +4 -0
  30. package/dist/cjs/extractor/removeUnusedHooks.js +4 -0
  31. package/dist/cjs/extractor/timer.js +46 -0
  32. package/dist/cjs/extractor/timer.js.map +7 -0
  33. package/dist/cjs/extractor/validHTMLAttributes.js +4 -0
  34. package/dist/cjs/index.js +6 -0
  35. package/dist/cjs/patchReactNativeWeb.js +23 -7
  36. package/dist/cjs/patchReactNativeWeb.js.map +2 -2
  37. package/dist/esm/extractor/babelParse.js.map +2 -2
  38. package/dist/esm/extractor/createExtractor.js +154 -106
  39. package/dist/esm/extractor/createExtractor.js.map +2 -2
  40. package/dist/esm/extractor/extractMediaStyle.js.map +2 -2
  41. package/dist/esm/extractor/extractToClassNames.js +15 -8
  42. package/dist/esm/extractor/extractToClassNames.js.map +2 -2
  43. package/dist/esm/extractor/getStaticBindingsForScope.js +10 -1
  44. package/dist/esm/extractor/getStaticBindingsForScope.js.map +2 -2
  45. package/dist/esm/extractor/loadTamagui.js +65 -46
  46. package/dist/esm/extractor/loadTamagui.js.map +2 -2
  47. package/dist/esm/extractor/timer.js +24 -0
  48. package/dist/esm/extractor/timer.js.map +7 -0
  49. package/dist/esm/patchReactNativeWeb.js +19 -7
  50. package/dist/esm/patchReactNativeWeb.js.map +2 -2
  51. package/dist/jsx/extractor/createExtractor.js +154 -106
  52. package/dist/jsx/extractor/extractToClassNames.js +15 -8
  53. package/dist/jsx/extractor/getStaticBindingsForScope.js +10 -1
  54. package/dist/jsx/extractor/loadTamagui.js +65 -46
  55. package/dist/jsx/extractor/timer.js +23 -0
  56. package/dist/jsx/patchReactNativeWeb.js +19 -7
  57. package/package.json +12 -12
  58. package/types/extractor/babelParse.d.ts.map +1 -1
  59. package/types/extractor/createExtractor.d.ts +2 -0
  60. package/types/extractor/createExtractor.d.ts.map +1 -1
  61. package/types/extractor/extractMediaStyle.d.ts +1 -1
  62. package/types/extractor/extractMediaStyle.d.ts.map +1 -1
  63. package/types/extractor/extractToClassNames.d.ts +2 -1
  64. package/types/extractor/extractToClassNames.d.ts.map +1 -1
  65. package/types/extractor/getStaticBindingsForScope.d.ts.map +1 -1
  66. package/types/extractor/loadTamagui.d.ts.map +1 -1
  67. package/types/extractor/timer.d.ts +5 -0
  68. package/types/extractor/timer.d.ts.map +1 -0
  69. package/types/patchReactNativeWeb.d.ts.map +1 -1
  70. package/LICENSE +0 -21
package/README.md CHANGED
@@ -1,5 +1 @@
1
- - onPress, onPressIn, onPressOut, onHoverIn, onHoverOut, ref, key extraction
2
- - bug with props after spread not applying, make them deopt:
3
- - <YStack {...baseStyle} cursor="default" /> wont be right rn
4
- - hoverStyle/pressStyle spread + constant
5
- - LinearGradient
1
+ ## static
@@ -33,4 +33,12 @@ const MEDIA_SEP = "_";
33
33
  const cacheDir = (0, import_find_cache_dir.default)({ name: "tamagui", create: true });
34
34
  const FAILED_EVAL = Symbol("failed_style_eval");
35
35
  const CONCAT_CLASSNAME_IMPORT = "concatClassName";
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ CONCAT_CLASSNAME_IMPORT,
39
+ CSS_FILE_NAME,
40
+ FAILED_EVAL,
41
+ MEDIA_SEP,
42
+ cacheDir
43
+ });
36
44
  //# sourceMappingURL=constants.js.map
@@ -29,4 +29,8 @@ function accessSafe(obj, member) {
29
29
  return t.logicalExpression("&&", t.logicalExpression("&&", t.binaryExpression("===", t.unaryExpression("typeof", obj), t.stringLiteral("object")), t.binaryExpression("!==", obj, t.nullLiteral())), t.memberExpression(obj, t.identifier(member), false));
30
30
  }
31
31
  __name(accessSafe, "accessSafe");
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ accessSafe
35
+ });
32
36
  //# sourceMappingURL=accessSafe.js.map
@@ -48,4 +48,9 @@ function babelParse(code) {
48
48
  return parser(code.toString(), parserOptions);
49
49
  }
50
50
  __name(babelParse, "babelParse");
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ babelParse,
54
+ parserOptions
55
+ });
51
56
  //# sourceMappingURL=babelParse.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/extractor/babelParse.ts"],
4
- "sourcesContent": ["import * as babelParser from '@babel/parser'\n\nexport const parserOptions: babelParser.ParserOptions = Object.freeze({\n plugins: [\n 'asyncGenerators',\n 'classProperties',\n 'dynamicImport',\n 'functionBind',\n 'jsx',\n 'numericSeparator',\n 'objectRestSpread',\n 'optionalCatchBinding',\n 'decorators-legacy',\n 'typescript',\n 'optionalChaining',\n 'nullishCoalescingOperator',\n // 'objectRestSpread',\n // 'dynamicImport'\n ],\n sourceType: 'module',\n})\n\nconst parser = babelParser.parse.bind(babelParser)\n\nexport function babelParse(code: string | Buffer): any {\n return parser(code.toString(), parserOptions)\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAEtB,MAAM,gBAA2C,OAAO,OAAO;AAAA,EACpE,SAAS;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAGF;AAAA,EACA,YAAY;AACd,CAAC;AAED,MAAM,SAAS,YAAY,MAAM,KAAK,WAAW;AAE1C,oBAAoB,MAA4B;AACrD,SAAO,OAAO,KAAK,SAAS,GAAG,aAAa;AAC9C;AAFgB;",
4
+ "sourcesContent": ["import * as babelParser from '@babel/parser'\n\nexport const parserOptions: babelParser.ParserOptions = Object.freeze({\n plugins: [\n 'asyncGenerators',\n 'classProperties',\n 'dynamicImport',\n 'functionBind',\n 'jsx',\n 'numericSeparator',\n 'objectRestSpread',\n 'optionalCatchBinding',\n 'decorators-legacy',\n 'typescript',\n 'optionalChaining',\n 'nullishCoalescingOperator',\n ],\n sourceType: 'module',\n})\n\nconst parser = babelParser.parse.bind(babelParser)\n\nexport function babelParse(code: string | Buffer): any {\n return parser(code.toString(), parserOptions)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAEtB,MAAM,gBAA2C,OAAO,OAAO;AAAA,EACpE,SAAS;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,YAAY;AACd,CAAC;AAED,MAAM,SAAS,YAAY,MAAM,KAAK,WAAW;AAE1C,oBAAoB,MAA4B;AACrD,SAAO,OAAO,KAAK,SAAS,GAAG,aAAa;AAC9C;AAFgB;",
6
6
  "names": []
7
7
  }
@@ -58,4 +58,8 @@ function buildClassName(classNameObjects) {
58
58
  }, null);
59
59
  }
60
60
  __name(buildClassName, "buildClassName");
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ buildClassName
64
+ });
61
65
  //# sourceMappingURL=buildClassName.js.map
@@ -70,4 +70,9 @@ function createSafeEvaluator(attemptEval) {
70
70
  };
71
71
  }
72
72
  __name(createSafeEvaluator, "createSafeEvaluator");
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ createEvaluator,
76
+ createSafeEvaluator
77
+ });
73
78
  //# sourceMappingURL=createEvaluator.js.map
@@ -53,6 +53,7 @@ __export(createExtractor_exports, {
53
53
  createExtractor: () => createExtractor
54
54
  });
55
55
  module.exports = __toCommonJS(createExtractor_exports);
56
+ var import_path = require("path");
56
57
  var import_traverse = __toESM(require("@babel/traverse"));
57
58
  var t = __toESM(require("@babel/types"));
58
59
  var import_core_node = require("@tamagui/core-node");
@@ -68,6 +69,7 @@ var import_loadTamagui = require("./loadTamagui");
68
69
  var import_logLines = require("./logLines");
69
70
  var import_normalizeTernaries = require("./normalizeTernaries");
70
71
  var import_removeUnusedHooks = require("./removeUnusedHooks");
72
+ var import_timer = require("./timer");
71
73
  var import_validHTMLAttributes = require("./validHTMLAttributes");
72
74
  const UNTOUCHED_PROPS = {
73
75
  key: true,
@@ -95,10 +97,6 @@ function createExtractor() {
95
97
  process.exit(1);
96
98
  }
97
99
  const shouldAddDebugProp = !process.env.npm_package_dependencies_next && process.env.TAMAGUI_TARGET !== "native" && process.env.IDENTIFY_TAGS !== "false" && (process.env.NODE_ENV === "development" || process.env.DEBUG || process.env.IDENTIFY_TAGS);
98
- require("esbuild-register/dist/node").register({
99
- target: "es2019",
100
- format: "cjs"
101
- });
102
100
  let loadedTamaguiConfig;
103
101
  let hasLogged = false;
104
102
  return {
@@ -146,12 +144,18 @@ function createExtractor() {
146
144
  if (!Array.isArray(props.components)) {
147
145
  throw new Error(`Must provide components array with list of Tamagui component modules`);
148
146
  }
147
+ const ogDebug = shouldPrintDebug;
148
+ const tm = (0, import_timer.timer)();
149
149
  const { components, tamaguiConfig } = (0, import_loadTamagui.loadTamagui)({
150
150
  config,
151
151
  components: props.components || ["tamagui"]
152
152
  });
153
+ if (shouldPrintDebug === "verbose") {
154
+ console.log("tamagui.config.ts:", { components, config });
155
+ }
156
+ tm.mark("load-tamagui", shouldPrintDebug === "verbose");
153
157
  loadedTamaguiConfig = tamaguiConfig;
154
- const defaultTheme = tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]];
158
+ const defaultTheme = (0, import_core_node.proxyThemeVariables)(tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]]);
155
159
  const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
156
160
  const isInternalImport = /* @__PURE__ */ __name((importStr) => {
157
161
  return (0, import_extractHelpers.isInsideTamagui)(sourcePath) && importStr[0] === ".";
@@ -163,6 +167,9 @@ function createExtractor() {
163
167
  obj[name] = components[name];
164
168
  return obj;
165
169
  }, {});
170
+ if (shouldPrintDebug === "verbose") {
171
+ console.log("validComponents", Object.keys(validComponents));
172
+ }
166
173
  let doesUseValidImport = false;
167
174
  let hasImportedTheme = false;
168
175
  for (const bodyPath of body) {
@@ -170,11 +177,16 @@ function createExtractor() {
170
177
  continue;
171
178
  const node = "node" in bodyPath ? bodyPath.node : bodyPath;
172
179
  const from = node.source.value;
173
- if (props.components.includes(from) || isInternalImport(from)) {
174
- if (node.specifiers.some((specifier) => {
180
+ const isValidImport = props.components.includes(from) || isInternalImport(from);
181
+ if (isValidImport) {
182
+ const isValidComponent = node.specifiers.some((specifier) => {
175
183
  const name = specifier.local.name;
176
184
  return validComponents[name] || validHooks[name];
177
- })) {
185
+ });
186
+ if (shouldPrintDebug === "verbose") {
187
+ console.log("import from", from, { isValidComponent });
188
+ }
189
+ if (isValidComponent) {
178
190
  doesUseValidImport = true;
179
191
  break;
180
192
  }
@@ -186,6 +198,7 @@ function createExtractor() {
186
198
  if (!doesUseValidImport) {
187
199
  return null;
188
200
  }
201
+ tm.mark("import-check", shouldPrintDebug === "verbose");
189
202
  let couldntParse = false;
190
203
  const modifiedComponents = /* @__PURE__ */ new Set();
191
204
  const bindingCache = {};
@@ -207,6 +220,7 @@ function createExtractor() {
207
220
  },
208
221
  JSXElement(traversePath) {
209
222
  var _a2, _b2, _c;
223
+ tm.mark("jsx-element", shouldPrintDebug === "verbose");
210
224
  const node = traversePath.node.openingElement;
211
225
  const ogAttributes = node.attributes;
212
226
  const componentName = (0, import_extractHelpers.findComponentName)(traversePath.scope);
@@ -233,13 +247,18 @@ function createExtractor() {
233
247
  }
234
248
  const originalNodeName = node.name.name;
235
249
  res.found++;
236
- const filePath = sourcePath.replace(process.cwd(), ".");
250
+ const filePath = `./${(0, import_path.relative)(process.cwd(), sourcePath)}`;
237
251
  const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
238
- const preName = componentName ? `${componentName}.` : "";
239
- const tagId = `${preName}${node.name.name}@${filePath.replace("./", "")}:${lineNumbers}`;
240
- const hasBooleanDebugTrue = node.attributes.some((n) => t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && n.name.name === "debug" && n.value === null);
241
- if (hasBooleanDebugTrue) {
242
- shouldPrintDebug = true;
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;
243
262
  }
244
263
  try {
245
264
  let isValidStyleKey = function(name) {
@@ -363,6 +382,10 @@ function createExtractor() {
363
382
  }
364
383
  }
365
384
  }
385
+ if (name === "theme") {
386
+ inlined.set("theme", attr.value);
387
+ return attr;
388
+ }
366
389
  const styleValue = attemptEvalSafe(value);
367
390
  if (!isValidStyleKey(name)) {
368
391
  let keys = [name];
@@ -378,10 +401,6 @@ function createExtractor() {
378
401
  let didInline = false;
379
402
  const attributes = keys.map((key) => {
380
403
  const val = out[key];
381
- if (key === "theme") {
382
- inlined.set(key, val);
383
- return attr;
384
- }
385
404
  if (isValidStyleKey(key)) {
386
405
  return {
387
406
  type: "style",
@@ -458,14 +477,14 @@ function createExtractor() {
458
477
  }
459
478
  const staticConditional = getStaticConditional(value);
460
479
  if (staticConditional) {
461
- if (shouldPrintDebug) {
462
- console.log(` static conditional ${name} = `, value);
480
+ if (shouldPrintDebug === "verbose") {
481
+ console.log(` static conditional ${name}`, value);
463
482
  }
464
483
  return { type: "ternary", value: staticConditional };
465
484
  }
466
485
  const staticLogical = getStaticLogical(value);
467
486
  if (staticLogical) {
468
- if (shouldPrintDebug) {
487
+ if (shouldPrintDebug === "verbose") {
469
488
  console.log(` static ternary ${name} = `, value);
470
489
  }
471
490
  return { type: "ternary", value: staticLogical };
@@ -498,9 +517,6 @@ function createExtractor() {
498
517
  function getStaticConditional(value2) {
499
518
  if (t.isConditionalExpression(value2)) {
500
519
  try {
501
- if (shouldPrintDebug) {
502
- console.log("attempt", value2.alternate, value2.consequent);
503
- }
504
520
  const aVal = attemptEval(value2.alternate);
505
521
  const cVal = attemptEval(value2.consequent);
506
522
  if (shouldPrintDebug) {
@@ -628,9 +644,15 @@ function createExtractor() {
628
644
  }));
629
645
  });
630
646
  }, mergeStyles = function(prev2, next) {
647
+ (0, import_core_node.normalizeStyleObject)(next);
631
648
  for (const key in next) {
632
649
  if (import_core_node.pseudos[key]) {
633
650
  prev2[key] = prev2[key] || {};
651
+ if (shouldPrintDebug) {
652
+ if (!next[key] || !prev2[key]) {
653
+ console.log("warn: missing", key, prev2, next);
654
+ }
655
+ }
634
656
  Object.assign(prev2[key], next[key]);
635
657
  } else {
636
658
  prev2[key] = next[key];
@@ -644,12 +666,13 @@ function createExtractor() {
644
666
  __name(mergeStyles, "mergeStyles");
645
667
  node.attributes.find((n) => t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && n.name.name === "debug" && n.value === null);
646
668
  if (shouldPrintDebug) {
647
- console.log(`
648
- <${originalNodeName} /> (${tagId})`);
669
+ console.log("\n");
670
+ console.log("\x1B[33m%s\x1B[0m", `${tagId[0]} | ${tagId[2]} -------------------`);
671
+ console.log("\x1B[1m", "\x1B[32m", `<${originalNodeName} />`);
649
672
  }
650
673
  if (shouldAddDebugProp && !disableDebugAttr) {
651
674
  res.modified++;
652
- node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(tagId)));
675
+ node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(tagId.join(" "))));
653
676
  }
654
677
  const shouldLog = !hasLogged;
655
678
  if (shouldLog) {
@@ -740,6 +763,7 @@ function createExtractor() {
740
763
  if (couldntParse) {
741
764
  return;
742
765
  }
766
+ tm.mark("jsx-element-flattened", shouldPrintDebug === "verbose");
743
767
  node.attributes = flattenedAttrs;
744
768
  if (staticConfig.defaultProps) {
745
769
  for (const key in staticConfig.defaultProps) {
@@ -765,6 +789,7 @@ function createExtractor() {
765
789
  attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
766
790
  try {
767
791
  const res2 = evaluateAttribute(path);
792
+ tm.mark("jsx-element-evaluate-attr", shouldPrintDebug === "verbose");
768
793
  if (!res2) {
769
794
  path.remove();
770
795
  }
@@ -827,71 +852,48 @@ function createExtractor() {
827
852
  out.push(cur);
828
853
  return out;
829
854
  }, []).flat();
830
- const completeStaticProps = __spreadValues({}, Object.keys(attrs).reduce((acc, index) => {
831
- const cur = attrs[index];
832
- if (cur.type === "style") {
833
- Object.assign(acc, cur.value);
834
- }
835
- if (cur.type === "attr") {
836
- if (t.isJSXSpreadAttribute(cur.value)) {
837
- return acc;
838
- }
839
- if (!t.isJSXIdentifier(cur.value.name)) {
840
- return acc;
841
- }
842
- const key = cur.value.name.name;
843
- const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
844
- if (value === import_constants.FAILED_EVAL) {
845
- return acc;
846
- }
847
- acc[key] = value;
848
- }
849
- return acc;
850
- }, {}));
851
855
  const hasSpread = node.attributes.some((x) => t.isJSXSpreadAttribute(x));
852
856
  const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
853
- const themeVal = inlined.get("theme");
857
+ let themeVal = inlined.get("theme");
854
858
  inlined.delete("theme");
855
859
  const allOtherPropsExtractable = [...inlined].every(([k, v]) => INLINE_EXTRACTABLE[k]);
856
- const shouldWrapInnerTheme = allOtherPropsExtractable && !!(hasOnlyStringChildren && themeVal);
857
- const canFlattenProps = inlined.size === 0 || shouldWrapInnerTheme || allOtherPropsExtractable;
860
+ const shouldWrapThme = allOtherPropsExtractable && !!themeVal;
861
+ const canFlattenProps = inlined.size === 0 || shouldWrapThme || allOtherPropsExtractable;
858
862
  let shouldFlatten = !shouldDeopt && canFlattenProps && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
859
- if (shouldFlatten && shouldWrapInnerTheme) {
860
- if (typeof themeVal !== "string") {
861
- console.warn("??");
862
- return;
863
- }
863
+ if (shouldPrintDebug) {
864
+ console.log(" - flatten?", (0, import_extractHelpers.objToStr)({ hasSpread, shouldDeopt, shouldFlatten, canFlattenProps, shouldWrapThme, allOtherPropsExtractable, hasOnlyStringChildren }));
865
+ }
866
+ if (shouldFlatten && shouldWrapThme) {
864
867
  if (shouldPrintDebug) {
865
868
  console.log(" - wrapping theme", allOtherPropsExtractable, themeVal);
866
869
  }
870
+ attrs = attrs.filter((x) => x.type === "attr" && t.isJSXAttribute(x.value) && x.value.name.name === "theme" ? false : true);
867
871
  if (!hasImportedTheme) {
868
872
  hasImportedTheme = true;
869
873
  programPath.node.body.push(t.importDeclaration([t.importSpecifier(t.identifier("_TamaguiTheme"), t.identifier("Theme"))], t.stringLiteral("@tamagui/core")));
870
874
  }
871
875
  traversePath.replaceWith(t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier("_TamaguiTheme"), [
872
- t.jsxAttribute(t.jsxIdentifier("name"), t.stringLiteral(`${themeVal}`))
876
+ t.jsxAttribute(t.jsxIdentifier("name"), themeVal.value)
873
877
  ]), t.jsxClosingElement(t.jsxIdentifier("_TamaguiTheme")), [traversePath.node]));
874
878
  }
875
879
  if (shouldFlatten && staticConfig.defaultProps) {
876
880
  const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap((key) => {
877
881
  if (!isValidStyleKey(key)) {
878
- return;
882
+ return [];
879
883
  }
880
- try {
881
- const serialize = require("babel-literal-to-ast");
882
- const val = staticConfig.defaultProps[key];
883
- const value = serialize(val);
884
- const name = tamaguiConfig.shorthands[key] || key;
885
- return {
886
- type: "style",
887
- name,
888
- value
889
- };
890
- } catch (err) {
891
- console.warn(`\u26A0\uFE0F Error evaluating default style for component, prop ${key}
892
- error: ${err}`);
884
+ const value = staticConfig.defaultProps[key];
885
+ const name = tamaguiConfig.shorthands[key] || key;
886
+ if (value === void 0) {
887
+ console.warn(`\u26A0\uFE0F Error evaluating default style for component, prop ${key} ${value}`);
893
888
  shouldDeopt = true;
889
+ return;
894
890
  }
891
+ const attr = {
892
+ type: "style",
893
+ name,
894
+ value: { [name]: value }
895
+ };
896
+ return attr;
895
897
  });
896
898
  if (defaultStyleAttrs.length) {
897
899
  attrs = [...defaultStyleAttrs, ...attrs];
@@ -959,6 +961,7 @@ function createExtractor() {
959
961
  acc.push(cur);
960
962
  return acc;
961
963
  }, []);
964
+ tm.mark("jsx-element-expanded", shouldPrintDebug === "verbose");
962
965
  if (shouldPrintDebug) {
963
966
  console.log(" - attrs (expanded): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
964
967
  }
@@ -995,48 +998,84 @@ function createExtractor() {
995
998
  acc.push(cur);
996
999
  return acc;
997
1000
  }, []);
1001
+ const state = {
1002
+ noClassNames: true,
1003
+ focus: false,
1004
+ hover: false,
1005
+ mounted: true,
1006
+ press: false,
1007
+ pressIn: false
1008
+ };
1009
+ const completeStaticProps = Object.keys(attrs).reduce((acc, index) => {
1010
+ const cur = attrs[index];
1011
+ if (cur.type === "style") {
1012
+ (0, import_core_node.normalizeStyleObject)(cur.value);
1013
+ Object.assign(acc, cur.value);
1014
+ }
1015
+ if (cur.type === "attr") {
1016
+ if (t.isJSXSpreadAttribute(cur.value)) {
1017
+ return acc;
1018
+ }
1019
+ if (!t.isJSXIdentifier(cur.value.name)) {
1020
+ return acc;
1021
+ }
1022
+ const key = cur.value.name.name;
1023
+ const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
1024
+ if (value === import_constants.FAILED_EVAL) {
1025
+ return acc;
1026
+ }
1027
+ acc[key] = value;
1028
+ }
1029
+ return acc;
1030
+ }, {});
1031
+ const completeProps = __spreadValues(__spreadValues({}, staticConfig.defaultProps), completeStaticProps);
998
1032
  if (shouldPrintDebug) {
999
1033
  console.log(" - attrs (combined \u{1F500}): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
1034
+ console.log(" - defaultProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(staticConfig.defaultProps)));
1035
+ console.log(" - completeStaticProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(completeStaticProps)));
1000
1036
  }
1001
- const completeProps = __spreadValues(__spreadValues({}, staticConfig.defaultProps), completeStaticProps);
1002
1037
  const getStyles = /* @__PURE__ */ __name((props2, debugName = "") => {
1003
- if (!props2)
1004
- return;
1005
- if (!Object.keys(props2).length)
1006
- return;
1038
+ if (!props2 || !Object.keys(props2).length) {
1039
+ if (shouldPrintDebug)
1040
+ console.log(" getStyles() no props");
1041
+ return {};
1042
+ }
1007
1043
  if (excludeProps && !!excludeProps.size) {
1008
1044
  for (const key in props2) {
1009
1045
  if (excludeProps.has(key)) {
1046
+ if (shouldPrintDebug)
1047
+ console.log(" delete excluded", key);
1010
1048
  delete props2[key];
1011
1049
  }
1012
1050
  }
1013
1051
  }
1014
- const out = (0, import_core_node.getSplitStyles)(props2, staticConfig, defaultTheme, {
1015
- noClassNames: true,
1016
- fallbackProps: completeProps,
1017
- focus: false,
1018
- hover: false,
1019
- mounted: true,
1020
- press: false,
1021
- pressIn: false
1022
- });
1023
- const outStyle = __spreadValues(__spreadValues({}, out.style), out.pseudos);
1024
- for (const key in outStyle) {
1052
+ try {
1053
+ const out = (0, import_core_node.getSplitStyles)(props2, staticConfig, defaultTheme, __spreadProps(__spreadValues({}, state), {
1054
+ fallbackProps: completeProps
1055
+ }));
1056
+ const outStyle = __spreadValues(__spreadValues({}, out.style), out.pseudos);
1025
1057
  if (staticConfig.validStyles) {
1026
- if (!staticConfig.validStyles[key] && !import_core_node.pseudos[key]) {
1027
- delete outStyle[key];
1058
+ for (const key in outStyle) {
1059
+ if (!staticConfig.validStyles[key] && !import_core_node.pseudos[key] && !/(hover|focus|press)Style$/.test(key)) {
1060
+ if (shouldPrintDebug)
1061
+ console.log(" delete invalid style", key);
1062
+ delete outStyle[key];
1063
+ }
1028
1064
  }
1029
1065
  }
1030
- }
1031
- if (shouldPrintDebug === "verbose") {
1032
- console.log(` getStyles ${debugName} (props):
1066
+ if (shouldPrintDebug) {
1067
+ console.log(` getStyles ${debugName} (props):
1033
1068
  `, (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(props2)));
1034
- console.log(` getStyles ${debugName} (out.viewProps):
1069
+ console.log(` getStyles ${debugName} (out.viewProps):
1035
1070
  `, (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(out.viewProps)));
1036
- console.log(` getStyles ${debugName} (out.style):
1071
+ console.log(` getStyles ${debugName} (out.style):
1037
1072
  `, (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(outStyle || {}), true));
1073
+ }
1074
+ return outStyle;
1075
+ } catch (err) {
1076
+ console.log("error", err.message, err.stack);
1077
+ return {};
1038
1078
  }
1039
- return outStyle;
1040
1079
  }, "getStyles");
1041
1080
  const completeStylesProcessed = getStyles(completeProps, "completeStylesProcessed");
1042
1081
  if (!completeStylesProcessed) {
@@ -1077,11 +1116,13 @@ function createExtractor() {
1077
1116
  console.log(" => tern ", (0, import_extractHelpers.attrStr)(attr));
1078
1117
  continue;
1079
1118
  case "style":
1119
+ if (shouldPrintDebug)
1120
+ console.log(" * styles in", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(attr.value)));
1080
1121
  const styles = getStyles(attr.value, "style");
1122
+ if (shouldPrintDebug)
1123
+ console.log(" * styles out", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(styles)));
1081
1124
  if (styles) {
1082
1125
  attr.value = Object.fromEntries(Object.keys(styles).map((k) => [k, completeStylesProcessed[k]]));
1083
- } else {
1084
- console.warn("?????????");
1085
1126
  }
1086
1127
  continue;
1087
1128
  }
@@ -1089,6 +1130,7 @@ function createExtractor() {
1089
1130
  getStyleError = err;
1090
1131
  }
1091
1132
  }
1133
+ tm.mark("jsx-element-styles", shouldPrintDebug === "verbose");
1092
1134
  if (getStyleError) {
1093
1135
  console.log(" \u26A0\uFE0F postprocessing error, deopt", getStyleError);
1094
1136
  node.attributes = ogAttributes;
@@ -1112,6 +1154,9 @@ function createExtractor() {
1112
1154
  if (attr.type === "style") {
1113
1155
  for (const key in attr.value) {
1114
1156
  if (existingStyleKeys.has(key)) {
1157
+ if (shouldPrintDebug) {
1158
+ console.log(" >> delete existing", key);
1159
+ }
1115
1160
  delete attr.value[key];
1116
1161
  } else {
1117
1162
  existingStyleKeys.add(key);
@@ -1147,12 +1192,13 @@ function createExtractor() {
1147
1192
  } catch (err) {
1148
1193
  throw err;
1149
1194
  } finally {
1150
- if (hasBooleanDebugTrue) {
1151
- shouldPrintDebug = false;
1195
+ if (debugPropValue) {
1196
+ shouldPrintDebug = ogDebug;
1152
1197
  }
1153
1198
  }
1154
1199
  }
1155
1200
  });
1201
+ tm.mark("jsx-done", shouldPrintDebug === "verbose");
1156
1202
  if (modifiedComponents.size) {
1157
1203
  const all = Array.from(modifiedComponents);
1158
1204
  if (shouldPrintDebug) {
@@ -1162,9 +1208,14 @@ function createExtractor() {
1162
1208
  (0, import_removeUnusedHooks.removeUnusedHooks)(comp, shouldPrintDebug);
1163
1209
  }
1164
1210
  }
1211
+ tm.done(shouldPrintDebug === "verbose");
1165
1212
  return res;
1166
1213
  }
1167
1214
  };
1168
1215
  }
1169
1216
  __name(createExtractor, "createExtractor");
1217
+ // Annotate the CommonJS export names for ESM import in node:
1218
+ 0 && (module.exports = {
1219
+ createExtractor
1220
+ });
1170
1221
  //# sourceMappingURL=createExtractor.js.map