@tamagui/static 1.0.0-alpha.0 → 1.0.0-alpha.12
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/LICENSE +21 -0
- package/dist/cjs/constants.js +33 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/extractor/accessSafe.js +33 -0
- package/dist/cjs/extractor/accessSafe.js.map +7 -0
- package/dist/cjs/extractor/babelParse.js +52 -0
- package/dist/cjs/extractor/babelParse.js.map +7 -0
- package/dist/cjs/extractor/buildClassName.js +62 -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 +903 -0
- package/dist/cjs/extractor/createExtractor.js.map +7 -0
- package/dist/cjs/extractor/ensureImportingConcat.js +46 -0
- package/dist/cjs/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/cjs/extractor/evaluateAstNode.js +116 -0
- package/dist/cjs/extractor/evaluateAstNode.js.map +7 -0
- package/dist/cjs/extractor/extractHelpers.js +118 -0
- package/dist/cjs/extractor/extractHelpers.js.map +7 -0
- package/dist/cjs/extractor/extractMediaStyle.js +187 -0
- package/dist/cjs/extractor/extractMediaStyle.js.map +7 -0
- package/dist/cjs/extractor/extractToClassNames.js +272 -0
- package/dist/cjs/extractor/extractToClassNames.js.map +7 -0
- package/dist/cjs/extractor/findTopmostFunction.js +29 -0
- package/dist/cjs/extractor/findTopmostFunction.js.map +7 -0
- package/dist/cjs/extractor/generatedUid.js +50 -0
- package/dist/cjs/extractor/generatedUid.js.map +7 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js +71 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +7 -0
- package/dist/cjs/extractor/getSourceModule.js +91 -0
- package/dist/cjs/extractor/getSourceModule.js.map +7 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js +150 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +7 -0
- package/dist/cjs/extractor/hoistClassNames.js +66 -0
- package/dist/cjs/extractor/hoistClassNames.js.map +7 -0
- package/dist/cjs/extractor/literalToAst.js +56 -0
- package/dist/cjs/extractor/literalToAst.js.map +7 -0
- package/dist/cjs/extractor/loadTamagui.js +63 -0
- package/dist/cjs/extractor/loadTamagui.js.map +7 -0
- package/dist/cjs/extractor/logLines.js +23 -0
- package/dist/cjs/extractor/logLines.js.map +7 -0
- package/dist/cjs/extractor/normalizeTernaries.js +102 -0
- package/dist/cjs/extractor/normalizeTernaries.js.map +7 -0
- package/dist/cjs/extractor/removeUnusedHooks.js +101 -0
- package/dist/cjs/extractor/removeUnusedHooks.js.map +7 -0
- package/dist/cjs/index.js +37 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/patchReactNativeWeb.js +129 -0
- package/dist/cjs/patchReactNativeWeb.js.map +7 -0
- package/dist/cjs/types.js +4 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/{constants.js → esm/constants.js} +0 -0
- package/dist/{constants.js.map → esm/constants.js.map} +1 -1
- package/dist/{extractor → esm/extractor}/accessSafe.js +0 -0
- package/dist/{extractor → esm/extractor}/accessSafe.js.map +1 -1
- package/dist/{extractor → esm/extractor}/babelParse.js +0 -0
- package/dist/{extractor → esm/extractor}/babelParse.js.map +1 -1
- package/dist/{extractor → esm/extractor}/buildClassName.js +0 -0
- package/dist/{extractor → esm/extractor}/buildClassName.js.map +1 -1
- package/dist/{extractor → esm/extractor}/createEvaluator.js +0 -0
- package/dist/{extractor → esm/extractor}/createEvaluator.js.map +1 -1
- package/dist/{extractor → esm/extractor}/createExtractor.js +92 -53
- package/dist/esm/extractor/createExtractor.js.map +7 -0
- package/dist/{extractor → esm/extractor}/ensureImportingConcat.js +0 -0
- package/dist/{extractor → esm/extractor}/ensureImportingConcat.js.map +1 -1
- package/dist/{extractor → esm/extractor}/evaluateAstNode.js +0 -0
- package/dist/{extractor → esm/extractor}/evaluateAstNode.js.map +1 -1
- package/dist/{extractor → esm/extractor}/extractHelpers.js +3 -1
- package/dist/esm/extractor/extractHelpers.js.map +7 -0
- package/dist/{extractor → esm/extractor}/extractMediaStyle.js +0 -0
- package/dist/{extractor → esm/extractor}/extractMediaStyle.js.map +1 -1
- package/dist/{extractor → esm/extractor}/extractToClassNames.js +11 -21
- 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 +1 -1
- package/dist/{extractor → esm/extractor}/generatedUid.js +0 -0
- package/dist/{extractor → esm/extractor}/generatedUid.js.map +1 -1
- package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js +0 -0
- package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js.map +1 -1
- package/dist/{extractor → esm/extractor}/getSourceModule.js +0 -0
- package/dist/{extractor → esm/extractor}/getSourceModule.js.map +1 -1
- package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js +0 -0
- package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js.map +1 -1
- package/dist/{extractor → esm/extractor}/hoistClassNames.js +0 -0
- package/dist/{extractor → esm/extractor}/hoistClassNames.js.map +1 -1
- package/dist/{extractor → esm/extractor}/literalToAst.js +0 -0
- package/dist/{extractor → esm/extractor}/literalToAst.js.map +1 -1
- package/dist/{extractor → esm/extractor}/loadTamagui.js +0 -0
- package/dist/{extractor → esm/extractor}/loadTamagui.js.map +1 -1
- package/dist/esm/extractor/logLines.js +17 -0
- package/dist/esm/extractor/logLines.js.map +7 -0
- package/dist/{extractor → esm/extractor}/normalizeTernaries.js +0 -0
- package/dist/{extractor → esm/extractor}/normalizeTernaries.js.map +1 -1
- package/dist/{extractor → esm/extractor}/removeUnusedHooks.js +0 -0
- package/dist/{extractor → esm/extractor}/removeUnusedHooks.js.map +1 -1
- 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} +18 -3
- 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 +9 -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 +50 -0
- package/dist/jsx/extractor/createExtractor.js +839 -0
- package/dist/jsx/extractor/ensureImportingConcat.js +23 -0
- package/dist/jsx/extractor/evaluateAstNode.js +93 -0
- package/dist/jsx/extractor/extractHelpers.js +93 -0
- package/dist/jsx/extractor/extractMediaStyle.js +150 -0
- package/dist/jsx/extractor/extractToClassNames.js +232 -0
- package/dist/jsx/extractor/findTopmostFunction.js +22 -0
- package/dist/jsx/extractor/generatedUid.js +27 -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 +33 -0
- package/dist/jsx/extractor/loadTamagui.js +40 -0
- package/dist/jsx/extractor/logLines.js +16 -0
- package/dist/jsx/extractor/normalizeTernaries.js +51 -0
- package/dist/jsx/extractor/removeUnusedHooks.js +77 -0
- package/dist/jsx/index.js +13 -0
- package/dist/jsx/patchReactNativeWeb.js +106 -0
- package/dist/jsx/types.js +0 -0
- package/package.json +30 -27
- package/src/extractor/createExtractor.ts +115 -76
- package/src/extractor/extractHelpers.ts +12 -3
- package/src/extractor/extractToClassNames.ts +7 -21
- package/src/extractor/logLines.ts +11 -0
- package/src/patchReactNativeWeb.ts +21 -5
- package/src/types.ts +13 -3
- package/types/constants.d.ts +4 -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 +34 -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 +22 -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/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 +3 -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/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 +79 -0
- package/types/types.d.ts.map +1 -0
- package/dist/extractor/createExtractor.js.map +0 -7
- package/dist/extractor/extractHelpers.js.map +0 -7
- package/dist/extractor/extractToClassNames.js.map +0 -7
- package/dist/index.cjs +0 -2079
- package/dist/index.cjs.map +0 -7
- package/dist/patchReactNativeWeb.js.map +0 -7
|
@@ -0,0 +1,903 @@
|
|
|
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
|
+
__export(exports, {
|
|
55
|
+
FAILED_EVAL: () => FAILED_EVAL,
|
|
56
|
+
createExtractor: () => createExtractor
|
|
57
|
+
});
|
|
58
|
+
var import_traverse = __toModule(require("@babel/traverse"));
|
|
59
|
+
var t = __toModule(require("@babel/types"));
|
|
60
|
+
var CoreNode = __toModule(require("@tamagui/core-node"));
|
|
61
|
+
var import_helpers = __toModule(require("@tamagui/helpers"));
|
|
62
|
+
var import_lodash = __toModule(require("lodash"));
|
|
63
|
+
var import_createEvaluator = __toModule(require("./createEvaluator"));
|
|
64
|
+
var import_evaluateAstNode = __toModule(require("./evaluateAstNode"));
|
|
65
|
+
var import_extractHelpers = __toModule(require("./extractHelpers"));
|
|
66
|
+
var import_findTopmostFunction = __toModule(require("./findTopmostFunction"));
|
|
67
|
+
var import_getStaticBindingsForScope = __toModule(require("./getStaticBindingsForScope"));
|
|
68
|
+
var import_literalToAst = __toModule(require("./literalToAst"));
|
|
69
|
+
var import_loadTamagui = __toModule(require("./loadTamagui"));
|
|
70
|
+
var import_logLines = __toModule(require("./logLines"));
|
|
71
|
+
var import_normalizeTernaries = __toModule(require("./normalizeTernaries"));
|
|
72
|
+
var import_removeUnusedHooks = __toModule(require("./removeUnusedHooks"));
|
|
73
|
+
const { mediaQueryConfig, postProcessStyles, pseudos } = CoreNode;
|
|
74
|
+
const FAILED_EVAL = Symbol("failed_style_eval");
|
|
75
|
+
const UNTOUCHED_PROPS = {
|
|
76
|
+
key: true,
|
|
77
|
+
style: true,
|
|
78
|
+
className: true
|
|
79
|
+
};
|
|
80
|
+
const isAttr = /* @__PURE__ */ __name((x) => x.type === "attr", "isAttr");
|
|
81
|
+
const validHooks = {
|
|
82
|
+
useMedia: true,
|
|
83
|
+
useTheme: true
|
|
84
|
+
};
|
|
85
|
+
const createTernary = /* @__PURE__ */ __name((x) => x, "createTernary");
|
|
86
|
+
function createExtractor() {
|
|
87
|
+
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);
|
|
88
|
+
require("esbuild-register/dist/node").register({
|
|
89
|
+
target: "es2019",
|
|
90
|
+
format: "cjs"
|
|
91
|
+
});
|
|
92
|
+
let loadedTamaguiConfig;
|
|
93
|
+
let hasLogged = false;
|
|
94
|
+
return {
|
|
95
|
+
getTamagui() {
|
|
96
|
+
return loadedTamaguiConfig;
|
|
97
|
+
},
|
|
98
|
+
parse: (fileOrPath, _a) => {
|
|
99
|
+
var _b = _a, {
|
|
100
|
+
config = "tamagui.config.ts",
|
|
101
|
+
importsWhitelist = ["constants.js"],
|
|
102
|
+
evaluateVars = true,
|
|
103
|
+
shouldPrintDebug = false,
|
|
104
|
+
sourcePath = "",
|
|
105
|
+
onExtractTag,
|
|
106
|
+
getFlattenedNode,
|
|
107
|
+
disableExtraction,
|
|
108
|
+
disableExtractInlineMedia,
|
|
109
|
+
disableExtractVariables,
|
|
110
|
+
disableDebugAttr
|
|
111
|
+
} = _b, props = __objRest(_b, [
|
|
112
|
+
"config",
|
|
113
|
+
"importsWhitelist",
|
|
114
|
+
"evaluateVars",
|
|
115
|
+
"shouldPrintDebug",
|
|
116
|
+
"sourcePath",
|
|
117
|
+
"onExtractTag",
|
|
118
|
+
"getFlattenedNode",
|
|
119
|
+
"disableExtraction",
|
|
120
|
+
"disableExtractInlineMedia",
|
|
121
|
+
"disableExtractVariables",
|
|
122
|
+
"disableDebugAttr"
|
|
123
|
+
]);
|
|
124
|
+
if (sourcePath === "") {
|
|
125
|
+
throw new Error(`Must provide a source file name`);
|
|
126
|
+
}
|
|
127
|
+
if (!Array.isArray(props.components)) {
|
|
128
|
+
throw new Error(`Must provide components array with list of Tamagui component modules`);
|
|
129
|
+
}
|
|
130
|
+
const { components, tamaguiConfig } = (0, import_loadTamagui.loadTamagui)({
|
|
131
|
+
config,
|
|
132
|
+
components: props.components || ["tamagui"]
|
|
133
|
+
});
|
|
134
|
+
loadedTamaguiConfig = tamaguiConfig;
|
|
135
|
+
const defaultTheme = tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]];
|
|
136
|
+
const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
|
|
137
|
+
const isInternalImport = /* @__PURE__ */ __name((importStr) => {
|
|
138
|
+
return (0, import_extractHelpers.isInsideTamagui)(sourcePath) && importStr[0] === ".";
|
|
139
|
+
}, "isInternalImport");
|
|
140
|
+
const validComponents = Object.keys(components).filter((key) => {
|
|
141
|
+
var _a2;
|
|
142
|
+
return key[0].toUpperCase() === key[0] && !!((_a2 = components[key]) == null ? void 0 : _a2.staticConfig);
|
|
143
|
+
}).reduce((obj, name) => {
|
|
144
|
+
obj[name] = components[name];
|
|
145
|
+
return obj;
|
|
146
|
+
}, {});
|
|
147
|
+
let doesUseValidImport = false;
|
|
148
|
+
for (const bodyPath of body) {
|
|
149
|
+
if (bodyPath.type !== "ImportDeclaration")
|
|
150
|
+
continue;
|
|
151
|
+
const node = "node" in bodyPath ? bodyPath.node : bodyPath;
|
|
152
|
+
const from = node.source.value;
|
|
153
|
+
if (props.components.includes(from) || isInternalImport(from)) {
|
|
154
|
+
if (node.specifiers.some((specifier) => {
|
|
155
|
+
const name = specifier.local.name;
|
|
156
|
+
return validComponents[name] || validHooks[name];
|
|
157
|
+
})) {
|
|
158
|
+
doesUseValidImport = true;
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (shouldPrintDebug) {
|
|
164
|
+
console.log(sourcePath, { doesUseValidImport });
|
|
165
|
+
}
|
|
166
|
+
if (!doesUseValidImport) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
let couldntParse = false;
|
|
170
|
+
const modifiedComponents = new Set();
|
|
171
|
+
const bindingCache = {};
|
|
172
|
+
const callTraverse = /* @__PURE__ */ __name((a) => {
|
|
173
|
+
return fileOrPath.type === "File" ? (0, import_traverse.default)(fileOrPath, a) : fileOrPath.traverse(a);
|
|
174
|
+
}, "callTraverse");
|
|
175
|
+
let programPath;
|
|
176
|
+
const res = {
|
|
177
|
+
flattened: 0,
|
|
178
|
+
optimized: 0,
|
|
179
|
+
modified: 0
|
|
180
|
+
};
|
|
181
|
+
callTraverse({
|
|
182
|
+
Program: {
|
|
183
|
+
enter(path) {
|
|
184
|
+
programPath = path;
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
JSXElement(traversePath) {
|
|
188
|
+
var _a2;
|
|
189
|
+
const node = traversePath.node.openingElement;
|
|
190
|
+
const ogAttributes = node.attributes;
|
|
191
|
+
const componentName = (0, import_extractHelpers.findComponentName)(traversePath.scope);
|
|
192
|
+
const closingElement = traversePath.node.closingElement;
|
|
193
|
+
if (t.isJSXMemberExpression(closingElement == null ? void 0 : closingElement.name) || !t.isJSXIdentifier(node.name)) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const binding = traversePath.scope.getBinding(node.name.name);
|
|
197
|
+
if (binding) {
|
|
198
|
+
if (!t.isImportDeclaration(binding.path.parent)) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const source = binding.path.parent.source;
|
|
202
|
+
if (!props.components.includes(source.value) && !isInternalImport(source.value)) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (!validComponents[binding.identifier.name]) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const component = validComponents[node.name.name];
|
|
210
|
+
if (!component || !component.staticConfig) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const originalNodeName = node.name.name;
|
|
214
|
+
if (shouldPrintDebug) {
|
|
215
|
+
console.log(`
|
|
216
|
+
<${originalNodeName} />`);
|
|
217
|
+
}
|
|
218
|
+
const filePath = sourcePath.replace(process.cwd(), ".");
|
|
219
|
+
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
220
|
+
if (shouldAddDebugProp && !disableDebugAttr) {
|
|
221
|
+
const preName = componentName ? `${componentName}:` : "";
|
|
222
|
+
res.modified++;
|
|
223
|
+
node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(` ${preName}${node.name.name} ${filePath.replace("./", "")}:${lineNumbers} `)));
|
|
224
|
+
}
|
|
225
|
+
if (disableExtraction) {
|
|
226
|
+
if (!hasLogged) {
|
|
227
|
+
console.log("\u{1F95A} Tamagui disableExtraction set: no CSS or optimizations will be run");
|
|
228
|
+
hasLogged = true;
|
|
229
|
+
}
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const { staticConfig } = component;
|
|
233
|
+
const isTextView = staticConfig.isText || false;
|
|
234
|
+
const validStyles = (staticConfig == null ? void 0 : staticConfig.validStyles) ?? {};
|
|
235
|
+
let tagName = ((_a2 = staticConfig.defaultProps) == null ? void 0 : _a2.tag) ?? (isTextView ? "span" : "div");
|
|
236
|
+
traversePath.get("openingElement").get("attributes").forEach((path) => {
|
|
237
|
+
const attr = path.node;
|
|
238
|
+
if (t.isJSXSpreadAttribute(attr))
|
|
239
|
+
return;
|
|
240
|
+
if (attr.name.name !== "tag")
|
|
241
|
+
return;
|
|
242
|
+
const val = attr.value;
|
|
243
|
+
if (!t.isStringLiteral(val))
|
|
244
|
+
return;
|
|
245
|
+
tagName = val.value;
|
|
246
|
+
});
|
|
247
|
+
const flatNode = getFlattenedNode({ isTextView, tag: tagName });
|
|
248
|
+
const deoptProps = new Set([
|
|
249
|
+
...props.deoptProps ?? [],
|
|
250
|
+
...staticConfig.deoptProps ?? []
|
|
251
|
+
]);
|
|
252
|
+
const excludeProps = new Set(props.excludeProps ?? []);
|
|
253
|
+
const isExcludedProp = /* @__PURE__ */ __name((name) => {
|
|
254
|
+
const res2 = excludeProps.has(name);
|
|
255
|
+
if (res2 && shouldPrintDebug)
|
|
256
|
+
console.log(` excluding ${name}`);
|
|
257
|
+
return res2;
|
|
258
|
+
}, "isExcludedProp");
|
|
259
|
+
const isDeoptedProp = /* @__PURE__ */ __name((name) => {
|
|
260
|
+
const res2 = deoptProps.has(name);
|
|
261
|
+
if (res2 && shouldPrintDebug)
|
|
262
|
+
console.log(` deopting ${name}`);
|
|
263
|
+
return res2;
|
|
264
|
+
}, "isDeoptedProp");
|
|
265
|
+
const staticNamespace = (0, import_getStaticBindingsForScope.getStaticBindingsForScope)(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
|
|
266
|
+
const attemptEval = !evaluateVars ? import_evaluateAstNode.evaluateAstNode : (0, import_createEvaluator.createEvaluator)({
|
|
267
|
+
tamaguiConfig,
|
|
268
|
+
staticNamespace,
|
|
269
|
+
sourcePath,
|
|
270
|
+
traversePath,
|
|
271
|
+
shouldPrintDebug
|
|
272
|
+
});
|
|
273
|
+
const attemptEvalSafe = (0, import_createEvaluator.createSafeEvaluator)(attemptEval);
|
|
274
|
+
if (shouldPrintDebug) {
|
|
275
|
+
console.log(" staticNamespace", Object.keys(staticNamespace).join(", "));
|
|
276
|
+
}
|
|
277
|
+
const hasDeopt = /* @__PURE__ */ __name((obj) => {
|
|
278
|
+
return Object.keys(obj).some(isDeoptedProp);
|
|
279
|
+
}, "hasDeopt");
|
|
280
|
+
const flattenedAttrs = [];
|
|
281
|
+
traversePath.get("openingElement").get("attributes").forEach((path) => {
|
|
282
|
+
const attr = path.node;
|
|
283
|
+
if (!t.isJSXSpreadAttribute(attr)) {
|
|
284
|
+
flattenedAttrs.push(attr);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
let arg;
|
|
288
|
+
try {
|
|
289
|
+
arg = attemptEval(attr.argument);
|
|
290
|
+
} catch (e) {
|
|
291
|
+
if (shouldPrintDebug) {
|
|
292
|
+
console.log(" couldnt parse spread", e.message);
|
|
293
|
+
}
|
|
294
|
+
flattenedAttrs.push(attr);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (typeof arg !== "undefined") {
|
|
298
|
+
try {
|
|
299
|
+
if (typeof arg !== "object" || arg == null) {
|
|
300
|
+
if (shouldPrintDebug) {
|
|
301
|
+
console.log(" non object or null arg", arg);
|
|
302
|
+
}
|
|
303
|
+
flattenedAttrs.push(attr);
|
|
304
|
+
} else {
|
|
305
|
+
for (const k in arg) {
|
|
306
|
+
const value = arg[k];
|
|
307
|
+
if (!value && typeof value === "object") {
|
|
308
|
+
console.log("shouldnt we handle this?", k, value, arg);
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
flattenedAttrs.push(t.jsxAttribute(t.jsxIdentifier(k), t.jsxExpressionContainer((0, import_literalToAst.literalToAst)(value))));
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
} catch (err) {
|
|
315
|
+
console.warn("cant parse spread, caught err", err);
|
|
316
|
+
couldntParse = true;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
if (couldntParse) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
node.attributes = flattenedAttrs;
|
|
324
|
+
if (staticConfig.defaultProps) {
|
|
325
|
+
for (const key in staticConfig.defaultProps) {
|
|
326
|
+
const serialize = require("babel-literal-to-ast");
|
|
327
|
+
const val = staticConfig.defaultProps[key];
|
|
328
|
+
node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier(key), typeof val === "string" ? t.stringLiteral(val) : t.jsxExpressionContainer(serialize(val))));
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
let attrs = [];
|
|
332
|
+
let shouldDeopt = false;
|
|
333
|
+
let inlinePropCount = 0;
|
|
334
|
+
let isFlattened = false;
|
|
335
|
+
attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
|
|
336
|
+
try {
|
|
337
|
+
const res2 = evaluateAttribute(path);
|
|
338
|
+
if (!res2) {
|
|
339
|
+
path.remove();
|
|
340
|
+
}
|
|
341
|
+
return res2;
|
|
342
|
+
} catch (err) {
|
|
343
|
+
console.log("Error extracting attribute", err.message, err.stack);
|
|
344
|
+
console.log("node", path.node);
|
|
345
|
+
return {
|
|
346
|
+
type: "attr",
|
|
347
|
+
value: path.node
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
}).flat(4).filter(import_extractHelpers.isPresent);
|
|
351
|
+
function isStaticAttributeName(name) {
|
|
352
|
+
var _a3, _b2;
|
|
353
|
+
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));
|
|
354
|
+
}
|
|
355
|
+
__name(isStaticAttributeName, "isStaticAttributeName");
|
|
356
|
+
function isExtractable(obj) {
|
|
357
|
+
return t.isObjectExpression(obj) && obj.properties.every((prop) => {
|
|
358
|
+
if (!t.isObjectProperty(prop)) {
|
|
359
|
+
console.log("not object prop", prop);
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
const propName = prop.key["name"];
|
|
363
|
+
if (!isStaticAttributeName(propName) && propName !== "tag") {
|
|
364
|
+
if (shouldPrintDebug) {
|
|
365
|
+
console.log(" not a valid style prop!", propName);
|
|
366
|
+
}
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
369
|
+
return true;
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
__name(isExtractable, "isExtractable");
|
|
373
|
+
function createTernariesFromObjectProperties(test, side, ternaryPartial = {}) {
|
|
374
|
+
if (!side) {
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
377
|
+
if (!isExtractable(side)) {
|
|
378
|
+
throw new Error("not extractable");
|
|
379
|
+
}
|
|
380
|
+
return side.properties.flatMap((property) => {
|
|
381
|
+
if (!t.isObjectProperty(property)) {
|
|
382
|
+
throw new Error("expected object property");
|
|
383
|
+
}
|
|
384
|
+
if (t.isConditionalExpression(property.value)) {
|
|
385
|
+
const [truthy, falsy] = [
|
|
386
|
+
t.objectExpression([t.objectProperty(property.key, property.value.consequent)]),
|
|
387
|
+
t.objectExpression([t.objectProperty(property.key, property.value.alternate)])
|
|
388
|
+
].map((x) => attemptEval(x));
|
|
389
|
+
return [
|
|
390
|
+
createTernary(__spreadProps(__spreadValues({
|
|
391
|
+
remove() {
|
|
392
|
+
}
|
|
393
|
+
}, ternaryPartial), {
|
|
394
|
+
test: t.logicalExpression("&&", test, property.value.test),
|
|
395
|
+
consequent: truthy,
|
|
396
|
+
alternate: null
|
|
397
|
+
})),
|
|
398
|
+
createTernary(__spreadProps(__spreadValues({}, ternaryPartial), {
|
|
399
|
+
test: t.logicalExpression("&&", test, t.unaryExpression("!", property.value.test)),
|
|
400
|
+
consequent: falsy,
|
|
401
|
+
alternate: null,
|
|
402
|
+
remove() {
|
|
403
|
+
}
|
|
404
|
+
}))
|
|
405
|
+
];
|
|
406
|
+
}
|
|
407
|
+
const obj = t.objectExpression([t.objectProperty(property.key, property.value)]);
|
|
408
|
+
const consequent = attemptEval(obj);
|
|
409
|
+
return createTernary(__spreadProps(__spreadValues({
|
|
410
|
+
remove() {
|
|
411
|
+
}
|
|
412
|
+
}, ternaryPartial), {
|
|
413
|
+
test,
|
|
414
|
+
consequent,
|
|
415
|
+
alternate: null
|
|
416
|
+
}));
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
__name(createTernariesFromObjectProperties, "createTernariesFromObjectProperties");
|
|
420
|
+
function evaluateAttribute(path) {
|
|
421
|
+
const attribute = path.node;
|
|
422
|
+
const attr = { type: "attr", value: attribute };
|
|
423
|
+
if (t.isJSXSpreadAttribute(attribute)) {
|
|
424
|
+
const arg = attribute.argument;
|
|
425
|
+
const conditional = t.isConditionalExpression(arg) ? [arg.test, arg.consequent, arg.alternate] : t.isLogicalExpression(arg) && arg.operator === "&&" ? [arg.left, arg.right, null] : null;
|
|
426
|
+
if (conditional) {
|
|
427
|
+
const [test, alt, cons] = conditional;
|
|
428
|
+
if (!test)
|
|
429
|
+
throw new Error(`no test`);
|
|
430
|
+
if ([alt, cons].some((side) => side && !isExtractable(side))) {
|
|
431
|
+
if (shouldPrintDebug) {
|
|
432
|
+
console.log("not extractable", alt, cons);
|
|
433
|
+
}
|
|
434
|
+
return attr;
|
|
435
|
+
}
|
|
436
|
+
return [
|
|
437
|
+
...createTernariesFromObjectProperties(test, alt) || [],
|
|
438
|
+
...cons && createTernariesFromObjectProperties(t.unaryExpression("!", test), cons) || []
|
|
439
|
+
].map((ternary) => ({
|
|
440
|
+
type: "ternary",
|
|
441
|
+
value: ternary
|
|
442
|
+
}));
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if (t.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name !== "string") {
|
|
446
|
+
inlinePropCount++;
|
|
447
|
+
return attr;
|
|
448
|
+
}
|
|
449
|
+
const name = attribute.name.name;
|
|
450
|
+
if (isExcludedProp(name)) {
|
|
451
|
+
return null;
|
|
452
|
+
}
|
|
453
|
+
if (isDeoptedProp(name)) {
|
|
454
|
+
if (shouldPrintDebug) {
|
|
455
|
+
console.log(" ! inlining, deopt prop", name);
|
|
456
|
+
}
|
|
457
|
+
inlinePropCount++;
|
|
458
|
+
return attr;
|
|
459
|
+
}
|
|
460
|
+
if (UNTOUCHED_PROPS[name]) {
|
|
461
|
+
return attr;
|
|
462
|
+
}
|
|
463
|
+
if (name[0] === "$" && t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
|
|
464
|
+
if (disableExtractInlineMedia) {
|
|
465
|
+
return attr;
|
|
466
|
+
}
|
|
467
|
+
const shortname = name.slice(1);
|
|
468
|
+
if (mediaQueryConfig[shortname]) {
|
|
469
|
+
const expression = attribute.value.expression;
|
|
470
|
+
if (!t.isJSXEmptyExpression(expression)) {
|
|
471
|
+
const ternaries2 = createTernariesFromObjectProperties(t.stringLiteral(shortname), expression, {
|
|
472
|
+
inlineMediaQuery: shortname
|
|
473
|
+
});
|
|
474
|
+
if (ternaries2) {
|
|
475
|
+
return ternaries2.map((value2) => ({
|
|
476
|
+
type: "ternary",
|
|
477
|
+
value: value2
|
|
478
|
+
}));
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
const [value, valuePath] = (() => {
|
|
484
|
+
if (t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
|
|
485
|
+
return [attribute.value.expression, path.get("value")];
|
|
486
|
+
} else {
|
|
487
|
+
return [attribute.value, path.get("value")];
|
|
488
|
+
}
|
|
489
|
+
})();
|
|
490
|
+
const remove = /* @__PURE__ */ __name(() => {
|
|
491
|
+
Array.isArray(valuePath) ? valuePath.map((p) => p.remove()) : valuePath.remove();
|
|
492
|
+
}, "remove");
|
|
493
|
+
if (name === "ref") {
|
|
494
|
+
if (shouldPrintDebug) {
|
|
495
|
+
console.log(" ! inlining, ref", name);
|
|
496
|
+
}
|
|
497
|
+
inlinePropCount++;
|
|
498
|
+
return attr;
|
|
499
|
+
}
|
|
500
|
+
if (name === "tag") {
|
|
501
|
+
return {
|
|
502
|
+
type: "attr",
|
|
503
|
+
value: path.node
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
if (disableExtractVariables) {
|
|
507
|
+
if (value) {
|
|
508
|
+
if (value.type === "StringLiteral" && value.value[0] === "$") {
|
|
509
|
+
if (shouldPrintDebug) {
|
|
510
|
+
console.log(" native, disable extract var", value.value);
|
|
511
|
+
}
|
|
512
|
+
inlinePropCount++;
|
|
513
|
+
return attr;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
const styleValue = attemptEvalSafe(value);
|
|
518
|
+
if (!isStaticAttributeName(name)) {
|
|
519
|
+
let keys = [name];
|
|
520
|
+
if (staticConfig.propMapper) {
|
|
521
|
+
const out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps);
|
|
522
|
+
if (out) {
|
|
523
|
+
keys = Object.keys(out);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
if (keys.some((k) => !isStaticAttributeName(k) && k !== "tag")) {
|
|
527
|
+
if (shouldPrintDebug) {
|
|
528
|
+
console.log(" ! inlining, not static attribute name", name);
|
|
529
|
+
}
|
|
530
|
+
inlinePropCount++;
|
|
531
|
+
return attr;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (styleValue !== FAILED_EVAL) {
|
|
535
|
+
return {
|
|
536
|
+
type: "style",
|
|
537
|
+
value: { [name]: styleValue },
|
|
538
|
+
name,
|
|
539
|
+
attr: path.node
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
if (t.isBinaryExpression(value)) {
|
|
543
|
+
const { operator, left, right } = value;
|
|
544
|
+
const lVal = attemptEvalSafe(left);
|
|
545
|
+
const rVal = attemptEvalSafe(right);
|
|
546
|
+
if (shouldPrintDebug) {
|
|
547
|
+
console.log(` evalBinaryExpression lVal ${String(lVal)}, rVal ${String(rVal)}`);
|
|
548
|
+
}
|
|
549
|
+
if (lVal !== FAILED_EVAL && t.isConditionalExpression(right)) {
|
|
550
|
+
const ternary = addBinaryConditional(operator, left, right);
|
|
551
|
+
if (ternary)
|
|
552
|
+
return ternary;
|
|
553
|
+
}
|
|
554
|
+
if (rVal !== FAILED_EVAL && t.isConditionalExpression(left)) {
|
|
555
|
+
const ternary = addBinaryConditional(operator, right, left);
|
|
556
|
+
if (ternary)
|
|
557
|
+
return ternary;
|
|
558
|
+
}
|
|
559
|
+
if (shouldPrintDebug) {
|
|
560
|
+
console.log(` evalBinaryExpression cant extract`);
|
|
561
|
+
}
|
|
562
|
+
inlinePropCount++;
|
|
563
|
+
return attr;
|
|
564
|
+
}
|
|
565
|
+
const staticConditional = getStaticConditional(value);
|
|
566
|
+
if (staticConditional) {
|
|
567
|
+
return { type: "ternary", value: staticConditional };
|
|
568
|
+
}
|
|
569
|
+
const staticLogical = getStaticLogical(value);
|
|
570
|
+
if (staticLogical) {
|
|
571
|
+
return { type: "ternary", value: staticLogical };
|
|
572
|
+
}
|
|
573
|
+
if (shouldPrintDebug) {
|
|
574
|
+
console.log(" ! inline prop via no match", name, value.type);
|
|
575
|
+
}
|
|
576
|
+
inlinePropCount++;
|
|
577
|
+
return attr;
|
|
578
|
+
function addBinaryConditional(operator, staticExpr, cond) {
|
|
579
|
+
if (getStaticConditional(cond)) {
|
|
580
|
+
const alt = attemptEval(t.binaryExpression(operator, staticExpr, cond.alternate));
|
|
581
|
+
const cons = attemptEval(t.binaryExpression(operator, staticExpr, cond.consequent));
|
|
582
|
+
if (shouldPrintDebug) {
|
|
583
|
+
console.log(" binaryConditional", cond.test, cons, alt);
|
|
584
|
+
}
|
|
585
|
+
return {
|
|
586
|
+
type: "ternary",
|
|
587
|
+
value: {
|
|
588
|
+
test: cond.test,
|
|
589
|
+
remove,
|
|
590
|
+
alternate: { [name]: alt },
|
|
591
|
+
consequent: { [name]: cons }
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
return null;
|
|
596
|
+
}
|
|
597
|
+
__name(addBinaryConditional, "addBinaryConditional");
|
|
598
|
+
function getStaticConditional(value2) {
|
|
599
|
+
if (t.isConditionalExpression(value2)) {
|
|
600
|
+
try {
|
|
601
|
+
if (shouldPrintDebug) {
|
|
602
|
+
console.log("attempt", value2.alternate, value2.consequent);
|
|
603
|
+
}
|
|
604
|
+
const aVal = attemptEval(value2.alternate);
|
|
605
|
+
const cVal = attemptEval(value2.consequent);
|
|
606
|
+
if (shouldPrintDebug) {
|
|
607
|
+
const type = value2.test.type;
|
|
608
|
+
console.log(" static ternary", type, cVal, aVal);
|
|
609
|
+
}
|
|
610
|
+
return {
|
|
611
|
+
test: value2.test,
|
|
612
|
+
remove,
|
|
613
|
+
consequent: { [name]: cVal },
|
|
614
|
+
alternate: { [name]: aVal }
|
|
615
|
+
};
|
|
616
|
+
} catch (err) {
|
|
617
|
+
if (shouldPrintDebug) {
|
|
618
|
+
console.log(" cant eval ternary", err.message);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
return null;
|
|
623
|
+
}
|
|
624
|
+
__name(getStaticConditional, "getStaticConditional");
|
|
625
|
+
function getStaticLogical(value2) {
|
|
626
|
+
if (t.isLogicalExpression(value2)) {
|
|
627
|
+
if (value2.operator === "&&") {
|
|
628
|
+
try {
|
|
629
|
+
const val = attemptEval(value2.right);
|
|
630
|
+
if (shouldPrintDebug) {
|
|
631
|
+
console.log(" staticLogical", value2.left, name, val);
|
|
632
|
+
}
|
|
633
|
+
return {
|
|
634
|
+
test: value2.left,
|
|
635
|
+
remove,
|
|
636
|
+
consequent: { [name]: val },
|
|
637
|
+
alternate: null
|
|
638
|
+
};
|
|
639
|
+
} catch (err) {
|
|
640
|
+
if (shouldPrintDebug) {
|
|
641
|
+
console.log(" cant static eval logical", err);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
return null;
|
|
647
|
+
}
|
|
648
|
+
__name(getStaticLogical, "getStaticLogical");
|
|
649
|
+
}
|
|
650
|
+
__name(evaluateAttribute, "evaluateAttribute");
|
|
651
|
+
if (shouldPrintDebug) {
|
|
652
|
+
console.log(" - attrs (before):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
653
|
+
}
|
|
654
|
+
node.attributes = attrs.filter(isAttr).map((x) => x.value);
|
|
655
|
+
if (couldntParse) {
|
|
656
|
+
if (shouldPrintDebug) {
|
|
657
|
+
console.log(` cancel:`, { couldntParse, shouldDeopt });
|
|
658
|
+
}
|
|
659
|
+
node.attributes = ogAttributes;
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
const parentFn = (0, import_findTopmostFunction.findTopmostFunction)(traversePath);
|
|
663
|
+
if (parentFn) {
|
|
664
|
+
modifiedComponents.add(parentFn);
|
|
665
|
+
}
|
|
666
|
+
let ternaries = [];
|
|
667
|
+
attrs = attrs.reduce((out, cur) => {
|
|
668
|
+
const next = attrs[attrs.indexOf(cur) + 1];
|
|
669
|
+
if (cur.type === "ternary") {
|
|
670
|
+
ternaries.push(cur.value);
|
|
671
|
+
}
|
|
672
|
+
if ((!next || next.type !== "ternary") && ternaries.length) {
|
|
673
|
+
const normalized = (0, import_normalizeTernaries.normalizeTernaries)(ternaries).map((_a3) => {
|
|
674
|
+
var _b2 = _a3, { alternate, consequent } = _b2, rest = __objRest(_b2, ["alternate", "consequent"]);
|
|
675
|
+
return {
|
|
676
|
+
type: "ternary",
|
|
677
|
+
value: __spreadProps(__spreadValues({}, rest), {
|
|
678
|
+
alternate: alternate || null,
|
|
679
|
+
consequent: consequent || null
|
|
680
|
+
})
|
|
681
|
+
};
|
|
682
|
+
});
|
|
683
|
+
try {
|
|
684
|
+
return [...out, ...normalized];
|
|
685
|
+
} finally {
|
|
686
|
+
if (shouldPrintDebug) {
|
|
687
|
+
console.log(` normalizeTernaries (${ternaries.length} => ${normalized.length})`);
|
|
688
|
+
}
|
|
689
|
+
ternaries = [];
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
if (cur.type === "ternary") {
|
|
693
|
+
return out;
|
|
694
|
+
}
|
|
695
|
+
out.push(cur);
|
|
696
|
+
return out;
|
|
697
|
+
}, []).flat();
|
|
698
|
+
const completeStaticProps = __spreadValues({}, Object.keys(attrs).reduce((acc, index) => {
|
|
699
|
+
const cur = attrs[index];
|
|
700
|
+
if (cur.type === "style") {
|
|
701
|
+
Object.assign(acc, cur.value);
|
|
702
|
+
}
|
|
703
|
+
if (cur.type === "attr") {
|
|
704
|
+
if (t.isJSXSpreadAttribute(cur.value)) {
|
|
705
|
+
return acc;
|
|
706
|
+
}
|
|
707
|
+
if (!t.isJSXIdentifier(cur.value.name)) {
|
|
708
|
+
return acc;
|
|
709
|
+
}
|
|
710
|
+
const key = cur.value.name.name;
|
|
711
|
+
const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
|
|
712
|
+
if (value === FAILED_EVAL) {
|
|
713
|
+
return acc;
|
|
714
|
+
}
|
|
715
|
+
acc[key] = value;
|
|
716
|
+
}
|
|
717
|
+
return acc;
|
|
718
|
+
}, {}));
|
|
719
|
+
const hasSpread = node.attributes.some((x) => t.isJSXSpreadAttribute(x));
|
|
720
|
+
const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
|
|
721
|
+
const shouldFlatten = !shouldDeopt && inlinePropCount === 0 && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
|
|
722
|
+
if (!shouldFlatten) {
|
|
723
|
+
attrs = attrs.reduce((acc, cur) => {
|
|
724
|
+
var _a3, _b2;
|
|
725
|
+
if (cur.type === "style") {
|
|
726
|
+
for (const key in cur.value) {
|
|
727
|
+
const shouldEnsureOverridden = !!((_a3 = staticConfig.ensureOverriddenProp) == null ? void 0 : _a3[key]);
|
|
728
|
+
const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
|
|
729
|
+
if (!isSetInAttrsAlready) {
|
|
730
|
+
const isVariant = !!((_b2 = staticConfig.variants) == null ? void 0 : _b2[cur.name || ""]);
|
|
731
|
+
if (isVariant || shouldEnsureOverridden) {
|
|
732
|
+
acc.push({
|
|
733
|
+
type: "attr",
|
|
734
|
+
value: cur.attr || t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.nullLiteral()))
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
acc.push(cur);
|
|
741
|
+
return acc;
|
|
742
|
+
}, []);
|
|
743
|
+
}
|
|
744
|
+
if (shouldPrintDebug) {
|
|
745
|
+
console.log(" - attrs (flattened): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
746
|
+
}
|
|
747
|
+
attrs = attrs.reduce((acc, cur) => {
|
|
748
|
+
if (cur.type !== "attr" || !t.isJSXAttribute(cur.value) || typeof cur.value.name.name !== "string") {
|
|
749
|
+
if (cur.type === "style") {
|
|
750
|
+
const key = Object.keys(cur.value)[0];
|
|
751
|
+
if (!validStyles[key] && !pseudos[key]) {
|
|
752
|
+
if (shouldPrintDebug) {
|
|
753
|
+
console.log(" \u274C excluding", key);
|
|
754
|
+
}
|
|
755
|
+
return acc;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
acc.push(cur);
|
|
760
|
+
return acc;
|
|
761
|
+
}, []);
|
|
762
|
+
if (shouldPrintDebug) {
|
|
763
|
+
console.log(" - attrs (evaluated styles): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
764
|
+
}
|
|
765
|
+
let prev = null;
|
|
766
|
+
attrs = attrs.reduce((acc, cur) => {
|
|
767
|
+
if (cur.type === "style") {
|
|
768
|
+
if ((prev == null ? void 0 : prev.type) === "style") {
|
|
769
|
+
Object.assign(prev.value, cur.value);
|
|
770
|
+
return acc;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
acc.push(cur);
|
|
774
|
+
prev = cur;
|
|
775
|
+
return acc;
|
|
776
|
+
}, []);
|
|
777
|
+
if (shouldPrintDebug) {
|
|
778
|
+
console.log(" - attrs (combined \u{1F500}): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
779
|
+
}
|
|
780
|
+
const getStyles = /* @__PURE__ */ __name((props2) => {
|
|
781
|
+
if (!props2)
|
|
782
|
+
return;
|
|
783
|
+
if (!!excludeProps.size) {
|
|
784
|
+
for (const key in props2) {
|
|
785
|
+
if (isExcludedProp(key))
|
|
786
|
+
delete props2[key];
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
const out = postProcessStyles(props2, staticConfig, defaultTheme);
|
|
790
|
+
const next = (out == null ? void 0 : out.style) ?? props2;
|
|
791
|
+
if (shouldPrintDebug) {
|
|
792
|
+
console.log(" getStyles props >>\n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(props2)));
|
|
793
|
+
console.log(" getStyles next >>\n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(next)));
|
|
794
|
+
console.log(" getStyles style >>\n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(out.style)));
|
|
795
|
+
console.log(" getStyles viewp >>\n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(out.viewProps)));
|
|
796
|
+
}
|
|
797
|
+
if (staticConfig.validStyles) {
|
|
798
|
+
for (const key in next) {
|
|
799
|
+
if (!staticConfig.validStyles[key] && !pseudos[key]) {
|
|
800
|
+
delete next[key];
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
return next;
|
|
805
|
+
}, "getStyles");
|
|
806
|
+
const completeStylesProcessed = getStyles(__spreadValues(__spreadValues({}, staticConfig.defaultProps), completeStaticProps));
|
|
807
|
+
const stylesToAddToInitialGroup = (0, import_lodash.difference)(Object.keys(completeStylesProcessed), Object.keys(completeStaticProps));
|
|
808
|
+
if (stylesToAddToInitialGroup.length) {
|
|
809
|
+
const toAdd = (0, import_lodash.pick)(completeStylesProcessed, ...stylesToAddToInitialGroup);
|
|
810
|
+
const firstGroup = attrs.find((x) => x.type === "style");
|
|
811
|
+
if (shouldPrintDebug) {
|
|
812
|
+
console.log(" stylesToAddToInitialGroup", stylesToAddToInitialGroup.join(", "));
|
|
813
|
+
console.log(" toAdd", (0, import_extractHelpers.objToStr)(toAdd));
|
|
814
|
+
}
|
|
815
|
+
if (!firstGroup) {
|
|
816
|
+
attrs.unshift({ type: "style", value: toAdd });
|
|
817
|
+
} else {
|
|
818
|
+
Object.assign(firstGroup.value, toAdd);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
if (shouldPrintDebug) {
|
|
822
|
+
console.log(" completeStaticProps\n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(completeStaticProps)));
|
|
823
|
+
console.log(" completeStylesProcessed\n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(completeStylesProcessed)));
|
|
824
|
+
}
|
|
825
|
+
for (const attr of attrs) {
|
|
826
|
+
try {
|
|
827
|
+
switch (attr.type) {
|
|
828
|
+
case "ternary":
|
|
829
|
+
const a = getStyles(attr.value.alternate);
|
|
830
|
+
const c = getStyles(attr.value.consequent);
|
|
831
|
+
attr.value.alternate = a;
|
|
832
|
+
attr.value.consequent = c;
|
|
833
|
+
if (shouldPrintDebug) {
|
|
834
|
+
console.log(" => tern ", (0, import_extractHelpers.attrStr)(attr));
|
|
835
|
+
}
|
|
836
|
+
break;
|
|
837
|
+
case "style":
|
|
838
|
+
const next = {};
|
|
839
|
+
for (const key in attr.value) {
|
|
840
|
+
if (key in import_helpers.stylePropsTransform) {
|
|
841
|
+
next["transform"] = completeStylesProcessed["transform"];
|
|
842
|
+
} else {
|
|
843
|
+
next[key] = completeStylesProcessed[key] ?? attr.value[key];
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
attr.value = next;
|
|
847
|
+
break;
|
|
848
|
+
}
|
|
849
|
+
} catch (err) {
|
|
850
|
+
if (shouldPrintDebug) {
|
|
851
|
+
console.log(" postprocessing error, deopt", err);
|
|
852
|
+
node.attributes = ogAttributes;
|
|
853
|
+
return node;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
if (shouldPrintDebug) {
|
|
858
|
+
console.log(" - attrs (after):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
859
|
+
}
|
|
860
|
+
if (shouldFlatten) {
|
|
861
|
+
if (shouldPrintDebug) {
|
|
862
|
+
console.log(" [\u2705] flattening", originalNodeName, flatNode);
|
|
863
|
+
}
|
|
864
|
+
isFlattened = true;
|
|
865
|
+
node.name.name = flatNode;
|
|
866
|
+
res.flattened++;
|
|
867
|
+
if (closingElement) {
|
|
868
|
+
closingElement.name.name = flatNode;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
if (shouldPrintDebug) {
|
|
872
|
+
console.log(" [\u274A] inline props ", inlinePropCount, shouldDeopt ? " deopted" : "", hasSpread ? " spread" : "", "!flatten", staticConfig.neverFlatten);
|
|
873
|
+
console.log(" - attrs (end):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
874
|
+
}
|
|
875
|
+
res.optimized++;
|
|
876
|
+
onExtractTag({
|
|
877
|
+
attrs,
|
|
878
|
+
node,
|
|
879
|
+
lineNumbers,
|
|
880
|
+
filePath,
|
|
881
|
+
attemptEval,
|
|
882
|
+
jsxPath: traversePath,
|
|
883
|
+
originalNodeName,
|
|
884
|
+
isFlattened,
|
|
885
|
+
programPath
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
if (modifiedComponents.size) {
|
|
890
|
+
const all = Array.from(modifiedComponents);
|
|
891
|
+
if (shouldPrintDebug) {
|
|
892
|
+
console.log(" [\u{1FA9D}] hook check", all.length);
|
|
893
|
+
}
|
|
894
|
+
for (const comp of all) {
|
|
895
|
+
(0, import_removeUnusedHooks.removeUnusedHooks)(comp, shouldPrintDebug);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
return res;
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
__name(createExtractor, "createExtractor");
|
|
903
|
+
//# sourceMappingURL=createExtractor.js.map
|