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