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

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.
@@ -26,6 +26,15 @@ const UNTOUCHED_PROPS = {
26
26
  style: true,
27
27
  className: true
28
28
  };
29
+ const INLINE_EXTRACTABLE = {
30
+ ref: "ref",
31
+ key: "key",
32
+ onPress: "onClick",
33
+ onHoverIn: "onMouseEnter",
34
+ onHoverOut: "onMouseLeave",
35
+ onPressIn: "onMouseDown",
36
+ onPressOut: "onMouseUp"
37
+ };
29
38
  const isAttr = /* @__PURE__ */ __name((x) => x.type === "attr", "isAttr");
30
39
  const validHooks = {
31
40
  useMedia: true,
@@ -88,6 +97,7 @@ function createExtractor() {
88
97
  return obj;
89
98
  }, {});
90
99
  let doesUseValidImport = false;
100
+ let hasImportedTheme = false;
91
101
  for (const bodyPath of body) {
92
102
  if (bodyPath.type !== "ImportDeclaration")
93
103
  continue;
@@ -280,7 +290,7 @@ function createExtractor() {
280
290
  }
281
291
  let attrs = [];
282
292
  let shouldDeopt = false;
283
- let inlinePropCount = 0;
293
+ const inlined = /* @__PURE__ */ new Map();
284
294
  let hasSetOptimized = false;
285
295
  attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
286
296
  try {
@@ -332,7 +342,7 @@ function createExtractor() {
332
342
  if (shouldPrintDebug) {
333
343
  console.log(" ! inlining, spread attr");
334
344
  }
335
- inlinePropCount++;
345
+ inlined.set(`${Math.random()}`, "spread");
336
346
  return attr;
337
347
  }
338
348
  const name = attribute.name.name;
@@ -343,7 +353,7 @@ function createExtractor() {
343
353
  return null;
344
354
  }
345
355
  if (inlineProps.has(name)) {
346
- inlinePropCount++;
356
+ inlined.set(name, name);
347
357
  if (shouldPrintDebug) {
348
358
  console.log(" ! inlining, inline prop", name);
349
359
  }
@@ -351,7 +361,7 @@ function createExtractor() {
351
361
  }
352
362
  if (deoptProps.has(name)) {
353
363
  shouldDeopt = true;
354
- inlinePropCount++;
364
+ inlined.set(name, name);
355
365
  if (shouldPrintDebug) {
356
366
  console.log(" ! inlining, deopted prop", name);
357
367
  }
@@ -360,6 +370,10 @@ function createExtractor() {
360
370
  if (UNTOUCHED_PROPS[name]) {
361
371
  return attr;
362
372
  }
373
+ if (INLINE_EXTRACTABLE[name]) {
374
+ inlined.set(name, INLINE_EXTRACTABLE[name]);
375
+ return attr;
376
+ }
363
377
  if (name.startsWith("data-")) {
364
378
  return attr;
365
379
  }
@@ -397,7 +411,7 @@ function createExtractor() {
397
411
  if (shouldPrintDebug) {
398
412
  console.log(" ! inlining, ref", name);
399
413
  }
400
- inlinePropCount++;
414
+ inlined.set("ref", "ref");
401
415
  return attr;
402
416
  }
403
417
  if (name === "tag") {
@@ -412,7 +426,7 @@ function createExtractor() {
412
426
  if (shouldPrintDebug) {
413
427
  console.log(` ! inlining, native disable extract: ${name} =`, value.value);
414
428
  }
415
- inlinePropCount++;
429
+ inlined.set(name, true);
416
430
  return attr;
417
431
  }
418
432
  }
@@ -429,19 +443,46 @@ function createExtractor() {
429
443
  keys = Object.keys(out);
430
444
  }
431
445
  }
446
+ let didInline = false;
432
447
  const attributes = keys.map((key) => {
433
448
  const val = out[key];
434
- if (!isValidStyleKey(key)) {
435
- if (validHTMLAttributes[key]) {
436
- return {
437
- type: "attr",
438
- value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(literalToAst(val)))
439
- };
440
- }
441
- if (shouldPrintDebug) {
442
- console.log(" ! inlining, non-static", key);
449
+ if (isValidStyleKey(key)) {
450
+ return {
451
+ type: "style",
452
+ value: { [name]: styleValue },
453
+ name,
454
+ attr: path.node
455
+ };
456
+ }
457
+ if (validHTMLAttributes[key]) {
458
+ return {
459
+ type: "attr",
460
+ value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(literalToAst(val)))
461
+ };
462
+ }
463
+ if (shouldPrintDebug) {
464
+ console.log(" ! inlining, non-static", key);
465
+ }
466
+ didInline = true;
467
+ inlined.set(key, val);
468
+ return val;
469
+ });
470
+ if (didInline) {
471
+ console.log("we inlined something off", { attributes });
472
+ return attr;
473
+ }
474
+ return attributes;
475
+ }
476
+ if (styleValue !== FAILED_EVAL) {
477
+ if (isValidStyleKey(name)) {
478
+ if (shouldPrintDebug) {
479
+ console.log(` style: ${name} =`, styleValue);
480
+ }
481
+ if (!(name in staticConfig.defaultProps)) {
482
+ if (!hasSetOptimized) {
483
+ res.optimized++;
484
+ hasSetOptimized = true;
443
485
  }
444
- inlinePropCount++;
445
486
  }
446
487
  return {
447
488
  type: "style",
@@ -449,28 +490,10 @@ function createExtractor() {
449
490
  name,
450
491
  attr: path.node
451
492
  };
452
- });
453
- if (inlinePropCount) {
493
+ } else {
494
+ inlined.set(name, true);
454
495
  return attr;
455
496
  }
456
- return attributes;
457
- }
458
- if (styleValue !== FAILED_EVAL) {
459
- if (shouldPrintDebug) {
460
- console.log(` style: ${name} =`, styleValue);
461
- }
462
- if (!(name in staticConfig.defaultProps)) {
463
- if (!hasSetOptimized) {
464
- res.optimized++;
465
- hasSetOptimized = true;
466
- }
467
- }
468
- return {
469
- type: "style",
470
- value: { [name]: styleValue },
471
- name,
472
- attr: path.node
473
- };
474
497
  }
475
498
  if (t.isBinaryExpression(value)) {
476
499
  if (shouldPrintDebug) {
@@ -495,7 +518,7 @@ function createExtractor() {
495
518
  if (shouldPrintDebug) {
496
519
  console.log(` evalBinaryExpression cant extract`);
497
520
  }
498
- inlinePropCount++;
521
+ inlined.set(name, true);
499
522
  return attr;
500
523
  }
501
524
  const staticConditional = getStaticConditional(value);
@@ -512,12 +535,9 @@ function createExtractor() {
512
535
  }
513
536
  return { type: "ternary", value: staticLogical };
514
537
  }
538
+ inlined.set(name, true);
515
539
  if (shouldPrintDebug) {
516
- console.log(" ! inline prop via no match", name, value.type);
517
- }
518
- inlinePropCount++;
519
- if (shouldPrintDebug) {
520
- console.log(` inlining ${name} = `, value);
540
+ console.log(` ! inline no match ${name}`, value);
521
541
  }
522
542
  return attr;
523
543
  function addBinaryConditional(operator, staticExpr, cond) {
@@ -750,7 +770,32 @@ function createExtractor() {
750
770
  };
751
771
  const hasSpread = node.attributes.some((x) => t.isJSXSpreadAttribute(x));
752
772
  const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
753
- const shouldFlatten = !shouldDeopt && inlinePropCount === 0 && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
773
+ const themeVal = inlined.get("theme");
774
+ inlined.delete("theme");
775
+ const allOtherPropsExtractable = [...inlined].every(([k, v]) => INLINE_EXTRACTABLE[k]);
776
+ const shouldWrapInnerTheme = !!(hasOnlyStringChildren && themeVal);
777
+ const canFlattenProps = inlined.size === 0 || allOtherPropsExtractable && shouldWrapInnerTheme || allOtherPropsExtractable;
778
+ let shouldFlatten = !shouldDeopt && canFlattenProps && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
779
+ if (shouldWrapInnerTheme) {
780
+ const parents = traversePath.parentPath.node;
781
+ if (!t.isJSXElement(parents) && !t.isJSXFragment(parents)) {
782
+ shouldFlatten = false;
783
+ } else {
784
+ if (typeof themeVal === "string") {
785
+ if (!hasImportedTheme) {
786
+ hasImportedTheme = true;
787
+ programPath.node.body.push(t.importDeclaration([t.importSpecifier(t.identifier("_TamaguiTheme"), t.identifier("Theme"))], t.stringLiteral("@tamagui/core")));
788
+ }
789
+ const children = parents.children;
790
+ parents.children = [
791
+ t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier("_TamaguiTheme"), [
792
+ t.jsxAttribute(t.jsxIdentifier("name"), t.stringLiteral(`${themeVal}`))
793
+ ]), t.jsxClosingElement(t.jsxIdentifier("_TamaguiTheme")), children)
794
+ ];
795
+ } else {
796
+ }
797
+ }
798
+ }
754
799
  if (shouldFlatten && staticConfig.defaultProps) {
755
800
  const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap((key) => {
756
801
  if (!isValidStyleKey(key)) {
@@ -805,8 +850,12 @@ function createExtractor() {
805
850
  if (!cur) {
806
851
  return acc;
807
852
  }
808
- if (shouldFlatten && cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value) && cur.value.name.name === "tag") {
809
- return acc;
853
+ if (cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value)) {
854
+ if (shouldFlatten) {
855
+ if (cur.value.name.name === "tag") {
856
+ return acc;
857
+ }
858
+ }
810
859
  }
811
860
  if (cur.type !== "style") {
812
861
  acc.push(cur);
@@ -982,6 +1031,18 @@ function createExtractor() {
982
1031
  const existingStyleKeys = /* @__PURE__ */ new Set();
983
1032
  for (let i = attrs.length - 1; i >= 0; i--) {
984
1033
  const attr = attrs[i];
1034
+ if (shouldFlatten && canFlattenProps) {
1035
+ if (attr.type === "attr") {
1036
+ if (t.isJSXAttribute(attr.value)) {
1037
+ if (t.isJSXIdentifier(attr.value.name)) {
1038
+ const name = attr.value.name.name;
1039
+ if (INLINE_EXTRACTABLE[name]) {
1040
+ attr.value.name.name = INLINE_EXTRACTABLE[name];
1041
+ }
1042
+ }
1043
+ }
1044
+ }
1045
+ }
985
1046
  if (attr.type === "style") {
986
1047
  for (const key in attr.value) {
987
1048
  if (existingStyleKeys.has(key)) {
@@ -1006,7 +1067,7 @@ function createExtractor() {
1006
1067
  }
1007
1068
  }
1008
1069
  if (shouldPrintDebug) {
1009
- console.log(` \u274A\u274A inline props (${inlinePropCount}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : "");
1070
+ console.log(` \u274A\u274A inline props (${inlined.size}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : "");
1010
1071
  console.log(" - attrs (end):\n", logLines(attrs.map(attrStr).join(", ")));
1011
1072
  }
1012
1073
  onExtractTag({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/static",
3
- "version": "1.0.0-beta.187+b4ae9217",
3
+ "version": "1.0.0-beta.202+a1a54793",
4
4
  "source": "src/index.ts",
5
5
  "typings": "types",
6
6
  "main": "dist/cjs",
@@ -57,10 +57,10 @@
57
57
  "@babel/parser": "^7.15.7",
58
58
  "@babel/traverse": "^7.15.4",
59
59
  "@expo/match-media": "^0.1.0",
60
- "@tamagui/build": "^1.0.0-beta.187+b4ae9217",
61
- "@tamagui/core-node": "^1.0.0-beta.187+b4ae9217",
62
- "@tamagui/fake-react-native": "^1.0.0-beta.187+b4ae9217",
63
- "@tamagui/helpers": "^1.0.0-beta.187+b4ae9217",
60
+ "@tamagui/build": "^1.0.0-beta.202+a1a54793",
61
+ "@tamagui/core-node": "^1.0.0-beta.202+a1a54793",
62
+ "@tamagui/fake-react-native": "^1.0.0-beta.202+a1a54793",
63
+ "@tamagui/helpers": "^1.0.0-beta.202+a1a54793",
64
64
  "babel-literal-to-ast": "^2.1.0",
65
65
  "esbuild": "^0.14.36",
66
66
  "esbuild-register": "^3.1.2",
@@ -68,10 +68,10 @@
68
68
  "fs-extra": "^9.1.0",
69
69
  "invariant": "^2.2.4",
70
70
  "lodash": "^4.17.21",
71
- "tamagui": "^1.0.0-beta.187+b4ae9217"
71
+ "tamagui": "^1.0.0-beta.202+a1a54793"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "react-native-web": "*"
75
75
  },
76
- "gitHead": "b4ae92179a688f73380c8f41296ecfc881b1cbc0"
76
+ "gitHead": "a1a54793ee1890507fc934f42f2eb3a4020b57c5"
77
77
  }
@@ -1 +1 @@
1
- {"version":3,"file":"createExtractor.d.ts","sourceRoot":"","sources":["../../src/extractor/createExtractor.ts"],"names":[],"mappings":"AAAA,OAAiB,EAAE,QAAQ,EAAW,MAAM,iBAAiB,CAAA;AAC7D,OAAO,KAAK,CAAC,MAAM,cAAc,CAAA;AACjC,OAAO,EAGL,qBAAqB,EAKtB,MAAM,oBAAoB,CAAA;AAK3B,OAAO,EAIL,mBAAmB,EAEpB,MAAM,UAAU,CAAA;AA0BjB,oBAAY,SAAS,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA;AAI1D,wBAAgB,eAAe;;;;;;;;;;;;;;wBAsBb,SAAS,EAAE,OAAO,CAAC,GAAG,MAAM,kPAiBrC,mBAAmB;;;;;;EA42C3B"}
1
+ {"version":3,"file":"createExtractor.d.ts","sourceRoot":"","sources":["../../src/extractor/createExtractor.ts"],"names":[],"mappings":"AAAA,OAAiB,EAAE,QAAQ,EAAW,MAAM,iBAAiB,CAAA;AAC7D,OAAO,KAAK,CAAC,MAAM,cAAc,CAAA;AACjC,OAAO,EAGL,qBAAqB,EAKtB,MAAM,oBAAoB,CAAA;AAK3B,OAAO,EAIL,mBAAmB,EAEpB,MAAM,UAAU,CAAA;AAoCjB,oBAAY,SAAS,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA;AAI1D,wBAAgB,eAAe;;;;;;;;;;;;;;wBA2Bb,SAAS,EAAE,OAAO,CAAC,GAAG,MAAM,kPAiBrC,mBAAmB;;;;;;EAi6C3B"}
@@ -1 +1 @@
1
- {"version":3,"file":"extractToClassNames.d.ts","sourceRoot":"","sources":["../../src/extractor/extractToClassNames.ts"],"names":[],"mappings":";AAKA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAA;AAKjC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAGvC,OAAO,EAAgC,cAAc,EAAW,MAAM,UAAU,CAAA;AAGhF,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAgB7C,oBAAY,iBAAiB,GAAG;IAC9B,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,GAAG,EAAE,CAAC,CAAC,IAAI,CAAA;IACX,GAAG,EAAE,GAAG,CAAA;CACT,CAAA;AAED,wBAAgB,mBAAmB,CAAC,EAClC,MAAM,EACN,SAAS,EACT,MAAM,EACN,UAAU,EACV,OAAO,EACP,gBAAgB,EAChB,QAAQ,EACR,OAAO,GACR,EAAE;IACD,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,CAAA;IAC1B,SAAS,EAAE,SAAS,CAAA;IACpB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,cAAc,CAAA;IACvB,gBAAgB,EAAE,OAAO,GAAG,SAAS,CAAA;IACrC,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,GAAG,iBAAiB,GAAG,IAAI,CA4W3B"}
1
+ {"version":3,"file":"extractToClassNames.d.ts","sourceRoot":"","sources":["../../src/extractor/extractToClassNames.ts"],"names":[],"mappings":";AAKA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAA;AAKjC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAGvC,OAAO,EAAgC,cAAc,EAAW,MAAM,UAAU,CAAA;AAGhF,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAgB7C,oBAAY,iBAAiB,GAAG;IAC9B,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,GAAG,EAAE,CAAC,CAAC,IAAI,CAAA;IACX,GAAG,EAAE,GAAG,CAAA;CACT,CAAA;AAED,wBAAgB,mBAAmB,CAAC,EAClC,MAAM,EACN,SAAS,EACT,MAAM,EACN,UAAU,EACV,OAAO,EACP,gBAAgB,EAChB,QAAQ,EACR,OAAO,GACR,EAAE;IACD,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,CAAA;IAC1B,SAAS,EAAE,SAAS,CAAA;IACpB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,cAAc,CAAA;IACvB,gBAAgB,EAAE,OAAO,GAAG,SAAS,CAAA;IACrC,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,GAAG,iBAAiB,GAAG,IAAI,CAwW3B"}
@@ -1,9 +1,9 @@
1
- import type { StaticComponent, TamaguiInternalConfig } from '@tamagui/core';
1
+ import type { TamaguiComponent, TamaguiInternalConfig } from '@tamagui/core';
2
2
  export declare function loadTamagui(props: {
3
3
  components: string[];
4
4
  config: string;
5
5
  }): {
6
- components: Record<string, StaticComponent>;
6
+ components: Record<string, TamaguiComponent>;
7
7
  tamaguiConfig: TamaguiInternalConfig;
8
8
  };
9
9
  //# sourceMappingURL=loadTamagui.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loadTamagui.d.ts","sourceRoot":"","sources":["../../src/extractor/loadTamagui.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAK3E,wBAAgB,WAAW,CAAC,KAAK,EAAE;IAAE,UAAU,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IAC5E,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IAC3C,aAAa,EAAE,qBAAqB,CAAA;CACrC,CA0EA"}
1
+ {"version":3,"file":"loadTamagui.d.ts","sourceRoot":"","sources":["../../src/extractor/loadTamagui.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAK5E,wBAAgB,WAAW,CAAC,KAAK,EAAE;IAAE,UAAU,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IAC5E,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;IAC5C,aAAa,EAAE,qBAAqB,CAAA;CACrC,CA0EA"}