@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
|
@@ -0,0 +1,1100 @@
|
|
|
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
25
|
+
var __objRest = (source, exclude) => {
|
|
26
|
+
var target = {};
|
|
27
|
+
for (var prop in source)
|
|
28
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
if (source != null && __getOwnPropSymbols)
|
|
31
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
+
target[prop] = source[prop];
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
37
|
+
var __export = (target, all) => {
|
|
38
|
+
for (var name in all)
|
|
39
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
+
};
|
|
41
|
+
var __copyProps = (to, from, except, desc) => {
|
|
42
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
+
for (let key of __getOwnPropNames(from))
|
|
44
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
+
}
|
|
47
|
+
return to;
|
|
48
|
+
};
|
|
49
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
50
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
51
|
+
var createExtractor_exports = {};
|
|
52
|
+
__export(createExtractor_exports, {
|
|
53
|
+
createExtractor: () => createExtractor
|
|
54
|
+
});
|
|
55
|
+
module.exports = __toCommonJS(createExtractor_exports);
|
|
56
|
+
var import_traverse = __toESM(require("@babel/traverse"));
|
|
57
|
+
var t = __toESM(require("@babel/types"));
|
|
58
|
+
var import_core_node = require("@tamagui/core-node");
|
|
59
|
+
var import_lodash = require("lodash");
|
|
60
|
+
var import_constants = require("../constants");
|
|
61
|
+
var import_createEvaluator = require("./createEvaluator");
|
|
62
|
+
var import_evaluateAstNode = require("./evaluateAstNode");
|
|
63
|
+
var import_extractHelpers = require("./extractHelpers");
|
|
64
|
+
var import_findTopmostFunction = require("./findTopmostFunction");
|
|
65
|
+
var import_getStaticBindingsForScope = require("./getStaticBindingsForScope");
|
|
66
|
+
var import_literalToAst = require("./literalToAst");
|
|
67
|
+
var import_loadTamagui = require("./loadTamagui");
|
|
68
|
+
var import_logLines = require("./logLines");
|
|
69
|
+
var import_normalizeTernaries = require("./normalizeTernaries");
|
|
70
|
+
var import_removeUnusedHooks = require("./removeUnusedHooks");
|
|
71
|
+
var import_validHTMLAttributes = require("./validHTMLAttributes");
|
|
72
|
+
const UNTOUCHED_PROPS = {
|
|
73
|
+
key: true,
|
|
74
|
+
style: true,
|
|
75
|
+
className: true
|
|
76
|
+
};
|
|
77
|
+
const isAttr = /* @__PURE__ */ __name((x) => x.type === "attr", "isAttr");
|
|
78
|
+
const validHooks = {
|
|
79
|
+
useMedia: true,
|
|
80
|
+
useTheme: true
|
|
81
|
+
};
|
|
82
|
+
const createTernary = /* @__PURE__ */ __name((x) => x, "createTernary");
|
|
83
|
+
function createExtractor() {
|
|
84
|
+
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);
|
|
85
|
+
require("esbuild-register/dist/node").register({
|
|
86
|
+
target: "es2019",
|
|
87
|
+
format: "cjs"
|
|
88
|
+
});
|
|
89
|
+
let loadedTamaguiConfig;
|
|
90
|
+
let hasLogged = false;
|
|
91
|
+
return {
|
|
92
|
+
getTamagui() {
|
|
93
|
+
return loadedTamaguiConfig;
|
|
94
|
+
},
|
|
95
|
+
parse: (fileOrPath, _a) => {
|
|
96
|
+
var _b = _a, {
|
|
97
|
+
config = "tamagui.config.ts",
|
|
98
|
+
importsWhitelist = ["constants.js"],
|
|
99
|
+
evaluateVars = true,
|
|
100
|
+
shouldPrintDebug = false,
|
|
101
|
+
sourcePath = "",
|
|
102
|
+
onExtractTag,
|
|
103
|
+
getFlattenedNode,
|
|
104
|
+
disable,
|
|
105
|
+
disableExtraction,
|
|
106
|
+
disableExtractInlineMedia,
|
|
107
|
+
disableExtractVariables,
|
|
108
|
+
disableDebugAttr,
|
|
109
|
+
prefixLogs,
|
|
110
|
+
excludeProps
|
|
111
|
+
} = _b, props = __objRest(_b, [
|
|
112
|
+
"config",
|
|
113
|
+
"importsWhitelist",
|
|
114
|
+
"evaluateVars",
|
|
115
|
+
"shouldPrintDebug",
|
|
116
|
+
"sourcePath",
|
|
117
|
+
"onExtractTag",
|
|
118
|
+
"getFlattenedNode",
|
|
119
|
+
"disable",
|
|
120
|
+
"disableExtraction",
|
|
121
|
+
"disableExtractInlineMedia",
|
|
122
|
+
"disableExtractVariables",
|
|
123
|
+
"disableDebugAttr",
|
|
124
|
+
"prefixLogs",
|
|
125
|
+
"excludeProps"
|
|
126
|
+
]);
|
|
127
|
+
if (disable) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
if (sourcePath === "") {
|
|
131
|
+
throw new Error(`Must provide a source file name`);
|
|
132
|
+
}
|
|
133
|
+
if (!Array.isArray(props.components)) {
|
|
134
|
+
throw new Error(`Must provide components array with list of Tamagui component modules`);
|
|
135
|
+
}
|
|
136
|
+
const { components, tamaguiConfig } = (0, import_loadTamagui.loadTamagui)({
|
|
137
|
+
config,
|
|
138
|
+
components: props.components || ["tamagui"]
|
|
139
|
+
});
|
|
140
|
+
loadedTamaguiConfig = tamaguiConfig;
|
|
141
|
+
const defaultTheme = tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]];
|
|
142
|
+
const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
|
|
143
|
+
const isInternalImport = /* @__PURE__ */ __name((importStr) => {
|
|
144
|
+
return (0, import_extractHelpers.isInsideTamagui)(sourcePath) && importStr[0] === ".";
|
|
145
|
+
}, "isInternalImport");
|
|
146
|
+
const validComponents = Object.keys(components).filter((key) => {
|
|
147
|
+
var _a2;
|
|
148
|
+
return key[0].toUpperCase() === key[0] && !!((_a2 = components[key]) == null ? void 0 : _a2.staticConfig);
|
|
149
|
+
}).reduce((obj, name) => {
|
|
150
|
+
obj[name] = components[name];
|
|
151
|
+
return obj;
|
|
152
|
+
}, {});
|
|
153
|
+
let doesUseValidImport = false;
|
|
154
|
+
for (const bodyPath of body) {
|
|
155
|
+
if (bodyPath.type !== "ImportDeclaration")
|
|
156
|
+
continue;
|
|
157
|
+
const node = "node" in bodyPath ? bodyPath.node : bodyPath;
|
|
158
|
+
const from = node.source.value;
|
|
159
|
+
if (props.components.includes(from) || isInternalImport(from)) {
|
|
160
|
+
if (node.specifiers.some((specifier) => {
|
|
161
|
+
const name = specifier.local.name;
|
|
162
|
+
return validComponents[name] || validHooks[name];
|
|
163
|
+
})) {
|
|
164
|
+
doesUseValidImport = true;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (shouldPrintDebug) {
|
|
170
|
+
console.log(sourcePath, { doesUseValidImport });
|
|
171
|
+
}
|
|
172
|
+
if (!doesUseValidImport) {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
let couldntParse = false;
|
|
176
|
+
const modifiedComponents = /* @__PURE__ */ new Set();
|
|
177
|
+
const bindingCache = {};
|
|
178
|
+
const callTraverse = /* @__PURE__ */ __name((a) => {
|
|
179
|
+
return fileOrPath.type === "File" ? (0, import_traverse.default)(fileOrPath, a) : fileOrPath.traverse(a);
|
|
180
|
+
}, "callTraverse");
|
|
181
|
+
let programPath;
|
|
182
|
+
const res = {
|
|
183
|
+
flattened: 0,
|
|
184
|
+
optimized: 0,
|
|
185
|
+
modified: 0,
|
|
186
|
+
found: 0
|
|
187
|
+
};
|
|
188
|
+
callTraverse({
|
|
189
|
+
Program: {
|
|
190
|
+
enter(path) {
|
|
191
|
+
programPath = path;
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
JSXElement(traversePath) {
|
|
195
|
+
var _a2, _b2, _c;
|
|
196
|
+
const node = traversePath.node.openingElement;
|
|
197
|
+
const ogAttributes = node.attributes;
|
|
198
|
+
const componentName = (0, import_extractHelpers.findComponentName)(traversePath.scope);
|
|
199
|
+
const closingElement = traversePath.node.closingElement;
|
|
200
|
+
if (t.isJSXMemberExpression(closingElement == null ? void 0 : closingElement.name) || !t.isJSXIdentifier(node.name)) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const binding = traversePath.scope.getBinding(node.name.name);
|
|
204
|
+
if (binding) {
|
|
205
|
+
if (!t.isImportDeclaration(binding.path.parent)) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const source = binding.path.parent.source;
|
|
209
|
+
if (!props.components.includes(source.value) && !isInternalImport(source.value)) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (!validComponents[binding.identifier.name]) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const component = validComponents[node.name.name];
|
|
217
|
+
if (!component || !component.staticConfig) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const originalNodeName = node.name.name;
|
|
221
|
+
res.found++;
|
|
222
|
+
if (shouldPrintDebug) {
|
|
223
|
+
console.log(`
|
|
224
|
+
<${originalNodeName} />`);
|
|
225
|
+
}
|
|
226
|
+
const filePath = sourcePath.replace(process.cwd(), ".");
|
|
227
|
+
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
228
|
+
if (shouldAddDebugProp && !disableDebugAttr) {
|
|
229
|
+
const preName = componentName ? `${componentName}.` : "";
|
|
230
|
+
res.modified++;
|
|
231
|
+
node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(`${preName}${node.name.name}@${filePath.replace("./", "")}:${lineNumbers}`)));
|
|
232
|
+
}
|
|
233
|
+
const shouldLog = !hasLogged;
|
|
234
|
+
if (shouldLog) {
|
|
235
|
+
const prefix = " |";
|
|
236
|
+
console.log(prefixLogs || prefix, " total \xB7 optimized \xB7 flattened ");
|
|
237
|
+
hasLogged = true;
|
|
238
|
+
}
|
|
239
|
+
if (disableExtraction) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const { staticConfig } = component;
|
|
243
|
+
const isTextView = staticConfig.isText || false;
|
|
244
|
+
const validStyles = (staticConfig == null ? void 0 : staticConfig.validStyles) ?? {};
|
|
245
|
+
function isValidStyleKey(name) {
|
|
246
|
+
var _a3;
|
|
247
|
+
return !!(!!validStyles[name] || !!import_core_node.pseudos[name] || ((_a3 = staticConfig.variants) == null ? void 0 : _a3[name]) || tamaguiConfig.shorthands[name] || (name[0] === "$" ? !!import_core_node.mediaQueryConfig[name.slice(1)] : false));
|
|
248
|
+
}
|
|
249
|
+
__name(isValidStyleKey, "isValidStyleKey");
|
|
250
|
+
let tagName = ((_a2 = staticConfig.defaultProps) == null ? void 0 : _a2.tag) ?? (isTextView ? "span" : "div");
|
|
251
|
+
traversePath.get("openingElement").get("attributes").forEach((path) => {
|
|
252
|
+
const attr = path.node;
|
|
253
|
+
if (t.isJSXSpreadAttribute(attr))
|
|
254
|
+
return;
|
|
255
|
+
if (attr.name.name !== "tag")
|
|
256
|
+
return;
|
|
257
|
+
const val = attr.value;
|
|
258
|
+
if (!t.isStringLiteral(val))
|
|
259
|
+
return;
|
|
260
|
+
tagName = val.value;
|
|
261
|
+
});
|
|
262
|
+
const flatNode = getFlattenedNode({ isTextView, tag: tagName });
|
|
263
|
+
const inlineProps = /* @__PURE__ */ new Set([
|
|
264
|
+
...props.inlineProps || [],
|
|
265
|
+
...staticConfig.inlineProps || []
|
|
266
|
+
]);
|
|
267
|
+
const deoptProps = /* @__PURE__ */ new Set([
|
|
268
|
+
...props.deoptProps || [],
|
|
269
|
+
...staticConfig.deoptProps || []
|
|
270
|
+
]);
|
|
271
|
+
const staticNamespace = (0, import_getStaticBindingsForScope.getStaticBindingsForScope)(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
|
|
272
|
+
const attemptEval = !evaluateVars ? import_evaluateAstNode.evaluateAstNode : (0, import_createEvaluator.createEvaluator)({
|
|
273
|
+
tamaguiConfig,
|
|
274
|
+
staticNamespace,
|
|
275
|
+
sourcePath,
|
|
276
|
+
traversePath,
|
|
277
|
+
shouldPrintDebug
|
|
278
|
+
});
|
|
279
|
+
const attemptEvalSafe = (0, import_createEvaluator.createSafeEvaluator)(attemptEval);
|
|
280
|
+
if (shouldPrintDebug) {
|
|
281
|
+
console.log(" staticNamespace", Object.keys(staticNamespace).join(", "));
|
|
282
|
+
}
|
|
283
|
+
const flattenedAttrs = [];
|
|
284
|
+
traversePath.get("openingElement").get("attributes").forEach((path) => {
|
|
285
|
+
const attr = path.node;
|
|
286
|
+
if (!t.isJSXSpreadAttribute(attr)) {
|
|
287
|
+
flattenedAttrs.push(attr);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
let arg;
|
|
291
|
+
try {
|
|
292
|
+
arg = attemptEval(attr.argument);
|
|
293
|
+
} catch (e) {
|
|
294
|
+
if (shouldPrintDebug) {
|
|
295
|
+
console.log(" couldnt parse spread", e.message);
|
|
296
|
+
}
|
|
297
|
+
flattenedAttrs.push(attr);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (arg !== void 0) {
|
|
301
|
+
try {
|
|
302
|
+
if (typeof arg !== "object" || arg == null) {
|
|
303
|
+
if (shouldPrintDebug) {
|
|
304
|
+
console.log(" non object or null arg", arg);
|
|
305
|
+
}
|
|
306
|
+
flattenedAttrs.push(attr);
|
|
307
|
+
} else {
|
|
308
|
+
for (const k in arg) {
|
|
309
|
+
const value = arg[k];
|
|
310
|
+
if (!value && typeof value === "object") {
|
|
311
|
+
console.log("shouldnt we handle this?", k, value, arg);
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
flattenedAttrs.push(t.jsxAttribute(t.jsxIdentifier(k), t.jsxExpressionContainer((0, import_literalToAst.literalToAst)(value))));
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
} catch (err) {
|
|
318
|
+
console.warn("cant parse spread, caught err", err);
|
|
319
|
+
couldntParse = true;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
if (couldntParse) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
node.attributes = flattenedAttrs;
|
|
327
|
+
if (staticConfig.defaultProps) {
|
|
328
|
+
for (const key in staticConfig.defaultProps) {
|
|
329
|
+
if (isValidStyleKey(key)) {
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
const serialize = require("babel-literal-to-ast");
|
|
333
|
+
const val = staticConfig.defaultProps[key];
|
|
334
|
+
try {
|
|
335
|
+
const serializedDefaultProp = serialize(val);
|
|
336
|
+
node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier(key), typeof val === "string" ? t.stringLiteral(val) : t.jsxExpressionContainer(serializedDefaultProp)));
|
|
337
|
+
} catch (err) {
|
|
338
|
+
console.warn(`\u26A0\uFE0F Error evaluating default prop for component ${node.name.name}, prop ${key}
|
|
339
|
+
error: ${err}
|
|
340
|
+
value:`, val, "\n defaultProps:", staticConfig.defaultProps);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
let attrs = [];
|
|
345
|
+
let shouldDeopt = false;
|
|
346
|
+
let inlinePropCount = 0;
|
|
347
|
+
let hasSetOptimized = false;
|
|
348
|
+
attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
|
|
349
|
+
try {
|
|
350
|
+
const res2 = evaluateAttribute(path);
|
|
351
|
+
if (!res2) {
|
|
352
|
+
path.remove();
|
|
353
|
+
}
|
|
354
|
+
return res2;
|
|
355
|
+
} catch (err) {
|
|
356
|
+
if (shouldPrintDebug) {
|
|
357
|
+
console.log("Error extracting attribute", err.message, err.stack);
|
|
358
|
+
console.log("node", path.node);
|
|
359
|
+
}
|
|
360
|
+
return {
|
|
361
|
+
type: "attr",
|
|
362
|
+
value: path.node
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
}).flat(4).filter(import_extractHelpers.isPresent);
|
|
366
|
+
if (shouldPrintDebug) {
|
|
367
|
+
console.log(" - attrs (before):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
368
|
+
}
|
|
369
|
+
function evaluateAttribute(path) {
|
|
370
|
+
const attribute = path.node;
|
|
371
|
+
const attr = { type: "attr", value: attribute };
|
|
372
|
+
if (t.isJSXSpreadAttribute(attribute)) {
|
|
373
|
+
const arg = attribute.argument;
|
|
374
|
+
const conditional = t.isConditionalExpression(arg) ? [arg.test, arg.consequent, arg.alternate] : t.isLogicalExpression(arg) && arg.operator === "&&" ? [arg.left, arg.right, null] : null;
|
|
375
|
+
if (conditional) {
|
|
376
|
+
const [test, alt, cons] = conditional;
|
|
377
|
+
if (!test)
|
|
378
|
+
throw new Error(`no test`);
|
|
379
|
+
if ([alt, cons].some((side) => side && !isExtractable(side))) {
|
|
380
|
+
if (shouldPrintDebug) {
|
|
381
|
+
console.log("not extractable", alt, cons);
|
|
382
|
+
}
|
|
383
|
+
return attr;
|
|
384
|
+
}
|
|
385
|
+
return [
|
|
386
|
+
...createTernariesFromObjectProperties(test, alt) || [],
|
|
387
|
+
...cons && createTernariesFromObjectProperties(t.unaryExpression("!", test), cons) || []
|
|
388
|
+
].map((ternary) => ({
|
|
389
|
+
type: "ternary",
|
|
390
|
+
value: ternary
|
|
391
|
+
}));
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
if (t.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name !== "string") {
|
|
395
|
+
if (shouldPrintDebug) {
|
|
396
|
+
console.log(" ! inlining, spread attr");
|
|
397
|
+
}
|
|
398
|
+
inlinePropCount++;
|
|
399
|
+
return attr;
|
|
400
|
+
}
|
|
401
|
+
const name = attribute.name.name;
|
|
402
|
+
if (excludeProps == null ? void 0 : excludeProps.has(name)) {
|
|
403
|
+
if (shouldPrintDebug) {
|
|
404
|
+
console.log(" excluding prop", name);
|
|
405
|
+
}
|
|
406
|
+
return null;
|
|
407
|
+
}
|
|
408
|
+
if (inlineProps.has(name)) {
|
|
409
|
+
inlinePropCount++;
|
|
410
|
+
if (shouldPrintDebug) {
|
|
411
|
+
console.log(" ! inlining, inline prop", name);
|
|
412
|
+
}
|
|
413
|
+
return attr;
|
|
414
|
+
}
|
|
415
|
+
if (deoptProps.has(name)) {
|
|
416
|
+
shouldDeopt = true;
|
|
417
|
+
inlinePropCount++;
|
|
418
|
+
if (shouldPrintDebug) {
|
|
419
|
+
console.log(" ! inlining, deopted prop", name);
|
|
420
|
+
}
|
|
421
|
+
return attr;
|
|
422
|
+
}
|
|
423
|
+
if (UNTOUCHED_PROPS[name]) {
|
|
424
|
+
return attr;
|
|
425
|
+
}
|
|
426
|
+
if (name.startsWith("data-")) {
|
|
427
|
+
return attr;
|
|
428
|
+
}
|
|
429
|
+
if (name[0] === "$" && t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
|
|
430
|
+
if (disableExtractInlineMedia) {
|
|
431
|
+
return attr;
|
|
432
|
+
}
|
|
433
|
+
const shortname = name.slice(1);
|
|
434
|
+
if (import_core_node.mediaQueryConfig[shortname]) {
|
|
435
|
+
const expression = attribute.value.expression;
|
|
436
|
+
if (!t.isJSXEmptyExpression(expression)) {
|
|
437
|
+
const ternaries2 = createTernariesFromObjectProperties(t.stringLiteral(shortname), expression, {
|
|
438
|
+
inlineMediaQuery: shortname
|
|
439
|
+
});
|
|
440
|
+
if (ternaries2) {
|
|
441
|
+
return ternaries2.map((value2) => ({
|
|
442
|
+
type: "ternary",
|
|
443
|
+
value: value2
|
|
444
|
+
}));
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
const [value, valuePath] = (() => {
|
|
450
|
+
if (t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
|
|
451
|
+
return [attribute.value.expression, path.get("value")];
|
|
452
|
+
} else {
|
|
453
|
+
return [attribute.value, path.get("value")];
|
|
454
|
+
}
|
|
455
|
+
})();
|
|
456
|
+
const remove = /* @__PURE__ */ __name(() => {
|
|
457
|
+
Array.isArray(valuePath) ? valuePath.map((p) => p.remove()) : valuePath.remove();
|
|
458
|
+
}, "remove");
|
|
459
|
+
if (name === "ref") {
|
|
460
|
+
if (shouldPrintDebug) {
|
|
461
|
+
console.log(" ! inlining, ref", name);
|
|
462
|
+
}
|
|
463
|
+
inlinePropCount++;
|
|
464
|
+
return attr;
|
|
465
|
+
}
|
|
466
|
+
if (name === "tag") {
|
|
467
|
+
return {
|
|
468
|
+
type: "attr",
|
|
469
|
+
value: path.node
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
if (disableExtractVariables) {
|
|
473
|
+
if (value) {
|
|
474
|
+
if (value.type === "StringLiteral" && value.value[0] === "$") {
|
|
475
|
+
if (shouldPrintDebug) {
|
|
476
|
+
console.log(` ! inlining, native disable extract: ${name} =`, value.value);
|
|
477
|
+
}
|
|
478
|
+
inlinePropCount++;
|
|
479
|
+
return attr;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
const styleValue = attemptEvalSafe(value);
|
|
484
|
+
if (!isValidStyleKey(name)) {
|
|
485
|
+
let keys = [name];
|
|
486
|
+
let out = null;
|
|
487
|
+
if (staticConfig.propMapper) {
|
|
488
|
+
out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, staticConfig);
|
|
489
|
+
if (out) {
|
|
490
|
+
out = import_core_node.rnw.createDOMProps(isTextView ? "span" : "div", out);
|
|
491
|
+
delete out.className;
|
|
492
|
+
keys = Object.keys(out);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
const attributes = keys.map((key) => {
|
|
496
|
+
const val = out[key];
|
|
497
|
+
if (!isValidStyleKey(key)) {
|
|
498
|
+
if (import_validHTMLAttributes.validHTMLAttributes[key]) {
|
|
499
|
+
return {
|
|
500
|
+
type: "attr",
|
|
501
|
+
value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer((0, import_literalToAst.literalToAst)(val)))
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
if (shouldPrintDebug) {
|
|
505
|
+
console.log(" ! inlining, non-static", key);
|
|
506
|
+
}
|
|
507
|
+
inlinePropCount++;
|
|
508
|
+
}
|
|
509
|
+
return {
|
|
510
|
+
type: "style",
|
|
511
|
+
value: { [name]: styleValue },
|
|
512
|
+
name,
|
|
513
|
+
attr: path.node
|
|
514
|
+
};
|
|
515
|
+
});
|
|
516
|
+
if (inlinePropCount) {
|
|
517
|
+
return attr;
|
|
518
|
+
}
|
|
519
|
+
return attributes;
|
|
520
|
+
}
|
|
521
|
+
if (styleValue !== import_constants.FAILED_EVAL) {
|
|
522
|
+
if (shouldPrintDebug) {
|
|
523
|
+
console.log(` style: ${name} =`, styleValue);
|
|
524
|
+
}
|
|
525
|
+
if (!(name in staticConfig.defaultProps)) {
|
|
526
|
+
if (!hasSetOptimized) {
|
|
527
|
+
res.optimized++;
|
|
528
|
+
hasSetOptimized = true;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
return {
|
|
532
|
+
type: "style",
|
|
533
|
+
value: { [name]: styleValue },
|
|
534
|
+
name,
|
|
535
|
+
attr: path.node
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
if (t.isBinaryExpression(value)) {
|
|
539
|
+
if (shouldPrintDebug) {
|
|
540
|
+
console.log(` binary expression ${name} = `, value);
|
|
541
|
+
}
|
|
542
|
+
const { operator, left, right } = value;
|
|
543
|
+
const lVal = attemptEvalSafe(left);
|
|
544
|
+
const rVal = attemptEvalSafe(right);
|
|
545
|
+
if (shouldPrintDebug) {
|
|
546
|
+
console.log(` evalBinaryExpression lVal ${String(lVal)}, rVal ${String(rVal)}`);
|
|
547
|
+
}
|
|
548
|
+
if (lVal !== import_constants.FAILED_EVAL && t.isConditionalExpression(right)) {
|
|
549
|
+
const ternary = addBinaryConditional(operator, left, right);
|
|
550
|
+
if (ternary)
|
|
551
|
+
return ternary;
|
|
552
|
+
}
|
|
553
|
+
if (rVal !== import_constants.FAILED_EVAL && t.isConditionalExpression(left)) {
|
|
554
|
+
const ternary = addBinaryConditional(operator, right, left);
|
|
555
|
+
if (ternary)
|
|
556
|
+
return ternary;
|
|
557
|
+
}
|
|
558
|
+
if (shouldPrintDebug) {
|
|
559
|
+
console.log(` evalBinaryExpression cant extract`);
|
|
560
|
+
}
|
|
561
|
+
inlinePropCount++;
|
|
562
|
+
return attr;
|
|
563
|
+
}
|
|
564
|
+
const staticConditional = getStaticConditional(value);
|
|
565
|
+
if (staticConditional) {
|
|
566
|
+
if (shouldPrintDebug) {
|
|
567
|
+
console.log(` static conditional ${name} = `, value);
|
|
568
|
+
}
|
|
569
|
+
return { type: "ternary", value: staticConditional };
|
|
570
|
+
}
|
|
571
|
+
const staticLogical = getStaticLogical(value);
|
|
572
|
+
if (staticLogical) {
|
|
573
|
+
if (shouldPrintDebug) {
|
|
574
|
+
console.log(` static ternary ${name} = `, value);
|
|
575
|
+
}
|
|
576
|
+
return { type: "ternary", value: staticLogical };
|
|
577
|
+
}
|
|
578
|
+
if (shouldPrintDebug) {
|
|
579
|
+
console.log(" ! inline prop via no match", name, value.type);
|
|
580
|
+
}
|
|
581
|
+
inlinePropCount++;
|
|
582
|
+
if (shouldPrintDebug) {
|
|
583
|
+
console.log(` inlining ${name} = `, value);
|
|
584
|
+
}
|
|
585
|
+
return attr;
|
|
586
|
+
function addBinaryConditional(operator, staticExpr, cond) {
|
|
587
|
+
if (getStaticConditional(cond)) {
|
|
588
|
+
const alt = attemptEval(t.binaryExpression(operator, staticExpr, cond.alternate));
|
|
589
|
+
const cons = attemptEval(t.binaryExpression(operator, staticExpr, cond.consequent));
|
|
590
|
+
if (shouldPrintDebug) {
|
|
591
|
+
console.log(" binaryConditional", cond.test, cons, alt);
|
|
592
|
+
}
|
|
593
|
+
return {
|
|
594
|
+
type: "ternary",
|
|
595
|
+
value: {
|
|
596
|
+
test: cond.test,
|
|
597
|
+
remove,
|
|
598
|
+
alternate: { [name]: alt },
|
|
599
|
+
consequent: { [name]: cons }
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
return null;
|
|
604
|
+
}
|
|
605
|
+
__name(addBinaryConditional, "addBinaryConditional");
|
|
606
|
+
function getStaticConditional(value2) {
|
|
607
|
+
if (t.isConditionalExpression(value2)) {
|
|
608
|
+
try {
|
|
609
|
+
if (shouldPrintDebug) {
|
|
610
|
+
console.log("attempt", value2.alternate, value2.consequent);
|
|
611
|
+
}
|
|
612
|
+
const aVal = attemptEval(value2.alternate);
|
|
613
|
+
const cVal = attemptEval(value2.consequent);
|
|
614
|
+
if (shouldPrintDebug) {
|
|
615
|
+
const type = value2.test.type;
|
|
616
|
+
console.log(" static ternary", type, cVal, aVal);
|
|
617
|
+
}
|
|
618
|
+
return {
|
|
619
|
+
test: value2.test,
|
|
620
|
+
remove,
|
|
621
|
+
consequent: { [name]: cVal },
|
|
622
|
+
alternate: { [name]: aVal }
|
|
623
|
+
};
|
|
624
|
+
} catch (err) {
|
|
625
|
+
if (shouldPrintDebug) {
|
|
626
|
+
console.log(" cant eval ternary", err.message);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
return null;
|
|
631
|
+
}
|
|
632
|
+
__name(getStaticConditional, "getStaticConditional");
|
|
633
|
+
function getStaticLogical(value2) {
|
|
634
|
+
if (t.isLogicalExpression(value2)) {
|
|
635
|
+
if (value2.operator === "&&") {
|
|
636
|
+
try {
|
|
637
|
+
const val = attemptEval(value2.right);
|
|
638
|
+
if (shouldPrintDebug) {
|
|
639
|
+
console.log(" staticLogical", value2.left, name, val);
|
|
640
|
+
}
|
|
641
|
+
return {
|
|
642
|
+
test: value2.left,
|
|
643
|
+
remove,
|
|
644
|
+
consequent: { [name]: val },
|
|
645
|
+
alternate: null
|
|
646
|
+
};
|
|
647
|
+
} catch (err) {
|
|
648
|
+
if (shouldPrintDebug) {
|
|
649
|
+
console.log(" cant static eval logical", err);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
return null;
|
|
655
|
+
}
|
|
656
|
+
__name(getStaticLogical, "getStaticLogical");
|
|
657
|
+
}
|
|
658
|
+
__name(evaluateAttribute, "evaluateAttribute");
|
|
659
|
+
function isExtractable(obj) {
|
|
660
|
+
return t.isObjectExpression(obj) && obj.properties.every((prop) => {
|
|
661
|
+
if (!t.isObjectProperty(prop)) {
|
|
662
|
+
console.log("not object prop", prop);
|
|
663
|
+
return false;
|
|
664
|
+
}
|
|
665
|
+
const propName = prop.key["name"];
|
|
666
|
+
if (!isValidStyleKey(propName) && propName !== "tag") {
|
|
667
|
+
if (shouldPrintDebug) {
|
|
668
|
+
console.log(" not a valid style prop!", propName);
|
|
669
|
+
}
|
|
670
|
+
return false;
|
|
671
|
+
}
|
|
672
|
+
return true;
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
__name(isExtractable, "isExtractable");
|
|
676
|
+
function createTernariesFromObjectProperties(test, side, ternaryPartial = {}) {
|
|
677
|
+
if (!side) {
|
|
678
|
+
return null;
|
|
679
|
+
}
|
|
680
|
+
if (!isExtractable(side)) {
|
|
681
|
+
throw new Error("not extractable");
|
|
682
|
+
}
|
|
683
|
+
return side.properties.flatMap((property) => {
|
|
684
|
+
if (!t.isObjectProperty(property)) {
|
|
685
|
+
throw new Error("expected object property");
|
|
686
|
+
}
|
|
687
|
+
if (t.isIdentifier(property.key)) {
|
|
688
|
+
const key = property.key.name;
|
|
689
|
+
const mediaQueryKey = key.slice(1);
|
|
690
|
+
const isMediaQuery = key[0] === "$" && import_core_node.mediaQueryConfig[mediaQueryKey];
|
|
691
|
+
if (isMediaQuery) {
|
|
692
|
+
if (t.isExpression(property.value)) {
|
|
693
|
+
const ternaries2 = createTernariesFromObjectProperties(t.stringLiteral(mediaQueryKey), property.value, {
|
|
694
|
+
inlineMediaQuery: mediaQueryKey
|
|
695
|
+
});
|
|
696
|
+
if (ternaries2) {
|
|
697
|
+
return ternaries2.map((value) => __spreadProps(__spreadValues(__spreadValues({}, ternaryPartial), value), {
|
|
698
|
+
test: t.logicalExpression("&&", value.test, test)
|
|
699
|
+
}));
|
|
700
|
+
} else {
|
|
701
|
+
console.log("\u26A0\uFE0F no ternaries?", property);
|
|
702
|
+
}
|
|
703
|
+
} else {
|
|
704
|
+
console.log("\u26A0\uFE0F not expression", property);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
if (t.isConditionalExpression(property.value)) {
|
|
709
|
+
const [truthy, falsy] = [
|
|
710
|
+
t.objectExpression([t.objectProperty(property.key, property.value.consequent)]),
|
|
711
|
+
t.objectExpression([t.objectProperty(property.key, property.value.alternate)])
|
|
712
|
+
].map((x) => attemptEval(x));
|
|
713
|
+
return [
|
|
714
|
+
createTernary(__spreadProps(__spreadValues({
|
|
715
|
+
remove() {
|
|
716
|
+
}
|
|
717
|
+
}, ternaryPartial), {
|
|
718
|
+
test: t.logicalExpression("&&", test, property.value.test),
|
|
719
|
+
consequent: truthy,
|
|
720
|
+
alternate: null
|
|
721
|
+
})),
|
|
722
|
+
createTernary(__spreadProps(__spreadValues({}, ternaryPartial), {
|
|
723
|
+
test: t.logicalExpression("&&", test, t.unaryExpression("!", property.value.test)),
|
|
724
|
+
consequent: falsy,
|
|
725
|
+
alternate: null,
|
|
726
|
+
remove() {
|
|
727
|
+
}
|
|
728
|
+
}))
|
|
729
|
+
];
|
|
730
|
+
}
|
|
731
|
+
const obj = t.objectExpression([t.objectProperty(property.key, property.value)]);
|
|
732
|
+
const consequent = attemptEval(obj);
|
|
733
|
+
return createTernary(__spreadProps(__spreadValues({
|
|
734
|
+
remove() {
|
|
735
|
+
}
|
|
736
|
+
}, ternaryPartial), {
|
|
737
|
+
test,
|
|
738
|
+
consequent,
|
|
739
|
+
alternate: null
|
|
740
|
+
}));
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
__name(createTernariesFromObjectProperties, "createTernariesFromObjectProperties");
|
|
744
|
+
node.attributes = attrs.filter(isAttr).map((x) => x.value);
|
|
745
|
+
if (couldntParse || shouldDeopt) {
|
|
746
|
+
if (shouldPrintDebug) {
|
|
747
|
+
console.log(` avoid optimizing:`, { couldntParse, shouldDeopt });
|
|
748
|
+
}
|
|
749
|
+
node.attributes = ogAttributes;
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
const parentFn = (0, import_findTopmostFunction.findTopmostFunction)(traversePath);
|
|
753
|
+
if (parentFn) {
|
|
754
|
+
modifiedComponents.add(parentFn);
|
|
755
|
+
}
|
|
756
|
+
let ternaries = [];
|
|
757
|
+
attrs = attrs.reduce((out, cur) => {
|
|
758
|
+
const next = attrs[attrs.indexOf(cur) + 1];
|
|
759
|
+
if (cur.type === "ternary") {
|
|
760
|
+
ternaries.push(cur.value);
|
|
761
|
+
}
|
|
762
|
+
if ((!next || next.type !== "ternary") && ternaries.length) {
|
|
763
|
+
const normalized = (0, import_normalizeTernaries.normalizeTernaries)(ternaries).map((_a3) => {
|
|
764
|
+
var _b3 = _a3, { alternate, consequent } = _b3, rest = __objRest(_b3, ["alternate", "consequent"]);
|
|
765
|
+
return {
|
|
766
|
+
type: "ternary",
|
|
767
|
+
value: __spreadProps(__spreadValues({}, rest), {
|
|
768
|
+
alternate: alternate || null,
|
|
769
|
+
consequent: consequent || null
|
|
770
|
+
})
|
|
771
|
+
};
|
|
772
|
+
});
|
|
773
|
+
try {
|
|
774
|
+
return [...out, ...normalized];
|
|
775
|
+
} finally {
|
|
776
|
+
if (shouldPrintDebug) {
|
|
777
|
+
console.log(` normalizeTernaries (${ternaries.length} => ${normalized.length})`);
|
|
778
|
+
}
|
|
779
|
+
ternaries = [];
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
if (cur.type === "ternary") {
|
|
783
|
+
return out;
|
|
784
|
+
}
|
|
785
|
+
out.push(cur);
|
|
786
|
+
return out;
|
|
787
|
+
}, []).flat();
|
|
788
|
+
const completeStaticProps = __spreadValues({}, Object.keys(attrs).reduce((acc, index) => {
|
|
789
|
+
const cur = attrs[index];
|
|
790
|
+
if (cur.type === "style") {
|
|
791
|
+
Object.assign(acc, cur.value);
|
|
792
|
+
}
|
|
793
|
+
if (cur.type === "attr") {
|
|
794
|
+
if (t.isJSXSpreadAttribute(cur.value)) {
|
|
795
|
+
return acc;
|
|
796
|
+
}
|
|
797
|
+
if (!t.isJSXIdentifier(cur.value.name)) {
|
|
798
|
+
return acc;
|
|
799
|
+
}
|
|
800
|
+
const key = cur.value.name.name;
|
|
801
|
+
const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
|
|
802
|
+
if (value === import_constants.FAILED_EVAL) {
|
|
803
|
+
return acc;
|
|
804
|
+
}
|
|
805
|
+
acc[key] = value;
|
|
806
|
+
}
|
|
807
|
+
return acc;
|
|
808
|
+
}, {}));
|
|
809
|
+
const hasSpread = node.attributes.some((x) => t.isJSXSpreadAttribute(x));
|
|
810
|
+
const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
|
|
811
|
+
const shouldFlatten = !shouldDeopt && inlinePropCount === 0 && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
|
|
812
|
+
if (shouldFlatten && staticConfig.defaultProps) {
|
|
813
|
+
const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap((key) => {
|
|
814
|
+
if (!isValidStyleKey(key)) {
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
try {
|
|
818
|
+
const serialize = require("babel-literal-to-ast");
|
|
819
|
+
const val = staticConfig.defaultProps[key];
|
|
820
|
+
const value = serialize(val);
|
|
821
|
+
const name = tamaguiConfig.shorthands[key] || key;
|
|
822
|
+
return {
|
|
823
|
+
type: "style",
|
|
824
|
+
name,
|
|
825
|
+
value
|
|
826
|
+
};
|
|
827
|
+
} catch (err) {
|
|
828
|
+
console.warn(`\u26A0\uFE0F Error evaluating default style for component, prop ${key}
|
|
829
|
+
error: ${err}`);
|
|
830
|
+
shouldDeopt = true;
|
|
831
|
+
}
|
|
832
|
+
});
|
|
833
|
+
if (defaultStyleAttrs.length) {
|
|
834
|
+
attrs = [...defaultStyleAttrs, ...attrs];
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
if (shouldDeopt) {
|
|
838
|
+
node.attributes = ogAttributes;
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
const ensureOverridden = {};
|
|
842
|
+
if (!shouldFlatten) {
|
|
843
|
+
for (const cur of attrs) {
|
|
844
|
+
if (cur.type === "style") {
|
|
845
|
+
for (const key in cur.value) {
|
|
846
|
+
const shouldEnsureOverridden = !!((_b2 = staticConfig.ensureOverriddenProp) == null ? void 0 : _b2[key]);
|
|
847
|
+
const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
|
|
848
|
+
if (!isSetInAttrsAlready) {
|
|
849
|
+
const isVariant = !!((_c = staticConfig.variants) == null ? void 0 : _c[cur.name || ""]);
|
|
850
|
+
if (isVariant || shouldEnsureOverridden) {
|
|
851
|
+
ensureOverridden[key] = true;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
if (shouldPrintDebug) {
|
|
859
|
+
console.log(" - attrs (flattened): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
860
|
+
console.log(" - ensureOverriden:", Object.keys(ensureOverridden).join(", "));
|
|
861
|
+
}
|
|
862
|
+
attrs = attrs.reduce((acc, cur) => {
|
|
863
|
+
if (!cur) {
|
|
864
|
+
return acc;
|
|
865
|
+
}
|
|
866
|
+
if (shouldFlatten && cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value) && cur.value.name.name === "tag") {
|
|
867
|
+
return acc;
|
|
868
|
+
}
|
|
869
|
+
if (cur.type !== "style") {
|
|
870
|
+
acc.push(cur);
|
|
871
|
+
return acc;
|
|
872
|
+
}
|
|
873
|
+
let key = Object.keys(cur.value)[0];
|
|
874
|
+
const value = cur.value[key];
|
|
875
|
+
const fullKey = tamaguiConfig.shorthands[key];
|
|
876
|
+
if (fullKey) {
|
|
877
|
+
cur.value = { [fullKey]: value };
|
|
878
|
+
key = fullKey;
|
|
879
|
+
}
|
|
880
|
+
if (disableExtractVariables) {
|
|
881
|
+
if (value[0] === "$") {
|
|
882
|
+
if (shouldPrintDebug) {
|
|
883
|
+
console.log(` keeping variable inline: ${key} =`, value);
|
|
884
|
+
}
|
|
885
|
+
acc.push({
|
|
886
|
+
type: "attr",
|
|
887
|
+
value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.stringLiteral(value)))
|
|
888
|
+
});
|
|
889
|
+
return acc;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
acc.push(cur);
|
|
893
|
+
return acc;
|
|
894
|
+
}, []);
|
|
895
|
+
if (shouldPrintDebug) {
|
|
896
|
+
console.log(" - attrs (expanded): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
897
|
+
}
|
|
898
|
+
let prev = null;
|
|
899
|
+
function mergeStyles(prev2, next) {
|
|
900
|
+
for (const key in next) {
|
|
901
|
+
if (import_core_node.pseudos[key]) {
|
|
902
|
+
prev2[key] = prev2[key] || {};
|
|
903
|
+
Object.assign(prev2[key], next[key]);
|
|
904
|
+
} else {
|
|
905
|
+
prev2[key] = next[key];
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
__name(mergeStyles, "mergeStyles");
|
|
910
|
+
attrs = attrs.reduce((acc, cur) => {
|
|
911
|
+
if (cur.type === "style") {
|
|
912
|
+
const key = Object.keys(cur.value)[0];
|
|
913
|
+
const value = cur.value[key];
|
|
914
|
+
const shouldKeepOriginalAttr = !shouldFlatten && !validStyles[key] && !import_core_node.pseudos[key] && !key.startsWith("data-");
|
|
915
|
+
if (shouldPrintDebug) {
|
|
916
|
+
console.log("go", {
|
|
917
|
+
key,
|
|
918
|
+
value,
|
|
919
|
+
prevType: prev == null ? void 0 : prev.type,
|
|
920
|
+
shouldKeepOriginalAttr,
|
|
921
|
+
ensureOverridden: ensureOverridden[key]
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
if (shouldKeepOriginalAttr) {
|
|
925
|
+
if (shouldPrintDebug) {
|
|
926
|
+
console.log(" - keeping as non-style", key);
|
|
927
|
+
}
|
|
928
|
+
prev = cur;
|
|
929
|
+
acc.push({
|
|
930
|
+
type: "attr",
|
|
931
|
+
value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(typeof value === "string" ? t.stringLiteral(value) : (0, import_literalToAst.literalToAst)(value)))
|
|
932
|
+
});
|
|
933
|
+
acc.push(cur);
|
|
934
|
+
return acc;
|
|
935
|
+
}
|
|
936
|
+
if (ensureOverridden[key]) {
|
|
937
|
+
acc.push({
|
|
938
|
+
type: "attr",
|
|
939
|
+
value: cur.attr || t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.nullLiteral()))
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
if ((prev == null ? void 0 : prev.type) === "style") {
|
|
943
|
+
mergeStyles(prev.value, cur.value);
|
|
944
|
+
return acc;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
prev = cur;
|
|
948
|
+
acc.push(cur);
|
|
949
|
+
return acc;
|
|
950
|
+
}, []);
|
|
951
|
+
if (shouldPrintDebug) {
|
|
952
|
+
console.log(" - attrs (combined \u{1F500}): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
953
|
+
}
|
|
954
|
+
const getStyles = /* @__PURE__ */ __name((props2, debugName = "") => {
|
|
955
|
+
if (!props2)
|
|
956
|
+
return;
|
|
957
|
+
if (!Object.keys(props2).length)
|
|
958
|
+
return;
|
|
959
|
+
if (excludeProps && !!excludeProps.size) {
|
|
960
|
+
for (const key in props2) {
|
|
961
|
+
if (excludeProps.has(key)) {
|
|
962
|
+
delete props2[key];
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
const out = (0, import_core_node.getSplitStyles)(props2, staticConfig, defaultTheme, {
|
|
967
|
+
noClassNames: true
|
|
968
|
+
});
|
|
969
|
+
const outStyle = __spreadValues(__spreadValues({}, out.style), out.pseudos);
|
|
970
|
+
if (shouldPrintDebug === "verbose") {
|
|
971
|
+
console.log(` getStyles ${debugName} (props):
|
|
972
|
+
`, (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(props2)));
|
|
973
|
+
console.log(` getStyles ${debugName} (out.viewProps):
|
|
974
|
+
`, (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(out.viewProps)));
|
|
975
|
+
console.log(` getStyles ${debugName} (out.style):
|
|
976
|
+
`, (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(outStyle || {}), true));
|
|
977
|
+
}
|
|
978
|
+
for (const key in outStyle) {
|
|
979
|
+
if (staticConfig.validStyles) {
|
|
980
|
+
if (!staticConfig.validStyles[key] && !import_core_node.pseudos[key]) {
|
|
981
|
+
delete outStyle[key];
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
return outStyle;
|
|
986
|
+
}, "getStyles");
|
|
987
|
+
const completeStylesProcessed = getStyles(__spreadValues(__spreadValues({}, staticConfig.defaultProps), completeStaticProps), "completeStylesProcessed");
|
|
988
|
+
if (!completeStylesProcessed) {
|
|
989
|
+
throw new Error(`Impossible, no styles`);
|
|
990
|
+
}
|
|
991
|
+
const stylesToAddToInitialGroup = shouldFlatten ? (0, import_lodash.difference)(Object.keys(completeStylesProcessed), Object.keys(completeStaticProps)) : [];
|
|
992
|
+
if (stylesToAddToInitialGroup.length) {
|
|
993
|
+
const toAdd = (0, import_lodash.pick)(completeStylesProcessed, ...stylesToAddToInitialGroup);
|
|
994
|
+
const firstGroup = attrs.find((x) => x.type === "style");
|
|
995
|
+
if (shouldPrintDebug) {
|
|
996
|
+
console.log(" toAdd", (0, import_extractHelpers.objToStr)(toAdd));
|
|
997
|
+
}
|
|
998
|
+
if (!firstGroup) {
|
|
999
|
+
attrs.unshift({ type: "style", value: toAdd });
|
|
1000
|
+
} else {
|
|
1001
|
+
Object.assign(firstGroup.value, toAdd);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
if (shouldPrintDebug) {
|
|
1005
|
+
console.log(" -- stylesToAddToInitialGroup", stylesToAddToInitialGroup.join(", "), { shouldFlatten });
|
|
1006
|
+
console.log(" -- completeStaticProps:\n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(completeStaticProps)));
|
|
1007
|
+
console.log(" -- completeStylesProcessed:\n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(completeStylesProcessed)));
|
|
1008
|
+
}
|
|
1009
|
+
let getStyleError = null;
|
|
1010
|
+
for (const attr of attrs) {
|
|
1011
|
+
try {
|
|
1012
|
+
if (shouldPrintDebug)
|
|
1013
|
+
console.log(" *", (0, import_extractHelpers.attrStr)(attr));
|
|
1014
|
+
switch (attr.type) {
|
|
1015
|
+
case "ternary":
|
|
1016
|
+
const a = getStyles(attr.value.alternate, "ternary.alternate");
|
|
1017
|
+
const c = getStyles(attr.value.consequent, "ternary.consequent");
|
|
1018
|
+
if (a)
|
|
1019
|
+
attr.value.alternate = a;
|
|
1020
|
+
if (c)
|
|
1021
|
+
attr.value.consequent = c;
|
|
1022
|
+
if (shouldPrintDebug)
|
|
1023
|
+
console.log(" => tern ", (0, import_extractHelpers.attrStr)(attr));
|
|
1024
|
+
continue;
|
|
1025
|
+
case "style":
|
|
1026
|
+
const styles = getStyles(attr.value, "style");
|
|
1027
|
+
if (styles) {
|
|
1028
|
+
attr.value = Object.fromEntries(Object.keys(styles).map((k) => [k, completeStylesProcessed[k]]));
|
|
1029
|
+
} else {
|
|
1030
|
+
console.warn("?????????");
|
|
1031
|
+
}
|
|
1032
|
+
continue;
|
|
1033
|
+
}
|
|
1034
|
+
} catch (err) {
|
|
1035
|
+
getStyleError = err;
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
if (getStyleError) {
|
|
1039
|
+
console.log(" \u26A0\uFE0F postprocessing error, deopt", getStyleError);
|
|
1040
|
+
node.attributes = ogAttributes;
|
|
1041
|
+
return node;
|
|
1042
|
+
}
|
|
1043
|
+
const existingStyleKeys = /* @__PURE__ */ new Set();
|
|
1044
|
+
for (let i = attrs.length - 1; i >= 0; i--) {
|
|
1045
|
+
const attr = attrs[i];
|
|
1046
|
+
if (attr.type === "style") {
|
|
1047
|
+
for (const key in attr.value) {
|
|
1048
|
+
if (existingStyleKeys.has(key)) {
|
|
1049
|
+
delete attr.value[key];
|
|
1050
|
+
} else {
|
|
1051
|
+
existingStyleKeys.add(key);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
if (shouldPrintDebug) {
|
|
1057
|
+
console.log(" - attrs (after):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
1058
|
+
}
|
|
1059
|
+
if (shouldFlatten) {
|
|
1060
|
+
if (shouldPrintDebug) {
|
|
1061
|
+
console.log(" [\u2705] flattening", originalNodeName, flatNode);
|
|
1062
|
+
}
|
|
1063
|
+
node.name.name = flatNode;
|
|
1064
|
+
res.flattened++;
|
|
1065
|
+
if (closingElement) {
|
|
1066
|
+
closingElement.name.name = flatNode;
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
if (shouldPrintDebug) {
|
|
1070
|
+
console.log(` \u274A\u274A inline props (${inlinePropCount}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : "");
|
|
1071
|
+
console.log(" - attrs (end):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
1072
|
+
}
|
|
1073
|
+
onExtractTag({
|
|
1074
|
+
attrs,
|
|
1075
|
+
node,
|
|
1076
|
+
lineNumbers,
|
|
1077
|
+
filePath,
|
|
1078
|
+
attemptEval,
|
|
1079
|
+
jsxPath: traversePath,
|
|
1080
|
+
originalNodeName,
|
|
1081
|
+
isFlattened: shouldFlatten,
|
|
1082
|
+
programPath
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
});
|
|
1086
|
+
if (modifiedComponents.size) {
|
|
1087
|
+
const all = Array.from(modifiedComponents);
|
|
1088
|
+
if (shouldPrintDebug) {
|
|
1089
|
+
console.log(" [\u{1FA9D}] hook check", all.length);
|
|
1090
|
+
}
|
|
1091
|
+
for (const comp of all) {
|
|
1092
|
+
(0, import_removeUnusedHooks.removeUnusedHooks)(comp, shouldPrintDebug);
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
return res;
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
__name(createExtractor, "createExtractor");
|
|
1100
|
+
//# sourceMappingURL=createExtractor.js.map
|