styled-components-to-stylex-codemod 0.0.59 → 0.0.60
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/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as ImportSource, i as AdapterInput, o as MarkerFileContext, s as defineAdapter, t as CollectedWarning } from "./logger-
|
|
1
|
+
import { a as ImportSource, i as AdapterInput, o as MarkerFileContext, s as defineAdapter, t as CollectedWarning } from "./logger-Byc7DAuP.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/run.d.ts
|
|
4
4
|
interface RunTransformOptions {
|
|
@@ -959,7 +959,7 @@ declare function defineAdapter<T extends AdapterInput>(adapter: T): T;
|
|
|
959
959
|
//#endregion
|
|
960
960
|
//#region src/internal/logger.d.ts
|
|
961
961
|
type Severity = "info" | "warning" | "error";
|
|
962
|
-
type WarningType = "`css` helper function switch must return css templates in all branches" | "`css` helper usage as a function call (css(...)) is not supported" | "`css` helper used outside of a styled component template cannot be statically transformed" | "Adapter helper call in border interpolation did not resolve to a single CSS value" | "Adapter resolveCall returned an unparseable styles expression" | "Adapter resolveCall returned an unparseable value expression" | "Adapter resolveCall returned StyleX styles for helper call where a CSS value was expected" | "Adapter resolved an imported helper call as StyleX styles without replacing the RuleSet helper" | "Adapter resolveCall returned undefined for helper call" | "Adapter resolveBaseComponent threw an error" | "Adapter resolved className-only helper cannot be applied under nested selectors/at-rules" | "Adapter resolved StyleX styles cannot be applied under nested selectors/at-rules" | "Adapter resolved StyleX styles inside pseudo selector but did not provide cssText for property expansion — add cssText to resolveCall result to enable pseudo-wrapping" | "Adapter resolved imported StyleX value under nested selectors/at-rules but did not provide cssText for property expansion — add cssText to resolveValue result to enable pseudo-wrapping" | 'Adapter resolveCall cssText could not be parsed as CSS declarations — expected semicolon-separated property: value pairs (e.g. "white-space: nowrap; overflow: hidden;")' | 'Adapter resolveValue cssText could not be parsed as CSS declarations — expected semicolon-separated property: value pairs (e.g. "white-space: nowrap; overflow: hidden;")' | "Adapter resolveValue returned an unparseable value expression" | "Adapter resolveValue returned undefined for imported value" | "Imported constant cannot be referenced inside stylex.create() — move it into a `.stylex` defineConsts/defineVars group (or map it via adapter.resolveValue)" | "Arrow function: body is not a recognized pattern (expected ternary, logical, call, or member expression)" | "Arrow function: conditional branches could not be resolved to static or theme values" | "Arrow function: helper call body is not supported" | "Arrow function: indexed theme lookup pattern not matched" | "Arrow function: logical expression pattern not supported" | "Arrow function: prop access cannot be converted to style function for this CSS property" | "Arrow function: theme access path could not be resolved" | "Component selectors like `${OtherComponent}:hover &` are not directly representable in StyleX. Manual refactor is required" | "Conditional `css` block: !important is not supported in StyleX" | "Conditional `css` block: unsupported or mixed @-rules require manual handling" | "CSS block contains unsupported at-rule (only @media, @container, and @supports are supported; mixed nested at-rules require manual handling)" | "Conditional `css` block: dynamic interpolation could not be resolved to a single component prop" | "Conditional `css` block: failed to parse expression" | "Conditional `css` block: missing CSS property name" | "Conditional `css` block: missing interpolation expression" | "Conditional `css` block: mixed static/dynamic values with non-theme expressions cannot be safely transformed" | "Conditional `css` block: multiple interpolation slots in a single property value" | "Conditional `css` block: finite ternary before a later overlapping declaration requires manual source-order handling" | "Conditional `css` block: runtime pseudo-alias styles are not supported" | "Conditional `css` block: ternary branch value could not be resolved (imported values require adapter support)" | "Conditional `css` block: ternary expressions inside pseudo selectors are not supported" | "Conditional `css` block: media query interpolation must be a simple imported reference (expressions like `value + 1` are not supported)" | "Conditional `css` block: unsupported selector" | "Directional border helper styles are not supported" | "Multi-slot border interpolation could not be resolved" | "Resolved border helper value could not be expanded to longhand properties" | "Resolved conditional border variant could not be expanded to longhand properties" | "createGlobalStyle is not supported in StyleX. Global styles should be handled separately (e.g., in a CSS file or using CSS reset libraries)" | "Failed to parse theme expressions" | "Heterogeneous background values (mix of gradients and colors) not currently supported" | "Higher-order styled factory wrappers (e.g. hoc(styled)) are not supported" | "Imported CSS helper mixins: cannot determine inherited properties for correct pseudo selector handling" | "Local helper function returns CSS that cannot be decomposed into individual properties" | "Local helper function computes CSS values that cannot be statically traced to the component prop" | "Unsupported background shorthand: multiple components cannot be mapped to a single StyleX longhand" | "Styled-components specificity hacks like `&&` / `&&&` are not representable in StyleX" | "Theme-dependent block-level conditional could not be fully resolved (branches may contain dynamic interpolations)" | "Theme-dependant call expression could not be resolved (e.g. theme helper calls like theme.highlight() are not supported)" | "Theme value with fallback (props.theme.X ?? / || default) cannot be resolved statically — use adapter.resolveValue to map theme paths to StyleX tokens" | "Theme-dependent nested prop access requires a project-specific theme source (e.g. useTheme())" | "Theme-dependent template literals require a project-specific theme source (e.g. useTheme())" | "Theme prop overrides on styled components are not supported" | "Universal selectors (`*`) are currently unsupported" | "Unsupported call expression (expected imported helper(...) or imported helper(...)(...))" | "Unsupported conditional test in shouldForwardProp" | "Unsupported .attrs() callback pattern" | "Unsupported .attrs() object value" | "Unsupported .attrs() object/array value on a styled component sharing a multi-declarator statement" | "Unsupported .attrs() object/array value on a styled component whose name is shadowed in another scope" | "Unsupported shouldForwardProp pattern (only !prop.startsWith(), ![].includes(prop), and prop !== are supported)" | "Unsupported interpolation: arrow function" | "Unsupported interpolation: call expression" | "Unsupported interpolation: identifier" | "css helper with prop-based interpolation cannot be reused as a mixin" | "Unsupported interpolation: member expression" | "Unsupported interpolation: multiple dynamic slots in one declaration" | "Unsupported interpolation: property" | "Unsupported interpolation: unknown" | `Unsupported CSS property "${string}" cannot be emitted in StyleX` | "Dynamic logical scroll shorthand cannot be expanded — bind a specific longhand (e.g. scroll-padding-inline-start) instead" | "Imported runtime condition root collides with a component prop of the same name" | "Mixed logical and physical scroll properties cannot be normalized without a known writing-mode" | "Unsupported nested conditional interpolation" | "Unsupported prop-based inline style expression cannot be safely inlined" | "Unsupported prop-based inline style props.theme access is not supported" | "Unsupported selector interpolation: imported value in selector position" | "Unsupported: media query interpolation must be a simple imported reference (expressions like `value + 1` are not supported)" | "Unsupported selector: class selector" | "Unsupported selector: comma-separated selectors must all be simple pseudos or pseudo-elements" | "Unsupported selector: descendant pseudo selector (space before pseudo)" | "Unsupported selector: adjacent sibling combinator" | "Unsupported selector: descendant/child/sibling selector" | "Unsupported selector: conditional css block inside pseudo-element selector" | "Unsupported selector: interpolated pseudo selector" | "Unsupported selector: pseudo-class on pseudo-element selector" | "Unsupported selector: unsupported pseudo-element" | "Unsupported selector: sibling combinator" | "Unsupported selector: unresolved interpolation in sibling selector" | "Unsupported selector: ambiguous element selector" | "Unsupported selector: attribute selector on unsupported element" | "Unsupported selector: element selector on exported component" | "Unsupported selector: element selector with combined ancestor and child pseudos" | "Unsupported selector: element selector with dynamic children" | "Unsupported selector: element selector with plain intrinsic children" | "Unsupported selector: element selector pseudo collision" | "Unsupported selector: cross-file component selector target has no JSX usage in this file" | "Unsupported selector: unresolved interpolation in cross-file component selector" | "Unsupported selector: unresolved interpolation in descendant component selector" | "Unsupported selector: unresolved interpolation in attribute selector" | "Unsupported selector: unresolved interpolation in element selector" | "Unsupported selector: unresolved interpolation in reverse component selector" | "Unsupported selector: unresolved interpolation in cross-component sibling selector" | "Unsupported selector: grouped reverse selector references different components" | "Unsupported selector: computed media query inside ancestor attribute selector" | "Unsupported selector: computed media query inside cross-component sibling selector" | "Unsupported selector: computed media query inside sibling selector" | "Unsupported selector: computed media query inside :has() component selector" | "Unsupported: a property combines a computed at-rule key (from resolveSelector) with a static at-rule key on the same property — StyleX emits computed keys last, so the original cascade order between the at-rules cannot be preserved" | "Unsupported selector: cross-file :has() component selector not yet supported" | "Unsupported selector: unresolved interpolation in :has() component selector" | "Unsupported selector: unknown component selector" | "Unsupported selector: component selector with child pseudo" | "Unsupported selector: component selector target has no patchable JSX usage under selector parent" | "Unsupported selector: compound pseudo selector" | "Unsupported css`` mixin: after-base mixin style is not a plain object" | "Unsupported css`` mixin: nested contextual conditions in after-base mixin" | "Unsupported css`` mixin: cannot infer base default for after-base contextual override (base value is non-literal)" | "css`` helper function interpolation references closure variable that cannot be hoisted" | "Using styled-components components as mixins is not supported; use css`` mixins or strings instead" | "Partial migration left styled-components declarations unconverted" | "styled(ImportedComponent) wraps a component whose file uses styled-components — convert the base component's file first to avoid CSS cascade conflicts" | "Partial transform would have a StyleX leaf wrap a styled-components base — the extending component was transformed but its base was not, so the leaf's StyleX overrides cannot reliably beat the base's styled-components styles" | "Partial transform would leave a StyleX child reveal targeting a styled-components ancestor — the component-selector ancestor was not converted, so it cannot render the marker the child's stylex.when.ancestor() reveal needs; the child is preserved as styled-components to keep the reveal working" | "Conditional StyleX default would override an unproven earlier style for the same property" | "Flat StyleX value would erase earlier conditional property states" | "Forwarded sx conditional default would override an unproven wrapped component base style" | "Wrapped component does not accept className or sx for generated StyleX styles" | "Wrapped component sx prop targets an inner element for a root style property" | "Wrapped component sx prop rejects logical CSS properties that cannot be preserved losslessly" | "Wrapped component sx prop does not accept generated StyleX property" | "Transient $-prefixed props renamed on exported component — update consumer call sites to use the new prop names" | "Shorthand property has an opaque value that StyleX will expand to longhands — use `directional` in resolveValue to return separate longhand tokens" | "animation shorthand contains a var() with no classifiable fallback — its longhand position cannot be determined statically; bind the variable to a specific longhand (e.g. animation-duration: var(--x)) instead";
|
|
962
|
+
type WarningType = "`css` helper function switch must return css templates in all branches" | "`css` helper usage as a function call (css(...)) is not supported" | "`css` helper used outside of a styled component template cannot be statically transformed" | "Adapter helper call in border interpolation did not resolve to a single CSS value" | "Adapter resolveCall returned an unparseable styles expression" | "Adapter resolveCall returned an unparseable value expression" | "Adapter resolveCall returned StyleX styles for helper call where a CSS value was expected" | "Adapter resolved an imported helper call as StyleX styles without replacing the RuleSet helper" | "Adapter resolveCall returned undefined for helper call" | "Adapter resolveBaseComponent threw an error" | "Adapter resolved className-only helper cannot be applied under nested selectors/at-rules" | "Adapter resolved StyleX styles cannot be applied under nested selectors/at-rules" | "Adapter resolved StyleX styles inside pseudo selector but did not provide cssText for property expansion — add cssText to resolveCall result to enable pseudo-wrapping" | "Adapter resolved imported StyleX value under nested selectors/at-rules but did not provide cssText for property expansion — add cssText to resolveValue result to enable pseudo-wrapping" | 'Adapter resolveCall cssText could not be parsed as CSS declarations — expected semicolon-separated property: value pairs (e.g. "white-space: nowrap; overflow: hidden;")' | 'Adapter resolveValue cssText could not be parsed as CSS declarations — expected semicolon-separated property: value pairs (e.g. "white-space: nowrap; overflow: hidden;")' | "Adapter resolveValue returned an unparseable value expression" | "Adapter resolveValue returned undefined for imported value" | "Imported constant cannot be referenced inside stylex.create() — move it into a `.stylex` defineConsts/defineVars group (or map it via adapter.resolveValue)" | "Arrow function: body is not a recognized pattern (expected ternary, logical, call, or member expression)" | "Arrow function: conditional branches could not be resolved to static or theme values" | "Arrow function: helper call body is not supported" | "Arrow function: indexed theme lookup pattern not matched" | "Arrow function: logical expression pattern not supported" | "Arrow function: prop access cannot be converted to style function for this CSS property" | "Arrow function: theme access path could not be resolved" | "Component selectors like `${OtherComponent}:hover &` are not directly representable in StyleX. Manual refactor is required" | "Conditional `css` block: !important is not supported in StyleX" | "Conditional `css` block: unsupported or mixed @-rules require manual handling" | "CSS block contains unsupported at-rule (only @media, @container, and @supports are supported; mixed nested at-rules require manual handling)" | "Conditional `css` block: dynamic interpolation could not be resolved to a single component prop" | "Conditional `css` block: failed to parse expression" | "Conditional `css` block: missing CSS property name" | "Conditional `css` block: missing interpolation expression" | "Conditional `css` block: mixed static/dynamic values with non-theme expressions cannot be safely transformed" | "Conditional `css` block: multiple interpolation slots in a single property value" | "Conditional `css` block: finite ternary before a later overlapping declaration requires manual source-order handling" | "Conditional `css` block: runtime pseudo-alias styles are not supported" | "Conditional `css` block: ternary branch value could not be resolved (imported values require adapter support)" | "Conditional `css` block: ternary expressions inside pseudo selectors are not supported" | "Conditional `css` block: media query interpolation must be a simple imported reference (expressions like `value + 1` are not supported)" | "Conditional `css` block: unsupported selector" | "Directional border helper styles are not supported" | "Multi-slot border interpolation could not be resolved" | "Resolved border helper value could not be expanded to longhand properties" | "Resolved conditional border variant could not be expanded to longhand properties" | "createGlobalStyle is not supported in StyleX. Global styles should be handled separately (e.g., in a CSS file or using CSS reset libraries)" | "Failed to parse theme expressions" | "Heterogeneous background values (mix of gradients and colors) not currently supported" | "Higher-order styled factory wrappers (e.g. hoc(styled)) are not supported" | "Imported CSS helper mixins: cannot determine inherited properties for correct pseudo selector handling" | "Local helper function returns CSS that cannot be decomposed into individual properties" | "Local helper function computes CSS values that cannot be statically traced to the component prop" | "Unsupported background shorthand: multiple components cannot be mapped to a single StyleX longhand" | "Styled-components specificity hacks like `&&` / `&&&` are not representable in StyleX" | "Theme-dependent block-level conditional could not be fully resolved (branches may contain dynamic interpolations)" | "Theme-dependant call expression could not be resolved (e.g. theme helper calls like theme.highlight() are not supported)" | "Theme value with fallback (props.theme.X ?? / || default) cannot be resolved statically — use adapter.resolveValue to map theme paths to StyleX tokens" | "Theme-dependent nested prop access requires a project-specific theme source (e.g. useTheme())" | "Theme-dependent template literals require a project-specific theme source (e.g. useTheme())" | "Theme prop overrides on styled components are not supported" | "Universal selectors (`*`) are currently unsupported" | "Unsupported call expression (expected imported helper(...) or imported helper(...)(...))" | "Unsupported conditional test in shouldForwardProp" | "Unsupported .attrs() callback pattern" | "Unsupported .attrs() object value" | "Unsupported .attrs() object/array value on a styled component sharing a multi-declarator statement" | "Unsupported .attrs() object/array value on a styled component whose name is shadowed in another scope" | "Unsupported shouldForwardProp pattern (only !prop.startsWith(), ![].includes(prop), and prop !== are supported)" | "Unsupported interpolation: arrow function" | "Unsupported interpolation: call expression" | "Unsupported interpolation: identifier" | "css helper with prop-based interpolation cannot be reused as a mixin" | "Unsupported interpolation: member expression" | "Unsupported interpolation: multiple dynamic slots in one declaration" | "Unsupported interpolation: property" | "Unsupported interpolation: unknown" | `Unsupported CSS property "${string}" cannot be emitted in StyleX` | "Dynamic logical scroll shorthand cannot be expanded — bind a specific longhand (e.g. scroll-padding-inline-start) instead" | "Prop-dependent dynamic style function cannot also carry a computed media-query override for the same property — split into static conditional styles or bind the media value separately" | "Imported runtime condition root collides with a component prop of the same name" | "Mixed logical and physical scroll properties cannot be normalized without a known writing-mode" | "Unsupported nested conditional interpolation" | "Unsupported prop-based inline style expression cannot be safely inlined" | "Unsupported prop-based inline style props.theme access is not supported" | "Unsupported selector interpolation: imported value in selector position" | "Unsupported: media query interpolation must be a simple imported reference (expressions like `value + 1` are not supported)" | "Unsupported selector: class selector" | "Unsupported selector: comma-separated selectors must all be simple pseudos or pseudo-elements" | "Unsupported selector: descendant pseudo selector (space before pseudo)" | "Unsupported selector: adjacent sibling combinator" | "Unsupported selector: descendant/child/sibling selector" | "Unsupported selector: conditional css block inside pseudo-element selector" | "Unsupported selector: interpolated pseudo selector" | "Unsupported selector: pseudo-class on pseudo-element selector" | "Unsupported selector: unsupported pseudo-element" | "Unsupported selector: sibling combinator" | "Unsupported selector: unresolved interpolation in sibling selector" | "Unsupported selector: ambiguous element selector" | "Unsupported selector: attribute selector on unsupported element" | "Unsupported selector: element selector on exported component" | "Unsupported selector: element selector with combined ancestor and child pseudos" | "Unsupported selector: element selector with dynamic children" | "Unsupported selector: element selector with plain intrinsic children" | "Unsupported selector: element selector pseudo collision" | "Unsupported selector: cross-file component selector target has no JSX usage in this file" | "Unsupported selector: unresolved interpolation in cross-file component selector" | "Unsupported selector: unresolved interpolation in descendant component selector" | "Unsupported selector: unresolved interpolation in attribute selector" | "Unsupported selector: unresolved interpolation in element selector" | "Unsupported selector: unresolved interpolation in reverse component selector" | "Unsupported selector: unresolved interpolation in cross-component sibling selector" | "Unsupported selector: grouped reverse selector references different components" | "Unsupported selector: computed media query inside ancestor attribute selector" | "Unsupported selector: computed media query inside cross-component sibling selector" | "Unsupported selector: computed media query inside sibling selector" | "Unsupported selector: computed media query inside :has() component selector" | "Unsupported: a property combines a computed at-rule key (from resolveSelector) with a static at-rule key on the same property — StyleX emits computed keys last, so the original cascade order between the at-rules cannot be preserved" | "Unsupported selector: cross-file :has() component selector not yet supported" | "Unsupported selector: unresolved interpolation in :has() component selector" | "Unsupported selector: unknown component selector" | "Unsupported selector: component selector with child pseudo" | "Unsupported selector: component selector target has no patchable JSX usage under selector parent" | "Unsupported selector: compound pseudo selector" | "Unsupported css`` mixin: after-base mixin style is not a plain object" | "Unsupported css`` mixin: nested contextual conditions in after-base mixin" | "Unsupported css`` mixin: cannot infer base default for after-base contextual override (base value is non-literal)" | "css`` helper function interpolation references closure variable that cannot be hoisted" | "Using styled-components components as mixins is not supported; use css`` mixins or strings instead" | "Partial migration left styled-components declarations unconverted" | "styled(ImportedComponent) wraps a component whose file uses styled-components — convert the base component's file first to avoid CSS cascade conflicts" | "Partial transform would have a StyleX leaf wrap a styled-components base — the extending component was transformed but its base was not, so the leaf's StyleX overrides cannot reliably beat the base's styled-components styles" | "Partial transform would leave a StyleX child reveal targeting a styled-components ancestor — the component-selector ancestor was not converted, so it cannot render the marker the child's stylex.when.ancestor() reveal needs; the child is preserved as styled-components to keep the reveal working" | "Conditional StyleX default would override an unproven earlier style for the same property" | "Flat StyleX value would erase earlier conditional property states" | "Forwarded sx conditional default would override an unproven wrapped component base style" | "Wrapped component does not accept className or sx for generated StyleX styles" | "Wrapped component sx prop targets an inner element for a root style property" | "Wrapped component sx prop rejects logical CSS properties that cannot be preserved losslessly" | "Wrapped component sx prop does not accept generated StyleX property" | "Transient $-prefixed props renamed on exported component — update consumer call sites to use the new prop names" | "Shorthand property has an opaque value that StyleX will expand to longhands — use `directional` in resolveValue to return separate longhand tokens" | "animation shorthand contains a var() with no classifiable fallback — its longhand position cannot be determined statically; bind the variable to a specific longhand (e.g. animation-duration: var(--x)) instead";
|
|
963
963
|
interface WarningLog {
|
|
964
964
|
severity: Severity;
|
|
965
965
|
type: WarningType;
|
package/dist/transform.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as WarningLog, r as Adapter } from "./logger-
|
|
1
|
+
import { n as WarningLog, r as Adapter } from "./logger-Byc7DAuP.mjs";
|
|
2
2
|
import { API, FileInfo, Options } from "jscodeshift";
|
|
3
3
|
//#region src/internal/prepass/typescript-analysis.d.ts
|
|
4
4
|
interface TypeScriptPrepassMetadata {
|
package/dist/transform.mjs
CHANGED
|
@@ -2940,6 +2940,49 @@ function isSlotBindingOrJsxTagReference(idNode, parent) {
|
|
|
2940
2940
|
}
|
|
2941
2941
|
}
|
|
2942
2942
|
//#endregion
|
|
2943
|
+
//#region src/internal/utilities/import-source.ts
|
|
2944
|
+
/**
|
|
2945
|
+
* Helpers for converting an `ImportSource` into the textual specifier used in
|
|
2946
|
+
* an emitted `import` declaration, and into a writable absolute file path.
|
|
2947
|
+
*/
|
|
2948
|
+
/**
|
|
2949
|
+
* Convert an `ImportSource` to a module specifier string for use in import declarations.
|
|
2950
|
+
* - `kind: "specifier"` → returned as-is.
|
|
2951
|
+
* - `kind: "absolutePath"` → returned as a relative path from `filePath`'s directory,
|
|
2952
|
+
* prefixed with `./` when needed.
|
|
2953
|
+
*
|
|
2954
|
+
* Pass `stripTsExtension: true` to drop a trailing `.ts`/`.tsx` from the relative
|
|
2955
|
+
* specifier (e.g. when emitting an import to a sidecar `.stylex.ts` file).
|
|
2956
|
+
*/
|
|
2957
|
+
function importSourceToModuleSpecifier(source, filePath, options = {}) {
|
|
2958
|
+
if (source.kind === "specifier") return source.value;
|
|
2959
|
+
let rel = relative(dirname(filePath), source.value).split(sep).join("/");
|
|
2960
|
+
if (options.stripTsExtension) rel = rel.replace(/\.tsx?$/, "");
|
|
2961
|
+
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
2962
|
+
return rel;
|
|
2963
|
+
}
|
|
2964
|
+
/**
|
|
2965
|
+
* Resolve an `ImportSource` to an absolute file path for writing the sidecar file.
|
|
2966
|
+
* - `kind: "absolutePath"` → returned as-is.
|
|
2967
|
+
* - `kind: "specifier"` → resolved relative to `filePath`'s directory; appends `.ts`
|
|
2968
|
+
* when the result has no `.{j,t}sx?` extension.
|
|
2969
|
+
*/
|
|
2970
|
+
function importSourceToAbsolutePath(source, filePath) {
|
|
2971
|
+
if (source.kind === "absolutePath") return source.value;
|
|
2972
|
+
let resolved = join(dirname(filePath), source.value);
|
|
2973
|
+
if (!/\.[jt]sx?$/.test(resolved)) resolved += ".ts";
|
|
2974
|
+
return resolved;
|
|
2975
|
+
}
|
|
2976
|
+
/**
|
|
2977
|
+
* Throws if `source` is structurally invalid for use as a module reference,
|
|
2978
|
+
* with a `label` prefixed for caller context. Used by the merger import step
|
|
2979
|
+
* which validates user-provided adapter configuration at use-time.
|
|
2980
|
+
*/
|
|
2981
|
+
function assertValidImportSource(source, label) {
|
|
2982
|
+
if (typeof source.value !== "string" || source.value.trim() === "") throw new Error(`Invalid ${label}: expected non-empty string, got ${JSON.stringify(source.value)}`);
|
|
2983
|
+
if (source.kind === "absolutePath" && !isAbsolute(source.value)) throw new Error(`Invalid ${label}: expected absolute path, got ${JSON.stringify(source.value)}`);
|
|
2984
|
+
}
|
|
2985
|
+
//#endregion
|
|
2943
2986
|
//#region src/internal/utilities/component-value-references.ts
|
|
2944
2987
|
/**
|
|
2945
2988
|
* True when this Identifier path is a non-JSX value reference to a styled component (not its
|
|
@@ -9902,17 +9945,24 @@ function analyzeBeforeEmitStep(ctx) {
|
|
|
9902
9945
|
if (j(p).closest(j.TaggedTemplateExpression).filter((tp) => ctx.isStyledTag(tp.node.tag)).size() > 0) return false;
|
|
9903
9946
|
return true;
|
|
9904
9947
|
}).size() > 0;
|
|
9905
|
-
const
|
|
9948
|
+
const existingImportBindings = /* @__PURE__ */ new Map();
|
|
9906
9949
|
root.find(j.ImportDeclaration).forEach((p) => {
|
|
9907
9950
|
const specs = p.node.specifiers ?? [];
|
|
9951
|
+
const sourceValue = typeof p.node.source?.value === "string" ? p.node.source.value : null;
|
|
9908
9952
|
for (const s of specs) {
|
|
9909
9953
|
if (s?.importKind === "type") continue;
|
|
9910
9954
|
const local = s?.local?.type === "Identifier" ? s.local.name : s?.type === "ImportDefaultSpecifier" && s.local?.type === "Identifier" ? s.local.name : s?.type === "ImportNamespaceSpecifier" && s.local?.type === "Identifier" ? s.local.name : null;
|
|
9911
|
-
if (local && isUsedOutsideStyledTemplates(local))
|
|
9955
|
+
if (local && isUsedOutsideStyledTemplates(local)) {
|
|
9956
|
+
const imported = s?.type === "ImportDefaultSpecifier" ? "default" : s?.type === "ImportNamespaceSpecifier" ? "*" : s?.imported?.name ?? s?.imported?.value ?? null;
|
|
9957
|
+
existingImportBindings.set(local, sourceValue !== null && typeof imported === "string" ? {
|
|
9958
|
+
imported,
|
|
9959
|
+
source: sourceValue
|
|
9960
|
+
} : null);
|
|
9961
|
+
}
|
|
9912
9962
|
}
|
|
9913
9963
|
});
|
|
9914
9964
|
const resolverImportAliases = /* @__PURE__ */ new Map();
|
|
9915
|
-
const usedLocals = new Set(
|
|
9965
|
+
const usedLocals = new Set(existingImportBindings.keys());
|
|
9916
9966
|
const makeUniqueLocal = (base) => {
|
|
9917
9967
|
let candidate = base;
|
|
9918
9968
|
let i = 1;
|
|
@@ -9926,7 +9976,10 @@ function analyzeBeforeEmitStep(ctx) {
|
|
|
9926
9976
|
for (const imp of ctx.resolverImports.values()) for (const n of imp.names ?? []) {
|
|
9927
9977
|
const desired = n.local ?? n.imported;
|
|
9928
9978
|
if (!desired) continue;
|
|
9929
|
-
if (
|
|
9979
|
+
if (existingImportBindings.has(desired)) {
|
|
9980
|
+
const existingBinding = existingImportBindings.get(desired);
|
|
9981
|
+
const resolverModuleSpecifier = importSourceToModuleSpecifier(imp.from, file.path, { stripTsExtension: true });
|
|
9982
|
+
if (existingBinding && existingBinding.imported === n.imported && existingBinding.source === resolverModuleSpecifier) continue;
|
|
9930
9983
|
const alias = makeUniqueLocal(`${desired}Vars`);
|
|
9931
9984
|
resolverImportAliases.set(desired, alias);
|
|
9932
9985
|
n.local = alias;
|
|
@@ -13277,20 +13330,44 @@ function findStylexCreateBlockEnd(code, blockStart) {
|
|
|
13277
13330
|
let blockEnd = blockStart;
|
|
13278
13331
|
let inString = null;
|
|
13279
13332
|
let escaped = false;
|
|
13333
|
+
let inLineComment = false;
|
|
13334
|
+
let inBlockComment = false;
|
|
13280
13335
|
for (let i = blockStart; i < code.length && depth > 0; i++) {
|
|
13281
13336
|
const ch = code[i];
|
|
13282
|
-
|
|
13283
|
-
|
|
13337
|
+
const next = code[i + 1];
|
|
13338
|
+
if (inLineComment) {
|
|
13339
|
+
if (ch === "\n") inLineComment = false;
|
|
13284
13340
|
continue;
|
|
13285
13341
|
}
|
|
13286
|
-
if (
|
|
13287
|
-
|
|
13342
|
+
if (inBlockComment) {
|
|
13343
|
+
if (ch === "*" && next === "/") {
|
|
13344
|
+
inBlockComment = false;
|
|
13345
|
+
i++;
|
|
13346
|
+
}
|
|
13288
13347
|
continue;
|
|
13289
13348
|
}
|
|
13290
13349
|
if (inString) {
|
|
13350
|
+
if (escaped) {
|
|
13351
|
+
escaped = false;
|
|
13352
|
+
continue;
|
|
13353
|
+
}
|
|
13354
|
+
if (ch === "\\") {
|
|
13355
|
+
escaped = true;
|
|
13356
|
+
continue;
|
|
13357
|
+
}
|
|
13291
13358
|
if (ch === inString) inString = null;
|
|
13292
13359
|
continue;
|
|
13293
13360
|
}
|
|
13361
|
+
if (ch === "/" && next === "/") {
|
|
13362
|
+
inLineComment = true;
|
|
13363
|
+
i++;
|
|
13364
|
+
continue;
|
|
13365
|
+
}
|
|
13366
|
+
if (ch === "/" && next === "*") {
|
|
13367
|
+
inBlockComment = true;
|
|
13368
|
+
i++;
|
|
13369
|
+
continue;
|
|
13370
|
+
}
|
|
13294
13371
|
if (ch === "\"" || ch === "'" || ch === "`") {
|
|
13295
13372
|
inString = ch;
|
|
13296
13373
|
continue;
|
|
@@ -13326,10 +13403,79 @@ function transformStylexCreateBlocks(code, transformBlock) {
|
|
|
13326
13403
|
/**
|
|
13327
13404
|
* Remove blank lines inside stylex.create({...}) blocks.
|
|
13328
13405
|
* Finds each `stylex.create({` and tracks brace depth to the matching `})`,
|
|
13329
|
-
* then
|
|
13406
|
+
* then drops every blank line within that region so style entries stay adjacent.
|
|
13407
|
+
* Blank lines inside multiline template-literal values are preserved, since they
|
|
13408
|
+
* are part of the CSS value and removing them would not be lossless.
|
|
13330
13409
|
*/
|
|
13331
13410
|
function removeBlankLinesInStylexCreate(code) {
|
|
13332
|
-
return transformStylexCreateBlocks(code, (blockContent) =>
|
|
13411
|
+
return transformStylexCreateBlocks(code, (blockContent) => {
|
|
13412
|
+
const lines = blockContent.split("\n");
|
|
13413
|
+
const protectedLines = protectedLineStarts(blockContent, lines.length);
|
|
13414
|
+
const kept = [];
|
|
13415
|
+
for (let i = 0; i < lines.length; i++) {
|
|
13416
|
+
const line = lines[i] ?? "";
|
|
13417
|
+
if (!protectedLines[i] && line.trim() === "") continue;
|
|
13418
|
+
kept.push(line);
|
|
13419
|
+
}
|
|
13420
|
+
return kept.join("\n").replace(/content:\s+"\\"([\s\S]*?)\\""/g, "content: '\"$1\"'").replace(/content:\s+"'\s*([\s\S]*?)\s*'"/g, "content: '\"$1\"'");
|
|
13421
|
+
});
|
|
13422
|
+
}
|
|
13423
|
+
/**
|
|
13424
|
+
* Returns, per line, whether that line *starts* inside a region where blank
|
|
13425
|
+
* lines are content and must be preserved: a multiline template-literal value or
|
|
13426
|
+
* a multiline block comment. Backticks inside comments or other string literals
|
|
13427
|
+
* are ignored, so an unmatched backtick in a preserved comment cannot flip the
|
|
13428
|
+
* template state and corrupt a following template value.
|
|
13429
|
+
*/
|
|
13430
|
+
function protectedLineStarts(code, lineCount) {
|
|
13431
|
+
const protectedLines = Array.from({ length: lineCount }).fill(false);
|
|
13432
|
+
let inString = null;
|
|
13433
|
+
let inLineComment = false;
|
|
13434
|
+
let inBlockComment = false;
|
|
13435
|
+
let escaped = false;
|
|
13436
|
+
let line = 0;
|
|
13437
|
+
for (let i = 0; i < code.length; i++) {
|
|
13438
|
+
const ch = code[i];
|
|
13439
|
+
const next = code[i + 1];
|
|
13440
|
+
if (ch === "\n") {
|
|
13441
|
+
line++;
|
|
13442
|
+
inLineComment = false;
|
|
13443
|
+
if (line < lineCount) protectedLines[line] = inString === "`" || inBlockComment;
|
|
13444
|
+
continue;
|
|
13445
|
+
}
|
|
13446
|
+
if (inLineComment) continue;
|
|
13447
|
+
if (inBlockComment) {
|
|
13448
|
+
if (ch === "*" && next === "/") {
|
|
13449
|
+
inBlockComment = false;
|
|
13450
|
+
i++;
|
|
13451
|
+
}
|
|
13452
|
+
continue;
|
|
13453
|
+
}
|
|
13454
|
+
if (inString) {
|
|
13455
|
+
if (escaped) {
|
|
13456
|
+
escaped = false;
|
|
13457
|
+
continue;
|
|
13458
|
+
}
|
|
13459
|
+
if (ch === "\\") {
|
|
13460
|
+
escaped = true;
|
|
13461
|
+
continue;
|
|
13462
|
+
}
|
|
13463
|
+
if (ch === inString) inString = null;
|
|
13464
|
+
continue;
|
|
13465
|
+
}
|
|
13466
|
+
if (ch === "/" && next === "/") {
|
|
13467
|
+
inLineComment = true;
|
|
13468
|
+
i++;
|
|
13469
|
+
continue;
|
|
13470
|
+
}
|
|
13471
|
+
if (ch === "/" && next === "*") {
|
|
13472
|
+
inBlockComment = true;
|
|
13473
|
+
i++;
|
|
13474
|
+
continue;
|
|
13475
|
+
}
|
|
13476
|
+
if (ch === "\"" || ch === "'" || ch === "`") inString = ch;
|
|
13477
|
+
}
|
|
13478
|
+
return protectedLines;
|
|
13333
13479
|
}
|
|
13334
13480
|
/**
|
|
13335
13481
|
* Indents lines inside multiline template literal object values so each continuation
|
|
@@ -17937,49 +18083,6 @@ function rewriteCssHelpersStep(ctx) {
|
|
|
17937
18083
|
return CONTINUE;
|
|
17938
18084
|
}
|
|
17939
18085
|
//#endregion
|
|
17940
|
-
//#region src/internal/utilities/import-source.ts
|
|
17941
|
-
/**
|
|
17942
|
-
* Helpers for converting an `ImportSource` into the textual specifier used in
|
|
17943
|
-
* an emitted `import` declaration, and into a writable absolute file path.
|
|
17944
|
-
*/
|
|
17945
|
-
/**
|
|
17946
|
-
* Convert an `ImportSource` to a module specifier string for use in import declarations.
|
|
17947
|
-
* - `kind: "specifier"` → returned as-is.
|
|
17948
|
-
* - `kind: "absolutePath"` → returned as a relative path from `filePath`'s directory,
|
|
17949
|
-
* prefixed with `./` when needed.
|
|
17950
|
-
*
|
|
17951
|
-
* Pass `stripTsExtension: true` to drop a trailing `.ts`/`.tsx` from the relative
|
|
17952
|
-
* specifier (e.g. when emitting an import to a sidecar `.stylex.ts` file).
|
|
17953
|
-
*/
|
|
17954
|
-
function importSourceToModuleSpecifier(source, filePath, options = {}) {
|
|
17955
|
-
if (source.kind === "specifier") return source.value;
|
|
17956
|
-
let rel = relative(dirname(filePath), source.value).split(sep).join("/");
|
|
17957
|
-
if (options.stripTsExtension) rel = rel.replace(/\.tsx?$/, "");
|
|
17958
|
-
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
17959
|
-
return rel;
|
|
17960
|
-
}
|
|
17961
|
-
/**
|
|
17962
|
-
* Resolve an `ImportSource` to an absolute file path for writing the sidecar file.
|
|
17963
|
-
* - `kind: "absolutePath"` → returned as-is.
|
|
17964
|
-
* - `kind: "specifier"` → resolved relative to `filePath`'s directory; appends `.ts`
|
|
17965
|
-
* when the result has no `.{j,t}sx?` extension.
|
|
17966
|
-
*/
|
|
17967
|
-
function importSourceToAbsolutePath(source, filePath) {
|
|
17968
|
-
if (source.kind === "absolutePath") return source.value;
|
|
17969
|
-
let resolved = join(dirname(filePath), source.value);
|
|
17970
|
-
if (!/\.[jt]sx?$/.test(resolved)) resolved += ".ts";
|
|
17971
|
-
return resolved;
|
|
17972
|
-
}
|
|
17973
|
-
/**
|
|
17974
|
-
* Throws if `source` is structurally invalid for use as a module reference,
|
|
17975
|
-
* with a `label` prefixed for caller context. Used by the merger import step
|
|
17976
|
-
* which validates user-provided adapter configuration at use-time.
|
|
17977
|
-
*/
|
|
17978
|
-
function assertValidImportSource(source, label) {
|
|
17979
|
-
if (typeof source.value !== "string" || source.value.trim() === "") throw new Error(`Invalid ${label}: expected non-empty string, got ${JSON.stringify(source.value)}`);
|
|
17980
|
-
if (source.kind === "absolutePath" && !isAbsolute(source.value)) throw new Error(`Invalid ${label}: expected absolute path, got ${JSON.stringify(source.value)}`);
|
|
17981
|
-
}
|
|
17982
|
-
//#endregion
|
|
17983
18086
|
//#region src/internal/utilities/import-insertion.ts
|
|
17984
18087
|
/**
|
|
17985
18088
|
* Return the index of the LAST top-level `ImportDeclaration` in `body`, or -1
|
|
@@ -42063,9 +42166,13 @@ function calleeKey(callee) {
|
|
|
42063
42166
|
//#endregion
|
|
42064
42167
|
//#region src/internal/lower-rules/resolved-style-function-handlers.ts
|
|
42065
42168
|
function tryHandleResolvedStyleFunctionNode(rc) {
|
|
42066
|
-
const { ctx, d, media, pseudos, res, slotId, loc, avoidNames, flags, addResolverImports, bailUnsupportedLocal, annotateScalarParams, tryEmitIdentityVariantBuckets, tryEmitTransformedObservedVariantBuckets, shouldPreserveNumericCssTextForProp } = rc;
|
|
42169
|
+
const { ctx, d, media, pseudos, resolvedSelectorMedia, res, slotId, loc, avoidNames, flags, addResolverImports, bailUnsupportedLocal, annotateScalarParams, tryEmitIdentityVariantBuckets, tryEmitTransformedObservedVariantBuckets, shouldPreserveNumericCssTextForProp } = rc;
|
|
42067
42170
|
const { state, decl, styleObj, styleFnFromProps, styleFnDecls, inlineStyleProps, annotateParamFromJsxProp } = ctx;
|
|
42068
42171
|
const { j, filePath, warnings, parseExpr, resolveCall, warnPropInlineStyle, resolveImportInScope, resolveImportForExpr } = state;
|
|
42172
|
+
if (resolvedSelectorMedia && d.property && (decl.shouldForwardProp || res?.type === "emitStyleFunctionFromPropsObject" || res?.type === "emitStyleFunctionWithDefault" || res?.type === "emitStyleFunction")) {
|
|
42173
|
+
bailUnsupportedLocal(decl, "Prop-dependent dynamic style function cannot also carry a computed media-query override for the same property — split into static conditional styles or bind the media value separately");
|
|
42174
|
+
return true;
|
|
42175
|
+
}
|
|
42069
42176
|
if (res && res.type === "emitStyleFunctionFromPropsObject") if (!d.property) {} else {
|
|
42070
42177
|
const e = decl.templateExpressions[slotId];
|
|
42071
42178
|
if (e?.type !== "ArrowFunctionExpression" && e?.type !== "FunctionExpression") {
|
|
@@ -43158,7 +43265,7 @@ function handleInterpolatedDeclaration(args) {
|
|
|
43158
43265
|
if (isJsxPropOptional(propName)) addUndefinedToParamType(j, param);
|
|
43159
43266
|
});
|
|
43160
43267
|
};
|
|
43161
|
-
const { api, j, filePath, warnings, resolverImports, keyframesNames, parseExpr, resolveValue, resolveCall, importMap, cssHelperNames, cssHelperObjectMembers, declByLocalName, cssHelperValuesByKey, staticPropertyValues, applyCssHelperMixin, hasLocalThemeBinding, resolveThemeValue, resolveThemeValueFromFn, getOrCreateLocalStylexVar } = state;
|
|
43268
|
+
const { api, j, filePath, warnings, resolverImports, keyframesNames, parseExpr, resolveValue, resolveCall, importMap, cssHelperNames, cssHelperObjectMembers, declByLocalName, cssHelperValuesByKey, staticPropertyValues, localFunctionIdentifierNames, applyCssHelperMixin, hasLocalThemeBinding, resolveThemeValue, resolveThemeValueFromFn, getOrCreateLocalStylexVar } = state;
|
|
43162
43269
|
const avoidNames = new Set(importMap.keys());
|
|
43163
43270
|
if (state.bail) return;
|
|
43164
43271
|
if (d.value.kind !== "interpolated") return;
|
|
@@ -43199,6 +43306,15 @@ function handleInterpolatedDeclaration(args) {
|
|
|
43199
43306
|
flags
|
|
43200
43307
|
});
|
|
43201
43308
|
for (let _i = 0; _i < 1; _i++) {
|
|
43309
|
+
if (flags.bail) break;
|
|
43310
|
+
for (const part of d.value.parts ?? []) {
|
|
43311
|
+
if (part?.kind !== "slot" || part.slotId === void 0) continue;
|
|
43312
|
+
const slotExpr = decl.templateExpressions[part.slotId];
|
|
43313
|
+
if (slotExpr?.type === "Identifier" && slotExpr.name && localFunctionIdentifierNames.has(slotExpr.name)) {
|
|
43314
|
+
bailUnsupportedLocal(decl, "Unsupported interpolation: identifier");
|
|
43315
|
+
break;
|
|
43316
|
+
}
|
|
43317
|
+
}
|
|
43202
43318
|
if (flags.bail) break;
|
|
43203
43319
|
if (tryHandleMappedFunctionColor(d)) continue;
|
|
43204
43320
|
if (tryHandleAnimation({
|
|
@@ -46229,10 +46345,13 @@ function createLowerRulesState(ctx) {
|
|
|
46229
46345
|
};
|
|
46230
46346
|
const staticPropertyValues = /* @__PURE__ */ new Map();
|
|
46231
46347
|
const staticIdentifierValues = /* @__PURE__ */ new Map();
|
|
46348
|
+
const localFunctionIdentifierNames = /* @__PURE__ */ new Set();
|
|
46232
46349
|
root.find(j.VariableDeclarator).forEach((p) => {
|
|
46233
46350
|
if (!isTopLevelConstDeclarator(p)) return;
|
|
46234
46351
|
const node = p.node;
|
|
46235
46352
|
if (node.id?.type !== "Identifier" || !node.id.name) return;
|
|
46353
|
+
const initType = node.init?.type;
|
|
46354
|
+
if (initType === "ArrowFunctionExpression" || initType === "FunctionExpression") localFunctionIdentifierNames.add(node.id.name);
|
|
46236
46355
|
const staticValue = literalToStaticValue(node.init, { allowStaticArrowFunctions: false });
|
|
46237
46356
|
if (staticValue !== null) staticIdentifierValues.set(node.id.name, staticValue);
|
|
46238
46357
|
});
|
|
@@ -46361,6 +46480,7 @@ function createLowerRulesState(ctx) {
|
|
|
46361
46480
|
mixinValuesByKey,
|
|
46362
46481
|
staticPropertyValues,
|
|
46363
46482
|
staticIdentifierValues,
|
|
46483
|
+
localFunctionIdentifierNames,
|
|
46364
46484
|
usedCssHelperFunctions: /* @__PURE__ */ new Set(),
|
|
46365
46485
|
warnPropInlineStyle,
|
|
46366
46486
|
applyCssHelperMixin,
|