styled-components-to-stylex-codemod 0.0.48 → 0.0.49
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/{extract-external-interface-CvkkJZb1.mjs → ast-walk-DigTJqU7.mjs} +26 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +164 -5
- package/dist/{compute-leaf-set-90UrZ9WP.mjs → prepass-parser-CwdDzSgx.mjs} +100 -2
- package/dist/{prop-usage-Bz3z0V2F.mjs → prop-usage-QtOSsKTr.mjs} +15 -1
- package/dist/{run-prepass-1yZOVT3P.mjs → run-prepass-BWQCThfh.mjs} +117 -106
- package/dist/{transform-types-Bshr_dBf.d.mts → transform-types-CHRHLCj_.d.mts} +10 -1
- package/dist/transform.d.mts +1 -1
- package/dist/transform.mjs +2160 -364
- package/dist/{typescript-analysis-C_25uBrt.mjs → typescript-analysis-CmIDxfLv.mjs} +117 -0
- package/package.json +1 -1
package/dist/transform.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { t as createModuleResolver } from "./resolve-imports-DgSAddIF.mjs";
|
|
2
2
|
import { a as isDirectionalResult, n as mergeMarkerDeclarations, o as assertValidAdapter, r as DEFAULT_THEME_HOOK, t as transformedComponentAcceptsSx } from "./sx-surface-BzqO3hcC.mjs";
|
|
3
|
-
import { c as
|
|
3
|
+
import { a as getReExportedSourceName, c as Logger, i as findImportSource, l as UNSUPPORTED_SHOULD_FORWARD_PROP_WARNING, n as fileExports, s as resolveBarrelReExportBinding, t as walkAst } from "./ast-walk-DigTJqU7.mjs";
|
|
4
4
|
import { n as resolveExistingFilePath, r as toRealPath, t as isRelativeSpecifier } from "./path-utils-BC4U8X_q.mjs";
|
|
5
5
|
import { a as isBackgroundImageValue, c as isSingleBackgroundComponent, d as kebabToCamelCase, f as looksLikeLength, h as sanitizeIdentifier, i as getCommentBody, l as isStyleSectionMarkerComment, m as normalizeWhitespace, n as capitalize, o as isJSDocBlockComment, p as lowerFirst, r as escapeRegex, s as isPrettierIgnoreComment, t as camelToKebabCase, u as isValidIdentifierName } from "./string-utils-DD9wdRHW.mjs";
|
|
6
6
|
import { a as terminateStandaloneInterpolationStatements, i as parseStyledTemplateLiteral, n as isTemplatePlaceholderInSelectorContext, r as PLACEHOLDER_RE } from "./selector-context-heuristic-LVizWWOR.mjs";
|
|
7
|
-
import { i as
|
|
7
|
+
import { a as mergeComponentPropUsage, i as getExhaustiveObservedStaticValues, n as createComponentPropUsageInfo, o as readStaticJsxLiteral, r as formatObservedVariantCondition, t as KNOWN_NON_ELEMENT_PROPS } from "./prop-usage-QtOSsKTr.mjs";
|
|
8
8
|
import { createRequire } from "node:module";
|
|
9
9
|
import jscodeshift from "jscodeshift";
|
|
10
10
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
@@ -251,6 +251,11 @@ const STYLEX_STRING_ONLY_CSS_PROPS = new Set([
|
|
|
251
251
|
"gridColumnEnd",
|
|
252
252
|
"outlineOffset"
|
|
253
253
|
]);
|
|
254
|
+
const GRID_LINE_STYLEX_PROPS = new Set([
|
|
255
|
+
"gridArea",
|
|
256
|
+
"gridColumn",
|
|
257
|
+
"gridRow"
|
|
258
|
+
]);
|
|
254
259
|
const UNSUPPORTED_STYLEX_CSS_PROPS = new Set([
|
|
255
260
|
"all",
|
|
256
261
|
"scroll-margin-block",
|
|
@@ -403,9 +408,10 @@ function cssDeclarationToStylexDeclarations(decl) {
|
|
|
403
408
|
if (decl.value.kind === "interpolated") return expandInterpolatedBorder(prop, directionCapitalized, decl.value);
|
|
404
409
|
return borderShorthandToStylex(raw, directionCapitalized);
|
|
405
410
|
}
|
|
411
|
+
const stylexProp = cssPropertyToStylexProp(prop);
|
|
406
412
|
return [{
|
|
407
|
-
prop:
|
|
408
|
-
value: decl.value
|
|
413
|
+
prop: stylexProp,
|
|
414
|
+
value: normalizeGridLineSlashSpacing(stylexProp, decl.value)
|
|
409
415
|
}];
|
|
410
416
|
}
|
|
411
417
|
function cssPropertyToStylexProp(prop) {
|
|
@@ -423,6 +429,32 @@ const BORDER_STYLES = new Set([
|
|
|
423
429
|
"inset",
|
|
424
430
|
"outset"
|
|
425
431
|
]);
|
|
432
|
+
function normalizeGridLineSlashSpacing(stylexProp, value) {
|
|
433
|
+
if (!GRID_LINE_STYLEX_PROPS.has(stylexProp) || value.kind !== "static") return value;
|
|
434
|
+
return {
|
|
435
|
+
kind: "static",
|
|
436
|
+
value: normalizeUnescapedSlashSpacing(value.value)
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
function normalizeUnescapedSlashSpacing(value) {
|
|
440
|
+
let output = "";
|
|
441
|
+
for (let index = 0; index < value.length; index++) {
|
|
442
|
+
const char = value.charAt(index);
|
|
443
|
+
if (char === "/" && !isEscapedAt(value, index)) {
|
|
444
|
+
output = output.replace(/\s+$/g, "");
|
|
445
|
+
output += " / ";
|
|
446
|
+
while (index + 1 < value.length && /\s/.test(value.charAt(index + 1))) index++;
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
output += char;
|
|
450
|
+
}
|
|
451
|
+
return output;
|
|
452
|
+
}
|
|
453
|
+
function isEscapedAt(value, index) {
|
|
454
|
+
let backslashCount = 0;
|
|
455
|
+
for (let cursor = index - 1; cursor >= 0 && value.charAt(cursor) === "\\"; cursor--) backslashCount++;
|
|
456
|
+
return backslashCount % 2 === 1;
|
|
457
|
+
}
|
|
426
458
|
/**
|
|
427
459
|
* Expands an interpolated border shorthand into separate width/style/color properties.
|
|
428
460
|
* Extracts static width and style tokens from the value parts, leaving the interpolated
|
|
@@ -944,6 +976,13 @@ function isAstNode(v) {
|
|
|
944
976
|
return !!v && typeof v === "object" && !Array.isArray(v) && typeof v.type === "string";
|
|
945
977
|
}
|
|
946
978
|
/**
|
|
979
|
+
* Generic type guard narrowing an unknown value to an AST node of a specific `type`.
|
|
980
|
+
* Returns false for arrays and non-objects.
|
|
981
|
+
*/
|
|
982
|
+
function isNodeOfType(node, type) {
|
|
983
|
+
return isAstNode(node) && node.type === type;
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
947
986
|
* Type guard for function-like nodes including class/object methods.
|
|
948
987
|
*/
|
|
949
988
|
function isFunctionNode$1(node) {
|
|
@@ -1140,6 +1179,26 @@ function collectIdentifiers(node, out) {
|
|
|
1140
1179
|
}
|
|
1141
1180
|
}
|
|
1142
1181
|
/**
|
|
1182
|
+
* Collects binding names introduced by an object/array destructuring pattern.
|
|
1183
|
+
*/
|
|
1184
|
+
function collectPatternBindingNames$2(node, names) {
|
|
1185
|
+
if (!node || typeof node !== "object") return;
|
|
1186
|
+
if (Array.isArray(node)) {
|
|
1187
|
+
for (const child of node) collectPatternBindingNames$2(child, names);
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1190
|
+
const typed = node;
|
|
1191
|
+
if (typed.type === "Identifier" && typed.name) {
|
|
1192
|
+
names.add(typed.name);
|
|
1193
|
+
return;
|
|
1194
|
+
}
|
|
1195
|
+
if (typed.type === "MemberExpression" || typed.type === "OptionalMemberExpression" || typed.type === "TSQualifiedName") return;
|
|
1196
|
+
for (const key of Object.keys(node)) {
|
|
1197
|
+
if (key === "loc" || key === "comments" || key === "leadingComments") continue;
|
|
1198
|
+
collectPatternBindingNames$2(node[key], names);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
/**
|
|
1143
1202
|
* Converts an AST literal node to its static JavaScript value.
|
|
1144
1203
|
*
|
|
1145
1204
|
* Supports:
|
|
@@ -2629,34 +2688,56 @@ function defaultExportMatches(component, names) {
|
|
|
2629
2688
|
//#region src/internal/utilities/wrapped-component-interface.ts
|
|
2630
2689
|
function wrappedComponentInterfaceFor(ctx, componentLocalName) {
|
|
2631
2690
|
if (!ctx.adapter.useSxProp) return;
|
|
2632
|
-
const
|
|
2691
|
+
const [rootLocalName, ...memberPath] = componentLocalName.split(".");
|
|
2692
|
+
if (!rootLocalName) return;
|
|
2693
|
+
const importInfo = ctx.importMap?.get(rootLocalName);
|
|
2633
2694
|
if (importInfo) {
|
|
2634
|
-
const
|
|
2695
|
+
const componentNames = memberPath.length > 0 ? memberComponentNames(rootLocalName, importInfo.importedName, memberPath) : importInfo.importedName === "default" ? [rootLocalName, importInfo.importedName] : [importInfo.importedName];
|
|
2696
|
+
const typedInterface = importInfo.source.kind === "absolutePath" ? typedComponentInterfaceFor(ctx, importInfo.source.value, componentNames) : void 0;
|
|
2635
2697
|
const adapterResult = ctx.adapter.wrappedComponentInterface?.({
|
|
2636
2698
|
localName: componentLocalName,
|
|
2637
2699
|
importSource: importInfo.source.value,
|
|
2638
2700
|
importedName: importInfo.importedName,
|
|
2701
|
+
...memberPath.length > 0 ? { memberPath } : {},
|
|
2639
2702
|
filePath: ctx.file.path
|
|
2640
2703
|
});
|
|
2641
|
-
if (adapterResult !== void 0)
|
|
2642
|
-
if (adapterResult.acceptsSx && hasTypedSxConstraints(typedInterface)) return {
|
|
2643
|
-
...adapterResult,
|
|
2644
|
-
sxExcludedProperties: mergeUniqueStrings(adapterResult.sxExcludedProperties, typedInterface.sxExcludedProperties ?? []),
|
|
2645
|
-
sxAllowedProperties: mergeAllowedPropertyLists(adapterResult.sxAllowedProperties, typedInterface.sxAllowedProperties)
|
|
2646
|
-
};
|
|
2647
|
-
return adapterResult;
|
|
2648
|
-
}
|
|
2704
|
+
if (adapterResult !== void 0) return mergeWrappedComponentInterface(adapterResult, typedInterface);
|
|
2649
2705
|
return typedInterface;
|
|
2650
2706
|
}
|
|
2651
2707
|
return typedComponentInterfaceFor(ctx, ctx.file.path, [componentLocalName]);
|
|
2652
2708
|
}
|
|
2653
|
-
function
|
|
2654
|
-
|
|
2709
|
+
function memberComponentNames(rootLocalName, importedName, memberPath) {
|
|
2710
|
+
const memberName = memberPath[memberPath.length - 1];
|
|
2711
|
+
const dottedImportedName = importedName === "default" ? [rootLocalName, ...memberPath].join(".") : [importedName, ...memberPath].join(".");
|
|
2712
|
+
return [...new Set([
|
|
2713
|
+
dottedImportedName,
|
|
2714
|
+
[rootLocalName, ...memberPath].join("."),
|
|
2715
|
+
memberName
|
|
2716
|
+
])].filter((name) => typeof name === "string" && name.length > 0);
|
|
2717
|
+
}
|
|
2718
|
+
function mergeWrappedComponentInterface(adapterResult, typedInterface) {
|
|
2719
|
+
if (!adapterResult.acceptsSx || !hasTypedSxMetadata(typedInterface)) return adapterResult;
|
|
2720
|
+
return {
|
|
2721
|
+
...adapterResult,
|
|
2722
|
+
...typedInterface.sxTarget ? { sxTarget: typedInterface.sxTarget } : {},
|
|
2723
|
+
sxExcludedProperties: mergeUniqueStrings(adapterResult.sxExcludedProperties, typedInterface.sxExcludedProperties ?? []),
|
|
2724
|
+
sxAllowedProperties: mergeAllowedPropertyLists(adapterResult.sxAllowedProperties, typedInterface.sxAllowedProperties)
|
|
2725
|
+
};
|
|
2726
|
+
}
|
|
2727
|
+
/**
|
|
2728
|
+
* Checks if the typed interface has any sx metadata to merge with the adapter result.
|
|
2729
|
+
* This includes sxTarget (even without property constraints), property exclusions,
|
|
2730
|
+
* or allowed property lists.
|
|
2731
|
+
*/
|
|
2732
|
+
function hasTypedSxMetadata(typedInterface) {
|
|
2733
|
+
if (!typedInterface) return false;
|
|
2734
|
+
return typedInterface.sxTarget !== void 0 || (typedInterface.sxExcludedProperties?.length ?? 0) > 0 || typedInterface.sxAllowedProperties !== void 0;
|
|
2655
2735
|
}
|
|
2656
2736
|
function typedComponentInterfaceFor(ctx, filePath, componentNames) {
|
|
2657
2737
|
const typedComponent = findTypeScriptComponentMetadata(ctx.options.crossFileInfo?.typeScriptMetadata, filePath, componentNames);
|
|
2658
2738
|
if (typedComponent?.supportsSxProp) return {
|
|
2659
2739
|
acceptsSx: true,
|
|
2740
|
+
...typedComponent.sxTarget ? { sxTarget: typedComponent.sxTarget } : {},
|
|
2660
2741
|
sxExcludedProperties: typedComponent.sxExcludedProperties,
|
|
2661
2742
|
sxAllowedProperties: typedComponent.sxAllowedProperties
|
|
2662
2743
|
};
|
|
@@ -2887,7 +2968,7 @@ function canInlineSingleUseSxAwareComponentWrapper(args) {
|
|
|
2887
2968
|
if (hasAttrsAsOverride(decl.attrsInfo) || hasAttrsPayload(decl.attrsInfo)) return false;
|
|
2888
2969
|
if (needsShouldForwardPropWrapper(decl) || decl.attrWrapper || decl.bridgeClassName || decl.enumVariant || (decl.inlineStyleProps?.length ?? 0) > 0 || (decl.styleFnFromProps?.length ?? 0) > 0 || (decl.variantDimensions?.length ?? 0) > 0 || Object.keys(decl.variantStyleKeys ?? {}).length > 0 || (decl.compoundVariants?.length ?? 0) > 0 || (decl.pseudoAliasSelectors?.length ?? 0) > 0 || (decl.pseudoExpandSelectors?.length ?? 0) > 0 || (decl.localElementOverrides?.length ?? 0) > 0 || (decl.needsUseThemeHook?.length ?? 0) > 0 || (decl.extraStylexPropsArgs?.some((arg) => arg.when) ?? false)) return false;
|
|
2889
2970
|
const componentInterface = wrappedComponentInterfaceFor(ctx, decl.base.ident);
|
|
2890
|
-
return componentInterface?.acceptsSx === true && (componentInterface.sxExcludedProperties?.length ?? 0) === 0 && componentInterface.sxAllowedProperties === void 0;
|
|
2971
|
+
return componentInterface?.acceptsSx === true && componentInterface.sxTarget !== "inner" && (componentInterface.sxExcludedProperties?.length ?? 0) === 0 && componentInterface.sxAllowedProperties === void 0;
|
|
2891
2972
|
}
|
|
2892
2973
|
function hasAttrsPayload(attrsInfo) {
|
|
2893
2974
|
return !!(Object.keys(attrsInfo?.staticAttrs ?? {}).length > 0 || (attrsInfo?.conditionalAttrs?.length ?? 0) > 0 || (attrsInfo?.defaultAttrs?.length ?? 0) > 0 || (attrsInfo?.dynamicAttrs?.length ?? 0) > 0 || (attrsInfo?.invertedBoolAttrs?.length ?? 0) > 0 || Object.keys(attrsInfo?.attrsStaticStyles ?? {}).length > 0 || attrsInfo?.attrsStaticStyleExpr || (attrsInfo?.attrsDynamicStyles?.length ?? 0) > 0);
|
|
@@ -3087,6 +3168,121 @@ function getBridgeClassVar(decl) {
|
|
|
3087
3168
|
return decl.bridgeClassName ? bridgeClassVarName(decl.localName) : void 0;
|
|
3088
3169
|
}
|
|
3089
3170
|
//#endregion
|
|
3171
|
+
//#region src/internal/utilities/element-type-host.ts
|
|
3172
|
+
function isStyleOnlyElementTypeHost(args) {
|
|
3173
|
+
const { j, root, hostName, elementTypePropNames } = args;
|
|
3174
|
+
const fnNode = findLocalComponentFunction(j, root, hostName);
|
|
3175
|
+
if (!fnNode) return false;
|
|
3176
|
+
const slots = collectElementTypeSlotBindings(j, fnNode, elementTypePropNames);
|
|
3177
|
+
if (slots.size === 0) return false;
|
|
3178
|
+
const fn = j(fnNode);
|
|
3179
|
+
let renderedSlotCount = 0;
|
|
3180
|
+
let forwardsClassName = false;
|
|
3181
|
+
fn.find(j.JSXOpeningElement).forEach((path) => {
|
|
3182
|
+
const node = path.node;
|
|
3183
|
+
const tag = getRootJsxIdentifierName(node.name);
|
|
3184
|
+
if (!tag || !slots.has(tag)) return;
|
|
3185
|
+
renderedSlotCount += 1;
|
|
3186
|
+
for (const attr of node.attributes ?? []) if (attr.type === "JSXSpreadAttribute") forwardsClassName = true;
|
|
3187
|
+
else if (attr.type === "JSXAttribute" && attr.name?.type === "JSXIdentifier" && attr.name.name === "className") forwardsClassName = true;
|
|
3188
|
+
});
|
|
3189
|
+
if (forwardsClassName || renderedSlotCount === 0) return false;
|
|
3190
|
+
let slotEscapes = false;
|
|
3191
|
+
fn.find(j.Identifier).forEach((path) => {
|
|
3192
|
+
const name = path.node.name;
|
|
3193
|
+
if (!name || !slots.has(name)) return;
|
|
3194
|
+
const parent = path.parentPath?.node;
|
|
3195
|
+
if (!isSlotBindingOrJsxTagReference(path.node, parent)) slotEscapes = true;
|
|
3196
|
+
});
|
|
3197
|
+
return !slotEscapes;
|
|
3198
|
+
}
|
|
3199
|
+
function findLocalComponentFunction(j, root, hostName) {
|
|
3200
|
+
let fnNode = null;
|
|
3201
|
+
root.find(j.FunctionDeclaration).forEach((path) => {
|
|
3202
|
+
const node = path.node;
|
|
3203
|
+
if (node.id?.name === hostName) fnNode ??= node;
|
|
3204
|
+
});
|
|
3205
|
+
if (fnNode) return fnNode;
|
|
3206
|
+
root.find(j.VariableDeclarator).forEach((path) => {
|
|
3207
|
+
const node = path.node;
|
|
3208
|
+
if (node.id?.name !== hostName) return;
|
|
3209
|
+
const init = node.init;
|
|
3210
|
+
if (init?.type === "ArrowFunctionExpression" || init?.type === "FunctionExpression") fnNode ??= init;
|
|
3211
|
+
});
|
|
3212
|
+
return fnNode;
|
|
3213
|
+
}
|
|
3214
|
+
function collectElementTypeSlotBindings(j, fnNode, elementTypePropNames) {
|
|
3215
|
+
const slots = /* @__PURE__ */ new Set();
|
|
3216
|
+
const first = (fnNode.params ?? [])[0];
|
|
3217
|
+
if (first?.type === "ObjectPattern") for (const prop of first.properties ?? []) {
|
|
3218
|
+
if (prop.type !== "ObjectProperty" && prop.type !== "Property") continue;
|
|
3219
|
+
const key = prop.key;
|
|
3220
|
+
if (key?.type !== "Identifier" || !key.name || !elementTypePropNames.has(key.name)) continue;
|
|
3221
|
+
const value = prop.value;
|
|
3222
|
+
if (value?.type === "Identifier") slots.add(value.name ?? "");
|
|
3223
|
+
else if (value?.type === "AssignmentPattern" && value.left?.type === "Identifier") slots.add(value.left.name ?? "");
|
|
3224
|
+
}
|
|
3225
|
+
const propsName = first?.type === "Identifier" ? first.name : null;
|
|
3226
|
+
if (propsName && fnNode.body) j(fnNode.body).find(j.VariableDeclarator).forEach((path) => {
|
|
3227
|
+
const node = path.node;
|
|
3228
|
+
const id = node.id;
|
|
3229
|
+
if (id?.type === "Identifier" && id.name && initReferencesElementTypeProp(node.init, propsName, elementTypePropNames)) slots.add(id.name);
|
|
3230
|
+
});
|
|
3231
|
+
slots.delete("");
|
|
3232
|
+
return slots;
|
|
3233
|
+
}
|
|
3234
|
+
function initReferencesElementTypeProp(init, propsName, elementTypePropNames) {
|
|
3235
|
+
const node = init;
|
|
3236
|
+
if (!node) return false;
|
|
3237
|
+
if (node.type === "MemberExpression" && node.computed !== true && node.object?.type === "Identifier" && node.object.name === propsName && node.property?.type === "Identifier" && elementTypePropNames.has(node.property.name ?? "")) return true;
|
|
3238
|
+
if (node.type === "LogicalExpression") return initReferencesElementTypeProp(node.left, propsName, elementTypePropNames);
|
|
3239
|
+
return false;
|
|
3240
|
+
}
|
|
3241
|
+
function isSlotBindingOrJsxTagReference(idNode, parent) {
|
|
3242
|
+
if (!parent) return false;
|
|
3243
|
+
switch (parent.type) {
|
|
3244
|
+
case "JSXOpeningElement":
|
|
3245
|
+
case "JSXClosingElement": return parent.name === idNode;
|
|
3246
|
+
case "VariableDeclarator": return parent.id === idNode;
|
|
3247
|
+
case "ObjectProperty":
|
|
3248
|
+
case "Property": return parent.value === idNode;
|
|
3249
|
+
case "AssignmentPattern": return parent.left === idNode;
|
|
3250
|
+
case "MemberExpression": return parent.property === idNode;
|
|
3251
|
+
default: return false;
|
|
3252
|
+
}
|
|
3253
|
+
}
|
|
3254
|
+
//#endregion
|
|
3255
|
+
//#region src/internal/utilities/component-value-references.ts
|
|
3256
|
+
/**
|
|
3257
|
+
* True when this Identifier path is a non-JSX value reference to a styled component (not its
|
|
3258
|
+
* declaration, not a JSX tag, not a `styled(...)` extension or tagged-template tag).
|
|
3259
|
+
*/
|
|
3260
|
+
function isNonJsxStyledValueReferencePath(path, styledDefaultImport) {
|
|
3261
|
+
const parent = path.parentPath?.node;
|
|
3262
|
+
if (parent?.type === "VariableDeclarator" && parent.id === path.node) return false;
|
|
3263
|
+
if (parent?.type === "JSXOpeningElement" || parent?.type === "JSXClosingElement") return false;
|
|
3264
|
+
if (parent?.type === "JSXMemberExpression" && parent.object === path.node) return false;
|
|
3265
|
+
if (parent?.type === "CallExpression") {
|
|
3266
|
+
const callee = parent.callee;
|
|
3267
|
+
if (callee?.type === "Identifier" && callee.name === styledDefaultImport) return false;
|
|
3268
|
+
if (callee?.type === "MemberExpression" && callee.object?.type === "CallExpression" && callee.object.callee?.type === "Identifier" && callee.object.callee.name === styledDefaultImport) return false;
|
|
3269
|
+
}
|
|
3270
|
+
if (parent?.type === "TaggedTemplateExpression") return false;
|
|
3271
|
+
if (parent?.type === "CallExpression" && path.parentPath?.parentPath?.node?.type === "TaggedTemplateExpression") return false;
|
|
3272
|
+
if (parent?.type === "TemplateLiteral") return false;
|
|
3273
|
+
return true;
|
|
3274
|
+
}
|
|
3275
|
+
/** Returns the subset of `names` that appear as a non-JSX value reference anywhere in the file. */
|
|
3276
|
+
function componentsReferencedAsValue(root, j, names, styledDefaultImport) {
|
|
3277
|
+
const referenced = /* @__PURE__ */ new Set();
|
|
3278
|
+
if (names.size === 0) return referenced;
|
|
3279
|
+
root.find(j.Identifier).forEach((path) => {
|
|
3280
|
+
const name = path.node.name;
|
|
3281
|
+
if (name && names.has(name) && !referenced.has(name) && isNonJsxStyledValueReferencePath(path, styledDefaultImport)) referenced.add(name);
|
|
3282
|
+
});
|
|
3283
|
+
return referenced;
|
|
3284
|
+
}
|
|
3285
|
+
//#endregion
|
|
3090
3286
|
//#region src/internal/utilities/jsx-name-utils.ts
|
|
3091
3287
|
function jsxNamePath(name) {
|
|
3092
3288
|
const node = name;
|
|
@@ -3179,7 +3375,7 @@ function specifierExportedName(spec) {
|
|
|
3179
3375
|
* - Disjunction: `"a || b"` → `a || b`
|
|
3180
3376
|
* - Grouped negation: `"!(a || b)"` → `!(a || b)`
|
|
3181
3377
|
*/
|
|
3182
|
-
function parseVariantWhenToAst(j, when, booleanProps) {
|
|
3378
|
+
function parseVariantWhenToAst(j, when, booleanProps, knownProps) {
|
|
3183
3379
|
const buildMemberExpr = (raw) => {
|
|
3184
3380
|
if (!raw.includes(".")) return null;
|
|
3185
3381
|
const parts = raw.split(".").map((part) => part.trim()).filter(Boolean);
|
|
@@ -3206,14 +3402,15 @@ function parseVariantWhenToAst(j, when, booleanProps) {
|
|
|
3206
3402
|
propName: null,
|
|
3207
3403
|
expr: j.identifier(trimmedRaw)
|
|
3208
3404
|
};
|
|
3405
|
+
const expr = parts.slice(2).reduce((acc, part) => j.memberExpression(acc, j.identifier(part)), j.identifier(propRoot));
|
|
3209
3406
|
return {
|
|
3210
|
-
propName: propRoot,
|
|
3211
|
-
expr
|
|
3407
|
+
propName: isConditionPropIdentifier(propRoot) ? propRoot : null,
|
|
3408
|
+
expr
|
|
3212
3409
|
};
|
|
3213
3410
|
}
|
|
3214
3411
|
const memberExpr = buildMemberExpr(trimmedRaw);
|
|
3215
3412
|
if (memberExpr) return {
|
|
3216
|
-
propName: root
|
|
3413
|
+
propName: root && root !== "theme" && isConditionPropIdentifier(root) ? root : null,
|
|
3217
3414
|
expr: memberExpr
|
|
3218
3415
|
};
|
|
3219
3416
|
return {
|
|
@@ -3222,7 +3419,7 @@ function parseVariantWhenToAst(j, when, booleanProps) {
|
|
|
3222
3419
|
};
|
|
3223
3420
|
}
|
|
3224
3421
|
return {
|
|
3225
|
-
propName: trimmedRaw === "theme" ? null : trimmedRaw,
|
|
3422
|
+
propName: trimmedRaw === "theme" || !isConditionPropIdentifier(trimmedRaw) ? null : trimmedRaw,
|
|
3226
3423
|
expr: j.identifier(trimmedRaw)
|
|
3227
3424
|
};
|
|
3228
3425
|
};
|
|
@@ -3233,7 +3430,7 @@ function parseVariantWhenToAst(j, when, booleanProps) {
|
|
|
3233
3430
|
isBoolean: true
|
|
3234
3431
|
};
|
|
3235
3432
|
if (trimmed.startsWith("!(") && trimmed.endsWith(")")) {
|
|
3236
|
-
const innerParsed = parseVariantWhenToAst(j, trimmed.slice(2, -1).trim(), booleanProps);
|
|
3433
|
+
const innerParsed = parseVariantWhenToAst(j, trimmed.slice(2, -1).trim(), booleanProps, knownProps);
|
|
3237
3434
|
return {
|
|
3238
3435
|
cond: j.unaryExpression("!", innerParsed.cond),
|
|
3239
3436
|
props: innerParsed.props,
|
|
@@ -3241,7 +3438,7 @@ function parseVariantWhenToAst(j, when, booleanProps) {
|
|
|
3241
3438
|
};
|
|
3242
3439
|
}
|
|
3243
3440
|
if (trimmed.includes("&&")) {
|
|
3244
|
-
const parsed = trimmed.split("&&").map((s) => s.trim()).filter(Boolean).map((p) => parseVariantWhenToAst(j, p, booleanProps));
|
|
3441
|
+
const parsed = trimmed.split("&&").map((s) => s.trim()).filter(Boolean).map((p) => parseVariantWhenToAst(j, p, booleanProps, knownProps));
|
|
3245
3442
|
const firstParsed = parsed[0];
|
|
3246
3443
|
if (!firstParsed) return {
|
|
3247
3444
|
cond: j.identifier("true"),
|
|
@@ -3255,7 +3452,7 @@ function parseVariantWhenToAst(j, when, booleanProps) {
|
|
|
3255
3452
|
};
|
|
3256
3453
|
}
|
|
3257
3454
|
if (trimmed.includes(" || ")) {
|
|
3258
|
-
const parsed = trimmed.split(" || ").map((s) => s.trim()).filter(Boolean).map((p) => parseVariantWhenToAst(j, p, booleanProps));
|
|
3455
|
+
const parsed = trimmed.split(" || ").map((s) => s.trim()).filter(Boolean).map((p) => parseVariantWhenToAst(j, p, booleanProps, knownProps));
|
|
3259
3456
|
const firstParsedOr = parsed[0];
|
|
3260
3457
|
if (!firstParsedOr) return {
|
|
3261
3458
|
cond: j.identifier("true"),
|
|
@@ -3269,7 +3466,7 @@ function parseVariantWhenToAst(j, when, booleanProps) {
|
|
|
3269
3466
|
};
|
|
3270
3467
|
}
|
|
3271
3468
|
if (trimmed.startsWith("!")) {
|
|
3272
|
-
const innerParsed = parseVariantWhenToAst(j, trimmed.slice(1).trim(), booleanProps);
|
|
3469
|
+
const innerParsed = parseVariantWhenToAst(j, trimmed.slice(1).trim(), booleanProps, knownProps);
|
|
3273
3470
|
return {
|
|
3274
3471
|
cond: j.unaryExpression("!", innerParsed.cond),
|
|
3275
3472
|
props: innerParsed.props,
|
|
@@ -3289,6 +3486,12 @@ function parseVariantWhenToAst(j, when, booleanProps) {
|
|
|
3289
3486
|
isBoolean: true
|
|
3290
3487
|
};
|
|
3291
3488
|
}
|
|
3489
|
+
const expression = parseConditionExpression(j, trimmed);
|
|
3490
|
+
if (expression) return {
|
|
3491
|
+
cond: expression,
|
|
3492
|
+
props: collectGuardExpressionPropNames(expression, knownProps),
|
|
3493
|
+
isBoolean: true
|
|
3494
|
+
};
|
|
3292
3495
|
const simple = parsePropRef(trimmed);
|
|
3293
3496
|
const propIsBoolean = !!(simple.propName && booleanProps?.has(simple.propName));
|
|
3294
3497
|
return {
|
|
@@ -3297,14 +3500,103 @@ function parseVariantWhenToAst(j, when, booleanProps) {
|
|
|
3297
3500
|
isBoolean: propIsBoolean
|
|
3298
3501
|
};
|
|
3299
3502
|
}
|
|
3503
|
+
function parseConditionExpression(j, source) {
|
|
3504
|
+
if (!source.includes("(") && !/[<>?[\]]/.test(source)) return null;
|
|
3505
|
+
try {
|
|
3506
|
+
const declarator = j(`const __condition = (${source});`).find(j.VariableDeclarator).nodes()[0];
|
|
3507
|
+
return unwrapParenthesizedExpression(declarator?.init) ?? null;
|
|
3508
|
+
} catch {
|
|
3509
|
+
return null;
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
function unwrapParenthesizedExpression(expr) {
|
|
3513
|
+
let current = expr;
|
|
3514
|
+
while (current && current.type === "ParenthesizedExpression") current = current.expression;
|
|
3515
|
+
return current ?? null;
|
|
3516
|
+
}
|
|
3517
|
+
function collectGuardExpressionPropNames(expr, knownProps) {
|
|
3518
|
+
const props = /* @__PURE__ */ new Set();
|
|
3519
|
+
collectGuardProps(expr, props, knownProps);
|
|
3520
|
+
return [...props];
|
|
3521
|
+
}
|
|
3522
|
+
function collectGuardProps(node, props, knownProps) {
|
|
3523
|
+
if (!node || typeof node !== "object") return;
|
|
3524
|
+
const record = node;
|
|
3525
|
+
const type = record.type;
|
|
3526
|
+
if (type === "Identifier") {
|
|
3527
|
+
const name = record.name;
|
|
3528
|
+
if (typeof name === "string" && isConditionPropIdentifier(name, knownProps)) props.add(name);
|
|
3529
|
+
return;
|
|
3530
|
+
}
|
|
3531
|
+
if (type === "CallExpression" || type === "OptionalCallExpression") {
|
|
3532
|
+
if (isMemberExpressionRecord(record.callee)) collectMemberExpressionProp(record.callee, props, knownProps);
|
|
3533
|
+
const args = record.arguments;
|
|
3534
|
+
if (Array.isArray(args)) for (const arg of args) collectGuardProps(arg, props, knownProps);
|
|
3535
|
+
return;
|
|
3536
|
+
}
|
|
3537
|
+
if (type === "MemberExpression" || type === "OptionalMemberExpression") {
|
|
3538
|
+
collectMemberExpressionProp(record, props, knownProps);
|
|
3539
|
+
return;
|
|
3540
|
+
}
|
|
3541
|
+
for (const [key, value] of Object.entries(record)) {
|
|
3542
|
+
if (key === "type" || key === "loc" || key === "comments" || key === "leadingComments") continue;
|
|
3543
|
+
if (Array.isArray(value)) for (const item of value) collectGuardProps(item, props, knownProps);
|
|
3544
|
+
else collectGuardProps(value, props, knownProps);
|
|
3545
|
+
}
|
|
3546
|
+
}
|
|
3547
|
+
function isMemberExpressionRecord(node) {
|
|
3548
|
+
if (!node || typeof node !== "object") return false;
|
|
3549
|
+
const type = node.type;
|
|
3550
|
+
return type === "MemberExpression" || type === "OptionalMemberExpression";
|
|
3551
|
+
}
|
|
3552
|
+
function collectMemberExpressionProp(node, props, knownProps) {
|
|
3553
|
+
const object = node.object;
|
|
3554
|
+
const property = node.property;
|
|
3555
|
+
const rootName = readMemberRootIdentifier(object);
|
|
3556
|
+
if (rootName === "props" || rootName === "p") {
|
|
3557
|
+
const propName = findPropsDirectProperty(node);
|
|
3558
|
+
if (typeof propName === "string" && isConditionPropIdentifier(propName, knownProps)) props.add(propName);
|
|
3559
|
+
} else if (typeof rootName === "string" && rootName !== "theme" && isConditionPropIdentifier(rootName, knownProps)) props.add(rootName);
|
|
3560
|
+
if (node.computed) collectGuardProps(property, props, knownProps);
|
|
3561
|
+
}
|
|
3562
|
+
function readMemberRootIdentifier(node) {
|
|
3563
|
+
if (!node) return null;
|
|
3564
|
+
if (node.type === "Identifier" && typeof node.name === "string") return node.name;
|
|
3565
|
+
if (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") return readMemberRootIdentifier(node.object);
|
|
3566
|
+
return null;
|
|
3567
|
+
}
|
|
3568
|
+
/**
|
|
3569
|
+
* For chained member expressions rooted at `props` or `p`, finds the property
|
|
3570
|
+
* directly on `props`. For `props.size.startsWith`, returns "size".
|
|
3571
|
+
* For `props.foo`, returns "foo".
|
|
3572
|
+
*/
|
|
3573
|
+
function findPropsDirectProperty(node) {
|
|
3574
|
+
const object = node.object;
|
|
3575
|
+
const property = node.property;
|
|
3576
|
+
if (!object) return null;
|
|
3577
|
+
if (object.type === "Identifier") {
|
|
3578
|
+
const objName = object.name;
|
|
3579
|
+
if (objName === "props" || objName === "p") return property?.type === "Identifier" ? property.name : null;
|
|
3580
|
+
return null;
|
|
3581
|
+
}
|
|
3582
|
+
if (object.type === "MemberExpression" || object.type === "OptionalMemberExpression") return findPropsDirectProperty(object);
|
|
3583
|
+
return null;
|
|
3584
|
+
}
|
|
3585
|
+
function isConditionPropIdentifier(name, knownProps) {
|
|
3586
|
+
if (knownProps) return knownProps.has(name);
|
|
3587
|
+
if (name === "undefined" || name === "NaN" || name === "Infinity") return false;
|
|
3588
|
+
if (/^[A-Z][A-Z0-9_]*$/.test(name)) return false;
|
|
3589
|
+
if (/^[A-Z][a-zA-Z0-9]*$/.test(name) && !name.includes("_")) return false;
|
|
3590
|
+
return isValidIdentifierName(name);
|
|
3591
|
+
}
|
|
3300
3592
|
/**
|
|
3301
3593
|
* Parses a "when" string and optionally collects the referenced prop names
|
|
3302
3594
|
* into a `destructureProps` array so they can be included in the wrapper
|
|
3303
3595
|
* function's parameter destructuring.
|
|
3304
3596
|
*/
|
|
3305
3597
|
function collectConditionProps(j, args) {
|
|
3306
|
-
const { when, destructureProps, booleanProps } = args;
|
|
3307
|
-
const parsed = parseVariantWhenToAst(j, when, booleanProps);
|
|
3598
|
+
const { when, destructureProps, booleanProps, knownProps } = args;
|
|
3599
|
+
const parsed = parseVariantWhenToAst(j, when, booleanProps, knownProps);
|
|
3308
3600
|
if (destructureProps) {
|
|
3309
3601
|
for (const p of parsed.props) if (p && !destructureProps.includes(p)) destructureProps.push(p);
|
|
3310
3602
|
}
|
|
@@ -3345,7 +3637,7 @@ function areEquivalentWhen(left, right) {
|
|
|
3345
3637
|
* Two entries with `when: "prop"` and `when: "!prop"` are merged into
|
|
3346
3638
|
* `prop ? trueExpr : falseExpr` instead of emitting separate conditionals.
|
|
3347
3639
|
*/
|
|
3348
|
-
function
|
|
3640
|
+
function buildExtraStylexPropsExprEntries(j, args) {
|
|
3349
3641
|
const { entries, destructureProps, booleanProps } = args;
|
|
3350
3642
|
const result = [];
|
|
3351
3643
|
const consumed = /* @__PURE__ */ new Set();
|
|
@@ -3353,7 +3645,12 @@ function buildExtraStylexPropsExprs(j, args) {
|
|
|
3353
3645
|
if (consumed.has(i)) continue;
|
|
3354
3646
|
const entry = entries[i];
|
|
3355
3647
|
if (!entry.when) {
|
|
3356
|
-
result.push(
|
|
3648
|
+
result.push({
|
|
3649
|
+
expr: entry.expr,
|
|
3650
|
+
conditional: false,
|
|
3651
|
+
afterBase: entry.afterBase,
|
|
3652
|
+
afterVariants: entry.afterVariants
|
|
3653
|
+
});
|
|
3357
3654
|
continue;
|
|
3358
3655
|
}
|
|
3359
3656
|
const complementIndex = findComplementaryEntry(entries, i, consumed);
|
|
@@ -3368,7 +3665,12 @@ function buildExtraStylexPropsExprs(j, args) {
|
|
|
3368
3665
|
const isEntryPositive = areEquivalentWhen(entry.when, positiveWhenRaw);
|
|
3369
3666
|
const trueExpr = isEntryPositive ? entry.expr : other.expr;
|
|
3370
3667
|
const falseExpr = isEntryPositive ? other.expr : entry.expr;
|
|
3371
|
-
result.push(
|
|
3668
|
+
result.push({
|
|
3669
|
+
expr: j.conditionalExpression(cond, trueExpr, falseExpr),
|
|
3670
|
+
conditional: true,
|
|
3671
|
+
afterBase: entry.afterBase || other.afterBase,
|
|
3672
|
+
afterVariants: entry.afterVariants || other.afterVariants
|
|
3673
|
+
});
|
|
3372
3674
|
continue;
|
|
3373
3675
|
}
|
|
3374
3676
|
const { cond, isBoolean } = collectConditionProps(j, {
|
|
@@ -3376,14 +3678,22 @@ function buildExtraStylexPropsExprs(j, args) {
|
|
|
3376
3678
|
destructureProps,
|
|
3377
3679
|
booleanProps
|
|
3378
3680
|
});
|
|
3379
|
-
result.push(
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3681
|
+
result.push({
|
|
3682
|
+
expr: makeConditionalStyleExpr(j, {
|
|
3683
|
+
cond,
|
|
3684
|
+
expr: entry.expr,
|
|
3685
|
+
isBoolean
|
|
3686
|
+
}),
|
|
3687
|
+
conditional: true,
|
|
3688
|
+
afterBase: entry.afterBase,
|
|
3689
|
+
afterVariants: entry.afterVariants
|
|
3690
|
+
});
|
|
3384
3691
|
}
|
|
3385
3692
|
return result;
|
|
3386
3693
|
}
|
|
3694
|
+
function buildExtraStylexPropsExprs(j, args) {
|
|
3695
|
+
return buildExtraStylexPropsExprEntries(j, args).map((entry) => entry.expr);
|
|
3696
|
+
}
|
|
3387
3697
|
/**
|
|
3388
3698
|
* Merges adjacent `cond && styleA, !cond && styleB` expressions into
|
|
3389
3699
|
* `cond ? styleA : styleB` without reordering other style args.
|
|
@@ -4499,23 +4809,6 @@ function mapAst(root, replacer) {
|
|
|
4499
4809
|
* Recursively walk an AST tree and call `visitor` on each node to collect data.
|
|
4500
4810
|
* Skips `loc` and `comments` keys.
|
|
4501
4811
|
*/
|
|
4502
|
-
function walkAst(root, visitor) {
|
|
4503
|
-
const visit = (node) => {
|
|
4504
|
-
if (!node || typeof node !== "object") return;
|
|
4505
|
-
if (Array.isArray(node)) {
|
|
4506
|
-
for (const child of node) visit(child);
|
|
4507
|
-
return;
|
|
4508
|
-
}
|
|
4509
|
-
const n = node;
|
|
4510
|
-
visitor(n);
|
|
4511
|
-
for (const key of Object.keys(n)) {
|
|
4512
|
-
if (key === "loc" || key === "comments") continue;
|
|
4513
|
-
const child = n[key];
|
|
4514
|
-
if (child && typeof child === "object") visit(child);
|
|
4515
|
-
}
|
|
4516
|
-
};
|
|
4517
|
-
visit(root);
|
|
4518
|
-
}
|
|
4519
4812
|
//#endregion
|
|
4520
4813
|
//#region src/internal/emit-wrappers/types.ts
|
|
4521
4814
|
/**
|
|
@@ -4835,38 +5128,30 @@ function buildChildStyleObjectList(childKeys, resolvedStyleObjects) {
|
|
|
4835
5128
|
//#region src/internal/utilities/style-composition-plan.ts
|
|
4836
5129
|
function buildStyleKeySequence(ctx, decl, options) {
|
|
4837
5130
|
const entries = [];
|
|
4838
|
-
const
|
|
5131
|
+
const extraEntries = buildExtraStyleEntries(decl);
|
|
4839
5132
|
if (options?.includeLocalBase !== false) for (const styleKey of localBaseStyleKeys(ctx, decl)) entries.push({
|
|
4840
5133
|
styleKey,
|
|
4841
5134
|
patchable: false,
|
|
4842
5135
|
source: "base"
|
|
4843
5136
|
});
|
|
4844
|
-
|
|
4845
|
-
styleKey,
|
|
4846
|
-
patchable: false,
|
|
4847
|
-
source: "mixin"
|
|
4848
|
-
});
|
|
5137
|
+
entries.push(...extraEntries.beforeBase);
|
|
4849
5138
|
if (!decl.skipBaseStyleRef) entries.push({
|
|
4850
5139
|
styleKey: decl.styleKey,
|
|
4851
5140
|
patchable: true,
|
|
4852
5141
|
source: "base"
|
|
4853
5142
|
});
|
|
4854
|
-
|
|
4855
|
-
styleKey,
|
|
4856
|
-
patchable: true,
|
|
4857
|
-
source: "mixin"
|
|
4858
|
-
});
|
|
5143
|
+
entries.push(...extraEntries.afterBase);
|
|
4859
5144
|
const variantAndStyleFnEntries = buildVariantAndStyleFnEntries(decl);
|
|
4860
5145
|
const variantDimensionEntries = buildVariantDimensionEntries(decl);
|
|
4861
5146
|
entries.push(...variantAndStyleFnEntries.immediate);
|
|
4862
5147
|
entries.push(...variantDimensionEntries.immediate);
|
|
4863
|
-
entries.push(...buildExtraStylexPropsArgEntries(decl));
|
|
4864
5148
|
entries.push(...buildThemeEntries(decl));
|
|
4865
5149
|
entries.push(...buildAttrWrapperEntries(decl));
|
|
4866
5150
|
entries.push(...buildPseudoExpandEntries(decl));
|
|
4867
5151
|
entries.push(...buildPseudoAliasEntries(decl));
|
|
4868
5152
|
entries.push(...buildCompoundVariantEntries(decl));
|
|
4869
5153
|
entries.push(...mergeOrderedEntries$1([variantDimensionEntries.ordered, variantAndStyleFnEntries.ordered]));
|
|
5154
|
+
entries.push(...extraEntries.afterVariants);
|
|
4870
5155
|
entries.push(...buildEnumVariantEntries(decl));
|
|
4871
5156
|
entries.push(...buildCallSiteCombinedEntries(decl));
|
|
4872
5157
|
entries.push(...buildPromotedStyleEntries(decl));
|
|
@@ -4877,13 +5162,89 @@ function buildStyleKeySequence(ctx, decl, options) {
|
|
|
4877
5162
|
});
|
|
4878
5163
|
return entries;
|
|
4879
5164
|
}
|
|
4880
|
-
function
|
|
4881
|
-
|
|
5165
|
+
function buildExtraStyleEntries(decl) {
|
|
5166
|
+
const groups = {
|
|
5167
|
+
beforeBase: [],
|
|
5168
|
+
afterBase: [],
|
|
5169
|
+
afterVariants: []
|
|
5170
|
+
};
|
|
5171
|
+
const mixinOrder = decl.mixinOrder;
|
|
5172
|
+
const extraStyleKeys = decl.extraStyleKeys ?? [];
|
|
5173
|
+
const propsArgs = (decl.extraStylexPropsArgs ?? []).map((arg, index) => ({
|
|
5174
|
+
arg,
|
|
5175
|
+
index
|
|
5176
|
+
}));
|
|
5177
|
+
const afterBaseKeys = new Set(decl.extraStyleKeysAfterBase ?? []);
|
|
5178
|
+
if (!mixinOrder || mixinOrder.length === 0) {
|
|
5179
|
+
for (const styleKey of extraStyleKeys) {
|
|
5180
|
+
const entry = styleKeyEntry(styleKey, afterBaseKeys.has(styleKey));
|
|
5181
|
+
if (afterBaseKeys.has(styleKey)) groups.afterBase.push(entry);
|
|
5182
|
+
else groups.beforeBase.push(entry);
|
|
5183
|
+
}
|
|
5184
|
+
for (const propsArg of propsArgs) pushPropsArgEntry(groups, decl, propsArg.index, "afterBase");
|
|
5185
|
+
return groups;
|
|
5186
|
+
}
|
|
5187
|
+
let styleKeyIndex = 0;
|
|
5188
|
+
let propsArgIndex = 0;
|
|
5189
|
+
for (const entryKind of mixinOrder) if (entryKind === "styleKey" && styleKeyIndex < extraStyleKeys.length) {
|
|
5190
|
+
pushStyleKeyEntry(groups, extraStyleKeys[styleKeyIndex], afterBaseKeys);
|
|
5191
|
+
styleKeyIndex += 1;
|
|
5192
|
+
} else if (entryKind === "propsArg" && propsArgIndex < propsArgs.length) propsArgIndex = pushPropsArgsThroughNextUnconditional({
|
|
5193
|
+
groups,
|
|
5194
|
+
decl,
|
|
5195
|
+
propsArgs,
|
|
5196
|
+
propsArgIndex,
|
|
5197
|
+
fallbackGroup: "beforeBase"
|
|
5198
|
+
});
|
|
5199
|
+
for (; styleKeyIndex < extraStyleKeys.length; styleKeyIndex++) pushStyleKeyEntry(groups, extraStyleKeys[styleKeyIndex], afterBaseKeys);
|
|
5200
|
+
for (; propsArgIndex < propsArgs.length; propsArgIndex++) {
|
|
5201
|
+
const propsArg = propsArgs[propsArgIndex];
|
|
5202
|
+
if (propsArg) pushPropsArgEntry(groups, decl, propsArg.index, "afterBase");
|
|
5203
|
+
}
|
|
5204
|
+
return groups;
|
|
5205
|
+
}
|
|
5206
|
+
function pushPropsArgsThroughNextUnconditional(args) {
|
|
5207
|
+
let propsArgIndex = args.propsArgIndex;
|
|
5208
|
+
while (propsArgIndex < args.propsArgs.length) {
|
|
5209
|
+
const propsArg = args.propsArgs[propsArgIndex];
|
|
5210
|
+
if (!propsArg?.arg.when) break;
|
|
5211
|
+
pushPropsArgEntry(args.groups, args.decl, propsArg.index, args.fallbackGroup);
|
|
5212
|
+
propsArgIndex += 1;
|
|
5213
|
+
}
|
|
5214
|
+
const propsArg = args.propsArgs[propsArgIndex];
|
|
5215
|
+
if (propsArg) {
|
|
5216
|
+
pushPropsArgEntry(args.groups, args.decl, propsArg.index, args.fallbackGroup);
|
|
5217
|
+
propsArgIndex += 1;
|
|
5218
|
+
}
|
|
5219
|
+
return propsArgIndex;
|
|
5220
|
+
}
|
|
5221
|
+
function pushStyleKeyEntry(groups, styleKey, afterBaseKeys) {
|
|
5222
|
+
const afterBase = afterBaseKeys.has(styleKey);
|
|
5223
|
+
const entry = styleKeyEntry(styleKey, afterBase);
|
|
5224
|
+
if (afterBase) groups.afterBase.push(entry);
|
|
5225
|
+
else groups.beforeBase.push(entry);
|
|
5226
|
+
}
|
|
5227
|
+
function pushPropsArgEntry(groups, decl, index, fallbackGroup) {
|
|
5228
|
+
const arg = decl.extraStylexPropsArgs?.[index];
|
|
5229
|
+
const entry = propsArgEntry(decl, index);
|
|
5230
|
+
if (arg?.afterVariants) groups.afterVariants.push(entry);
|
|
5231
|
+
else if (arg?.afterBase || fallbackGroup === "afterBase") groups.afterBase.push(entry);
|
|
5232
|
+
else groups.beforeBase.push(entry);
|
|
5233
|
+
}
|
|
5234
|
+
function styleKeyEntry(styleKey, patchable) {
|
|
5235
|
+
return {
|
|
5236
|
+
styleKey,
|
|
5237
|
+
patchable,
|
|
5238
|
+
source: "mixin"
|
|
5239
|
+
};
|
|
5240
|
+
}
|
|
5241
|
+
function propsArgEntry(decl, index) {
|
|
5242
|
+
return {
|
|
4882
5243
|
styleKey: `${decl.styleKey}ExtraStylexPropsArg${index}`,
|
|
4883
5244
|
patchable: false,
|
|
4884
5245
|
contributesDynamic: true,
|
|
4885
5246
|
source: "propsArg"
|
|
4886
|
-
}
|
|
5247
|
+
};
|
|
4887
5248
|
}
|
|
4888
5249
|
function localBaseStyleKeys(ctx, decl) {
|
|
4889
5250
|
if (decl.extendsStyleKey) return [decl.extendsStyleKey];
|
|
@@ -5869,16 +6230,7 @@ function walk(node, visit, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
5869
6230
|
//#endregion
|
|
5870
6231
|
//#region src/internal/transform-steps/analyze-before-emit.ts
|
|
5871
6232
|
const INLINE_USAGE_THRESHOLD = 1;
|
|
5872
|
-
const
|
|
5873
|
-
const REACT_WINDOW_ELEMENT_TYPE_PROPS = new Set(["innerElementType", "outerElementType"]);
|
|
5874
|
-
const REACT_WINDOW_COMPONENT_EXPORTS = new Set([
|
|
5875
|
-
"FixedSizeGrid",
|
|
5876
|
-
"FixedSizeList",
|
|
5877
|
-
"Grid",
|
|
5878
|
-
"List",
|
|
5879
|
-
"VariableSizeGrid",
|
|
5880
|
-
"VariableSizeList"
|
|
5881
|
-
]);
|
|
6233
|
+
const ELEMENT_TYPE_PROP_NAMES = new Set(["innerElementType", "outerElementType"]);
|
|
5882
6234
|
/**
|
|
5883
6235
|
* Analyzes declarations to determine wrappers, exports, usage patterns, and import aliasing before emit.
|
|
5884
6236
|
*/
|
|
@@ -5957,6 +6309,7 @@ function analyzeBeforeEmitStep(ctx) {
|
|
|
5957
6309
|
};
|
|
5958
6310
|
const isUsedInJsx = (name) => getJsxUsageCount(name) > 0;
|
|
5959
6311
|
const canInlineImportedComponentWrapper = (decl) => {
|
|
6312
|
+
if (decl.base.kind === "component" && wrappedComponentInterfaceFor(ctx, decl.base.ident)?.sxTarget === "inner") return false;
|
|
5960
6313
|
if (decl.variantStyleKeys && Object.keys(decl.variantStyleKeys).length > 0) return false;
|
|
5961
6314
|
if (decl.variantDimensions && decl.variantDimensions.length > 0 && !decl.inlinedBaseComponent?.hasInlineJsxVariants) return false;
|
|
5962
6315
|
if (decl.inlineStyleProps && decl.inlineStyleProps.length > 0) return false;
|
|
@@ -6030,32 +6383,66 @@ function analyzeBeforeEmitStep(ctx) {
|
|
|
6030
6383
|
const { className, style, ref } = getJsxAttributeUsage(targetDecl.localName);
|
|
6031
6384
|
return targetDecl.base.kind === "intrinsic" && !targetDecl.isExported && !targetDecl.needsWrapperComponent && !className && !style && !ref && !hasSpreadInJsx(root, j, targetDecl.localName);
|
|
6032
6385
|
};
|
|
6033
|
-
const nonJsxComponentValueReferences = (name) => root.find(j.Identifier, { name }).filter((p) =>
|
|
6034
|
-
if (p.parentPath?.node?.type === "VariableDeclarator" && p.parentPath.node.id === p.node) return false;
|
|
6035
|
-
if (p.parentPath?.node?.type === "JSXOpeningElement" || p.parentPath?.node?.type === "JSXClosingElement") return false;
|
|
6036
|
-
if (p.parentPath?.node?.type === "JSXMemberExpression" && p.parentPath.node.object === p.node) return false;
|
|
6037
|
-
if (p.parentPath?.node?.type === "CallExpression") {
|
|
6038
|
-
const callee = p.parentPath.node.callee;
|
|
6039
|
-
if (callee?.type === "Identifier" && callee.name === ctx.styledDefaultImport) return false;
|
|
6040
|
-
if (callee?.type === "MemberExpression" && callee.object?.type === "CallExpression" && callee.object.callee?.type === "Identifier" && callee.object.callee.name === ctx.styledDefaultImport) return false;
|
|
6041
|
-
}
|
|
6042
|
-
if (p.parentPath?.node?.type === "TaggedTemplateExpression") return false;
|
|
6043
|
-
if (p.parentPath?.node?.type === "CallExpression" && p.parentPath.parentPath?.node?.type === "TaggedTemplateExpression") return false;
|
|
6044
|
-
if (p.parentPath?.node?.type === "TemplateLiteral") return false;
|
|
6045
|
-
return true;
|
|
6046
|
-
});
|
|
6386
|
+
const nonJsxComponentValueReferences = (name) => root.find(j.Identifier, { name }).filter((p) => isNonJsxStyledValueReferencePath(p, ctx.styledDefaultImport));
|
|
6047
6387
|
const hasNonJsxComponentValueReference = (name) => nonJsxComponentValueReferences(name).size() > 0;
|
|
6048
|
-
const
|
|
6388
|
+
const hasOnlyElementTypePropValueReferences = (name) => {
|
|
6049
6389
|
const refs = nonJsxComponentValueReferences(name);
|
|
6050
6390
|
if (refs.size() === 0) return false;
|
|
6051
|
-
let
|
|
6391
|
+
let onlyElementTypeProp = true;
|
|
6052
6392
|
refs.forEach((p) => {
|
|
6053
|
-
const
|
|
6054
|
-
const
|
|
6055
|
-
const
|
|
6056
|
-
if (expressionContainer
|
|
6393
|
+
const usage = findContainingJsxAttributeExpression(p);
|
|
6394
|
+
const expressionContainer = usage?.expressionContainer;
|
|
6395
|
+
const attr = usage?.attr;
|
|
6396
|
+
if (!isNodeOfType(expressionContainer, "JSXExpressionContainer") || !isNodeOfType(attr, "JSXAttribute") || !isNodeOfType(attr.name, "JSXIdentifier") || typeof attr.name.name !== "string" || !ELEMENT_TYPE_PROP_NAMES.has(attr.name.name)) onlyElementTypeProp = false;
|
|
6397
|
+
});
|
|
6398
|
+
return onlyElementTypeProp;
|
|
6399
|
+
};
|
|
6400
|
+
const findContainingJsxAttributeExpression = (path) => {
|
|
6401
|
+
let current = path.parentPath;
|
|
6402
|
+
while (current) {
|
|
6403
|
+
const node = current.node;
|
|
6404
|
+
if (node?.type === "JSXExpressionContainer") {
|
|
6405
|
+
const attrPath = current.parentPath;
|
|
6406
|
+
return {
|
|
6407
|
+
expressionContainer: node,
|
|
6408
|
+
attr: attrPath?.node,
|
|
6409
|
+
attrPath
|
|
6410
|
+
};
|
|
6411
|
+
}
|
|
6412
|
+
if (node?.type === "JSXElement" || node?.type === "JSXOpeningElement" || node?.type === "Program") return null;
|
|
6413
|
+
current = current.parentPath;
|
|
6414
|
+
}
|
|
6415
|
+
return null;
|
|
6416
|
+
};
|
|
6417
|
+
const styleOnlyElementTypeHostCache = /* @__PURE__ */ new Map();
|
|
6418
|
+
const elementTypeHostsAreStyleOnly = (name) => {
|
|
6419
|
+
const refs = nonJsxComponentValueReferences(name);
|
|
6420
|
+
if (refs.size() === 0) return false;
|
|
6421
|
+
let allStyleOnly = true;
|
|
6422
|
+
refs.forEach((p) => {
|
|
6423
|
+
const openingElement = (findContainingJsxAttributeExpression(p)?.attrPath)?.parentPath?.node;
|
|
6424
|
+
if (!isNodeOfType(openingElement, "JSXOpeningElement")) {
|
|
6425
|
+
allStyleOnly = false;
|
|
6426
|
+
return;
|
|
6427
|
+
}
|
|
6428
|
+
const hostName = getRootJsxIdentifierName(openingElement.name);
|
|
6429
|
+
if (!hostName) {
|
|
6430
|
+
allStyleOnly = false;
|
|
6431
|
+
return;
|
|
6432
|
+
}
|
|
6433
|
+
let styleOnly = styleOnlyElementTypeHostCache.get(hostName);
|
|
6434
|
+
if (styleOnly === void 0) {
|
|
6435
|
+
styleOnly = isStyleOnlyElementTypeHost({
|
|
6436
|
+
j,
|
|
6437
|
+
root,
|
|
6438
|
+
hostName,
|
|
6439
|
+
elementTypePropNames: ELEMENT_TYPE_PROP_NAMES
|
|
6440
|
+
});
|
|
6441
|
+
styleOnlyElementTypeHostCache.set(hostName, styleOnly);
|
|
6442
|
+
}
|
|
6443
|
+
if (!styleOnly) allStyleOnly = false;
|
|
6057
6444
|
});
|
|
6058
|
-
return
|
|
6445
|
+
return allStyleOnly;
|
|
6059
6446
|
};
|
|
6060
6447
|
for (const decl of styledDecls) {
|
|
6061
6448
|
if (!decl.adjacentSiblingStyleKey) continue;
|
|
@@ -6282,7 +6669,7 @@ function analyzeBeforeEmitStep(ctx) {
|
|
|
6282
6669
|
const declNamespaceName = getDeclNamespaceName(root, j, decl.localName);
|
|
6283
6670
|
if (collectReferencedTypeNames(decl.propsType).some((name) => isTypeNameUsedElsewhere(root, j, name, decl.localName, declNamespaceName) || !isTypeLocallyDefined(root, j, name))) continue;
|
|
6284
6671
|
const propsToSkip = [];
|
|
6285
|
-
for (const prop of renames.keys()) if (isModuleScopeBinding(root, j, prop, decl.localName) || resolverImportNames.has(prop)) propsToSkip.push(prop);
|
|
6672
|
+
for (const prop of renames.keys()) if ((isModuleScopeBinding(root, j, prop, decl.localName) || resolverImportNames.has(prop)) && (!transientRenameHasNormalizedPropUsage(decl, prop) || transientRenameWouldTouchExpressionIdentifier(decl, prop) || transientRenameWouldTouchResolvedStyleObject(decl, prop, ctx.resolvedStyleObjects))) propsToSkip.push(prop);
|
|
6286
6673
|
for (const prop of propsToSkip) renames.delete(prop);
|
|
6287
6674
|
if (renames.size === 0) continue;
|
|
6288
6675
|
decl.transientPropRenames = renames;
|
|
@@ -6324,13 +6711,35 @@ function analyzeBeforeEmitStep(ctx) {
|
|
|
6324
6711
|
}
|
|
6325
6712
|
}
|
|
6326
6713
|
for (const decl of styledDecls) {
|
|
6714
|
+
if (canInlinePrivateMemberBaseJsx(decl)) {
|
|
6715
|
+
decl.isDirectJsxResolution = true;
|
|
6716
|
+
decl.needsWrapperComponent = false;
|
|
6717
|
+
continue;
|
|
6718
|
+
}
|
|
6327
6719
|
if (decl.isDirectJsxResolution) continue;
|
|
6328
6720
|
if (hasNonJsxComponentValueReference(decl.localName)) {
|
|
6329
6721
|
decl.usedAsValue = true;
|
|
6330
|
-
if (
|
|
6722
|
+
if (hasOnlyElementTypePropValueReferences(decl.localName) && elementTypeHostsAreStyleOnly(decl.localName)) {
|
|
6723
|
+
decl.valueUsageKind = "elementTypeProp";
|
|
6724
|
+
if (!exportedComponents.has(decl.localName)) {
|
|
6725
|
+
decl.supportsExternalStyles = false;
|
|
6726
|
+
decl.consumerUsesClassName = false;
|
|
6727
|
+
decl.consumerUsesStyle = false;
|
|
6728
|
+
decl.consumerUsesElementProps = false;
|
|
6729
|
+
decl.consumerUsesSpread = false;
|
|
6730
|
+
}
|
|
6731
|
+
}
|
|
6331
6732
|
decl.needsWrapperComponent = true;
|
|
6332
6733
|
}
|
|
6333
6734
|
}
|
|
6735
|
+
function canInlinePrivateMemberBaseJsx(decl) {
|
|
6736
|
+
if (decl.base.kind !== "component" || !decl.base.ident.includes(".") || decl.isExported || exportedComponents.has(decl.localName) || decl.propsType || decl.attrsInfo || decl.usedAsValue || hasNonJsxComponentValueReference(decl.localName) || decl.supportsExternalStyles || decl.supportsAsProp || decl.supportsRefProp || decl.consumerUsesSpread || decl.consumerUsesClassName || decl.consumerUsesStyle || decl.consumerUsesElementProps || decl.isCssHelper || decl.rules.some((rule) => rule.selector.trim() !== "&")) return false;
|
|
6737
|
+
if (!canInlineImportedComponentWrapper(decl) || hasDynamicPropStyling(decl)) return false;
|
|
6738
|
+
return getJsxUsageCount(decl.localName) === 1;
|
|
6739
|
+
}
|
|
6740
|
+
function hasDynamicPropStyling(decl) {
|
|
6741
|
+
return !!((decl.styleFnFromProps?.length ?? 0) > 0 || (decl.variantDimensions?.length ?? 0) > 0 || (decl.compoundVariants?.length ?? 0) > 0 || (decl.transientPropRenames?.size ?? 0) > 0 || (decl.observedExpressionConditionDropProps?.size ?? 0) > 0 || (decl.styleValueVariantProps?.size ?? 0) > 0);
|
|
6742
|
+
}
|
|
6334
6743
|
const jsxNamespaceRoots = /* @__PURE__ */ new Set();
|
|
6335
6744
|
root.find(j.JSXMemberExpression).forEach((p) => {
|
|
6336
6745
|
const rootName = getRootJsxIdentifierName(p.node);
|
|
@@ -7148,6 +7557,44 @@ function renameIdentifiersInAst(node, renames) {
|
|
|
7148
7557
|
else if (value && typeof value === "object") renameIdentifiersInAst(value, renames);
|
|
7149
7558
|
}
|
|
7150
7559
|
}
|
|
7560
|
+
function transientRenameWouldTouchExpressionIdentifier(decl, propName) {
|
|
7561
|
+
for (const styleFn of decl.styleFnFromProps ?? []) {
|
|
7562
|
+
if (astContainsIdentifier(styleFn.callArg, propName)) return true;
|
|
7563
|
+
for (const extra of styleFn.extraCallArgs ?? []) if (astContainsIdentifier(extra.callArg, propName)) return true;
|
|
7564
|
+
}
|
|
7565
|
+
for (const inlineStyle of decl.inlineStyleProps ?? []) if (astContainsIdentifier(inlineStyle.expr, propName)) return true;
|
|
7566
|
+
return false;
|
|
7567
|
+
}
|
|
7568
|
+
function transientRenameWouldTouchResolvedStyleObject(decl, propName, resolvedStyleObjects) {
|
|
7569
|
+
if (!resolvedStyleObjects) return false;
|
|
7570
|
+
for (const styleKey of collectAllStyleKeysForDecl(decl)) {
|
|
7571
|
+
const value = resolvedStyleObjects.get(styleKey);
|
|
7572
|
+
if (value && typeof value === "object" && astContainsIdentifier(value, propName)) return true;
|
|
7573
|
+
}
|
|
7574
|
+
return false;
|
|
7575
|
+
}
|
|
7576
|
+
function transientRenameHasNormalizedPropUsage(decl, propName) {
|
|
7577
|
+
const normalized = propName.startsWith("$") ? propName.slice(1) : propName;
|
|
7578
|
+
for (const styleFn of decl.styleFnFromProps ?? []) {
|
|
7579
|
+
if (astContainsIdentifier(styleFn.callArg, normalized)) return true;
|
|
7580
|
+
for (const extra of styleFn.extraCallArgs ?? []) if (astContainsIdentifier(extra.callArg, normalized)) return true;
|
|
7581
|
+
}
|
|
7582
|
+
for (const inlineStyle of decl.inlineStyleProps ?? []) if (astContainsIdentifier(inlineStyle.expr, normalized)) return true;
|
|
7583
|
+
return false;
|
|
7584
|
+
}
|
|
7585
|
+
function astContainsIdentifier(node, name) {
|
|
7586
|
+
if (!node || typeof node !== "object") return false;
|
|
7587
|
+
const n = node;
|
|
7588
|
+
if (typeof n.type !== "string") return false;
|
|
7589
|
+
if (n.type === "Identifier" && n.name === name) return true;
|
|
7590
|
+
for (const [key, value] of Object.entries(n)) {
|
|
7591
|
+
if (AST_METADATA_KEYS.has(key)) continue;
|
|
7592
|
+
if (Array.isArray(value)) {
|
|
7593
|
+
if (value.some((item) => astContainsIdentifier(item, name))) return true;
|
|
7594
|
+
} else if (value && typeof value === "object" && astContainsIdentifier(value, name)) return true;
|
|
7595
|
+
}
|
|
7596
|
+
return false;
|
|
7597
|
+
}
|
|
7151
7598
|
/**
|
|
7152
7599
|
* Renames `$`-prefixed members in interface/type alias declarations
|
|
7153
7600
|
* referenced by a propsType AST node.
|
|
@@ -8367,7 +8814,8 @@ function validateWrappedComponentStyleChannels(ctx, styledDecls) {
|
|
|
8367
8814
|
if (!importInfo && !isLocalNonStyledWrappedComponent) continue;
|
|
8368
8815
|
if (importInfo?.source.kind === "absolutePath" && ctx.options.transformedFileSources?.has(resolveExistingFilePath(importInfo.source.value))) continue;
|
|
8369
8816
|
if (!declHasEmittedStyle(ctx, decl)) continue;
|
|
8370
|
-
|
|
8817
|
+
const componentInterface = wrappedComponentInterfaceFor(ctx, baseIdent);
|
|
8818
|
+
if (componentInterface?.acceptsSx === true && componentInterface.sxTarget !== "inner") continue;
|
|
8371
8819
|
const metadata = findWrappedComponentMetadata(ctx, baseIdent);
|
|
8372
8820
|
if (!metadata || componentAcceptsStylexClassName(metadata)) continue;
|
|
8373
8821
|
if (isLocalNonStyledWrappedComponent && !hasInlineObjectPropType(metadata)) continue;
|
|
@@ -8430,26 +8878,6 @@ function staticObjectPropertyName(prop) {
|
|
|
8430
8878
|
if (key.type === "Literal" || key.type === "StringLiteral") return typeof key.value === "string" ? key.value : null;
|
|
8431
8879
|
return null;
|
|
8432
8880
|
}
|
|
8433
|
-
function isKnownReactWindowElementTypeAttribute(attrPath, importMap) {
|
|
8434
|
-
const openingElement = attrPath?.parentPath?.node;
|
|
8435
|
-
if (openingElement?.type !== "JSXOpeningElement") return false;
|
|
8436
|
-
return jsxNameIsKnownReactWindowComponent(openingElement.name, importMap);
|
|
8437
|
-
}
|
|
8438
|
-
function jsxNameIsKnownReactWindowComponent(jsxName, importMap) {
|
|
8439
|
-
const name = jsxName;
|
|
8440
|
-
if (name.type === "JSXIdentifier") return localNameIsReactWindowComponent(name.name, importMap);
|
|
8441
|
-
if (name.type !== "JSXMemberExpression") return false;
|
|
8442
|
-
const namespace = name.object;
|
|
8443
|
-
const member = name.property;
|
|
8444
|
-
if (namespace?.type !== "JSXIdentifier" || member?.type !== "JSXIdentifier" || !REACT_WINDOW_COMPONENT_EXPORTS.has(member.name ?? "")) return false;
|
|
8445
|
-
const importInfo = namespace.name ? importMap?.get(namespace.name) : void 0;
|
|
8446
|
-
return importInfo?.source.value === REACT_WINDOW_SOURCE && importInfo.importedName === "*";
|
|
8447
|
-
}
|
|
8448
|
-
function localNameIsReactWindowComponent(localName, importMap) {
|
|
8449
|
-
if (!localName) return false;
|
|
8450
|
-
const importInfo = importMap?.get(localName);
|
|
8451
|
-
return importInfo?.source.value === REACT_WINDOW_SOURCE && REACT_WINDOW_COMPONENT_EXPORTS.has(importInfo.importedName);
|
|
8452
|
-
}
|
|
8453
8881
|
function isStylexConditionKey(key) {
|
|
8454
8882
|
return key === "default" || key === "__computedKeys" || key.startsWith(":") || key.startsWith("@") || key.startsWith("stylex.when");
|
|
8455
8883
|
}
|
|
@@ -8678,7 +9106,9 @@ function normalizeStylisAstToIR(stylisAst, slots, options = {}) {
|
|
|
8678
9106
|
const rules = [];
|
|
8679
9107
|
const atRuleStack = [];
|
|
8680
9108
|
let pendingComment = null;
|
|
9109
|
+
let pendingLineComment = null;
|
|
8681
9110
|
let lastDecl = null;
|
|
9111
|
+
let lineCommentCursor = 0;
|
|
8682
9112
|
const stripBlockComment = (raw) => {
|
|
8683
9113
|
const trimmed = raw.trim();
|
|
8684
9114
|
if (trimmed.startsWith("/*") && trimmed.endsWith("*/")) return trimmed.slice(2, -2).trim();
|
|
@@ -8703,11 +9133,48 @@ function normalizeStylisAstToIR(stylisAst, slots, options = {}) {
|
|
|
8703
9133
|
}
|
|
8704
9134
|
return false;
|
|
8705
9135
|
};
|
|
9136
|
+
const appendLineComment = (existing, next) => existing ? `${existing}\n${next}` : next;
|
|
9137
|
+
const findRawLineCommentPlacement = (body) => {
|
|
9138
|
+
if (!rawCss) return null;
|
|
9139
|
+
let searchStart = lineCommentCursor;
|
|
9140
|
+
while (searchStart < rawCss.length) {
|
|
9141
|
+
const idx = rawCss.indexOf("//", searchStart);
|
|
9142
|
+
if (idx === -1) return null;
|
|
9143
|
+
const nextLf = rawCss.indexOf("\n", idx);
|
|
9144
|
+
const nextCr = rawCss.indexOf("\r", idx);
|
|
9145
|
+
const newlineIdx = nextLf === -1 ? nextCr : nextCr === -1 ? nextLf : Math.min(nextLf, nextCr);
|
|
9146
|
+
const lineEnd = newlineIdx === -1 ? rawCss.length : newlineIdx;
|
|
9147
|
+
if (rawCss.slice(idx + 2, lineEnd).trim() !== body.trim()) {
|
|
9148
|
+
searchStart = idx + 2;
|
|
9149
|
+
continue;
|
|
9150
|
+
}
|
|
9151
|
+
lineCommentCursor = lineEnd;
|
|
9152
|
+
const previousLf = rawCss.lastIndexOf("\n", idx - 1);
|
|
9153
|
+
const previousCr = rawCss.lastIndexOf("\r", idx - 1);
|
|
9154
|
+
const lineStart = Math.max(previousLf, previousCr) + 1;
|
|
9155
|
+
return rawCss.slice(lineStart, idx).trim() ? "trailing" : "leading";
|
|
9156
|
+
}
|
|
9157
|
+
return null;
|
|
9158
|
+
};
|
|
9159
|
+
const attachPendingComments = (decl) => {
|
|
9160
|
+
if (pendingComment) {
|
|
9161
|
+
decl.leadingComment = pendingComment;
|
|
9162
|
+
pendingComment = null;
|
|
9163
|
+
}
|
|
9164
|
+
if (pendingLineComment) {
|
|
9165
|
+
decl.leadingLineComment = appendLineComment(decl.leadingLineComment, pendingLineComment);
|
|
9166
|
+
pendingLineComment = null;
|
|
9167
|
+
}
|
|
9168
|
+
};
|
|
8706
9169
|
const handleCommentNode = (raw) => {
|
|
8707
9170
|
const body = stripBlockComment(raw);
|
|
8708
9171
|
if (isPrettierIgnoreComment(body)) return;
|
|
8709
|
-
if (
|
|
8710
|
-
lastDecl
|
|
9172
|
+
if (isStylisConvertedLineComment(raw)) {
|
|
9173
|
+
if (findRawLineCommentPlacement(body) === "leading" || !lastDecl) {
|
|
9174
|
+
pendingLineComment = appendLineComment(pendingLineComment, body);
|
|
9175
|
+
return;
|
|
9176
|
+
}
|
|
9177
|
+
lastDecl.trailingLineComment = appendLineComment(lastDecl.trailingLineComment, body);
|
|
8711
9178
|
return;
|
|
8712
9179
|
}
|
|
8713
9180
|
if (lastDecl && isInlineTrailingBlockCommentInRawCss(raw)) {
|
|
@@ -8741,10 +9208,7 @@ function normalizeStylisAstToIR(stylisAst, slots, options = {}) {
|
|
|
8741
9208
|
const decls = parseDeclarations(String(node.value ?? ""), slotByPlaceholder);
|
|
8742
9209
|
const firstDecl = decls[0];
|
|
8743
9210
|
if (decls.length && firstDecl) {
|
|
8744
|
-
|
|
8745
|
-
firstDecl.leadingComment = pendingComment;
|
|
8746
|
-
pendingComment = null;
|
|
8747
|
-
}
|
|
9211
|
+
attachPendingComments(firstDecl);
|
|
8748
9212
|
ensureRule("&", atRuleStack).declarations.push(...decls);
|
|
8749
9213
|
lastDecl = decls[decls.length - 1] ?? null;
|
|
8750
9214
|
}
|
|
@@ -8752,8 +9216,10 @@ function normalizeStylisAstToIR(stylisAst, slots, options = {}) {
|
|
|
8752
9216
|
}
|
|
8753
9217
|
if (node.type === "rule") {
|
|
8754
9218
|
const prevPending = pendingComment;
|
|
9219
|
+
const prevPendingLine = pendingLineComment;
|
|
8755
9220
|
const prevLastDecl = lastDecl;
|
|
8756
9221
|
pendingComment = null;
|
|
9222
|
+
pendingLineComment = null;
|
|
8757
9223
|
lastDecl = null;
|
|
8758
9224
|
const selectorValue = String(node.value ?? "");
|
|
8759
9225
|
const selectorRaw = stripFormFeedInSelectors ? selectorValue.replaceAll("\f", "") : selectorValue;
|
|
@@ -8772,10 +9238,7 @@ function normalizeStylisAstToIR(stylisAst, slots, options = {}) {
|
|
|
8772
9238
|
const decls = parseDeclarations(String(child.value ?? ""), slotByPlaceholder);
|
|
8773
9239
|
const firstDeclInner = decls[0];
|
|
8774
9240
|
if (decls.length && firstDeclInner) {
|
|
8775
|
-
|
|
8776
|
-
firstDeclInner.leadingComment = pendingComment;
|
|
8777
|
-
pendingComment = null;
|
|
8778
|
-
}
|
|
9241
|
+
attachPendingComments(firstDeclInner);
|
|
8779
9242
|
rule.declarations.push(...decls);
|
|
8780
9243
|
lastDecl = decls[decls.length - 1] ?? null;
|
|
8781
9244
|
}
|
|
@@ -8791,10 +9254,7 @@ function normalizeStylisAstToIR(stylisAst, slots, options = {}) {
|
|
|
8791
9254
|
const decls = parseDeclarations(String(atChild.value ?? ""), slotByPlaceholder);
|
|
8792
9255
|
const firstDeclInner = decls[0];
|
|
8793
9256
|
if (decls.length && firstDeclInner) {
|
|
8794
|
-
|
|
8795
|
-
firstDeclInner.leadingComment = pendingComment;
|
|
8796
|
-
pendingComment = null;
|
|
8797
|
-
}
|
|
9257
|
+
attachPendingComments(firstDeclInner);
|
|
8798
9258
|
nestedRule.declarations.push(...decls);
|
|
8799
9259
|
lastDecl = decls[decls.length - 1] ?? null;
|
|
8800
9260
|
}
|
|
@@ -8805,6 +9265,7 @@ function normalizeStylisAstToIR(stylisAst, slots, options = {}) {
|
|
|
8805
9265
|
} else visit(child);
|
|
8806
9266
|
else visit(children);
|
|
8807
9267
|
pendingComment = prevPending;
|
|
9268
|
+
pendingLineComment = prevPendingLine;
|
|
8808
9269
|
lastDecl = prevLastDecl;
|
|
8809
9270
|
return;
|
|
8810
9271
|
}
|
|
@@ -11368,56 +11829,102 @@ function styledTemplateKey(localName, loc) {
|
|
|
11368
11829
|
}
|
|
11369
11830
|
//#endregion
|
|
11370
11831
|
//#region src/internal/utilities/format-output.ts
|
|
11371
|
-
|
|
11372
|
-
|
|
11373
|
-
|
|
11374
|
-
|
|
11375
|
-
|
|
11376
|
-
|
|
11377
|
-
|
|
11832
|
+
const STYLEX_CREATE_MARKER = "stylex.create({";
|
|
11833
|
+
function findStylexCreateBlockEnd(code, blockStart) {
|
|
11834
|
+
let depth = 1;
|
|
11835
|
+
let blockEnd = blockStart;
|
|
11836
|
+
let inString = null;
|
|
11837
|
+
let escaped = false;
|
|
11838
|
+
for (let i = blockStart; i < code.length && depth > 0; i++) {
|
|
11839
|
+
const ch = code[i];
|
|
11840
|
+
if (escaped) {
|
|
11841
|
+
escaped = false;
|
|
11842
|
+
continue;
|
|
11843
|
+
}
|
|
11844
|
+
if (ch === "\\") {
|
|
11845
|
+
escaped = true;
|
|
11846
|
+
continue;
|
|
11847
|
+
}
|
|
11848
|
+
if (inString) {
|
|
11849
|
+
if (ch === inString) inString = null;
|
|
11850
|
+
continue;
|
|
11851
|
+
}
|
|
11852
|
+
if (ch === "\"" || ch === "'" || ch === "`") {
|
|
11853
|
+
inString = ch;
|
|
11854
|
+
continue;
|
|
11855
|
+
}
|
|
11856
|
+
if (ch === "{") {
|
|
11857
|
+
depth++;
|
|
11858
|
+
continue;
|
|
11859
|
+
}
|
|
11860
|
+
if (ch === "}") {
|
|
11861
|
+
depth--;
|
|
11862
|
+
if (depth === 0) blockEnd = i;
|
|
11863
|
+
}
|
|
11864
|
+
}
|
|
11865
|
+
return blockEnd;
|
|
11866
|
+
}
|
|
11867
|
+
function transformStylexCreateBlocks(code, transformBlock) {
|
|
11378
11868
|
let result = "";
|
|
11379
11869
|
let pos = 0;
|
|
11380
11870
|
while (pos < code.length) {
|
|
11381
|
-
const markerIdx = code.indexOf(
|
|
11871
|
+
const markerIdx = code.indexOf(STYLEX_CREATE_MARKER, pos);
|
|
11382
11872
|
if (markerIdx === -1) {
|
|
11383
11873
|
result += code.slice(pos);
|
|
11384
11874
|
break;
|
|
11385
11875
|
}
|
|
11386
11876
|
result += code.slice(pos, markerIdx);
|
|
11387
|
-
const
|
|
11388
|
-
|
|
11389
|
-
|
|
11390
|
-
|
|
11391
|
-
|
|
11392
|
-
|
|
11393
|
-
|
|
11394
|
-
|
|
11395
|
-
|
|
11396
|
-
|
|
11397
|
-
|
|
11398
|
-
|
|
11399
|
-
|
|
11400
|
-
|
|
11401
|
-
|
|
11402
|
-
|
|
11403
|
-
|
|
11404
|
-
|
|
11405
|
-
|
|
11406
|
-
|
|
11407
|
-
|
|
11877
|
+
const blockEnd = findStylexCreateBlockEnd(code, markerIdx + 15);
|
|
11878
|
+
const blockContent = code.slice(markerIdx, blockEnd + 1);
|
|
11879
|
+
result += transformBlock(blockContent);
|
|
11880
|
+
pos = blockEnd + 1;
|
|
11881
|
+
}
|
|
11882
|
+
return result;
|
|
11883
|
+
}
|
|
11884
|
+
/**
|
|
11885
|
+
* Remove blank lines inside stylex.create({...}) blocks.
|
|
11886
|
+
* Finds each `stylex.create({` and tracks brace depth to the matching `})`,
|
|
11887
|
+
* then removes blank lines between properties within that region.
|
|
11888
|
+
*/
|
|
11889
|
+
function removeBlankLinesInStylexCreate(code) {
|
|
11890
|
+
return transformStylexCreateBlocks(code, (blockContent) => blockContent.replace(/(\n\s*\},)\n\n+(\s+(?:[a-zA-Z_$][a-zA-Z0-9_$]*|["'].*?["']|\d+|::[a-zA-Z-]+|@[a-zA-Z-]+|:[a-zA-Z-]+)\s*:)/g, "$1\n$2").replace(/,\n\n+(\s+(?:[a-zA-Z_$"']|\/\/|\/\*))/g, ",\n$1").replace(/content:\s+"\\"([\s\S]*?)\\""/g, "content: '\"$1\"'").replace(/content:\s+"'\s*([\s\S]*?)\s*'"/g, "content: '\"$1\"'"));
|
|
11891
|
+
}
|
|
11892
|
+
/**
|
|
11893
|
+
* Indents lines inside multiline template literal object values so each continuation
|
|
11894
|
+
* line is two spaces deeper than the property line that opens the template.
|
|
11895
|
+
*/
|
|
11896
|
+
function indentMultilineTemplateLiterals(code) {
|
|
11897
|
+
const lines = code.split("\n");
|
|
11898
|
+
const result = [];
|
|
11899
|
+
for (let i = 0; i < lines.length; i++) {
|
|
11900
|
+
const line = lines[i] ?? "";
|
|
11901
|
+
const openerMatch = line.match(/^(\s+).+:\s*`$/);
|
|
11902
|
+
if (!openerMatch) {
|
|
11903
|
+
result.push(line);
|
|
11904
|
+
continue;
|
|
11905
|
+
}
|
|
11906
|
+
const continuationIndent = `${openerMatch[1]} `;
|
|
11907
|
+
result.push(line);
|
|
11908
|
+
i++;
|
|
11909
|
+
while (i < lines.length) {
|
|
11910
|
+
const innerLine = lines[i] ?? "";
|
|
11911
|
+
const closeIdx = innerLine.lastIndexOf("`");
|
|
11912
|
+
if (closeIdx === -1) {
|
|
11913
|
+
result.push(continuationIndent + innerLine.trimStart());
|
|
11914
|
+
i++;
|
|
11408
11915
|
continue;
|
|
11409
11916
|
}
|
|
11410
|
-
|
|
11411
|
-
|
|
11412
|
-
|
|
11413
|
-
|
|
11414
|
-
}
|
|
11917
|
+
const content = innerLine.slice(0, closeIdx).trimStart();
|
|
11918
|
+
const afterBacktick = innerLine.slice(closeIdx);
|
|
11919
|
+
result.push(continuationIndent + content + afterBacktick);
|
|
11920
|
+
break;
|
|
11415
11921
|
}
|
|
11416
|
-
const cleaned = code.slice(markerIdx, blockEnd + 1).replace(/(\n\s*\},)\n\n+(\s+(?:[a-zA-Z_$][a-zA-Z0-9_$]*|["'].*?["']|\d+|::[a-zA-Z-]+|@[a-zA-Z-]+|:[a-zA-Z-]+)\s*:)/g, "$1\n$2").replace(/,\n\n+(\s+(?:[a-zA-Z_$"']|\/\/|\/\*))/g, ",\n$1").replace(/content:\s+"\\"([\s\S]*?)\\""/g, "content: '\"$1\"'").replace(/content:\s+"'\s*([\s\S]*?)\s*'"/g, "content: '\"$1\"'");
|
|
11417
|
-
result += cleaned;
|
|
11418
|
-
pos = blockEnd + 1;
|
|
11419
11922
|
}
|
|
11420
|
-
return result;
|
|
11923
|
+
return result.join("\n");
|
|
11924
|
+
}
|
|
11925
|
+
/** Applies multiline template literal indentation only inside `stylex.create({...})` blocks. */
|
|
11926
|
+
function indentMultilineTemplateLiteralsInStylexCreate(code) {
|
|
11927
|
+
return transformStylexCreateBlocks(code, indentMultilineTemplateLiterals);
|
|
11421
11928
|
}
|
|
11422
11929
|
function formatOutput(code) {
|
|
11423
11930
|
let out = removeBlankLinesInStylexCreate(code);
|
|
@@ -11471,6 +11978,7 @@ function formatOutput(code) {
|
|
|
11471
11978
|
return lines.join("\n");
|
|
11472
11979
|
})();
|
|
11473
11980
|
out = out.replace(/(^\s+const\s+\{[^}]*\} = props;\n)\n(\s+)/gm, "$1$2");
|
|
11981
|
+
out = indentMultilineTemplateLiteralsInStylexCreate(out);
|
|
11474
11982
|
return out.trimEnd() + "\n";
|
|
11475
11983
|
}
|
|
11476
11984
|
//#endregion
|
|
@@ -11584,18 +12092,172 @@ function collectStyledDeclsStep(ctx) {
|
|
|
11584
12092
|
return CONTINUE;
|
|
11585
12093
|
}
|
|
11586
12094
|
//#endregion
|
|
12095
|
+
//#region src/internal/utilities/css-authored-multiline.ts
|
|
12096
|
+
/** Extra indent for continuation lines relative to the property line that opens the template literal. */
|
|
12097
|
+
const MULTILINE_INDENT = " ";
|
|
12098
|
+
function isTemplateLiteralNode(node) {
|
|
12099
|
+
return isAstNode(node) && node.type === "TemplateLiteral";
|
|
12100
|
+
}
|
|
12101
|
+
function normalizeValueForMatch(value) {
|
|
12102
|
+
return value.replace(/\s+/g, " ").replace(/\s*,\s*/g, ",").trim();
|
|
12103
|
+
}
|
|
12104
|
+
function extractCssValueFrom(rawCss, valueStart) {
|
|
12105
|
+
let i = valueStart;
|
|
12106
|
+
while (i < rawCss.length && /\s/.test(rawCss[i])) i++;
|
|
12107
|
+
const start = i;
|
|
12108
|
+
let depth = 0;
|
|
12109
|
+
let inString = false;
|
|
12110
|
+
let inComment = false;
|
|
12111
|
+
for (; i < rawCss.length; i++) {
|
|
12112
|
+
const ch = rawCss[i];
|
|
12113
|
+
if (!inString && !inComment && ch === "/" && rawCss[i + 1] === "*") {
|
|
12114
|
+
inComment = true;
|
|
12115
|
+
i++;
|
|
12116
|
+
continue;
|
|
12117
|
+
}
|
|
12118
|
+
if (inComment) {
|
|
12119
|
+
if (ch === "*" && rawCss[i + 1] === "/") {
|
|
12120
|
+
inComment = false;
|
|
12121
|
+
i++;
|
|
12122
|
+
}
|
|
12123
|
+
continue;
|
|
12124
|
+
}
|
|
12125
|
+
if ((ch === "\"" || ch === "'") && rawCss[i - 1] !== "\\") {
|
|
12126
|
+
if (!inString) inString = ch;
|
|
12127
|
+
else if (inString === ch) inString = false;
|
|
12128
|
+
continue;
|
|
12129
|
+
}
|
|
12130
|
+
if (inString) continue;
|
|
12131
|
+
if (ch === "(") {
|
|
12132
|
+
depth++;
|
|
12133
|
+
continue;
|
|
12134
|
+
}
|
|
12135
|
+
if (ch === ")") {
|
|
12136
|
+
depth = Math.max(0, depth - 1);
|
|
12137
|
+
continue;
|
|
12138
|
+
}
|
|
12139
|
+
if (depth === 0 && ch === ";") return rawCss.slice(start, i);
|
|
12140
|
+
if (depth === 0 && ch === "}") return rawCss.slice(start, i);
|
|
12141
|
+
}
|
|
12142
|
+
if (start < rawCss.length) return rawCss.slice(start);
|
|
12143
|
+
return null;
|
|
12144
|
+
}
|
|
12145
|
+
function findAuthoredDeclarationValue(rawCss, property, stylisValueRaw) {
|
|
12146
|
+
if (!rawCss?.trim()) return null;
|
|
12147
|
+
const normalizedTarget = normalizeValueForMatch(stylisValueRaw);
|
|
12148
|
+
const propRe = new RegExp(`(?:^|[\\s{])${escapeRegex(property)}\\s*:`, "gi");
|
|
12149
|
+
let match;
|
|
12150
|
+
while (match = propRe.exec(rawCss)) {
|
|
12151
|
+
const value = extractCssValueFrom(rawCss, match.index + match[0].lastIndexOf(":") + 1);
|
|
12152
|
+
if (value && normalizeValueForMatch(value) === normalizedTarget) return value;
|
|
12153
|
+
}
|
|
12154
|
+
return null;
|
|
12155
|
+
}
|
|
12156
|
+
function parseAuthoredValueParts(value) {
|
|
12157
|
+
const parts = [];
|
|
12158
|
+
const placeholderPattern = new RegExp(PLACEHOLDER_RE.source, "g");
|
|
12159
|
+
let lastIndex = 0;
|
|
12160
|
+
let match;
|
|
12161
|
+
while (match = placeholderPattern.exec(value)) {
|
|
12162
|
+
const start = match.index;
|
|
12163
|
+
if (start > lastIndex) parts.push({
|
|
12164
|
+
kind: "static",
|
|
12165
|
+
value: value.slice(lastIndex, start)
|
|
12166
|
+
});
|
|
12167
|
+
parts.push({
|
|
12168
|
+
kind: "slot",
|
|
12169
|
+
slotId: Number(match[1])
|
|
12170
|
+
});
|
|
12171
|
+
lastIndex = start + match[0].length;
|
|
12172
|
+
}
|
|
12173
|
+
if (lastIndex < value.length) parts.push({
|
|
12174
|
+
kind: "static",
|
|
12175
|
+
value: value.slice(lastIndex)
|
|
12176
|
+
});
|
|
12177
|
+
return parts;
|
|
12178
|
+
}
|
|
12179
|
+
function normalizeStaticMultilineChunk(chunk, isFirst, isLast, beforeSlot) {
|
|
12180
|
+
let text = chunk;
|
|
12181
|
+
if (isFirst) text = text.replace(/^\s+/, "");
|
|
12182
|
+
if (isLast) text = text.replace(/\s+$/, "");
|
|
12183
|
+
else if (!beforeSlot) text = text.replace(/\s+$/, "");
|
|
12184
|
+
return text.replace(/,\s*\r?\n\s*/g, `,\n${MULTILINE_INDENT}`);
|
|
12185
|
+
}
|
|
12186
|
+
function isAuthoredMultilineInterpolatedValue(authoredValue) {
|
|
12187
|
+
if (!/\r?\n/.test(authoredValue)) return false;
|
|
12188
|
+
return parseAuthoredValueParts(authoredValue).some((part) => part.kind === "slot");
|
|
12189
|
+
}
|
|
12190
|
+
function applyAuthoredMultilineTemplateFormatting(j, templateLiteral, authoredValue) {
|
|
12191
|
+
if (!isAuthoredMultilineInterpolatedValue(authoredValue)) return templateLiteral;
|
|
12192
|
+
const authoredParts = parseAuthoredValueParts(authoredValue);
|
|
12193
|
+
if (authoredParts.filter((part) => part.kind === "slot").length !== templateLiteral.expressions.length) return templateLiteral;
|
|
12194
|
+
const quasis = [];
|
|
12195
|
+
let staticBuffer = "";
|
|
12196
|
+
let slotIndex = 0;
|
|
12197
|
+
for (const part of authoredParts) {
|
|
12198
|
+
if (part.kind === "static") {
|
|
12199
|
+
staticBuffer += part.value;
|
|
12200
|
+
continue;
|
|
12201
|
+
}
|
|
12202
|
+
const isFirst = slotIndex === 0;
|
|
12203
|
+
const quasiText = normalizeStaticMultilineChunk(staticBuffer, isFirst, false, true);
|
|
12204
|
+
const raw = isFirst && quasiText ? `\n${MULTILINE_INDENT}${quasiText.replace(/^\s+/, "")}` : quasiText;
|
|
12205
|
+
quasis.push(j.templateElement({
|
|
12206
|
+
raw,
|
|
12207
|
+
cooked: raw
|
|
12208
|
+
}, false));
|
|
12209
|
+
staticBuffer = "";
|
|
12210
|
+
slotIndex++;
|
|
12211
|
+
}
|
|
12212
|
+
const trailing = normalizeStaticMultilineChunk(staticBuffer, slotIndex === 0, true, false);
|
|
12213
|
+
quasis.push(j.templateElement({
|
|
12214
|
+
raw: trailing,
|
|
12215
|
+
cooked: trailing
|
|
12216
|
+
}, true));
|
|
12217
|
+
return j.templateLiteral(quasis, templateLiteral.expressions);
|
|
12218
|
+
}
|
|
12219
|
+
function maybeApplyAuthoredMultilineTemplateFormatting(args) {
|
|
12220
|
+
const authoredValue = findAuthoredDeclarationValue(args.rawCss, args.property, args.stylisValueRaw);
|
|
12221
|
+
if (!authoredValue) return args.templateLiteral;
|
|
12222
|
+
return applyAuthoredMultilineTemplateFormatting(args.j, args.templateLiteral, authoredValue);
|
|
12223
|
+
}
|
|
12224
|
+
/** Applies multiline CSS formatting when `built` is a template literal. */
|
|
12225
|
+
function maybeApplyAuthoredMultilineToExpression(j, built, context) {
|
|
12226
|
+
if (!isTemplateLiteralNode(built)) return built;
|
|
12227
|
+
return maybeApplyAuthoredMultilineTemplateFormatting({
|
|
12228
|
+
j,
|
|
12229
|
+
templateLiteral: built,
|
|
12230
|
+
...context
|
|
12231
|
+
});
|
|
12232
|
+
}
|
|
12233
|
+
//#endregion
|
|
11587
12234
|
//#region src/internal/lower-rules/inline-styles.ts
|
|
11588
|
-
function
|
|
12235
|
+
function getImportedStylexIdentifiers(importMap, resolverImports) {
|
|
12236
|
+
const identifiers = /* @__PURE__ */ new Set();
|
|
12237
|
+
for (const [localName, importEntry] of importMap) if (importEntry?.source?.value?.includes(".stylex")) identifiers.add(localName);
|
|
12238
|
+
for (const importSpec of resolverImports.values()) {
|
|
12239
|
+
if (!importSpec.from.value.includes(".stylex")) continue;
|
|
12240
|
+
for (const name of importSpec.names) identifiers.add(name.local ?? name.imported);
|
|
12241
|
+
}
|
|
12242
|
+
return identifiers;
|
|
12243
|
+
}
|
|
12244
|
+
function buildTemplateWithStaticParts(j, expr, prefix, suffix, multilineContext) {
|
|
11589
12245
|
if (!prefix && !suffix) return expr;
|
|
11590
12246
|
const staticValue = literalToStaticValue(expr);
|
|
11591
12247
|
if (staticValue !== null) return j.stringLiteral(prefix + String(staticValue) + suffix);
|
|
11592
|
-
|
|
12248
|
+
const templateLiteral = j.templateLiteral([j.templateElement({
|
|
11593
12249
|
raw: prefix,
|
|
11594
12250
|
cooked: prefix
|
|
11595
12251
|
}, false), j.templateElement({
|
|
11596
12252
|
raw: suffix,
|
|
11597
12253
|
cooked: suffix
|
|
11598
12254
|
}, true)], [expr]);
|
|
12255
|
+
if (!multilineContext) return templateLiteral;
|
|
12256
|
+
return maybeApplyAuthoredMultilineTemplateFormatting({
|
|
12257
|
+
j,
|
|
12258
|
+
templateLiteral,
|
|
12259
|
+
...multilineContext
|
|
12260
|
+
});
|
|
11599
12261
|
}
|
|
11600
12262
|
/**
|
|
11601
12263
|
* Rewrites `props.theme.X` member access to `theme.X` in a cloned AST node.
|
|
@@ -11674,6 +12336,14 @@ function collectPropsFromArrowFnDestructured(expr) {
|
|
|
11674
12336
|
});
|
|
11675
12337
|
return props;
|
|
11676
12338
|
}
|
|
12339
|
+
function collectDollarParamBindingIdentifiers(expr) {
|
|
12340
|
+
const identifiers = /* @__PURE__ */ new Set();
|
|
12341
|
+
if (!expr || expr.type !== "ArrowFunctionExpression") return identifiers;
|
|
12342
|
+
const bindings = getArrowFnParamBindings(expr);
|
|
12343
|
+
if (!bindings || bindings.kind !== "destructured") return identifiers;
|
|
12344
|
+
for (const localName of bindings.bindings.keys()) if (localName.startsWith("$")) identifiers.add(localName);
|
|
12345
|
+
return identifiers;
|
|
12346
|
+
}
|
|
11677
12347
|
function countConditionalExpressions(node) {
|
|
11678
12348
|
let count = 0;
|
|
11679
12349
|
walkAst(node, (n) => {
|
|
@@ -11796,7 +12466,7 @@ function collectPropsFromExpressions(expressions, propsUsed) {
|
|
|
11796
12466
|
* - `props.$foo` -> `props.foo` (strip $ prefix)
|
|
11797
12467
|
* - `props.foo` -> unchanged
|
|
11798
12468
|
*/
|
|
11799
|
-
function normalizeDollarProps(j, exprNode) {
|
|
12469
|
+
function normalizeDollarProps(j, exprNode, opts) {
|
|
11800
12470
|
return mapAst(cloneAstNode(exprNode), (n) => {
|
|
11801
12471
|
if (isMemberExpression(n) && n.object?.type === "Identifier" && n.object?.name === "props" && n.property?.type === "Identifier" && n.computed === false) {
|
|
11802
12472
|
const propName = n.property.name;
|
|
@@ -11805,7 +12475,8 @@ function normalizeDollarProps(j, exprNode) {
|
|
|
11805
12475
|
}
|
|
11806
12476
|
if (n.type === "Identifier") {
|
|
11807
12477
|
const identName = n.name;
|
|
11808
|
-
|
|
12478
|
+
const isLocalDollarIdentifier = !!identName && opts?.localDollarIdentifiers?.has(identName);
|
|
12479
|
+
if (identName?.startsWith("$") && (isLocalDollarIdentifier || !opts?.skipIdentifiers?.has(identName))) return j.memberExpression(j.identifier("props"), j.identifier(identName.slice(1)));
|
|
11809
12480
|
}
|
|
11810
12481
|
});
|
|
11811
12482
|
}
|
|
@@ -15204,14 +15875,21 @@ function emitStylesAndImports(ctx) {
|
|
|
15204
15875
|
const kfDecl = j.variableDeclaration("const", [j.variableDeclarator(j.identifier(name), j.callExpression(j.memberExpression(j.identifier("stylex"), j.identifier("keyframes")), [objectToAst(j, frames)]))]);
|
|
15205
15876
|
inlineKeyframeDecls.push(kfDecl);
|
|
15206
15877
|
}
|
|
15207
|
-
emitLocalDefineVarsSidecars(ctx, [...nonEmptyStyleEntries.map(([, value]) => value), ...styledDecls.flatMap((decl) => (decl.inlineStyleProps ?? []).
|
|
15878
|
+
emitLocalDefineVarsSidecars(ctx, [...nonEmptyStyleEntries.map(([, value]) => value), ...styledDecls.flatMap((decl) => (decl.inlineStyleProps ?? []).map((prop) => prop.expr))]);
|
|
15208
15879
|
const programBody = root.get().node.program.body;
|
|
15209
|
-
const
|
|
15210
|
-
|
|
15211
|
-
|
|
15212
|
-
|
|
15213
|
-
|
|
15214
|
-
|
|
15880
|
+
const { statements: relocatedKeyframes, insertIndex: keyframesInsertIndex } = extractModuleLevelStylexKeyframesStatements(programBody, resolveStylesAnchorIndex({
|
|
15881
|
+
programBody,
|
|
15882
|
+
stylesInsertPosition,
|
|
15883
|
+
stylesIdentifier,
|
|
15884
|
+
mergeTarget,
|
|
15885
|
+
willInsertStylesDecl: stylesDecl != null
|
|
15886
|
+
}), new Set(styledDecls.filter((decl) => !decl.skipTransform).map((decl) => decl.localName)));
|
|
15887
|
+
const insertNodes = [
|
|
15888
|
+
...relocatedKeyframes,
|
|
15889
|
+
...inlineKeyframeDecls,
|
|
15890
|
+
...stylesDecl ? [stylesDecl] : []
|
|
15891
|
+
];
|
|
15892
|
+
if (insertNodes.length > 0) programBody.splice(keyframesInsertIndex, 0, ...insertNodes);
|
|
15215
15893
|
const dimensionsByName = /* @__PURE__ */ new Map();
|
|
15216
15894
|
for (const decl of styledDecls) {
|
|
15217
15895
|
if (decl.skipTransform || !decl.variantDimensions) continue;
|
|
@@ -15531,6 +16209,186 @@ function groupLocalStylexVars(vars) {
|
|
|
15531
16209
|
}
|
|
15532
16210
|
return groups;
|
|
15533
16211
|
}
|
|
16212
|
+
function isStylexKeyframesInit(init) {
|
|
16213
|
+
if (!init || typeof init !== "object" || !("type" in init)) return false;
|
|
16214
|
+
const call = init;
|
|
16215
|
+
return call.type === "CallExpression" && call.callee?.type === "MemberExpression" && call.callee.object?.type === "Identifier" && call.callee.object.name === "stylex" && call.callee.property?.type === "Identifier" && call.callee.property.name === "keyframes";
|
|
16216
|
+
}
|
|
16217
|
+
function isStylexCreateInit(init) {
|
|
16218
|
+
if (!init || typeof init !== "object" || !("type" in init)) return false;
|
|
16219
|
+
const call = init;
|
|
16220
|
+
return call.type === "CallExpression" && call.callee?.type === "MemberExpression" && call.callee.object?.type === "Identifier" && call.callee.object.name === "stylex" && call.callee.property?.type === "Identifier" && call.callee.property.name === "create";
|
|
16221
|
+
}
|
|
16222
|
+
function getVariableDeclarationFromStatement(statement) {
|
|
16223
|
+
if (!statement || typeof statement !== "object" || !("type" in statement)) return null;
|
|
16224
|
+
const typed = statement;
|
|
16225
|
+
if (typed.type === "VariableDeclaration") return typed;
|
|
16226
|
+
if (typed.type === "ExportNamedDeclaration" && typed.declaration?.type === "VariableDeclaration") return typed.declaration;
|
|
16227
|
+
return null;
|
|
16228
|
+
}
|
|
16229
|
+
function variableDeclarationHasOnlyStylexKeyframes(decl) {
|
|
16230
|
+
if (decl.type !== "VariableDeclaration" || !decl.declarations?.length) return false;
|
|
16231
|
+
return decl.declarations.every((d) => isStylexKeyframesInit(d.init));
|
|
16232
|
+
}
|
|
16233
|
+
function getStylexKeyframesBindingNames(variableDecl) {
|
|
16234
|
+
const names = /* @__PURE__ */ new Set();
|
|
16235
|
+
for (const declarator of variableDecl.declarations ?? []) if (declarator.id?.type === "Identifier" && declarator.id.name && isStylexKeyframesInit(declarator.init)) names.add(declarator.id.name);
|
|
16236
|
+
return names;
|
|
16237
|
+
}
|
|
16238
|
+
function statementReferencesAnyBinding(statement, bindingNames) {
|
|
16239
|
+
if (bindingNames.size === 0) return false;
|
|
16240
|
+
const identifiers = /* @__PURE__ */ new Set();
|
|
16241
|
+
collectIdentifiers(statement, identifiers);
|
|
16242
|
+
for (const name of identifiers) if (bindingNames.has(name)) return true;
|
|
16243
|
+
return false;
|
|
16244
|
+
}
|
|
16245
|
+
function declaratorReferencesAnyBinding(declarator, bindingNames) {
|
|
16246
|
+
const identifiers = /* @__PURE__ */ new Set();
|
|
16247
|
+
collectIdentifiers(declarator.id, identifiers);
|
|
16248
|
+
collectIdentifiers(declarator.init, identifiers);
|
|
16249
|
+
for (const name of identifiers) if (bindingNames.has(name)) return true;
|
|
16250
|
+
return false;
|
|
16251
|
+
}
|
|
16252
|
+
function statementReferencesKeyframesBindingFromSurvivingDeclarators(statement, bindingNames, removedStyledDeclNames) {
|
|
16253
|
+
const variableDecl = getVariableDeclarationFromStatement(statement);
|
|
16254
|
+
if (variableDecl?.declarations) {
|
|
16255
|
+
for (const declarator of variableDecl.declarations) {
|
|
16256
|
+
const id = declarator.id;
|
|
16257
|
+
if (id?.type === "Identifier" && id.name != null && removedStyledDeclNames.has(id.name)) continue;
|
|
16258
|
+
if (declaratorReferencesAnyBinding(declarator, bindingNames)) return true;
|
|
16259
|
+
}
|
|
16260
|
+
return false;
|
|
16261
|
+
}
|
|
16262
|
+
return statementReferencesAnyBinding(statement, bindingNames);
|
|
16263
|
+
}
|
|
16264
|
+
function interveningStatementUsesKeyframesBinding(statement, bindingNames, removedStyledDeclNames) {
|
|
16265
|
+
return statementReferencesKeyframesBindingFromSurvivingDeclarators(statement, bindingNames, removedStyledDeclNames);
|
|
16266
|
+
}
|
|
16267
|
+
function getTopLevelDeclaredBindingNames(statement) {
|
|
16268
|
+
const names = /* @__PURE__ */ new Set();
|
|
16269
|
+
const variableDecl = getVariableDeclarationFromStatement(statement);
|
|
16270
|
+
if (variableDecl?.declarations) {
|
|
16271
|
+
for (const declarator of variableDecl.declarations) {
|
|
16272
|
+
const id = declarator.id;
|
|
16273
|
+
if (id?.type === "Identifier" && id.name) names.add(id.name);
|
|
16274
|
+
else if (id) collectPatternBindingNames$2(id, names);
|
|
16275
|
+
}
|
|
16276
|
+
return names;
|
|
16277
|
+
}
|
|
16278
|
+
const typed = statement;
|
|
16279
|
+
if (typed.type === "FunctionDeclaration" && typed.id?.type === "Identifier" && typed.id.name) names.add(typed.id.name);
|
|
16280
|
+
return names;
|
|
16281
|
+
}
|
|
16282
|
+
function keyframesInitReferencesBindingsDeclaredBetween(variableDecl, programBody, rangeStart, rangeEnd) {
|
|
16283
|
+
const referencedInInit = /* @__PURE__ */ new Set();
|
|
16284
|
+
for (const declarator of variableDecl.declarations ?? []) collectIdentifiers(declarator.init, referencedInInit);
|
|
16285
|
+
for (let index = rangeStart; index < rangeEnd; index++) {
|
|
16286
|
+
const declared = getTopLevelDeclaredBindingNames(programBody[index]);
|
|
16287
|
+
for (const name of declared) if (referencedInInit.has(name)) return true;
|
|
16288
|
+
}
|
|
16289
|
+
return false;
|
|
16290
|
+
}
|
|
16291
|
+
function getClassDeclarationFromStatement(statement) {
|
|
16292
|
+
if (!statement || typeof statement !== "object" || !("type" in statement)) return null;
|
|
16293
|
+
const typed = statement;
|
|
16294
|
+
if (typed.type === "ClassDeclaration") return typed;
|
|
16295
|
+
if (typed.type === "ExportNamedDeclaration" && typed.declaration?.type === "ClassDeclaration") return typed.declaration;
|
|
16296
|
+
return null;
|
|
16297
|
+
}
|
|
16298
|
+
function classDeclarationCapturesKeyframes(classDecl, bindingNames) {
|
|
16299
|
+
if (classDecl.id?.type !== "Identifier" || !classDecl.id.name) return null;
|
|
16300
|
+
const members = classDecl.body?.body;
|
|
16301
|
+
if (!Array.isArray(members)) return null;
|
|
16302
|
+
for (const member of members) if (statementReferencesAnyBinding(member, bindingNames)) return classDecl.id.name;
|
|
16303
|
+
return null;
|
|
16304
|
+
}
|
|
16305
|
+
function collectTopLevelBindingsCapturingKeyframes(programBody, beforeIndex, bindingNames, removedStyledDeclNames) {
|
|
16306
|
+
const captures = /* @__PURE__ */ new Set();
|
|
16307
|
+
for (let index = 0; index < beforeIndex; index++) {
|
|
16308
|
+
const statement = programBody[index];
|
|
16309
|
+
const classDecl = getClassDeclarationFromStatement(statement);
|
|
16310
|
+
if (classDecl) {
|
|
16311
|
+
const className = classDeclarationCapturesKeyframes(classDecl, bindingNames);
|
|
16312
|
+
if (className) captures.add(className);
|
|
16313
|
+
continue;
|
|
16314
|
+
}
|
|
16315
|
+
const variableDecl = getVariableDeclarationFromStatement(statement);
|
|
16316
|
+
if (variableDecl?.declarations) {
|
|
16317
|
+
for (const declarator of variableDecl.declarations) {
|
|
16318
|
+
const id = declarator.id;
|
|
16319
|
+
if (id?.type === "Identifier" && id.name != null && removedStyledDeclNames.has(id.name)) continue;
|
|
16320
|
+
if (!declaratorReferencesAnyBinding(declarator, bindingNames)) continue;
|
|
16321
|
+
if (id?.type === "Identifier" && id.name) captures.add(id.name);
|
|
16322
|
+
else if (id) collectPatternBindingNames$2(id, captures);
|
|
16323
|
+
}
|
|
16324
|
+
continue;
|
|
16325
|
+
}
|
|
16326
|
+
const typed = statement;
|
|
16327
|
+
if (typed.type === "FunctionDeclaration" && typed.id?.type === "Identifier" && typed.id.name) {
|
|
16328
|
+
if (statementReferencesAnyBinding(typed.body, bindingNames)) captures.add(typed.id.name);
|
|
16329
|
+
}
|
|
16330
|
+
}
|
|
16331
|
+
return captures;
|
|
16332
|
+
}
|
|
16333
|
+
function canSafelyRelocateKeyframesStatement(statementIndex, anchorIndex, programBody, variableDecl, removedStyledDeclNames) {
|
|
16334
|
+
const bindingNames = getStylexKeyframesBindingNames(variableDecl);
|
|
16335
|
+
const rangeStart = Math.min(statementIndex, anchorIndex);
|
|
16336
|
+
const rangeEnd = Math.max(statementIndex, anchorIndex);
|
|
16337
|
+
if (statementIndex > anchorIndex && keyframesInitReferencesBindingsDeclaredBetween(variableDecl, programBody, anchorIndex, statementIndex)) return false;
|
|
16338
|
+
if (statementIndex < anchorIndex && keyframesInitReferencesBindingsDeclaredBetween(variableDecl, programBody, statementIndex + 1, anchorIndex)) return false;
|
|
16339
|
+
const indirectCaptureNames = statementIndex < anchorIndex ? collectTopLevelBindingsCapturingKeyframes(programBody, statementIndex, bindingNames, removedStyledDeclNames) : /* @__PURE__ */ new Set();
|
|
16340
|
+
for (let index = rangeStart; index < rangeEnd; index++) {
|
|
16341
|
+
if (index === statementIndex) continue;
|
|
16342
|
+
const statement = programBody[index];
|
|
16343
|
+
if (interveningStatementUsesKeyframesBinding(statement, bindingNames, removedStyledDeclNames)) return false;
|
|
16344
|
+
if (indirectCaptureNames.size > 0 && interveningStatementUsesKeyframesBinding(statement, indirectCaptureNames, removedStyledDeclNames)) return false;
|
|
16345
|
+
}
|
|
16346
|
+
return true;
|
|
16347
|
+
}
|
|
16348
|
+
function extractModuleLevelStylexKeyframesStatements(programBody, anchorIndex, removedStyledDeclNames) {
|
|
16349
|
+
const extracted = [];
|
|
16350
|
+
for (let index = 0; index < programBody.length; index++) {
|
|
16351
|
+
const statement = programBody[index];
|
|
16352
|
+
const variableDecl = getVariableDeclarationFromStatement(statement);
|
|
16353
|
+
if (!variableDecl || !variableDeclarationHasOnlyStylexKeyframes(variableDecl)) continue;
|
|
16354
|
+
if (!canSafelyRelocateKeyframesStatement(index, anchorIndex, programBody, variableDecl, removedStyledDeclNames)) continue;
|
|
16355
|
+
extracted.push({
|
|
16356
|
+
index,
|
|
16357
|
+
statement
|
|
16358
|
+
});
|
|
16359
|
+
}
|
|
16360
|
+
extracted.sort((a, b) => a.index - b.index);
|
|
16361
|
+
let insertIndex = anchorIndex;
|
|
16362
|
+
for (let i = extracted.length - 1; i >= 0; i--) {
|
|
16363
|
+
const { index } = extracted[i];
|
|
16364
|
+
if (index < insertIndex) insertIndex--;
|
|
16365
|
+
programBody.splice(index, 1);
|
|
16366
|
+
}
|
|
16367
|
+
return {
|
|
16368
|
+
statements: extracted.map((entry) => entry.statement),
|
|
16369
|
+
insertIndex
|
|
16370
|
+
};
|
|
16371
|
+
}
|
|
16372
|
+
function findMainStylexCreateStatementIndex(programBody, stylesIdentifier) {
|
|
16373
|
+
for (let index = 0; index < programBody.length; index++) {
|
|
16374
|
+
const variableDecl = getVariableDeclarationFromStatement(programBody[index]);
|
|
16375
|
+
if (!variableDecl?.declarations) continue;
|
|
16376
|
+
for (const declarator of variableDecl.declarations) if (declarator.id?.type === "Identifier" && declarator.id.name === stylesIdentifier && isStylexCreateInit(declarator.init)) return index;
|
|
16377
|
+
}
|
|
16378
|
+
return -1;
|
|
16379
|
+
}
|
|
16380
|
+
function resolveStylesAnchorIndex(args) {
|
|
16381
|
+
const { programBody, stylesInsertPosition, stylesIdentifier, mergeTarget, willInsertStylesDecl } = args;
|
|
16382
|
+
if (mergeTarget || !willInsertStylesDecl) {
|
|
16383
|
+
const existingIndex = findMainStylexCreateStatementIndex(programBody, stylesIdentifier);
|
|
16384
|
+
if (existingIndex >= 0) return existingIndex;
|
|
16385
|
+
}
|
|
16386
|
+
if (stylesInsertPosition === "afterImports") {
|
|
16387
|
+
const lastImportIdx = findLastImportIndex(programBody);
|
|
16388
|
+
return lastImportIdx >= 0 ? lastImportIdx + 1 : 0;
|
|
16389
|
+
}
|
|
16390
|
+
return programBody.length;
|
|
16391
|
+
}
|
|
15534
16392
|
//#endregion
|
|
15535
16393
|
//#region src/internal/transform-steps/emit-styles.ts
|
|
15536
16394
|
/**
|
|
@@ -15943,7 +16801,8 @@ function isCustomPropertyKey(prop) {
|
|
|
15943
16801
|
return prop.startsWith("--") || prop.includes(".");
|
|
15944
16802
|
}
|
|
15945
16803
|
function inlineStyleProperty(j, prop) {
|
|
15946
|
-
const
|
|
16804
|
+
const key = prop.keyExpr ?? inlineStylePropKey(j, prop.prop);
|
|
16805
|
+
const property = j.property("init", key, prop.expr);
|
|
15947
16806
|
if (prop.keyExpr) property.computed = true;
|
|
15948
16807
|
return property;
|
|
15949
16808
|
}
|
|
@@ -16099,7 +16958,21 @@ const withLeadingCommentsOnFirstFunction = (nodes, d) => {
|
|
|
16099
16958
|
//#region src/internal/lower-rules/variants.ts
|
|
16100
16959
|
function parseVariantCondition(when) {
|
|
16101
16960
|
const trimmed = when.trim();
|
|
16102
|
-
if (trimmed.includes("&&"))
|
|
16961
|
+
if (trimmed.includes("&&")) {
|
|
16962
|
+
const parts = trimmed.split("&&").map((part) => part.trim()).filter(Boolean);
|
|
16963
|
+
const parsedParts = parts.map(parseVariantCondition);
|
|
16964
|
+
const equalityParts = parsedParts.filter((part) => part.type === "equality");
|
|
16965
|
+
if (equalityParts.length === 1) {
|
|
16966
|
+
const equality = equalityParts[0];
|
|
16967
|
+
const equalityIndex = parsedParts.findIndex((part) => part === equality);
|
|
16968
|
+
const guardParts = parts.filter((_, index) => index !== equalityIndex);
|
|
16969
|
+
if (guardParts.length > 0) return {
|
|
16970
|
+
...equality,
|
|
16971
|
+
conditionWhen: guardParts.join(" && ")
|
|
16972
|
+
};
|
|
16973
|
+
}
|
|
16974
|
+
return { type: "compound" };
|
|
16975
|
+
}
|
|
16103
16976
|
if (trimmed.startsWith("!")) {
|
|
16104
16977
|
const inner = trimmed.slice(1).trim().replace(/^\(|\)$/g, "");
|
|
16105
16978
|
if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(inner)) return {
|
|
@@ -16173,10 +17046,11 @@ function hasFiniteNumericVariantKey(dimension) {
|
|
|
16173
17046
|
* Compound conditions (e.g., `disabled && color === "primary"`) are kept separate
|
|
16174
17047
|
* and not grouped into dimensions.
|
|
16175
17048
|
*/
|
|
16176
|
-
function groupVariantBucketsIntoDimensions(variantBuckets, variantStyleKeys,
|
|
16177
|
-
const getVariantObjectName = (propName, suffix) => {
|
|
17049
|
+
function groupVariantBucketsIntoDimensions(variantBuckets, variantStyleKeys, baseStyleKey, baseStyles, findJsxPropTsType, isJsxPropOptional) {
|
|
17050
|
+
const getVariantObjectName = (propName, suffix, useBaseStyleKey) => {
|
|
17051
|
+
const baseName = useBaseStyleKey ? styleKeyWithSuffix(baseStyleKey, propName) : propName;
|
|
16178
17052
|
if (propName === "variant") return suffix ? `${suffix.toLowerCase()}Variants` : "variants";
|
|
16179
|
-
return suffix ? `${
|
|
17053
|
+
return suffix ? `${baseName}${suffix}Variants` : `${baseName}Variants`;
|
|
16180
17054
|
};
|
|
16181
17055
|
const propGroups = /* @__PURE__ */ new Map();
|
|
16182
17056
|
const remainingBuckets = /* @__PURE__ */ new Map();
|
|
@@ -16189,7 +17063,8 @@ function groupVariantBucketsIntoDimensions(variantBuckets, variantStyleKeys, _ba
|
|
|
16189
17063
|
existing.push({
|
|
16190
17064
|
when,
|
|
16191
17065
|
value: parsed.value,
|
|
16192
|
-
styles
|
|
17066
|
+
styles,
|
|
17067
|
+
conditionWhen: parsed.conditionWhen
|
|
16193
17068
|
});
|
|
16194
17069
|
propGroups.set(parsed.propName, existing);
|
|
16195
17070
|
} else {
|
|
@@ -16235,6 +17110,16 @@ function groupVariantBucketsIntoDimensions(variantBuckets, variantStyleKeys, _ba
|
|
|
16235
17110
|
}
|
|
16236
17111
|
const variantMap = {};
|
|
16237
17112
|
const allOverriddenProps = /* @__PURE__ */ new Set();
|
|
17113
|
+
const conditionGroup = commonConditionWhen(variants);
|
|
17114
|
+
if (!conditionGroup.canGroup) {
|
|
17115
|
+
for (const v of variants) {
|
|
17116
|
+
remainingBuckets.set(v.when, v.styles);
|
|
17117
|
+
const styleKey = variantStyleKeys[v.when];
|
|
17118
|
+
if (styleKey) remainingStyleKeys[v.when] = styleKey;
|
|
17119
|
+
}
|
|
17120
|
+
continue;
|
|
17121
|
+
}
|
|
17122
|
+
const { conditionWhen } = conditionGroup;
|
|
16238
17123
|
for (const v of variants) {
|
|
16239
17124
|
variantMap[v.value] = v.styles;
|
|
16240
17125
|
for (const cssProp of Object.keys(v.styles)) allOverriddenProps.add(cssProp);
|
|
@@ -16267,7 +17152,7 @@ function groupVariantBucketsIntoDimensions(variantBuckets, variantStyleKeys, _ba
|
|
|
16267
17152
|
}
|
|
16268
17153
|
if (overlappingBoolProp) break;
|
|
16269
17154
|
}
|
|
16270
|
-
if (overlappingBoolProp && overlappingBoolStyles) {
|
|
17155
|
+
if (overlappingBoolProp && overlappingBoolStyles && !conditionWhen) {
|
|
16271
17156
|
dimensions.push({
|
|
16272
17157
|
propName,
|
|
16273
17158
|
variantObjectName: getVariantObjectName(propName, "Enabled"),
|
|
@@ -16305,9 +17190,10 @@ function groupVariantBucketsIntoDimensions(variantBuckets, variantStyleKeys, _ba
|
|
|
16305
17190
|
for (const cssProp of variantCssProps) propsToStrip.add(cssProp);
|
|
16306
17191
|
} else dimensions.push({
|
|
16307
17192
|
propName,
|
|
16308
|
-
variantObjectName: getVariantObjectName(propName),
|
|
17193
|
+
variantObjectName: getVariantObjectName(propName, void 0, !!conditionWhen),
|
|
16309
17194
|
variants: variantMap,
|
|
16310
17195
|
defaultValue,
|
|
17196
|
+
...conditionWhen ? { conditionWhen } : {},
|
|
16311
17197
|
isOptional: propIsOptional
|
|
16312
17198
|
});
|
|
16313
17199
|
}
|
|
@@ -16318,6 +17204,15 @@ function groupVariantBucketsIntoDimensions(variantBuckets, variantStyleKeys, _ba
|
|
|
16318
17204
|
propsToStrip
|
|
16319
17205
|
};
|
|
16320
17206
|
}
|
|
17207
|
+
function commonConditionWhen(variants) {
|
|
17208
|
+
const conditions = [...new Set(variants.map((variant) => variant.conditionWhen))];
|
|
17209
|
+
if (conditions.length !== 1) return { canGroup: false };
|
|
17210
|
+
const conditionWhen = conditions[0];
|
|
17211
|
+
return conditionWhen ? {
|
|
17212
|
+
canGroup: true,
|
|
17213
|
+
conditionWhen
|
|
17214
|
+
} : { canGroup: true };
|
|
17215
|
+
}
|
|
16321
17216
|
//#endregion
|
|
16322
17217
|
//#region src/internal/emit-wrappers/type-helpers.ts
|
|
16323
17218
|
/**
|
|
@@ -16725,6 +17620,25 @@ function wrapCallArgForPropsObject(j, rawArg, propsObjectKey) {
|
|
|
16725
17620
|
if (rawArg.type === "Identifier" && rawArg.name === propsObjectKey) prop.shorthand = true;
|
|
16726
17621
|
return j.objectExpression([prop]);
|
|
16727
17622
|
}
|
|
17623
|
+
function collectKnownConditionPropNames(emitter, d) {
|
|
17624
|
+
const names = /* @__PURE__ */ new Set();
|
|
17625
|
+
const add = (name) => {
|
|
17626
|
+
if (name && name !== "__props" && name !== "__helper") names.add(name);
|
|
17627
|
+
};
|
|
17628
|
+
if (d.propsType) for (const name of emitter.getExplicitPropNames(d.propsType)) add(name);
|
|
17629
|
+
for (const dim of d.variantDimensions ?? []) {
|
|
17630
|
+
add(dim.propName);
|
|
17631
|
+
add(dim.namespaceBooleanProp);
|
|
17632
|
+
}
|
|
17633
|
+
for (const entry of d.styleFnFromProps ?? []) {
|
|
17634
|
+
add(entry.jsxProp);
|
|
17635
|
+
for (const extra of entry.extraCallArgs ?? []) add(extra.jsxProp);
|
|
17636
|
+
}
|
|
17637
|
+
for (const prop of d.styleValueVariantProps ?? []) add(prop);
|
|
17638
|
+
for (const prop of collectInlineStylePropNames(d.inlineStyleProps ?? [])) add(prop);
|
|
17639
|
+
for (const prop of d.shouldForwardProp?.dropProps ?? []) add(prop);
|
|
17640
|
+
return names.size > 0 ? names : void 0;
|
|
17641
|
+
}
|
|
16728
17642
|
/**
|
|
16729
17643
|
* Assembles the initial `styleArgs` array from extends, extra before/after base,
|
|
16730
17644
|
* and the base style expression. This is the common pattern used by all emitters.
|
|
@@ -16769,12 +17683,12 @@ function buildInterleavedExtraStyleArgs(j, stylesIdentifier, d, propsArgExprs) {
|
|
|
16769
17683
|
const mixinOrder = d.mixinOrder;
|
|
16770
17684
|
const afterBaseKeys = new Set(d.extraStyleKeysAfterBase ?? []);
|
|
16771
17685
|
const extraStyleKeys = d.extraStyleKeys ?? [];
|
|
16772
|
-
const propsArgs =
|
|
17686
|
+
const propsArgs = propsArgExprs;
|
|
16773
17687
|
if (!mixinOrder || mixinOrder.length === 0) {
|
|
16774
17688
|
const { beforeBase, afterBase } = splitExtraStyleArgs(j, stylesIdentifier, d);
|
|
16775
17689
|
const afterVariants = [];
|
|
16776
|
-
for (
|
|
16777
|
-
else afterBase.push(
|
|
17690
|
+
for (const propsArg of propsArgExprs) if (propsArg.afterVariants) afterVariants.push(propsArg.expr);
|
|
17691
|
+
else afterBase.push(propsArg.expr);
|
|
16778
17692
|
return {
|
|
16779
17693
|
beforeBase,
|
|
16780
17694
|
afterBase,
|
|
@@ -16786,28 +17700,37 @@ function buildInterleavedExtraStyleArgs(j, stylesIdentifier, d, propsArgExprs) {
|
|
|
16786
17700
|
const afterVariants = [];
|
|
16787
17701
|
let styleKeyIdx = 0;
|
|
16788
17702
|
let propsArgIdx = 0;
|
|
17703
|
+
const pushPropsArg = (index, fallbackGroup) => {
|
|
17704
|
+
const arg = propsArgs[index];
|
|
17705
|
+
if (!arg) return;
|
|
17706
|
+
if (arg.afterVariants) afterVariants.push(arg.expr);
|
|
17707
|
+
else if (arg.afterBase || fallbackGroup === "afterBase") afterBase.push(arg.expr);
|
|
17708
|
+
else beforeBase.push(arg.expr);
|
|
17709
|
+
};
|
|
17710
|
+
const pushPropsArgsThroughNextUnconditional = (fallbackGroup) => {
|
|
17711
|
+
while (propsArgIdx < propsArgs.length && propsArgs[propsArgIdx]?.conditional) {
|
|
17712
|
+
pushPropsArg(propsArgIdx, fallbackGroup);
|
|
17713
|
+
propsArgIdx++;
|
|
17714
|
+
}
|
|
17715
|
+
if (propsArgIdx < propsArgs.length) {
|
|
17716
|
+
pushPropsArg(propsArgIdx, fallbackGroup);
|
|
17717
|
+
propsArgIdx++;
|
|
17718
|
+
}
|
|
17719
|
+
};
|
|
16789
17720
|
for (const entry of mixinOrder) if (entry === "styleKey" && styleKeyIdx < extraStyleKeys.length) {
|
|
16790
17721
|
const key = extraStyleKeys[styleKeyIdx];
|
|
16791
17722
|
styleKeyIdx++;
|
|
16792
17723
|
const expr = styleRef(j, stylesIdentifier, key);
|
|
16793
17724
|
if (afterBaseKeys.has(key)) afterBase.push(expr);
|
|
16794
17725
|
else beforeBase.push(expr);
|
|
16795
|
-
} else if (entry === "propsArg" && propsArgIdx <
|
|
16796
|
-
const arg = propsArgs[propsArgIdx];
|
|
16797
|
-
const argExpr = propsArgExprs[propsArgIdx];
|
|
16798
|
-
propsArgIdx++;
|
|
16799
|
-
if (arg?.afterVariants) afterVariants.push(argExpr);
|
|
16800
|
-
else if (arg?.afterBase) afterBase.push(argExpr);
|
|
16801
|
-
else beforeBase.push(argExpr);
|
|
16802
|
-
}
|
|
17726
|
+
} else if (entry === "propsArg" && propsArgIdx < propsArgs.length) pushPropsArgsThroughNextUnconditional("beforeBase");
|
|
16803
17727
|
for (; styleKeyIdx < extraStyleKeys.length; styleKeyIdx++) {
|
|
16804
17728
|
const key = extraStyleKeys[styleKeyIdx];
|
|
16805
17729
|
const expr = styleRef(j, stylesIdentifier, key);
|
|
16806
17730
|
if (afterBaseKeys.has(key)) afterBase.push(expr);
|
|
16807
17731
|
else beforeBase.push(expr);
|
|
16808
17732
|
}
|
|
16809
|
-
for (; propsArgIdx <
|
|
16810
|
-
else afterBase.push(propsArgExprs[propsArgIdx]);
|
|
17733
|
+
for (; propsArgIdx < propsArgs.length; propsArgIdx++) pushPropsArg(propsArgIdx, "afterBase");
|
|
16811
17734
|
return {
|
|
16812
17735
|
beforeBase,
|
|
16813
17736
|
afterBase,
|
|
@@ -16953,7 +17876,7 @@ function isExpressionLike(value) {
|
|
|
16953
17876
|
* components
|
|
16954
17877
|
*/
|
|
16955
17878
|
function buildVariantDimensionLookups(j, args) {
|
|
16956
|
-
const { dimensions, styleArgs, destructureProps, propDefaults, namespaceBooleanProps } = args;
|
|
17879
|
+
const { dimensions, styleArgs, destructureProps, propDefaults, namespaceBooleanProps, knownProps } = args;
|
|
16957
17880
|
/** Push a style expression to orderedEntries (if source order available) or styleArgs. */
|
|
16958
17881
|
const pushExpr = (expr, dim) => {
|
|
16959
17882
|
if (args.orderedEntries && dim.sourceOrder !== void 0) args.orderedEntries.push({
|
|
@@ -16969,6 +17892,21 @@ function buildVariantDimensionLookups(j, args) {
|
|
|
16969
17892
|
const fallbackCall = j.callExpression(styleRef(j, args.stylesIdentifier, dim.fallbackFnKey), [propId]);
|
|
16970
17893
|
return j.logicalExpression("??", lookup, fallbackCall);
|
|
16971
17894
|
};
|
|
17895
|
+
const buildConditionallyGuardedLookup = (dim, lookup) => {
|
|
17896
|
+
if (!dim.conditionWhen) return lookup;
|
|
17897
|
+
const booleanProps = namespaceBooleanProps ? new Set(namespaceBooleanProps) : void 0;
|
|
17898
|
+
const { cond, isBoolean } = collectConditionProps(j, {
|
|
17899
|
+
when: dim.conditionWhen,
|
|
17900
|
+
destructureProps,
|
|
17901
|
+
...booleanProps ? { booleanProps } : {},
|
|
17902
|
+
...knownProps ? { knownProps } : {}
|
|
17903
|
+
});
|
|
17904
|
+
return makeConditionalStyleExpr(j, {
|
|
17905
|
+
cond,
|
|
17906
|
+
expr: lookup,
|
|
17907
|
+
isBoolean
|
|
17908
|
+
});
|
|
17909
|
+
};
|
|
16972
17910
|
const namespacePairs = /* @__PURE__ */ new Map();
|
|
16973
17911
|
const regularDimensions = [];
|
|
16974
17912
|
for (const dim of dimensions) if (dim.namespaceBooleanProp) {
|
|
@@ -16991,11 +17929,12 @@ function buildVariantDimensionLookups(j, args) {
|
|
|
16991
17929
|
const castProp = buildKeyofTypeofCast(j, propId, dim.variantObjectName);
|
|
16992
17930
|
const lookup = j.memberExpression(variantsId, castProp, true);
|
|
16993
17931
|
const defaultAccess = j.memberExpression(j.identifier(dim.variantObjectName), j.identifier("default"));
|
|
16994
|
-
pushExpr(j.logicalExpression("??", lookup, defaultAccess), dim);
|
|
17932
|
+
pushExpr(buildConditionallyGuardedLookup(dim, j.logicalExpression("??", lookup, defaultAccess)), dim);
|
|
16995
17933
|
} else {
|
|
16996
17934
|
if (dim.defaultValue && dim.isOptional && propDefaults) propDefaults.set(dim.propName, dim.defaultValue);
|
|
16997
17935
|
const lookup = dim.fallbackFnKey ? buildFallbackExpr(dim, propId) : j.memberExpression(variantsId, dim.forceKeyofLookupCast ? buildKeyofTypeofCast(j, propId, dim.variantObjectName) : propId, true);
|
|
16998
|
-
if (dim.
|
|
17936
|
+
if (dim.conditionWhen) pushExpr(buildConditionallyGuardedLookup(dim, lookup), dim);
|
|
17937
|
+
else if (dim.isOptional && !dim.defaultValue) {
|
|
16999
17938
|
const guard = j.binaryExpression("!=", j.identifier(dim.propName), j.literal(null));
|
|
17000
17939
|
pushExpr(j.logicalExpression("&&", guard, lookup), dim);
|
|
17001
17940
|
} else pushExpr(lookup, dim);
|
|
@@ -17026,6 +17965,9 @@ function buildVariantDimensionLookups(j, args) {
|
|
|
17026
17965
|
pushExpr(j.conditionalExpression(boolPropId, disabledLookup, enabledLookup), enabled);
|
|
17027
17966
|
}
|
|
17028
17967
|
}
|
|
17968
|
+
function hasStyleSourceOrder(d) {
|
|
17969
|
+
return !!(d.variantSourceOrder && Object.keys(d.variantSourceOrder).length > 0) || (d.pseudoAliasSelectors ?? []).some((entry) => entry.sourceOrder !== void 0);
|
|
17970
|
+
}
|
|
17029
17971
|
/**
|
|
17030
17972
|
* Sort ordered entries by source order and append them to styleArgs.
|
|
17031
17973
|
* Used to merge variant and styleFn entries while preserving CSS cascade order.
|
|
@@ -17056,6 +17998,7 @@ function buildStyleFnExpressions(emitter, args) {
|
|
|
17056
17998
|
const propExprBuilder = args.propExprBuilder ?? ((prop) => j.identifier(prop));
|
|
17057
17999
|
const styleFnPairs = d.styleFnFromProps ?? [];
|
|
17058
18000
|
const explicitPropNames = d.propsType ? emitter.getExplicitPropNames(d.propsType) : null;
|
|
18001
|
+
const knownProps = collectKnownConditionPropNames(emitter, d);
|
|
17059
18002
|
const inferPropFromCallArg = (expr) => {
|
|
17060
18003
|
if (!expr || typeof expr !== "object") return null;
|
|
17061
18004
|
const unwrap = (node) => {
|
|
@@ -17125,7 +18068,8 @@ function buildStyleFnExpressions(emitter, args) {
|
|
|
17125
18068
|
const { cond, isBoolean } = collectConditionProps(j, {
|
|
17126
18069
|
when: p.conditionWhen,
|
|
17127
18070
|
destructureProps,
|
|
17128
|
-
booleanProps
|
|
18071
|
+
booleanProps,
|
|
18072
|
+
...knownProps ? { knownProps } : {}
|
|
17129
18073
|
});
|
|
17130
18074
|
pushExpr(makeConditionalStyleExpr(j, {
|
|
17131
18075
|
cond,
|
|
@@ -17154,11 +18098,13 @@ function buildStyleFnExpressions(emitter, args) {
|
|
|
17154
18098
|
function collectDestructurePropsFromStyleFns(emitter, args) {
|
|
17155
18099
|
const { j } = emitter;
|
|
17156
18100
|
const { d, styleArgs, destructureProps } = args;
|
|
18101
|
+
const knownProps = collectKnownConditionPropNames(emitter, d);
|
|
17157
18102
|
for (const p of d.styleFnFromProps ?? []) {
|
|
17158
18103
|
if (p.jsxProp && p.jsxProp !== "__props" && p.jsxProp !== "__helper" && !destructureProps.includes(p.jsxProp)) destructureProps.push(p.jsxProp);
|
|
17159
18104
|
if (p.conditionWhen) collectConditionProps(j, {
|
|
17160
18105
|
when: p.conditionWhen,
|
|
17161
|
-
destructureProps
|
|
18106
|
+
destructureProps,
|
|
18107
|
+
knownProps
|
|
17162
18108
|
});
|
|
17163
18109
|
for (const extra of p.extraCallArgs ?? []) if (extra.jsxProp && extra.jsxProp !== "__props" && extra.jsxProp !== "__helper" && !destructureProps.includes(extra.jsxProp)) destructureProps.push(extra.jsxProp);
|
|
17164
18110
|
}
|
|
@@ -17184,9 +18130,10 @@ function collectDestructurePropsFromStyleFns(emitter, args) {
|
|
|
17184
18130
|
* Results are pushed to `styleArgs` (or `orderedEntries` when source order tracking is active).
|
|
17185
18131
|
*/
|
|
17186
18132
|
function buildVariantStyleExprs(opts) {
|
|
17187
|
-
const { d, emitter, j, stylesIdentifier, styleArgs, orderedEntries, hasSourceOrder, destructureProps, booleanProps, compoundVariantKeys, enableComplementaryMerging, onNewDestructureProp } = opts;
|
|
18133
|
+
const { d, emitter, j, stylesIdentifier, styleArgs, orderedEntries, hasSourceOrder, destructureProps, booleanProps, knownProps: providedKnownProps, compoundVariantKeys, enableComplementaryMerging, onNewDestructureProp } = opts;
|
|
17188
18134
|
if (!d.variantStyleKeys) return;
|
|
17189
18135
|
const sortedEntries = sortVariantEntriesBySpecificity(Object.entries(d.variantStyleKeys));
|
|
18136
|
+
const knownProps = providedKnownProps ?? collectKnownConditionPropNames(emitter, d);
|
|
17190
18137
|
/** Push an expression to orderedEntries (if source ordering) or directly to styleArgs. */
|
|
17191
18138
|
const pushExpr = (expr, when) => {
|
|
17192
18139
|
const order = d.variantSourceOrder?.[when];
|
|
@@ -17212,7 +18159,8 @@ function buildVariantStyleExprs(opts) {
|
|
|
17212
18159
|
const { cond } = emitter.collectConditionProps({
|
|
17213
18160
|
when: positiveWhen,
|
|
17214
18161
|
destructureProps,
|
|
17215
|
-
booleanProps
|
|
18162
|
+
booleanProps,
|
|
18163
|
+
...knownProps ? { knownProps } : {}
|
|
17216
18164
|
});
|
|
17217
18165
|
if (onNewDestructureProp && prevLengthRef && destructureProps) for (let i = prevLengthRef.value; i < destructureProps.length; i++) onNewDestructureProp(destructureProps[i]);
|
|
17218
18166
|
const isCurrentPositive = areEquivalentWhen(when, positiveWhen);
|
|
@@ -17226,7 +18174,8 @@ function buildVariantStyleExprs(opts) {
|
|
|
17226
18174
|
const { cond, isBoolean } = emitter.collectConditionProps({
|
|
17227
18175
|
when,
|
|
17228
18176
|
destructureProps,
|
|
17229
|
-
booleanProps
|
|
18177
|
+
booleanProps,
|
|
18178
|
+
...knownProps ? { knownProps } : {}
|
|
17230
18179
|
});
|
|
17231
18180
|
if (onNewDestructureProp && prevLengthRef && destructureProps) for (let i = prevLengthRef.value; i < destructureProps.length; i++) onNewDestructureProp(destructureProps[i]);
|
|
17232
18181
|
const styleExpr = styleRef(j, stylesIdentifier, variantKey);
|
|
@@ -17241,7 +18190,8 @@ function buildVariantStyleExprs(opts) {
|
|
|
17241
18190
|
const { cond, isBoolean } = emitter.collectConditionProps({
|
|
17242
18191
|
when,
|
|
17243
18192
|
destructureProps,
|
|
17244
|
-
booleanProps
|
|
18193
|
+
booleanProps,
|
|
18194
|
+
...knownProps ? { knownProps } : {}
|
|
17245
18195
|
});
|
|
17246
18196
|
const styleExpr = styleRef(j, stylesIdentifier, variantKey);
|
|
17247
18197
|
pushExpr(emitter.makeConditionalStyleExpr({
|
|
@@ -17296,12 +18246,31 @@ function appendGuardedStyleArgs(entries, styleArgs, j, buildExpr, booleanProps)
|
|
|
17296
18246
|
*
|
|
17297
18247
|
* Returns the list of guard prop names that need destructuring.
|
|
17298
18248
|
*/
|
|
17299
|
-
function appendPseudoAliasStyleArgs(entries, styleArgs, j, stylesIdentifier) {
|
|
18249
|
+
function appendPseudoAliasStyleArgs(entries, styleArgs, j, stylesIdentifier, orderedEntries) {
|
|
17300
18250
|
if (!entries?.length) return [];
|
|
17301
|
-
|
|
18251
|
+
const guardProps = [];
|
|
18252
|
+
const aliasExprs = [];
|
|
18253
|
+
for (const entry of entries) {
|
|
17302
18254
|
const properties = entry.pseudoNames.map((name, i) => j.property("init", /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name) ? j.identifier(name) : j.literal(name), styleRef(j, stylesIdentifier, entry.styleKeys[i])));
|
|
17303
|
-
|
|
17304
|
-
|
|
18255
|
+
const expr = j.callExpression(cloneAstNode(entry.styleSelectorExpr), [j.objectExpression(properties)]);
|
|
18256
|
+
let finalExpr = expr;
|
|
18257
|
+
if (entry.guard) {
|
|
18258
|
+
const parsed = parseVariantWhenToAst(j, entry.guard.when);
|
|
18259
|
+
for (const p of parsed.props) if (p && !guardProps.includes(p)) guardProps.push(p);
|
|
18260
|
+
finalExpr = makeConditionalStyleExpr(j, {
|
|
18261
|
+
cond: parsed.cond,
|
|
18262
|
+
expr,
|
|
18263
|
+
isBoolean: parsed.isBoolean
|
|
18264
|
+
});
|
|
18265
|
+
}
|
|
18266
|
+
if (orderedEntries && entry.sourceOrder !== void 0) orderedEntries.push({
|
|
18267
|
+
order: entry.sourceOrder,
|
|
18268
|
+
expr: finalExpr
|
|
18269
|
+
});
|
|
18270
|
+
else aliasExprs.push(finalExpr);
|
|
18271
|
+
}
|
|
18272
|
+
if (aliasExprs.length > 0) styleArgs.unshift(...aliasExprs);
|
|
18273
|
+
return guardProps;
|
|
17305
18274
|
}
|
|
17306
18275
|
/**
|
|
17307
18276
|
* Appends pseudo-expand style args as static `styles.key` references.
|
|
@@ -17317,8 +18286,8 @@ function appendPseudoExpandStyleArgs(entries, styleArgs, j, stylesIdentifier) {
|
|
|
17317
18286
|
* Appends both pseudo-alias and pseudo-expand style args, deduplicating guard props.
|
|
17318
18287
|
* Returns the combined list of guard prop names that need destructuring.
|
|
17319
18288
|
*/
|
|
17320
|
-
function appendAllPseudoStyleArgs(d, styleArgs, j, stylesIdentifier) {
|
|
17321
|
-
const guardProps = appendPseudoAliasStyleArgs(d.pseudoAliasSelectors, styleArgs, j, stylesIdentifier);
|
|
18289
|
+
function appendAllPseudoStyleArgs(d, styleArgs, j, stylesIdentifier, orderedEntries) {
|
|
18290
|
+
const guardProps = appendPseudoAliasStyleArgs(d.pseudoAliasSelectors, styleArgs, j, stylesIdentifier, orderedEntries);
|
|
17322
18291
|
for (const gp of appendPseudoExpandStyleArgs(d.pseudoExpandSelectors, styleArgs, j, stylesIdentifier)) if (!guardProps.includes(gp)) guardProps.push(gp);
|
|
17323
18292
|
return guardProps;
|
|
17324
18293
|
}
|
|
@@ -17331,7 +18300,8 @@ function appendAllPseudoStyleArgs(d, styleArgs, j, stylesIdentifier) {
|
|
|
17331
18300
|
function buildAllVariantAndStyleExprs(opts) {
|
|
17332
18301
|
const { d, emitter, j, stylesIdentifier, styleArgs, destructureProps, propDefaults, compoundVariantKeys, afterVariantStyleArgs, enableComplementaryMerging, buildCompoundVariantExpressions } = opts;
|
|
17333
18302
|
const booleanProps = collectBooleanPropNames(d);
|
|
17334
|
-
const
|
|
18303
|
+
const knownProps = collectKnownConditionPropNames(emitter, d);
|
|
18304
|
+
const hasSourceOrder = hasStyleSourceOrder(d);
|
|
17335
18305
|
const orderedEntries = [];
|
|
17336
18306
|
buildVariantStyleExprs({
|
|
17337
18307
|
d,
|
|
@@ -17343,6 +18313,7 @@ function buildAllVariantAndStyleExprs(opts) {
|
|
|
17343
18313
|
hasSourceOrder,
|
|
17344
18314
|
destructureProps,
|
|
17345
18315
|
booleanProps,
|
|
18316
|
+
knownProps,
|
|
17346
18317
|
compoundVariantKeys,
|
|
17347
18318
|
enableComplementaryMerging
|
|
17348
18319
|
});
|
|
@@ -17351,10 +18322,11 @@ function buildAllVariantAndStyleExprs(opts) {
|
|
|
17351
18322
|
styleArgs,
|
|
17352
18323
|
destructureProps,
|
|
17353
18324
|
propDefaults,
|
|
17354
|
-
orderedEntries: hasSourceOrder ? orderedEntries : void 0
|
|
18325
|
+
orderedEntries: hasSourceOrder ? orderedEntries : void 0,
|
|
18326
|
+
knownProps
|
|
17355
18327
|
});
|
|
17356
18328
|
if (d.compoundVariants) buildCompoundVariantExpressions(d.compoundVariants, styleArgs, destructureProps);
|
|
17357
|
-
for (const gp of appendAllPseudoStyleArgs(d, styleArgs, j, stylesIdentifier)) if (!destructureProps.includes(gp)) destructureProps.push(gp);
|
|
18329
|
+
for (const gp of appendAllPseudoStyleArgs(d, styleArgs, j, stylesIdentifier, hasSourceOrder ? orderedEntries : void 0)) if (!destructureProps.includes(gp)) destructureProps.push(gp);
|
|
17358
18330
|
for (const prop of collectInlineStylePropNames(d.inlineStyleProps ?? [])) if (!destructureProps.includes(prop)) destructureProps.push(prop);
|
|
17359
18331
|
emitter.buildStyleFnExpressions({
|
|
17360
18332
|
d,
|
|
@@ -17439,11 +18411,19 @@ var WrapperEmitter = class {
|
|
|
17439
18411
|
* configure the hook.
|
|
17440
18412
|
*/
|
|
17441
18413
|
wrappedComponentAcceptsSxProp(componentLocalName) {
|
|
17442
|
-
|
|
18414
|
+
const componentInterface = this.wrappedComponentInterfaceFor(componentLocalName);
|
|
18415
|
+
return componentInterface?.acceptsSx === true && componentInterface.sxTarget !== "inner";
|
|
17443
18416
|
}
|
|
17444
18417
|
wrappedComponentInterfaceFor(componentLocalName) {
|
|
17445
18418
|
if (!this.useSxProp) return;
|
|
17446
18419
|
const importInfo = this.importMap.get(componentLocalName);
|
|
18420
|
+
const typedComponent = this.typeScriptComponentMetadataFor(componentLocalName);
|
|
18421
|
+
const typedInterface = typedComponent?.supportsSxProp ? {
|
|
18422
|
+
acceptsSx: true,
|
|
18423
|
+
...typedComponent.sxTarget ? { sxTarget: typedComponent.sxTarget } : {},
|
|
18424
|
+
sxExcludedProperties: typedComponent.sxExcludedProperties,
|
|
18425
|
+
sxAllowedProperties: typedComponent.sxAllowedProperties
|
|
18426
|
+
} : void 0;
|
|
17447
18427
|
if (importInfo) {
|
|
17448
18428
|
const adapterResult = this.wrappedComponentInterface?.({
|
|
17449
18429
|
localName: componentLocalName,
|
|
@@ -17451,15 +18431,10 @@ var WrapperEmitter = class {
|
|
|
17451
18431
|
importedName: importInfo.importedName,
|
|
17452
18432
|
filePath: this.filePath
|
|
17453
18433
|
});
|
|
17454
|
-
if (adapterResult !== void 0) return adapterResult;
|
|
18434
|
+
if (adapterResult !== void 0) return mergeWrappedComponentInterface(adapterResult, typedInterface);
|
|
17455
18435
|
}
|
|
17456
|
-
const typedComponent = this.typeScriptComponentMetadataFor(componentLocalName);
|
|
17457
18436
|
if (typedComponent) {
|
|
17458
|
-
if (
|
|
17459
|
-
acceptsSx: true,
|
|
17460
|
-
sxExcludedProperties: typedComponent.sxExcludedProperties,
|
|
17461
|
-
sxAllowedProperties: typedComponent.sxAllowedProperties
|
|
17462
|
-
};
|
|
18437
|
+
if (typedInterface) return typedInterface;
|
|
17463
18438
|
if (!this.hasSourceOverrideFor(componentLocalName)) return { acceptsSx: false };
|
|
17464
18439
|
}
|
|
17465
18440
|
return importInfo?.source.kind === "absolutePath" && transformedComponentAcceptsSx({
|
|
@@ -17567,7 +18542,7 @@ var WrapperEmitter = class {
|
|
|
17567
18542
|
return Boolean(d.usedAsValue) || this.isUsedAsValueInFile(d.localName);
|
|
17568
18543
|
}
|
|
17569
18544
|
isBroadValueUsage(d) {
|
|
17570
|
-
return this.isUsedAsValue(d) && d.valueUsageKind !== "
|
|
18545
|
+
return this.isUsedAsValue(d) && d.valueUsageKind !== "elementTypeProp";
|
|
17571
18546
|
}
|
|
17572
18547
|
requiresRestForValueUsage(d) {
|
|
17573
18548
|
return this.isUsedAsValueInFile(d.localName) || this.hasAliasedJsxSpreadUsage(d.localName);
|
|
@@ -17610,13 +18585,13 @@ var WrapperEmitter = class {
|
|
|
17610
18585
|
shouldAllowStyleProp(d) {
|
|
17611
18586
|
if (d.consumerUsesStyle ?? d.supportsExternalStyles) return true;
|
|
17612
18587
|
if (d.consumerUsesSpread) return this.spreadMayContainProp(d, "style");
|
|
17613
|
-
if (d.valueUsageKind === "
|
|
18588
|
+
if (d.valueUsageKind === "elementTypeProp") return true;
|
|
17614
18589
|
if (this.isBroadValueUsage(d)) return true;
|
|
17615
18590
|
const used = this.getUsedAttrs(d.localName);
|
|
17616
18591
|
return used.has("*") || used.has("style");
|
|
17617
18592
|
}
|
|
17618
18593
|
shouldAllowSxProp(d) {
|
|
17619
|
-
if (d.valueUsageKind === "
|
|
18594
|
+
if (d.valueUsageKind === "elementTypeProp") return (d.supportsExternalStyles ?? false) || d.typeScriptSupportsSxProp === true;
|
|
17620
18595
|
return (d.supportsExternalStyles ?? false) || d.typeScriptSupportsSxProp === true || this.shouldAllowClassNameProp(d) || this.shouldAllowStyleProp(d);
|
|
17621
18596
|
}
|
|
17622
18597
|
typedComponentHasProp(componentLocalName, propName) {
|
|
@@ -18507,6 +19482,9 @@ var WrapperEmitter = class {
|
|
|
18507
19482
|
buildExtraStylexPropsExprs(args) {
|
|
18508
19483
|
return buildExtraStylexPropsExprs(this.j, args);
|
|
18509
19484
|
}
|
|
19485
|
+
buildExtraStylexPropsExprEntries(args) {
|
|
19486
|
+
return buildExtraStylexPropsExprEntries(this.j, args);
|
|
19487
|
+
}
|
|
18510
19488
|
literalExpr(value) {
|
|
18511
19489
|
return literalExpr(this.j, value);
|
|
18512
19490
|
}
|
|
@@ -19203,18 +20181,20 @@ function emitComponentWrappers(emitter) {
|
|
|
19203
20181
|
const styleValueVariantProps = new Set(d.styleValueVariantProps ?? []);
|
|
19204
20182
|
const observedExpressionConditionDropProps = new Set(d.observedExpressionConditionDropProps ?? []);
|
|
19205
20183
|
for (const prop of styleValueVariantProps) styleFnValueProps.add(prop);
|
|
19206
|
-
const propsArgExprs = d.extraStylexPropsArgs ? emitter.
|
|
20184
|
+
const propsArgExprs = d.extraStylexPropsArgs ? emitter.buildExtraStylexPropsExprEntries({
|
|
19207
20185
|
entries: d.extraStylexPropsArgs,
|
|
19208
20186
|
destructureProps
|
|
19209
20187
|
}) : [];
|
|
19210
|
-
const { beforeBase: extraStyleArgs, afterBase: extraStyleArgsAfterBase } = emitter.buildInterleavedExtraStyleArgs(d, propsArgExprs);
|
|
20188
|
+
const { beforeBase: extraStyleArgs, afterBase: extraStyleArgsAfterBase, afterVariants: afterVariantStyleArgs } = emitter.buildInterleavedExtraStyleArgs(d, propsArgExprs);
|
|
19211
20189
|
const styleArgs = [
|
|
19212
20190
|
...extraStyleArgs,
|
|
19213
20191
|
...emitter.baseStyleExpr(d),
|
|
19214
20192
|
...extraStyleArgsAfterBase
|
|
19215
20193
|
];
|
|
19216
|
-
const hasSourceOrder =
|
|
20194
|
+
const hasSourceOrder = hasStyleSourceOrder(d);
|
|
19217
20195
|
const orderedEntries = [];
|
|
20196
|
+
const booleanProps = collectBooleanPropNames(d);
|
|
20197
|
+
const knownProps = collectKnownConditionPropNames(emitter, d);
|
|
19218
20198
|
buildVariantStyleExprs({
|
|
19219
20199
|
d,
|
|
19220
20200
|
emitter,
|
|
@@ -19224,7 +20204,8 @@ function emitComponentWrappers(emitter) {
|
|
|
19224
20204
|
orderedEntries,
|
|
19225
20205
|
hasSourceOrder,
|
|
19226
20206
|
destructureProps,
|
|
19227
|
-
booleanProps
|
|
20207
|
+
booleanProps,
|
|
20208
|
+
knownProps,
|
|
19228
20209
|
compoundVariantKeys: collectCompoundVariantKeys(d.compoundVariants),
|
|
19229
20210
|
enableComplementaryMerging: true,
|
|
19230
20211
|
onNewDestructureProp: (prop) => styleOnlyConditionProps.add(prop)
|
|
@@ -19235,7 +20216,8 @@ function emitComponentWrappers(emitter) {
|
|
|
19235
20216
|
destructureProps,
|
|
19236
20217
|
propDefaults,
|
|
19237
20218
|
namespaceBooleanProps,
|
|
19238
|
-
orderedEntries: hasSourceOrder ? orderedEntries : void 0
|
|
20219
|
+
orderedEntries: hasSourceOrder ? orderedEntries : void 0,
|
|
20220
|
+
knownProps
|
|
19239
20221
|
});
|
|
19240
20222
|
if (d.compoundVariants) {
|
|
19241
20223
|
const prevLengthCompound = destructureProps.length;
|
|
@@ -19251,7 +20233,7 @@ function emitComponentWrappers(emitter) {
|
|
|
19251
20233
|
const needsUseTheme = appendThemeBooleanStyleArgs(d.needsUseThemeHook, styleArgs, j, stylesIdentifier, () => {
|
|
19252
20234
|
needsUseThemeImport = true;
|
|
19253
20235
|
});
|
|
19254
|
-
for (const gp of appendAllPseudoStyleArgs(d, styleArgs, j, stylesIdentifier)) if (!destructureProps.includes(gp)) {
|
|
20236
|
+
for (const gp of appendAllPseudoStyleArgs(d, styleArgs, j, stylesIdentifier, hasSourceOrder ? orderedEntries : void 0)) if (!destructureProps.includes(gp)) {
|
|
19255
20237
|
destructureProps.push(gp);
|
|
19256
20238
|
styleOnlyConditionProps.add(gp);
|
|
19257
20239
|
}
|
|
@@ -19275,6 +20257,7 @@ function emitComponentWrappers(emitter) {
|
|
|
19275
20257
|
styleFnValueProps.add(prop);
|
|
19276
20258
|
}
|
|
19277
20259
|
mergeOrderedEntries(orderedEntries, styleArgs);
|
|
20260
|
+
if (afterVariantStyleArgs.length > 0) styleArgs.push(...afterVariantStyleArgs);
|
|
19278
20261
|
const filterOnlyTransientProps = [];
|
|
19279
20262
|
const wrapperOnlyTransientProps = [];
|
|
19280
20263
|
const wrapperExplicitPropNames = /* @__PURE__ */ new Set();
|
|
@@ -19414,7 +20397,11 @@ function emitComponentWrappers(emitter) {
|
|
|
19414
20397
|
if (!firstPart || memberParts.length === 0) jsxTagName = j.jsxIdentifier(renderedComponent);
|
|
19415
20398
|
else jsxTagName = memberParts.reduce((object, member) => j.jsxMemberExpression(object, j.jsxIdentifier(member)), j.jsxIdentifier(firstPart));
|
|
19416
20399
|
} else jsxTagName = j.jsxIdentifier(renderedComponent);
|
|
19417
|
-
const
|
|
20400
|
+
const ownBridgeClassVar = getBridgeClassVar(d);
|
|
20401
|
+
const inheritedBridgeClassVar = renderedComponent !== wrappedComponent && wrappedLocalDecl ? getBridgeClassVar(wrappedLocalDecl) : void 0;
|
|
20402
|
+
const hasInheritedBridgeExtraClass = !!inheritedBridgeClassVar && (d.extraClassNames ?? []).some((entry) => entry.expr.type === "Identifier" && entry.expr.name === inheritedBridgeClassVar);
|
|
20403
|
+
const inheritedBridgeClassNames = inheritedBridgeClassVar && inheritedBridgeClassVar !== ownBridgeClassVar && !hasInheritedBridgeExtraClass ? [{ expr: j.identifier(inheritedBridgeClassVar) }] : [];
|
|
20404
|
+
const { attrsInfo, staticClassNameExpr } = emitter.splitAttrsInfo(d.attrsInfo, ownBridgeClassVar, inheritedBridgeClassNames.length > 0 ? [...inheritedBridgeClassNames, ...d.extraClassNames ?? []] : d.extraClassNames);
|
|
19418
20405
|
const defaultAttrs = attrsInfo?.defaultAttrs ?? [];
|
|
19419
20406
|
const dynamicAttrs = attrsInfo?.dynamicAttrs ?? [];
|
|
19420
20407
|
const staticAttrs = normalizeStaticForwardedAsAttr(attrsInfo?.staticAttrs ?? {}, shouldLowerForwardedAs);
|
|
@@ -20688,7 +21675,7 @@ function emitInputWrappers(ctx) {
|
|
|
20688
21675
|
}
|
|
20689
21676
|
])
|
|
20690
21677
|
];
|
|
20691
|
-
const pseudoGuardProps = appendAllPseudoStyleArgs(d, styleArgs, j, stylesIdentifier);
|
|
21678
|
+
const pseudoGuardProps = appendAllPseudoStyleArgs(d, styleArgs, j, stylesIdentifier, void 0);
|
|
20692
21679
|
const extraDestructureProps = ["type"];
|
|
20693
21680
|
if (aw.readonlyKey) extraDestructureProps.push("readOnly");
|
|
20694
21681
|
buildAttrWrapperBody(ctx, {
|
|
@@ -20752,7 +21739,7 @@ function emitLinkWrappers(ctx) {
|
|
|
20752
21739
|
}
|
|
20753
21740
|
])
|
|
20754
21741
|
];
|
|
20755
|
-
const pseudoGuardProps = appendAllPseudoStyleArgs(d, styleArgs, j, stylesIdentifier);
|
|
21742
|
+
const pseudoGuardProps = appendAllPseudoStyleArgs(d, styleArgs, j, stylesIdentifier, void 0);
|
|
20756
21743
|
const hrefId = j.identifier("href");
|
|
20757
21744
|
const targetId = j.identifier("target");
|
|
20758
21745
|
buildAttrWrapperBody(ctx, {
|
|
@@ -20833,7 +21820,7 @@ function emitEnumVariantWrappers(ctx) {
|
|
|
20833
21820
|
j.logicalExpression("&&", condPrimary, styleRef(j, stylesIdentifier, primary.styleKey)),
|
|
20834
21821
|
j.logicalExpression("&&", condSecondary, styleRef(j, stylesIdentifier, secondary.styleKey))
|
|
20835
21822
|
];
|
|
20836
|
-
const pseudoGuardPropsEnum = appendAllPseudoStyleArgs(d, styleArgs, j, stylesIdentifier);
|
|
21823
|
+
const pseudoGuardPropsEnum = appendAllPseudoStyleArgs(d, styleArgs, j, stylesIdentifier, void 0);
|
|
20837
21824
|
if (pseudoGuardPropsEnum.length > 0) injectDestructureProps(j, declStmt, pseudoGuardPropsEnum);
|
|
20838
21825
|
const sxDecl = j.variableDeclaration("const", [j.variableDeclarator(j.identifier("sx"), j.callExpression(j.memberExpression(j.identifier("stylex"), j.identifier("props")), styleArgs))]);
|
|
20839
21826
|
const openingEl = j.jsxOpeningElement(j.jsxIdentifier(allowAsProp ? "Component" : "div"), [j.jsxSpreadAttribute(j.identifier("sx")), ...includesForwardedAs ? [j.jsxAttribute(j.jsxIdentifier("as"), j.jsxExpressionContainer(forwardedAsId))] : []], false);
|
|
@@ -20951,11 +21938,11 @@ function emitIntrinsicPolymorphicWrappers(ctx) {
|
|
|
20951
21938
|
ctx.markNeedsReactTypeImport();
|
|
20952
21939
|
const destructureProps = [];
|
|
20953
21940
|
const propDefaults = /* @__PURE__ */ new Map();
|
|
20954
|
-
const propsArgExprs = d.extraStylexPropsArgs ? emitter.
|
|
21941
|
+
const propsArgExprs = d.extraStylexPropsArgs ? emitter.buildExtraStylexPropsExprEntries({
|
|
20955
21942
|
entries: d.extraStylexPropsArgs,
|
|
20956
21943
|
destructureProps
|
|
20957
21944
|
}) : [];
|
|
20958
|
-
const { beforeBase: extraStyleArgs, afterBase: extraStyleArgsAfterBase } = emitter.buildInterleavedExtraStyleArgs(d, propsArgExprs);
|
|
21945
|
+
const { beforeBase: extraStyleArgs, afterBase: extraStyleArgsAfterBase, afterVariants: afterVariantStyleArgs } = emitter.buildInterleavedExtraStyleArgs(d, propsArgExprs);
|
|
20959
21946
|
const styleArgs = buildInitialStyleArgs(j, stylesIdentifier, d, extraStyleArgs, extraStyleArgsAfterBase);
|
|
20960
21947
|
buildAllVariantAndStyleExprs({
|
|
20961
21948
|
d,
|
|
@@ -20966,6 +21953,7 @@ function emitIntrinsicPolymorphicWrappers(ctx) {
|
|
|
20966
21953
|
destructureProps,
|
|
20967
21954
|
propDefaults,
|
|
20968
21955
|
compoundVariantKeys: collectCompoundVariantKeys(d.compoundVariants),
|
|
21956
|
+
afterVariantStyleArgs,
|
|
20969
21957
|
buildCompoundVariantExpressions
|
|
20970
21958
|
});
|
|
20971
21959
|
const isVoidTag = VOID_TAGS.has(tagName);
|
|
@@ -21083,9 +22071,13 @@ function emitShouldForwardPropWrappers(ctx) {
|
|
|
21083
22071
|
const includesForwardedAs = hasForwardedAsUsage(d);
|
|
21084
22072
|
const allowAsProp = shouldAllowAsProp(d, tagName);
|
|
21085
22073
|
const extraProps = /* @__PURE__ */ new Set();
|
|
22074
|
+
const knownConditionProps = collectKnownConditionPropNames(emitter, d);
|
|
21086
22075
|
for (const p of d.shouldForwardProp?.dropProps ?? []) if (p) extraProps.add(p);
|
|
21087
22076
|
for (const when of Object.keys(d.variantStyleKeys ?? {})) {
|
|
21088
|
-
const { props } = emitter.collectConditionProps({
|
|
22077
|
+
const { props } = emitter.collectConditionProps({
|
|
22078
|
+
when,
|
|
22079
|
+
...knownConditionProps ? { knownProps: knownConditionProps } : {}
|
|
22080
|
+
});
|
|
21089
22081
|
for (const p of props) if (p) extraProps.add(p);
|
|
21090
22082
|
}
|
|
21091
22083
|
for (const dim of d.variantDimensions ?? []) extraProps.add(dim.propName);
|
|
@@ -21203,15 +22195,16 @@ function emitShouldForwardPropWrappers(ctx) {
|
|
|
21203
22195
|
}
|
|
21204
22196
|
ctx.markNeedsReactTypeImport();
|
|
21205
22197
|
const propDefaults = /* @__PURE__ */ new Map();
|
|
21206
|
-
const propsArgExprs = d.extraStylexPropsArgs ? emitter.
|
|
22198
|
+
const propsArgExprs = d.extraStylexPropsArgs ? emitter.buildExtraStylexPropsExprEntries({ entries: d.extraStylexPropsArgs }) : [];
|
|
21207
22199
|
const { beforeBase: extraStyleArgs, afterBase: extraStyleArgsAfterBase, afterVariants: afterVariantStyleArgs } = emitter.buildInterleavedExtraStyleArgs(d, propsArgExprs);
|
|
21208
22200
|
const styleArgs = buildInitialStyleArgs(j, stylesIdentifier, d, extraStyleArgs, extraStyleArgsAfterBase);
|
|
21209
22201
|
const needsUseTheme = appendThemeBooleanStyleArgs(d.needsUseThemeHook, styleArgs, j, stylesIdentifier, () => ctx.markNeedsUseThemeImport());
|
|
21210
|
-
const pseudoGuardProps = appendAllPseudoStyleArgs(d, styleArgs, j, stylesIdentifier);
|
|
21211
22202
|
const compoundVariantKeys = collectCompoundVariantKeys(d.compoundVariants);
|
|
21212
22203
|
const booleanProps = collectBooleanPropNames(d);
|
|
21213
|
-
const
|
|
22204
|
+
const knownProps = collectKnownConditionPropNames(emitter, d);
|
|
22205
|
+
const hasSourceOrder = hasStyleSourceOrder(d);
|
|
21214
22206
|
const orderedEntries = [];
|
|
22207
|
+
const pseudoGuardProps = appendAllPseudoStyleArgs(d, styleArgs, j, stylesIdentifier, hasSourceOrder ? orderedEntries : void 0);
|
|
21215
22208
|
buildVariantStyleExprs({
|
|
21216
22209
|
d,
|
|
21217
22210
|
emitter,
|
|
@@ -21221,12 +22214,16 @@ function emitShouldForwardPropWrappers(ctx) {
|
|
|
21221
22214
|
orderedEntries,
|
|
21222
22215
|
hasSourceOrder,
|
|
21223
22216
|
booleanProps,
|
|
22217
|
+
knownProps,
|
|
21224
22218
|
compoundVariantKeys
|
|
21225
22219
|
});
|
|
21226
22220
|
const dropProps = d.shouldForwardProp?.dropProps ?? [];
|
|
21227
22221
|
if (d.variantStyleKeys) for (const when of Object.keys(d.variantStyleKeys)) {
|
|
21228
22222
|
if (compoundVariantKeys.has(when)) continue;
|
|
21229
|
-
const { props } = emitter.collectConditionProps({
|
|
22223
|
+
const { props } = emitter.collectConditionProps({
|
|
22224
|
+
when,
|
|
22225
|
+
...knownProps ? { knownProps } : {}
|
|
22226
|
+
});
|
|
21230
22227
|
for (const p of props) if (p && !dropProps.includes(p)) dropProps.push(p);
|
|
21231
22228
|
}
|
|
21232
22229
|
const dropPrefix = d.shouldForwardProp?.dropPrefix;
|
|
@@ -21234,7 +22231,10 @@ function emitShouldForwardPropWrappers(ctx) {
|
|
|
21234
22231
|
for (const p of dropProps) destructureParts.push(p);
|
|
21235
22232
|
if (d.extraStylexPropsArgs) {
|
|
21236
22233
|
for (const extra of d.extraStylexPropsArgs) if (extra.when) {
|
|
21237
|
-
const { props } = emitter.collectConditionProps({
|
|
22234
|
+
const { props } = emitter.collectConditionProps({
|
|
22235
|
+
when: extra.when,
|
|
22236
|
+
...knownProps ? { knownProps } : {}
|
|
22237
|
+
});
|
|
21238
22238
|
for (const p of props) if (p && !destructureParts.includes(p)) destructureParts.push(p);
|
|
21239
22239
|
}
|
|
21240
22240
|
}
|
|
@@ -21244,7 +22244,8 @@ function emitShouldForwardPropWrappers(ctx) {
|
|
|
21244
22244
|
styleArgs,
|
|
21245
22245
|
destructureProps: destructureParts,
|
|
21246
22246
|
propDefaults,
|
|
21247
|
-
orderedEntries: hasSourceOrder ? orderedEntries : void 0
|
|
22247
|
+
orderedEntries: hasSourceOrder ? orderedEntries : void 0,
|
|
22248
|
+
knownProps
|
|
21248
22249
|
});
|
|
21249
22250
|
if (d.compoundVariants) buildCompoundVariantExpressions(d.compoundVariants, styleArgs, destructureParts);
|
|
21250
22251
|
const styleFnPairs = d.styleFnFromProps ?? [];
|
|
@@ -21265,7 +22266,8 @@ function emitShouldForwardPropWrappers(ctx) {
|
|
|
21265
22266
|
const { cond, isBoolean } = emitter.collectConditionProps({
|
|
21266
22267
|
when: p.conditionWhen,
|
|
21267
22268
|
destructureProps: destructureParts,
|
|
21268
|
-
booleanProps
|
|
22269
|
+
booleanProps,
|
|
22270
|
+
...knownProps ? { knownProps } : {}
|
|
21269
22271
|
});
|
|
21270
22272
|
expr = emitter.makeConditionalStyleExpr({
|
|
21271
22273
|
cond,
|
|
@@ -21499,7 +22501,7 @@ function emitSimpleWithConfigWrappers(ctx) {
|
|
|
21499
22501
|
if (d.consumerUsesSpread === true || d.consumerUsesElementProps === true || d.consumerUsesSpread === void 0 && d.consumerUsesElementProps === void 0 && supportsExternalStyles) return true;
|
|
21500
22502
|
if (allowClassNameProp || allowStyleProp || allowSxProp) return true;
|
|
21501
22503
|
const used = emitter.getUsedAttrs(d.localName);
|
|
21502
|
-
if (used.has("*") || d.valueUsageKind === "
|
|
22504
|
+
if (used.has("*") || d.valueUsageKind === "elementTypeProp") return true;
|
|
21503
22505
|
return used.size > 0;
|
|
21504
22506
|
})();
|
|
21505
22507
|
const baseTypeText = shouldUseIntrinsicProps ? emitter.inferredIntrinsicPropsTypeText({
|
|
@@ -21546,7 +22548,7 @@ function emitSimpleWithConfigWrappers(ctx) {
|
|
|
21546
22548
|
const { beforeBase: extraStyleArgs, afterBase: extraStyleArgsAfterBase } = emitter.splitExtraStyleArgs(d);
|
|
21547
22549
|
const styleArgs = buildInitialStyleArgs(j, stylesIdentifier, d, extraStyleArgs, extraStyleArgsAfterBase);
|
|
21548
22550
|
const needsUseThemeWithConfig = appendThemeBooleanStyleArgs(d.needsUseThemeHook, styleArgs, j, stylesIdentifier, () => ctx.markNeedsUseThemeImport());
|
|
21549
|
-
const pseudoGuardProps = appendAllPseudoStyleArgs(d, styleArgs, j, stylesIdentifier);
|
|
22551
|
+
const pseudoGuardProps = appendAllPseudoStyleArgs(d, styleArgs, j, stylesIdentifier, void 0);
|
|
21550
22552
|
const propsParamId = j.identifier("props");
|
|
21551
22553
|
if (allowAsProp && emitTypes) emitter.annotatePropsParam(propsParamId, d.localName, `${emitter.propsTypeNameFor(d.localName)}<C>`);
|
|
21552
22554
|
else emitter.annotatePropsParam(propsParamId, d.localName);
|
|
@@ -21560,8 +22562,12 @@ function emitSimpleWithConfigWrappers(ctx) {
|
|
|
21560
22562
|
const usedAttrs = emitter.getUsedAttrs(d.localName);
|
|
21561
22563
|
const includeRest = usedAttrs.has("*") || emitter.isBroadValueUsage(d) || (d.isExported ?? false) || usedAttrs.size > 0 || hasElementPropsInDefaultAttrs(d);
|
|
21562
22564
|
const variantProps = /* @__PURE__ */ new Set();
|
|
22565
|
+
const knownProps = collectKnownConditionPropNames(emitter, d);
|
|
21563
22566
|
if (d.variantStyleKeys) for (const [when] of Object.entries(d.variantStyleKeys)) {
|
|
21564
|
-
const { props } = emitter.collectConditionProps({
|
|
22567
|
+
const { props } = emitter.collectConditionProps({
|
|
22568
|
+
when,
|
|
22569
|
+
...knownProps ? { knownProps } : {}
|
|
22570
|
+
});
|
|
21565
22571
|
for (const p of props) if (p) variantProps.add(p);
|
|
21566
22572
|
}
|
|
21567
22573
|
for (const dim of d.variantDimensions ?? []) variantProps.add(dim.propName);
|
|
@@ -21572,7 +22578,10 @@ function emitSimpleWithConfigWrappers(ctx) {
|
|
|
21572
22578
|
const extraProps = /* @__PURE__ */ new Set();
|
|
21573
22579
|
if (d.extraStylexPropsArgs) for (const extra of d.extraStylexPropsArgs) {
|
|
21574
22580
|
if (!extra.when) continue;
|
|
21575
|
-
const { props } = emitter.collectConditionProps({
|
|
22581
|
+
const { props } = emitter.collectConditionProps({
|
|
22582
|
+
when: extra.when,
|
|
22583
|
+
...knownProps ? { knownProps } : {}
|
|
22584
|
+
});
|
|
21576
22585
|
for (const p of props) if (p) extraProps.add(p);
|
|
21577
22586
|
}
|
|
21578
22587
|
const inlineProps = new Set(collectInlineStylePropNames(d.inlineStyleProps ?? []));
|
|
@@ -21715,7 +22724,7 @@ function emitSimpleExportedIntrinsicWrappers(ctx) {
|
|
|
21715
22724
|
let inlineTypeText;
|
|
21716
22725
|
const isExportedComponent = d.isExported ?? false;
|
|
21717
22726
|
const usePolymorphicPattern = allowAsProp && isExportedComponent;
|
|
21718
|
-
const willForwardRef = (d.supportsRefProp ?? false) || isExportedComponent || d.valueUsageKind === "
|
|
22727
|
+
const willForwardRef = (d.supportsRefProp ?? false) || isExportedComponent || d.valueUsageKind === "elementTypeProp" || hasComplementaryVariantPairs(d) || !!d.variantDimensions?.some((dim) => dim.namespaceBooleanProp);
|
|
21719
22728
|
const useSlimType = !isExportedComponent && !(d.supportsExternalStyles ?? false) && !emitter.isBroadValueUsage(d) && !hasElementPropsInDefaultAttrs(d);
|
|
21720
22729
|
{
|
|
21721
22730
|
const explicit = emitter.stringifyTsType(d.propsType);
|
|
@@ -21881,7 +22890,7 @@ function emitSimpleExportedIntrinsicWrappers(ctx) {
|
|
|
21881
22890
|
}
|
|
21882
22891
|
const destructureProps = [];
|
|
21883
22892
|
const propDefaults = /* @__PURE__ */ new Map();
|
|
21884
|
-
const propsArgExprs = d.extraStylexPropsArgs ? emitter.
|
|
22893
|
+
const propsArgExprs = d.extraStylexPropsArgs ? emitter.buildExtraStylexPropsExprEntries({
|
|
21885
22894
|
entries: d.extraStylexPropsArgs,
|
|
21886
22895
|
destructureProps
|
|
21887
22896
|
}) : [];
|
|
@@ -22160,13 +23169,13 @@ function getTypeNameText(typeName) {
|
|
|
22160
23169
|
}
|
|
22161
23170
|
return null;
|
|
22162
23171
|
}
|
|
22163
|
-
function collectPropsUsedOutsideExtraStyleConditionals(j, d) {
|
|
23172
|
+
function collectPropsUsedOutsideExtraStyleConditionals(j, d, knownProps) {
|
|
22164
23173
|
const used = /* @__PURE__ */ new Set();
|
|
22165
23174
|
const add = (name) => {
|
|
22166
23175
|
if (name) used.add(name);
|
|
22167
23176
|
};
|
|
22168
23177
|
for (const [when] of Object.entries(d.variantStyleKeys ?? {})) {
|
|
22169
|
-
const parsed = parseVariantWhenToAst(j, when);
|
|
23178
|
+
const parsed = parseVariantWhenToAst(j, when, void 0, knownProps);
|
|
22170
23179
|
for (const prop of parsed.props) add(prop);
|
|
22171
23180
|
}
|
|
22172
23181
|
for (const dim of d.variantDimensions ?? []) {
|
|
@@ -23588,6 +24597,18 @@ function tryResolveConditionalValue(node, ctx) {
|
|
|
23588
24597
|
};
|
|
23589
24598
|
}
|
|
23590
24599
|
if (!b || typeof b !== "object") return null;
|
|
24600
|
+
if (b.type === "BinaryExpression") {
|
|
24601
|
+
const binary = b;
|
|
24602
|
+
if (isCssCalcOperator$1(binary.operator)) {
|
|
24603
|
+
const left = branchToExpr(binary.left);
|
|
24604
|
+
const right = branchToExpr(binary.right);
|
|
24605
|
+
if (left && right && left.usage === expectedUsage && right.usage === expectedUsage && (left.imports.length > 0 || right.imports.length > 0) && isCssCalcSafeOperand(left) && isCssCalcSafeOperand(right)) return {
|
|
24606
|
+
usage: expectedUsage,
|
|
24607
|
+
expr: buildCssCalcExprSource(left, binary.operator, right),
|
|
24608
|
+
imports: [...left.imports, ...right.imports]
|
|
24609
|
+
};
|
|
24610
|
+
}
|
|
24611
|
+
}
|
|
23591
24612
|
const callHasThemeArg = (call) => (call.arguments ?? []).some((arg) => {
|
|
23592
24613
|
if (!arg || typeof arg !== "object" || arg.type !== "MemberExpression") return false;
|
|
23593
24614
|
if (propsParamName) {
|
|
@@ -24072,6 +25093,21 @@ function tryResolveConditionalValue(node, ctx) {
|
|
|
24072
25093
|
}
|
|
24073
25094
|
return buildRuntimeCallResult();
|
|
24074
25095
|
}
|
|
25096
|
+
function isCssCalcOperator$1(operator) {
|
|
25097
|
+
return operator === "+" || operator === "-" || operator === "*" || operator === "/";
|
|
25098
|
+
}
|
|
25099
|
+
function isCssCalcSafeOperand(branch) {
|
|
25100
|
+
return branch.imports.length > 0 || isNumericExpressionSource(branch.expr);
|
|
25101
|
+
}
|
|
25102
|
+
function isNumericExpressionSource(expr) {
|
|
25103
|
+
return /^-?(?:0|[1-9]\d*)(?:\.\d+)?$/.test(expr);
|
|
25104
|
+
}
|
|
25105
|
+
function buildCssCalcExprSource(left, operator, right) {
|
|
25106
|
+
return `\`calc(${cssCalcOperandSource(left)} ${operator} ${cssCalcOperandSource(right)})\``;
|
|
25107
|
+
}
|
|
25108
|
+
function cssCalcOperandSource(branch) {
|
|
25109
|
+
return branch.imports.length > 0 ? `\${${branch.expr}}` : branch.expr;
|
|
25110
|
+
}
|
|
24075
25111
|
function tryResolveConditionalCssBlock(node, ctx) {
|
|
24076
25112
|
const expr = node.expr;
|
|
24077
25113
|
if (!isArrowFunctionExpression(expr)) return null;
|
|
@@ -26046,7 +27082,11 @@ function tryHandleInterpolatedStringValue(args) {
|
|
|
26046
27082
|
cssValue: d.value,
|
|
26047
27083
|
resolveCallExpr,
|
|
26048
27084
|
resolveImportedValueExpr,
|
|
26049
|
-
addImport
|
|
27085
|
+
addImport,
|
|
27086
|
+
multiline: {
|
|
27087
|
+
property: (d.property ?? "").trim(),
|
|
27088
|
+
stylisValueRaw: d.valueRaw ?? ""
|
|
27089
|
+
}
|
|
26050
27090
|
});
|
|
26051
27091
|
if (!tl) return false;
|
|
26052
27092
|
const outputs = cssDeclarationToStylexDeclarations(d);
|
|
@@ -26061,7 +27101,7 @@ function tryHandleInterpolatedStringValue(args) {
|
|
|
26061
27101
|
return true;
|
|
26062
27102
|
}
|
|
26063
27103
|
function buildInterpolatedTemplate(args) {
|
|
26064
|
-
const { j, decl, cssValue, resolveCallExpr, resolveImportedValueExpr, addImport } = args;
|
|
27104
|
+
const { j, decl, cssValue, resolveCallExpr, resolveImportedValueExpr, addImport, multiline } = args;
|
|
26065
27105
|
if (!cssValue || cssValue.kind !== "interpolated") return null;
|
|
26066
27106
|
const parts = cssValue.parts ?? [];
|
|
26067
27107
|
const exprs = [];
|
|
@@ -26149,7 +27189,13 @@ function buildInterpolatedTemplate(args) {
|
|
|
26149
27189
|
raw: q,
|
|
26150
27190
|
cooked: q
|
|
26151
27191
|
}, true));
|
|
26152
|
-
|
|
27192
|
+
const templateLiteral = j.templateLiteral(quasis, exprs);
|
|
27193
|
+
if (!multiline) return templateLiteral;
|
|
27194
|
+
return maybeApplyAuthoredMultilineToExpression(j, templateLiteral, {
|
|
27195
|
+
rawCss: decl.rawCss,
|
|
27196
|
+
property: multiline.property,
|
|
27197
|
+
stylisValueRaw: multiline.stylisValueRaw
|
|
27198
|
+
});
|
|
26153
27199
|
}
|
|
26154
27200
|
function hasAdjacentUnitInParts(parts, slotIndex) {
|
|
26155
27201
|
const before = parts[slotIndex - 1]?.kind === "static" ? parts[slotIndex - 1]?.value ?? "" : "";
|
|
@@ -27399,6 +28445,57 @@ const createCssHelperHandlers = (ctx) => {
|
|
|
27399
28445
|
};
|
|
27400
28446
|
};
|
|
27401
28447
|
//#endregion
|
|
28448
|
+
//#region src/internal/lower-rules/observed-variant-buckets.ts
|
|
28449
|
+
/** Upper bound on observed values before bucketing is considered too broad to be worthwhile. */
|
|
28450
|
+
const MAX_OBSERVED_VARIANT_VALUES = 20;
|
|
28451
|
+
/**
|
|
28452
|
+
* Validates that `propName` is an optional prop whose consumer usage is exhaustively observed
|
|
28453
|
+
* (it is sometimes omitted and every supplied value is a static string/number), returning the
|
|
28454
|
+
* observed values when bucketing is viable or `null` to bail.
|
|
28455
|
+
*
|
|
28456
|
+
* These buckets carry no runtime fallback, so they are only sound when every call site is
|
|
28457
|
+
* observable. Both flags are required and force a bail when set:
|
|
28458
|
+
* - `isExported`: callers outside the analyzed set can render the component with unseen values.
|
|
28459
|
+
* - `escapesAsValue`: the component is passed as a value (innerElementType/as/HOC/alias), so an
|
|
28460
|
+
* unobserved host may render it with unseen values.
|
|
28461
|
+
* In both cases callers fall back to dynamic styles instead.
|
|
28462
|
+
*/
|
|
28463
|
+
function resolveObservedVariantValues(args) {
|
|
28464
|
+
if (args.isExported || args.escapesAsValue || !args.isOptional) return null;
|
|
28465
|
+
if ((args.usage?.props[args.propName]?.omittedCount ?? 0) === 0) return null;
|
|
28466
|
+
const values = getExhaustiveObservedStaticValues(args.usage, args.propName);
|
|
28467
|
+
if (!values || values.length < (args.minValues ?? 1) || values.length > MAX_OBSERVED_VARIANT_VALUES) return null;
|
|
28468
|
+
return values;
|
|
28469
|
+
}
|
|
28470
|
+
/**
|
|
28471
|
+
* Computes every bucket up front and emits atomically: if any value bails, nothing is emitted and
|
|
28472
|
+
* `false` is returned so the caller can fall back to its dynamic path. Returns `true` once at least
|
|
28473
|
+
* one variant has been emitted and the prop has been marked for lookup-cast + drop + wrapping.
|
|
28474
|
+
*/
|
|
28475
|
+
function emitObservedVariantBuckets(params) {
|
|
28476
|
+
const buckets = [];
|
|
28477
|
+
for (const propValue of params.observedValues) {
|
|
28478
|
+
const result = params.buildBucket(propValue);
|
|
28479
|
+
if (result.kind === "bail") return false;
|
|
28480
|
+
if (result.kind === "skip" || Object.keys(result.style).length === 0) continue;
|
|
28481
|
+
const condition = formatObservedVariantCondition(params.propName, propValue);
|
|
28482
|
+
buckets.push({
|
|
28483
|
+
when: result.whenPrefix ? `${result.whenPrefix} && ${condition}` : condition,
|
|
28484
|
+
style: result.style
|
|
28485
|
+
});
|
|
28486
|
+
}
|
|
28487
|
+
if (buckets.length === 0) return false;
|
|
28488
|
+
for (const { when, style } of buckets) params.applyVariant({
|
|
28489
|
+
when,
|
|
28490
|
+
propName: params.propName
|
|
28491
|
+
}, style);
|
|
28492
|
+
params.decl.variantLookupCastProps ??= /* @__PURE__ */ new Set();
|
|
28493
|
+
params.decl.variantLookupCastProps.add(params.propName);
|
|
28494
|
+
params.ensurePropDrop(params.propName);
|
|
28495
|
+
params.decl.needsWrapperComponent = true;
|
|
28496
|
+
return true;
|
|
28497
|
+
}
|
|
28498
|
+
//#endregion
|
|
27402
28499
|
//#region src/internal/lower-rules/static-evaluator.ts
|
|
27403
28500
|
const MAX_STATIC_CALL_DEPTH = 20;
|
|
27404
28501
|
function evaluateLocalCallValueTransform(args) {
|
|
@@ -27631,7 +28728,7 @@ function isStaticEvalValue(value) {
|
|
|
27631
28728
|
//#endregion
|
|
27632
28729
|
//#region src/internal/lower-rules/css-helper-conditional.ts
|
|
27633
28730
|
function createCssHelperConditionalHandler(ctx) {
|
|
27634
|
-
const { j, decl, filePath, warnings, parseExpr, resolveValue, resolveCall, resolveSelector, resolveImportInScope, resolverImports, componentInfo, handlerContext, styleObj, styleFnFromProps, styleFnDecls, inlineStyleProps, isCssHelperTaggedTemplate, resolveCssHelperTemplate, resolveStaticCssBlock, isPlainTemplateLiteral, isThemeAccessTest, applyVariant, dropAllTestInfoProps, annotateParamFromJsxProp, findJsxPropTsType, isJsxPropOptional, markBail, importMap, root, extraStyleObjects, resolvedStyleObjects } = ctx;
|
|
28731
|
+
const { j, decl, filePath, warnings, parseExpr, resolveValue, resolveCall, resolveSelector, resolveImportInScope, resolverImports, componentInfo, handlerContext, styleObj, styleFnFromProps, styleFnDecls, inlineStyleProps, isCssHelperTaggedTemplate, resolveCssHelperTemplate, resolveStaticCssBlock, isPlainTemplateLiteral, isThemeAccessTest, applyVariant, dropAllTestInfoProps, annotateParamFromJsxProp, findJsxPropTsType, isJsxPropOptional, markBail, importMap, root, extraStyleObjects, resolvedStyleObjects, allocateSourceOrder } = ctx;
|
|
27635
28732
|
const avoidNames = new Set(importMap.keys());
|
|
27636
28733
|
const cssHelperTemplateOptions = { rejectStrippedSpecificity: decl.base.kind === "component" };
|
|
27637
28734
|
/**
|
|
@@ -27730,21 +28827,28 @@ function createCssHelperConditionalHandler(ctx) {
|
|
|
27730
28827
|
}
|
|
27731
28828
|
return null;
|
|
27732
28829
|
};
|
|
27733
|
-
const replaceParamWithProps = (exprNode) => {
|
|
28830
|
+
const replaceParamWithProps = (exprNode, localParamName, localBindings) => {
|
|
27734
28831
|
const cloned = cloneAstNode(exprNode);
|
|
27735
28832
|
const replace = (node, parent) => {
|
|
27736
28833
|
if (!node || typeof node !== "object") return node;
|
|
27737
28834
|
if (Array.isArray(node)) return node.map((child) => replace(child, parent));
|
|
27738
28835
|
const n = node;
|
|
27739
|
-
if (bindings.kind === "simple" && isMemberExpression(n) && n.object?.type === "Identifier" && n.object?.name === bindings.paramName && n.property?.type === "Identifier" && (n.property?.name ?? "").startsWith("$") && n.computed === false) return j.identifier(n.property.name);
|
|
28836
|
+
if ((bindings.kind === "simple" || localParamName || localBindings?.kind === "simple") && isMemberExpression(n) && n.object?.type === "Identifier" && (bindings.kind === "simple" && n.object?.name === bindings.paramName || localParamName && n.object?.name === localParamName || localBindings?.kind === "simple" && n.object?.name === localBindings.paramName) && n.property?.type === "Identifier" && (n.property?.name ?? "").startsWith("$") && n.computed === false) return j.identifier(n.property.name);
|
|
27740
28837
|
if (n.type === "Identifier") {
|
|
27741
28838
|
const nodeName = n.name ?? "";
|
|
27742
|
-
if (bindings.kind === "simple" && nodeName === bindings.paramName) {
|
|
28839
|
+
if (bindings.kind === "simple" && nodeName === bindings.paramName || localParamName && nodeName === localParamName || localBindings?.kind === "simple" && nodeName === localBindings.paramName) {
|
|
27743
28840
|
const p = parent;
|
|
27744
28841
|
const isMemberProp = p && isMemberExpression(p) && p.property === n && p.computed === false;
|
|
27745
28842
|
const isObjectKey = p && p.type === "Property" && p.key === n && p.shorthand !== true;
|
|
27746
28843
|
if (!isMemberProp && !isObjectKey) return j.identifier("props");
|
|
27747
28844
|
}
|
|
28845
|
+
if (localBindings?.kind === "destructured" && localBindings.bindings.has(nodeName)) {
|
|
28846
|
+
const propName = localBindings.bindings.get(nodeName);
|
|
28847
|
+
const defaultValue = localBindings.defaults?.get(propName);
|
|
28848
|
+
const base = propName.startsWith("$") ? j.identifier(propName) : j.memberExpression(j.identifier("props"), j.identifier(propName));
|
|
28849
|
+
if (defaultValue) return j.logicalExpression("??", base, cloneAstNode(defaultValue));
|
|
28850
|
+
return base;
|
|
28851
|
+
}
|
|
27748
28852
|
if (bindings.kind === "destructured" && bindings.bindings.has(nodeName)) {
|
|
27749
28853
|
const propName = bindings.bindings.get(nodeName);
|
|
27750
28854
|
const defaultValue = bindings.defaults?.get(propName);
|
|
@@ -27777,6 +28881,11 @@ function createCssHelperConditionalHandler(ctx) {
|
|
|
27777
28881
|
};
|
|
27778
28882
|
return replace(cloned, void 0);
|
|
27779
28883
|
};
|
|
28884
|
+
const getFunctionParamName = (node) => {
|
|
28885
|
+
if (node.type !== "ArrowFunctionExpression" && node.type !== "FunctionExpression") return;
|
|
28886
|
+
const firstParam = node.params?.[0];
|
|
28887
|
+
return firstParam?.type === "Identifier" ? firstParam.name : void 0;
|
|
28888
|
+
};
|
|
27780
28889
|
/** Apply conditional variants, composing with an outer condition, and inject useTheme() for theme refs. */
|
|
27781
28890
|
const applyConditionalVariantsInline = (conditionalVariants, outerCondition) => {
|
|
27782
28891
|
for (const cv of conditionalVariants) {
|
|
@@ -27802,14 +28911,18 @@ function createCssHelperConditionalHandler(ctx) {
|
|
|
27802
28911
|
if (!tpl || tpl.type !== "TemplateLiteral") return null;
|
|
27803
28912
|
const { rules, slotExprById } = parseCssTemplateToRules(tpl);
|
|
27804
28913
|
const out = /* @__PURE__ */ new Map();
|
|
28914
|
+
const runtimePseudoAliases = [];
|
|
27805
28915
|
const mediaValues = /* @__PURE__ */ new Map();
|
|
27806
28916
|
const computedMediaValues = /* @__PURE__ */ new Map();
|
|
27807
|
-
let
|
|
28917
|
+
let sawInterpolatedPseudoSelector = false;
|
|
27808
28918
|
const setValueForProp = (prop, value, media, computedKey, pseudoEntries) => {
|
|
27809
28919
|
if (pseudoEntries?.length) {
|
|
27810
28920
|
if (media || computedKey) return false;
|
|
27811
|
-
|
|
27812
|
-
|
|
28921
|
+
const localDefaultExpr = out.get(prop);
|
|
28922
|
+
const defaultExpr = localDefaultExpr ?? (styleObj[prop] !== void 0 ? styleValueToExpression(j, styleObj[prop]) : j.literal(null));
|
|
28923
|
+
const wrapped = localDefaultExpr?.type === "ObjectExpression" ? appendValueWithResolvedPseudos(localDefaultExpr, value, defaultExpr, pseudoEntries) : wrapValueWithResolvedPseudos(value, defaultExpr, pseudoEntries);
|
|
28924
|
+
if (localDefaultExpr) inlineMapPseudoRootDefaults.set(wrapped, true);
|
|
28925
|
+
out.set(prop, wrapped);
|
|
27813
28926
|
return true;
|
|
27814
28927
|
}
|
|
27815
28928
|
if (computedKey) {
|
|
@@ -27827,10 +28940,14 @@ function createCssHelperConditionalHandler(ctx) {
|
|
|
27827
28940
|
};
|
|
27828
28941
|
const resolveRulePseudoEntries = (selector) => {
|
|
27829
28942
|
if (selector === "&") return [];
|
|
27830
|
-
const
|
|
27831
|
-
if (
|
|
27832
|
-
const
|
|
27833
|
-
const
|
|
28943
|
+
const staticPseudo = selector.match(/^&((?::[a-zA-Z][a-zA-Z0-9-]*(?:\([^)]*\))?)+)$/);
|
|
28944
|
+
if (staticPseudo?.[1]) return [{ pseudo: staticPseudo[1] }];
|
|
28945
|
+
const placeholderMatch = selector.match(/__SC_EXPR_(\d+)__/);
|
|
28946
|
+
const beforePlaceholder = placeholderMatch?.index === void 0 ? "" : selector.slice(0, placeholderMatch.index);
|
|
28947
|
+
const normalizedAfterPlaceholder = (placeholderMatch?.index === void 0 ? "" : selector.slice(placeholderMatch.index + placeholderMatch[0].length)).trim();
|
|
28948
|
+
const prefixPseudo = beforePlaceholder.replace(/^&/, "").replace(/:$/, "");
|
|
28949
|
+
if (!placeholderMatch?.[1] || normalizedAfterPlaceholder !== "" && normalizedAfterPlaceholder !== "&" || !(prefixPseudo === "" || /^(?::[a-zA-Z][a-zA-Z0-9-]*(?:\([^)]*\))?)+$/.test(prefixPseudo))) return null;
|
|
28950
|
+
const slotExpr = slotExprById.get(Number(placeholderMatch[1]));
|
|
27834
28951
|
if (!slotExpr || typeof slotExpr !== "object") return null;
|
|
27835
28952
|
let localName = null;
|
|
27836
28953
|
let path;
|
|
@@ -27861,8 +28978,24 @@ function createCssHelperConditionalHandler(ctx) {
|
|
|
27861
28978
|
});
|
|
27862
28979
|
if (!selectorResult) return null;
|
|
27863
28980
|
registerImports(selectorResult.imports, resolverImports);
|
|
27864
|
-
if (selectorResult.kind === "pseudoAlias")
|
|
28981
|
+
if (selectorResult.kind === "pseudoAlias") {
|
|
28982
|
+
const styleSelectorExpr = parseExpr(selectorResult.styleSelectorExpr);
|
|
28983
|
+
if (!styleSelectorExpr) return null;
|
|
28984
|
+
const pseudoKeys = selectorResult.values.map((value) => `${prefixPseudo}:${value}`);
|
|
28985
|
+
const alias = {
|
|
28986
|
+
pseudoNames: selectorResult.values,
|
|
28987
|
+
pseudoKeys,
|
|
28988
|
+
styleSelectorExpr
|
|
28989
|
+
};
|
|
28990
|
+
runtimePseudoAliases.push(alias);
|
|
28991
|
+
sawInterpolatedPseudoSelector = true;
|
|
28992
|
+
return pseudoKeys.map((pseudo) => ({
|
|
28993
|
+
pseudo,
|
|
28994
|
+
alias
|
|
28995
|
+
}));
|
|
28996
|
+
}
|
|
27865
28997
|
if (selectorResult.kind !== "pseudoExpand") return null;
|
|
28998
|
+
sawInterpolatedPseudoSelector = true;
|
|
27866
28999
|
const entries = [];
|
|
27867
29000
|
for (const expansion of selectorResult.expansions) {
|
|
27868
29001
|
let conditionExpr;
|
|
@@ -27879,8 +29012,7 @@ function createCssHelperConditionalHandler(ctx) {
|
|
|
27879
29012
|
}
|
|
27880
29013
|
return entries;
|
|
27881
29014
|
};
|
|
27882
|
-
const wrapValueWithResolvedPseudos = (
|
|
27883
|
-
const defaultExpr = styleObj[prop] !== void 0 ? styleValueToExpression(j, styleObj[prop]) : j.literal(null);
|
|
29015
|
+
const wrapValueWithResolvedPseudos = (value, defaultExpr, pseudoEntries) => {
|
|
27884
29016
|
const properties = [j.property("init", j.identifier("default"), cloneAstNode(defaultExpr))];
|
|
27885
29017
|
for (const entry of pseudoEntries) {
|
|
27886
29018
|
let entryValue = value;
|
|
@@ -27893,6 +29025,19 @@ function createCssHelperConditionalHandler(ctx) {
|
|
|
27893
29025
|
}
|
|
27894
29026
|
return j.objectExpression(properties);
|
|
27895
29027
|
};
|
|
29028
|
+
const appendValueWithResolvedPseudos = (existing, value, defaultExpr, pseudoEntries) => {
|
|
29029
|
+
const properties = existing.type === "ObjectExpression" ? [...existing.properties] : [];
|
|
29030
|
+
for (const entry of pseudoEntries) {
|
|
29031
|
+
let entryValue = value;
|
|
29032
|
+
if (entry.conditionExpr) entryValue = j.objectExpression([j.property("init", j.identifier("default"), cloneAstNode(defaultExpr)), (() => {
|
|
29033
|
+
const p = j.property("init", entry.conditionExpr, value);
|
|
29034
|
+
p.computed = true;
|
|
29035
|
+
return p;
|
|
29036
|
+
})()]);
|
|
29037
|
+
properties.push(j.property("init", j.literal(entry.pseudo), entryValue));
|
|
29038
|
+
}
|
|
29039
|
+
return j.objectExpression(properties);
|
|
29040
|
+
};
|
|
27896
29041
|
for (const rule of rules) {
|
|
27897
29042
|
const rawMedia = findSupportedAtRule(rule.atRuleStack);
|
|
27898
29043
|
if (hasUnsupportedAtRule(rule.atRuleStack)) return null;
|
|
@@ -27960,9 +29105,24 @@ function createCssHelperConditionalHandler(ctx) {
|
|
|
27960
29105
|
if (slotParts.length !== 1) return null;
|
|
27961
29106
|
const slotExpr = slotExprById.get(slotParts[0].slotId);
|
|
27962
29107
|
if (!slotExpr || typeof slotExpr !== "object") return null;
|
|
27963
|
-
|
|
29108
|
+
const slotExprNode = slotExpr;
|
|
29109
|
+
const slotValueExpr = slotExprNode.type === "ArrowFunctionExpression" || slotExprNode.type === "FunctionExpression" ? getFunctionBodyExpr(slotExprNode) : slotExprNode;
|
|
29110
|
+
if (!slotValueExpr) return null;
|
|
29111
|
+
const localBindings = slotExprNode.type === "ArrowFunctionExpression" || slotExprNode.type === "FunctionExpression" ? getArrowFnParamBindings(slotExprNode) : void 0;
|
|
29112
|
+
const rawExpr = replaceParamWithProps(slotValueExpr, getFunctionParamName(slotExprNode), localBindings ?? void 0);
|
|
29113
|
+
let resolvedExpr = rawExpr;
|
|
29114
|
+
if (rawExpr.type === "CallExpression") {
|
|
29115
|
+
const resolvedCall = tryResolveAdapterCall(rawExpr, d.property, {
|
|
29116
|
+
resolveCall,
|
|
29117
|
+
resolveImportInScope,
|
|
29118
|
+
parseExpr,
|
|
29119
|
+
resolverImports,
|
|
29120
|
+
filePath
|
|
29121
|
+
});
|
|
29122
|
+
if (resolvedCall) resolvedExpr = resolvedCall.ast;
|
|
29123
|
+
}
|
|
27964
29124
|
const memberPath = paramName && isMemberExpression(slotExpr) ? getMemberPathFromIdentifier(slotExpr, paramName) : null;
|
|
27965
|
-
if (memberPath?.[0] === "theme") {
|
|
29125
|
+
if (rawExpr.type !== "CallExpression" && memberPath?.[0] === "theme") {
|
|
27966
29126
|
const resolved = resolveValue({
|
|
27967
29127
|
kind: "theme",
|
|
27968
29128
|
path: memberPath.slice(1).join("."),
|
|
@@ -27994,15 +29154,245 @@ function createCssHelperConditionalHandler(ctx) {
|
|
|
27994
29154
|
}
|
|
27995
29155
|
out.set(prop, j.objectExpression(properties));
|
|
27996
29156
|
}
|
|
27997
|
-
if (opts?.requireResolvedPseudoSelector && !
|
|
29157
|
+
if (opts?.requireResolvedPseudoSelector && !sawInterpolatedPseudoSelector) return null;
|
|
29158
|
+
if (runtimePseudoAliases.length > 0) inlineMapPseudoAliases.set(out, runtimePseudoAliases);
|
|
27998
29159
|
return out;
|
|
27999
29160
|
};
|
|
29161
|
+
const inlineMapPseudoAliases = /* @__PURE__ */ new WeakMap();
|
|
29162
|
+
const inlineMapPseudoRootDefaults = /* @__PURE__ */ new WeakMap();
|
|
29163
|
+
const tryApplyObservedVariants = (testInfo, propName, buildStyle) => {
|
|
29164
|
+
const observedValues = resolveObservedVariantValues({
|
|
29165
|
+
usage: ctx.propUsageByComponent?.get(decl.localName),
|
|
29166
|
+
propName,
|
|
29167
|
+
isOptional: isJsxPropOptional(propName),
|
|
29168
|
+
isExported: ctx.exportedComponentNames.has(decl.localName),
|
|
29169
|
+
escapesAsValue: ctx.componentsUsedAsValue.has(decl.localName)
|
|
29170
|
+
});
|
|
29171
|
+
const testExpr = parseExpr(testInfo.when);
|
|
29172
|
+
if (!observedValues || !testExpr) return false;
|
|
29173
|
+
return emitObservedVariantBuckets({
|
|
29174
|
+
decl,
|
|
29175
|
+
propName,
|
|
29176
|
+
observedValues,
|
|
29177
|
+
applyVariant,
|
|
29178
|
+
ensurePropDrop: (prop) => ensureShouldForwardPropDrop(decl, prop),
|
|
29179
|
+
buildBucket: (propValue) => {
|
|
29180
|
+
if (evaluateObservedDynamicExpression({
|
|
29181
|
+
j,
|
|
29182
|
+
root,
|
|
29183
|
+
expression: testExpr,
|
|
29184
|
+
propName,
|
|
29185
|
+
propValue
|
|
29186
|
+
}) !== true) return { kind: "skip" };
|
|
29187
|
+
const style = buildStyle(propValue);
|
|
29188
|
+
return style === null ? { kind: "bail" } : {
|
|
29189
|
+
kind: "emit",
|
|
29190
|
+
style
|
|
29191
|
+
};
|
|
29192
|
+
}
|
|
29193
|
+
});
|
|
29194
|
+
};
|
|
29195
|
+
const tryApplyObservedDynamicPropVariants = (testInfo, dynamicProps) => {
|
|
29196
|
+
if (dynamicProps.length === 0) return false;
|
|
29197
|
+
const propNames = [...new Set(dynamicProps.map((entry) => entry.jsxProp))];
|
|
29198
|
+
if (propNames.length !== 1) return false;
|
|
29199
|
+
const propName = propNames[0];
|
|
29200
|
+
return tryApplyObservedVariants(testInfo, propName, (propValue) => {
|
|
29201
|
+
const style = {};
|
|
29202
|
+
for (const dyn of dynamicProps) {
|
|
29203
|
+
if (!dyn.callArg) return null;
|
|
29204
|
+
const cssValue = evaluateObservedDynamicExpression({
|
|
29205
|
+
j,
|
|
29206
|
+
root,
|
|
29207
|
+
expression: dyn.callArg,
|
|
29208
|
+
propName,
|
|
29209
|
+
propValue
|
|
29210
|
+
});
|
|
29211
|
+
if (typeof cssValue !== "string" && typeof cssValue !== "number") return null;
|
|
29212
|
+
style[dyn.stylexProp] = cssValue;
|
|
29213
|
+
}
|
|
29214
|
+
return style;
|
|
29215
|
+
});
|
|
29216
|
+
};
|
|
29217
|
+
const tryApplyObservedRuntimeStyleVariants = (testInfo, style, basePropNames) => {
|
|
29218
|
+
if (Object.keys(style).length === 0 || basePropNames.size !== 1) return false;
|
|
29219
|
+
const propName = [...basePropNames][0];
|
|
29220
|
+
return tryApplyObservedVariants(testInfo, propName, (propValue) => {
|
|
29221
|
+
const evaluatedStyle = {};
|
|
29222
|
+
for (const [stylexProp, value] of Object.entries(style)) {
|
|
29223
|
+
if (!value || typeof value !== "object") {
|
|
29224
|
+
evaluatedStyle[stylexProp] = value;
|
|
29225
|
+
continue;
|
|
29226
|
+
}
|
|
29227
|
+
const cssValue = evaluateObservedDynamicExpression({
|
|
29228
|
+
j,
|
|
29229
|
+
root,
|
|
29230
|
+
expression: value,
|
|
29231
|
+
propName,
|
|
29232
|
+
propValue
|
|
29233
|
+
});
|
|
29234
|
+
if (typeof cssValue !== "string" && typeof cssValue !== "number") return null;
|
|
29235
|
+
evaluatedStyle[stylexProp] = cssValue;
|
|
29236
|
+
}
|
|
29237
|
+
return evaluatedStyle;
|
|
29238
|
+
});
|
|
29239
|
+
};
|
|
29240
|
+
const tryApplyRuntimeStyleFunction = (testInfo, style, opts) => {
|
|
29241
|
+
const importedStylexIdentifiers = getImportedStylexIdentifiers(importMap, resolverImports);
|
|
29242
|
+
const basePropNames = collectRuntimeStylePropNames(style, importMap, importedStylexIdentifiers);
|
|
29243
|
+
const referencesTheme = styleReferencesRuntimeTheme(style);
|
|
29244
|
+
const dynamicProps = opts?.dynamicProps ?? [];
|
|
29245
|
+
if (basePropNames.size === 0 && dynamicProps.length === 0 && !referencesTheme) return false;
|
|
29246
|
+
if (!referencesTheme && tryApplyObservedRuntimeStyleVariants(testInfo, style, basePropNames)) return true;
|
|
29247
|
+
if (Object.keys(style).length === 0 && !referencesTheme && tryApplyObservedDynamicPropVariants(testInfo, dynamicProps)) return true;
|
|
29248
|
+
if (Object.keys(style).length === 0 && dynamicProps.length > 0 && !referencesTheme) {
|
|
29249
|
+
for (const dyn of dynamicProps) {
|
|
29250
|
+
const fnKey = styleKeyWithSuffix(decl.styleKey, dyn.stylexProp);
|
|
29251
|
+
const isGuardedBySameProp = normalizeTransientPropName(dyn.jsxProp) === normalizeTransientPropName(testInfo.propName);
|
|
29252
|
+
const conditionWhen = isGuardedBySameProp ? void 0 : testInfo.when;
|
|
29253
|
+
const condition = isGuardedBySameProp ? "truthy" : void 0;
|
|
29254
|
+
if (!styleFnDecls.has(fnKey)) {
|
|
29255
|
+
const dynParamName = cssPropertyToIdentifier(dyn.stylexProp, avoidNames);
|
|
29256
|
+
const param = j.identifier(dynParamName);
|
|
29257
|
+
annotateParamFromJsxProp(param, dyn.jsxProp);
|
|
29258
|
+
const p = makeCssProperty(j, dyn.stylexProp, dynParamName);
|
|
29259
|
+
const bodyExpr = j.objectExpression([p]);
|
|
29260
|
+
styleFnDecls.set(fnKey, j.arrowFunctionExpression([param], bodyExpr));
|
|
29261
|
+
}
|
|
29262
|
+
if (!styleFnFromProps.some((p) => p.fnKey === fnKey && p.jsxProp === dyn.jsxProp && p.condition === condition && p.conditionWhen === conditionWhen)) styleFnFromProps.push({
|
|
29263
|
+
fnKey,
|
|
29264
|
+
jsxProp: dyn.jsxProp,
|
|
29265
|
+
...condition ? { condition } : {},
|
|
29266
|
+
...conditionWhen ? { conditionWhen } : {}
|
|
29267
|
+
});
|
|
29268
|
+
ensureShouldForwardPropDrop(decl, dyn.jsxProp);
|
|
29269
|
+
}
|
|
29270
|
+
for (const propName of testInfo.allPropNames ?? [testInfo.propName]) if (propName) ensureShouldForwardPropDrop(decl, propName);
|
|
29271
|
+
decl.needsWrapperComponent = true;
|
|
29272
|
+
return true;
|
|
29273
|
+
}
|
|
29274
|
+
const runtimeStyle = { ...style };
|
|
29275
|
+
for (const dyn of dynamicProps) runtimeStyle[dyn.stylexProp] = j.memberExpression(j.identifier("props"), j.identifier(normalizeTransientPropName(dyn.jsxProp)));
|
|
29276
|
+
const propNames = collectRuntimeStylePropNames(runtimeStyle, importMap, importedStylexIdentifiers);
|
|
29277
|
+
for (const propName of testInfo.allPropNames ?? [testInfo.propName]) if (propName) propNames.add(normalizeTransientPropName(propName));
|
|
29278
|
+
const fnKey = ensureUniqueKey([
|
|
29279
|
+
styleFnDecls,
|
|
29280
|
+
extraStyleObjects,
|
|
29281
|
+
resolvedStyleObjects
|
|
29282
|
+
], styleKeyWithSuffix(decl.styleKey, normalizeTransientPropName(testInfo.propName) || "dynamic"));
|
|
29283
|
+
const params = [j.identifier("props")];
|
|
29284
|
+
if (referencesTheme) params.push(j.identifier("theme"));
|
|
29285
|
+
const callArg = j.objectExpression([...propNames].sort().map((propName) => {
|
|
29286
|
+
const id = j.identifier(propName);
|
|
29287
|
+
const prop = j.property("init", id, id);
|
|
29288
|
+
prop.shorthand = true;
|
|
29289
|
+
return prop;
|
|
29290
|
+
}));
|
|
29291
|
+
const addRuntimeStyleFn = (key, body) => {
|
|
29292
|
+
styleFnDecls.set(key, j.arrowFunctionExpression(params.map((param) => cloneAstNode(param)), body));
|
|
29293
|
+
styleFnFromProps.push({
|
|
29294
|
+
fnKey: key,
|
|
29295
|
+
jsxProp: "__props",
|
|
29296
|
+
callArg: cloneAstNode(callArg),
|
|
29297
|
+
conditionWhen: testInfo.when,
|
|
29298
|
+
...referencesTheme ? { extraCallArgs: [{
|
|
29299
|
+
jsxProp: "__helper",
|
|
29300
|
+
callArg: j.identifier("theme")
|
|
29301
|
+
}] } : {}
|
|
29302
|
+
});
|
|
29303
|
+
};
|
|
29304
|
+
const styleProperties = Object.entries(runtimeStyle).flatMap(([prop, value]) => {
|
|
29305
|
+
const { expression, customProps } = bridgeRuntimePseudoColorValues(j, fnKey, prop, toRuntimeStyleExpression(j, value, importedStylexIdentifiers));
|
|
29306
|
+
return [...customProps, j.property("init", makeCssPropKey(j, prop), expression)];
|
|
29307
|
+
});
|
|
29308
|
+
addRuntimeStyleFn(fnKey, j.objectExpression(styleProperties));
|
|
29309
|
+
for (const propName of propNames) ensureShouldForwardPropDrop(decl, propName);
|
|
29310
|
+
if (referencesTheme) {
|
|
29311
|
+
decl.needsUseThemeHook ??= [];
|
|
29312
|
+
if (!decl.needsUseThemeHook.some((entry) => entry.themeProp === "__runtime")) decl.needsUseThemeHook.push({
|
|
29313
|
+
themeProp: "__runtime",
|
|
29314
|
+
trueStyleKey: null,
|
|
29315
|
+
falseStyleKey: null
|
|
29316
|
+
});
|
|
29317
|
+
}
|
|
29318
|
+
decl.needsWrapperComponent = true;
|
|
29319
|
+
return true;
|
|
29320
|
+
};
|
|
29321
|
+
const applyStaticPseudoAliasVariants = (testInfo, style, pseudoAliases) => {
|
|
29322
|
+
let rootStyle = style;
|
|
29323
|
+
for (const pseudoAlias of pseudoAliases) {
|
|
29324
|
+
const split = splitStaticPseudoAliasStyle(j, rootStyle, pseudoAlias.pseudoNames, pseudoAlias.pseudoKeys, inlineMapPseudoRootDefaults, (propName) => !hasPriorRootStyleFnForProps(styleFnFromProps, styleFnDecls, new Set([propName])));
|
|
29325
|
+
const { pseudoAliasStyles } = split;
|
|
29326
|
+
if (!pseudoAliasStyles) return false;
|
|
29327
|
+
if (styleReferencesRuntimeTheme(Object.fromEntries(pseudoAliasStyles))) return false;
|
|
29328
|
+
const importedStylexIdentifiers = getImportedStylexIdentifiers(importMap, resolverImports);
|
|
29329
|
+
for (const pseudoStyle of pseudoAliasStyles.values()) if (collectRuntimeStylePropNames(pseudoStyle, importMap, importedStylexIdentifiers).size > 0) {
|
|
29330
|
+
warnings.push({
|
|
29331
|
+
severity: "warning",
|
|
29332
|
+
type: "Conditional `css` block: runtime pseudo-alias styles are not supported",
|
|
29333
|
+
loc: decl.loc
|
|
29334
|
+
});
|
|
29335
|
+
return false;
|
|
29336
|
+
}
|
|
29337
|
+
const styleKeys = [];
|
|
29338
|
+
const guardBase = styleKeyWithSuffix(decl.styleKey, testInfo.when);
|
|
29339
|
+
for (const pseudoName of pseudoAlias.pseudoNames) {
|
|
29340
|
+
const styleKey = ensureUniqueKey([
|
|
29341
|
+
styleFnDecls,
|
|
29342
|
+
extraStyleObjects,
|
|
29343
|
+
resolvedStyleObjects
|
|
29344
|
+
], `${guardBase}Pseudo${capitalize(kebabToCamelCase(pseudoName))}`);
|
|
29345
|
+
const pseudoStyle = pseudoAliasStyles.get(pseudoName);
|
|
29346
|
+
if (!pseudoStyle) return false;
|
|
29347
|
+
styleKeys.push(styleKey);
|
|
29348
|
+
extraStyleObjects.set(styleKey, pseudoStyle);
|
|
29349
|
+
}
|
|
29350
|
+
const aliasPropNames = collectStylePropNames(pseudoAliasStyles.values());
|
|
29351
|
+
const sourceOrder = !hasRootStyleForProps(styleObj, aliasPropNames) && !hasRootStyleForProps(split.rootStyle, aliasPropNames) && !hasPriorRootStyleFnForProps(styleFnFromProps, styleFnDecls, aliasPropNames) ? allocateSourceOrder() : void 0;
|
|
29352
|
+
decl.pseudoAliasSelectors ??= [];
|
|
29353
|
+
decl.pseudoAliasSelectors.push({
|
|
29354
|
+
styleKeys,
|
|
29355
|
+
styleSelectorExpr: cloneAstNode(pseudoAlias.styleSelectorExpr),
|
|
29356
|
+
pseudoNames: pseudoAlias.pseudoNames,
|
|
29357
|
+
guard: { when: testInfo.when },
|
|
29358
|
+
...sourceOrder !== void 0 ? { sourceOrder } : {}
|
|
29359
|
+
});
|
|
29360
|
+
rootStyle = split.rootStyle;
|
|
29361
|
+
}
|
|
29362
|
+
if (Object.keys(rootStyle).length > 0) {
|
|
29363
|
+
if (!tryApplyRuntimeStyleFunction(testInfo, rootStyle)) {
|
|
29364
|
+
const rootStyleKey = ensureUniqueKey([
|
|
29365
|
+
styleFnDecls,
|
|
29366
|
+
extraStyleObjects,
|
|
29367
|
+
resolvedStyleObjects
|
|
29368
|
+
], `${styleKeyWithSuffix(decl.styleKey, testInfo.when)}Root`);
|
|
29369
|
+
extraStyleObjects.set(rootStyleKey, rootStyle);
|
|
29370
|
+
decl.pseudoExpandSelectors ??= [];
|
|
29371
|
+
decl.pseudoExpandSelectors.push({
|
|
29372
|
+
styleKey: rootStyleKey,
|
|
29373
|
+
guard: { when: normalizeTransientWhen(testInfo.when) }
|
|
29374
|
+
});
|
|
29375
|
+
}
|
|
29376
|
+
}
|
|
29377
|
+
dropAllTestInfoProps(testInfo);
|
|
29378
|
+
decl.needsWrapperComponent = true;
|
|
29379
|
+
return true;
|
|
29380
|
+
};
|
|
28000
29381
|
const body = expr.body;
|
|
28001
29382
|
if (body?.type === "LogicalExpression" && body.operator === "&&") {
|
|
28002
29383
|
if (pseudoElement && (isCssHelperTaggedTemplate(body.right) || body.right?.type === "TemplateLiteral" || body.right?.type === "StringLiteral" || body.right?.type === "Literal" && typeof body.right.value === "string")) return bailPseudoElementConditional();
|
|
28003
29384
|
const testInfo = parseChainedTestInfo(body.left);
|
|
28004
29385
|
if (!testInfo) return false;
|
|
28005
29386
|
if (isCssHelperTaggedTemplate(body.right)) {
|
|
29387
|
+
const inlineMap = resolveCssBranchToInlineMap(body.right, { requireResolvedPseudoSelector: true });
|
|
29388
|
+
if (inlineMap) {
|
|
29389
|
+
const inlineStyle = Object.fromEntries(inlineMap);
|
|
29390
|
+
const pseudoAliases = inlineMapPseudoAliases.get(inlineMap);
|
|
29391
|
+
if (pseudoAliases) {
|
|
29392
|
+
if (!applyStaticPseudoAliasVariants(testInfo, inlineStyle, pseudoAliases)) markBail();
|
|
29393
|
+
} else if (!tryApplyRuntimeStyleFunction(testInfo, inlineStyle)) applyVariant(testInfo, inlineStyle);
|
|
29394
|
+
return true;
|
|
29395
|
+
}
|
|
28006
29396
|
const cssNode = body.right;
|
|
28007
29397
|
const resolved = resolveCssHelperTemplate(cssNode.quasi, paramName, decl.loc, cssHelperTemplateOptions);
|
|
28008
29398
|
if (!resolved) {
|
|
@@ -28010,13 +29400,18 @@ function createCssHelperConditionalHandler(ctx) {
|
|
|
28010
29400
|
return true;
|
|
28011
29401
|
}
|
|
28012
29402
|
const { style: consStyle, dynamicProps, conditionalVariants } = resolved;
|
|
29403
|
+
if (tryApplyRuntimeStyleFunction(testInfo, consStyle, { dynamicProps })) {
|
|
29404
|
+
applyConditionalVariantsInline(conditionalVariants, testInfo.when);
|
|
29405
|
+
dropAllTestInfoProps(testInfo);
|
|
29406
|
+
return true;
|
|
29407
|
+
}
|
|
28013
29408
|
if (dynamicProps.length > 0) {
|
|
28014
29409
|
const propName = testInfo.propName;
|
|
28015
|
-
const hasMismatchedProp = dynamicProps.some((p) => p.jsxProp !== propName);
|
|
28016
29410
|
const isComparison = testInfo.when.includes("===") || testInfo.when.includes("!==");
|
|
28017
|
-
if (!propName ||
|
|
29411
|
+
if (!propName || testInfo.when.startsWith("!") || isComparison) return false;
|
|
28018
29412
|
for (const dyn of dynamicProps) {
|
|
28019
29413
|
const fnKey = styleKeyWithSuffix(decl.styleKey, dyn.stylexProp);
|
|
29414
|
+
const conditionWhen = normalizeTransientPropName(dyn.jsxProp) === normalizeTransientPropName(propName) ? void 0 : testInfo.when;
|
|
28020
29415
|
if (!styleFnDecls.has(fnKey)) {
|
|
28021
29416
|
const dynParamName = cssPropertyToIdentifier(dyn.stylexProp, avoidNames);
|
|
28022
29417
|
const param = j.identifier(dynParamName);
|
|
@@ -28025,10 +29420,11 @@ function createCssHelperConditionalHandler(ctx) {
|
|
|
28025
29420
|
const bodyExpr = j.objectExpression([p]);
|
|
28026
29421
|
styleFnDecls.set(fnKey, j.arrowFunctionExpression([param], bodyExpr));
|
|
28027
29422
|
}
|
|
28028
|
-
if (!styleFnFromProps.some((p) => p.fnKey === fnKey && p.jsxProp === dyn.jsxProp && p.condition === "truthy")) styleFnFromProps.push({
|
|
29423
|
+
if (!styleFnFromProps.some((p) => p.fnKey === fnKey && p.jsxProp === dyn.jsxProp && p.condition === "truthy" && p.conditionWhen === conditionWhen)) styleFnFromProps.push({
|
|
28029
29424
|
fnKey,
|
|
28030
29425
|
jsxProp: dyn.jsxProp,
|
|
28031
|
-
condition: "truthy"
|
|
29426
|
+
condition: "truthy",
|
|
29427
|
+
...conditionWhen ? { conditionWhen } : {}
|
|
28032
29428
|
});
|
|
28033
29429
|
ensureShouldForwardPropDrop(decl, dyn.jsxProp);
|
|
28034
29430
|
}
|
|
@@ -28203,13 +29599,10 @@ function createCssHelperConditionalHandler(ctx) {
|
|
|
28203
29599
|
});
|
|
28204
29600
|
}
|
|
28205
29601
|
if (buckets.length === 0) return false;
|
|
28206
|
-
for (const { propValue, style } of buckets) {
|
|
28207
|
-
|
|
28208
|
-
|
|
28209
|
-
|
|
28210
|
-
propName: args.propName
|
|
28211
|
-
}, style);
|
|
28212
|
-
}
|
|
29602
|
+
for (const { propValue, style } of buckets) applyVariant({
|
|
29603
|
+
when: formatObservedVariantCondition(args.propName, propValue),
|
|
29604
|
+
propName: args.propName
|
|
29605
|
+
}, style);
|
|
28213
29606
|
decl.variantLookupCastProps ??= /* @__PURE__ */ new Set();
|
|
28214
29607
|
decl.variantLookupCastProps.add(args.propName);
|
|
28215
29608
|
ensureShouldForwardPropDrop(decl, args.propName);
|
|
@@ -28614,7 +30007,11 @@ function createCssHelperConditionalHandler(ctx) {
|
|
|
28614
30007
|
if (consIsCss && altIsEmpty) {
|
|
28615
30008
|
const consMap = resolveCssBranchToInlineMap(cons, { requireResolvedPseudoSelector: true });
|
|
28616
30009
|
if (consMap) {
|
|
28617
|
-
|
|
30010
|
+
const consStyle = Object.fromEntries(consMap);
|
|
30011
|
+
const pseudoAliases = inlineMapPseudoAliases.get(consMap);
|
|
30012
|
+
if (pseudoAliases) {
|
|
30013
|
+
if (!applyStaticPseudoAliasVariants(testInfo, consStyle, pseudoAliases)) markBail();
|
|
30014
|
+
} else if (!tryApplyRuntimeStyleFunction(testInfo, consStyle)) applyVariant(testInfo, consStyle);
|
|
28618
30015
|
return true;
|
|
28619
30016
|
}
|
|
28620
30017
|
const consResolved = resolveCssBranch(cons);
|
|
@@ -28622,24 +30019,44 @@ function createCssHelperConditionalHandler(ctx) {
|
|
|
28622
30019
|
markBail();
|
|
28623
30020
|
return true;
|
|
28624
30021
|
}
|
|
30022
|
+
if (tryApplyRuntimeStyleFunction(testInfo, consResolved.style, { dynamicProps: consResolved.dynamicProps })) {
|
|
30023
|
+
applyConditionalVariants(consResolved.conditionalVariants, testInfo.when);
|
|
30024
|
+
dropAllTestInfoProps(testInfo);
|
|
30025
|
+
return true;
|
|
30026
|
+
}
|
|
28625
30027
|
if (consResolved.dynamicProps.length > 0) return false;
|
|
28626
|
-
applyVariant(testInfo, consResolved.style);
|
|
30028
|
+
if (!tryApplyRuntimeStyleFunction(testInfo, consResolved.style)) applyVariant(testInfo, consResolved.style);
|
|
28627
30029
|
applyConditionalVariants(consResolved.conditionalVariants, testInfo.when);
|
|
28628
30030
|
return true;
|
|
28629
30031
|
}
|
|
28630
30032
|
if (consIsEmpty && altIsCss) {
|
|
30033
|
+
const invertedWhen = invertWhen(testInfo.when);
|
|
30034
|
+
if (!invertedWhen) return false;
|
|
30035
|
+
const invertedTestInfo = {
|
|
30036
|
+
...testInfo,
|
|
30037
|
+
when: invertedWhen
|
|
30038
|
+
};
|
|
30039
|
+
const altMap = resolveCssBranchToInlineMap(alt, { requireResolvedPseudoSelector: true });
|
|
30040
|
+
if (altMap) {
|
|
30041
|
+
const altStyle = Object.fromEntries(altMap);
|
|
30042
|
+
const pseudoAliases = inlineMapPseudoAliases.get(altMap);
|
|
30043
|
+
if (pseudoAliases) {
|
|
30044
|
+
if (!applyStaticPseudoAliasVariants(invertedTestInfo, altStyle, pseudoAliases)) markBail();
|
|
30045
|
+
} else if (!tryApplyRuntimeStyleFunction(invertedTestInfo, altStyle)) applyVariant(invertedTestInfo, altStyle);
|
|
30046
|
+
return true;
|
|
30047
|
+
}
|
|
28631
30048
|
const altResolved = resolveCssBranch(alt);
|
|
28632
30049
|
if (!altResolved) {
|
|
28633
30050
|
markBail();
|
|
28634
30051
|
return true;
|
|
28635
30052
|
}
|
|
30053
|
+
if (tryApplyRuntimeStyleFunction(invertedTestInfo, altResolved.style, { dynamicProps: altResolved.dynamicProps })) {
|
|
30054
|
+
applyConditionalVariants(altResolved.conditionalVariants, invertedWhen);
|
|
30055
|
+
dropAllTestInfoProps(testInfo);
|
|
30056
|
+
return true;
|
|
30057
|
+
}
|
|
28636
30058
|
if (altResolved.dynamicProps.length > 0) return false;
|
|
28637
|
-
|
|
28638
|
-
if (!invertedWhen) return false;
|
|
28639
|
-
applyVariant({
|
|
28640
|
-
...testInfo,
|
|
28641
|
-
when: invertedWhen
|
|
28642
|
-
}, altResolved.style);
|
|
30059
|
+
if (!tryApplyRuntimeStyleFunction(invertedTestInfo, altResolved.style)) applyVariant(invertedTestInfo, altResolved.style);
|
|
28643
30060
|
applyConditionalVariants(altResolved.conditionalVariants, invertedWhen);
|
|
28644
30061
|
return true;
|
|
28645
30062
|
}
|
|
@@ -28938,9 +30355,224 @@ function tryResolveBlockLevelThemeConditional(args) {
|
|
|
28938
30355
|
return true;
|
|
28939
30356
|
}
|
|
28940
30357
|
function styleValueToExpression(j, value) {
|
|
30358
|
+
if (value === null) return j.literal(null);
|
|
28941
30359
|
if (value !== null && typeof value === "object" && "type" in value) return cloneAstNode(value);
|
|
30360
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value)) return j.objectExpression(Object.entries(value).map(([key, nestedValue]) => j.property("init", /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? j.identifier(key) : j.literal(key), styleValueToExpression(j, nestedValue))));
|
|
28942
30361
|
return staticValueToLiteral(j, value);
|
|
28943
30362
|
}
|
|
30363
|
+
function toRuntimeStyleExpression(j, value, stylexTokenIdentifiers) {
|
|
30364
|
+
return rewritePropsThemeToThemeVar(normalizeDollarProps(j, styleValueToExpression(j, value), { skipIdentifiers: stylexTokenIdentifiers }));
|
|
30365
|
+
}
|
|
30366
|
+
function splitStaticPseudoAliasStyle(j, style, pseudoNames, pseudoKeys, rootDefaultObjects, shouldPreserveAliasDefault) {
|
|
30367
|
+
const rootStyle = {};
|
|
30368
|
+
const pseudoAliasStyles = /* @__PURE__ */ new Map();
|
|
30369
|
+
for (const pseudoName of pseudoNames) pseudoAliasStyles.set(pseudoName, {});
|
|
30370
|
+
let hasAliasStyle = false;
|
|
30371
|
+
for (const [prop, value] of Object.entries(style)) {
|
|
30372
|
+
const split = splitPseudoObjectByAliasName(j, value, pseudoNames, pseudoKeys, rootDefaultObjects, shouldPreserveAliasDefault(prop));
|
|
30373
|
+
if (!split) {
|
|
30374
|
+
rootStyle[prop] = value;
|
|
30375
|
+
continue;
|
|
30376
|
+
}
|
|
30377
|
+
hasAliasStyle = true;
|
|
30378
|
+
if (split.rootValue) rootStyle[prop] = split.rootValue;
|
|
30379
|
+
for (const [pseudoName, pseudoValue] of split.byPseudoName) {
|
|
30380
|
+
const styleForPseudo = pseudoAliasStyles.get(pseudoName);
|
|
30381
|
+
if (styleForPseudo) styleForPseudo[prop] = pseudoValue;
|
|
30382
|
+
}
|
|
30383
|
+
}
|
|
30384
|
+
return {
|
|
30385
|
+
rootStyle,
|
|
30386
|
+
pseudoAliasStyles: hasAliasStyle ? pseudoAliasStyles : null
|
|
30387
|
+
};
|
|
30388
|
+
}
|
|
30389
|
+
function splitPseudoObjectByAliasName(j, value, pseudoNames, pseudoKeys, rootDefaultObjects, preserveAliasDefault) {
|
|
30390
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
30391
|
+
const node = value;
|
|
30392
|
+
if (node.type !== "ObjectExpression") return null;
|
|
30393
|
+
const properties = node.properties;
|
|
30394
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
30395
|
+
const pseudoKeySet = new Set(pseudoKeys);
|
|
30396
|
+
const rootValue = {};
|
|
30397
|
+
let aliasDefaultValue = null;
|
|
30398
|
+
for (const property of properties ?? []) {
|
|
30399
|
+
if (!property || property.type !== "Property") continue;
|
|
30400
|
+
const keyName = getStaticObjectPropertyKeyName(property);
|
|
30401
|
+
if (keyName) {
|
|
30402
|
+
byKey.set(keyName, property.value);
|
|
30403
|
+
if (preserveAliasDefault && keyName === "default" && !rootDefaultObjects.has(node)) {
|
|
30404
|
+
const staticDefault = staticValueFromExpression(property.value);
|
|
30405
|
+
if (staticDefault !== null && staticDefault !== void 0) aliasDefaultValue = property.value;
|
|
30406
|
+
}
|
|
30407
|
+
if (!pseudoKeySet.has(keyName) && (keyName !== "default" || rootDefaultObjects.has(node))) if (keyName === "default" && property.value?.type === "ObjectExpression") copyObjectExpressionPropertiesToRootValue(rootValue, property.value);
|
|
30408
|
+
else rootValue[keyName] = staticValueFromExpression(property.value) ?? cloneAstNode(property.value);
|
|
30409
|
+
}
|
|
30410
|
+
}
|
|
30411
|
+
const byPseudoName = /* @__PURE__ */ new Map();
|
|
30412
|
+
for (let index = 0; index < pseudoNames.length; index++) {
|
|
30413
|
+
const pseudoName = pseudoNames[index];
|
|
30414
|
+
const pseudoKey = pseudoKeys[index] ?? `:${pseudoName}`;
|
|
30415
|
+
const pseudoValue = byKey.get(pseudoKey);
|
|
30416
|
+
if (!pseudoValue) return null;
|
|
30417
|
+
byPseudoName.set(pseudoName, j.objectExpression([...aliasDefaultValue ? [j.property("init", j.identifier("default"), cloneAstNode(aliasDefaultValue))] : [], j.property("init", j.literal(pseudoKey), cloneAstNode(pseudoValue))]));
|
|
30418
|
+
}
|
|
30419
|
+
return {
|
|
30420
|
+
byPseudoName,
|
|
30421
|
+
...Object.keys(rootValue).length > 0 ? { rootValue } : {}
|
|
30422
|
+
};
|
|
30423
|
+
}
|
|
30424
|
+
function bridgeRuntimePseudoColorValues(j, styleKey, stylexProp, expression) {
|
|
30425
|
+
if (!isColorLikeStylexProp(stylexProp) || expression.type !== "ObjectExpression") return {
|
|
30426
|
+
expression,
|
|
30427
|
+
customProps: []
|
|
30428
|
+
};
|
|
30429
|
+
const customProps = [];
|
|
30430
|
+
for (const property of expression.properties ?? []) {
|
|
30431
|
+
if (!property || property.type !== "Property") continue;
|
|
30432
|
+
const keyName = getStaticObjectPropertyKeyName(property);
|
|
30433
|
+
if (!keyName?.startsWith(":")) continue;
|
|
30434
|
+
const value = property.value;
|
|
30435
|
+
if (!referencesRuntimeValue(value)) continue;
|
|
30436
|
+
const variableName = buildRuntimePseudoVariableName(styleKey, stylexProp, keyName);
|
|
30437
|
+
customProps.push(j.property("init", j.literal(variableName), cloneAstNode(value)));
|
|
30438
|
+
property.value = j.literal(`var(${variableName})`);
|
|
30439
|
+
}
|
|
30440
|
+
return {
|
|
30441
|
+
expression,
|
|
30442
|
+
customProps
|
|
30443
|
+
};
|
|
30444
|
+
}
|
|
30445
|
+
function isColorLikeStylexProp(stylexProp) {
|
|
30446
|
+
return stylexProp === "color" || stylexProp === "fill" || stylexProp === "stroke" || stylexProp.endsWith("Color");
|
|
30447
|
+
}
|
|
30448
|
+
function referencesRuntimeValue(value) {
|
|
30449
|
+
return findInAst(value, (node) => {
|
|
30450
|
+
if (node.type === "Identifier" && node.name === "theme") return true;
|
|
30451
|
+
return isMemberExpression(node) && node.object?.type === "Identifier" && (node.object.name === "props" || node.object.name === "theme") && node.computed === false;
|
|
30452
|
+
});
|
|
30453
|
+
}
|
|
30454
|
+
function getStaticObjectPropertyKeyName(property) {
|
|
30455
|
+
const key = property.key;
|
|
30456
|
+
if (!key) return null;
|
|
30457
|
+
if (key.type === "Identifier") return key.name ?? null;
|
|
30458
|
+
if (key.type === "Literal" || key.type === "StringLiteral") {
|
|
30459
|
+
const value = key.value;
|
|
30460
|
+
return typeof value === "string" ? value : null;
|
|
30461
|
+
}
|
|
30462
|
+
return null;
|
|
30463
|
+
}
|
|
30464
|
+
function buildRuntimePseudoVariableName(styleKey, stylexProp, pseudo) {
|
|
30465
|
+
const pseudoSuffix = pseudo.replace(/^:+/, "").replace(/[^A-Za-z0-9]+/g, "-").replace(/^-|-$/g, "") || "state";
|
|
30466
|
+
return `--${camelToKebabCase(styleKey)}-${camelToKebabCase(stylexProp)}-${pseudoSuffix}`;
|
|
30467
|
+
}
|
|
30468
|
+
function collectRuntimeStylePropNames(style, importMap, stylexTokenIdentifiers) {
|
|
30469
|
+
const names = /* @__PURE__ */ new Set();
|
|
30470
|
+
for (const value of Object.values(style)) collectRuntimePropNames(value, names, importMap, stylexTokenIdentifiers);
|
|
30471
|
+
return names;
|
|
30472
|
+
}
|
|
30473
|
+
function collectRuntimePropNames(value, names, importMap, stylexTokenIdentifiers) {
|
|
30474
|
+
if (!value || typeof value !== "object") return;
|
|
30475
|
+
if (Array.isArray(value)) {
|
|
30476
|
+
for (const item of value) collectRuntimePropNames(item, names, importMap, stylexTokenIdentifiers);
|
|
30477
|
+
return;
|
|
30478
|
+
}
|
|
30479
|
+
const node = value;
|
|
30480
|
+
if (node.type === "Identifier") {
|
|
30481
|
+
const name = node.name;
|
|
30482
|
+
if (name?.startsWith("$") && !importMap.has(name) && !stylexTokenIdentifiers.has(name)) names.add(normalizeTransientPropName(name));
|
|
30483
|
+
return;
|
|
30484
|
+
}
|
|
30485
|
+
if (isMemberExpression(node)) {
|
|
30486
|
+
const object = node.object;
|
|
30487
|
+
const property = node.property;
|
|
30488
|
+
if (object?.type === "Identifier" && object.name === "props" && property?.type === "Identifier" && node.computed === false) {
|
|
30489
|
+
const propName = property.name;
|
|
30490
|
+
if (propName && propName !== "theme") names.add(normalizeTransientPropName(propName));
|
|
30491
|
+
if (propName === "theme") return;
|
|
30492
|
+
}
|
|
30493
|
+
collectRuntimePropNames(node.object, names, importMap, stylexTokenIdentifiers);
|
|
30494
|
+
if (node.computed) collectRuntimePropNames(node.property, names, importMap, stylexTokenIdentifiers);
|
|
30495
|
+
return;
|
|
30496
|
+
}
|
|
30497
|
+
if (node.type === "Property") {
|
|
30498
|
+
if (node.computed) collectRuntimePropNames(node.key, names, importMap, stylexTokenIdentifiers);
|
|
30499
|
+
collectRuntimePropNames(node.value, names, importMap, stylexTokenIdentifiers);
|
|
30500
|
+
return;
|
|
30501
|
+
}
|
|
30502
|
+
for (const [key, child] of Object.entries(node)) {
|
|
30503
|
+
if (key === "loc" || key === "comments" || key === "type") continue;
|
|
30504
|
+
collectRuntimePropNames(child, names, importMap, stylexTokenIdentifiers);
|
|
30505
|
+
}
|
|
30506
|
+
}
|
|
30507
|
+
function styleReferencesRuntimeTheme(style) {
|
|
30508
|
+
return Object.values(style).some((value) => findInAst(value, (node) => isMemberExpression(node) && node.object?.type === "Identifier" && node.object.name === "props" && node.property?.type === "Identifier" && node.property.name === "theme" && node.computed === false));
|
|
30509
|
+
}
|
|
30510
|
+
function normalizeTransientPropName(propName) {
|
|
30511
|
+
return propName.startsWith("$") ? propName.slice(1) : propName;
|
|
30512
|
+
}
|
|
30513
|
+
function normalizeTransientWhen(when) {
|
|
30514
|
+
return when.replace(/\$([A-Za-z_][A-Za-z0-9_]*)/g, "$1");
|
|
30515
|
+
}
|
|
30516
|
+
function collectStylePropNames(styles) {
|
|
30517
|
+
const propNames = /* @__PURE__ */ new Set();
|
|
30518
|
+
for (const style of styles) for (const propName of Object.keys(style)) propNames.add(propName);
|
|
30519
|
+
return propNames;
|
|
30520
|
+
}
|
|
30521
|
+
function hasRootStyleForProps(style, propNames) {
|
|
30522
|
+
for (const propName of propNames) if (Object.prototype.hasOwnProperty.call(style, propName) && styleValueIncludesRootDefault(style[propName])) return true;
|
|
30523
|
+
return false;
|
|
30524
|
+
}
|
|
30525
|
+
function hasPriorRootStyleFnForProps(styleFnFromProps, styleFnDecls, propNames) {
|
|
30526
|
+
for (const entry of styleFnFromProps) {
|
|
30527
|
+
const styleFn = styleFnDecls.get(entry.fnKey);
|
|
30528
|
+
if (styleFn && typeof styleFn === "object" && styleFn.type === "ArrowFunctionExpression") {
|
|
30529
|
+
const body = styleFn.body;
|
|
30530
|
+
if (objectExpressionHasRootStyleForProps(body, propNames)) return true;
|
|
30531
|
+
}
|
|
30532
|
+
}
|
|
30533
|
+
return false;
|
|
30534
|
+
}
|
|
30535
|
+
function objectExpressionHasRootStyleForProps(node, propNames) {
|
|
30536
|
+
if (!node || typeof node !== "object" || node.type !== "ObjectExpression") return false;
|
|
30537
|
+
const properties = node.properties;
|
|
30538
|
+
for (const property of properties ?? []) {
|
|
30539
|
+
if (!property || property.type !== "Property") continue;
|
|
30540
|
+
const keyName = getStaticObjectPropertyKeyName(property);
|
|
30541
|
+
if (keyName && propNames.has(keyName) && styleValueIncludesRootDefault(property.value)) return true;
|
|
30542
|
+
}
|
|
30543
|
+
return false;
|
|
30544
|
+
}
|
|
30545
|
+
function styleValueIncludesRootDefault(value) {
|
|
30546
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return true;
|
|
30547
|
+
if (value.type === "ObjectExpression") {
|
|
30548
|
+
const properties = value.properties;
|
|
30549
|
+
for (const property of properties ?? []) {
|
|
30550
|
+
if (!property || property.type !== "Property") continue;
|
|
30551
|
+
const keyName = getStaticObjectPropertyKeyName(property);
|
|
30552
|
+
if (keyName && isRootStyleValueKey(keyName)) return true;
|
|
30553
|
+
}
|
|
30554
|
+
return false;
|
|
30555
|
+
}
|
|
30556
|
+
for (const keyName of Object.keys(value)) if (isRootStyleValueKey(keyName)) return true;
|
|
30557
|
+
return false;
|
|
30558
|
+
}
|
|
30559
|
+
function isRootStyleValueKey(keyName) {
|
|
30560
|
+
return keyName === "default" || !keyName.startsWith(":") && !keyName.startsWith("@");
|
|
30561
|
+
}
|
|
30562
|
+
function copyObjectExpressionPropertiesToRootValue(rootValue, objectExpression) {
|
|
30563
|
+
const properties = objectExpression.properties;
|
|
30564
|
+
for (const property of properties ?? []) {
|
|
30565
|
+
if (!property || property.type !== "Property") continue;
|
|
30566
|
+
const keyName = getStaticObjectPropertyKeyName(property);
|
|
30567
|
+
if (!keyName) continue;
|
|
30568
|
+
rootValue[keyName] = staticValueFromExpression(property.value) ?? cloneAstNode(property.value);
|
|
30569
|
+
}
|
|
30570
|
+
}
|
|
30571
|
+
function staticValueFromExpression(node) {
|
|
30572
|
+
if (node && typeof node === "object" && node.type === "Literal" && node.value === null) return null;
|
|
30573
|
+
const value = literalToStaticValue(node);
|
|
30574
|
+
return value === null ? void 0 : value;
|
|
30575
|
+
}
|
|
28944
30576
|
/**
|
|
28945
30577
|
* If the node is a `typeof x === "type"` expression (a TypeScript type guard),
|
|
28946
30578
|
* returns the name of the narrowed identifier. Returns null otherwise.
|
|
@@ -29658,8 +31290,9 @@ function createDeclProcessingState(state, decl) {
|
|
|
29658
31290
|
const variantSourceOrder = {};
|
|
29659
31291
|
/** Monotonically increasing counter for tracking CSS source order of variants and styleFns. */
|
|
29660
31292
|
let dynamicSlotOrder = 0;
|
|
31293
|
+
const allocateSourceOrder = () => dynamicSlotOrder++;
|
|
29661
31294
|
const variantStyleKeys = new Proxy({}, { set(target, prop, value) {
|
|
29662
|
-
if (typeof prop === "string" && !(prop in target)) variantSourceOrder[prop] =
|
|
31295
|
+
if (typeof prop === "string" && !(prop in target)) variantSourceOrder[prop] = allocateSourceOrder();
|
|
29663
31296
|
target[prop] = value;
|
|
29664
31297
|
return true;
|
|
29665
31298
|
} });
|
|
@@ -29667,7 +31300,7 @@ function createDeclProcessingState(state, decl) {
|
|
|
29667
31300
|
const styleFnFromProps = new Proxy([], { get(target, prop, receiver) {
|
|
29668
31301
|
if (prop === "push") return (...entries) => {
|
|
29669
31302
|
for (const entry of entries) {
|
|
29670
|
-
if (entry.sourceOrder === void 0) entry.sourceOrder =
|
|
31303
|
+
if (entry.sourceOrder === void 0) entry.sourceOrder = allocateSourceOrder();
|
|
29671
31304
|
target.push(entry);
|
|
29672
31305
|
}
|
|
29673
31306
|
return target.length;
|
|
@@ -29715,6 +31348,23 @@ function createDeclProcessingState(state, decl) {
|
|
|
29715
31348
|
return helperVal;
|
|
29716
31349
|
};
|
|
29717
31350
|
const getComposedDefaultValue = (propName) => resolveComposedDefaultValue(cssHelperPropValues.get(propName), propName);
|
|
31351
|
+
const getWrappedComponentBaseDefaultValue = (propName) => {
|
|
31352
|
+
if (decl.base.kind !== "component" || !state.resolveBaseComponent) return;
|
|
31353
|
+
const importInfo = importMap.get(decl.base.ident);
|
|
31354
|
+
if (!importInfo) return;
|
|
31355
|
+
const staticProps = {};
|
|
31356
|
+
for (const [key, value] of Object.entries(decl.attrsInfo?.staticAttrs ?? {})) if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") staticProps[key] = value;
|
|
31357
|
+
try {
|
|
31358
|
+
return state.resolveBaseComponent({
|
|
31359
|
+
importSource: importInfo.source.value,
|
|
31360
|
+
importedName: importInfo.importedName,
|
|
31361
|
+
staticProps,
|
|
31362
|
+
filePath
|
|
31363
|
+
})?.sx?.[propName];
|
|
31364
|
+
} catch {
|
|
31365
|
+
return;
|
|
31366
|
+
}
|
|
31367
|
+
};
|
|
29718
31368
|
const { findJsxPropTsType, findJsxPropTsTypeForVariantExtraction, annotateParamFromJsxProp, isJsxPropOptional } = createTypeInferenceHelpers({
|
|
29719
31369
|
root,
|
|
29720
31370
|
j,
|
|
@@ -29868,6 +31518,7 @@ function createDeclProcessingState(state, decl) {
|
|
|
29868
31518
|
variantBuckets,
|
|
29869
31519
|
variantStyleKeys,
|
|
29870
31520
|
variantSourceOrder,
|
|
31521
|
+
allocateSourceOrder,
|
|
29871
31522
|
extraStyleObjects,
|
|
29872
31523
|
styleFnFromProps,
|
|
29873
31524
|
styleFnDecls,
|
|
@@ -29878,6 +31529,7 @@ function createDeclProcessingState(state, decl) {
|
|
|
29878
31529
|
cssHelperPropValues,
|
|
29879
31530
|
resolveComposedDefaultValue,
|
|
29880
31531
|
getComposedDefaultValue,
|
|
31532
|
+
getWrappedComponentBaseDefaultValue,
|
|
29881
31533
|
findJsxPropTsType,
|
|
29882
31534
|
findJsxPropTsTypeForVariantExtraction,
|
|
29883
31535
|
annotateParamFromJsxProp,
|
|
@@ -29915,10 +31567,13 @@ function createDeclProcessingState(state, decl) {
|
|
|
29915
31567
|
annotateParamFromJsxProp,
|
|
29916
31568
|
findJsxPropTsType,
|
|
29917
31569
|
isJsxPropOptional,
|
|
31570
|
+
allocateSourceOrder,
|
|
29918
31571
|
extraStyleObjects,
|
|
29919
31572
|
resolvedStyleObjects: state.resolvedStyleObjects,
|
|
29920
31573
|
keyframesNames: state.keyframesNames,
|
|
29921
|
-
inlineKeyframeNameMap: state.inlineKeyframeNameMap
|
|
31574
|
+
inlineKeyframeNameMap: state.inlineKeyframeNameMap,
|
|
31575
|
+
exportedComponentNames: state.exportedComponentNames,
|
|
31576
|
+
componentsUsedAsValue: state.componentsUsedAsValue
|
|
29922
31577
|
}),
|
|
29923
31578
|
getBaseStyleTarget,
|
|
29924
31579
|
notifyResolvedStylesArg
|
|
@@ -29975,7 +31630,7 @@ function finalizeDeclProcessing(ctx) {
|
|
|
29975
31630
|
const defaultValue = findLocalCustomPropertyFallbackFromRules(prop, decl);
|
|
29976
31631
|
if (!defaultValue) continue;
|
|
29977
31632
|
const localVar = state.getOrCreateLocalStylexVar(prop, defaultValue);
|
|
29978
|
-
inlineStyleProp.keyExpr =
|
|
31633
|
+
inlineStyleProp.keyExpr = stylexVarMemberExpression(state.j, localVar);
|
|
29979
31634
|
if (expr && typeof expr === "object" && isAstNode(expr)) rewriteCssVarsInAstNode(expr, localVarValues, varsToDrop);
|
|
29980
31635
|
}
|
|
29981
31636
|
for (const bucket of bucketsForVarRewrite) rewriteCssVarsInStyleObject(bucket, localVarValues, varsToDrop);
|
|
@@ -31243,8 +32898,8 @@ function resolveDirectionalConflicts(styleObj) {
|
|
|
31243
32898
|
startVal = hasStart ? computeMergedLonghand(styleObj[start], shorthandMap) : { ...shorthandMap };
|
|
31244
32899
|
endVal = hasEnd ? computeMergedLonghand(styleObj[end], shorthandMap) : { ...shorthandMap };
|
|
31245
32900
|
} else {
|
|
31246
|
-
startVal = hasStart ? styleObj[start] : shorthandVal;
|
|
31247
|
-
endVal = hasEnd ? styleObj[end] : shorthandVal;
|
|
32901
|
+
startVal = hasStart ? mergeScalarDefaultIntoLonghand(styleObj[start], shorthandVal) : shorthandVal;
|
|
32902
|
+
endVal = hasEnd ? mergeScalarDefaultIntoLonghand(styleObj[end], shorthandVal) : shorthandVal;
|
|
31248
32903
|
}
|
|
31249
32904
|
const entries = Object.entries(styleObj);
|
|
31250
32905
|
for (const key of Object.keys(styleObj)) delete styleObj[key];
|
|
@@ -31269,6 +32924,12 @@ function computeMergedLonghand(longhandVal, shorthandMap) {
|
|
|
31269
32924
|
for (const [key, val] of Object.entries(shorthandMap)) if (key !== "default") merged[key] = val;
|
|
31270
32925
|
return merged;
|
|
31271
32926
|
}
|
|
32927
|
+
function mergeScalarDefaultIntoLonghand(longhandVal, scalarDefault) {
|
|
32928
|
+
if (!isMediaOrPseudoMap(longhandVal)) return longhandVal;
|
|
32929
|
+
const merged = { ...longhandVal };
|
|
32930
|
+
if (merged.default === null || merged.default === void 0) merged.default = scalarDefault;
|
|
32931
|
+
return merged;
|
|
32932
|
+
}
|
|
31272
32933
|
/**
|
|
31273
32934
|
* Full CSS shorthand properties that StyleX will expand to longhands.
|
|
31274
32935
|
* If the value is an opaque AST node (e.g., a theme token), each longhand
|
|
@@ -31838,7 +33499,7 @@ function preScanCssHelperPlaceholders(ctx) {
|
|
|
31838
33499
|
//#endregion
|
|
31839
33500
|
//#region src/internal/lower-rules/borders.ts
|
|
31840
33501
|
function tryHandleInterpolatedBorder(ctx, args) {
|
|
31841
|
-
const { api, j, filePath, decl, extraStyleObjects, resolveValue, resolveCall, importMap, resolverImports, parseExpr, variantBuckets, variantStyleKeys, inlineStyleProps } = ctx;
|
|
33502
|
+
const { api, j, filePath, decl, extraStyleObjects, resolveValue, resolveCall, importMap, resolverImports, parseExpr, variantBuckets, variantStyleKeys, inlineStyleProps, hasStaticPropsBeforeResolvedStylesArg, notifyResolvedStylesArg } = ctx;
|
|
31842
33503
|
const { hasLocalThemeBinding } = ctx;
|
|
31843
33504
|
const { d, selector, atRuleStack, applyResolvedPropValue, bailUnsupported, bailUnsupportedWithContext } = args;
|
|
31844
33505
|
const prop = (d.property ?? "").trim();
|
|
@@ -32164,7 +33825,14 @@ function tryHandleInterpolatedBorder(ctx, args) {
|
|
|
32164
33825
|
return true;
|
|
32165
33826
|
}
|
|
32166
33827
|
decl.extraStylexPropsArgs ??= [];
|
|
32167
|
-
decl.
|
|
33828
|
+
const order = decl.mixinOrder ?? [];
|
|
33829
|
+
order.push("propsArg");
|
|
33830
|
+
decl.mixinOrder = order;
|
|
33831
|
+
decl.extraStylexPropsArgs.push({
|
|
33832
|
+
expr: resolved.exprAst,
|
|
33833
|
+
afterBase: hasStaticPropsBeforeResolvedStylesArg()
|
|
33834
|
+
});
|
|
33835
|
+
notifyResolvedStylesArg();
|
|
32168
33836
|
decl.needsWrapperComponent = true;
|
|
32169
33837
|
return true;
|
|
32170
33838
|
}
|
|
@@ -32999,7 +34667,8 @@ function emitPseudoMediaStyleFnFromProps(args) {
|
|
|
32999
34667
|
//#region src/internal/lower-rules/rule-interpolated-declaration.ts
|
|
33000
34668
|
function handleInterpolatedDeclaration(args) {
|
|
33001
34669
|
const { ctx, rule, d, media, pseudos, pseudoElement, attrTarget, resolvedSelectorMedia, applyResolvedPropValue } = args;
|
|
33002
|
-
const { state, decl, styleObj, perPropPseudo, variantBuckets, variantStyleKeys, variantSourceOrder, observedVariantFallbackFns, extraStyleObjects, styleFnFromProps, styleFnDecls, inlineStyleProps, cssHelperPropValues, tryHandleMappedFunctionColor, tryHandleLogicalOrDefault, tryHandleConditionalPropCoalesceWithTheme, tryHandleEnumIfChainValue, tryHandleThemeIndexedLookup, handlerContext, componentInfo, tryHandlePropertyTernaryTemplateLiteral, tryHandleCssHelperFunctionSwitchBlock, tryHandleCssHelperConditionalBlock, findJsxPropTsType, findJsxPropTsTypeForVariantExtraction, annotateParamFromJsxProp, isJsxPropOptional, applyVariant, notifyResolvedStylesArg } = ctx;
|
|
34670
|
+
const { state, decl, styleObj, perPropPseudo, variantBuckets, variantStyleKeys, variantSourceOrder, observedVariantFallbackFns, extraStyleObjects, styleFnFromProps, styleFnDecls, inlineStyleProps, cssHelperPropValues, tryHandleMappedFunctionColor, tryHandleLogicalOrDefault, tryHandleConditionalPropCoalesceWithTheme, tryHandleEnumIfChainValue, tryHandleThemeIndexedLookup, handlerContext, componentInfo, tryHandlePropertyTernaryTemplateLiteral, tryHandleCssHelperFunctionSwitchBlock, tryHandleCssHelperConditionalBlock, findJsxPropTsType, findJsxPropTsTypeForVariantExtraction, annotateParamFromJsxProp, isJsxPropOptional, applyVariant, getBaseStyleTarget, notifyResolvedStylesArg } = ctx;
|
|
34671
|
+
const hasStaticPropsBeforeResolvedStylesArg = () => Object.keys(styleObj).length > 0 || getBaseStyleTarget() !== styleObj;
|
|
33003
34672
|
const annotateScalarParams = (params, propNames) => {
|
|
33004
34673
|
if (!/\.(ts|tsx)$/.test(filePath)) return;
|
|
33005
34674
|
propNames.forEach((propName, paramIndex) => {
|
|
@@ -33037,9 +34706,7 @@ function handleInterpolatedDeclaration(args) {
|
|
|
33037
34706
|
}
|
|
33038
34707
|
};
|
|
33039
34708
|
const getObservedStaticVariantValues = (jsxProp) => {
|
|
33040
|
-
const
|
|
33041
|
-
if (!usage) return null;
|
|
33042
|
-
const propUsage = usage.props[jsxProp];
|
|
34709
|
+
const propUsage = state.propUsageByComponent.get(decl.localName)?.props[jsxProp];
|
|
33043
34710
|
if (!propUsage || propUsage.values.length < 2) return null;
|
|
33044
34711
|
const values = propUsage.values.filter((value) => typeof value === "string" || typeof value === "number");
|
|
33045
34712
|
if (values.length !== propUsage.values.length) return null;
|
|
@@ -33049,10 +34716,12 @@ function handleInterpolatedDeclaration(args) {
|
|
|
33049
34716
|
const tryHandleMultiSlotRuntimeValue = (resolveImportedValueExprArg) => {
|
|
33050
34717
|
if (!d.property || d.value.kind !== "interpolated") return false;
|
|
33051
34718
|
const cssProperty = d.property.trim();
|
|
33052
|
-
if (cssProperty !== "background" && cssProperty !== "background-image") return false;
|
|
33053
34719
|
if (media || attrTarget || pseudos?.length || pseudoElement || resolvedSelectorMedia) return false;
|
|
33054
34720
|
const parts = d.value.parts ?? [];
|
|
33055
34721
|
if (parts.filter((part) => part.kind === "slot").length < 2) return false;
|
|
34722
|
+
if (cssProperty !== "background" && cssProperty !== "background-image" && cssProperty !== "box-shadow" && cssProperty !== "transform") return false;
|
|
34723
|
+
const stylexDecls = cssDeclarationToStylexDeclarations(d);
|
|
34724
|
+
if (stylexDecls.length !== 1 || !stylexDecls[0]?.prop) return false;
|
|
33056
34725
|
if (cssProperty === "background" && isUnsupportedBackgroundShorthandValue(d.valueRaw ?? "")) {
|
|
33057
34726
|
state.bailUnsupported(decl, "Unsupported background shorthand: multiple components cannot be mapped to a single StyleX longhand");
|
|
33058
34727
|
return true;
|
|
@@ -33089,7 +34758,7 @@ function handleInterpolatedDeclaration(args) {
|
|
|
33089
34758
|
slotExpr = importedValueResolution.resolved;
|
|
33090
34759
|
}
|
|
33091
34760
|
if (rawExpr.type === "ArrowFunctionExpression") {
|
|
33092
|
-
for (const propName of
|
|
34761
|
+
for (const propName of collectPropsFromArrowFnDestructured(rawExpr)) if (propName !== "theme") propsUsed.add(propName);
|
|
33093
34762
|
if (hasThemeAccessInArrowFn(rawExpr)) {
|
|
33094
34763
|
needsTheme = true;
|
|
33095
34764
|
slotExpr = rewritePropsThemeToThemeVar(slotExpr);
|
|
@@ -33100,15 +34769,18 @@ function handleInterpolatedDeclaration(args) {
|
|
|
33100
34769
|
cooked: currentStaticPart
|
|
33101
34770
|
}, false));
|
|
33102
34771
|
currentStaticPart = "";
|
|
33103
|
-
|
|
34772
|
+
const importedStylexIdentifiers = getImportedStylexIdentifiers(importMap, resolverImports);
|
|
34773
|
+
const localDollarIdentifiers = rawExpr.type === "ArrowFunctionExpression" ? collectDollarParamBindingIdentifiers(rawExpr) : void 0;
|
|
34774
|
+
expressions.push(normalizeDollarProps(j, slotExpr, {
|
|
34775
|
+
skipIdentifiers: importedStylexIdentifiers,
|
|
34776
|
+
localDollarIdentifiers
|
|
34777
|
+
}));
|
|
33104
34778
|
}
|
|
33105
34779
|
quasis.push(j.templateElement({
|
|
33106
34780
|
raw: currentStaticPart,
|
|
33107
34781
|
cooked: currentStaticPart
|
|
33108
34782
|
}, true));
|
|
33109
34783
|
const valueExpr = j.templateLiteral(quasis, expressions);
|
|
33110
|
-
const stylexDecls = cssDeclarationToStylexDeclarations(d);
|
|
33111
|
-
if (stylexDecls.length === 0) return false;
|
|
33112
34784
|
const normalizedPropNames = [...propsUsed].map((propName) => propName.startsWith("$") ? propName.slice(1) : propName);
|
|
33113
34785
|
const propsCallArg = normalizedPropNames.length > 0 ? j.objectExpression(normalizedPropNames.map((propName) => {
|
|
33114
34786
|
const id = j.identifier(propName);
|
|
@@ -33169,7 +34841,7 @@ function handleInterpolatedDeclaration(args) {
|
|
|
33169
34841
|
for (const value of values) {
|
|
33170
34842
|
if (value === skipValue) continue;
|
|
33171
34843
|
applyVariant({
|
|
33172
|
-
when:
|
|
34844
|
+
when: formatObservedVariantCondition(jsxProp, value),
|
|
33173
34845
|
propName: jsxProp
|
|
33174
34846
|
}, { [stylexProp]: emitStaticObservedValue(value, stylexProp, observedValues !== null, staticParts) });
|
|
33175
34847
|
}
|
|
@@ -33202,7 +34874,7 @@ function handleInterpolatedDeclaration(args) {
|
|
|
33202
34874
|
});
|
|
33203
34875
|
}
|
|
33204
34876
|
for (const { propValue, cssValue } of transformedValues) applyVariant({
|
|
33205
|
-
when:
|
|
34877
|
+
when: formatObservedVariantCondition(jsxProp, propValue),
|
|
33206
34878
|
propName: jsxProp
|
|
33207
34879
|
}, { [stylexProp]: cssValue });
|
|
33208
34880
|
const fallbackFnKey = ensureObservedVariantFallbackFn(jsxProp, stylexProp, (param) => j.callExpression(j.identifier(valueTransform.calleeIdent), [param]));
|
|
@@ -33249,7 +34921,7 @@ function handleInterpolatedDeclaration(args) {
|
|
|
33249
34921
|
conditionWhen
|
|
33250
34922
|
});
|
|
33251
34923
|
for (const { propValue, cssValue } of transformedValues) applyVariant({
|
|
33252
|
-
when: `${conditionWhen} && ${jsxProp
|
|
34924
|
+
when: `${conditionWhen} && ${formatObservedVariantCondition(jsxProp, propValue)}`,
|
|
33253
34925
|
propName: jsxProp,
|
|
33254
34926
|
allPropNames: [conditionProp, jsxProp]
|
|
33255
34927
|
}, { [stylexProp]: cssValue });
|
|
@@ -33257,6 +34929,63 @@ function handleInterpolatedDeclaration(args) {
|
|
|
33257
34929
|
ensureObservedVariantPropDrop(jsxProp);
|
|
33258
34930
|
return true;
|
|
33259
34931
|
};
|
|
34932
|
+
const tryEmitObservedCssBlockVariantBuckets = (expr) => {
|
|
34933
|
+
if (media || pseudos?.length || attrTarget || resolvedSelectorMedia || !expr || typeof expr !== "object" || expr.type !== "ArrowFunctionExpression" && expr.type !== "FunctionExpression") return false;
|
|
34934
|
+
if (hasThemeAccessInArrowFn(expr)) return false;
|
|
34935
|
+
const fnExpr = expr;
|
|
34936
|
+
const paramName = getArrowFnSingleParamName(fnExpr);
|
|
34937
|
+
const bodyExpr = getFunctionBodyExpr(fnExpr);
|
|
34938
|
+
if (!paramName || !bodyExpr) return false;
|
|
34939
|
+
const propsUsed = [...new Set([...collectPropsFromArrowFn(fnExpr), ...collectPropsFromArrowFnDestructured(fnExpr)])];
|
|
34940
|
+
if (propsUsed.length !== 1) return false;
|
|
34941
|
+
const jsxProp = propsUsed[0];
|
|
34942
|
+
const observedValues = resolveObservedVariantValues({
|
|
34943
|
+
usage: state.propUsageByComponent.get(decl.localName),
|
|
34944
|
+
propName: jsxProp,
|
|
34945
|
+
isOptional: isJsxPropOptional(jsxProp),
|
|
34946
|
+
isExported: state.exportedComponentNames.has(decl.localName),
|
|
34947
|
+
escapesAsValue: state.componentsUsedAsValue.has(decl.localName),
|
|
34948
|
+
minValues: 2
|
|
34949
|
+
});
|
|
34950
|
+
if (!observedValues) return false;
|
|
34951
|
+
const bindings = getArrowFnParamBindings(fnExpr);
|
|
34952
|
+
const guarded = extractGuardedDynamicBranch(j, bodyExpr);
|
|
34953
|
+
const conditionWhen = guarded ? printScalarizedExpression({
|
|
34954
|
+
j,
|
|
34955
|
+
expr: guarded.test,
|
|
34956
|
+
paramName,
|
|
34957
|
+
propNames: propsUsed,
|
|
34958
|
+
...bindings ? { bindings } : {}
|
|
34959
|
+
}) : null;
|
|
34960
|
+
if (guarded && !conditionWhen) return false;
|
|
34961
|
+
return emitObservedVariantBuckets({
|
|
34962
|
+
decl,
|
|
34963
|
+
propName: jsxProp,
|
|
34964
|
+
observedValues,
|
|
34965
|
+
applyVariant,
|
|
34966
|
+
ensurePropDrop: ensureObservedVariantPropDrop,
|
|
34967
|
+
buildBucket: (propValue) => {
|
|
34968
|
+
const evaluatedValue = evaluateObservedDynamicExpression({
|
|
34969
|
+
j,
|
|
34970
|
+
root: state.root,
|
|
34971
|
+
expression: bodyExpr,
|
|
34972
|
+
propName: jsxProp,
|
|
34973
|
+
propValue,
|
|
34974
|
+
paramName
|
|
34975
|
+
});
|
|
34976
|
+
if (typeof evaluatedValue !== "string") return { kind: "bail" };
|
|
34977
|
+
const cssText = evaluatedValue.trim();
|
|
34978
|
+
if (!cssText) return { kind: "skip" };
|
|
34979
|
+
const parsedStyle = parseCssDeclarationBlock(cssText);
|
|
34980
|
+
if (!parsedStyle || Object.keys(parsedStyle).length === 0) return { kind: "bail" };
|
|
34981
|
+
return {
|
|
34982
|
+
kind: "emit",
|
|
34983
|
+
style: parsedStyle,
|
|
34984
|
+
...conditionWhen ? { whenPrefix: conditionWhen } : {}
|
|
34985
|
+
};
|
|
34986
|
+
}
|
|
34987
|
+
});
|
|
34988
|
+
};
|
|
33260
34989
|
const observedExpressionFallbackFnKey = (jsxProp, conditionWhen) => {
|
|
33261
34990
|
const normalizedJsxProp = jsxProp.startsWith("$") ? jsxProp.slice(1) : jsxProp;
|
|
33262
34991
|
const baseFnKey = styleKeyWithSuffix(decl.styleKey, normalizedJsxProp);
|
|
@@ -33405,7 +35134,9 @@ function handleInterpolatedDeclaration(args) {
|
|
|
33405
35134
|
parseExpr,
|
|
33406
35135
|
variantBuckets,
|
|
33407
35136
|
variantStyleKeys,
|
|
33408
|
-
inlineStyleProps
|
|
35137
|
+
inlineStyleProps,
|
|
35138
|
+
hasStaticPropsBeforeResolvedStylesArg,
|
|
35139
|
+
notifyResolvedStylesArg
|
|
33409
35140
|
}, {
|
|
33410
35141
|
d,
|
|
33411
35142
|
selector: rule.selector,
|
|
@@ -33431,7 +35162,11 @@ function handleInterpolatedDeclaration(args) {
|
|
|
33431
35162
|
const resolved = (expr?.type === "ArrowFunctionExpression" || expr?.type === "FunctionExpression" ? resolveThemeValueFromFn(expr) : resolveThemeValue(expr)) ?? null;
|
|
33432
35163
|
if (!resolved) return false;
|
|
33433
35164
|
const { prefix, suffix } = extractStaticPartsForDecl(d);
|
|
33434
|
-
const finalValue = buildTemplateWithStaticParts(j, resolved, prefix, suffix
|
|
35165
|
+
const finalValue = buildTemplateWithStaticParts(j, resolved, prefix, suffix, {
|
|
35166
|
+
rawCss: decl.rawCss,
|
|
35167
|
+
property: (d.property ?? "").trim(),
|
|
35168
|
+
stylisValueRaw: d.valueRaw ?? ""
|
|
35169
|
+
});
|
|
33435
35170
|
if (pseudoElement) {
|
|
33436
35171
|
for (const out of cssDeclarationToStylexDeclarations(d)) applyResolvedPropValue(out.prop, finalValue, null);
|
|
33437
35172
|
return true;
|
|
@@ -33783,6 +35518,7 @@ function handleInterpolatedDeclaration(args) {
|
|
|
33783
35518
|
const slot = d.value.parts.find((p) => p.kind === "slot");
|
|
33784
35519
|
if (slot) {
|
|
33785
35520
|
const expr = decl.templateExpressions[slot.slotId];
|
|
35521
|
+
if (tryEmitObservedCssBlockVariantBuckets(expr)) continue;
|
|
33786
35522
|
if (expr?.type === "Identifier" && cssHelperNames.has(expr.name)) {
|
|
33787
35523
|
const helperDecl = declByLocalName.get(expr.name);
|
|
33788
35524
|
if (helperDecl) {
|
|
@@ -34557,6 +36293,7 @@ function handleInterpolatedDeclaration(args) {
|
|
|
34557
36293
|
const fnKey = styleKeyWithSuffix(decl.styleKey, out.prop);
|
|
34558
36294
|
let helperCallArgs = [];
|
|
34559
36295
|
let scalarPropNames = null;
|
|
36296
|
+
let guardedConditionWhenForScalar = null;
|
|
34560
36297
|
if (!styleFnDecls.has(fnKey)) {
|
|
34561
36298
|
const helperResolution = resolveHelperCallsInDynamicValue({
|
|
34562
36299
|
j,
|
|
@@ -34596,6 +36333,15 @@ function handleInterpolatedDeclaration(args) {
|
|
|
34596
36333
|
if (!scalarProps && needsOriginalParam) styleFnParamNames.unshift(paramName);
|
|
34597
36334
|
const { prefix, suffix } = extractStaticPartsForDecl(d);
|
|
34598
36335
|
const valueExpr = (d.property === "transition" ? buildFullInterpolatedDeclarationValueExpr(j, decl, d) : null) ?? (prefix || suffix ? buildTemplateWithStaticParts(j, scalarProps?.valueExpr ?? valueExprRaw, prefix, suffix) : scalarProps?.valueExpr ?? valueExprRaw);
|
|
36336
|
+
const guardedDynamic = extractGuardedDynamicBranch(j, bodyExpr);
|
|
36337
|
+
const guardedConditionWhen = guardedDynamic && scalarProps?.paramNames.length === 1 ? printScalarizedExpression({
|
|
36338
|
+
j,
|
|
36339
|
+
expr: guardedDynamic.test,
|
|
36340
|
+
paramName,
|
|
36341
|
+
propNames: scalarProps.paramNames,
|
|
36342
|
+
bindings: bindings ?? void 0
|
|
36343
|
+
}) : null;
|
|
36344
|
+
guardedConditionWhenForScalar = guardedConditionWhen && isHelperCallGuard(guardedConditionWhen) ? guardedConditionWhen : null;
|
|
34599
36345
|
const params = styleFnParamNames.map((name) => j.identifier(name));
|
|
34600
36346
|
if (/\.(ts|tsx)$/.test(filePath)) {
|
|
34601
36347
|
const isNamedTypeRef = decl.propsType?.type === "TSTypeReference";
|
|
@@ -34633,7 +36379,8 @@ function handleInterpolatedDeclaration(args) {
|
|
|
34633
36379
|
const scalarEntry = scalarPropNames ? scalarStyleFnEntryFromProps({
|
|
34634
36380
|
j,
|
|
34635
36381
|
fnKey,
|
|
34636
|
-
propNames: scalarPropNames
|
|
36382
|
+
propNames: scalarPropNames,
|
|
36383
|
+
...guardedConditionWhenForScalar ? { conditionWhen: guardedConditionWhenForScalar } : {}
|
|
34637
36384
|
}) : null;
|
|
34638
36385
|
styleFnFromProps.push(scalarEntry ?? {
|
|
34639
36386
|
fnKey,
|
|
@@ -35072,13 +36819,13 @@ function tryHandleLocalCustomPropertyDefinition(args) {
|
|
|
35072
36819
|
if (!customValue) return false;
|
|
35073
36820
|
const defaultValue = findLocalCustomPropertyFallback(customValue.cssName, decl);
|
|
35074
36821
|
if (!defaultValue) return false;
|
|
35075
|
-
const
|
|
36822
|
+
const localVar = getOrCreateLocalStylexVar(customValue.cssName, defaultValue);
|
|
35076
36823
|
const propName = conditionProp.startsWith("$") ? conditionProp.slice(1) : conditionProp;
|
|
35077
36824
|
const valueExpr = buildTemplateWithStaticParts(j, j.identifier(propName), customValue.prefix, customValue.suffix);
|
|
35078
36825
|
inlineStyleProps.push({
|
|
35079
36826
|
prop: customValue.cssName,
|
|
35080
36827
|
expr: j.conditionalExpression(j.identifier(propName), valueExpr, j.identifier("undefined")),
|
|
35081
|
-
keyExpr:
|
|
36828
|
+
keyExpr: stylexVarMemberExpression(j, localVar)
|
|
35082
36829
|
});
|
|
35083
36830
|
if (conditionProp.startsWith("$")) ensureShouldForwardPropDrop(decl, conditionProp);
|
|
35084
36831
|
decl.needsWrapperComponent = true;
|
|
@@ -35617,6 +37364,38 @@ function scalarStyleFnEntryFromProps(args) {
|
|
|
35617
37364
|
})) } : {}
|
|
35618
37365
|
};
|
|
35619
37366
|
}
|
|
37367
|
+
function extractGuardedDynamicBranch(j, expr) {
|
|
37368
|
+
if (!expr || typeof expr !== "object" || expr.type !== "ConditionalExpression") return null;
|
|
37369
|
+
const conditional = expr;
|
|
37370
|
+
if (!conditional.test || !conditional.consequent || !conditional.alternate) return null;
|
|
37371
|
+
const consequentEmpty = isEmptyRuntimeStyleBranch(conditional.consequent);
|
|
37372
|
+
if (consequentEmpty === isEmptyRuntimeStyleBranch(conditional.alternate)) return null;
|
|
37373
|
+
return {
|
|
37374
|
+
test: consequentEmpty ? j.unaryExpression("!", conditional.test, true) : conditional.test,
|
|
37375
|
+
value: consequentEmpty ? conditional.alternate : conditional.consequent
|
|
37376
|
+
};
|
|
37377
|
+
}
|
|
37378
|
+
function isEmptyRuntimeStyleBranch(expr) {
|
|
37379
|
+
const value = literalToStaticValue(expr);
|
|
37380
|
+
return value === "" || value === null || value === false || value === void 0;
|
|
37381
|
+
}
|
|
37382
|
+
function isHelperCallGuard(conditionWhen) {
|
|
37383
|
+
return conditionWhen.includes("(");
|
|
37384
|
+
}
|
|
37385
|
+
function printScalarizedExpression(args) {
|
|
37386
|
+
const expr = scalarizePropsObjectDynamicValue({
|
|
37387
|
+
j: args.j,
|
|
37388
|
+
valueExpr: args.expr,
|
|
37389
|
+
paramName: args.paramName,
|
|
37390
|
+
propNames: args.propNames,
|
|
37391
|
+
...args.bindings ? { bindings: args.bindings } : {}
|
|
37392
|
+
})?.valueExpr ?? args.expr;
|
|
37393
|
+
try {
|
|
37394
|
+
return args.j(expr).toSource();
|
|
37395
|
+
} catch {
|
|
37396
|
+
return null;
|
|
37397
|
+
}
|
|
37398
|
+
}
|
|
35620
37399
|
function uniqueScalarPropNames(propNames) {
|
|
35621
37400
|
const seen = /* @__PURE__ */ new Set();
|
|
35622
37401
|
const result = [];
|
|
@@ -36858,6 +38637,7 @@ function resolveInterpolatedPropertyName(property, ctx) {
|
|
|
36858
38637
|
function processDeclRules(ctx) {
|
|
36859
38638
|
const { state, decl, styleObj, perPropPseudo, perPropMedia, nestedSelectors, variantBuckets, styleFnDecls, attrBuckets, localVarValues, cssHelperPropValues, getComposedDefaultValue } = ctx;
|
|
36860
38639
|
const { j, root, warnings, resolverImports, resolveSelector, parseExpr, cssHelperNames, declByLocalName, relationOverridePseudoBuckets, relationOverrides, ancestorSelectorParents, resolveThemeValue, resolveThemeValueFromFn, resolveImportInScope } = state;
|
|
38640
|
+
const getConditionDefaultValue = (propName) => cssHelperPropValues.has(propName) ? getComposedDefaultValue(propName) : ctx.getWrappedComponentBaseDefaultValue(propName) ?? null;
|
|
36861
38641
|
/**
|
|
36862
38642
|
* Attempts to resolve an element selector (e.g., `& svg`, `& > button`) to a
|
|
36863
38643
|
* styled component override. Returns "break" to bail, "continue" to skip to next
|
|
@@ -37468,12 +39248,12 @@ function processDeclRules(ctx) {
|
|
|
37468
39248
|
const current = target[prop];
|
|
37469
39249
|
if (current && typeof current === "object" && !Array.isArray(current) && !isAstNode(current)) {
|
|
37470
39250
|
const map = current;
|
|
37471
|
-
if (!("default" in map)) map.default =
|
|
39251
|
+
if (!("default" in map)) map.default = getConditionDefaultValue(prop);
|
|
37472
39252
|
map[conditionKey] = conditionValue;
|
|
37473
39253
|
return;
|
|
37474
39254
|
}
|
|
37475
39255
|
target[prop] = {
|
|
37476
|
-
default: current ??
|
|
39256
|
+
default: current ?? getConditionDefaultValue(prop),
|
|
37477
39257
|
[conditionKey]: conditionValue
|
|
37478
39258
|
};
|
|
37479
39259
|
};
|
|
@@ -37538,12 +39318,10 @@ function processDeclRules(ctx) {
|
|
|
37538
39318
|
noteSourceCssProperty(existing);
|
|
37539
39319
|
if (!("default" in existing)) {
|
|
37540
39320
|
const existingVal = styleObj[prop];
|
|
37541
|
-
|
|
37542
|
-
else if (cssHelperPropValues.has(prop)) existing.default = getComposedDefaultValue(prop);
|
|
37543
|
-
else existing.default = null;
|
|
39321
|
+
existing.default = existingVal !== void 0 ? existingVal : getConditionDefaultValue(prop);
|
|
37544
39322
|
}
|
|
37545
39323
|
const current = existing[media];
|
|
37546
|
-
const mediaMap = current && typeof current === "object" && !Array.isArray(current) && !isAstNode(current) ? current : { default: current ??
|
|
39324
|
+
const mediaMap = current && typeof current === "object" && !Array.isArray(current) && !isAstNode(current) ? current : { default: current ?? getConditionDefaultValue(prop) };
|
|
37547
39325
|
for (const ps of pseudos) mediaMap[ps] = value;
|
|
37548
39326
|
existing[media] = mediaMap;
|
|
37549
39327
|
} else {
|
|
@@ -37552,16 +39330,14 @@ function processDeclRules(ctx) {
|
|
|
37552
39330
|
noteSourceCssProperty(existing);
|
|
37553
39331
|
if (!("default" in existing)) {
|
|
37554
39332
|
const existingVal = styleObj[prop];
|
|
37555
|
-
|
|
37556
|
-
else if (cssHelperPropValues.has(prop)) existing.default = getComposedDefaultValue(prop);
|
|
37557
|
-
else existing.default = null;
|
|
39333
|
+
existing.default = existingVal !== void 0 ? existingVal : getConditionDefaultValue(prop);
|
|
37558
39334
|
}
|
|
37559
39335
|
for (const ps of pseudos) {
|
|
37560
39336
|
const current = existing[ps];
|
|
37561
39337
|
if (!current || typeof current !== "object") {
|
|
37562
|
-
const fallbackDefault =
|
|
39338
|
+
const fallbackDefault = getConditionDefaultValue(prop);
|
|
37563
39339
|
existing[ps] = { default: current !== void 0 ? current : fallbackDefault };
|
|
37564
|
-
} else if (!("default" in current)) current.default =
|
|
39340
|
+
} else if (!("default" in current)) current.default = getConditionDefaultValue(prop);
|
|
37565
39341
|
existing[ps][media] = value;
|
|
37566
39342
|
}
|
|
37567
39343
|
}
|
|
@@ -37609,7 +39385,7 @@ function processDeclRules(ctx) {
|
|
|
37609
39385
|
noteSourceCssProperty(peTarget);
|
|
37610
39386
|
const current = peTarget[prop];
|
|
37611
39387
|
if (!current || typeof current !== "object" || isAstNode(current)) peTarget[prop] = {
|
|
37612
|
-
default: current ??
|
|
39388
|
+
default: current ?? getConditionDefaultValue(prop),
|
|
37613
39389
|
[media]: value
|
|
37614
39390
|
};
|
|
37615
39391
|
else {
|
|
@@ -37638,9 +39414,7 @@ function processDeclRules(ctx) {
|
|
|
37638
39414
|
noteSourceCssProperty(existing);
|
|
37639
39415
|
if (!("default" in existing)) {
|
|
37640
39416
|
const existingVal = styleObj[prop];
|
|
37641
|
-
|
|
37642
|
-
else if (cssHelperPropValues.has(prop)) existing.default = getComposedDefaultValue(prop);
|
|
37643
|
-
else existing.default = null;
|
|
39417
|
+
existing.default = existingVal !== void 0 ? existingVal : getConditionDefaultValue(prop);
|
|
37644
39418
|
}
|
|
37645
39419
|
const currentMediaValue = existing[media];
|
|
37646
39420
|
if (currentMediaValue && typeof currentMediaValue === "object" && !Array.isArray(currentMediaValue) && !isAstNode(currentMediaValue)) currentMediaValue.default = value;
|
|
@@ -37662,7 +39436,7 @@ function processDeclRules(ctx) {
|
|
|
37662
39436
|
const existingVal = peTarget[prop];
|
|
37663
39437
|
if (typeof existingVal === "object" && existingVal !== null && "default" in existingVal) for (const ps of pseudos) existingVal[ps] = value;
|
|
37664
39438
|
else {
|
|
37665
|
-
const pseudoMap = { default: existingVal ??
|
|
39439
|
+
const pseudoMap = { default: existingVal ?? getConditionDefaultValue(prop) };
|
|
37666
39440
|
for (const ps of pseudos) pseudoMap[ps] = value;
|
|
37667
39441
|
peTarget[prop] = pseudoMap;
|
|
37668
39442
|
}
|
|
@@ -37674,9 +39448,7 @@ function processDeclRules(ctx) {
|
|
|
37674
39448
|
noteSourceCssProperty(existing);
|
|
37675
39449
|
if (!("default" in existing)) {
|
|
37676
39450
|
const existingVal = styleObj[prop];
|
|
37677
|
-
|
|
37678
|
-
else if (cssHelperPropValues.has(prop)) existing.default = getComposedDefaultValue(prop);
|
|
37679
|
-
else existing.default = null;
|
|
39451
|
+
existing.default = existingVal !== void 0 ? existingVal : getConditionDefaultValue(prop);
|
|
37680
39452
|
}
|
|
37681
39453
|
for (const ps of pseudos) existing[ps] = value;
|
|
37682
39454
|
return;
|
|
@@ -37827,7 +39599,14 @@ function writeResolvedDeclaration(d, bucket, j, decl, resolveThemeValue, resolve
|
|
|
37827
39599
|
if (!resolveResult || resolveResult === "bail") return "unresolved";
|
|
37828
39600
|
for (const out of cssDeclarationToStylexDeclarations(d)) {
|
|
37829
39601
|
if (out.value.kind === "static") bucket[out.prop] = cssValueToJs(out.value, d.important, out.prop);
|
|
37830
|
-
else
|
|
39602
|
+
else {
|
|
39603
|
+
const built = buildInterpolatedValue(j, { value: out.value }, resolveResult);
|
|
39604
|
+
bucket[out.prop] = maybeApplyAuthoredMultilineToExpression(j, built, {
|
|
39605
|
+
rawCss: decl.rawCss,
|
|
39606
|
+
property: (d.property ?? "").trim(),
|
|
39607
|
+
stylisValueRaw: d.valueRaw ?? ""
|
|
39608
|
+
});
|
|
39609
|
+
}
|
|
37831
39610
|
writtenProps.add(out.prop);
|
|
37832
39611
|
}
|
|
37833
39612
|
return "written";
|
|
@@ -38726,6 +40505,8 @@ function createLowerRulesState(ctx) {
|
|
|
38726
40505
|
const stringMappingFns = ctx.stringMappingFns ?? /* @__PURE__ */ new Map();
|
|
38727
40506
|
const resolvedStyleObjects = /* @__PURE__ */ new Map();
|
|
38728
40507
|
const declByLocalName = new Map(styledDecls.map((d) => [d.localName, d]));
|
|
40508
|
+
const exportedComponentNames = new Set(collectExportedComponents(root, j, declByLocalName).keys());
|
|
40509
|
+
const componentsUsedAsValue = componentsReferencedAsValue(root, j, new Set(declByLocalName.keys()), ctx.styledDefaultImport);
|
|
38729
40510
|
const relationOverrides = [];
|
|
38730
40511
|
const ancestorSelectorParents = /* @__PURE__ */ new Set();
|
|
38731
40512
|
const siblingMarkerParents = /* @__PURE__ */ new Set();
|
|
@@ -38754,7 +40535,8 @@ function createLowerRulesState(ctx) {
|
|
|
38754
40535
|
trackMixinPropertyValues(cssHelperValuesByKey.get(helperDecl.styleKey), cssHelperPropValues);
|
|
38755
40536
|
if (helperDecl.inlineStyleProps?.length) for (const p of helperDecl.inlineStyleProps) inlineStyleProps.push({
|
|
38756
40537
|
prop: p.prop,
|
|
38757
|
-
expr: cloneAstNode(p.expr)
|
|
40538
|
+
expr: cloneAstNode(p.expr),
|
|
40539
|
+
...p.keyExpr ? { keyExpr: cloneAstNode(p.keyExpr) } : {}
|
|
38758
40540
|
});
|
|
38759
40541
|
if (helperDecl.extraStyleKeys?.length) for (const key of helperDecl.extraStyleKeys) {
|
|
38760
40542
|
addStyleKeyMixin(decl, key, { afterBase: helperDecl.extraStyleKeysAfterBase?.includes(key) ?? false });
|
|
@@ -38854,6 +40636,7 @@ function createLowerRulesState(ctx) {
|
|
|
38854
40636
|
resolveCall,
|
|
38855
40637
|
resolveCallOptional,
|
|
38856
40638
|
resolveThemeCall,
|
|
40639
|
+
resolveBaseComponent: ctx.resolveBaseComponent,
|
|
38857
40640
|
resolveSelector,
|
|
38858
40641
|
localStylexVars,
|
|
38859
40642
|
getOrCreateLocalStylexVar,
|
|
@@ -38865,6 +40648,8 @@ function createLowerRulesState(ctx) {
|
|
|
38865
40648
|
stringMappingFns,
|
|
38866
40649
|
resolvedStyleObjects,
|
|
38867
40650
|
declByLocalName,
|
|
40651
|
+
exportedComponentNames,
|
|
40652
|
+
componentsUsedAsValue,
|
|
38868
40653
|
relationOverrides,
|
|
38869
40654
|
ancestorSelectorParents,
|
|
38870
40655
|
siblingMarkerParents,
|
|
@@ -40703,19 +42488,13 @@ function wrappedComponentAcceptsSxProp(ctx, componentLocalName, visiting = /* @_
|
|
|
40703
42488
|
visiting.delete(componentLocalName);
|
|
40704
42489
|
return true;
|
|
40705
42490
|
}
|
|
40706
|
-
const
|
|
40707
|
-
if (
|
|
40708
|
-
|
|
40709
|
-
|
|
40710
|
-
importSource: importInfo.source.value,
|
|
40711
|
-
importedName: importInfo.importedName,
|
|
40712
|
-
filePath: ctx.file.path
|
|
40713
|
-
});
|
|
40714
|
-
if (adapterResult !== void 0) {
|
|
40715
|
-
visiting.delete(componentLocalName);
|
|
40716
|
-
return adapterResult.acceptsSx === true;
|
|
40717
|
-
}
|
|
42491
|
+
const componentInterface = wrappedComponentInterfaceFor(ctx, componentLocalName);
|
|
42492
|
+
if (componentInterface !== void 0) {
|
|
42493
|
+
visiting.delete(componentLocalName);
|
|
42494
|
+
return componentInterface.acceptsSx === true && componentInterface.sxTarget !== "inner";
|
|
40718
42495
|
}
|
|
42496
|
+
const [rootLocalName] = componentLocalName.split(".");
|
|
42497
|
+
const importInfo = rootLocalName ? ctx.importMap?.get(rootLocalName) : void 0;
|
|
40719
42498
|
const typedComponent = (() => {
|
|
40720
42499
|
if (importInfo?.source.kind === "absolutePath") {
|
|
40721
42500
|
const names = importInfo.importedName === "default" ? [componentLocalName, importInfo.importedName] : [importInfo.importedName];
|
|
@@ -40724,7 +42503,7 @@ function wrappedComponentAcceptsSxProp(ctx, componentLocalName, visiting = /* @_
|
|
|
40724
42503
|
return findTypeScriptComponentMetadata(ctx.options.crossFileInfo?.typeScriptMetadata, ctx.file.path, [componentLocalName]);
|
|
40725
42504
|
})();
|
|
40726
42505
|
if (typedComponent) {
|
|
40727
|
-
if (typedComponent.supportsSxProp) {
|
|
42506
|
+
if (typedComponent.supportsSxProp && typedComponent.sxTarget !== "inner") {
|
|
40728
42507
|
visiting.delete(componentLocalName);
|
|
40729
42508
|
return true;
|
|
40730
42509
|
}
|
|
@@ -40733,7 +42512,7 @@ function wrappedComponentAcceptsSxProp(ctx, componentLocalName, visiting = /* @_
|
|
|
40733
42512
|
return false;
|
|
40734
42513
|
}
|
|
40735
42514
|
}
|
|
40736
|
-
const accepts = importInfo?.source.kind === "absolutePath" && transformedComponentAcceptsSx({
|
|
42515
|
+
const accepts = rootLocalName === componentLocalName && importInfo?.source.kind === "absolutePath" && transformedComponentAcceptsSx({
|
|
40737
42516
|
absolutePath: importInfo.source.value,
|
|
40738
42517
|
componentNames: importInfo.importedName === "default" ? [componentLocalName, importInfo.importedName] : [importInfo.importedName],
|
|
40739
42518
|
sourceOverrides: ctx.options.transformedFileSources
|
|
@@ -40911,6 +42690,7 @@ function rewriteJsxStep(ctx) {
|
|
|
40911
42690
|
const afterBaseKeys = new Set(decl.extraStyleKeysAfterBase ?? []);
|
|
40912
42691
|
const extraMixinArgs = [];
|
|
40913
42692
|
const extraAfterBaseArgs = [];
|
|
42693
|
+
const extraAfterVariantArgs = [];
|
|
40914
42694
|
if (mixinOrder && mixinOrder.length > 0) {
|
|
40915
42695
|
let styleKeyIdx = 0;
|
|
40916
42696
|
let propsArgIdx = 0;
|
|
@@ -40925,16 +42705,31 @@ function rewriteJsxStep(ctx) {
|
|
|
40925
42705
|
} else if (entry === "propsArg" && propsArgIdx < extraStylexPropsArgs.length) {
|
|
40926
42706
|
const arg = extraStylexPropsArgs[propsArgIdx];
|
|
40927
42707
|
propsArgIdx++;
|
|
40928
|
-
if (arg) if (arg.
|
|
42708
|
+
if (arg) if (arg.afterVariants) extraAfterVariantArgs.push(arg.expr);
|
|
42709
|
+
else if (arg.afterBase) extraAfterBaseArgs.push(arg.expr);
|
|
40929
42710
|
else extraMixinArgs.push(arg.expr);
|
|
40930
42711
|
}
|
|
42712
|
+
for (; styleKeyIdx < extraStyleKeys.length; styleKeyIdx++) {
|
|
42713
|
+
const key = extraStyleKeys[styleKeyIdx];
|
|
42714
|
+
if (key) {
|
|
42715
|
+
const expr = j.memberExpression(j.identifier(ctx.stylesIdentifier ?? "styles"), j.identifier(key));
|
|
42716
|
+
if (afterBaseKeys.has(key)) extraAfterBaseArgs.push(expr);
|
|
42717
|
+
else extraMixinArgs.push(expr);
|
|
42718
|
+
}
|
|
42719
|
+
}
|
|
42720
|
+
for (; propsArgIdx < extraStylexPropsArgs.length; propsArgIdx++) {
|
|
42721
|
+
const arg = extraStylexPropsArgs[propsArgIdx];
|
|
42722
|
+
if (arg) if (arg.afterVariants) extraAfterVariantArgs.push(arg.expr);
|
|
42723
|
+
else extraAfterBaseArgs.push(arg.expr);
|
|
42724
|
+
}
|
|
40931
42725
|
} else {
|
|
40932
|
-
for (const arg of extraStylexPropsArgs) extraMixinArgs.push(arg.expr);
|
|
40933
42726
|
for (const key of extraStyleKeys) {
|
|
40934
42727
|
const expr = j.memberExpression(j.identifier(ctx.stylesIdentifier ?? "styles"), j.identifier(key));
|
|
40935
42728
|
if (afterBaseKeys.has(key)) extraAfterBaseArgs.push(expr);
|
|
40936
42729
|
else extraMixinArgs.push(expr);
|
|
40937
42730
|
}
|
|
42731
|
+
for (const arg of extraStylexPropsArgs) if (arg.afterVariants) extraAfterVariantArgs.push(arg.expr);
|
|
42732
|
+
else extraAfterBaseArgs.push(arg.expr);
|
|
40938
42733
|
}
|
|
40939
42734
|
const baseStyleKey = matchedCombinedStyleKey ?? decl.styleKey;
|
|
40940
42735
|
const mergeArgs = matchedCombinedStyleKey ? void 0 : opening.__promotedMergeArgs;
|
|
@@ -41051,6 +42846,7 @@ function rewriteJsxStep(ctx) {
|
|
|
41051
42846
|
};
|
|
41052
42847
|
for (const attr of leading) processAttr(attr, keptLeadingAfterVariants);
|
|
41053
42848
|
for (const attr of rest) processAttr(attr, keptRestAfterVariants);
|
|
42849
|
+
styleArgs.push(...extraAfterVariantArgs);
|
|
41054
42850
|
if (adjacentSiblingStyleKey && hasPreviousStaticSiblingWithName(p, decl.localName)) styleArgs.push(j.memberExpression(j.identifier(ctx.stylesIdentifier ?? "styles"), j.identifier(adjacentSiblingStyleKey)));
|
|
41055
42851
|
let finalInsertIndex = keptRestAfterVariants.length;
|
|
41056
42852
|
for (let i = keptRestAfterVariants.length - 1; i >= 0; i--) {
|