@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.
- package/dist/cjs/extractor/createExtractor.js +107 -46
- package/dist/cjs/extractor/createExtractor.js.map +2 -2
- package/dist/cjs/extractor/loadTamagui.js.map +1 -1
- package/dist/esm/extractor/createExtractor.js +107 -46
- package/dist/esm/extractor/createExtractor.js.map +2 -2
- package/dist/esm/extractor/loadTamagui.js.map +1 -1
- package/dist/jsx/extractor/createExtractor.js +107 -46
- package/package.json +7 -7
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/extractToClassNames.d.ts.map +1 -1
- package/types/extractor/loadTamagui.d.ts +2 -2
- package/types/extractor/loadTamagui.d.ts.map +1 -1
|
@@ -74,6 +74,15 @@ const UNTOUCHED_PROPS = {
|
|
|
74
74
|
style: true,
|
|
75
75
|
className: true
|
|
76
76
|
};
|
|
77
|
+
const INLINE_EXTRACTABLE = {
|
|
78
|
+
ref: "ref",
|
|
79
|
+
key: "key",
|
|
80
|
+
onPress: "onClick",
|
|
81
|
+
onHoverIn: "onMouseEnter",
|
|
82
|
+
onHoverOut: "onMouseLeave",
|
|
83
|
+
onPressIn: "onMouseDown",
|
|
84
|
+
onPressOut: "onMouseUp"
|
|
85
|
+
};
|
|
77
86
|
const isAttr = /* @__PURE__ */ __name((x) => x.type === "attr", "isAttr");
|
|
78
87
|
const validHooks = {
|
|
79
88
|
useMedia: true,
|
|
@@ -151,6 +160,7 @@ function createExtractor() {
|
|
|
151
160
|
return obj;
|
|
152
161
|
}, {});
|
|
153
162
|
let doesUseValidImport = false;
|
|
163
|
+
let hasImportedTheme = false;
|
|
154
164
|
for (const bodyPath of body) {
|
|
155
165
|
if (bodyPath.type !== "ImportDeclaration")
|
|
156
166
|
continue;
|
|
@@ -343,7 +353,7 @@ function createExtractor() {
|
|
|
343
353
|
}
|
|
344
354
|
let attrs = [];
|
|
345
355
|
let shouldDeopt = false;
|
|
346
|
-
|
|
356
|
+
const inlined = /* @__PURE__ */ new Map();
|
|
347
357
|
let hasSetOptimized = false;
|
|
348
358
|
attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
|
|
349
359
|
try {
|
|
@@ -395,7 +405,7 @@ function createExtractor() {
|
|
|
395
405
|
if (shouldPrintDebug) {
|
|
396
406
|
console.log(" ! inlining, spread attr");
|
|
397
407
|
}
|
|
398
|
-
|
|
408
|
+
inlined.set(`${Math.random()}`, "spread");
|
|
399
409
|
return attr;
|
|
400
410
|
}
|
|
401
411
|
const name = attribute.name.name;
|
|
@@ -406,7 +416,7 @@ function createExtractor() {
|
|
|
406
416
|
return null;
|
|
407
417
|
}
|
|
408
418
|
if (inlineProps.has(name)) {
|
|
409
|
-
|
|
419
|
+
inlined.set(name, name);
|
|
410
420
|
if (shouldPrintDebug) {
|
|
411
421
|
console.log(" ! inlining, inline prop", name);
|
|
412
422
|
}
|
|
@@ -414,7 +424,7 @@ function createExtractor() {
|
|
|
414
424
|
}
|
|
415
425
|
if (deoptProps.has(name)) {
|
|
416
426
|
shouldDeopt = true;
|
|
417
|
-
|
|
427
|
+
inlined.set(name, name);
|
|
418
428
|
if (shouldPrintDebug) {
|
|
419
429
|
console.log(" ! inlining, deopted prop", name);
|
|
420
430
|
}
|
|
@@ -423,6 +433,10 @@ function createExtractor() {
|
|
|
423
433
|
if (UNTOUCHED_PROPS[name]) {
|
|
424
434
|
return attr;
|
|
425
435
|
}
|
|
436
|
+
if (INLINE_EXTRACTABLE[name]) {
|
|
437
|
+
inlined.set(name, INLINE_EXTRACTABLE[name]);
|
|
438
|
+
return attr;
|
|
439
|
+
}
|
|
426
440
|
if (name.startsWith("data-")) {
|
|
427
441
|
return attr;
|
|
428
442
|
}
|
|
@@ -460,7 +474,7 @@ function createExtractor() {
|
|
|
460
474
|
if (shouldPrintDebug) {
|
|
461
475
|
console.log(" ! inlining, ref", name);
|
|
462
476
|
}
|
|
463
|
-
|
|
477
|
+
inlined.set("ref", "ref");
|
|
464
478
|
return attr;
|
|
465
479
|
}
|
|
466
480
|
if (name === "tag") {
|
|
@@ -475,7 +489,7 @@ function createExtractor() {
|
|
|
475
489
|
if (shouldPrintDebug) {
|
|
476
490
|
console.log(` ! inlining, native disable extract: ${name} =`, value.value);
|
|
477
491
|
}
|
|
478
|
-
|
|
492
|
+
inlined.set(name, true);
|
|
479
493
|
return attr;
|
|
480
494
|
}
|
|
481
495
|
}
|
|
@@ -492,19 +506,46 @@ function createExtractor() {
|
|
|
492
506
|
keys = Object.keys(out);
|
|
493
507
|
}
|
|
494
508
|
}
|
|
509
|
+
let didInline = false;
|
|
495
510
|
const attributes = keys.map((key) => {
|
|
496
511
|
const val = out[key];
|
|
497
|
-
if (
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
|
|
512
|
+
if (isValidStyleKey(key)) {
|
|
513
|
+
return {
|
|
514
|
+
type: "style",
|
|
515
|
+
value: { [name]: styleValue },
|
|
516
|
+
name,
|
|
517
|
+
attr: path.node
|
|
518
|
+
};
|
|
519
|
+
}
|
|
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
|
+
}
|
|
526
|
+
if (shouldPrintDebug) {
|
|
527
|
+
console.log(" ! inlining, non-static", key);
|
|
528
|
+
}
|
|
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)) {
|
|
541
|
+
if (shouldPrintDebug) {
|
|
542
|
+
console.log(` style: ${name} =`, styleValue);
|
|
543
|
+
}
|
|
544
|
+
if (!(name in staticConfig.defaultProps)) {
|
|
545
|
+
if (!hasSetOptimized) {
|
|
546
|
+
res.optimized++;
|
|
547
|
+
hasSetOptimized = true;
|
|
506
548
|
}
|
|
507
|
-
inlinePropCount++;
|
|
508
549
|
}
|
|
509
550
|
return {
|
|
510
551
|
type: "style",
|
|
@@ -512,28 +553,10 @@ function createExtractor() {
|
|
|
512
553
|
name,
|
|
513
554
|
attr: path.node
|
|
514
555
|
};
|
|
515
|
-
}
|
|
516
|
-
|
|
556
|
+
} else {
|
|
557
|
+
inlined.set(name, true);
|
|
517
558
|
return attr;
|
|
518
559
|
}
|
|
519
|
-
return attributes;
|
|
520
|
-
}
|
|
521
|
-
if (styleValue !== import_constants.FAILED_EVAL) {
|
|
522
|
-
if (shouldPrintDebug) {
|
|
523
|
-
console.log(` style: ${name} =`, styleValue);
|
|
524
|
-
}
|
|
525
|
-
if (!(name in staticConfig.defaultProps)) {
|
|
526
|
-
if (!hasSetOptimized) {
|
|
527
|
-
res.optimized++;
|
|
528
|
-
hasSetOptimized = true;
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
return {
|
|
532
|
-
type: "style",
|
|
533
|
-
value: { [name]: styleValue },
|
|
534
|
-
name,
|
|
535
|
-
attr: path.node
|
|
536
|
-
};
|
|
537
560
|
}
|
|
538
561
|
if (t.isBinaryExpression(value)) {
|
|
539
562
|
if (shouldPrintDebug) {
|
|
@@ -558,7 +581,7 @@ function createExtractor() {
|
|
|
558
581
|
if (shouldPrintDebug) {
|
|
559
582
|
console.log(` evalBinaryExpression cant extract`);
|
|
560
583
|
}
|
|
561
|
-
|
|
584
|
+
inlined.set(name, true);
|
|
562
585
|
return attr;
|
|
563
586
|
}
|
|
564
587
|
const staticConditional = getStaticConditional(value);
|
|
@@ -575,12 +598,9 @@ function createExtractor() {
|
|
|
575
598
|
}
|
|
576
599
|
return { type: "ternary", value: staticLogical };
|
|
577
600
|
}
|
|
601
|
+
inlined.set(name, true);
|
|
578
602
|
if (shouldPrintDebug) {
|
|
579
|
-
console.log(
|
|
580
|
-
}
|
|
581
|
-
inlinePropCount++;
|
|
582
|
-
if (shouldPrintDebug) {
|
|
583
|
-
console.log(` inlining ${name} = `, value);
|
|
603
|
+
console.log(` ! inline no match ${name}`, value);
|
|
584
604
|
}
|
|
585
605
|
return attr;
|
|
586
606
|
function addBinaryConditional(operator, staticExpr, cond) {
|
|
@@ -808,7 +828,32 @@ function createExtractor() {
|
|
|
808
828
|
}, {}));
|
|
809
829
|
const hasSpread = node.attributes.some((x) => t.isJSXSpreadAttribute(x));
|
|
810
830
|
const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
|
|
811
|
-
const
|
|
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 {
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
}
|
|
812
857
|
if (shouldFlatten && staticConfig.defaultProps) {
|
|
813
858
|
const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap((key) => {
|
|
814
859
|
if (!isValidStyleKey(key)) {
|
|
@@ -863,8 +908,12 @@ function createExtractor() {
|
|
|
863
908
|
if (!cur) {
|
|
864
909
|
return acc;
|
|
865
910
|
}
|
|
866
|
-
if (
|
|
867
|
-
|
|
911
|
+
if (cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value)) {
|
|
912
|
+
if (shouldFlatten) {
|
|
913
|
+
if (cur.value.name.name === "tag") {
|
|
914
|
+
return acc;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
868
917
|
}
|
|
869
918
|
if (cur.type !== "style") {
|
|
870
919
|
acc.push(cur);
|
|
@@ -1034,6 +1083,18 @@ function createExtractor() {
|
|
|
1034
1083
|
const existingStyleKeys = /* @__PURE__ */ new Set();
|
|
1035
1084
|
for (let i = attrs.length - 1; i >= 0; i--) {
|
|
1036
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];
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1037
1098
|
if (attr.type === "style") {
|
|
1038
1099
|
for (const key in attr.value) {
|
|
1039
1100
|
if (existingStyleKeys.has(key)) {
|
|
@@ -1058,7 +1119,7 @@ function createExtractor() {
|
|
|
1058
1119
|
}
|
|
1059
1120
|
}
|
|
1060
1121
|
if (shouldPrintDebug) {
|
|
1061
|
-
console.log(` \u274A\u274A inline props (${
|
|
1122
|
+
console.log(` \u274A\u274A inline props (${inlined.size}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : "");
|
|
1062
1123
|
console.log(" - attrs (end):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
1063
1124
|
}
|
|
1064
1125
|
onExtractTag({
|