@tamagui/static 1.0.1-rc.8 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/constants.js +49 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/extractor/accessSafe.js +35 -0
- package/dist/cjs/extractor/accessSafe.js.map +7 -0
- package/dist/cjs/extractor/babelParse.js +56 -0
- package/dist/cjs/extractor/babelParse.js.map +7 -0
- package/dist/cjs/extractor/buildClassName.js +64 -0
- package/dist/cjs/extractor/buildClassName.js.map +7 -0
- package/dist/cjs/extractor/bundle.js +137 -0
- package/dist/cjs/extractor/bundle.js.map +7 -0
- package/dist/cjs/extractor/createEvaluator.js +81 -0
- package/dist/cjs/extractor/createEvaluator.js.map +7 -0
- package/dist/cjs/extractor/createExtractor.js +1330 -0
- package/dist/cjs/extractor/createExtractor.js.map +7 -0
- package/dist/cjs/extractor/defaultTamaguiConfig.js +167 -0
- package/dist/cjs/extractor/defaultTamaguiConfig.js.map +7 -0
- package/dist/cjs/extractor/ensureImportingConcat.js +48 -0
- package/dist/cjs/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/cjs/extractor/evaluateAstNode.js +118 -0
- package/dist/cjs/extractor/evaluateAstNode.js.map +7 -0
- package/dist/cjs/extractor/extractHelpers.js +131 -0
- package/dist/cjs/extractor/extractHelpers.js.map +7 -0
- package/dist/cjs/extractor/extractMediaStyle.js +174 -0
- package/dist/cjs/extractor/extractMediaStyle.js.map +7 -0
- package/dist/cjs/extractor/extractToClassNames.js +305 -0
- package/dist/cjs/extractor/extractToClassNames.js.map +7 -0
- package/dist/cjs/extractor/findTopmostFunction.js +44 -0
- package/dist/cjs/extractor/findTopmostFunction.js.map +7 -0
- package/dist/cjs/extractor/generatedUid.js +52 -0
- package/dist/cjs/extractor/generatedUid.js.map +7 -0
- package/dist/cjs/extractor/getPrefixLogs.js +32 -0
- package/dist/cjs/extractor/getPrefixLogs.js.map +7 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js +73 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +7 -0
- package/dist/cjs/extractor/getSourceModule.js +93 -0
- package/dist/cjs/extractor/getSourceModule.js.map +7 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js +184 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +7 -0
- package/dist/cjs/extractor/hoistClassNames.js +67 -0
- package/dist/cjs/extractor/hoistClassNames.js.map +7 -0
- package/dist/cjs/extractor/literalToAst.js +103 -0
- package/dist/cjs/extractor/literalToAst.js.map +7 -0
- package/dist/cjs/extractor/loadFile.js +21 -0
- package/dist/cjs/extractor/loadFile.js.map +7 -0
- package/dist/cjs/extractor/loadTamagui.js +105 -0
- package/dist/cjs/extractor/loadTamagui.js.map +7 -0
- package/dist/cjs/extractor/logLines.js +44 -0
- package/dist/cjs/extractor/logLines.js.map +7 -0
- package/dist/cjs/extractor/normalizeTernaries.js +76 -0
- package/dist/cjs/extractor/normalizeTernaries.js.map +7 -0
- package/dist/cjs/extractor/removeUnusedHooks.js +103 -0
- package/dist/cjs/extractor/removeUnusedHooks.js.map +7 -0
- package/dist/cjs/extractor/timer.js +46 -0
- package/dist/cjs/extractor/timer.js.map +7 -0
- package/dist/cjs/extractor/validHTMLAttributes.js +127 -0
- package/dist/cjs/extractor/validHTMLAttributes.js.map +7 -0
- package/dist/cjs/getPragmaOptions.js +67 -0
- package/dist/cjs/getPragmaOptions.js.map +7 -0
- package/dist/cjs/helpers/memoize.js +45 -0
- package/dist/cjs/helpers/memoize.js.map +7 -0
- package/dist/cjs/index.js +43 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/require.js +104 -0
- package/dist/cjs/require.js.map +7 -0
- package/dist/cjs/types.js +17 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/cjs/webpackPlugin.js +34 -0
- package/dist/cjs/webpackPlugin.js.map +7 -0
- package/dist/esm/constants.js +17 -0
- package/dist/esm/constants.js.map +7 -0
- package/dist/esm/extractor/accessSafe.js +8 -0
- package/dist/esm/extractor/accessSafe.js.map +7 -0
- package/dist/esm/extractor/babelParse.js +28 -0
- package/dist/esm/extractor/babelParse.js.map +7 -0
- package/dist/esm/extractor/buildClassName.js +37 -0
- package/dist/esm/extractor/buildClassName.js.map +7 -0
- package/dist/esm/extractor/bundle.js +112 -0
- package/dist/esm/extractor/bundle.js.map +7 -0
- package/dist/esm/extractor/createEvaluator.js +53 -0
- package/dist/esm/extractor/createEvaluator.js.map +7 -0
- package/dist/esm/extractor/createExtractor.js +1311 -0
- package/dist/esm/extractor/createExtractor.js.map +7 -0
- package/dist/esm/extractor/defaultTamaguiConfig.js +143 -0
- package/dist/esm/extractor/defaultTamaguiConfig.js.map +7 -0
- package/dist/esm/extractor/ensureImportingConcat.js +21 -0
- package/dist/esm/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/esm/extractor/evaluateAstNode.js +91 -0
- package/dist/esm/extractor/evaluateAstNode.js.map +7 -0
- package/dist/esm/extractor/extractHelpers.js +97 -0
- package/dist/esm/extractor/extractHelpers.js.map +7 -0
- package/dist/esm/extractor/extractMediaStyle.js +146 -0
- package/dist/esm/extractor/extractMediaStyle.js.map +7 -0
- package/dist/esm/extractor/extractToClassNames.js +278 -0
- package/dist/esm/extractor/extractToClassNames.js.map +7 -0
- package/dist/esm/extractor/findTopmostFunction.js +20 -0
- package/dist/esm/extractor/findTopmostFunction.js.map +7 -0
- package/dist/esm/extractor/generatedUid.js +25 -0
- package/dist/esm/extractor/generatedUid.js.map +7 -0
- package/dist/esm/extractor/getPrefixLogs.js +8 -0
- package/dist/esm/extractor/getPrefixLogs.js.map +7 -0
- package/dist/esm/extractor/getPropValueFromAttributes.js +46 -0
- package/dist/esm/extractor/getPropValueFromAttributes.js.map +7 -0
- package/dist/esm/extractor/getSourceModule.js +66 -0
- package/dist/esm/extractor/getSourceModule.js.map +7 -0
- package/dist/esm/extractor/getStaticBindingsForScope.js +157 -0
- package/dist/esm/extractor/getStaticBindingsForScope.js.map +7 -0
- package/dist/esm/extractor/hoistClassNames.js +40 -0
- package/dist/esm/extractor/hoistClassNames.js.map +7 -0
- package/dist/esm/extractor/literalToAst.js +75 -0
- package/dist/esm/extractor/literalToAst.js.map +7 -0
- package/dist/esm/extractor/loadFile.js +20 -0
- package/dist/esm/extractor/loadFile.js.map +7 -0
- package/dist/esm/extractor/loadTamagui.js +81 -0
- package/dist/esm/extractor/loadTamagui.js.map +7 -0
- package/dist/esm/extractor/logLines.js +20 -0
- package/dist/esm/extractor/logLines.js.map +7 -0
- package/dist/esm/extractor/normalizeTernaries.js +49 -0
- package/dist/esm/extractor/normalizeTernaries.js.map +7 -0
- package/dist/esm/extractor/removeUnusedHooks.js +76 -0
- package/dist/esm/extractor/removeUnusedHooks.js.map +7 -0
- package/dist/esm/extractor/timer.js +22 -0
- package/dist/esm/extractor/timer.js.map +7 -0
- package/dist/esm/extractor/validHTMLAttributes.js +102 -0
- package/dist/esm/extractor/validHTMLAttributes.js.map +7 -0
- package/dist/esm/getPragmaOptions.js +44 -0
- package/dist/esm/getPragmaOptions.js.map +7 -0
- package/dist/esm/helpers/memoize.js +22 -0
- package/dist/esm/helpers/memoize.js.map +7 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/require.js +78 -0
- package/dist/esm/require.js.map +7 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +7 -0
- package/dist/esm/webpackPlugin.js +11 -0
- package/dist/esm/webpackPlugin.js.map +7 -0
- package/dist/extractor/babelParse.js +5 -1
- package/dist/extractor/babelParse.js.map +2 -2
- package/dist/extractor/createExtractor.js.map +2 -2
- package/dist/extractor/extractToClassNames.js +27 -4
- package/dist/extractor/extractToClassNames.js.map +2 -2
- package/dist/extractor/getStaticBindingsForScope.js +1 -1
- package/dist/extractor/getStaticBindingsForScope.js.map +1 -1
- package/dist/extractor/loadTamagui.js +25 -13
- package/dist/extractor/loadTamagui.js.map +2 -2
- package/dist/jsx/constants.js +17 -0
- package/dist/jsx/constants.js.map +7 -0
- package/dist/jsx/extractor/accessSafe.js +8 -0
- package/dist/jsx/extractor/accessSafe.js.map +7 -0
- package/dist/jsx/extractor/babelParse.js +28 -0
- package/dist/jsx/extractor/babelParse.js.map +7 -0
- package/dist/jsx/extractor/buildClassName.js +37 -0
- package/dist/jsx/extractor/buildClassName.js.map +7 -0
- package/dist/jsx/extractor/bundle.js +86 -0
- package/dist/jsx/extractor/bundle.js.map +7 -0
- package/dist/jsx/extractor/createEvaluator.js +53 -0
- package/dist/jsx/extractor/createEvaluator.js.map +7 -0
- package/dist/jsx/extractor/createExtractor.js +1311 -0
- package/dist/jsx/extractor/createExtractor.js.map +7 -0
- package/dist/jsx/extractor/defaultTamaguiConfig.js +143 -0
- package/dist/jsx/extractor/defaultTamaguiConfig.js.map +7 -0
- package/dist/jsx/extractor/ensureImportingConcat.js +21 -0
- package/dist/jsx/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/jsx/extractor/evaluateAstNode.js +91 -0
- package/dist/jsx/extractor/evaluateAstNode.js.map +7 -0
- package/dist/jsx/extractor/extractHelpers.js +97 -0
- package/dist/jsx/extractor/extractHelpers.js.map +7 -0
- package/dist/jsx/extractor/extractMediaStyle.js +146 -0
- package/dist/jsx/extractor/extractMediaStyle.js.map +7 -0
- package/dist/jsx/extractor/extractToClassNames.js +280 -0
- package/dist/jsx/extractor/extractToClassNames.js.map +7 -0
- package/dist/jsx/extractor/findTopmostFunction.js +20 -0
- package/dist/jsx/extractor/findTopmostFunction.js.map +7 -0
- package/dist/jsx/extractor/generatedUid.js +25 -0
- package/dist/jsx/extractor/generatedUid.js.map +7 -0
- package/dist/jsx/extractor/getPrefixLogs.js +9 -0
- package/dist/jsx/extractor/getPrefixLogs.js.map +7 -0
- package/dist/jsx/extractor/getPropValueFromAttributes.js +46 -0
- package/dist/jsx/extractor/getPropValueFromAttributes.js.map +7 -0
- package/dist/jsx/extractor/getSourceModule.js +66 -0
- package/dist/jsx/extractor/getSourceModule.js.map +7 -0
- package/dist/jsx/extractor/getStaticBindingsForScope.js +157 -0
- package/dist/jsx/extractor/getStaticBindingsForScope.js.map +7 -0
- package/dist/jsx/extractor/hoistClassNames.js +40 -0
- package/dist/jsx/extractor/hoistClassNames.js.map +7 -0
- package/dist/jsx/extractor/literalToAst.js +75 -0
- package/dist/jsx/extractor/literalToAst.js.map +7 -0
- package/dist/jsx/extractor/loadFile.js +20 -0
- package/dist/jsx/extractor/loadFile.js.map +7 -0
- package/dist/jsx/extractor/loadTamagui.js +81 -0
- package/dist/jsx/extractor/loadTamagui.js.map +7 -0
- package/dist/jsx/extractor/logLines.js +20 -0
- package/dist/jsx/extractor/logLines.js.map +7 -0
- package/dist/jsx/extractor/normalizeTernaries.js +50 -0
- package/dist/jsx/extractor/normalizeTernaries.js.map +7 -0
- package/dist/jsx/extractor/removeUnusedHooks.js +77 -0
- package/dist/jsx/extractor/removeUnusedHooks.js.map +7 -0
- package/dist/jsx/extractor/timer.js +22 -0
- package/dist/jsx/extractor/timer.js.map +7 -0
- package/dist/jsx/extractor/validHTMLAttributes.js +102 -0
- package/dist/jsx/extractor/validHTMLAttributes.js.map +7 -0
- package/dist/jsx/getPragmaOptions.js +44 -0
- package/dist/jsx/getPragmaOptions.js.map +7 -0
- package/dist/jsx/helpers/memoize.js +22 -0
- package/dist/jsx/helpers/memoize.js.map +7 -0
- package/dist/jsx/index.js +16 -0
- package/dist/jsx/index.js.map +7 -0
- package/dist/jsx/require.js +78 -0
- package/dist/jsx/require.js.map +7 -0
- package/dist/jsx/types.js +1 -0
- package/dist/jsx/types.js.map +7 -0
- package/dist/jsx/webpackPlugin.js +11 -0
- package/dist/jsx/webpackPlugin.js.map +7 -0
- package/package.json +15 -15
- package/src/extractor/babelParse.ts +5 -1
- package/src/extractor/createExtractor.ts +3 -0
- package/src/extractor/extractToClassNames.ts +29 -6
- package/src/extractor/getStaticBindingsForScope.ts +1 -1
- package/src/extractor/loadTamagui.ts +28 -10
|
@@ -0,0 +1,1330 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
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));
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var createExtractor_exports = {};
|
|
23
|
+
__export(createExtractor_exports, {
|
|
24
|
+
createExtractor: () => createExtractor
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(createExtractor_exports);
|
|
27
|
+
var import_path = require("path");
|
|
28
|
+
var import_traverse = __toESM(require("@babel/traverse"));
|
|
29
|
+
var t = __toESM(require("@babel/types"));
|
|
30
|
+
var import_core_node = require("@tamagui/core-node");
|
|
31
|
+
var import_constants = require("../constants");
|
|
32
|
+
var import_createEvaluator = require("./createEvaluator");
|
|
33
|
+
var import_evaluateAstNode = require("./evaluateAstNode");
|
|
34
|
+
var import_extractHelpers = require("./extractHelpers");
|
|
35
|
+
var import_findTopmostFunction = require("./findTopmostFunction");
|
|
36
|
+
var import_getStaticBindingsForScope = require("./getStaticBindingsForScope");
|
|
37
|
+
var import_literalToAst = require("./literalToAst");
|
|
38
|
+
var import_loadTamagui = require("./loadTamagui");
|
|
39
|
+
var import_logLines = require("./logLines");
|
|
40
|
+
var import_normalizeTernaries = require("./normalizeTernaries");
|
|
41
|
+
var import_removeUnusedHooks = require("./removeUnusedHooks");
|
|
42
|
+
var import_timer = require("./timer");
|
|
43
|
+
var import_validHTMLAttributes = require("./validHTMLAttributes");
|
|
44
|
+
const UNTOUCHED_PROPS = {
|
|
45
|
+
key: true,
|
|
46
|
+
style: true,
|
|
47
|
+
className: true
|
|
48
|
+
};
|
|
49
|
+
const INLINE_EXTRACTABLE = {
|
|
50
|
+
ref: "ref",
|
|
51
|
+
key: "key",
|
|
52
|
+
...process.env.TAMAGUI_TARGET === "web" && {
|
|
53
|
+
onPress: "onClick",
|
|
54
|
+
onHoverIn: "onMouseEnter",
|
|
55
|
+
onHoverOut: "onMouseLeave",
|
|
56
|
+
onPressIn: "onMouseDown",
|
|
57
|
+
onPressOut: "onMouseUp"
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const isAttr = (x) => x.type === "attr";
|
|
61
|
+
const validHooks = {
|
|
62
|
+
useMedia: true,
|
|
63
|
+
useTheme: true
|
|
64
|
+
};
|
|
65
|
+
const createTernary = (x) => x;
|
|
66
|
+
function createExtractor() {
|
|
67
|
+
if (!process.env.TAMAGUI_TARGET) {
|
|
68
|
+
console.log('\u26A0\uFE0F Please set process.env.TAMAGUI_TARGET to either "web" or "native"');
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
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);
|
|
72
|
+
let loadedTamaguiConfig;
|
|
73
|
+
let hasLogged = false;
|
|
74
|
+
function isValidStyleKey(name, staticConfig) {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
return !!(!!((_a = staticConfig.validStyles) == null ? void 0 : _a[name]) || !!import_core_node.pseudoDescriptors[name] || ((_b = staticConfig.variants) == null ? void 0 : _b[name]) || loadedTamaguiConfig.shorthands[name] || (name[0] === "$" ? !!import_core_node.mediaQueryConfig[name.slice(1)] : false));
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
getTamagui() {
|
|
80
|
+
return loadedTamaguiConfig;
|
|
81
|
+
},
|
|
82
|
+
parse: (fileOrPath, {
|
|
83
|
+
config = "tamagui.config.ts",
|
|
84
|
+
importsWhitelist = ["constants.js"],
|
|
85
|
+
evaluateVars = true,
|
|
86
|
+
shouldPrintDebug = false,
|
|
87
|
+
sourcePath = "",
|
|
88
|
+
onExtractTag,
|
|
89
|
+
onStyleRule,
|
|
90
|
+
getFlattenedNode,
|
|
91
|
+
disable,
|
|
92
|
+
disableExtraction,
|
|
93
|
+
disableExtractInlineMedia,
|
|
94
|
+
disableExtractVariables,
|
|
95
|
+
disableDebugAttr,
|
|
96
|
+
extractStyledDefinitions = false,
|
|
97
|
+
prefixLogs,
|
|
98
|
+
excludeProps,
|
|
99
|
+
target,
|
|
100
|
+
...props
|
|
101
|
+
}) => {
|
|
102
|
+
if (disable) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
if (sourcePath === "") {
|
|
106
|
+
throw new Error(`Must provide a source file name`);
|
|
107
|
+
}
|
|
108
|
+
if (!Array.isArray(props.components)) {
|
|
109
|
+
throw new Error(`Must provide components array with list of Tamagui component modules`);
|
|
110
|
+
}
|
|
111
|
+
const isTargetingHTML = target === "html";
|
|
112
|
+
const ogDebug = shouldPrintDebug;
|
|
113
|
+
const tm = (0, import_timer.timer)();
|
|
114
|
+
const { components, tamaguiConfig } = (0, import_loadTamagui.loadTamagui)({
|
|
115
|
+
config,
|
|
116
|
+
components: props.components || ["tamagui"]
|
|
117
|
+
});
|
|
118
|
+
if (shouldPrintDebug === "verbose") {
|
|
119
|
+
console.log("tamagui.config.ts:", { components, config });
|
|
120
|
+
}
|
|
121
|
+
tm.mark("load-tamagui", shouldPrintDebug === "verbose");
|
|
122
|
+
loadedTamaguiConfig = tamaguiConfig;
|
|
123
|
+
const proxiedTheme = (0, import_core_node.proxyThemeVariables)(tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]]);
|
|
124
|
+
const themeAccessListeners = /* @__PURE__ */ new Set();
|
|
125
|
+
const defaultTheme = new Proxy(proxiedTheme, {
|
|
126
|
+
get(target2, key) {
|
|
127
|
+
if (key[0] === "$") {
|
|
128
|
+
themeAccessListeners.forEach((cb) => cb(String(key)));
|
|
129
|
+
}
|
|
130
|
+
return Reflect.get(target2, key);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
|
|
134
|
+
const isInternalImport = (importStr) => {
|
|
135
|
+
return (0, import_extractHelpers.isInsideTamagui)(sourcePath) && importStr[0] === ".";
|
|
136
|
+
};
|
|
137
|
+
const validComponents = Object.keys(components).filter((key) => {
|
|
138
|
+
var _a;
|
|
139
|
+
return key[0].toUpperCase() === key[0] && !!((_a = components[key]) == null ? void 0 : _a.staticConfig);
|
|
140
|
+
}).reduce((obj, name) => {
|
|
141
|
+
obj[name] = components[name];
|
|
142
|
+
return obj;
|
|
143
|
+
}, {});
|
|
144
|
+
if (shouldPrintDebug === "verbose") {
|
|
145
|
+
console.log("validComponents", Object.keys(validComponents));
|
|
146
|
+
}
|
|
147
|
+
let doesUseValidImport = false;
|
|
148
|
+
let hasImportedTheme = false;
|
|
149
|
+
for (const bodyPath of body) {
|
|
150
|
+
if (bodyPath.type !== "ImportDeclaration")
|
|
151
|
+
continue;
|
|
152
|
+
const node = "node" in bodyPath ? bodyPath.node : bodyPath;
|
|
153
|
+
const from = node.source.value;
|
|
154
|
+
if (extractStyledDefinitions) {
|
|
155
|
+
if (from === "@tamagui/core" || from === "tamagui") {
|
|
156
|
+
if (node.specifiers.some((specifier) => {
|
|
157
|
+
return specifier.local.name === "styled";
|
|
158
|
+
})) {
|
|
159
|
+
doesUseValidImport = true;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const isValidImport = props.components.includes(from) || isInternalImport(from);
|
|
165
|
+
if (isValidImport) {
|
|
166
|
+
const isValidComponent = node.specifiers.some((specifier) => {
|
|
167
|
+
const name = specifier.local.name;
|
|
168
|
+
return !!(validComponents[name] || validHooks[name]);
|
|
169
|
+
});
|
|
170
|
+
if (shouldPrintDebug === "verbose") {
|
|
171
|
+
console.log("import from", from, { isValidComponent });
|
|
172
|
+
}
|
|
173
|
+
if (isValidComponent) {
|
|
174
|
+
doesUseValidImport = true;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (shouldPrintDebug) {
|
|
180
|
+
console.log(sourcePath, { doesUseValidImport });
|
|
181
|
+
}
|
|
182
|
+
if (!doesUseValidImport) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
tm.mark("import-check", shouldPrintDebug === "verbose");
|
|
186
|
+
let couldntParse = false;
|
|
187
|
+
const modifiedComponents = /* @__PURE__ */ new Set();
|
|
188
|
+
const bindingCache = {};
|
|
189
|
+
const callTraverse = (a) => {
|
|
190
|
+
return fileOrPath.type === "File" ? (0, import_traverse.default)(fileOrPath, a) : fileOrPath.traverse(a);
|
|
191
|
+
};
|
|
192
|
+
let programPath;
|
|
193
|
+
const res = {
|
|
194
|
+
styled: 0,
|
|
195
|
+
flattened: 0,
|
|
196
|
+
optimized: 0,
|
|
197
|
+
modified: 0,
|
|
198
|
+
found: 0
|
|
199
|
+
};
|
|
200
|
+
callTraverse({
|
|
201
|
+
Program: {
|
|
202
|
+
enter(path) {
|
|
203
|
+
programPath = path;
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
CallExpression(path) {
|
|
207
|
+
var _a;
|
|
208
|
+
if (disable || disableExtraction || extractStyledDefinitions === false) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (!t.isIdentifier(path.node.callee) || path.node.callee.name !== "styled") {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const name = t.isVariableDeclarator(path.parent) && t.isIdentifier(path.parent.id) ? path.parent.id.name : "unknown";
|
|
215
|
+
const definition = path.node.arguments[1];
|
|
216
|
+
if (!name || !definition || !t.isObjectExpression(definition)) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const Component = validComponents[name];
|
|
220
|
+
if (!Component) {
|
|
221
|
+
if (shouldPrintDebug) {
|
|
222
|
+
console.log(`Didn't recognize styled(${name}), ${name} isn't in design system provided to tamagui.config.ts`);
|
|
223
|
+
}
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const componentSkipProps = /* @__PURE__ */ new Set([
|
|
227
|
+
...Component.staticConfig.inlineWhenUnflattened || [],
|
|
228
|
+
...Component.staticConfig.inlineProps || [],
|
|
229
|
+
...Component.staticConfig.deoptProps || [],
|
|
230
|
+
"variants",
|
|
231
|
+
"defaultVariants",
|
|
232
|
+
"fontFamily",
|
|
233
|
+
"name"
|
|
234
|
+
]);
|
|
235
|
+
const skipped = [];
|
|
236
|
+
const styles = {};
|
|
237
|
+
const staticNamespace = (0, import_getStaticBindingsForScope.getStaticBindingsForScope)(path.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
|
|
238
|
+
const attemptEval = !evaluateVars ? import_evaluateAstNode.evaluateAstNode : (0, import_createEvaluator.createEvaluator)({
|
|
239
|
+
tamaguiConfig,
|
|
240
|
+
staticNamespace,
|
|
241
|
+
sourcePath,
|
|
242
|
+
shouldPrintDebug
|
|
243
|
+
});
|
|
244
|
+
const attemptEvalSafe = (0, import_createEvaluator.createSafeEvaluator)(attemptEval);
|
|
245
|
+
for (const property of definition.properties) {
|
|
246
|
+
if (!t.isObjectProperty(property) || !t.isIdentifier(property.key) || !isValidStyleKey(property.key.name, Component.staticConfig) || ((_a = Component.staticConfig.variants) == null ? void 0 : _a[property.key.name]) || componentSkipProps.has(property.key.name)) {
|
|
247
|
+
skipped.push(property);
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
const out2 = attemptEvalSafe(property.value);
|
|
251
|
+
if (out2 === import_constants.FAILED_EVAL) {
|
|
252
|
+
skipped.push(property);
|
|
253
|
+
} else {
|
|
254
|
+
styles[property.key.name] = out2;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const out = (0, import_core_node.getSplitStyles)(styles, Component.staticConfig, defaultTheme, {
|
|
258
|
+
focus: false,
|
|
259
|
+
hover: false,
|
|
260
|
+
mounted: false,
|
|
261
|
+
press: false,
|
|
262
|
+
pressIn: false,
|
|
263
|
+
resolveVariablesAs: "variable"
|
|
264
|
+
});
|
|
265
|
+
const classNames = {
|
|
266
|
+
...out.classNames
|
|
267
|
+
};
|
|
268
|
+
const atomics = (0, import_core_node.getStylesAtomic)(out.style);
|
|
269
|
+
if (shouldPrintDebug) {
|
|
270
|
+
console.log("Exctacting styled()", styles, out, "to", atomics);
|
|
271
|
+
}
|
|
272
|
+
for (const atomic of atomics) {
|
|
273
|
+
out.rulesToInsert = out.rulesToInsert || [];
|
|
274
|
+
out.rulesToInsert.push(atomic);
|
|
275
|
+
classNames[atomic.property] = atomic.identifier;
|
|
276
|
+
}
|
|
277
|
+
definition.properties = skipped;
|
|
278
|
+
for (const cn in classNames) {
|
|
279
|
+
if (componentSkipProps.has(cn)) {
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
const val = classNames[cn];
|
|
283
|
+
definition.properties.push(t.objectProperty(t.stringLiteral(cn), t.stringLiteral(val)));
|
|
284
|
+
}
|
|
285
|
+
if (out.rulesToInsert) {
|
|
286
|
+
for (const { identifier, rules } of out.rulesToInsert) {
|
|
287
|
+
onStyleRule == null ? void 0 : onStyleRule(identifier, rules);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
res.styled++;
|
|
291
|
+
if (shouldPrintDebug) {
|
|
292
|
+
console.log(`Extracted styled(${name}) props:`, styles);
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
JSXElement(traversePath) {
|
|
296
|
+
var _a, _b, _c;
|
|
297
|
+
tm.mark("jsx-element", shouldPrintDebug === "verbose");
|
|
298
|
+
const node = traversePath.node.openingElement;
|
|
299
|
+
const ogAttributes = node.attributes;
|
|
300
|
+
const componentName = (0, import_extractHelpers.findComponentName)(traversePath.scope);
|
|
301
|
+
const closingElement = traversePath.node.closingElement;
|
|
302
|
+
if (t.isJSXMemberExpression(closingElement == null ? void 0 : closingElement.name) || !t.isJSXIdentifier(node.name)) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const binding = traversePath.scope.getBinding(node.name.name);
|
|
306
|
+
if (binding) {
|
|
307
|
+
if (!t.isImportDeclaration(binding.path.parent)) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
const source = binding.path.parent.source;
|
|
311
|
+
if (!props.components.includes(source.value) && !isInternalImport(source.value)) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (!validComponents[binding.identifier.name]) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
const component = validComponents[node.name.name];
|
|
319
|
+
if (!component || !component.staticConfig) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
const originalNodeName = node.name.name;
|
|
323
|
+
res.found++;
|
|
324
|
+
const filePath = `./${(0, import_path.relative)(process.cwd(), sourcePath)}`;
|
|
325
|
+
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
326
|
+
const tagId = [componentName, `${node.name.name}`, `${filePath}:${lineNumbers}`].filter(Boolean);
|
|
327
|
+
const debugPropValue = node.attributes.filter((n) => t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && n.name.name === "debug").map((n) => {
|
|
328
|
+
if (n.value === null)
|
|
329
|
+
return true;
|
|
330
|
+
if (t.isStringLiteral(n.value))
|
|
331
|
+
return n.value.value;
|
|
332
|
+
return false;
|
|
333
|
+
})[0];
|
|
334
|
+
if (debugPropValue) {
|
|
335
|
+
shouldPrintDebug = debugPropValue;
|
|
336
|
+
}
|
|
337
|
+
try {
|
|
338
|
+
let evaluateAttribute2 = function(path) {
|
|
339
|
+
const attribute = path.node;
|
|
340
|
+
const attr = { type: "attr", value: attribute };
|
|
341
|
+
if (t.isJSXSpreadAttribute(attribute)) {
|
|
342
|
+
const arg = attribute.argument;
|
|
343
|
+
const conditional = t.isConditionalExpression(arg) ? [arg.test, arg.consequent, arg.alternate] : t.isLogicalExpression(arg) && arg.operator === "&&" ? [arg.left, arg.right, null] : null;
|
|
344
|
+
if (conditional) {
|
|
345
|
+
const [test, alt, cons] = conditional;
|
|
346
|
+
if (!test)
|
|
347
|
+
throw new Error(`no test`);
|
|
348
|
+
if ([alt, cons].some((side) => side && !isExtractable2(side))) {
|
|
349
|
+
if (shouldPrintDebug) {
|
|
350
|
+
console.log("not extractable", alt, cons);
|
|
351
|
+
}
|
|
352
|
+
return attr;
|
|
353
|
+
}
|
|
354
|
+
return [
|
|
355
|
+
...createTernariesFromObjectProperties2(test, alt) || [],
|
|
356
|
+
...cons && createTernariesFromObjectProperties2(t.unaryExpression("!", test), cons) || []
|
|
357
|
+
].map((ternary) => ({
|
|
358
|
+
type: "ternary",
|
|
359
|
+
value: ternary
|
|
360
|
+
}));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (t.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name !== "string") {
|
|
364
|
+
if (shouldPrintDebug) {
|
|
365
|
+
console.log(" ! inlining, spread attr");
|
|
366
|
+
}
|
|
367
|
+
inlined.set(`${Math.random()}`, "spread");
|
|
368
|
+
return attr;
|
|
369
|
+
}
|
|
370
|
+
const name = attribute.name.name;
|
|
371
|
+
if (excludeProps == null ? void 0 : excludeProps.has(name)) {
|
|
372
|
+
if (shouldPrintDebug) {
|
|
373
|
+
console.log(" excluding prop", name);
|
|
374
|
+
}
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
377
|
+
if (inlineProps.has(name)) {
|
|
378
|
+
inlined.set(name, name);
|
|
379
|
+
if (shouldPrintDebug) {
|
|
380
|
+
console.log(" ! inlining, inline prop", name);
|
|
381
|
+
}
|
|
382
|
+
return attr;
|
|
383
|
+
}
|
|
384
|
+
if (deoptProps.has(name)) {
|
|
385
|
+
shouldDeopt = true;
|
|
386
|
+
inlined.set(name, name);
|
|
387
|
+
if (shouldPrintDebug) {
|
|
388
|
+
console.log(" ! inlining, deopted prop", name);
|
|
389
|
+
}
|
|
390
|
+
return attr;
|
|
391
|
+
}
|
|
392
|
+
if (UNTOUCHED_PROPS[name]) {
|
|
393
|
+
return attr;
|
|
394
|
+
}
|
|
395
|
+
if (INLINE_EXTRACTABLE[name]) {
|
|
396
|
+
inlined.set(name, INLINE_EXTRACTABLE[name]);
|
|
397
|
+
return attr;
|
|
398
|
+
}
|
|
399
|
+
if (name.startsWith("data-")) {
|
|
400
|
+
return attr;
|
|
401
|
+
}
|
|
402
|
+
if (name[0] === "$" && t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
|
|
403
|
+
if (disableExtractInlineMedia) {
|
|
404
|
+
return attr;
|
|
405
|
+
}
|
|
406
|
+
const shortname = name.slice(1);
|
|
407
|
+
if (import_core_node.mediaQueryConfig[shortname]) {
|
|
408
|
+
const expression = attribute.value.expression;
|
|
409
|
+
if (!t.isJSXEmptyExpression(expression)) {
|
|
410
|
+
const ternaries2 = createTernariesFromObjectProperties2(t.stringLiteral(shortname), expression, {
|
|
411
|
+
inlineMediaQuery: shortname
|
|
412
|
+
});
|
|
413
|
+
if (ternaries2) {
|
|
414
|
+
return ternaries2.map((value2) => ({
|
|
415
|
+
type: "ternary",
|
|
416
|
+
value: value2
|
|
417
|
+
}));
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
const [value, valuePath] = (() => {
|
|
423
|
+
if (t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
|
|
424
|
+
return [attribute.value.expression, path.get("value")];
|
|
425
|
+
} else {
|
|
426
|
+
return [attribute.value, path.get("value")];
|
|
427
|
+
}
|
|
428
|
+
})();
|
|
429
|
+
const remove = () => {
|
|
430
|
+
Array.isArray(valuePath) ? valuePath.map((p) => p.remove()) : valuePath.remove();
|
|
431
|
+
};
|
|
432
|
+
if (name === "ref") {
|
|
433
|
+
if (shouldPrintDebug) {
|
|
434
|
+
console.log(" ! inlining, ref", name);
|
|
435
|
+
}
|
|
436
|
+
inlined.set("ref", "ref");
|
|
437
|
+
return attr;
|
|
438
|
+
}
|
|
439
|
+
if (name === "tag") {
|
|
440
|
+
return {
|
|
441
|
+
type: "attr",
|
|
442
|
+
value: path.node
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
if (disableExtractVariables) {
|
|
446
|
+
if (value) {
|
|
447
|
+
if (value.type === "StringLiteral" && value.value[0] === "$") {
|
|
448
|
+
if (shouldPrintDebug) {
|
|
449
|
+
console.log(` ! inlining, native disable extract: ${name} =`, value.value);
|
|
450
|
+
}
|
|
451
|
+
inlined.set(name, true);
|
|
452
|
+
return attr;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
if (name === "theme") {
|
|
457
|
+
inlined.set("theme", attr.value);
|
|
458
|
+
return attr;
|
|
459
|
+
}
|
|
460
|
+
const styleValue = attemptEvalSafe(value);
|
|
461
|
+
if (!variants[name] && !isValidStyleKey(name, staticConfig)) {
|
|
462
|
+
let keys = [name];
|
|
463
|
+
let out = null;
|
|
464
|
+
out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, { resolveVariablesAs: "auto" }, void 0, void 0, shouldPrintDebug);
|
|
465
|
+
if (out) {
|
|
466
|
+
if (!Array.isArray(out)) {
|
|
467
|
+
console.warn(`Error expected array but got`, out);
|
|
468
|
+
couldntParse = true;
|
|
469
|
+
shouldDeopt = true;
|
|
470
|
+
} else {
|
|
471
|
+
out = Object.fromEntries(out);
|
|
472
|
+
keys = Object.keys(out);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
if (out) {
|
|
476
|
+
if (isTargetingHTML) {
|
|
477
|
+
out = (0, import_core_node.createDOMProps)(isTextView ? "span" : "div", out);
|
|
478
|
+
delete out.className;
|
|
479
|
+
}
|
|
480
|
+
keys = Object.keys(out);
|
|
481
|
+
}
|
|
482
|
+
let didInline = false;
|
|
483
|
+
const attributes = keys.map((key) => {
|
|
484
|
+
const val = out[key];
|
|
485
|
+
if (isValidStyleKey(key, staticConfig)) {
|
|
486
|
+
return {
|
|
487
|
+
type: "style",
|
|
488
|
+
value: { [key]: styleValue },
|
|
489
|
+
name: key,
|
|
490
|
+
attr: path.node
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
if (import_validHTMLAttributes.validHTMLAttributes[key] || key.startsWith("aria-") || key.startsWith("data-")) {
|
|
494
|
+
return attr;
|
|
495
|
+
}
|
|
496
|
+
if (shouldPrintDebug) {
|
|
497
|
+
console.log(" ! inlining, non-static", key);
|
|
498
|
+
}
|
|
499
|
+
didInline = true;
|
|
500
|
+
inlined.set(key, val);
|
|
501
|
+
return val;
|
|
502
|
+
});
|
|
503
|
+
if (didInline) {
|
|
504
|
+
if (shouldPrintDebug) {
|
|
505
|
+
console.log(" bailing flattening due to attributes", attributes);
|
|
506
|
+
}
|
|
507
|
+
return attr;
|
|
508
|
+
}
|
|
509
|
+
return attributes;
|
|
510
|
+
}
|
|
511
|
+
if (styleValue !== import_constants.FAILED_EVAL) {
|
|
512
|
+
if (inlineWhenUnflattened.has(name)) {
|
|
513
|
+
inlineWhenUnflattenedOGVals[name] = { styleValue, attr };
|
|
514
|
+
}
|
|
515
|
+
if (isValidStyleKey(name, staticConfig)) {
|
|
516
|
+
if (shouldPrintDebug) {
|
|
517
|
+
console.log(` style: ${name} =`, styleValue);
|
|
518
|
+
}
|
|
519
|
+
if (!(name in staticConfig.defaultProps)) {
|
|
520
|
+
if (!hasSetOptimized) {
|
|
521
|
+
res.optimized++;
|
|
522
|
+
hasSetOptimized = true;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
return {
|
|
526
|
+
type: "style",
|
|
527
|
+
value: { [name]: styleValue },
|
|
528
|
+
name,
|
|
529
|
+
attr: path.node
|
|
530
|
+
};
|
|
531
|
+
} else {
|
|
532
|
+
if (variants[name]) {
|
|
533
|
+
variantValues.set(name, styleValue);
|
|
534
|
+
}
|
|
535
|
+
inlined.set(name, true);
|
|
536
|
+
return attr;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
if (t.isBinaryExpression(value)) {
|
|
540
|
+
if (shouldPrintDebug) {
|
|
541
|
+
console.log(` binary expression ${name} = `, value);
|
|
542
|
+
}
|
|
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 !== import_constants.FAILED_EVAL && t.isConditionalExpression(right)) {
|
|
550
|
+
const ternary = addBinaryConditional(operator, left, right);
|
|
551
|
+
if (ternary)
|
|
552
|
+
return ternary;
|
|
553
|
+
}
|
|
554
|
+
if (rVal !== import_constants.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
|
+
inlined.set(name, true);
|
|
563
|
+
return attr;
|
|
564
|
+
}
|
|
565
|
+
const staticConditional = getStaticConditional(value);
|
|
566
|
+
if (staticConditional) {
|
|
567
|
+
if (shouldPrintDebug === "verbose") {
|
|
568
|
+
console.log(` static conditional ${name}`, value);
|
|
569
|
+
}
|
|
570
|
+
return { type: "ternary", value: staticConditional };
|
|
571
|
+
}
|
|
572
|
+
const staticLogical = getStaticLogical(value);
|
|
573
|
+
if (staticLogical) {
|
|
574
|
+
if (shouldPrintDebug === "verbose") {
|
|
575
|
+
console.log(` static ternary ${name} = `, value);
|
|
576
|
+
}
|
|
577
|
+
return { type: "ternary", value: staticLogical };
|
|
578
|
+
}
|
|
579
|
+
inlined.set(name, true);
|
|
580
|
+
if (shouldPrintDebug) {
|
|
581
|
+
console.log(` ! inline no match ${name}`, value);
|
|
582
|
+
}
|
|
583
|
+
return attr;
|
|
584
|
+
function addBinaryConditional(operator, staticExpr, cond) {
|
|
585
|
+
if (getStaticConditional(cond)) {
|
|
586
|
+
const alt = attemptEval(t.binaryExpression(operator, staticExpr, cond.alternate));
|
|
587
|
+
const cons = attemptEval(t.binaryExpression(operator, staticExpr, cond.consequent));
|
|
588
|
+
if (shouldPrintDebug) {
|
|
589
|
+
console.log(" binaryConditional", cond.test, cons, alt);
|
|
590
|
+
}
|
|
591
|
+
return {
|
|
592
|
+
type: "ternary",
|
|
593
|
+
value: {
|
|
594
|
+
test: cond.test,
|
|
595
|
+
remove,
|
|
596
|
+
alternate: { [name]: alt },
|
|
597
|
+
consequent: { [name]: cons }
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
return null;
|
|
602
|
+
}
|
|
603
|
+
function getStaticConditional(value2) {
|
|
604
|
+
if (t.isConditionalExpression(value2)) {
|
|
605
|
+
try {
|
|
606
|
+
const aVal = attemptEval(value2.alternate);
|
|
607
|
+
const cVal = attemptEval(value2.consequent);
|
|
608
|
+
if (shouldPrintDebug) {
|
|
609
|
+
const type = value2.test.type;
|
|
610
|
+
console.log(" static ternary", type, cVal, aVal);
|
|
611
|
+
}
|
|
612
|
+
return {
|
|
613
|
+
test: value2.test,
|
|
614
|
+
remove,
|
|
615
|
+
consequent: { [name]: cVal },
|
|
616
|
+
alternate: { [name]: aVal }
|
|
617
|
+
};
|
|
618
|
+
} catch (err) {
|
|
619
|
+
if (shouldPrintDebug) {
|
|
620
|
+
console.log(" cant eval ternary", err.message);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
return null;
|
|
625
|
+
}
|
|
626
|
+
function getStaticLogical(value2) {
|
|
627
|
+
if (t.isLogicalExpression(value2)) {
|
|
628
|
+
if (value2.operator === "&&") {
|
|
629
|
+
try {
|
|
630
|
+
const val = attemptEval(value2.right);
|
|
631
|
+
if (shouldPrintDebug) {
|
|
632
|
+
console.log(" staticLogical", value2.left, name, val);
|
|
633
|
+
}
|
|
634
|
+
return {
|
|
635
|
+
test: value2.left,
|
|
636
|
+
remove,
|
|
637
|
+
consequent: { [name]: val },
|
|
638
|
+
alternate: null
|
|
639
|
+
};
|
|
640
|
+
} catch (err) {
|
|
641
|
+
if (shouldPrintDebug) {
|
|
642
|
+
console.log(" cant static eval logical", err);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
return null;
|
|
648
|
+
}
|
|
649
|
+
}, isExtractable2 = function(obj) {
|
|
650
|
+
return t.isObjectExpression(obj) && obj.properties.every((prop) => {
|
|
651
|
+
if (!t.isObjectProperty(prop)) {
|
|
652
|
+
console.log("not object prop", prop);
|
|
653
|
+
return false;
|
|
654
|
+
}
|
|
655
|
+
const propName = prop.key["name"];
|
|
656
|
+
if (!isValidStyleKey(propName, staticConfig) && propName !== "tag") {
|
|
657
|
+
if (shouldPrintDebug) {
|
|
658
|
+
console.log(" not a valid style prop!", propName);
|
|
659
|
+
}
|
|
660
|
+
return false;
|
|
661
|
+
}
|
|
662
|
+
return true;
|
|
663
|
+
});
|
|
664
|
+
}, createTernariesFromObjectProperties2 = function(test, side, ternaryPartial = {}) {
|
|
665
|
+
if (!side) {
|
|
666
|
+
return null;
|
|
667
|
+
}
|
|
668
|
+
if (!isExtractable2(side)) {
|
|
669
|
+
throw new Error("not extractable");
|
|
670
|
+
}
|
|
671
|
+
return side.properties.flatMap((property) => {
|
|
672
|
+
if (!t.isObjectProperty(property)) {
|
|
673
|
+
throw new Error("expected object property");
|
|
674
|
+
}
|
|
675
|
+
if (t.isIdentifier(property.key)) {
|
|
676
|
+
const key = property.key.name;
|
|
677
|
+
const mediaQueryKey = key.slice(1);
|
|
678
|
+
const isMediaQuery = key[0] === "$" && import_core_node.mediaQueryConfig[mediaQueryKey];
|
|
679
|
+
if (isMediaQuery) {
|
|
680
|
+
if (t.isExpression(property.value)) {
|
|
681
|
+
const ternaries2 = createTernariesFromObjectProperties2(t.stringLiteral(mediaQueryKey), property.value, {
|
|
682
|
+
inlineMediaQuery: mediaQueryKey
|
|
683
|
+
});
|
|
684
|
+
if (ternaries2) {
|
|
685
|
+
return ternaries2.map((value) => ({
|
|
686
|
+
...ternaryPartial,
|
|
687
|
+
...value,
|
|
688
|
+
test: t.logicalExpression("&&", value.test, test)
|
|
689
|
+
}));
|
|
690
|
+
} else {
|
|
691
|
+
console.log("\u26A0\uFE0F no ternaries?", property);
|
|
692
|
+
}
|
|
693
|
+
} else {
|
|
694
|
+
console.log("\u26A0\uFE0F not expression", property);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
if (t.isConditionalExpression(property.value)) {
|
|
699
|
+
const [truthy, falsy] = [
|
|
700
|
+
t.objectExpression([t.objectProperty(property.key, property.value.consequent)]),
|
|
701
|
+
t.objectExpression([t.objectProperty(property.key, property.value.alternate)])
|
|
702
|
+
].map((x) => attemptEval(x));
|
|
703
|
+
return [
|
|
704
|
+
createTernary({
|
|
705
|
+
remove() {
|
|
706
|
+
},
|
|
707
|
+
...ternaryPartial,
|
|
708
|
+
test: t.logicalExpression("&&", test, property.value.test),
|
|
709
|
+
consequent: truthy,
|
|
710
|
+
alternate: null
|
|
711
|
+
}),
|
|
712
|
+
createTernary({
|
|
713
|
+
...ternaryPartial,
|
|
714
|
+
test: t.logicalExpression("&&", test, t.unaryExpression("!", property.value.test)),
|
|
715
|
+
consequent: falsy,
|
|
716
|
+
alternate: null,
|
|
717
|
+
remove() {
|
|
718
|
+
}
|
|
719
|
+
})
|
|
720
|
+
];
|
|
721
|
+
}
|
|
722
|
+
const obj = t.objectExpression([t.objectProperty(property.key, property.value)]);
|
|
723
|
+
const consequent = attemptEval(obj);
|
|
724
|
+
return createTernary({
|
|
725
|
+
remove() {
|
|
726
|
+
},
|
|
727
|
+
...ternaryPartial,
|
|
728
|
+
test,
|
|
729
|
+
consequent,
|
|
730
|
+
alternate: null
|
|
731
|
+
});
|
|
732
|
+
});
|
|
733
|
+
}, mergeStyles2 = function(prev2, nextIn) {
|
|
734
|
+
const next = (0, import_core_node.expandStyles)(nextIn);
|
|
735
|
+
for (const key in next) {
|
|
736
|
+
if (import_core_node.pseudoDescriptors[key]) {
|
|
737
|
+
prev2[key] = prev2[key] || {};
|
|
738
|
+
if (shouldPrintDebug) {
|
|
739
|
+
if (!next[key] || !prev2[key]) {
|
|
740
|
+
console.log("warn: missing", key, prev2, next);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
Object.assign(prev2[key], next[key]);
|
|
744
|
+
} else {
|
|
745
|
+
prev2[key] = next[key];
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
var evaluateAttribute = evaluateAttribute2, isExtractable = isExtractable2, createTernariesFromObjectProperties = createTernariesFromObjectProperties2, mergeStyles = mergeStyles2;
|
|
750
|
+
node.attributes.find((n) => t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && n.name.name === "debug" && n.value === null);
|
|
751
|
+
if (shouldPrintDebug) {
|
|
752
|
+
console.log("\n");
|
|
753
|
+
console.log("\x1B[33m%s\x1B[0m", `${tagId[0]} | ${tagId[2]} -------------------`);
|
|
754
|
+
console.log("\x1B[1m", "\x1B[32m", `<${originalNodeName} />`);
|
|
755
|
+
}
|
|
756
|
+
if (shouldAddDebugProp && !disableDebugAttr) {
|
|
757
|
+
res.modified++;
|
|
758
|
+
node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(tagId.join(" "))));
|
|
759
|
+
}
|
|
760
|
+
const shouldLog = !hasLogged;
|
|
761
|
+
if (shouldLog) {
|
|
762
|
+
console.log(` 1\uFE0F\u20E3 Inline optimized 2\uFE0F\u20E3 Inline flattened 3\uFE0F\u20E3 styled() extracted`);
|
|
763
|
+
const prefix = " |";
|
|
764
|
+
console.log(prefixLogs || prefix, " total \xB7 1\uFE0F\u20E3 \xB7 2\uFE0F\u20E3 \xB7 3\uFE0F\u20E3");
|
|
765
|
+
hasLogged = true;
|
|
766
|
+
}
|
|
767
|
+
if (disableExtraction) {
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
const { staticConfig } = component;
|
|
771
|
+
const variants = staticConfig.variants || {};
|
|
772
|
+
const isTextView = staticConfig.isText || false;
|
|
773
|
+
const validStyles = (staticConfig == null ? void 0 : staticConfig.validStyles) ?? {};
|
|
774
|
+
let tagName = staticConfig.defaultProps.tag ?? (isTextView ? "span" : "div");
|
|
775
|
+
traversePath.get("openingElement").get("attributes").forEach((path) => {
|
|
776
|
+
const attr = path.node;
|
|
777
|
+
if (t.isJSXSpreadAttribute(attr))
|
|
778
|
+
return;
|
|
779
|
+
if (attr.name.name !== "tag")
|
|
780
|
+
return;
|
|
781
|
+
const val = attr.value;
|
|
782
|
+
if (!t.isStringLiteral(val))
|
|
783
|
+
return;
|
|
784
|
+
tagName = val.value;
|
|
785
|
+
});
|
|
786
|
+
const flatNode = getFlattenedNode({ isTextView, tag: tagName });
|
|
787
|
+
const inlineProps = /* @__PURE__ */ new Set([
|
|
788
|
+
...props.inlineProps || [],
|
|
789
|
+
...staticConfig.inlineProps || []
|
|
790
|
+
]);
|
|
791
|
+
const deoptProps = /* @__PURE__ */ new Set([
|
|
792
|
+
"animation",
|
|
793
|
+
...props.deoptProps || [],
|
|
794
|
+
...staticConfig.deoptProps || []
|
|
795
|
+
]);
|
|
796
|
+
const inlineWhenUnflattened = /* @__PURE__ */ new Set([...staticConfig.inlineWhenUnflattened || []]);
|
|
797
|
+
const staticNamespace = (0, import_getStaticBindingsForScope.getStaticBindingsForScope)(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
|
|
798
|
+
const attemptEval = !evaluateVars ? import_evaluateAstNode.evaluateAstNode : (0, import_createEvaluator.createEvaluator)({
|
|
799
|
+
tamaguiConfig,
|
|
800
|
+
staticNamespace,
|
|
801
|
+
sourcePath,
|
|
802
|
+
traversePath,
|
|
803
|
+
shouldPrintDebug
|
|
804
|
+
});
|
|
805
|
+
const attemptEvalSafe = (0, import_createEvaluator.createSafeEvaluator)(attemptEval);
|
|
806
|
+
if (shouldPrintDebug) {
|
|
807
|
+
console.log(" staticNamespace", Object.keys(staticNamespace).join(", "));
|
|
808
|
+
}
|
|
809
|
+
const flattenedAttrs = [];
|
|
810
|
+
traversePath.get("openingElement").get("attributes").forEach((path) => {
|
|
811
|
+
const attr = path.node;
|
|
812
|
+
if (!t.isJSXSpreadAttribute(attr)) {
|
|
813
|
+
flattenedAttrs.push(attr);
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
let arg;
|
|
817
|
+
try {
|
|
818
|
+
arg = attemptEval(attr.argument);
|
|
819
|
+
} catch (e) {
|
|
820
|
+
if (shouldPrintDebug) {
|
|
821
|
+
console.log(" couldnt parse spread", e.message);
|
|
822
|
+
}
|
|
823
|
+
flattenedAttrs.push(attr);
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
if (arg !== void 0) {
|
|
827
|
+
try {
|
|
828
|
+
if (typeof arg !== "object" || arg == null) {
|
|
829
|
+
if (shouldPrintDebug) {
|
|
830
|
+
console.log(" non object or null arg", arg);
|
|
831
|
+
}
|
|
832
|
+
flattenedAttrs.push(attr);
|
|
833
|
+
} else {
|
|
834
|
+
for (const k in arg) {
|
|
835
|
+
const value = arg[k];
|
|
836
|
+
if (!value && typeof value === "object") {
|
|
837
|
+
console.log("shouldnt we handle this?", k, value, arg);
|
|
838
|
+
continue;
|
|
839
|
+
}
|
|
840
|
+
flattenedAttrs.push(t.jsxAttribute(t.jsxIdentifier(k), t.jsxExpressionContainer((0, import_literalToAst.literalToAst)(value))));
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
} catch (err) {
|
|
844
|
+
console.warn("cant parse spread, caught err", err);
|
|
845
|
+
couldntParse = true;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
});
|
|
849
|
+
if (couldntParse) {
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
tm.mark("jsx-element-flattened", shouldPrintDebug === "verbose");
|
|
853
|
+
node.attributes = flattenedAttrs;
|
|
854
|
+
let attrs = [];
|
|
855
|
+
let shouldDeopt = false;
|
|
856
|
+
const inlined = /* @__PURE__ */ new Map();
|
|
857
|
+
const variantValues = /* @__PURE__ */ new Map();
|
|
858
|
+
let hasSetOptimized = false;
|
|
859
|
+
const inlineWhenUnflattenedOGVals = {};
|
|
860
|
+
attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
|
|
861
|
+
try {
|
|
862
|
+
const res2 = evaluateAttribute2(path);
|
|
863
|
+
tm.mark("jsx-element-evaluate-attr", shouldPrintDebug === "verbose");
|
|
864
|
+
if (!res2) {
|
|
865
|
+
path.remove();
|
|
866
|
+
}
|
|
867
|
+
return res2;
|
|
868
|
+
} catch (err) {
|
|
869
|
+
if (shouldPrintDebug) {
|
|
870
|
+
console.log("Error extracting attribute", err.message, err.stack);
|
|
871
|
+
console.log("node", path.node);
|
|
872
|
+
}
|
|
873
|
+
inlined.set(`${Math.random()}`, "spread");
|
|
874
|
+
return {
|
|
875
|
+
type: "attr",
|
|
876
|
+
value: path.node
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
}).flat(4).filter(import_extractHelpers.isPresent);
|
|
880
|
+
if (shouldPrintDebug) {
|
|
881
|
+
console.log(" - attrs (before):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
882
|
+
}
|
|
883
|
+
node.attributes = attrs.filter(isAttr).map((x) => x.value);
|
|
884
|
+
if (couldntParse || shouldDeopt) {
|
|
885
|
+
if (shouldPrintDebug) {
|
|
886
|
+
console.log(` avoid optimizing:`, { couldntParse, shouldDeopt });
|
|
887
|
+
}
|
|
888
|
+
node.attributes = ogAttributes;
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
const parentFn = (0, import_findTopmostFunction.findTopmostFunction)(traversePath);
|
|
892
|
+
if (parentFn) {
|
|
893
|
+
modifiedComponents.add(parentFn);
|
|
894
|
+
}
|
|
895
|
+
let ternaries = [];
|
|
896
|
+
attrs = attrs.reduce((out, cur) => {
|
|
897
|
+
const next = attrs[attrs.indexOf(cur) + 1];
|
|
898
|
+
if (cur.type === "ternary") {
|
|
899
|
+
ternaries.push(cur.value);
|
|
900
|
+
}
|
|
901
|
+
if ((!next || next.type !== "ternary") && ternaries.length) {
|
|
902
|
+
const normalized = (0, import_normalizeTernaries.normalizeTernaries)(ternaries).map(({ alternate, consequent, ...rest }) => {
|
|
903
|
+
return {
|
|
904
|
+
type: "ternary",
|
|
905
|
+
value: {
|
|
906
|
+
...rest,
|
|
907
|
+
alternate: alternate || null,
|
|
908
|
+
consequent: consequent || null
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
});
|
|
912
|
+
try {
|
|
913
|
+
return [...out, ...normalized];
|
|
914
|
+
} finally {
|
|
915
|
+
if (shouldPrintDebug) {
|
|
916
|
+
console.log(` normalizeTernaries (${ternaries.length} => ${normalized.length})`);
|
|
917
|
+
}
|
|
918
|
+
ternaries = [];
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
if (cur.type === "ternary") {
|
|
922
|
+
return out;
|
|
923
|
+
}
|
|
924
|
+
out.push(cur);
|
|
925
|
+
return out;
|
|
926
|
+
}, []).flat();
|
|
927
|
+
const hasSpread = node.attributes.some((x) => t.isJSXSpreadAttribute(x));
|
|
928
|
+
const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
|
|
929
|
+
const themeVal = inlined.get("theme");
|
|
930
|
+
inlined.delete("theme");
|
|
931
|
+
for (const [key] of [...inlined]) {
|
|
932
|
+
if (INLINE_EXTRACTABLE[key] || ((_a = staticConfig.variants) == null ? void 0 : _a[key])) {
|
|
933
|
+
inlined.delete(key);
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
const canFlattenProps = inlined.size === 0;
|
|
937
|
+
let shouldFlatten = !shouldDeopt && canFlattenProps && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
|
|
938
|
+
const shouldWrapTheme = shouldFlatten && themeVal;
|
|
939
|
+
if (disableExtractVariables) {
|
|
940
|
+
themeAccessListeners.add((key) => {
|
|
941
|
+
shouldFlatten = false;
|
|
942
|
+
if (shouldPrintDebug) {
|
|
943
|
+
console.log(" ! accessing theme key, avoid flatten", key);
|
|
944
|
+
}
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
if (shouldPrintDebug) {
|
|
948
|
+
console.log(" - flatten?", (0, import_extractHelpers.objToStr)({ hasSpread, shouldDeopt, shouldFlatten, canFlattenProps, shouldWrapTheme, hasOnlyStringChildren }), "inlined", [...inlined]);
|
|
949
|
+
}
|
|
950
|
+
if (shouldFlatten && shouldWrapTheme) {
|
|
951
|
+
if (shouldPrintDebug) {
|
|
952
|
+
console.log(" - wrapping theme", themeVal);
|
|
953
|
+
}
|
|
954
|
+
attrs = attrs.filter((x) => x.type === "attr" && t.isJSXAttribute(x.value) && x.value.name.name === "theme" ? false : true);
|
|
955
|
+
if (!hasImportedTheme) {
|
|
956
|
+
hasImportedTheme = true;
|
|
957
|
+
programPath.node.body.push(t.importDeclaration([t.importSpecifier(t.identifier("_TamaguiTheme"), t.identifier("Theme"))], t.stringLiteral("@tamagui/core")));
|
|
958
|
+
}
|
|
959
|
+
traversePath.replaceWith(t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier("_TamaguiTheme"), [
|
|
960
|
+
t.jsxAttribute(t.jsxIdentifier("name"), themeVal.value)
|
|
961
|
+
]), t.jsxClosingElement(t.jsxIdentifier("_TamaguiTheme")), [traversePath.node]));
|
|
962
|
+
}
|
|
963
|
+
if (shouldFlatten) {
|
|
964
|
+
const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap((key) => {
|
|
965
|
+
if (!isValidStyleKey(key, staticConfig)) {
|
|
966
|
+
return [];
|
|
967
|
+
}
|
|
968
|
+
const value = staticConfig.defaultProps[key];
|
|
969
|
+
const name = tamaguiConfig.shorthands[key] || key;
|
|
970
|
+
if (value === void 0) {
|
|
971
|
+
console.warn(`\u26A0\uFE0F Error evaluating default style for component, prop ${key} ${value}`);
|
|
972
|
+
shouldDeopt = true;
|
|
973
|
+
return;
|
|
974
|
+
}
|
|
975
|
+
const attr = {
|
|
976
|
+
type: "style",
|
|
977
|
+
name,
|
|
978
|
+
value: { [name]: value }
|
|
979
|
+
};
|
|
980
|
+
return attr;
|
|
981
|
+
});
|
|
982
|
+
if (defaultStyleAttrs.length) {
|
|
983
|
+
attrs = [...defaultStyleAttrs, ...attrs];
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
if (shouldDeopt) {
|
|
987
|
+
node.attributes = ogAttributes;
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
const ensureOverridden = {};
|
|
991
|
+
if (!shouldFlatten) {
|
|
992
|
+
for (const cur of attrs) {
|
|
993
|
+
if (cur.type === "style") {
|
|
994
|
+
for (const key in cur.value) {
|
|
995
|
+
const shouldEnsureOverridden = !!((_b = staticConfig.ensureOverriddenProp) == null ? void 0 : _b[key]);
|
|
996
|
+
const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
|
|
997
|
+
if (!isSetInAttrsAlready) {
|
|
998
|
+
const isVariant = !!((_c = staticConfig.variants) == null ? void 0 : _c[cur.name || ""]);
|
|
999
|
+
if (isVariant || shouldEnsureOverridden) {
|
|
1000
|
+
ensureOverridden[key] = true;
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
if (shouldPrintDebug) {
|
|
1008
|
+
console.log(" - attrs (flattened): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
1009
|
+
console.log(" - ensureOverriden:", Object.keys(ensureOverridden).join(", "));
|
|
1010
|
+
}
|
|
1011
|
+
const state = {
|
|
1012
|
+
noClassNames: false,
|
|
1013
|
+
focus: false,
|
|
1014
|
+
hover: false,
|
|
1015
|
+
mounted: true,
|
|
1016
|
+
press: false,
|
|
1017
|
+
pressIn: false
|
|
1018
|
+
};
|
|
1019
|
+
let foundStaticProps = {};
|
|
1020
|
+
for (const key in attrs) {
|
|
1021
|
+
const cur = attrs[key];
|
|
1022
|
+
if (cur.type === "style") {
|
|
1023
|
+
foundStaticProps = {
|
|
1024
|
+
...foundStaticProps,
|
|
1025
|
+
...(0, import_core_node.expandStyles)(cur.value)
|
|
1026
|
+
};
|
|
1027
|
+
continue;
|
|
1028
|
+
}
|
|
1029
|
+
if (cur.type === "attr") {
|
|
1030
|
+
if (t.isJSXSpreadAttribute(cur.value)) {
|
|
1031
|
+
continue;
|
|
1032
|
+
}
|
|
1033
|
+
if (!t.isJSXIdentifier(cur.value.name)) {
|
|
1034
|
+
continue;
|
|
1035
|
+
}
|
|
1036
|
+
const key2 = cur.value.name.name;
|
|
1037
|
+
const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
|
|
1038
|
+
if (value !== import_constants.FAILED_EVAL) {
|
|
1039
|
+
foundStaticProps = {
|
|
1040
|
+
...foundStaticProps,
|
|
1041
|
+
[key2]: value
|
|
1042
|
+
};
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
const completeProps = {};
|
|
1047
|
+
for (const key in staticConfig.defaultProps) {
|
|
1048
|
+
if (!(key in foundStaticProps)) {
|
|
1049
|
+
completeProps[key] = staticConfig.defaultProps[key];
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
for (const key in foundStaticProps) {
|
|
1053
|
+
completeProps[key] = foundStaticProps[key];
|
|
1054
|
+
}
|
|
1055
|
+
attrs = attrs.reduce((acc, cur) => {
|
|
1056
|
+
if (!cur)
|
|
1057
|
+
return acc;
|
|
1058
|
+
if (cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value)) {
|
|
1059
|
+
if (shouldFlatten) {
|
|
1060
|
+
const name = cur.value.name.name;
|
|
1061
|
+
if (typeof name === "string") {
|
|
1062
|
+
if (name === "tag") {
|
|
1063
|
+
return acc;
|
|
1064
|
+
}
|
|
1065
|
+
if (variants[name] && variantValues.has(name)) {
|
|
1066
|
+
let out = Object.fromEntries(staticConfig.propMapper(name, variantValues.get(name), defaultTheme, completeProps, { ...state, resolveVariablesAs: "auto" }, void 0, void 0, shouldPrintDebug) || []);
|
|
1067
|
+
if (out && isTargetingHTML) {
|
|
1068
|
+
const cn = out.className;
|
|
1069
|
+
out = (0, import_core_node.createDOMProps)(isTextView ? "span" : "div", out);
|
|
1070
|
+
out.className = cn;
|
|
1071
|
+
}
|
|
1072
|
+
if (shouldPrintDebug) {
|
|
1073
|
+
console.log(" - expanded variant", name, out);
|
|
1074
|
+
}
|
|
1075
|
+
for (const key2 in out) {
|
|
1076
|
+
const value2 = out[key2];
|
|
1077
|
+
if (isValidStyleKey(key2, staticConfig)) {
|
|
1078
|
+
acc.push({
|
|
1079
|
+
type: "style",
|
|
1080
|
+
value: { [key2]: value2 },
|
|
1081
|
+
name: key2,
|
|
1082
|
+
attr: cur.value
|
|
1083
|
+
});
|
|
1084
|
+
} else {
|
|
1085
|
+
acc.push({
|
|
1086
|
+
type: "attr",
|
|
1087
|
+
value: t.jsxAttribute(t.jsxIdentifier(key2), t.jsxExpressionContainer(typeof value2 === "string" ? t.stringLiteral(value2) : (0, import_literalToAst.literalToAst)(value2)))
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
if (cur.type !== "style") {
|
|
1096
|
+
acc.push(cur);
|
|
1097
|
+
return acc;
|
|
1098
|
+
}
|
|
1099
|
+
let key = Object.keys(cur.value)[0];
|
|
1100
|
+
const value = cur.value[key];
|
|
1101
|
+
const fullKey = tamaguiConfig.shorthands[key];
|
|
1102
|
+
if (fullKey) {
|
|
1103
|
+
cur.value = { [fullKey]: value };
|
|
1104
|
+
key = fullKey;
|
|
1105
|
+
}
|
|
1106
|
+
if (disableExtractVariables) {
|
|
1107
|
+
if (value[0] === "$") {
|
|
1108
|
+
if (shouldPrintDebug) {
|
|
1109
|
+
console.log(` keeping variable inline: ${key} =`, value);
|
|
1110
|
+
}
|
|
1111
|
+
acc.push({
|
|
1112
|
+
type: "attr",
|
|
1113
|
+
value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.stringLiteral(value)))
|
|
1114
|
+
});
|
|
1115
|
+
return acc;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
acc.push(cur);
|
|
1119
|
+
return acc;
|
|
1120
|
+
}, []);
|
|
1121
|
+
tm.mark("jsx-element-expanded", shouldPrintDebug === "verbose");
|
|
1122
|
+
if (shouldPrintDebug) {
|
|
1123
|
+
console.log(" - attrs (expanded): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
1124
|
+
}
|
|
1125
|
+
let prev = null;
|
|
1126
|
+
attrs = attrs.reduce((acc, cur) => {
|
|
1127
|
+
if (cur.type === "style") {
|
|
1128
|
+
const key = Object.keys(cur.value)[0];
|
|
1129
|
+
const value = cur.value[key];
|
|
1130
|
+
const shouldKeepOriginalAttr = !shouldFlatten && !validStyles[key] && !import_core_node.pseudoDescriptors[key] && !key.startsWith("data-");
|
|
1131
|
+
if (shouldKeepOriginalAttr) {
|
|
1132
|
+
if (shouldPrintDebug) {
|
|
1133
|
+
console.log(" - keeping as non-style", key);
|
|
1134
|
+
}
|
|
1135
|
+
prev = cur;
|
|
1136
|
+
acc.push({
|
|
1137
|
+
type: "attr",
|
|
1138
|
+
value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(typeof value === "string" ? t.stringLiteral(value) : (0, import_literalToAst.literalToAst)(value)))
|
|
1139
|
+
});
|
|
1140
|
+
acc.push(cur);
|
|
1141
|
+
return acc;
|
|
1142
|
+
}
|
|
1143
|
+
if (ensureOverridden[key]) {
|
|
1144
|
+
acc.push({
|
|
1145
|
+
type: "attr",
|
|
1146
|
+
value: cur.attr || t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.nullLiteral()))
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1149
|
+
if ((prev == null ? void 0 : prev.type) === "style") {
|
|
1150
|
+
mergeStyles2(prev.value, cur.value);
|
|
1151
|
+
return acc;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
prev = cur;
|
|
1155
|
+
acc.push(cur);
|
|
1156
|
+
return acc;
|
|
1157
|
+
}, []);
|
|
1158
|
+
if (shouldPrintDebug) {
|
|
1159
|
+
console.log(" - attrs (combined \u{1F500}): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
1160
|
+
console.log(" - defaultProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(staticConfig.defaultProps)));
|
|
1161
|
+
console.log(" - foundStaticProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(foundStaticProps)));
|
|
1162
|
+
console.log(" - completeProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(completeProps)));
|
|
1163
|
+
}
|
|
1164
|
+
const getStyles = (props2, debugName = "") => {
|
|
1165
|
+
if (!props2 || !Object.keys(props2).length) {
|
|
1166
|
+
if (shouldPrintDebug)
|
|
1167
|
+
console.log(" getStyles() no props");
|
|
1168
|
+
return {};
|
|
1169
|
+
}
|
|
1170
|
+
if (excludeProps && !!excludeProps.size) {
|
|
1171
|
+
for (const key in props2) {
|
|
1172
|
+
if (excludeProps.has(key)) {
|
|
1173
|
+
if (shouldPrintDebug)
|
|
1174
|
+
console.log(" delete excluded", key);
|
|
1175
|
+
delete props2[key];
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
try {
|
|
1180
|
+
const out = (0, import_core_node.getSplitStyles)(props2, staticConfig, defaultTheme, {
|
|
1181
|
+
...state,
|
|
1182
|
+
fallbackProps: completeProps
|
|
1183
|
+
}, void 0, props2["debug"]);
|
|
1184
|
+
const outStyle = {
|
|
1185
|
+
...out.style,
|
|
1186
|
+
...out.pseudos
|
|
1187
|
+
};
|
|
1188
|
+
return outStyle;
|
|
1189
|
+
} catch (err) {
|
|
1190
|
+
console.log("error", err.message, err.stack);
|
|
1191
|
+
return {};
|
|
1192
|
+
}
|
|
1193
|
+
};
|
|
1194
|
+
const completeStyles = getStyles(completeProps, "completeStyles");
|
|
1195
|
+
if (!completeStyles) {
|
|
1196
|
+
throw new Error(`Impossible, no styles`);
|
|
1197
|
+
}
|
|
1198
|
+
let getStyleError = null;
|
|
1199
|
+
for (const attr of attrs) {
|
|
1200
|
+
try {
|
|
1201
|
+
switch (attr.type) {
|
|
1202
|
+
case "ternary":
|
|
1203
|
+
const a = getStyles(attr.value.alternate, "ternary.alternate");
|
|
1204
|
+
const c = getStyles(attr.value.consequent, "ternary.consequent");
|
|
1205
|
+
if (a)
|
|
1206
|
+
attr.value.alternate = a;
|
|
1207
|
+
if (c)
|
|
1208
|
+
attr.value.consequent = c;
|
|
1209
|
+
if (shouldPrintDebug)
|
|
1210
|
+
console.log(" => tern ", (0, import_extractHelpers.attrStr)(attr));
|
|
1211
|
+
continue;
|
|
1212
|
+
case "style":
|
|
1213
|
+
const styles = getStyles(attr.value, "style");
|
|
1214
|
+
if (styles) {
|
|
1215
|
+
attr.value = styles;
|
|
1216
|
+
}
|
|
1217
|
+
if (shouldPrintDebug)
|
|
1218
|
+
console.log(" * styles (in)", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(attr.value)));
|
|
1219
|
+
if (shouldPrintDebug)
|
|
1220
|
+
console.log(" * styles (out)", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(styles)));
|
|
1221
|
+
continue;
|
|
1222
|
+
}
|
|
1223
|
+
} catch (err) {
|
|
1224
|
+
getStyleError = err;
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
if (shouldPrintDebug) {
|
|
1228
|
+
console.log(" - attrs (ternaries/combined):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
1229
|
+
}
|
|
1230
|
+
tm.mark("jsx-element-styles", shouldPrintDebug === "verbose");
|
|
1231
|
+
if (getStyleError) {
|
|
1232
|
+
console.log(" \u26A0\uFE0F postprocessing error, deopt", getStyleError);
|
|
1233
|
+
node.attributes = ogAttributes;
|
|
1234
|
+
return node;
|
|
1235
|
+
}
|
|
1236
|
+
const existingStyleKeys = /* @__PURE__ */ new Set();
|
|
1237
|
+
for (let i = attrs.length - 1; i >= 0; i--) {
|
|
1238
|
+
const attr = attrs[i];
|
|
1239
|
+
if (shouldFlatten) {
|
|
1240
|
+
if (attr.type === "attr") {
|
|
1241
|
+
if (t.isJSXAttribute(attr.value)) {
|
|
1242
|
+
if (t.isJSXIdentifier(attr.value.name)) {
|
|
1243
|
+
const name = attr.value.name.name;
|
|
1244
|
+
if (INLINE_EXTRACTABLE[name]) {
|
|
1245
|
+
attr.value.name.name = INLINE_EXTRACTABLE[name];
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
if (attr.type === "style") {
|
|
1252
|
+
for (const key in attr.value) {
|
|
1253
|
+
if (existingStyleKeys.has(key)) {
|
|
1254
|
+
if (shouldPrintDebug) {
|
|
1255
|
+
console.log(" >> delete existing", key);
|
|
1256
|
+
}
|
|
1257
|
+
delete attr.value[key];
|
|
1258
|
+
} else {
|
|
1259
|
+
existingStyleKeys.add(key);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
if (!shouldFlatten) {
|
|
1265
|
+
if (Object.keys(inlineWhenUnflattenedOGVals).length) {
|
|
1266
|
+
for (const [index, attr] of attrs.entries()) {
|
|
1267
|
+
if (attr.type === "style") {
|
|
1268
|
+
for (const key in attr.value) {
|
|
1269
|
+
const val = inlineWhenUnflattenedOGVals[key];
|
|
1270
|
+
if (val) {
|
|
1271
|
+
delete attr.value[key];
|
|
1272
|
+
attrs.splice(index - 1, 0, val.attr);
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
if (shouldFlatten) {
|
|
1280
|
+
if (shouldPrintDebug) {
|
|
1281
|
+
console.log(" [\u2705] flattening", originalNodeName, flatNode);
|
|
1282
|
+
}
|
|
1283
|
+
node.name.name = flatNode;
|
|
1284
|
+
res.flattened++;
|
|
1285
|
+
if (closingElement) {
|
|
1286
|
+
closingElement.name.name = flatNode;
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
if (shouldPrintDebug) {
|
|
1290
|
+
console.log(` \u274A\u274A inline props (${inlined.size}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : "");
|
|
1291
|
+
console.log(" - attrs (end):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
1292
|
+
}
|
|
1293
|
+
onExtractTag({
|
|
1294
|
+
attrs,
|
|
1295
|
+
node,
|
|
1296
|
+
lineNumbers,
|
|
1297
|
+
filePath,
|
|
1298
|
+
attemptEval,
|
|
1299
|
+
jsxPath: traversePath,
|
|
1300
|
+
originalNodeName,
|
|
1301
|
+
isFlattened: shouldFlatten,
|
|
1302
|
+
programPath
|
|
1303
|
+
});
|
|
1304
|
+
} finally {
|
|
1305
|
+
if (debugPropValue) {
|
|
1306
|
+
shouldPrintDebug = ogDebug;
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1311
|
+
tm.mark("jsx-done", shouldPrintDebug === "verbose");
|
|
1312
|
+
if (modifiedComponents.size) {
|
|
1313
|
+
const all = Array.from(modifiedComponents);
|
|
1314
|
+
if (shouldPrintDebug) {
|
|
1315
|
+
console.log(" [\u{1FA9D}] hook check", all.length);
|
|
1316
|
+
}
|
|
1317
|
+
for (const comp of all) {
|
|
1318
|
+
(0, import_removeUnusedHooks.removeUnusedHooks)(comp, shouldPrintDebug);
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
tm.done(shouldPrintDebug === "verbose");
|
|
1322
|
+
return res;
|
|
1323
|
+
}
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1327
|
+
0 && (module.exports = {
|
|
1328
|
+
createExtractor
|
|
1329
|
+
});
|
|
1330
|
+
//# sourceMappingURL=createExtractor.js.map
|