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