@tamagui/static 1.0.0-alpha.7 → 1.0.0-beta.172
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/README.md +3 -19
- package/dist/cjs/constants.js +36 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/extractor/accessSafe.js +32 -0
- package/dist/cjs/extractor/accessSafe.js.map +7 -0
- package/dist/cjs/extractor/babelParse.js +51 -0
- package/dist/cjs/extractor/babelParse.js.map +7 -0
- package/dist/cjs/extractor/buildClassName.js +61 -0
- package/dist/cjs/extractor/buildClassName.js.map +7 -0
- package/dist/cjs/extractor/createEvaluator.js +73 -0
- package/dist/cjs/extractor/createEvaluator.js.map +7 -0
- package/dist/cjs/extractor/createExtractor.js +1100 -0
- package/dist/cjs/extractor/createExtractor.js.map +7 -0
- package/dist/cjs/extractor/ensureImportingConcat.js +45 -0
- package/dist/cjs/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/cjs/extractor/evaluateAstNode.js +115 -0
- package/dist/cjs/extractor/evaluateAstNode.js.map +7 -0
- package/dist/cjs/extractor/extractHelpers.js +124 -0
- package/dist/cjs/extractor/extractHelpers.js.map +7 -0
- package/dist/cjs/extractor/extractMediaStyle.js +186 -0
- package/dist/cjs/extractor/extractMediaStyle.js.map +7 -0
- package/dist/cjs/extractor/extractToClassNames.js +324 -0
- package/dist/cjs/extractor/extractToClassNames.js.map +7 -0
- package/dist/cjs/extractor/findTopmostFunction.js +41 -0
- package/dist/cjs/extractor/findTopmostFunction.js.map +7 -0
- package/dist/cjs/extractor/generatedUid.js +49 -0
- package/dist/cjs/extractor/generatedUid.js.map +7 -0
- package/dist/cjs/extractor/getPrefixLogs.js +29 -0
- package/dist/cjs/extractor/getPrefixLogs.js.map +7 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js +70 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +7 -0
- package/dist/cjs/extractor/getSourceModule.js +90 -0
- package/dist/cjs/extractor/getSourceModule.js.map +7 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js +149 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +7 -0
- package/dist/cjs/extractor/hoistClassNames.js +65 -0
- package/dist/cjs/extractor/hoistClassNames.js.map +7 -0
- package/dist/cjs/extractor/literalToAst.js +114 -0
- package/dist/cjs/extractor/literalToAst.js.map +7 -0
- package/dist/cjs/extractor/loadTamagui.js +83 -0
- package/dist/cjs/extractor/loadTamagui.js.map +7 -0
- package/dist/cjs/extractor/logLines.js +40 -0
- package/dist/cjs/extractor/logLines.js.map +7 -0
- package/dist/cjs/extractor/normalizeTernaries.js +101 -0
- package/dist/cjs/extractor/normalizeTernaries.js.map +7 -0
- package/dist/cjs/extractor/removeUnusedHooks.js +100 -0
- package/dist/cjs/extractor/removeUnusedHooks.js.map +7 -0
- package/dist/cjs/extractor/validHTMLAttributes.js +71 -0
- package/dist/cjs/extractor/validHTMLAttributes.js.map +7 -0
- package/dist/cjs/index.js +34 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/patchReactNativeWeb.js +151 -0
- package/dist/cjs/patchReactNativeWeb.js.map +7 -0
- package/dist/cjs/types.js +16 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/{constants.js → esm/constants.js} +4 -0
- package/dist/{constants.js.map → esm/constants.js.map} +3 -3
- package/dist/{extractor → esm/extractor}/accessSafe.js +0 -0
- package/dist/{extractor → esm/extractor}/accessSafe.js.map +2 -2
- package/dist/{extractor → esm/extractor}/babelParse.js +0 -0
- package/dist/{extractor → esm/extractor}/babelParse.js.map +2 -2
- package/dist/{extractor → esm/extractor}/buildClassName.js +0 -0
- package/dist/{extractor → esm/extractor}/buildClassName.js.map +2 -2
- package/dist/{extractor → esm/extractor}/createEvaluator.js +3 -2
- package/dist/esm/extractor/createEvaluator.js.map +7 -0
- package/dist/{extractor → esm/extractor}/createExtractor.js +430 -199
- package/dist/esm/extractor/createExtractor.js.map +7 -0
- package/dist/{extractor → esm/extractor}/ensureImportingConcat.js +1 -1
- package/dist/esm/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/{extractor → esm/extractor}/evaluateAstNode.js +0 -0
- package/dist/esm/extractor/evaluateAstNode.js.map +7 -0
- package/dist/{extractor → esm/extractor}/extractHelpers.js +20 -11
- package/dist/esm/extractor/extractHelpers.js.map +7 -0
- package/dist/{extractor → esm/extractor}/extractMediaStyle.js +3 -2
- package/dist/esm/extractor/extractMediaStyle.js.map +7 -0
- package/dist/{extractor → esm/extractor}/extractToClassNames.js +101 -48
- package/dist/esm/extractor/extractToClassNames.js.map +7 -0
- package/dist/{extractor → esm/extractor}/findTopmostFunction.js +0 -0
- package/dist/{extractor → esm/extractor}/findTopmostFunction.js.map +2 -2
- package/dist/{extractor → esm/extractor}/generatedUid.js +0 -0
- package/dist/{extractor → esm/extractor}/generatedUid.js.map +2 -2
- package/dist/esm/extractor/getPrefixLogs.js +12 -0
- package/dist/esm/extractor/getPrefixLogs.js.map +7 -0
- package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js +0 -0
- package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js.map +2 -2
- package/dist/{extractor → esm/extractor}/getSourceModule.js +0 -0
- package/dist/{extractor → esm/extractor}/getSourceModule.js.map +2 -2
- package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js +0 -0
- package/dist/esm/extractor/getStaticBindingsForScope.js.map +7 -0
- package/dist/{extractor → esm/extractor}/hoistClassNames.js +0 -0
- package/dist/{extractor → esm/extractor}/hoistClassNames.js.map +2 -2
- package/dist/esm/extractor/literalToAst.js +80 -0
- package/dist/esm/extractor/literalToAst.js.map +7 -0
- package/dist/{extractor → esm/extractor}/loadTamagui.js +27 -3
- package/dist/esm/extractor/loadTamagui.js.map +7 -0
- package/dist/esm/extractor/logLines.js +22 -0
- package/dist/esm/extractor/logLines.js.map +7 -0
- package/dist/{extractor → esm/extractor}/normalizeTernaries.js +3 -2
- package/dist/esm/extractor/normalizeTernaries.js.map +7 -0
- package/dist/{extractor → esm/extractor}/removeUnusedHooks.js +5 -3
- package/dist/esm/extractor/removeUnusedHooks.js.map +7 -0
- package/dist/esm/extractor/validHTMLAttributes.js +52 -0
- package/dist/esm/extractor/validHTMLAttributes.js.map +7 -0
- package/dist/{index.js → esm/index.js} +0 -0
- package/dist/{index.js.map → esm/index.js.map} +1 -1
- package/dist/{patchReactNativeWeb.js → esm/patchReactNativeWeb.js} +37 -14
- package/dist/esm/patchReactNativeWeb.js.map +7 -0
- package/dist/{types.js → esm/types.js} +0 -0
- package/dist/{types.js.map → esm/types.js.map} +0 -0
- package/dist/jsx/constants.js +13 -0
- package/dist/jsx/extractor/accessSafe.js +10 -0
- package/dist/jsx/extractor/babelParse.js +29 -0
- package/dist/jsx/extractor/buildClassName.js +39 -0
- package/dist/jsx/extractor/createEvaluator.js +51 -0
- package/dist/jsx/extractor/createExtractor.js +1050 -0
- package/dist/jsx/extractor/ensureImportingConcat.js +23 -0
- package/dist/jsx/extractor/evaluateAstNode.js +93 -0
- package/dist/jsx/extractor/extractHelpers.js +102 -0
- package/dist/jsx/extractor/extractMediaStyle.js +151 -0
- package/dist/jsx/extractor/extractToClassNames.js +287 -0
- package/dist/jsx/extractor/findTopmostFunction.js +22 -0
- package/dist/jsx/extractor/generatedUid.js +27 -0
- package/dist/jsx/extractor/getPrefixLogs.js +11 -0
- package/dist/jsx/extractor/getPropValueFromAttributes.js +48 -0
- package/dist/jsx/extractor/getSourceModule.js +68 -0
- package/dist/jsx/extractor/getStaticBindingsForScope.js +127 -0
- package/dist/jsx/extractor/hoistClassNames.js +43 -0
- package/dist/jsx/extractor/literalToAst.js +79 -0
- package/dist/jsx/extractor/loadTamagui.js +64 -0
- package/dist/jsx/extractor/logLines.js +21 -0
- package/dist/jsx/extractor/normalizeTernaries.js +52 -0
- package/dist/jsx/extractor/removeUnusedHooks.js +79 -0
- package/dist/jsx/extractor/validHTMLAttributes.js +51 -0
- package/dist/jsx/index.js +13 -0
- package/{src/patchReactNativeWeb.ts → dist/jsx/patchReactNativeWeb.js} +65 -59
- package/dist/jsx/types.js +0 -0
- package/package.json +26 -22
- package/types/constants.d.ts +6 -0
- package/types/constants.d.ts.map +1 -0
- package/types/extractor/accessSafe.d.ts +3 -0
- package/types/extractor/accessSafe.d.ts.map +1 -0
- package/types/extractor/babelParse.d.ts +5 -0
- package/types/extractor/babelParse.d.ts.map +1 -0
- package/types/extractor/buildClassName.d.ts +4 -0
- package/types/extractor/buildClassName.d.ts.map +1 -0
- package/types/extractor/createEvaluator.d.ts +12 -0
- package/types/extractor/createEvaluator.d.ts.map +1 -0
- package/types/extractor/createExtractor.d.ts +27 -0
- package/types/extractor/createExtractor.d.ts.map +1 -0
- package/types/extractor/ensureImportingConcat.d.ts +4 -0
- package/types/extractor/ensureImportingConcat.d.ts.map +1 -0
- package/types/extractor/evaluateAstNode.d.ts +3 -0
- package/types/extractor/evaluateAstNode.d.ts.map +1 -0
- package/types/extractor/extractHelpers.d.ts +12 -0
- package/types/extractor/extractHelpers.d.ts.map +1 -0
- package/types/extractor/extractMediaStyle.d.ts +10 -0
- package/types/extractor/extractMediaStyle.d.ts.map +1 -0
- package/types/extractor/extractToClassNames.d.ts +23 -0
- package/types/extractor/extractToClassNames.d.ts.map +1 -0
- package/types/extractor/findTopmostFunction.d.ts +4 -0
- package/types/extractor/findTopmostFunction.d.ts.map +1 -0
- package/types/extractor/generatedUid.d.ts +5 -0
- package/types/extractor/generatedUid.d.ts.map +1 -0
- package/types/extractor/getPrefixLogs.d.ts +3 -0
- package/types/extractor/getPrefixLogs.d.ts.map +1 -0
- package/types/extractor/getPropValueFromAttributes.d.ts +3 -0
- package/types/extractor/getPropValueFromAttributes.d.ts.map +1 -0
- package/types/extractor/getSourceModule.d.ts +16 -0
- package/types/extractor/getSourceModule.d.ts.map +1 -0
- package/types/extractor/getStaticBindingsForScope.d.ts +4 -0
- package/types/extractor/getStaticBindingsForScope.d.ts.map +1 -0
- package/types/extractor/hoistClassNames.d.ts +6 -0
- package/types/extractor/hoistClassNames.d.ts.map +1 -0
- package/types/extractor/literalToAst.d.ts +4 -0
- package/types/extractor/literalToAst.d.ts.map +1 -0
- package/types/extractor/loadTamagui.d.ts +9 -0
- package/types/extractor/loadTamagui.d.ts.map +1 -0
- package/types/extractor/logLines.d.ts +2 -0
- package/types/extractor/logLines.d.ts.map +1 -0
- package/types/extractor/normalizeTernaries.d.ts +3 -0
- package/types/extractor/normalizeTernaries.d.ts.map +1 -0
- package/types/extractor/removeUnusedHooks.d.ts +3 -0
- package/types/extractor/removeUnusedHooks.d.ts.map +1 -0
- package/types/extractor/validHTMLAttributes.d.ts +49 -0
- package/types/extractor/validHTMLAttributes.d.ts.map +1 -0
- package/types/index.d.ts +8 -0
- package/types/index.d.ts.map +1 -0
- package/types/patchReactNativeWeb.d.ts +2 -0
- package/types/patchReactNativeWeb.d.ts.map +1 -0
- package/types/types.d.ts +85 -0
- package/types/types.d.ts.map +1 -0
- package/dist/extractor/createEvaluator.js.map +0 -7
- package/dist/extractor/createExtractor.js.map +0 -7
- package/dist/extractor/ensureImportingConcat.js.map +0 -7
- package/dist/extractor/evaluateAstNode.js.map +0 -7
- package/dist/extractor/extractHelpers.js.map +0 -7
- package/dist/extractor/extractMediaStyle.js.map +0 -7
- package/dist/extractor/extractToClassNames.js.map +0 -7
- package/dist/extractor/getStaticBindingsForScope.js.map +0 -7
- package/dist/extractor/literalToAst.js +0 -34
- package/dist/extractor/literalToAst.js.map +0 -7
- package/dist/extractor/loadTamagui.js.map +0 -7
- package/dist/extractor/normalizeTernaries.js.map +0 -7
- package/dist/extractor/removeUnusedHooks.js.map +0 -7
- package/dist/index.cjs +0 -2109
- package/dist/index.cjs.map +0 -7
- package/dist/patchReactNativeWeb.js.map +0 -7
- package/src/constants.ts +0 -10
- package/src/extractor/accessSafe.ts +0 -18
- package/src/extractor/babelParse.ts +0 -27
- package/src/extractor/buildClassName.ts +0 -61
- package/src/extractor/createEvaluator.ts +0 -68
- package/src/extractor/createExtractor.ts +0 -1139
- package/src/extractor/ensureImportingConcat.ts +0 -33
- package/src/extractor/evaluateAstNode.ts +0 -121
- package/src/extractor/extractHelpers.ts +0 -102
- package/src/extractor/extractMediaStyle.ts +0 -191
- package/src/extractor/extractToClassNames.ts +0 -326
- package/src/extractor/findTopmostFunction.ts +0 -22
- package/src/extractor/generatedUid.ts +0 -43
- package/src/extractor/getPropValueFromAttributes.ts +0 -92
- package/src/extractor/getSourceModule.ts +0 -101
- package/src/extractor/getStaticBindingsForScope.ts +0 -173
- package/src/extractor/hoistClassNames.ts +0 -45
- package/src/extractor/literalToAst.ts +0 -32
- package/src/extractor/loadTamagui.ts +0 -61
- package/src/extractor/normalizeTernaries.ts +0 -60
- package/src/extractor/removeUnusedHooks.ts +0 -76
- package/src/index.ts +0 -9
- package/src/types.ts +0 -84
- package/types.d.ts +0 -217
package/dist/index.cjs
DELETED
|
@@ -1,2109 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
25
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
26
|
-
var __objRest = (source, exclude) => {
|
|
27
|
-
var target = {};
|
|
28
|
-
for (var prop in source)
|
|
29
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
30
|
-
target[prop] = source[prop];
|
|
31
|
-
if (source != null && __getOwnPropSymbols)
|
|
32
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
33
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
34
|
-
target[prop] = source[prop];
|
|
35
|
-
}
|
|
36
|
-
return target;
|
|
37
|
-
};
|
|
38
|
-
var __export = (target, all) => {
|
|
39
|
-
__markAsModule(target);
|
|
40
|
-
for (var name in all)
|
|
41
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
42
|
-
};
|
|
43
|
-
var __reExport = (target, module2, desc) => {
|
|
44
|
-
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
45
|
-
for (let key of __getOwnPropNames(module2))
|
|
46
|
-
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
47
|
-
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
48
|
-
}
|
|
49
|
-
return target;
|
|
50
|
-
};
|
|
51
|
-
var __toModule = (module2) => {
|
|
52
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// src/index.ts
|
|
56
|
-
__export(exports, {
|
|
57
|
-
CONCAT_CLASSNAME_IMPORT: () => CONCAT_CLASSNAME_IMPORT,
|
|
58
|
-
CSS_FILE_NAME: () => CSS_FILE_NAME,
|
|
59
|
-
MEDIA_SEP: () => MEDIA_SEP,
|
|
60
|
-
attrStr: () => attrStr,
|
|
61
|
-
cacheDir: () => cacheDir,
|
|
62
|
-
createExtractor: () => createExtractor,
|
|
63
|
-
extractToClassNames: () => extractToClassNames,
|
|
64
|
-
findComponentName: () => findComponentName,
|
|
65
|
-
isInsideTamagui: () => isInsideTamagui,
|
|
66
|
-
isPresent: () => isPresent,
|
|
67
|
-
isSimpleSpread: () => isSimpleSpread,
|
|
68
|
-
isValidThemeHook: () => isValidThemeHook,
|
|
69
|
-
literalToAst: () => literalToAst,
|
|
70
|
-
objToStr: () => objToStr,
|
|
71
|
-
patchReactNativeWeb: () => patchReactNativeWeb,
|
|
72
|
-
ternaryStr: () => ternaryStr
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// src/extractor/createExtractor.ts
|
|
76
|
-
var import_traverse = __toModule(require("@babel/traverse"));
|
|
77
|
-
var t9 = __toModule(require("@babel/types"));
|
|
78
|
-
var CoreNode = __toModule(require("@tamagui/core-node"));
|
|
79
|
-
var import_helpers = __toModule(require("@tamagui/helpers"));
|
|
80
|
-
var import_lodash = __toModule(require("lodash"));
|
|
81
|
-
|
|
82
|
-
// src/extractor/createEvaluator.ts
|
|
83
|
-
var import_vm = __toModule(require("vm"));
|
|
84
|
-
var import_generator = __toModule(require("@babel/generator"));
|
|
85
|
-
var t3 = __toModule(require("@babel/types"));
|
|
86
|
-
|
|
87
|
-
// src/extractor/evaluateAstNode.ts
|
|
88
|
-
var t = __toModule(require("@babel/types"));
|
|
89
|
-
function evaluateAstNode(exprNode, evalFn, shouldPrintDebug) {
|
|
90
|
-
if (exprNode === void 0) {
|
|
91
|
-
return void 0;
|
|
92
|
-
}
|
|
93
|
-
if (exprNode === null) {
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
if (t.isJSXExpressionContainer(exprNode)) {
|
|
97
|
-
return evaluateAstNode(exprNode.expression);
|
|
98
|
-
}
|
|
99
|
-
if (t.isObjectExpression(exprNode)) {
|
|
100
|
-
const ret = {};
|
|
101
|
-
for (let idx = -1, len = exprNode.properties.length; ++idx < len; ) {
|
|
102
|
-
const value = exprNode.properties[idx];
|
|
103
|
-
if (!t.isObjectProperty(value)) {
|
|
104
|
-
throw new Error("evaluateAstNode can only evaluate object properties");
|
|
105
|
-
}
|
|
106
|
-
let key;
|
|
107
|
-
if (value.computed) {
|
|
108
|
-
if (typeof evalFn !== "function") {
|
|
109
|
-
throw new Error("evaluateAstNode does not support computed keys unless an eval function is provided");
|
|
110
|
-
}
|
|
111
|
-
key = evaluateAstNode(value.key, evalFn);
|
|
112
|
-
} else if (t.isIdentifier(value.key)) {
|
|
113
|
-
key = value.key.name;
|
|
114
|
-
} else if (t.isStringLiteral(value.key) || t.isNumericLiteral(value.key)) {
|
|
115
|
-
key = value.key.value;
|
|
116
|
-
} else {
|
|
117
|
-
throw new Error("Unsupported key type: " + value.key.type);
|
|
118
|
-
}
|
|
119
|
-
if (typeof key !== "string" && typeof key !== "number") {
|
|
120
|
-
throw new Error("key must be either a string or a number");
|
|
121
|
-
}
|
|
122
|
-
ret[key] = evaluateAstNode(value.value, evalFn);
|
|
123
|
-
}
|
|
124
|
-
return ret;
|
|
125
|
-
}
|
|
126
|
-
if (t.isArrayExpression(exprNode)) {
|
|
127
|
-
return exprNode.elements.map((x) => {
|
|
128
|
-
return evaluateAstNode(x, evalFn);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
if (t.isUnaryExpression(exprNode) && exprNode.operator === "-") {
|
|
132
|
-
const ret = evaluateAstNode(exprNode.argument, evalFn);
|
|
133
|
-
if (ret == null) {
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
return -ret;
|
|
137
|
-
}
|
|
138
|
-
if (t.isTemplateLiteral(exprNode)) {
|
|
139
|
-
if (typeof evalFn !== "function") {
|
|
140
|
-
throw new Error("evaluateAstNode does not support template literals unless an eval function is provided");
|
|
141
|
-
}
|
|
142
|
-
let ret = "";
|
|
143
|
-
for (let idx = -1, len = exprNode.quasis.length; ++idx < len; ) {
|
|
144
|
-
const quasi = exprNode.quasis[idx];
|
|
145
|
-
const expr = exprNode.expressions[idx];
|
|
146
|
-
ret += quasi.value.raw;
|
|
147
|
-
if (expr) {
|
|
148
|
-
ret += evaluateAstNode(expr, evalFn);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return ret;
|
|
152
|
-
}
|
|
153
|
-
if (t.isNullLiteral(exprNode)) {
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
if (t.isNumericLiteral(exprNode) || t.isStringLiteral(exprNode) || t.isBooleanLiteral(exprNode)) {
|
|
157
|
-
return exprNode.value;
|
|
158
|
-
}
|
|
159
|
-
if (t.isBinaryExpression(exprNode)) {
|
|
160
|
-
if (exprNode.operator === "+") {
|
|
161
|
-
return evaluateAstNode(exprNode.left, evalFn) + evaluateAstNode(exprNode.right, evalFn);
|
|
162
|
-
} else if (exprNode.operator === "-") {
|
|
163
|
-
return evaluateAstNode(exprNode.left, evalFn) - evaluateAstNode(exprNode.right, evalFn);
|
|
164
|
-
} else if (exprNode.operator === "*") {
|
|
165
|
-
return evaluateAstNode(exprNode.left, evalFn) * evaluateAstNode(exprNode.right, evalFn);
|
|
166
|
-
} else if (exprNode.operator === "/") {
|
|
167
|
-
return evaluateAstNode(exprNode.left, evalFn) / evaluateAstNode(exprNode.right, evalFn);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (typeof evalFn !== "function") {
|
|
171
|
-
throw new Error("evaluateAstNode does not support non-literal values unless an eval function is provided");
|
|
172
|
-
}
|
|
173
|
-
return evalFn(exprNode);
|
|
174
|
-
}
|
|
175
|
-
__name(evaluateAstNode, "evaluateAstNode");
|
|
176
|
-
|
|
177
|
-
// src/extractor/extractHelpers.ts
|
|
178
|
-
var t2 = __toModule(require("@babel/types"));
|
|
179
|
-
function isPresent(input) {
|
|
180
|
-
return input != null;
|
|
181
|
-
}
|
|
182
|
-
__name(isPresent, "isPresent");
|
|
183
|
-
function isSimpleSpread(node) {
|
|
184
|
-
return t2.isIdentifier(node.argument) || t2.isMemberExpression(node.argument);
|
|
185
|
-
}
|
|
186
|
-
__name(isSimpleSpread, "isSimpleSpread");
|
|
187
|
-
var attrStr = /* @__PURE__ */ __name((attr) => {
|
|
188
|
-
return attr.type === "attr" ? getNameAttr(attr.value) : attr.type === "ternary" ? `...${ternaryStr(attr.value)}` : `${attr.type}(${objToStr(attr.value)})`;
|
|
189
|
-
}, "attrStr");
|
|
190
|
-
var objToStr = /* @__PURE__ */ __name((obj) => {
|
|
191
|
-
return Object.entries(obj).map(([k, v]) => `${k}:${Array.isArray(v) ? `[...]` : v && typeof v === "object" ? `{${objToStr(v)}}` : v}`).join(", ");
|
|
192
|
-
}, "objToStr");
|
|
193
|
-
var getNameAttr = /* @__PURE__ */ __name((attr) => {
|
|
194
|
-
if (t2.isJSXSpreadAttribute(attr)) {
|
|
195
|
-
return `...${attr.argument["name"]}`;
|
|
196
|
-
}
|
|
197
|
-
return "name" in attr ? attr.name.name : `unknown-${attr["type"]}`;
|
|
198
|
-
}, "getNameAttr");
|
|
199
|
-
var ternaryStr = /* @__PURE__ */ __name((x) => {
|
|
200
|
-
return [
|
|
201
|
-
"ternary:",
|
|
202
|
-
t2.isIdentifier(x.test) ? x.test.name : t2.isMemberExpression(x.test) ? [x.test.object["name"], x.test.property["name"]] : x.test,
|
|
203
|
-
x.consequent ? ` ? ${objToStr(x.consequent)}` : " ? \u26AB\uFE0F",
|
|
204
|
-
x.alternate ? ` : ${objToStr(x.alternate)}` : " : \u26AB\uFE0F"
|
|
205
|
-
].flat().join("");
|
|
206
|
-
}, "ternaryStr");
|
|
207
|
-
function findComponentName(scope) {
|
|
208
|
-
var _a;
|
|
209
|
-
let componentName = "";
|
|
210
|
-
let cur = scope.path;
|
|
211
|
-
while (cur.parentPath && !t2.isProgram(cur.parentPath.parent)) {
|
|
212
|
-
cur = cur.parentPath;
|
|
213
|
-
}
|
|
214
|
-
let node = cur.parent;
|
|
215
|
-
if (t2.isExportNamedDeclaration(node)) {
|
|
216
|
-
node = node.declaration;
|
|
217
|
-
}
|
|
218
|
-
if (t2.isVariableDeclaration(node)) {
|
|
219
|
-
const [dec] = node.declarations;
|
|
220
|
-
if (t2.isVariableDeclarator(dec) && t2.isIdentifier(dec.id)) {
|
|
221
|
-
return dec.id.name;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
if (t2.isFunctionDeclaration(node)) {
|
|
225
|
-
return (_a = node.id) == null ? void 0 : _a.name;
|
|
226
|
-
}
|
|
227
|
-
return componentName;
|
|
228
|
-
}
|
|
229
|
-
__name(findComponentName, "findComponentName");
|
|
230
|
-
function isValidThemeHook(jsxPath, n, sourcePath) {
|
|
231
|
-
var _a;
|
|
232
|
-
if (!t2.isIdentifier(n.object) || !t2.isIdentifier(n.property))
|
|
233
|
-
return false;
|
|
234
|
-
const bindings = jsxPath.scope.getAllBindings();
|
|
235
|
-
const binding = bindings[n.object.name];
|
|
236
|
-
if (!(binding == null ? void 0 : binding.path))
|
|
237
|
-
return false;
|
|
238
|
-
if (!binding.path.isVariableDeclarator())
|
|
239
|
-
return false;
|
|
240
|
-
const init = binding.path.node.init;
|
|
241
|
-
if (!t2.isCallExpression(init))
|
|
242
|
-
return false;
|
|
243
|
-
if (!t2.isIdentifier(init.callee))
|
|
244
|
-
return false;
|
|
245
|
-
if (init.callee.name !== "useTheme")
|
|
246
|
-
return false;
|
|
247
|
-
const importNode = (_a = binding.scope.getBinding("useTheme")) == null ? void 0 : _a.path.parent;
|
|
248
|
-
if (!t2.isImportDeclaration(importNode))
|
|
249
|
-
return false;
|
|
250
|
-
if (importNode.source.value !== "tamagui") {
|
|
251
|
-
if (!isInsideTamagui(sourcePath)) {
|
|
252
|
-
return false;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return true;
|
|
256
|
-
}
|
|
257
|
-
__name(isValidThemeHook, "isValidThemeHook");
|
|
258
|
-
var isInsideTamagui = /* @__PURE__ */ __name((srcName) => {
|
|
259
|
-
return srcName.includes("/tamagui/_jsx") || srcName.includes("/core/src");
|
|
260
|
-
}, "isInsideTamagui");
|
|
261
|
-
|
|
262
|
-
// src/extractor/createEvaluator.ts
|
|
263
|
-
function createEvaluator({
|
|
264
|
-
tamaguiConfig,
|
|
265
|
-
staticNamespace,
|
|
266
|
-
sourcePath,
|
|
267
|
-
traversePath,
|
|
268
|
-
shouldPrintDebug
|
|
269
|
-
}) {
|
|
270
|
-
const evalFn = /* @__PURE__ */ __name((n) => {
|
|
271
|
-
if (t3.isMemberExpression(n) && t3.isIdentifier(n.property) && isValidThemeHook(traversePath, n, sourcePath)) {
|
|
272
|
-
const key = n.property.name;
|
|
273
|
-
if (shouldPrintDebug) {
|
|
274
|
-
console.log(" > found theme prop", key);
|
|
275
|
-
}
|
|
276
|
-
console.log("SHOULD FIND THEME (NESTED NOW)", key);
|
|
277
|
-
return `var(--${key})`;
|
|
278
|
-
}
|
|
279
|
-
if (t3.isIdentifier(n) && staticNamespace.hasOwnProperty(n.name)) {
|
|
280
|
-
return staticNamespace[n.name];
|
|
281
|
-
}
|
|
282
|
-
const evalContext = import_vm.default.createContext(staticNamespace);
|
|
283
|
-
const code = `(${(0, import_generator.default)(n).code})`;
|
|
284
|
-
return import_vm.default.runInContext(code, evalContext);
|
|
285
|
-
}, "evalFn");
|
|
286
|
-
return (n) => {
|
|
287
|
-
return evaluateAstNode(n, evalFn);
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
__name(createEvaluator, "createEvaluator");
|
|
291
|
-
function createSafeEvaluator(attemptEval) {
|
|
292
|
-
return (n) => {
|
|
293
|
-
try {
|
|
294
|
-
return attemptEval(n);
|
|
295
|
-
} catch (err) {
|
|
296
|
-
return FAILED_EVAL;
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
__name(createSafeEvaluator, "createSafeEvaluator");
|
|
301
|
-
|
|
302
|
-
// src/extractor/findTopmostFunction.ts
|
|
303
|
-
function findTopmostFunction(jsxPath) {
|
|
304
|
-
const isFunction = /* @__PURE__ */ __name((path3) => path3.isArrowFunctionExpression() || path3.isFunctionDeclaration() || path3.isFunctionExpression(), "isFunction");
|
|
305
|
-
let compFn = jsxPath.findParent(isFunction);
|
|
306
|
-
while (compFn) {
|
|
307
|
-
const parent = compFn.findParent(isFunction);
|
|
308
|
-
if (parent) {
|
|
309
|
-
compFn = parent;
|
|
310
|
-
} else {
|
|
311
|
-
break;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
if (!compFn) {
|
|
315
|
-
return null;
|
|
316
|
-
}
|
|
317
|
-
return compFn;
|
|
318
|
-
}
|
|
319
|
-
__name(findTopmostFunction, "findTopmostFunction");
|
|
320
|
-
|
|
321
|
-
// src/extractor/getStaticBindingsForScope.ts
|
|
322
|
-
var import_path = __toModule(require("path"));
|
|
323
|
-
var t5 = __toModule(require("@babel/types"));
|
|
324
|
-
var import_fs_extra = __toModule(require("fs-extra"));
|
|
325
|
-
|
|
326
|
-
// src/extractor/getSourceModule.ts
|
|
327
|
-
var t4 = __toModule(require("@babel/types"));
|
|
328
|
-
function getSourceModule(itemName, itemBinding) {
|
|
329
|
-
if (!itemBinding.constant) {
|
|
330
|
-
return null;
|
|
331
|
-
}
|
|
332
|
-
let sourceModule;
|
|
333
|
-
let imported;
|
|
334
|
-
let local;
|
|
335
|
-
let destructured;
|
|
336
|
-
let usesImportSyntax = false;
|
|
337
|
-
const itemNode = itemBinding.path.node;
|
|
338
|
-
if (t4.isImportDefaultSpecifier(itemNode) || t4.isImportSpecifier(itemNode)) {
|
|
339
|
-
if (t4.isImportDeclaration(itemBinding.path.parent)) {
|
|
340
|
-
sourceModule = itemBinding.path.parent.source.value;
|
|
341
|
-
local = itemNode.local.name;
|
|
342
|
-
usesImportSyntax = true;
|
|
343
|
-
if (t4.isImportSpecifier(itemNode)) {
|
|
344
|
-
imported = itemNode.imported["name"];
|
|
345
|
-
destructured = true;
|
|
346
|
-
} else {
|
|
347
|
-
imported = itemNode.local.name;
|
|
348
|
-
destructured = false;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
} else if (t4.isVariableDeclarator(itemNode) && itemNode.init != null && t4.isCallExpression(itemNode.init) && t4.isIdentifier(itemNode.init.callee) && itemNode.init.callee.name === "require" && itemNode.init.arguments.length === 1) {
|
|
352
|
-
const firstArg = itemNode.init.arguments[0];
|
|
353
|
-
if (!t4.isStringLiteral(firstArg)) {
|
|
354
|
-
return null;
|
|
355
|
-
}
|
|
356
|
-
sourceModule = firstArg.value;
|
|
357
|
-
if (t4.isIdentifier(itemNode.id)) {
|
|
358
|
-
local = itemNode.id.name;
|
|
359
|
-
imported = itemNode.id.name;
|
|
360
|
-
destructured = false;
|
|
361
|
-
} else if (t4.isObjectPattern(itemNode.id)) {
|
|
362
|
-
for (const objProp of itemNode.id.properties) {
|
|
363
|
-
if (t4.isObjectProperty(objProp) && t4.isIdentifier(objProp.value) && objProp.value.name === itemName) {
|
|
364
|
-
local = objProp.value.name;
|
|
365
|
-
imported = objProp.key.name;
|
|
366
|
-
destructured = true;
|
|
367
|
-
break;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
if (!local || !imported) {
|
|
371
|
-
console.error("could not find prop with value `%s`", itemName);
|
|
372
|
-
return null;
|
|
373
|
-
}
|
|
374
|
-
} else {
|
|
375
|
-
console.error("Unhandled id type: %s", itemNode.id.type);
|
|
376
|
-
return null;
|
|
377
|
-
}
|
|
378
|
-
} else {
|
|
379
|
-
return null;
|
|
380
|
-
}
|
|
381
|
-
return {
|
|
382
|
-
destructured,
|
|
383
|
-
imported,
|
|
384
|
-
local,
|
|
385
|
-
sourceModule,
|
|
386
|
-
usesImportSyntax
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
__name(getSourceModule, "getSourceModule");
|
|
390
|
-
|
|
391
|
-
// src/extractor/getStaticBindingsForScope.ts
|
|
392
|
-
var isLocalImport = /* @__PURE__ */ __name((path3) => path3.startsWith(".") || path3.startsWith("/"), "isLocalImport");
|
|
393
|
-
function resolveImportPath(sourcePath, path3) {
|
|
394
|
-
const sourceDir = (0, import_path.dirname)(sourcePath);
|
|
395
|
-
if (isLocalImport(path3)) {
|
|
396
|
-
if ((0, import_path.extname)(path3) === "") {
|
|
397
|
-
path3 += ".js";
|
|
398
|
-
}
|
|
399
|
-
return (0, import_path.resolve)(sourceDir, path3);
|
|
400
|
-
}
|
|
401
|
-
return path3;
|
|
402
|
-
}
|
|
403
|
-
__name(resolveImportPath, "resolveImportPath");
|
|
404
|
-
function importModule(path3) {
|
|
405
|
-
const filenames = [path3.replace(".js", ".tsx"), path3.replace(".js", ".ts"), path3];
|
|
406
|
-
for (const file of filenames) {
|
|
407
|
-
if ((0, import_fs_extra.existsSync)(file)) {
|
|
408
|
-
return require(file);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
return null;
|
|
412
|
-
}
|
|
413
|
-
__name(importModule, "importModule");
|
|
414
|
-
function getStaticBindingsForScope(scope, whitelist = [], sourcePath, bindingCache, shouldPrintDebug) {
|
|
415
|
-
const bindings = scope.getAllBindings();
|
|
416
|
-
const ret = {};
|
|
417
|
-
if (shouldPrintDebug) {
|
|
418
|
-
console.log(" ", Object.keys(bindings).length, "variables in scope");
|
|
419
|
-
}
|
|
420
|
-
const program = scope.getProgramParent().block;
|
|
421
|
-
for (const node of program.body) {
|
|
422
|
-
if (t5.isImportDeclaration(node)) {
|
|
423
|
-
const importPath = node.source.value;
|
|
424
|
-
if (!node.specifiers.length)
|
|
425
|
-
continue;
|
|
426
|
-
if (!isLocalImport(importPath)) {
|
|
427
|
-
continue;
|
|
428
|
-
}
|
|
429
|
-
const moduleName = resolveImportPath(sourcePath, importPath);
|
|
430
|
-
const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test));
|
|
431
|
-
if (!isOnWhitelist)
|
|
432
|
-
continue;
|
|
433
|
-
const src = importModule(moduleName);
|
|
434
|
-
if (!src)
|
|
435
|
-
continue;
|
|
436
|
-
for (const specifier of node.specifiers) {
|
|
437
|
-
if (t5.isImportSpecifier(specifier) && t5.isIdentifier(specifier.imported)) {
|
|
438
|
-
if (typeof src[specifier.imported.name] !== "undefined") {
|
|
439
|
-
const val = src[specifier.local.name];
|
|
440
|
-
ret[specifier.local.name] = val;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
if (!bindingCache) {
|
|
447
|
-
throw new Error("bindingCache is a required param");
|
|
448
|
-
}
|
|
449
|
-
for (const k in bindings) {
|
|
450
|
-
const binding = bindings[k];
|
|
451
|
-
const sourceModule = getSourceModule(k, binding);
|
|
452
|
-
if (sourceModule) {
|
|
453
|
-
if (!sourceModule.sourceModule) {
|
|
454
|
-
continue;
|
|
455
|
-
}
|
|
456
|
-
const moduleName = resolveImportPath(sourcePath, sourceModule.sourceModule);
|
|
457
|
-
const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test));
|
|
458
|
-
if (isOnWhitelist) {
|
|
459
|
-
const src = importModule(moduleName);
|
|
460
|
-
if (!src) {
|
|
461
|
-
console.log(`\u26A0\uFE0F missing file ${moduleName} via ${sourcePath} import ${sourceModule.sourceModule}?`);
|
|
462
|
-
return {};
|
|
463
|
-
}
|
|
464
|
-
if (sourceModule.destructured) {
|
|
465
|
-
if (sourceModule.imported) {
|
|
466
|
-
ret[k] = src[sourceModule.imported];
|
|
467
|
-
}
|
|
468
|
-
} else {
|
|
469
|
-
ret[k] = src;
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
continue;
|
|
473
|
-
}
|
|
474
|
-
const { parent, parentPath } = binding.path;
|
|
475
|
-
if (!t5.isVariableDeclaration(parent) || parent.kind !== "const") {
|
|
476
|
-
continue;
|
|
477
|
-
}
|
|
478
|
-
const dec = parent.declarations.find((d) => t5.isIdentifier(d.id) && d.id.name === k);
|
|
479
|
-
if (!dec || !dec.init) {
|
|
480
|
-
continue;
|
|
481
|
-
}
|
|
482
|
-
if (typeof dec.id.start !== "number" || typeof dec.id.end !== "number") {
|
|
483
|
-
console.error("dec.id.start/end is not a number");
|
|
484
|
-
continue;
|
|
485
|
-
}
|
|
486
|
-
if (!t5.isIdentifier(dec.id)) {
|
|
487
|
-
console.error("dec is not an identifier");
|
|
488
|
-
continue;
|
|
489
|
-
}
|
|
490
|
-
const cacheKey = `${dec.id.name}_${dec.id.start}-${dec.id.end}`;
|
|
491
|
-
if (bindingCache.hasOwnProperty(cacheKey)) {
|
|
492
|
-
ret[k] = bindingCache[cacheKey];
|
|
493
|
-
continue;
|
|
494
|
-
}
|
|
495
|
-
if (bindingCache.hasOwnProperty(cacheKey)) {
|
|
496
|
-
ret[k] = bindingCache[cacheKey];
|
|
497
|
-
continue;
|
|
498
|
-
}
|
|
499
|
-
try {
|
|
500
|
-
ret[k] = evaluateAstNode(dec.init, void 0, shouldPrintDebug);
|
|
501
|
-
bindingCache[cacheKey] = ret[k];
|
|
502
|
-
continue;
|
|
503
|
-
} catch (e) {
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
return ret;
|
|
507
|
-
}
|
|
508
|
-
__name(getStaticBindingsForScope, "getStaticBindingsForScope");
|
|
509
|
-
|
|
510
|
-
// src/extractor/literalToAst.ts
|
|
511
|
-
var t6 = __toModule(require("@babel/types"));
|
|
512
|
-
function literalToAst(literal) {
|
|
513
|
-
if (literal === null) {
|
|
514
|
-
return t6.nullLiteral();
|
|
515
|
-
}
|
|
516
|
-
switch (typeof literal) {
|
|
517
|
-
case "function":
|
|
518
|
-
throw new Error("Unsupported");
|
|
519
|
-
case "number":
|
|
520
|
-
return t6.numericLiteral(literal);
|
|
521
|
-
case "string":
|
|
522
|
-
return t6.stringLiteral(literal);
|
|
523
|
-
case "boolean":
|
|
524
|
-
return t6.booleanLiteral(literal);
|
|
525
|
-
case "undefined":
|
|
526
|
-
return t6.unaryExpression("void", t6.numericLiteral(0), true);
|
|
527
|
-
default:
|
|
528
|
-
if (Array.isArray(literal)) {
|
|
529
|
-
return t6.arrayExpression(literal.map(literalToAst));
|
|
530
|
-
}
|
|
531
|
-
return t6.objectExpression(Object.keys(literal).filter((k) => {
|
|
532
|
-
return typeof literal[k] !== "undefined";
|
|
533
|
-
}).map((k) => {
|
|
534
|
-
return t6.objectProperty(t6.stringLiteral(k), literalToAst(literal[k]));
|
|
535
|
-
}));
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
__name(literalToAst, "literalToAst");
|
|
539
|
-
|
|
540
|
-
// src/extractor/loadTamagui.ts
|
|
541
|
-
var import_path2 = __toModule(require("path"));
|
|
542
|
-
var import_core_node = __toModule(require("@tamagui/core-node"));
|
|
543
|
-
var loadedTamagui = null;
|
|
544
|
-
function loadTamagui(props) {
|
|
545
|
-
if (loadedTamagui) {
|
|
546
|
-
return loadedTamagui;
|
|
547
|
-
}
|
|
548
|
-
process.env.IS_STATIC = "is_static";
|
|
549
|
-
const proxyWorm = require("@tamagui/fake-react-native");
|
|
550
|
-
const Mod = require("module");
|
|
551
|
-
const og = Mod.prototype.require;
|
|
552
|
-
Mod.prototype.require = function(path3) {
|
|
553
|
-
if (path3.startsWith("react-native") && !path3.startsWith("react-native-web/dist/cjs/exports")) {
|
|
554
|
-
return proxyWorm;
|
|
555
|
-
}
|
|
556
|
-
return og.apply(this, arguments);
|
|
557
|
-
};
|
|
558
|
-
const configPath = (0, import_path2.join)(process.cwd(), props.config);
|
|
559
|
-
const tamaguiConfigExport = require(configPath);
|
|
560
|
-
const tamaguiConfig = tamaguiConfigExport["default"] || tamaguiConfigExport;
|
|
561
|
-
const components = {};
|
|
562
|
-
for (const module2 of props.components) {
|
|
563
|
-
const exported = require(module2);
|
|
564
|
-
Object.assign(components, exported);
|
|
565
|
-
}
|
|
566
|
-
process.env.IS_STATIC = void 0;
|
|
567
|
-
Mod.prototype.require = og;
|
|
568
|
-
(0, import_core_node.createTamagui)(tamaguiConfig);
|
|
569
|
-
loadedTamagui = {
|
|
570
|
-
components,
|
|
571
|
-
tamaguiConfig
|
|
572
|
-
};
|
|
573
|
-
return loadedTamagui;
|
|
574
|
-
}
|
|
575
|
-
__name(loadTamagui, "loadTamagui");
|
|
576
|
-
|
|
577
|
-
// src/extractor/normalizeTernaries.ts
|
|
578
|
-
var import_generator2 = __toModule(require("@babel/generator"));
|
|
579
|
-
var t7 = __toModule(require("@babel/types"));
|
|
580
|
-
var import_invariant = __toModule(require("invariant"));
|
|
581
|
-
function normalizeTernaries(ternaries) {
|
|
582
|
-
(0, import_invariant.default)(Array.isArray(ternaries), "extractStaticTernaries expects param 1 to be an array of ternaries");
|
|
583
|
-
if (ternaries.length === 0) {
|
|
584
|
-
return [];
|
|
585
|
-
}
|
|
586
|
-
const ternariesByKey = {};
|
|
587
|
-
for (let idx = -1, len = ternaries.length; ++idx < len; ) {
|
|
588
|
-
const _a = ternaries[idx], { test, consequent, alternate, remove } = _a, rest = __objRest(_a, ["test", "consequent", "alternate", "remove"]);
|
|
589
|
-
let ternaryTest = test;
|
|
590
|
-
if (t7.isExpressionStatement(test)) {
|
|
591
|
-
ternaryTest = test.expression;
|
|
592
|
-
}
|
|
593
|
-
let shouldSwap = false;
|
|
594
|
-
if (t7.isUnaryExpression(test) && test.operator === "!") {
|
|
595
|
-
ternaryTest = test.argument;
|
|
596
|
-
shouldSwap = true;
|
|
597
|
-
} else if (t7.isBinaryExpression(test)) {
|
|
598
|
-
if (test.operator === "!==" || test.operator === "!=") {
|
|
599
|
-
ternaryTest = t7.binaryExpression(test.operator, test.left, test.right);
|
|
600
|
-
shouldSwap = true;
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
const key = (0, import_generator2.default)(ternaryTest).code;
|
|
604
|
-
if (!ternariesByKey[key]) {
|
|
605
|
-
ternariesByKey[key] = __spreadProps(__spreadValues({}, rest), {
|
|
606
|
-
alternate: {},
|
|
607
|
-
consequent: {},
|
|
608
|
-
test: ternaryTest,
|
|
609
|
-
remove
|
|
610
|
-
});
|
|
611
|
-
}
|
|
612
|
-
const altStyle = (shouldSwap ? consequent : alternate) ?? {};
|
|
613
|
-
const consStyle = (shouldSwap ? alternate : consequent) ?? {};
|
|
614
|
-
Object.assign(ternariesByKey[key].alternate, altStyle);
|
|
615
|
-
Object.assign(ternariesByKey[key].consequent, consStyle);
|
|
616
|
-
}
|
|
617
|
-
const ternaryExpression = Object.keys(ternariesByKey).map((key) => {
|
|
618
|
-
return ternariesByKey[key];
|
|
619
|
-
});
|
|
620
|
-
return ternaryExpression;
|
|
621
|
-
}
|
|
622
|
-
__name(normalizeTernaries, "normalizeTernaries");
|
|
623
|
-
|
|
624
|
-
// src/extractor/removeUnusedHooks.ts
|
|
625
|
-
var t8 = __toModule(require("@babel/types"));
|
|
626
|
-
var hooks = {
|
|
627
|
-
useMedia: true,
|
|
628
|
-
useTheme: true
|
|
629
|
-
};
|
|
630
|
-
function removeUnusedHooks(compFn, shouldPrintDebug) {
|
|
631
|
-
compFn.scope.crawl();
|
|
632
|
-
let bodyStatements = compFn == null ? void 0 : compFn.get("body");
|
|
633
|
-
if (!bodyStatements) {
|
|
634
|
-
console.log("no body statemnts?", compFn);
|
|
635
|
-
return;
|
|
636
|
-
}
|
|
637
|
-
if (!Array.isArray(bodyStatements)) {
|
|
638
|
-
if (bodyStatements.isFunctionExpression()) {
|
|
639
|
-
bodyStatements = bodyStatements.scope.path.get("body");
|
|
640
|
-
} else {
|
|
641
|
-
bodyStatements = bodyStatements.get("body");
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
if (!bodyStatements || !Array.isArray(bodyStatements)) {
|
|
645
|
-
return;
|
|
646
|
-
}
|
|
647
|
-
const statements = bodyStatements;
|
|
648
|
-
for (const statement of statements) {
|
|
649
|
-
if (!statement.isVariableDeclaration()) {
|
|
650
|
-
continue;
|
|
651
|
-
}
|
|
652
|
-
const declarations = statement.get("declarations");
|
|
653
|
-
if (!Array.isArray(declarations)) {
|
|
654
|
-
continue;
|
|
655
|
-
}
|
|
656
|
-
const isBindingReferenced = /* @__PURE__ */ __name((name) => {
|
|
657
|
-
var _a;
|
|
658
|
-
return !!((_a = statement.scope.getBinding(name)) == null ? void 0 : _a.referenced);
|
|
659
|
-
}, "isBindingReferenced");
|
|
660
|
-
for (const declarator of declarations) {
|
|
661
|
-
const id = declarator.get("id");
|
|
662
|
-
const init = declarator.node.init;
|
|
663
|
-
if (Array.isArray(id) || Array.isArray(init)) {
|
|
664
|
-
continue;
|
|
665
|
-
}
|
|
666
|
-
const shouldRemove = (() => {
|
|
667
|
-
const isHook = t8.isCallExpression(init) && t8.isIdentifier(init.callee) && hooks[init.callee.name];
|
|
668
|
-
if (!isHook) {
|
|
669
|
-
return false;
|
|
670
|
-
}
|
|
671
|
-
if (t8.isIdentifier(id.node)) {
|
|
672
|
-
const name = id.node.name;
|
|
673
|
-
return !isBindingReferenced(name);
|
|
674
|
-
} else if (t8.isObjectPattern(id.node)) {
|
|
675
|
-
const propPaths = id.get("properties");
|
|
676
|
-
return propPaths.every((prop) => {
|
|
677
|
-
if (!prop.isObjectProperty())
|
|
678
|
-
return false;
|
|
679
|
-
const value = prop.get("value");
|
|
680
|
-
if (Array.isArray(value) || !value.isIdentifier())
|
|
681
|
-
return false;
|
|
682
|
-
const name = value.node.name;
|
|
683
|
-
return !isBindingReferenced(name);
|
|
684
|
-
});
|
|
685
|
-
}
|
|
686
|
-
return false;
|
|
687
|
-
})();
|
|
688
|
-
if (shouldRemove) {
|
|
689
|
-
declarator.remove();
|
|
690
|
-
if (shouldPrintDebug) {
|
|
691
|
-
console.log(` [\u{1FA9D}] removed ${id.node["name"] ?? ""}`);
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
__name(removeUnusedHooks, "removeUnusedHooks");
|
|
698
|
-
|
|
699
|
-
// src/extractor/createExtractor.ts
|
|
700
|
-
var { mediaQueryConfig, postProcessStyles, pseudos } = CoreNode;
|
|
701
|
-
var FAILED_EVAL = Symbol("failed_style_eval");
|
|
702
|
-
var UNTOUCHED_PROPS = {
|
|
703
|
-
key: true,
|
|
704
|
-
style: true,
|
|
705
|
-
className: true
|
|
706
|
-
};
|
|
707
|
-
var isAttr = /* @__PURE__ */ __name((x) => x.type === "attr", "isAttr");
|
|
708
|
-
var validHooks = {
|
|
709
|
-
useMedia: true,
|
|
710
|
-
useTheme: true
|
|
711
|
-
};
|
|
712
|
-
var createTernary = /* @__PURE__ */ __name((x) => x, "createTernary");
|
|
713
|
-
function createExtractor() {
|
|
714
|
-
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);
|
|
715
|
-
require("esbuild-register/dist/node").register({
|
|
716
|
-
target: "es2019",
|
|
717
|
-
format: "cjs"
|
|
718
|
-
});
|
|
719
|
-
let loadedTamaguiConfig;
|
|
720
|
-
let hasLogged = false;
|
|
721
|
-
return {
|
|
722
|
-
getTamaguiConfig() {
|
|
723
|
-
return loadedTamaguiConfig;
|
|
724
|
-
},
|
|
725
|
-
parse: (fileOrPath, _a) => {
|
|
726
|
-
var _b = _a, {
|
|
727
|
-
config = "tamagui.config.ts",
|
|
728
|
-
importsWhitelist = ["constants.js"],
|
|
729
|
-
evaluateVars = true,
|
|
730
|
-
shouldPrintDebug = false,
|
|
731
|
-
sourcePath = "",
|
|
732
|
-
onExtractTag,
|
|
733
|
-
getFlattenedNode,
|
|
734
|
-
disableExtraction,
|
|
735
|
-
disableExtractInlineMedia,
|
|
736
|
-
disableDebugAttr
|
|
737
|
-
} = _b, props = __objRest(_b, [
|
|
738
|
-
"config",
|
|
739
|
-
"importsWhitelist",
|
|
740
|
-
"evaluateVars",
|
|
741
|
-
"shouldPrintDebug",
|
|
742
|
-
"sourcePath",
|
|
743
|
-
"onExtractTag",
|
|
744
|
-
"getFlattenedNode",
|
|
745
|
-
"disableExtraction",
|
|
746
|
-
"disableExtractInlineMedia",
|
|
747
|
-
"disableDebugAttr"
|
|
748
|
-
]);
|
|
749
|
-
if (sourcePath === "") {
|
|
750
|
-
throw new Error(`Must provide a source file name`);
|
|
751
|
-
}
|
|
752
|
-
if (!Array.isArray(props.components)) {
|
|
753
|
-
throw new Error(`Must provide components array with list of Tamagui component modules`);
|
|
754
|
-
}
|
|
755
|
-
const { components, tamaguiConfig } = loadTamagui({
|
|
756
|
-
config,
|
|
757
|
-
components: props.components || ["tamagui"]
|
|
758
|
-
});
|
|
759
|
-
loadedTamaguiConfig = tamaguiConfig;
|
|
760
|
-
const defaultTheme = tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]];
|
|
761
|
-
const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
|
|
762
|
-
const isInternalImport = /* @__PURE__ */ __name((importStr) => isInsideTamagui(sourcePath) && importStr[0] === ".", "isInternalImport");
|
|
763
|
-
const validComponents = Object.keys(components).filter((key) => {
|
|
764
|
-
var _a2;
|
|
765
|
-
return key[0].toUpperCase() === key[0] && !!((_a2 = components[key]) == null ? void 0 : _a2.staticConfig);
|
|
766
|
-
}).reduce((obj, name) => {
|
|
767
|
-
obj[name] = components[name];
|
|
768
|
-
return obj;
|
|
769
|
-
}, {});
|
|
770
|
-
let doesUseValidImport = false;
|
|
771
|
-
for (const bodyPath of body) {
|
|
772
|
-
if (bodyPath.type !== "ImportDeclaration")
|
|
773
|
-
continue;
|
|
774
|
-
const node = "node" in bodyPath ? bodyPath.node : bodyPath;
|
|
775
|
-
const from = node.source.value;
|
|
776
|
-
if (props.components.includes(from) || isInternalImport(from)) {
|
|
777
|
-
if (node.specifiers.some((specifier) => {
|
|
778
|
-
const name = specifier.local.name;
|
|
779
|
-
return validComponents[name] || validHooks[name];
|
|
780
|
-
})) {
|
|
781
|
-
doesUseValidImport = true;
|
|
782
|
-
break;
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
if (shouldPrintDebug) {
|
|
787
|
-
console.log(sourcePath, { doesUseValidImport });
|
|
788
|
-
}
|
|
789
|
-
if (!doesUseValidImport) {
|
|
790
|
-
return null;
|
|
791
|
-
}
|
|
792
|
-
let couldntParse = false;
|
|
793
|
-
const modifiedComponents = new Set();
|
|
794
|
-
const bindingCache = {};
|
|
795
|
-
const callTraverse = /* @__PURE__ */ __name((a) => {
|
|
796
|
-
return fileOrPath.type === "File" ? (0, import_traverse.default)(fileOrPath, a) : fileOrPath.traverse(a);
|
|
797
|
-
}, "callTraverse");
|
|
798
|
-
let programPath;
|
|
799
|
-
const res = {
|
|
800
|
-
flattened: 0,
|
|
801
|
-
optimized: 0,
|
|
802
|
-
modified: 0
|
|
803
|
-
};
|
|
804
|
-
callTraverse({
|
|
805
|
-
Program: {
|
|
806
|
-
enter(path3) {
|
|
807
|
-
programPath = path3;
|
|
808
|
-
}
|
|
809
|
-
},
|
|
810
|
-
JSXElement(traversePath) {
|
|
811
|
-
var _a2;
|
|
812
|
-
const node = traversePath.node.openingElement;
|
|
813
|
-
const ogAttributes = node.attributes;
|
|
814
|
-
const componentName = findComponentName(traversePath.scope);
|
|
815
|
-
const closingElement = traversePath.node.closingElement;
|
|
816
|
-
if (t9.isJSXMemberExpression(closingElement == null ? void 0 : closingElement.name) || !t9.isJSXIdentifier(node.name)) {
|
|
817
|
-
return;
|
|
818
|
-
}
|
|
819
|
-
const binding = traversePath.scope.getBinding(node.name.name);
|
|
820
|
-
if (binding) {
|
|
821
|
-
if (!t9.isImportDeclaration(binding.path.parent)) {
|
|
822
|
-
return;
|
|
823
|
-
}
|
|
824
|
-
const source = binding.path.parent.source;
|
|
825
|
-
if (!props.components.includes(source.value) && !isInternalImport(source.value)) {
|
|
826
|
-
return;
|
|
827
|
-
}
|
|
828
|
-
if (!validComponents[binding.identifier.name]) {
|
|
829
|
-
return;
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
const component = validComponents[node.name.name];
|
|
833
|
-
if (!component || !component.staticConfig) {
|
|
834
|
-
return;
|
|
835
|
-
}
|
|
836
|
-
const originalNodeName = node.name.name;
|
|
837
|
-
if (shouldPrintDebug) {
|
|
838
|
-
console.log(`
|
|
839
|
-
<${originalNodeName} />`);
|
|
840
|
-
}
|
|
841
|
-
const filePath = sourcePath.replace(process.cwd(), ".");
|
|
842
|
-
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
843
|
-
if (shouldAddDebugProp && !disableDebugAttr) {
|
|
844
|
-
const preName = componentName ? `${componentName}:` : "";
|
|
845
|
-
res.modified++;
|
|
846
|
-
node.attributes.unshift(t9.jsxAttribute(t9.jsxIdentifier("data-is"), t9.stringLiteral(` ${preName}${node.name.name} ${filePath.replace("./", "")}:${lineNumbers} `)));
|
|
847
|
-
}
|
|
848
|
-
if (disableExtraction) {
|
|
849
|
-
if (!hasLogged) {
|
|
850
|
-
console.log("\u{1F95A} Tamagui disableExtraction set: no CSS or optimizations will be run");
|
|
851
|
-
hasLogged = true;
|
|
852
|
-
}
|
|
853
|
-
return;
|
|
854
|
-
}
|
|
855
|
-
const { staticConfig } = component;
|
|
856
|
-
const isTextView = staticConfig.isText || false;
|
|
857
|
-
const validStyles = (staticConfig == null ? void 0 : staticConfig.validStyles) ?? {};
|
|
858
|
-
let tagName = ((_a2 = staticConfig.defaultProps) == null ? void 0 : _a2.tag) ?? (isTextView ? "span" : "div");
|
|
859
|
-
traversePath.get("openingElement").get("attributes").forEach((path3) => {
|
|
860
|
-
const attr = path3.node;
|
|
861
|
-
if (t9.isJSXSpreadAttribute(attr))
|
|
862
|
-
return;
|
|
863
|
-
if (attr.name.name !== "tag")
|
|
864
|
-
return;
|
|
865
|
-
const val = attr.value;
|
|
866
|
-
if (!t9.isStringLiteral(val))
|
|
867
|
-
return;
|
|
868
|
-
tagName = val.value;
|
|
869
|
-
});
|
|
870
|
-
const flatNode = getFlattenedNode({ isTextView, tag: tagName });
|
|
871
|
-
const deoptProps = new Set([
|
|
872
|
-
...props.deoptProps ?? [],
|
|
873
|
-
...staticConfig.deoptProps ?? []
|
|
874
|
-
]);
|
|
875
|
-
const excludeProps = new Set(props.excludeProps ?? []);
|
|
876
|
-
const isExcludedProp = /* @__PURE__ */ __name((name) => {
|
|
877
|
-
const res2 = excludeProps.has(name);
|
|
878
|
-
if (res2 && shouldPrintDebug)
|
|
879
|
-
console.log(` excluding ${name}`);
|
|
880
|
-
return res2;
|
|
881
|
-
}, "isExcludedProp");
|
|
882
|
-
const isDeoptedProp = /* @__PURE__ */ __name((name) => {
|
|
883
|
-
const res2 = deoptProps.has(name);
|
|
884
|
-
if (res2 && shouldPrintDebug)
|
|
885
|
-
console.log(` deopting ${name}`);
|
|
886
|
-
return res2;
|
|
887
|
-
}, "isDeoptedProp");
|
|
888
|
-
const staticNamespace = getStaticBindingsForScope(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
|
|
889
|
-
const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
|
|
890
|
-
tamaguiConfig,
|
|
891
|
-
staticNamespace,
|
|
892
|
-
sourcePath,
|
|
893
|
-
traversePath,
|
|
894
|
-
shouldPrintDebug
|
|
895
|
-
});
|
|
896
|
-
const attemptEvalSafe = createSafeEvaluator(attemptEval);
|
|
897
|
-
if (shouldPrintDebug) {
|
|
898
|
-
console.log(" staticNamespace", Object.keys(staticNamespace).join(", "));
|
|
899
|
-
}
|
|
900
|
-
const hasDeopt = /* @__PURE__ */ __name((obj) => {
|
|
901
|
-
return Object.keys(obj).some(isDeoptedProp);
|
|
902
|
-
}, "hasDeopt");
|
|
903
|
-
const flattenedAttrs = [];
|
|
904
|
-
traversePath.get("openingElement").get("attributes").forEach((path3) => {
|
|
905
|
-
const attr = path3.node;
|
|
906
|
-
if (!t9.isJSXSpreadAttribute(attr)) {
|
|
907
|
-
flattenedAttrs.push(attr);
|
|
908
|
-
return;
|
|
909
|
-
}
|
|
910
|
-
let arg;
|
|
911
|
-
try {
|
|
912
|
-
arg = attemptEval(attr.argument);
|
|
913
|
-
} catch (e) {
|
|
914
|
-
if (shouldPrintDebug) {
|
|
915
|
-
console.log(" couldnt parse spread", e.message);
|
|
916
|
-
}
|
|
917
|
-
flattenedAttrs.push(attr);
|
|
918
|
-
return;
|
|
919
|
-
}
|
|
920
|
-
if (typeof arg !== "undefined") {
|
|
921
|
-
try {
|
|
922
|
-
if (typeof arg !== "object" || arg == null) {
|
|
923
|
-
if (shouldPrintDebug) {
|
|
924
|
-
console.log(" non object or null arg", arg);
|
|
925
|
-
}
|
|
926
|
-
flattenedAttrs.push(attr);
|
|
927
|
-
} else {
|
|
928
|
-
for (const k in arg) {
|
|
929
|
-
const value = arg[k];
|
|
930
|
-
if (!value && typeof value === "object") {
|
|
931
|
-
console.log("shouldnt we handle this?", k, value, arg);
|
|
932
|
-
continue;
|
|
933
|
-
}
|
|
934
|
-
flattenedAttrs.push(t9.jsxAttribute(t9.jsxIdentifier(k), t9.jsxExpressionContainer(literalToAst(value))));
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
} catch (err) {
|
|
938
|
-
console.warn("cant parse spread, caught err", err);
|
|
939
|
-
couldntParse = true;
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
});
|
|
943
|
-
if (couldntParse) {
|
|
944
|
-
return;
|
|
945
|
-
}
|
|
946
|
-
node.attributes = flattenedAttrs;
|
|
947
|
-
if (staticConfig.defaultProps) {
|
|
948
|
-
for (const key in staticConfig.defaultProps) {
|
|
949
|
-
const serialize = require("babel-literal-to-ast");
|
|
950
|
-
const val = staticConfig.defaultProps[key];
|
|
951
|
-
node.attributes.unshift(t9.jsxAttribute(t9.jsxIdentifier(key), typeof val === "string" ? t9.stringLiteral(val) : t9.jsxExpressionContainer(serialize(val))));
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
let attrs = [];
|
|
955
|
-
let shouldDeopt = false;
|
|
956
|
-
let inlinePropCount = 0;
|
|
957
|
-
let isFlattened = false;
|
|
958
|
-
attrs = traversePath.get("openingElement").get("attributes").flatMap((path3) => {
|
|
959
|
-
try {
|
|
960
|
-
const res2 = evaluateAttribute(path3);
|
|
961
|
-
if (!res2) {
|
|
962
|
-
path3.remove();
|
|
963
|
-
}
|
|
964
|
-
return res2;
|
|
965
|
-
} catch (err) {
|
|
966
|
-
console.log("Error extracting attribute", err.message, err.stack);
|
|
967
|
-
console.log("node", path3.node);
|
|
968
|
-
return {
|
|
969
|
-
type: "attr",
|
|
970
|
-
value: path3.node
|
|
971
|
-
};
|
|
972
|
-
}
|
|
973
|
-
}).flat(4).filter(isPresent);
|
|
974
|
-
function isStaticAttributeName(name) {
|
|
975
|
-
var _a3, _b2;
|
|
976
|
-
return !!(!!validStyles[name] || ((_a3 = staticConfig.validPropsExtra) == null ? void 0 : _a3[name]) || !!pseudos[name] || ((_b2 = staticConfig.variants) == null ? void 0 : _b2[name]) || tamaguiConfig.shorthands[name] || (name[0] === "$" ? !!mediaQueryConfig[name.slice(1)] : false));
|
|
977
|
-
}
|
|
978
|
-
__name(isStaticAttributeName, "isStaticAttributeName");
|
|
979
|
-
function isExtractable(obj) {
|
|
980
|
-
return t9.isObjectExpression(obj) && obj.properties.every((prop) => {
|
|
981
|
-
if (!t9.isObjectProperty(prop)) {
|
|
982
|
-
console.log("not object prop", prop);
|
|
983
|
-
return false;
|
|
984
|
-
}
|
|
985
|
-
const propName = prop.key["name"];
|
|
986
|
-
if (!isStaticAttributeName(propName) && propName !== "tag") {
|
|
987
|
-
if (shouldPrintDebug) {
|
|
988
|
-
console.log(" not a valid style prop!", propName);
|
|
989
|
-
}
|
|
990
|
-
return false;
|
|
991
|
-
}
|
|
992
|
-
return true;
|
|
993
|
-
});
|
|
994
|
-
}
|
|
995
|
-
__name(isExtractable, "isExtractable");
|
|
996
|
-
function createTernariesFromObjectProperties(test, side, ternaryPartial = {}) {
|
|
997
|
-
if (!side) {
|
|
998
|
-
return null;
|
|
999
|
-
}
|
|
1000
|
-
if (!isExtractable(side)) {
|
|
1001
|
-
throw new Error("not extractable");
|
|
1002
|
-
}
|
|
1003
|
-
return side.properties.flatMap((property) => {
|
|
1004
|
-
if (!t9.isObjectProperty(property)) {
|
|
1005
|
-
throw new Error("expected object property");
|
|
1006
|
-
}
|
|
1007
|
-
if (t9.isConditionalExpression(property.value)) {
|
|
1008
|
-
const [truthy, falsy] = [
|
|
1009
|
-
t9.objectExpression([t9.objectProperty(property.key, property.value.consequent)]),
|
|
1010
|
-
t9.objectExpression([t9.objectProperty(property.key, property.value.alternate)])
|
|
1011
|
-
].map((x) => attemptEval(x));
|
|
1012
|
-
return [
|
|
1013
|
-
createTernary(__spreadProps(__spreadValues({
|
|
1014
|
-
remove() {
|
|
1015
|
-
}
|
|
1016
|
-
}, ternaryPartial), {
|
|
1017
|
-
test: t9.logicalExpression("&&", test, property.value.test),
|
|
1018
|
-
consequent: truthy,
|
|
1019
|
-
alternate: null
|
|
1020
|
-
})),
|
|
1021
|
-
createTernary(__spreadProps(__spreadValues({}, ternaryPartial), {
|
|
1022
|
-
test: t9.logicalExpression("&&", test, t9.unaryExpression("!", property.value.test)),
|
|
1023
|
-
consequent: falsy,
|
|
1024
|
-
alternate: null,
|
|
1025
|
-
remove() {
|
|
1026
|
-
}
|
|
1027
|
-
}))
|
|
1028
|
-
];
|
|
1029
|
-
}
|
|
1030
|
-
const obj = t9.objectExpression([t9.objectProperty(property.key, property.value)]);
|
|
1031
|
-
const consequent = attemptEval(obj);
|
|
1032
|
-
return createTernary(__spreadProps(__spreadValues({
|
|
1033
|
-
remove() {
|
|
1034
|
-
}
|
|
1035
|
-
}, ternaryPartial), {
|
|
1036
|
-
test,
|
|
1037
|
-
consequent,
|
|
1038
|
-
alternate: null
|
|
1039
|
-
}));
|
|
1040
|
-
});
|
|
1041
|
-
}
|
|
1042
|
-
__name(createTernariesFromObjectProperties, "createTernariesFromObjectProperties");
|
|
1043
|
-
function evaluateAttribute(path3) {
|
|
1044
|
-
const attribute = path3.node;
|
|
1045
|
-
const attr = { type: "attr", value: attribute };
|
|
1046
|
-
if (t9.isJSXSpreadAttribute(attribute)) {
|
|
1047
|
-
const arg = attribute.argument;
|
|
1048
|
-
const conditional = t9.isConditionalExpression(arg) ? [arg.test, arg.consequent, arg.alternate] : t9.isLogicalExpression(arg) && arg.operator === "&&" ? [arg.left, arg.right, null] : null;
|
|
1049
|
-
if (conditional) {
|
|
1050
|
-
const [test, alt, cons] = conditional;
|
|
1051
|
-
if (!test)
|
|
1052
|
-
throw new Error(`no test`);
|
|
1053
|
-
if ([alt, cons].some((side) => side && !isExtractable(side))) {
|
|
1054
|
-
if (shouldPrintDebug) {
|
|
1055
|
-
console.log("not extractable", alt, cons);
|
|
1056
|
-
}
|
|
1057
|
-
return attr;
|
|
1058
|
-
}
|
|
1059
|
-
return [
|
|
1060
|
-
...createTernariesFromObjectProperties(test, alt) || [],
|
|
1061
|
-
...cons && createTernariesFromObjectProperties(t9.unaryExpression("!", test), cons) || []
|
|
1062
|
-
].map((ternary) => ({
|
|
1063
|
-
type: "ternary",
|
|
1064
|
-
value: ternary
|
|
1065
|
-
}));
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
if (t9.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name !== "string") {
|
|
1069
|
-
inlinePropCount++;
|
|
1070
|
-
return attr;
|
|
1071
|
-
}
|
|
1072
|
-
const name = attribute.name.name;
|
|
1073
|
-
if (isExcludedProp(name)) {
|
|
1074
|
-
return null;
|
|
1075
|
-
}
|
|
1076
|
-
if (isDeoptedProp(name)) {
|
|
1077
|
-
if (shouldPrintDebug) {
|
|
1078
|
-
console.log(" ! inlining, deopt prop", name);
|
|
1079
|
-
}
|
|
1080
|
-
inlinePropCount++;
|
|
1081
|
-
return attr;
|
|
1082
|
-
}
|
|
1083
|
-
if (UNTOUCHED_PROPS[name]) {
|
|
1084
|
-
return attr;
|
|
1085
|
-
}
|
|
1086
|
-
if (name[0] === "$" && t9.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value) && !disableExtractInlineMedia) {
|
|
1087
|
-
const shortname = name.slice(1);
|
|
1088
|
-
if (mediaQueryConfig[shortname]) {
|
|
1089
|
-
const expression = attribute.value.expression;
|
|
1090
|
-
if (!t9.isJSXEmptyExpression(expression)) {
|
|
1091
|
-
const ternaries2 = createTernariesFromObjectProperties(t9.stringLiteral(shortname), expression, {
|
|
1092
|
-
inlineMediaQuery: shortname
|
|
1093
|
-
});
|
|
1094
|
-
if (ternaries2) {
|
|
1095
|
-
return ternaries2.map((value2) => ({
|
|
1096
|
-
type: "ternary",
|
|
1097
|
-
value: value2
|
|
1098
|
-
}));
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
const [value, valuePath] = (() => {
|
|
1104
|
-
if (t9.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
|
|
1105
|
-
return [attribute.value.expression, path3.get("value")];
|
|
1106
|
-
} else {
|
|
1107
|
-
return [attribute.value, path3.get("value")];
|
|
1108
|
-
}
|
|
1109
|
-
})();
|
|
1110
|
-
const remove = /* @__PURE__ */ __name(() => {
|
|
1111
|
-
Array.isArray(valuePath) ? valuePath.map((p) => p.remove()) : valuePath.remove();
|
|
1112
|
-
}, "remove");
|
|
1113
|
-
if (name === "ref") {
|
|
1114
|
-
if (shouldPrintDebug) {
|
|
1115
|
-
console.log(" ! inlining, ref", name);
|
|
1116
|
-
}
|
|
1117
|
-
inlinePropCount++;
|
|
1118
|
-
return attr;
|
|
1119
|
-
}
|
|
1120
|
-
if (name === "tag") {
|
|
1121
|
-
return {
|
|
1122
|
-
type: "attr",
|
|
1123
|
-
value: path3.node
|
|
1124
|
-
};
|
|
1125
|
-
}
|
|
1126
|
-
const styleValue = attemptEvalSafe(value);
|
|
1127
|
-
if (!isStaticAttributeName(name)) {
|
|
1128
|
-
let keys = [name];
|
|
1129
|
-
if (staticConfig.propMapper) {
|
|
1130
|
-
const out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps);
|
|
1131
|
-
if (out) {
|
|
1132
|
-
keys = Object.keys(out);
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
if (keys.some((k) => !isStaticAttributeName(k) && k !== "tag")) {
|
|
1136
|
-
if (shouldPrintDebug) {
|
|
1137
|
-
console.log(" ! inlining, not static attribute name", name);
|
|
1138
|
-
}
|
|
1139
|
-
inlinePropCount++;
|
|
1140
|
-
return attr;
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
if (styleValue !== FAILED_EVAL) {
|
|
1144
|
-
return {
|
|
1145
|
-
type: "style",
|
|
1146
|
-
value: { [name]: styleValue }
|
|
1147
|
-
};
|
|
1148
|
-
}
|
|
1149
|
-
if (t9.isBinaryExpression(value)) {
|
|
1150
|
-
const { operator, left, right } = value;
|
|
1151
|
-
const lVal = attemptEvalSafe(left);
|
|
1152
|
-
const rVal = attemptEvalSafe(right);
|
|
1153
|
-
if (shouldPrintDebug) {
|
|
1154
|
-
console.log(` evalBinaryExpression lVal ${String(lVal)}, rVal ${String(rVal)}`);
|
|
1155
|
-
}
|
|
1156
|
-
if (lVal !== FAILED_EVAL && t9.isConditionalExpression(right)) {
|
|
1157
|
-
const ternary = addBinaryConditional(operator, left, right);
|
|
1158
|
-
if (ternary)
|
|
1159
|
-
return ternary;
|
|
1160
|
-
}
|
|
1161
|
-
if (rVal !== FAILED_EVAL && t9.isConditionalExpression(left)) {
|
|
1162
|
-
const ternary = addBinaryConditional(operator, right, left);
|
|
1163
|
-
if (ternary)
|
|
1164
|
-
return ternary;
|
|
1165
|
-
}
|
|
1166
|
-
if (shouldPrintDebug) {
|
|
1167
|
-
console.log(` evalBinaryExpression cant extract`);
|
|
1168
|
-
}
|
|
1169
|
-
inlinePropCount++;
|
|
1170
|
-
return attr;
|
|
1171
|
-
}
|
|
1172
|
-
const staticConditional = getStaticConditional(value);
|
|
1173
|
-
if (staticConditional) {
|
|
1174
|
-
return { type: "ternary", value: staticConditional };
|
|
1175
|
-
}
|
|
1176
|
-
const staticLogical = getStaticLogical(value);
|
|
1177
|
-
if (staticLogical) {
|
|
1178
|
-
return { type: "ternary", value: staticLogical };
|
|
1179
|
-
}
|
|
1180
|
-
if (shouldPrintDebug) {
|
|
1181
|
-
console.log(" ! inline prop via no match", name, value.type);
|
|
1182
|
-
}
|
|
1183
|
-
inlinePropCount++;
|
|
1184
|
-
return attr;
|
|
1185
|
-
function addBinaryConditional(operator, staticExpr, cond) {
|
|
1186
|
-
if (getStaticConditional(cond)) {
|
|
1187
|
-
const alt = attemptEval(t9.binaryExpression(operator, staticExpr, cond.alternate));
|
|
1188
|
-
const cons = attemptEval(t9.binaryExpression(operator, staticExpr, cond.consequent));
|
|
1189
|
-
if (shouldPrintDebug) {
|
|
1190
|
-
console.log(" binaryConditional", cond.test, cons, alt);
|
|
1191
|
-
}
|
|
1192
|
-
return {
|
|
1193
|
-
type: "ternary",
|
|
1194
|
-
value: {
|
|
1195
|
-
test: cond.test,
|
|
1196
|
-
remove,
|
|
1197
|
-
alternate: { [name]: alt },
|
|
1198
|
-
consequent: { [name]: cons }
|
|
1199
|
-
}
|
|
1200
|
-
};
|
|
1201
|
-
}
|
|
1202
|
-
return null;
|
|
1203
|
-
}
|
|
1204
|
-
__name(addBinaryConditional, "addBinaryConditional");
|
|
1205
|
-
function getStaticConditional(value2) {
|
|
1206
|
-
if (t9.isConditionalExpression(value2)) {
|
|
1207
|
-
try {
|
|
1208
|
-
if (shouldPrintDebug) {
|
|
1209
|
-
console.log("attempt", value2.alternate, value2.consequent);
|
|
1210
|
-
}
|
|
1211
|
-
const aVal = attemptEval(value2.alternate);
|
|
1212
|
-
const cVal = attemptEval(value2.consequent);
|
|
1213
|
-
if (shouldPrintDebug) {
|
|
1214
|
-
const type = value2.test.type;
|
|
1215
|
-
console.log(" static ternary", type, cVal, aVal);
|
|
1216
|
-
}
|
|
1217
|
-
return {
|
|
1218
|
-
test: value2.test,
|
|
1219
|
-
remove,
|
|
1220
|
-
consequent: { [name]: cVal },
|
|
1221
|
-
alternate: { [name]: aVal }
|
|
1222
|
-
};
|
|
1223
|
-
} catch (err) {
|
|
1224
|
-
if (shouldPrintDebug) {
|
|
1225
|
-
console.log(" cant eval ternary", err.message);
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
return null;
|
|
1230
|
-
}
|
|
1231
|
-
__name(getStaticConditional, "getStaticConditional");
|
|
1232
|
-
function getStaticLogical(value2) {
|
|
1233
|
-
if (t9.isLogicalExpression(value2)) {
|
|
1234
|
-
if (value2.operator === "&&") {
|
|
1235
|
-
try {
|
|
1236
|
-
const val = attemptEval(value2.right);
|
|
1237
|
-
if (shouldPrintDebug) {
|
|
1238
|
-
console.log(" staticLogical", value2.left, name, val);
|
|
1239
|
-
}
|
|
1240
|
-
return {
|
|
1241
|
-
test: value2.left,
|
|
1242
|
-
remove,
|
|
1243
|
-
consequent: { [name]: val },
|
|
1244
|
-
alternate: null
|
|
1245
|
-
};
|
|
1246
|
-
} catch (err) {
|
|
1247
|
-
if (shouldPrintDebug) {
|
|
1248
|
-
console.log(" cant static eval logical", err);
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
return null;
|
|
1254
|
-
}
|
|
1255
|
-
__name(getStaticLogical, "getStaticLogical");
|
|
1256
|
-
}
|
|
1257
|
-
__name(evaluateAttribute, "evaluateAttribute");
|
|
1258
|
-
if (shouldPrintDebug) {
|
|
1259
|
-
console.log(" - attrs (before): ", attrs.map(attrStr).join(", "));
|
|
1260
|
-
}
|
|
1261
|
-
node.attributes = attrs.filter(isAttr).map((x) => x.value);
|
|
1262
|
-
if (couldntParse) {
|
|
1263
|
-
if (shouldPrintDebug) {
|
|
1264
|
-
console.log(` cancel:`, { couldntParse, shouldDeopt });
|
|
1265
|
-
}
|
|
1266
|
-
node.attributes = ogAttributes;
|
|
1267
|
-
return;
|
|
1268
|
-
}
|
|
1269
|
-
const parentFn = findTopmostFunction(traversePath);
|
|
1270
|
-
if (parentFn) {
|
|
1271
|
-
modifiedComponents.add(parentFn);
|
|
1272
|
-
}
|
|
1273
|
-
let ternaries = [];
|
|
1274
|
-
attrs = attrs.reduce((out, cur) => {
|
|
1275
|
-
const next = attrs[attrs.indexOf(cur) + 1];
|
|
1276
|
-
if (cur.type === "ternary") {
|
|
1277
|
-
ternaries.push(cur.value);
|
|
1278
|
-
}
|
|
1279
|
-
if ((!next || next.type !== "ternary") && ternaries.length) {
|
|
1280
|
-
const normalized = normalizeTernaries(ternaries).map((_a3) => {
|
|
1281
|
-
var _b2 = _a3, { alternate, consequent } = _b2, rest = __objRest(_b2, ["alternate", "consequent"]);
|
|
1282
|
-
return {
|
|
1283
|
-
type: "ternary",
|
|
1284
|
-
value: __spreadProps(__spreadValues({}, rest), {
|
|
1285
|
-
alternate: alternate || null,
|
|
1286
|
-
consequent: consequent || null
|
|
1287
|
-
})
|
|
1288
|
-
};
|
|
1289
|
-
});
|
|
1290
|
-
try {
|
|
1291
|
-
return [...out, ...normalized];
|
|
1292
|
-
} finally {
|
|
1293
|
-
if (shouldPrintDebug) {
|
|
1294
|
-
console.log(` normalizeTernaries (${ternaries.length} => ${normalized.length})`);
|
|
1295
|
-
}
|
|
1296
|
-
ternaries = [];
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
1299
|
-
if (cur.type === "ternary") {
|
|
1300
|
-
return out;
|
|
1301
|
-
}
|
|
1302
|
-
out.push(cur);
|
|
1303
|
-
return out;
|
|
1304
|
-
}, []).flat();
|
|
1305
|
-
const completeStaticProps = __spreadValues({}, Object.keys(attrs).reduce((acc, index) => {
|
|
1306
|
-
const cur = attrs[index];
|
|
1307
|
-
if (cur.type === "style") {
|
|
1308
|
-
Object.assign(acc, cur.value);
|
|
1309
|
-
}
|
|
1310
|
-
if (cur.type === "attr") {
|
|
1311
|
-
if (t9.isJSXSpreadAttribute(cur.value)) {
|
|
1312
|
-
return acc;
|
|
1313
|
-
}
|
|
1314
|
-
if (!t9.isJSXIdentifier(cur.value.name)) {
|
|
1315
|
-
return acc;
|
|
1316
|
-
}
|
|
1317
|
-
const key = cur.value.name.name;
|
|
1318
|
-
const value = attemptEvalSafe(cur.value.value || t9.booleanLiteral(true));
|
|
1319
|
-
if (value === FAILED_EVAL) {
|
|
1320
|
-
return acc;
|
|
1321
|
-
}
|
|
1322
|
-
acc[key] = value;
|
|
1323
|
-
}
|
|
1324
|
-
return acc;
|
|
1325
|
-
}, {}));
|
|
1326
|
-
const hasSpread = node.attributes.some((x) => t9.isJSXSpreadAttribute(x));
|
|
1327
|
-
const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
|
|
1328
|
-
const shouldFlatten = !shouldDeopt && inlinePropCount === 0 && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
|
|
1329
|
-
if (!shouldFlatten) {
|
|
1330
|
-
attrs = attrs.reduce((acc, cur) => {
|
|
1331
|
-
var _a3;
|
|
1332
|
-
if (cur.type === "style") {
|
|
1333
|
-
for (const key in cur.value) {
|
|
1334
|
-
const shouldInsertNull = !!((_a3 = staticConfig.ensureOverriddenProp) == null ? void 0 : _a3[key]);
|
|
1335
|
-
const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
|
|
1336
|
-
const shouldInsertNullOverride = shouldInsertNull && !isSetInAttrsAlready;
|
|
1337
|
-
if (shouldInsertNullOverride) {
|
|
1338
|
-
acc.push({
|
|
1339
|
-
type: "attr",
|
|
1340
|
-
value: t9.jsxAttribute(t9.jsxIdentifier(key), t9.jsxExpressionContainer(t9.nullLiteral()))
|
|
1341
|
-
});
|
|
1342
|
-
}
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
acc.push(cur);
|
|
1346
|
-
return acc;
|
|
1347
|
-
}, []);
|
|
1348
|
-
}
|
|
1349
|
-
if (shouldPrintDebug) {
|
|
1350
|
-
console.log(" - attrs (flattened): ", attrs.map(attrStr).join(", "));
|
|
1351
|
-
}
|
|
1352
|
-
attrs = attrs.reduce((acc, cur) => {
|
|
1353
|
-
if (cur.type !== "attr" || !t9.isJSXAttribute(cur.value) || typeof cur.value.name.name !== "string") {
|
|
1354
|
-
if (cur.type === "style") {
|
|
1355
|
-
const key = Object.keys(cur.value)[0];
|
|
1356
|
-
if (!validStyles[key] && !pseudos[key]) {
|
|
1357
|
-
if (shouldPrintDebug) {
|
|
1358
|
-
console.log(" \u274C excluding", key);
|
|
1359
|
-
}
|
|
1360
|
-
return acc;
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
acc.push(cur);
|
|
1365
|
-
return acc;
|
|
1366
|
-
}, []);
|
|
1367
|
-
if (shouldPrintDebug) {
|
|
1368
|
-
console.log(" - attrs (evaluated styles): ", attrs.map(attrStr).join(", "));
|
|
1369
|
-
}
|
|
1370
|
-
let prev = null;
|
|
1371
|
-
attrs = attrs.reduce((acc, cur) => {
|
|
1372
|
-
if (cur.type === "style") {
|
|
1373
|
-
if ((prev == null ? void 0 : prev.type) === "style") {
|
|
1374
|
-
Object.assign(prev.value, cur.value);
|
|
1375
|
-
return acc;
|
|
1376
|
-
}
|
|
1377
|
-
}
|
|
1378
|
-
acc.push(cur);
|
|
1379
|
-
prev = cur;
|
|
1380
|
-
return acc;
|
|
1381
|
-
}, []);
|
|
1382
|
-
if (shouldPrintDebug) {
|
|
1383
|
-
console.log(" - attrs (combined \u{1F500}): ", attrs.map(attrStr).join(", "));
|
|
1384
|
-
}
|
|
1385
|
-
const getStyles = /* @__PURE__ */ __name((props2) => {
|
|
1386
|
-
if (!props2)
|
|
1387
|
-
return;
|
|
1388
|
-
if (!!excludeProps.size) {
|
|
1389
|
-
for (const key in props2) {
|
|
1390
|
-
if (isExcludedProp(key))
|
|
1391
|
-
delete props2[key];
|
|
1392
|
-
}
|
|
1393
|
-
}
|
|
1394
|
-
const out = postProcessStyles(props2, staticConfig, defaultTheme);
|
|
1395
|
-
const next = (out == null ? void 0 : out.style) ?? props2;
|
|
1396
|
-
if (shouldPrintDebug) {
|
|
1397
|
-
console.log(" >> getStyles: ", objToStr(props2), "==>>", objToStr(next));
|
|
1398
|
-
console.log(" >> style: ", objToStr(out.style));
|
|
1399
|
-
console.log(" >> viewp: ", objToStr(out.viewProps));
|
|
1400
|
-
}
|
|
1401
|
-
if (staticConfig.validStyles) {
|
|
1402
|
-
for (const key in next) {
|
|
1403
|
-
if (!staticConfig.validStyles[key] && !pseudos[key]) {
|
|
1404
|
-
delete next[key];
|
|
1405
|
-
}
|
|
1406
|
-
}
|
|
1407
|
-
}
|
|
1408
|
-
return next;
|
|
1409
|
-
}, "getStyles");
|
|
1410
|
-
if (shouldPrintDebug) {
|
|
1411
|
-
console.log(" staticConfig.defaultProps", staticConfig.defaultProps);
|
|
1412
|
-
}
|
|
1413
|
-
const completeStylesProcessed = getStyles(__spreadValues(__spreadValues({}, staticConfig.defaultProps), completeStaticProps));
|
|
1414
|
-
const stylesToAddToInitialGroup = (0, import_lodash.difference)(Object.keys(completeStylesProcessed), Object.keys(completeStaticProps));
|
|
1415
|
-
if (stylesToAddToInitialGroup.length) {
|
|
1416
|
-
const toAdd = (0, import_lodash.pick)(completeStylesProcessed, ...stylesToAddToInitialGroup);
|
|
1417
|
-
const firstGroup = attrs.find((x) => x.type === "style");
|
|
1418
|
-
if (shouldPrintDebug) {
|
|
1419
|
-
console.log(" stylesToAddToInitialGroup", stylesToAddToInitialGroup.join(", "));
|
|
1420
|
-
console.log(" toAdd", objToStr(toAdd));
|
|
1421
|
-
}
|
|
1422
|
-
if (!firstGroup) {
|
|
1423
|
-
attrs.unshift({ type: "style", value: toAdd });
|
|
1424
|
-
} else {
|
|
1425
|
-
Object.assign(firstGroup.value, toAdd);
|
|
1426
|
-
}
|
|
1427
|
-
}
|
|
1428
|
-
if (shouldPrintDebug) {
|
|
1429
|
-
console.log(" completeStaticProps", objToStr(completeStaticProps));
|
|
1430
|
-
console.log(" completeStylesProcessed", objToStr(completeStylesProcessed));
|
|
1431
|
-
}
|
|
1432
|
-
for (const attr of attrs) {
|
|
1433
|
-
try {
|
|
1434
|
-
switch (attr.type) {
|
|
1435
|
-
case "ternary":
|
|
1436
|
-
const a = getStyles(attr.value.alternate);
|
|
1437
|
-
const c = getStyles(attr.value.consequent);
|
|
1438
|
-
attr.value.alternate = a;
|
|
1439
|
-
attr.value.consequent = c;
|
|
1440
|
-
if (shouldPrintDebug) {
|
|
1441
|
-
console.log(" => tern ", attrStr(attr));
|
|
1442
|
-
}
|
|
1443
|
-
break;
|
|
1444
|
-
case "style":
|
|
1445
|
-
const next = {};
|
|
1446
|
-
for (const key in attr.value) {
|
|
1447
|
-
if (key in import_helpers.stylePropsTransform) {
|
|
1448
|
-
next["transform"] = completeStylesProcessed["transform"];
|
|
1449
|
-
} else {
|
|
1450
|
-
next[key] = completeStylesProcessed[key] ?? attr.value[key];
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
attr.value = next;
|
|
1454
|
-
break;
|
|
1455
|
-
}
|
|
1456
|
-
} catch (err) {
|
|
1457
|
-
if (shouldPrintDebug) {
|
|
1458
|
-
console.log(" postprocessing error, deopt", err);
|
|
1459
|
-
node.attributes = ogAttributes;
|
|
1460
|
-
return node;
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
if (shouldPrintDebug) {
|
|
1465
|
-
console.log(" - attrs (after): ", attrs.map(attrStr).join(", "));
|
|
1466
|
-
}
|
|
1467
|
-
if (shouldFlatten) {
|
|
1468
|
-
if (shouldPrintDebug) {
|
|
1469
|
-
console.log(" [\u2705] flattening", originalNodeName, flatNode);
|
|
1470
|
-
}
|
|
1471
|
-
isFlattened = true;
|
|
1472
|
-
node.name.name = flatNode;
|
|
1473
|
-
res.flattened++;
|
|
1474
|
-
if (closingElement) {
|
|
1475
|
-
closingElement.name.name = flatNode;
|
|
1476
|
-
}
|
|
1477
|
-
}
|
|
1478
|
-
if (shouldPrintDebug) {
|
|
1479
|
-
console.log(" [\u274A] inline props ", inlinePropCount, shouldDeopt ? " deopted" : "", hasSpread ? " spread" : "", "!flatten", staticConfig.neverFlatten);
|
|
1480
|
-
console.log(" - attrs (end): ", attrs.map(attrStr).join(", "));
|
|
1481
|
-
}
|
|
1482
|
-
res.optimized++;
|
|
1483
|
-
onExtractTag({
|
|
1484
|
-
attrs,
|
|
1485
|
-
node,
|
|
1486
|
-
lineNumbers,
|
|
1487
|
-
filePath,
|
|
1488
|
-
attemptEval,
|
|
1489
|
-
jsxPath: traversePath,
|
|
1490
|
-
originalNodeName,
|
|
1491
|
-
isFlattened,
|
|
1492
|
-
programPath
|
|
1493
|
-
});
|
|
1494
|
-
}
|
|
1495
|
-
});
|
|
1496
|
-
if (modifiedComponents.size) {
|
|
1497
|
-
const all = Array.from(modifiedComponents);
|
|
1498
|
-
if (shouldPrintDebug) {
|
|
1499
|
-
console.log(" [\u{1FA9D}] hook check", all.length);
|
|
1500
|
-
}
|
|
1501
|
-
for (const comp of all) {
|
|
1502
|
-
removeUnusedHooks(comp, shouldPrintDebug);
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
return res;
|
|
1506
|
-
}
|
|
1507
|
-
};
|
|
1508
|
-
}
|
|
1509
|
-
__name(createExtractor, "createExtractor");
|
|
1510
|
-
|
|
1511
|
-
// src/constants.ts
|
|
1512
|
-
var import_find_cache_dir = __toModule(require("find-cache-dir"));
|
|
1513
|
-
var CSS_FILE_NAME = "__snack.css";
|
|
1514
|
-
var MEDIA_SEP = "_";
|
|
1515
|
-
var cacheDir = (0, import_find_cache_dir.default)({ name: "tamagui", create: true });
|
|
1516
|
-
|
|
1517
|
-
// src/extractor/extractToClassNames.ts
|
|
1518
|
-
var path = __toModule(require("path"));
|
|
1519
|
-
var import_path3 = __toModule(require("path"));
|
|
1520
|
-
var util = __toModule(require("util"));
|
|
1521
|
-
var import_generator3 = __toModule(require("@babel/generator"));
|
|
1522
|
-
var t14 = __toModule(require("@babel/types"));
|
|
1523
|
-
var import_core_node3 = __toModule(require("@tamagui/core-node"));
|
|
1524
|
-
var import_helpers2 = __toModule(require("@tamagui/helpers"));
|
|
1525
|
-
var import_invariant2 = __toModule(require("invariant"));
|
|
1526
|
-
var import_loader_utils = __toModule(require("loader-utils"));
|
|
1527
|
-
|
|
1528
|
-
// src/extractor/babelParse.ts
|
|
1529
|
-
var babelParser = __toModule(require("@babel/parser"));
|
|
1530
|
-
var parserOptions = Object.freeze({
|
|
1531
|
-
plugins: [
|
|
1532
|
-
"asyncGenerators",
|
|
1533
|
-
"classProperties",
|
|
1534
|
-
"dynamicImport",
|
|
1535
|
-
"functionBind",
|
|
1536
|
-
"jsx",
|
|
1537
|
-
"numericSeparator",
|
|
1538
|
-
"objectRestSpread",
|
|
1539
|
-
"optionalCatchBinding",
|
|
1540
|
-
"decorators-legacy",
|
|
1541
|
-
"typescript",
|
|
1542
|
-
"optionalChaining",
|
|
1543
|
-
"nullishCoalescingOperator"
|
|
1544
|
-
],
|
|
1545
|
-
sourceType: "module"
|
|
1546
|
-
});
|
|
1547
|
-
var parser = babelParser.parse.bind(babelParser);
|
|
1548
|
-
function babelParse(code) {
|
|
1549
|
-
return parser(code.toString(), parserOptions);
|
|
1550
|
-
}
|
|
1551
|
-
__name(babelParse, "babelParse");
|
|
1552
|
-
|
|
1553
|
-
// src/extractor/buildClassName.ts
|
|
1554
|
-
var t10 = __toModule(require("@babel/types"));
|
|
1555
|
-
function buildClassName(classNameObjects) {
|
|
1556
|
-
return classNameObjects.reduce((acc, val) => {
|
|
1557
|
-
if (acc == null) {
|
|
1558
|
-
if (t10.isConditionalExpression(val) || t10.isStringLiteral(val) || t10.isNumericLiteral(val)) {
|
|
1559
|
-
return val;
|
|
1560
|
-
}
|
|
1561
|
-
return t10.logicalExpression("||", val, t10.stringLiteral(""));
|
|
1562
|
-
}
|
|
1563
|
-
let inner;
|
|
1564
|
-
if (t10.isStringLiteral(val)) {
|
|
1565
|
-
if (t10.isStringLiteral(acc)) {
|
|
1566
|
-
return t10.stringLiteral(`${acc.value} ${val.value}`);
|
|
1567
|
-
}
|
|
1568
|
-
inner = t10.stringLiteral(` ${val.value}`);
|
|
1569
|
-
} else if (t10.isLiteral(val)) {
|
|
1570
|
-
inner = t10.binaryExpression("+", t10.stringLiteral(" "), val);
|
|
1571
|
-
} else if (t10.isConditionalExpression(val) || t10.isBinaryExpression(val)) {
|
|
1572
|
-
if (t10.isStringLiteral(acc)) {
|
|
1573
|
-
return t10.binaryExpression("+", t10.stringLiteral(`${acc.value} `), val);
|
|
1574
|
-
}
|
|
1575
|
-
inner = t10.binaryExpression("+", t10.stringLiteral(" "), val);
|
|
1576
|
-
} else if (t10.isIdentifier(val) || t10.isMemberExpression(val)) {
|
|
1577
|
-
inner = t10.conditionalExpression(val, t10.binaryExpression("+", t10.stringLiteral(" "), val), t10.stringLiteral(""));
|
|
1578
|
-
} else {
|
|
1579
|
-
if (t10.isStringLiteral(acc)) {
|
|
1580
|
-
return t10.binaryExpression("+", t10.stringLiteral(`${acc.value} `), t10.logicalExpression("||", val, t10.stringLiteral("")));
|
|
1581
|
-
}
|
|
1582
|
-
inner = t10.binaryExpression("+", t10.stringLiteral(" "), t10.logicalExpression("||", val, t10.stringLiteral("")));
|
|
1583
|
-
}
|
|
1584
|
-
return t10.binaryExpression("+", acc, inner);
|
|
1585
|
-
}, null);
|
|
1586
|
-
}
|
|
1587
|
-
__name(buildClassName, "buildClassName");
|
|
1588
|
-
|
|
1589
|
-
// src/extractor/ensureImportingConcat.ts
|
|
1590
|
-
var t11 = __toModule(require("@babel/types"));
|
|
1591
|
-
var importConcatPkg = "@tamagui/helpers";
|
|
1592
|
-
function ensureImportingConcat(path3) {
|
|
1593
|
-
const bodyPath = path3.get("body");
|
|
1594
|
-
const imported = bodyPath.find((x) => x.isImportDeclaration() && x.node.source.value === importConcatPkg);
|
|
1595
|
-
const importSpecifier2 = t11.importSpecifier(t11.identifier(CONCAT_CLASSNAME_IMPORT), t11.identifier(CONCAT_CLASSNAME_IMPORT));
|
|
1596
|
-
if (!imported) {
|
|
1597
|
-
path3.node.body.push(t11.importDeclaration([importSpecifier2], t11.stringLiteral(importConcatPkg)));
|
|
1598
|
-
return;
|
|
1599
|
-
}
|
|
1600
|
-
const specifiers = imported.node.specifiers;
|
|
1601
|
-
const alreadyImported = specifiers.some((x) => t11.isImportSpecifier(x) && t11.isIdentifier(x.imported) && x.imported.name === CONCAT_CLASSNAME_IMPORT);
|
|
1602
|
-
if (!alreadyImported) {
|
|
1603
|
-
specifiers.push(t11.importSpecifier(t11.identifier(CONCAT_CLASSNAME_IMPORT), t11.identifier(CONCAT_CLASSNAME_IMPORT)));
|
|
1604
|
-
}
|
|
1605
|
-
}
|
|
1606
|
-
__name(ensureImportingConcat, "ensureImportingConcat");
|
|
1607
|
-
|
|
1608
|
-
// src/extractor/extractMediaStyle.ts
|
|
1609
|
-
var t12 = __toModule(require("@babel/types"));
|
|
1610
|
-
var import_core_node2 = __toModule(require("@tamagui/core-node"));
|
|
1611
|
-
function extractMediaStyle(ternary, jsxPath, tamaguiConfig, sourcePath, importance = 0, shouldPrintDebug = false) {
|
|
1612
|
-
const mt = getMediaQueryTernary(ternary, jsxPath, sourcePath);
|
|
1613
|
-
if (!mt) {
|
|
1614
|
-
return null;
|
|
1615
|
-
}
|
|
1616
|
-
const { key } = mt;
|
|
1617
|
-
const mq = tamaguiConfig.media[key];
|
|
1618
|
-
if (!mq) {
|
|
1619
|
-
console.error(`Media query "${key}" not found: ${Object.keys(tamaguiConfig.media)}`);
|
|
1620
|
-
return null;
|
|
1621
|
-
}
|
|
1622
|
-
const getStyleObj = /* @__PURE__ */ __name((styleObj, negate = false) => {
|
|
1623
|
-
return styleObj ? { styleObj, negate } : null;
|
|
1624
|
-
}, "getStyleObj");
|
|
1625
|
-
const styleOpts = [
|
|
1626
|
-
getStyleObj(ternary.consequent, false),
|
|
1627
|
-
getStyleObj(ternary.alternate, true)
|
|
1628
|
-
].filter(isPresent);
|
|
1629
|
-
if (shouldPrintDebug && !styleOpts.length) {
|
|
1630
|
-
console.log(" media query, no styles?");
|
|
1631
|
-
return null;
|
|
1632
|
-
}
|
|
1633
|
-
const mediaKeys = Object.keys(tamaguiConfig.media);
|
|
1634
|
-
const mediaKeyPrecendence = mediaKeys.reduce((acc, cur, i) => {
|
|
1635
|
-
acc[cur] = new Array(importance + 1).fill(":root").join("");
|
|
1636
|
-
return acc;
|
|
1637
|
-
}, {});
|
|
1638
|
-
let mediaStyles = [];
|
|
1639
|
-
for (const { styleObj, negate } of styleOpts) {
|
|
1640
|
-
const styles = (0, import_core_node2.getStylesAtomic)(styleObj);
|
|
1641
|
-
const singleMediaStyles = styles.map((style) => {
|
|
1642
|
-
const negKey = negate ? "0" : "";
|
|
1643
|
-
const ogPrefix = style.identifier.slice(0, style.identifier.indexOf("-") + 1);
|
|
1644
|
-
const identifier3 = `${style.identifier.replace(ogPrefix, `${ogPrefix}${MEDIA_SEP}${key}${negKey}${MEDIA_SEP}`)}`;
|
|
1645
|
-
const className = `.${identifier3}`;
|
|
1646
|
-
const mediaSelector = (0, import_core_node2.mediaObjectToString)(tamaguiConfig.media[key]);
|
|
1647
|
-
const screenStr = negate ? "not all" : "screen";
|
|
1648
|
-
const mediaQuery = `${screenStr} and ${mediaSelector}`;
|
|
1649
|
-
const precendencePrefix = mediaKeyPrecendence[key];
|
|
1650
|
-
const styleInner = style.rules[0].replace(style.identifier, identifier3);
|
|
1651
|
-
let styleRule = "";
|
|
1652
|
-
if (styleInner.includes("@media")) {
|
|
1653
|
-
styleRule = styleInner.replace("{", ` and ${mediaQuery} {`);
|
|
1654
|
-
} else {
|
|
1655
|
-
styleRule = `@media ${mediaQuery} { ${precendencePrefix} ${styleInner} }`;
|
|
1656
|
-
}
|
|
1657
|
-
return __spreadProps(__spreadValues({}, style), {
|
|
1658
|
-
identifier: identifier3,
|
|
1659
|
-
className,
|
|
1660
|
-
rules: [styleRule]
|
|
1661
|
-
});
|
|
1662
|
-
});
|
|
1663
|
-
if (shouldPrintDebug) {
|
|
1664
|
-
console.log(" media styles:", importance, singleMediaStyles.map((x) => x.identifier).join(", "));
|
|
1665
|
-
}
|
|
1666
|
-
mediaStyles = [...mediaStyles, ...singleMediaStyles];
|
|
1667
|
-
}
|
|
1668
|
-
ternary.remove();
|
|
1669
|
-
return { mediaStyles, ternaryWithoutMedia: mt.ternaryWithoutMedia };
|
|
1670
|
-
}
|
|
1671
|
-
__name(extractMediaStyle, "extractMediaStyle");
|
|
1672
|
-
function getMediaQueryTernary(ternary, jsxPath, sourcePath) {
|
|
1673
|
-
if (t12.isLogicalExpression(ternary.test) && ternary.test.operator === "&&") {
|
|
1674
|
-
const mediaLeft = getMediaInfoFromExpression(ternary.test.left, jsxPath, sourcePath, ternary.inlineMediaQuery);
|
|
1675
|
-
if (mediaLeft) {
|
|
1676
|
-
return __spreadProps(__spreadValues({}, mediaLeft), {
|
|
1677
|
-
ternaryWithoutMedia: __spreadProps(__spreadValues({}, ternary), {
|
|
1678
|
-
test: ternary.test.right
|
|
1679
|
-
})
|
|
1680
|
-
});
|
|
1681
|
-
}
|
|
1682
|
-
}
|
|
1683
|
-
const result = getMediaInfoFromExpression(ternary.test, jsxPath, sourcePath, ternary.inlineMediaQuery);
|
|
1684
|
-
if (result) {
|
|
1685
|
-
return __spreadProps(__spreadValues({}, result), {
|
|
1686
|
-
ternaryWithoutMedia: null
|
|
1687
|
-
});
|
|
1688
|
-
}
|
|
1689
|
-
return null;
|
|
1690
|
-
}
|
|
1691
|
-
__name(getMediaQueryTernary, "getMediaQueryTernary");
|
|
1692
|
-
function getMediaInfoFromExpression(test, jsxPath, sourcePath, inlineMediaQuery) {
|
|
1693
|
-
var _a, _b, _c;
|
|
1694
|
-
if (inlineMediaQuery) {
|
|
1695
|
-
return {
|
|
1696
|
-
key: inlineMediaQuery,
|
|
1697
|
-
bindingName: inlineMediaQuery
|
|
1698
|
-
};
|
|
1699
|
-
}
|
|
1700
|
-
if (t12.isMemberExpression(test) && t12.isIdentifier(test.object) && t12.isIdentifier(test.property)) {
|
|
1701
|
-
const name = test.object["name"];
|
|
1702
|
-
const key = test.property["name"];
|
|
1703
|
-
const bindings = jsxPath.scope.getAllBindings();
|
|
1704
|
-
const binding = bindings[name];
|
|
1705
|
-
if (!binding)
|
|
1706
|
-
return false;
|
|
1707
|
-
const bindingNode = (_a = binding.path) == null ? void 0 : _a.node;
|
|
1708
|
-
if (!t12.isVariableDeclarator(bindingNode) || !bindingNode.init)
|
|
1709
|
-
return false;
|
|
1710
|
-
if (!isValidMediaCall(jsxPath, bindingNode.init, sourcePath))
|
|
1711
|
-
return false;
|
|
1712
|
-
return { key, bindingName: name };
|
|
1713
|
-
}
|
|
1714
|
-
if (t12.isIdentifier(test)) {
|
|
1715
|
-
const key = test.name;
|
|
1716
|
-
const node = (_c = (_b = jsxPath.scope.getBinding(test.name)) == null ? void 0 : _b.path) == null ? void 0 : _c.node;
|
|
1717
|
-
if (!t12.isVariableDeclarator(node))
|
|
1718
|
-
return false;
|
|
1719
|
-
if (!node.init || !isValidMediaCall(jsxPath, node.init, sourcePath))
|
|
1720
|
-
return false;
|
|
1721
|
-
return { key, bindingName: key };
|
|
1722
|
-
}
|
|
1723
|
-
return null;
|
|
1724
|
-
}
|
|
1725
|
-
__name(getMediaInfoFromExpression, "getMediaInfoFromExpression");
|
|
1726
|
-
function isValidMediaCall(jsxPath, init, sourcePath) {
|
|
1727
|
-
if (!t12.isCallExpression(init))
|
|
1728
|
-
return false;
|
|
1729
|
-
if (!t12.isIdentifier(init.callee))
|
|
1730
|
-
return false;
|
|
1731
|
-
if (init.callee.name !== "useMedia")
|
|
1732
|
-
return false;
|
|
1733
|
-
const bindings = jsxPath.scope.getAllBindings();
|
|
1734
|
-
const mediaBinding = bindings["useMedia"];
|
|
1735
|
-
if (!mediaBinding)
|
|
1736
|
-
return false;
|
|
1737
|
-
const useMediaImport = mediaBinding.path.parent;
|
|
1738
|
-
if (!t12.isImportDeclaration(useMediaImport))
|
|
1739
|
-
return false;
|
|
1740
|
-
if (useMediaImport.source.value !== "tamagui") {
|
|
1741
|
-
if (!isInsideTamagui(sourcePath)) {
|
|
1742
|
-
return false;
|
|
1743
|
-
}
|
|
1744
|
-
}
|
|
1745
|
-
return true;
|
|
1746
|
-
}
|
|
1747
|
-
__name(isValidMediaCall, "isValidMediaCall");
|
|
1748
|
-
|
|
1749
|
-
// src/extractor/hoistClassNames.ts
|
|
1750
|
-
var t13 = __toModule(require("@babel/types"));
|
|
1751
|
-
function hoistClassNames(path3, existing, expr) {
|
|
1752
|
-
const hoist = hoistClassNames.bind(null, path3, existing);
|
|
1753
|
-
if (t13.isStringLiteral(expr)) {
|
|
1754
|
-
if (expr.value.trim() === "") {
|
|
1755
|
-
return expr;
|
|
1756
|
-
}
|
|
1757
|
-
if (existing[expr.value]) {
|
|
1758
|
-
return existing[expr.value];
|
|
1759
|
-
}
|
|
1760
|
-
const identifier3 = replaceStringWithVariable(expr);
|
|
1761
|
-
existing[expr.value] = identifier3;
|
|
1762
|
-
return identifier3;
|
|
1763
|
-
}
|
|
1764
|
-
if (t13.isBinaryExpression(expr)) {
|
|
1765
|
-
return t13.binaryExpression(expr.operator, hoist(expr.left), hoist(expr.right));
|
|
1766
|
-
}
|
|
1767
|
-
if (t13.isLogicalExpression(expr)) {
|
|
1768
|
-
return t13.logicalExpression(expr.operator, hoist(expr.left), hoist(expr.right));
|
|
1769
|
-
}
|
|
1770
|
-
if (t13.isConditionalExpression(expr)) {
|
|
1771
|
-
return t13.conditionalExpression(expr.test, hoist(expr.consequent), hoist(expr.alternate));
|
|
1772
|
-
}
|
|
1773
|
-
return expr;
|
|
1774
|
-
function replaceStringWithVariable(str) {
|
|
1775
|
-
const uid = path3.scope.generateUidIdentifier("cn");
|
|
1776
|
-
const parent = path3.findParent((path4) => path4.isProgram());
|
|
1777
|
-
if (!parent)
|
|
1778
|
-
throw new Error(`no program?`);
|
|
1779
|
-
const variable = t13.variableDeclaration("const", [
|
|
1780
|
-
t13.variableDeclarator(uid, t13.stringLiteral(` ${str.value}`))
|
|
1781
|
-
]);
|
|
1782
|
-
parent.unshiftContainer("body", variable);
|
|
1783
|
-
return uid;
|
|
1784
|
-
}
|
|
1785
|
-
__name(replaceStringWithVariable, "replaceStringWithVariable");
|
|
1786
|
-
}
|
|
1787
|
-
__name(hoistClassNames, "hoistClassNames");
|
|
1788
|
-
|
|
1789
|
-
// src/extractor/extractToClassNames.ts
|
|
1790
|
-
var CONCAT_CLASSNAME_IMPORT = "concatClassName";
|
|
1791
|
-
var mergeStyleGroups = {
|
|
1792
|
-
shadowOpacity: true,
|
|
1793
|
-
shadowRadius: true,
|
|
1794
|
-
shadowColor: true,
|
|
1795
|
-
shadowOffset: true
|
|
1796
|
-
};
|
|
1797
|
-
function extractToClassNames({
|
|
1798
|
-
loader,
|
|
1799
|
-
extractor,
|
|
1800
|
-
source,
|
|
1801
|
-
sourcePath,
|
|
1802
|
-
options,
|
|
1803
|
-
shouldPrintDebug,
|
|
1804
|
-
threaded,
|
|
1805
|
-
cssPath
|
|
1806
|
-
}) {
|
|
1807
|
-
if (typeof source !== "string") {
|
|
1808
|
-
throw new Error("`source` must be a string of javascript");
|
|
1809
|
-
}
|
|
1810
|
-
(0, import_invariant2.default)(typeof sourcePath === "string" && path.isAbsolute(sourcePath), "`sourcePath` must be an absolute path to a .js file");
|
|
1811
|
-
const shouldLogTiming = shouldPrintDebug || options.logTimings;
|
|
1812
|
-
const start = Date.now();
|
|
1813
|
-
const mem = shouldLogTiming ? process.memoryUsage() : null;
|
|
1814
|
-
let ast;
|
|
1815
|
-
try {
|
|
1816
|
-
ast = babelParse(source);
|
|
1817
|
-
} catch (err) {
|
|
1818
|
-
console.error("babel parse error:", sourcePath);
|
|
1819
|
-
throw err;
|
|
1820
|
-
}
|
|
1821
|
-
const cssMap = new Map();
|
|
1822
|
-
const existingHoists = {};
|
|
1823
|
-
const res = extractor.parse(ast, __spreadProps(__spreadValues({
|
|
1824
|
-
sourcePath,
|
|
1825
|
-
shouldPrintDebug
|
|
1826
|
-
}, options), {
|
|
1827
|
-
getFlattenedNode: ({ tag }) => tag,
|
|
1828
|
-
onExtractTag: ({
|
|
1829
|
-
attrs,
|
|
1830
|
-
node,
|
|
1831
|
-
attemptEval,
|
|
1832
|
-
jsxPath,
|
|
1833
|
-
originalNodeName,
|
|
1834
|
-
filePath,
|
|
1835
|
-
lineNumbers,
|
|
1836
|
-
programPath
|
|
1837
|
-
}) => {
|
|
1838
|
-
let finalClassNames = [];
|
|
1839
|
-
let finalAttrs = [];
|
|
1840
|
-
let finalStyles = [];
|
|
1841
|
-
const viewStyles = {};
|
|
1842
|
-
for (const attr of attrs) {
|
|
1843
|
-
if (attr.type === "style") {
|
|
1844
|
-
Object.assign(viewStyles, attr.value);
|
|
1845
|
-
}
|
|
1846
|
-
}
|
|
1847
|
-
const ensureNeededPrevStyle = /* @__PURE__ */ __name((style) => {
|
|
1848
|
-
const keys = Object.keys(style);
|
|
1849
|
-
if (!keys.some((key) => mergeStyleGroups[key])) {
|
|
1850
|
-
return style;
|
|
1851
|
-
}
|
|
1852
|
-
for (const k in mergeStyleGroups) {
|
|
1853
|
-
if (k in viewStyles) {
|
|
1854
|
-
style[k] = style[k] ?? viewStyles[k];
|
|
1855
|
-
}
|
|
1856
|
-
}
|
|
1857
|
-
return style;
|
|
1858
|
-
}, "ensureNeededPrevStyle");
|
|
1859
|
-
const addStyles = /* @__PURE__ */ __name((style) => {
|
|
1860
|
-
if (!style)
|
|
1861
|
-
return [];
|
|
1862
|
-
const styleWithPrev = ensureNeededPrevStyle(style);
|
|
1863
|
-
const res2 = (0, import_core_node3.getStylesAtomic)(styleWithPrev);
|
|
1864
|
-
if (res2.length) {
|
|
1865
|
-
finalStyles = [...finalStyles, ...res2];
|
|
1866
|
-
}
|
|
1867
|
-
return res2;
|
|
1868
|
-
}, "addStyles");
|
|
1869
|
-
let lastMediaImportance = 1;
|
|
1870
|
-
for (const attr of attrs) {
|
|
1871
|
-
switch (attr.type) {
|
|
1872
|
-
case "style":
|
|
1873
|
-
const styles2 = addStyles(attr.value);
|
|
1874
|
-
const newClassNames = (0, import_helpers2.concatClassName)(styles2.map((x) => x.identifier).join(" "));
|
|
1875
|
-
if (shouldPrintDebug) {
|
|
1876
|
-
console.log(" classnames", newClassNames, finalClassNames);
|
|
1877
|
-
}
|
|
1878
|
-
const existing = finalClassNames.find((x) => x.type == "StringLiteral");
|
|
1879
|
-
if (existing) {
|
|
1880
|
-
existing.value = `${existing.value} ${newClassNames}`;
|
|
1881
|
-
} else {
|
|
1882
|
-
finalClassNames = [...finalClassNames, t14.stringLiteral(newClassNames)];
|
|
1883
|
-
}
|
|
1884
|
-
if (shouldPrintDebug) {
|
|
1885
|
-
console.log(" classnames (after)", finalClassNames.map((x) => x["value"]).join(" "));
|
|
1886
|
-
}
|
|
1887
|
-
break;
|
|
1888
|
-
case "attr":
|
|
1889
|
-
const val = attr.value;
|
|
1890
|
-
if (t14.isJSXSpreadAttribute(val)) {
|
|
1891
|
-
if (isSimpleSpread(val)) {
|
|
1892
|
-
finalClassNames.push(t14.logicalExpression("&&", val.argument, t14.memberExpression(val.argument, t14.identifier("className"))));
|
|
1893
|
-
}
|
|
1894
|
-
} else if (val.name.name === "className") {
|
|
1895
|
-
const value = val.value;
|
|
1896
|
-
if (value) {
|
|
1897
|
-
try {
|
|
1898
|
-
const evaluatedValue = attemptEval(value);
|
|
1899
|
-
finalClassNames.push(t14.stringLiteral(evaluatedValue));
|
|
1900
|
-
} catch (e) {
|
|
1901
|
-
finalClassNames.push(value["expression"]);
|
|
1902
|
-
}
|
|
1903
|
-
}
|
|
1904
|
-
continue;
|
|
1905
|
-
}
|
|
1906
|
-
finalAttrs.push(val);
|
|
1907
|
-
break;
|
|
1908
|
-
case "ternary":
|
|
1909
|
-
const mediaExtraction = extractMediaStyle(attr.value, jsxPath, extractor.getTamaguiConfig(), sourcePath, lastMediaImportance, shouldPrintDebug);
|
|
1910
|
-
if (mediaExtraction) {
|
|
1911
|
-
lastMediaImportance++;
|
|
1912
|
-
finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles];
|
|
1913
|
-
finalClassNames = [
|
|
1914
|
-
...finalClassNames,
|
|
1915
|
-
...mediaExtraction.mediaStyles.map((x) => t14.stringLiteral(x.identifier))
|
|
1916
|
-
];
|
|
1917
|
-
if (!mediaExtraction.ternaryWithoutMedia) {
|
|
1918
|
-
continue;
|
|
1919
|
-
}
|
|
1920
|
-
}
|
|
1921
|
-
const ternary = (mediaExtraction == null ? void 0 : mediaExtraction.ternaryWithoutMedia) || attr.value;
|
|
1922
|
-
const consInfo = addStyles(ternary.consequent);
|
|
1923
|
-
const altInfo = addStyles(ternary.alternate);
|
|
1924
|
-
const cCN = consInfo.map((x) => x.identifier).join(" ");
|
|
1925
|
-
const aCN = altInfo.map((x) => x.identifier).join(" ");
|
|
1926
|
-
if (consInfo.length && altInfo.length) {
|
|
1927
|
-
finalClassNames.push(t14.conditionalExpression(ternary.test, t14.stringLiteral(cCN), t14.stringLiteral(aCN)));
|
|
1928
|
-
} else {
|
|
1929
|
-
finalClassNames.push(t14.conditionalExpression(ternary.test, t14.stringLiteral(" " + cCN), t14.stringLiteral(" " + aCN)));
|
|
1930
|
-
}
|
|
1931
|
-
break;
|
|
1932
|
-
}
|
|
1933
|
-
}
|
|
1934
|
-
node.attributes = finalAttrs;
|
|
1935
|
-
if (finalClassNames.length) {
|
|
1936
|
-
const names = buildClassName(finalClassNames);
|
|
1937
|
-
const nameExpr = names ? hoistClassNames(jsxPath, existingHoists, names) : null;
|
|
1938
|
-
let expr = nameExpr;
|
|
1939
|
-
if (nameExpr && !t14.isIdentifier(nameExpr)) {
|
|
1940
|
-
ensureImportingConcat(programPath);
|
|
1941
|
-
const simpleSpreads = attrs.filter((x) => t14.isJSXSpreadAttribute(x.value) && isSimpleSpread(x.value));
|
|
1942
|
-
expr = t14.callExpression(t14.identifier(CONCAT_CLASSNAME_IMPORT), [
|
|
1943
|
-
expr,
|
|
1944
|
-
...simpleSpreads.map((val) => val.value["argument"])
|
|
1945
|
-
]);
|
|
1946
|
-
}
|
|
1947
|
-
node.attributes.push(t14.jsxAttribute(t14.jsxIdentifier("className"), t14.jsxExpressionContainer(expr)));
|
|
1948
|
-
}
|
|
1949
|
-
const comment = util.format("/* %s:%s (%s) */", filePath, lineNumbers, originalNodeName);
|
|
1950
|
-
for (const { className, rules } of finalStyles) {
|
|
1951
|
-
if (cssMap.has(className)) {
|
|
1952
|
-
if (comment) {
|
|
1953
|
-
const val = cssMap.get(className);
|
|
1954
|
-
val.commentTexts.push(comment);
|
|
1955
|
-
cssMap.set(className, val);
|
|
1956
|
-
}
|
|
1957
|
-
} else if (rules.length) {
|
|
1958
|
-
if (rules.length > 1) {
|
|
1959
|
-
console.log(" rules error", { rules });
|
|
1960
|
-
throw new Error(`Shouldn't have more than one rule`);
|
|
1961
|
-
}
|
|
1962
|
-
cssMap.set(className, {
|
|
1963
|
-
css: rules[0],
|
|
1964
|
-
commentTexts: [comment]
|
|
1965
|
-
});
|
|
1966
|
-
}
|
|
1967
|
-
}
|
|
1968
|
-
}
|
|
1969
|
-
}));
|
|
1970
|
-
if (!res || !res.modified) {
|
|
1971
|
-
return null;
|
|
1972
|
-
}
|
|
1973
|
-
const styles = Array.from(cssMap.values()).map((x) => x.css).join("\n").trim();
|
|
1974
|
-
if (styles) {
|
|
1975
|
-
const cssQuery = threaded ? `cssData=${Buffer.from(styles).toString("base64")}` : `cssPath=${cssPath}`;
|
|
1976
|
-
const remReq = (0, import_loader_utils.getRemainingRequest)(loader);
|
|
1977
|
-
const importPath = `${cssPath}!=!tamagui-loader?${cssQuery}!${remReq}`;
|
|
1978
|
-
ast.program.body.unshift(t14.importDeclaration([], t14.stringLiteral(importPath)));
|
|
1979
|
-
}
|
|
1980
|
-
const result = (0, import_generator3.default)(ast, {
|
|
1981
|
-
concise: false,
|
|
1982
|
-
filename: sourcePath,
|
|
1983
|
-
retainLines: false,
|
|
1984
|
-
sourceFileName: sourcePath,
|
|
1985
|
-
sourceMaps: true
|
|
1986
|
-
}, source);
|
|
1987
|
-
if (shouldPrintDebug) {
|
|
1988
|
-
console.log("\n -------- output code ------- \n\n", result.code.split("\n").filter((x) => !x.startsWith("//")).join("\n"));
|
|
1989
|
-
console.log("\n -------- output style -------- \n\n", styles);
|
|
1990
|
-
}
|
|
1991
|
-
if (shouldLogTiming && mem) {
|
|
1992
|
-
const memUsed = Math.round((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204 * 10) / 10;
|
|
1993
|
-
console.log(` \u{1F95A} ${(0, import_path3.basename)(sourcePath).padStart(40)} ${`${Date.now() - start}`.padStart(3)}ms \u05C1\xB7 ${`${res.optimized}`.padStart(4)} optimized \xB7 ${res.flattened} flattened ${memUsed > 10 ? `used ${memUsed}MB` : ""}`);
|
|
1994
|
-
}
|
|
1995
|
-
return {
|
|
1996
|
-
ast,
|
|
1997
|
-
styles,
|
|
1998
|
-
js: result.code,
|
|
1999
|
-
map: result.map
|
|
2000
|
-
};
|
|
2001
|
-
}
|
|
2002
|
-
__name(extractToClassNames, "extractToClassNames");
|
|
2003
|
-
|
|
2004
|
-
// src/patchReactNativeWeb.ts
|
|
2005
|
-
var fs = __toModule(require("fs"));
|
|
2006
|
-
var import_path4 = __toModule(require("path"));
|
|
2007
|
-
function patchReactNativeWeb() {
|
|
2008
|
-
const rootDir = require.resolve("react-native-web").replace(/\/dist.*/, "");
|
|
2009
|
-
const modulePath = import_path4.default.join(rootDir, "dist", "tamagui-exports.js");
|
|
2010
|
-
const cjsPath = import_path4.default.join(rootDir, "dist", "cjs", "tamagui-exports.js");
|
|
2011
|
-
const isEqual = (() => {
|
|
2012
|
-
let res = false;
|
|
2013
|
-
try {
|
|
2014
|
-
res = fs.readFileSync(modulePath, "utf-8") === moduleExports && fs.readFileSync(cjsPath, "utf-8") == cjsExports;
|
|
2015
|
-
} catch {
|
|
2016
|
-
res = false;
|
|
2017
|
-
}
|
|
2018
|
-
return res;
|
|
2019
|
-
})();
|
|
2020
|
-
if (!isEqual) {
|
|
2021
|
-
console.log("\u{1F95A} Tamagui patching react-native-web to share atomic styling primitives");
|
|
2022
|
-
console.log(" > adding", modulePath);
|
|
2023
|
-
console.log(" > adding", cjsPath);
|
|
2024
|
-
fs.writeFileSync(modulePath, moduleExports);
|
|
2025
|
-
fs.writeFileSync(cjsPath, cjsExports);
|
|
2026
|
-
}
|
|
2027
|
-
const moduleEntry = import_path4.default.join(rootDir, "dist", "index.js");
|
|
2028
|
-
const moduleEntrySrc = fs.readFileSync(moduleEntry, "utf-8");
|
|
2029
|
-
if (!moduleEntrySrc.includes("// tamagui-patch-v4")) {
|
|
2030
|
-
fs.writeFileSync(moduleEntry, `${removePatch(moduleEntrySrc)}
|
|
2031
|
-
|
|
2032
|
-
// tamagui-patch-v4
|
|
2033
|
-
import * as TExports from './tamagui-exports'
|
|
2034
|
-
export const TamaguiExports = TExports
|
|
2035
|
-
// tamagui-patch-end
|
|
2036
|
-
`);
|
|
2037
|
-
}
|
|
2038
|
-
const cjsEntry = import_path4.default.join(rootDir, "dist", "cjs", "index.js");
|
|
2039
|
-
const cjsEntrySrc = fs.readFileSync(cjsEntry, "utf-8");
|
|
2040
|
-
if (!cjsEntrySrc.includes("// tamagui-patch-v4")) {
|
|
2041
|
-
fs.writeFileSync(cjsEntry, `${removePatch(cjsEntrySrc)}
|
|
2042
|
-
|
|
2043
|
-
// tamagui-patch-v4
|
|
2044
|
-
exports.TamaguiExports = _interopRequireDefault(require("./tamagui-exports"));
|
|
2045
|
-
// tamagui-patch-end
|
|
2046
|
-
`);
|
|
2047
|
-
}
|
|
2048
|
-
}
|
|
2049
|
-
__name(patchReactNativeWeb, "patchReactNativeWeb");
|
|
2050
|
-
function removePatch(source) {
|
|
2051
|
-
return source.replace(/\/\/ tamagui-patch([.\s\S]*)/g, "");
|
|
2052
|
-
}
|
|
2053
|
-
__name(removePatch, "removePatch");
|
|
2054
|
-
var forwardedPropsObj = `{
|
|
2055
|
-
...fwdProps.defaultProps,
|
|
2056
|
-
...fwdProps.accessibilityProps,
|
|
2057
|
-
...fwdProps.clickProps,
|
|
2058
|
-
...fwdProps.focusProps,
|
|
2059
|
-
...fwdProps.keyboardProps,
|
|
2060
|
-
...fwdProps.mouseProps,
|
|
2061
|
-
...fwdProps.touchProps,
|
|
2062
|
-
...fwdProps.styleProps,
|
|
2063
|
-
href: true,
|
|
2064
|
-
lang: true,
|
|
2065
|
-
onScroll: true,
|
|
2066
|
-
onWheel: true,
|
|
2067
|
-
pointerEvents: true
|
|
2068
|
-
}
|
|
2069
|
-
`;
|
|
2070
|
-
var moduleExports = `
|
|
2071
|
-
export { atomic } from './exports/StyleSheet/compile'
|
|
2072
|
-
export { default as createCompileableStyle } from './exports/StyleSheet/createCompileableStyle'
|
|
2073
|
-
export { default as createReactDOMStyle } from './exports/StyleSheet/createReactDOMStyle'
|
|
2074
|
-
export { default as i18Style } from './exports/StyleSheet/i18nStyle'
|
|
2075
|
-
export { default as createDOMProps } from './modules/createDOMProps'
|
|
2076
|
-
export { default as AccessibilityUtil } from './modules/AccessibilityUtil'
|
|
2077
|
-
export { default as createElement } from './exports/createElement'
|
|
2078
|
-
export { default as css } from './exports/StyleSheet/css'
|
|
2079
|
-
export { default as TextAncestorContext } from './exports/Text/TextAncestorContext'
|
|
2080
|
-
export { default as pick } from './modules/pick'
|
|
2081
|
-
export { default as useElementLayout } from './modules/useElementLayout'
|
|
2082
|
-
export { default as useMergeRefs } from './modules/useMergeRefs'
|
|
2083
|
-
export { default as usePlatformMethods } from './modules/usePlatformMethods'
|
|
2084
|
-
export { default as useResponderEvents } from './modules/useResponderEvents'
|
|
2085
|
-
import * as fwdProps from './modules/forwardedProps'
|
|
2086
|
-
export const forwardedProps = ${forwardedPropsObj}
|
|
2087
|
-
`;
|
|
2088
|
-
var cjsExports = `
|
|
2089
|
-
exports.atomic = require('./exports/StyleSheet/compile').atomic
|
|
2090
|
-
exports.createCompileableStyle = require('./exports/StyleSheet/createCompileableStyle')
|
|
2091
|
-
exports.createReactDOMStyle = require('./exports/StyleSheet/createReactDOMStyle')
|
|
2092
|
-
exports.i18Style = require('./exports/StyleSheet/i18nStyle')
|
|
2093
|
-
exports.createDOMProps = require('./modules/createDOMProps')
|
|
2094
|
-
exports.AccessibilityUtil = require('./modules/AccessibilityUtil')
|
|
2095
|
-
exports.createElement = require('./exports/createElement')
|
|
2096
|
-
exports.css = require('./exports/StyleSheet/css')
|
|
2097
|
-
exports.TextAncestorContext = require('./exports/Text/TextAncestorContext')
|
|
2098
|
-
exports.pick = require('./modules/pick')
|
|
2099
|
-
exports.useElementLayout = require('./modules/useElementLayout')
|
|
2100
|
-
exports.useMergeRefs = require('./modules/useMergeRefs')
|
|
2101
|
-
exports.usePlatformMethods = require('./modules/usePlatformMethods')
|
|
2102
|
-
exports.useResponderEvents = require('./modules/useResponderEvents')
|
|
2103
|
-
const fwdProps = require('./modules/forwardedProps')
|
|
2104
|
-
exports.forwardedProps = ${forwardedPropsObj}
|
|
2105
|
-
`;
|
|
2106
|
-
|
|
2107
|
-
// src/index.ts
|
|
2108
|
-
process.env.TAMAGUI_COMPILE_PROCESS = "1";
|
|
2109
|
-
//# sourceMappingURL=index.cjs.map
|