@tamagui/static 1.0.0-alpha.52 → 1.0.0-alpha.56

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.
@@ -117,7 +117,7 @@ function createExtractor() {
117
117
  }
118
118
  },
119
119
  JSXElement(traversePath) {
120
- var _a, _b, _c, _d, _e, _f, _g;
120
+ var _a, _b, _c, _d, _e, _f;
121
121
  const node = traversePath.node.openingElement;
122
122
  const ogAttributes = node.attributes;
123
123
  const componentName = findComponentName(traversePath.scope);
@@ -455,7 +455,7 @@ function createExtractor() {
455
455
  if (value) {
456
456
  if (value.type === "StringLiteral" && value.value[0] === "$") {
457
457
  if (shouldPrintDebug) {
458
- console.log(" native, disable extract var", value.value);
458
+ console.log(` native, disable extract: ${name} =`, value.value);
459
459
  }
460
460
  inlinePropCount++;
461
461
  return attr;
@@ -471,7 +471,7 @@ function createExtractor() {
471
471
  keys = Object.keys(out);
472
472
  }
473
473
  }
474
- if (keys.some((k) => !isStaticAttributeName(k) && k !== "tag")) {
474
+ if (keys.some((k) => !isStaticAttributeName(k) && k !== "tag" && !k.startsWith("data-"))) {
475
475
  if (shouldPrintDebug) {
476
476
  console.log(" ! inlining, not static attribute name", name);
477
477
  }
@@ -480,6 +480,9 @@ function createExtractor() {
480
480
  }
481
481
  }
482
482
  if (styleValue !== FAILED_EVAL) {
483
+ if (shouldPrintDebug) {
484
+ console.log(` style: ${name} =`, styleValue);
485
+ }
483
486
  return {
484
487
  type: "style",
485
488
  value: { [name]: styleValue },
@@ -488,6 +491,9 @@ function createExtractor() {
488
491
  };
489
492
  }
490
493
  if (t.isBinaryExpression(value)) {
494
+ if (shouldPrintDebug) {
495
+ console.log(` binary expression ${name} = `, value);
496
+ }
491
497
  const { operator, left, right } = value;
492
498
  const lVal = attemptEvalSafe(left);
493
499
  const rVal = attemptEvalSafe(right);
@@ -512,16 +518,25 @@ function createExtractor() {
512
518
  }
513
519
  const staticConditional = getStaticConditional(value);
514
520
  if (staticConditional) {
521
+ if (shouldPrintDebug) {
522
+ console.log(` static conditional ${name} = `, value);
523
+ }
515
524
  return { type: "ternary", value: staticConditional };
516
525
  }
517
526
  const staticLogical = getStaticLogical(value);
518
527
  if (staticLogical) {
528
+ if (shouldPrintDebug) {
529
+ console.log(` static ternary ${name} = `, value);
530
+ }
519
531
  return { type: "ternary", value: staticLogical };
520
532
  }
521
533
  if (shouldPrintDebug) {
522
534
  console.log(" ! inline prop via no match", name, value.type);
523
535
  }
524
536
  inlinePropCount++;
537
+ if (shouldPrintDebug) {
538
+ console.log(` inlining ${name} = `, value);
539
+ }
525
540
  return attr;
526
541
  function addBinaryConditional(operator, staticExpr, cond) {
527
542
  if (getStaticConditional(cond)) {
@@ -692,15 +707,32 @@ function createExtractor() {
692
707
  console.log(" - attrs (flattened): \n", logLines(attrs.map(attrStr).join(", ")));
693
708
  }
694
709
  attrs = attrs.reduce((acc, cur) => {
695
- if (cur.type !== "attr" || !t.isJSXAttribute(cur.value) || typeof cur.value.name.name !== "string") {
696
- if (cur.type === "style") {
697
- let key = Object.keys(cur.value)[0];
698
- if (!validStyles[key] && !pseudos[key]) {
710
+ if (cur.type === "style") {
711
+ let key = Object.keys(cur.value)[0];
712
+ let value = cur.value[key];
713
+ const nonShortKey = tamaguiConfig.shorthands[key];
714
+ if (nonShortKey) {
715
+ cur.value = { [nonShortKey]: value };
716
+ key = nonShortKey;
717
+ }
718
+ if (disableExtractVariables) {
719
+ if (value[0] === "$") {
699
720
  if (shouldPrintDebug) {
700
- console.log(" - ignoring (expanded already):", key);
721
+ console.log(` keeping variable inline: ${key} =`, value);
701
722
  }
702
- return acc;
723
+ return [
724
+ {
725
+ type: "attr",
726
+ value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.stringLiteral(value)))
727
+ }
728
+ ];
729
+ }
730
+ }
731
+ if (!validStyles[key] && !pseudos[key]) {
732
+ if (shouldPrintDebug) {
733
+ console.log(" - ignoring (expanded already):", key);
703
734
  }
735
+ return acc;
704
736
  }
705
737
  }
706
738
  acc.push(cur);
@@ -737,13 +769,12 @@ function createExtractor() {
737
769
  const out = postProcessStyles(props2, staticConfig, defaultTheme);
738
770
  const next = (_a2 = out == null ? void 0 : out.style) != null ? _a2 : props2;
739
771
  if (shouldPrintDebug) {
740
- console.log(" getStyles props >>\n", logLines(objToStr(props2)));
741
- console.log(" getStyles next >>\n", logLines(objToStr(next)));
742
- console.log(" getStyles style >>\n", logLines(objToStr(out.style)));
743
- console.log(" getStyles viewp >>\n", logLines(objToStr(out.viewProps)));
772
+ console.log(" viewProps >>\n", logLines(objToStr(out.viewProps)));
773
+ console.log(" props >>\n", logLines(objToStr(props2)));
774
+ console.log(" next <<\n", logLines(objToStr(next)));
744
775
  }
745
- if (staticConfig.validStyles) {
746
- for (const key in next) {
776
+ for (const key in next) {
777
+ if (staticConfig.validStyles) {
747
778
  if (!staticConfig.validStyles[key] && !pseudos[key]) {
748
779
  delete next[key];
749
780
  }
@@ -760,7 +791,6 @@ function createExtractor() {
760
791
  const toAdd = pick(completeStylesProcessed, ...stylesToAddToInitialGroup);
761
792
  const firstGroup = attrs.find((x) => x.type === "style");
762
793
  if (shouldPrintDebug) {
763
- console.log(" stylesToAddToInitialGroup", stylesToAddToInitialGroup.join(", "));
764
794
  console.log(" toAdd", objToStr(toAdd));
765
795
  }
766
796
  if (!firstGroup) {
@@ -773,6 +803,7 @@ function createExtractor() {
773
803
  console.log(" completeStaticProps\n", logLines(objToStr(completeStaticProps)));
774
804
  console.log(" completeStylesProcessed\n", logLines(objToStr(completeStylesProcessed)));
775
805
  }
806
+ let getStyleError = null;
776
807
  for (const attr of attrs) {
777
808
  try {
778
809
  switch (attr.type) {
@@ -781,30 +812,32 @@ function createExtractor() {
781
812
  const c = getStyles(attr.value.consequent);
782
813
  attr.value.alternate = a;
783
814
  attr.value.consequent = c;
784
- if (shouldPrintDebug) {
815
+ if (shouldPrintDebug)
785
816
  console.log(" => tern ", attrStr(attr));
786
- }
787
- break;
817
+ continue;
788
818
  case "style":
789
- const next = {};
790
- for (const key in attr.value) {
791
- if (key in stylePropsTransform) {
792
- next["transform"] = completeStylesProcessed["transform"];
793
- } else {
794
- next[key] = (_g = completeStylesProcessed[key]) != null ? _g : attr.value[key];
795
- }
819
+ for (const keyIn in attr.value) {
820
+ const [key, value] = (() => {
821
+ var _a2;
822
+ if (keyIn in stylePropsTransform) {
823
+ return ["transform", completeStylesProcessed["transform"]];
824
+ } else {
825
+ return [keyIn, (_a2 = completeStylesProcessed[keyIn]) != null ? _a2 : attr.value[keyIn]];
826
+ }
827
+ })();
828
+ attr.value[key] = value;
796
829
  }
797
- attr.value = next;
798
- break;
830
+ continue;
799
831
  }
800
832
  } catch (err) {
801
- if (shouldPrintDebug) {
802
- console.log(" postprocessing error, deopt", err);
803
- node.attributes = ogAttributes;
804
- return node;
805
- }
833
+ getStyleError = err;
806
834
  }
807
835
  }
836
+ if (getStyleError) {
837
+ console.log(" \u26A0\uFE0F postprocessing error, deopt", getStyleError);
838
+ node.attributes = ogAttributes;
839
+ return node;
840
+ }
808
841
  if (shouldPrintDebug) {
809
842
  console.log(" - attrs (after):\n", logLines(attrs.map(attrStr).join(", ")));
810
843
  }
@@ -50,11 +50,15 @@ function extractToClassNames({
50
50
  }
51
51
  const cssMap = /* @__PURE__ */ new Map();
52
52
  const existingHoists = {};
53
+ let hasFlattened = false;
53
54
  const res = extractor.parse(ast, {
54
55
  sourcePath,
55
56
  shouldPrintDebug,
56
57
  ...options,
57
- getFlattenedNode: ({ tag }) => tag,
58
+ getFlattenedNode: ({ tag }) => {
59
+ hasFlattened = true;
60
+ return tag;
61
+ },
58
62
  onExtractTag: ({
59
63
  attrs,
60
64
  node,
@@ -165,10 +169,8 @@ function extractToClassNames({
165
169
  const nameExpr = names ? hoistClassNames(jsxPath, existingHoists, names) : null;
166
170
  let expr = nameExpr;
167
171
  if (nameExpr && !t.isIdentifier(nameExpr)) {
168
- if (!(res == null ? void 0 : res.flattened)) {
169
- console.log("not flat");
172
+ if (!hasFlattened) {
170
173
  } else {
171
- console.log("flat");
172
174
  ensureImportingConcat(programPath);
173
175
  const simpleSpreads = attrs.filter((x) => t.isJSXSpreadAttribute(x.value) && isSimpleSpread(x.value));
174
176
  expr = t.callExpression(t.identifier(CONCAT_CLASSNAME_IMPORT), [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/static",
3
- "version": "1.0.0-alpha.52",
3
+ "version": "1.0.0-alpha.56",
4
4
  "source": "src/index.ts",
5
5
  "typings": "types",
6
6
  "main": "dist/cjs",
@@ -32,6 +32,7 @@
32
32
  "devDependencies": {
33
33
  "@babel/plugin-syntax-typescript": "^7.14.5",
34
34
  "@babel/types": "^7.15.6",
35
+ "@dish/proxy-worm": "^0.0.4",
35
36
  "@testing-library/react": "13.0.0-alpha.4",
36
37
  "@types/jest": "*",
37
38
  "@types/node": "^16.11.9",
@@ -58,7 +59,7 @@
58
59
  "@dish/babel-preset": "^0.0.6",
59
60
  "@expo/match-media": "^0.1.0",
60
61
  "@tamagui/build": "^1.0.0-alpha.44",
61
- "@tamagui/core": "^1.0.0-alpha.48",
62
+ "@tamagui/core": "^1.0.0-alpha.56",
62
63
  "@tamagui/core-node": "^1.0.0-alpha.48",
63
64
  "@tamagui/fake-react-native": "^1.0.0-alpha.17",
64
65
  "@tamagui/helpers": "^1.0.0-alpha.48",
@@ -70,10 +71,10 @@
70
71
  "invariant": "^2.2.4",
71
72
  "loader-utils": "^2.0.0",
72
73
  "lodash": "^4.17.21",
73
- "tamagui": "^1.0.0-alpha.52"
74
+ "tamagui": "^1.0.0-alpha.56"
74
75
  },
75
76
  "peerDependencies": {
76
77
  "react-native-web": "*"
77
78
  },
78
- "gitHead": "ef6a6ef60d230fab7196e25745e5e695113bb046"
79
+ "gitHead": "b447f26dfe9774656a9ffd16e82d06e588832ee0"
79
80
  }
@@ -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,KAAK,EAAsB,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAM9E,OAAO,EAAoC,mBAAmB,EAAW,MAAM,UAAU,CAAA;AAyBzF,oBAAY,SAAS,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA;AAI1D,wBAAgB,eAAe;;;;;;;;;;;;;;;;;;;;;wBAsBb,SAAS,EAAE,OAAO,CAAC,GAAG,MAAM,+MAcrC,mBAAmB;;;;;EAykC3B"}
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,KAAK,EAAsB,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAM9E,OAAO,EAAoC,mBAAmB,EAAW,MAAM,UAAU,CAAA;AAyBzF,oBAAY,SAAS,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA;AAI1D,wBAAgB,eAAe;;;;;;;;;;;;;;;;;;;;;wBAsBb,SAAS,EAAE,OAAO,CAAC,GAAG,MAAM,+MAcrC,mBAAmB;;;;;EA2mC3B"}
@@ -1 +1 @@
1
- {"version":3,"file":"extractToClassNames.d.ts","sourceRoot":"","sources":["../../src/extractor/extractToClassNames.ts"],"names":[],"mappings":";AAKA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAA;AAQjC,OAAO,EAAgC,cAAc,EAAE,MAAM,UAAU,CAAA;AAGvE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAc7C,wBAAgB,mBAAmB,CAAC,EAClC,MAAM,EACN,SAAS,EACT,MAAM,EACN,UAAU,EACV,OAAO,EACP,gBAAgB,EAChB,QAAQ,EACR,OAAO,GACR,EAAE;IACD,MAAM,EAAE,GAAG,CAAA;IACX,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,CAAA;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,GAAG,IAAI,GAAG;IACT,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,CAwRA"}
1
+ {"version":3,"file":"extractToClassNames.d.ts","sourceRoot":"","sources":["../../src/extractor/extractToClassNames.ts"],"names":[],"mappings":";AAKA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAA;AAQjC,OAAO,EAAgC,cAAc,EAAE,MAAM,UAAU,CAAA;AAGvE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAc7C,wBAAgB,mBAAmB,CAAC,EAClC,MAAM,EACN,SAAS,EACT,MAAM,EACN,UAAU,EACV,OAAO,EACP,gBAAgB,EAChB,QAAQ,EACR,OAAO,GACR,EAAE;IACD,MAAM,EAAE,GAAG,CAAA;IACX,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,CAAA;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,GAAG,IAAI,GAAG;IACT,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,CA4RA"}