@tamagui/static 1.0.0-alpha.37 → 1.0.0-alpha.38

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