styled-components-to-stylex-codemod 0.0.56 → 0.0.57
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/README.md +1 -1
- package/dist/{ast-walk-CLvMH7Lm.mjs → ast-walk-DVmYZ2mK.mjs} +81 -30
- package/dist/{bridge-consumer-patcher-B__X3jOg.mjs → bridge-consumer-patcher-jeeDUlId.mjs} +2 -2
- package/dist/{forwarded-as-consumer-patcher-Bs9ymhBa.mjs → forwarded-as-consumer-patcher-Do4PI4Qs.mjs} +2 -2
- package/dist/index.d.mts +1 -12
- package/dist/index.mjs +180 -28
- package/dist/{transform-types-BGGNjb8R.d.mts → logger-ByYsVkrB.d.mts} +1 -198
- package/dist/{prop-usage-z-bcXTOD.mjs → prop-usage-D1dECkkb.mjs} +118 -98
- package/dist/{run-prepass-BueJvYyf.mjs → run-prepass-CGL_ugPB.mjs} +29 -102
- package/dist/{sx-surface-_Hjc6ZDq.mjs → sx-surface-Kv8zK8L4.mjs} +32 -2
- package/dist/transform.d.mts +180 -2
- package/dist/transform.mjs +600 -861
- package/dist/{transient-prop-consumer-patcher-BDruM1OI.mjs → transient-prop-consumer-patcher-D-iqO8-T.mjs} +2 -2
- package/dist/{typescript-analysis-BzsnorIV.mjs → typescript-analysis-eRPqsZ2z.mjs} +1 -1
- package/package.json +1 -1
- package/dist/compute-leaf-set-D5GvkV-H.mjs +0 -255
- /package/dist/{path-utils-ByFNVtHo.mjs → path-utils-BC4U8X_q.mjs} +0 -0
- /package/dist/{string-utils-4eeXGa48.mjs → string-utils-Bo3cWgss.mjs} +0 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { API, FileInfo, Options } from "jscodeshift";
|
|
2
1
|
//#region src/adapter.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Adapter entry point for customizing the codemod.
|
|
@@ -973,200 +972,4 @@ interface CollectedWarning extends WarningLog {
|
|
|
973
972
|
filePath: string;
|
|
974
973
|
}
|
|
975
974
|
//#endregion
|
|
976
|
-
|
|
977
|
-
interface TypeScriptPrepassMetadata {
|
|
978
|
-
version: 1;
|
|
979
|
-
files: TypeScriptFileMetadata[];
|
|
980
|
-
}
|
|
981
|
-
interface TypeScriptFileMetadata {
|
|
982
|
-
filePath: string;
|
|
983
|
-
components: TypeScriptComponentMetadata[];
|
|
984
|
-
functions: TypeScriptFunctionMetadata[];
|
|
985
|
-
}
|
|
986
|
-
interface TypeScriptComponentMetadata {
|
|
987
|
-
name: string;
|
|
988
|
-
kind: "styled" | "react";
|
|
989
|
-
exported: boolean;
|
|
990
|
-
defaultExport: boolean;
|
|
991
|
-
typeParameters: string[];
|
|
992
|
-
propType: TypeScriptTypeMetadata | null;
|
|
993
|
-
props: TypeScriptPropMetadata[];
|
|
994
|
-
explicitPropNames: string[];
|
|
995
|
-
parameters: TypeScriptParameterMetadata[];
|
|
996
|
-
restProps: TypeScriptRestPropMetadata[];
|
|
997
|
-
hasIndexSignature: boolean;
|
|
998
|
-
supportsSxProp: boolean;
|
|
999
|
-
sxTarget?: "root" | "inner";
|
|
1000
|
-
sxExcludedProperties: string[];
|
|
1001
|
-
sxAllowedProperties?: string[];
|
|
1002
|
-
}
|
|
1003
|
-
interface TypeScriptFunctionMetadata {
|
|
1004
|
-
name: string;
|
|
1005
|
-
exported: boolean;
|
|
1006
|
-
defaultExport: boolean;
|
|
1007
|
-
typeParameters: string[];
|
|
1008
|
-
parameters: TypeScriptParameterMetadata[];
|
|
1009
|
-
}
|
|
1010
|
-
interface TypeScriptTypeMetadata {
|
|
1011
|
-
text: string;
|
|
1012
|
-
inheritedTypes: string[];
|
|
1013
|
-
intersectionTypes: string[];
|
|
1014
|
-
unionTypes: string[];
|
|
1015
|
-
}
|
|
1016
|
-
interface TypeScriptPropMetadata {
|
|
1017
|
-
name: string;
|
|
1018
|
-
optional: boolean;
|
|
1019
|
-
readonly: boolean;
|
|
1020
|
-
type: string;
|
|
1021
|
-
}
|
|
1022
|
-
interface TypeScriptParameterMetadata {
|
|
1023
|
-
name: string;
|
|
1024
|
-
optional: boolean;
|
|
1025
|
-
rest: boolean;
|
|
1026
|
-
type: string;
|
|
1027
|
-
}
|
|
1028
|
-
interface TypeScriptRestPropMetadata {
|
|
1029
|
-
name: string;
|
|
1030
|
-
source: "parameter" | "destructure";
|
|
1031
|
-
}
|
|
1032
|
-
//#endregion
|
|
1033
|
-
//#region src/internal/transform-types.d.ts
|
|
1034
|
-
/** A sidecar .stylex.ts file containing defineMarker() declarations. */
|
|
1035
|
-
interface SidecarFile {
|
|
1036
|
-
content: string;
|
|
1037
|
-
/** Absolute file path for writing. Undefined = default local sidecar next to the source file. */
|
|
1038
|
-
filePath?: string;
|
|
1039
|
-
}
|
|
1040
|
-
interface LocalStylexVarsSidecarFile {
|
|
1041
|
-
content: string;
|
|
1042
|
-
importPath: string;
|
|
1043
|
-
}
|
|
1044
|
-
/**
|
|
1045
|
-
* Result of the transform including any log entries
|
|
1046
|
-
*/
|
|
1047
|
-
interface TransformResult {
|
|
1048
|
-
code: string | null;
|
|
1049
|
-
warnings: WarningLog[];
|
|
1050
|
-
/** Sidecar .stylex.ts files (defineMarker declarations). Multiple entries when a file has
|
|
1051
|
-
* both cross-file markers (adapter.markerFile) and internal markers (local sidecar). */
|
|
1052
|
-
sidecarFiles?: SidecarFile[];
|
|
1053
|
-
/** Bridge components emitted for unconverted consumer selectors. */
|
|
1054
|
-
bridgeResults?: BridgeComponentResult[];
|
|
1055
|
-
/** Transient prop renames for exported components, keyed by export name. */
|
|
1056
|
-
transientPropRenames?: TransientPropRenameResult[];
|
|
1057
|
-
/** Local styled component names that were actually converted in this file. */
|
|
1058
|
-
transformedComponentNames?: string[];
|
|
1059
|
-
localStylexVarsSidecarFile?: LocalStylexVarsSidecarFile;
|
|
1060
|
-
}
|
|
1061
|
-
/** Describes a transient prop rename on an exported component for consumer patching. */
|
|
1062
|
-
interface TransientPropRenameResult {
|
|
1063
|
-
exportName: string;
|
|
1064
|
-
renames: Record<string, string>;
|
|
1065
|
-
}
|
|
1066
|
-
/** Describes a bridge className emitted for a component targeted by unconverted consumer selectors. */
|
|
1067
|
-
interface BridgeComponentResult {
|
|
1068
|
-
componentName: string;
|
|
1069
|
-
/** The export name (e.g. "default" for default exports, or the named export identifier). */
|
|
1070
|
-
exportName?: string;
|
|
1071
|
-
className: string;
|
|
1072
|
-
globalSelectorVarName: string;
|
|
1073
|
-
}
|
|
1074
|
-
type TransformMode = "all" | "leavesOnly";
|
|
1075
|
-
/**
|
|
1076
|
-
* Options for the transform
|
|
1077
|
-
*/
|
|
1078
|
-
interface TransformOptions extends Options {
|
|
1079
|
-
/**
|
|
1080
|
-
* Adapter for customizing the transform.
|
|
1081
|
-
* Controls value resolution and resolver-provided imports.
|
|
1082
|
-
*/
|
|
1083
|
-
adapter: Adapter;
|
|
1084
|
-
/**
|
|
1085
|
-
* Cross-file selector information from the prepass.
|
|
1086
|
-
* When present, enables cross-file component selector handling.
|
|
1087
|
-
*/
|
|
1088
|
-
crossFileInfo?: CrossFileInfo;
|
|
1089
|
-
/**
|
|
1090
|
-
* When true, individual declarations that hit an unsupported pattern are left
|
|
1091
|
-
* as-is while the rest of the file is transformed. When false (default), any
|
|
1092
|
-
* per-decl bail escalates to a whole-file bail.
|
|
1093
|
-
*/
|
|
1094
|
-
allowPartialMigration?: boolean;
|
|
1095
|
-
/**
|
|
1096
|
-
* Controls which styled declarations are eligible for conversion.
|
|
1097
|
-
* - "all" (default): transform every supported styled declaration.
|
|
1098
|
-
* - "leavesOnly": only transform styled declarations whose render base is
|
|
1099
|
-
* intrinsic after adapter resolution, or that wrap another leaf styled
|
|
1100
|
-
* declaration in the transform run (including cross-file imports).
|
|
1101
|
-
*/
|
|
1102
|
-
transformMode?: TransformMode;
|
|
1103
|
-
/**
|
|
1104
|
-
* From prepass when leaves-only mode is on: keys `${realpath}:${bindingName}` for leaf
|
|
1105
|
-
* styled definitions. An empty set means no leaf bindings were found (per-decl policy
|
|
1106
|
-
* treats all `styled(Component)` bases like missing keys). Used internally by the runner.
|
|
1107
|
-
*/
|
|
1108
|
-
globalLeafKeys?: Set<string>;
|
|
1109
|
-
/**
|
|
1110
|
-
* Module resolver for leaves-only import→definition lookup (`resolve(fromFile, specifier)`).
|
|
1111
|
-
* Set by runTransform.
|
|
1112
|
-
*/
|
|
1113
|
-
resolveModule?: (fromFile: string, specifier: string) => string | undefined;
|
|
1114
|
-
/**
|
|
1115
|
-
* In-memory outputs for files already converted in this run. Used during dry-run
|
|
1116
|
-
* so same-run dependency checks see the same source a real run would write.
|
|
1117
|
-
*/
|
|
1118
|
-
transformedFileSources?: ReadonlyMap<string, string>;
|
|
1119
|
-
}
|
|
1120
|
-
/**
|
|
1121
|
-
* Cross-file selector info passed from the prepass to the per-file transform.
|
|
1122
|
-
* Kept minimal: only what the transform needs to know about this specific file.
|
|
1123
|
-
*/
|
|
1124
|
-
interface CrossFileInfo {
|
|
1125
|
-
/** Cross-file selector usages where this file is the consumer */
|
|
1126
|
-
selectorUsages: CrossFileSelectorUsage[];
|
|
1127
|
-
/** Component names in this file that need a global selector bridge className (consumer not transformed) */
|
|
1128
|
-
bridgeComponentNames?: Set<string>;
|
|
1129
|
-
/** Styled component prop usage inventory from the prepass, keyed by local component name. */
|
|
1130
|
-
propUsageByComponent?: Map<string, ComponentPropUsageInfo>;
|
|
1131
|
-
/** Global map: files that define styled-components → set of local names. Used for cascade conflict detection. */
|
|
1132
|
-
styledDefFiles?: Map<string, Set<string>>;
|
|
1133
|
-
/** Global map: files that export components already using StyleX → set of export names. */
|
|
1134
|
-
stylexComponentFiles?: Map<string, Set<string>>;
|
|
1135
|
-
/** Global leaf keys from prepass when leaves-only mode is enabled. */
|
|
1136
|
-
globalLeafKeys?: Set<string>;
|
|
1137
|
-
/** Files successfully converted in the current transform run. Used to avoid bailing on same-run bases. */
|
|
1138
|
-
transformedFiles?: Set<string>;
|
|
1139
|
-
/** File → local styled component names successfully converted in the current transform run. */
|
|
1140
|
-
transformedComponents?: Map<string, Set<string>>;
|
|
1141
|
-
/** Opt-in TypeScript compiler metadata from the prepass. */
|
|
1142
|
-
typeScriptMetadata?: TypeScriptPrepassMetadata;
|
|
1143
|
-
}
|
|
1144
|
-
interface CrossFileSelectorUsage {
|
|
1145
|
-
/** Local name in the consumer file (e.g. "CollapseArrowIcon") */
|
|
1146
|
-
localName: string;
|
|
1147
|
-
/** Raw import specifier (e.g. "./lib/collapse-arrow-icon") */
|
|
1148
|
-
importSource: string;
|
|
1149
|
-
/** Imported binding name ("default" for default imports, otherwise named) */
|
|
1150
|
-
importedName: string;
|
|
1151
|
-
/** Absolute path of the target module */
|
|
1152
|
-
resolvedPath: string;
|
|
1153
|
-
/** Original component name for bridge GlobalSelector (e.g., "Foo" for "FooGlobalSelector") */
|
|
1154
|
-
bridgeComponentName?: string;
|
|
1155
|
-
/** Local name of the actual component in the consumer file (for JSX matching) */
|
|
1156
|
-
bridgeComponentLocalName?: string;
|
|
1157
|
-
}
|
|
1158
|
-
type StaticPropValue = string | number | boolean;
|
|
1159
|
-
interface PropUsageValueInfo {
|
|
1160
|
-
values: StaticPropValue[];
|
|
1161
|
-
hasUnknown: boolean;
|
|
1162
|
-
usageCount: number;
|
|
1163
|
-
omittedCount: number;
|
|
1164
|
-
}
|
|
1165
|
-
interface ComponentPropUsageInfo {
|
|
1166
|
-
componentName: string;
|
|
1167
|
-
usageCount: number;
|
|
1168
|
-
hasUnknownUsage: boolean;
|
|
1169
|
-
props: Record<string, PropUsageValueInfo>;
|
|
1170
|
-
}
|
|
1171
|
-
//#endregion
|
|
1172
|
-
export { CollectedWarning as a, MarkerFileContext as c, TransformResult as i, defineAdapter as l, TransformMode as n, AdapterInput as o, TransformOptions as r, ImportSource as s, BridgeComponentResult as t };
|
|
975
|
+
export { ImportSource as a, AdapterInput as i, WarningLog as n, MarkerFileContext as o, Adapter as r, defineAdapter as s, CollectedWarning as t };
|
|
@@ -1,9 +1,120 @@
|
|
|
1
|
-
import { m as createPrepassParser } from "./ast-walk-
|
|
2
|
-
//#region src/internal/prepass/
|
|
1
|
+
import { m as createPrepassParser } from "./ast-walk-DVmYZ2mK.mjs";
|
|
2
|
+
//#region src/internal/prepass/prepass-ast-utils.ts
|
|
3
|
+
/**
|
|
4
|
+
* Shared structural AST helpers for prepass modules that walk raw babel ASTs
|
|
5
|
+
* to relate exports, local bindings, and named references.
|
|
6
|
+
*
|
|
7
|
+
* These were duplicated verbatim across `component-styled-dependencies` and
|
|
8
|
+
* `stylex-component-exports`; centralizing keeps the traversal semantics
|
|
9
|
+
* (which keys to skip, how to read a node name) consistent.
|
|
10
|
+
*/
|
|
11
|
+
/** Parse a module `source` into its Program node, trying `tsx` then `babel`. */
|
|
12
|
+
function parseProgram(source) {
|
|
13
|
+
for (const parserName of ["tsx", "babel"]) try {
|
|
14
|
+
const ast = createPrepassParser(parserName).parse(source);
|
|
15
|
+
return ast.program ?? ast;
|
|
16
|
+
} catch {}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
function programBody(program) {
|
|
20
|
+
return astArray(program.body);
|
|
21
|
+
}
|
|
22
|
+
function astArray(value) {
|
|
23
|
+
return Array.isArray(value) ? value.filter(isAstNode) : [];
|
|
24
|
+
}
|
|
25
|
+
function nodeName(node) {
|
|
26
|
+
if (!node) return;
|
|
27
|
+
if (node.type === "Identifier" || node.type === "JSXIdentifier" || node.type === "StringLiteral") return typeof node.name === "string" ? node.name : typeof node.value === "string" ? node.value : void 0;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Top-level binding name → initializer/body node for function, class, and
|
|
31
|
+
* variable declarations (including those behind a named export).
|
|
32
|
+
*/
|
|
33
|
+
function localBindings(program) {
|
|
34
|
+
const bindings = [];
|
|
35
|
+
for (const stmt of programBody(program)) {
|
|
36
|
+
const declaration = stmt.type === "ExportNamedDeclaration" ? stmt.declaration : stmt;
|
|
37
|
+
if (!declaration) continue;
|
|
38
|
+
if (declaration.type === "FunctionDeclaration" || declaration.type === "ClassDeclaration") {
|
|
39
|
+
const name = nodeName(declaration.id);
|
|
40
|
+
const body = declaration.body;
|
|
41
|
+
if (name && body) bindings.push({
|
|
42
|
+
name,
|
|
43
|
+
node: body
|
|
44
|
+
});
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (declaration.type === "VariableDeclaration") for (const declarator of astArray(declaration.declarations)) {
|
|
48
|
+
const name = nodeName(declarator.id);
|
|
49
|
+
const init = declarator.init;
|
|
50
|
+
if (name && init) bindings.push({
|
|
51
|
+
name,
|
|
52
|
+
node: init
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return bindings;
|
|
57
|
+
}
|
|
3
58
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
59
|
+
* Depth-first walk that skips metadata (`loc`/comments), type annotations, and
|
|
60
|
+
* the non-computed `key`/`property` of object members and member expressions,
|
|
61
|
+
* so visitors only see value-position nodes.
|
|
6
62
|
*/
|
|
63
|
+
function walkValueAst(root, visitor) {
|
|
64
|
+
const visit = (node) => {
|
|
65
|
+
if (!node || typeof node !== "object") return;
|
|
66
|
+
if (Array.isArray(node)) {
|
|
67
|
+
for (const child of node) visit(child);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const astNode = node;
|
|
71
|
+
visitor(astNode);
|
|
72
|
+
for (const key of Object.keys(astNode)) {
|
|
73
|
+
if (shouldSkipChild(astNode, key)) continue;
|
|
74
|
+
const child = astNode[key];
|
|
75
|
+
if (child && typeof child === "object") visit(child);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
visit(root);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Whether `node` references any of `localNames`. `whenUndefined` is the
|
|
82
|
+
* conservative answer when `node` is absent — dependency checks treat a missing
|
|
83
|
+
* node as dependent (`true`), surface checks as not referencing (`false`).
|
|
84
|
+
*/
|
|
85
|
+
function nodeReferencesLocalNames$1(node, localNames, whenUndefined) {
|
|
86
|
+
if (!node) return whenUndefined;
|
|
87
|
+
let found = false;
|
|
88
|
+
walkValueAst(node, (candidate) => {
|
|
89
|
+
if (!found && isNamedReference(candidate, localNames)) found = true;
|
|
90
|
+
});
|
|
91
|
+
return found;
|
|
92
|
+
}
|
|
93
|
+
function isAstNode(value) {
|
|
94
|
+
return Boolean(value && typeof value === "object");
|
|
95
|
+
}
|
|
96
|
+
function isNamedReference(node, localNames) {
|
|
97
|
+
if (node.type === "Identifier" || node.type === "JSXIdentifier") return typeof node.name === "string" && localNames.has(node.name);
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
function shouldSkipChild(node, key) {
|
|
101
|
+
if ([
|
|
102
|
+
"loc",
|
|
103
|
+
"comments",
|
|
104
|
+
"leadingComments",
|
|
105
|
+
"trailingComments"
|
|
106
|
+
].includes(key)) return true;
|
|
107
|
+
if ([
|
|
108
|
+
"typeAnnotation",
|
|
109
|
+
"typeParameters",
|
|
110
|
+
"returnType"
|
|
111
|
+
].includes(key)) return true;
|
|
112
|
+
if (key === "key" && (node.type === "ObjectProperty" || node.type === "Property") && node.computed !== true) return true;
|
|
113
|
+
if (key === "property" && node.type === "MemberExpression" && node.computed !== true) return true;
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/internal/prepass/stylex-component-exports.ts
|
|
7
118
|
function collectStylexExportNames(source) {
|
|
8
119
|
const parsed = parseProgram(source);
|
|
9
120
|
if (!parsed) return /* @__PURE__ */ new Set();
|
|
@@ -16,13 +127,6 @@ function collectStylexExportNames(source) {
|
|
|
16
127
|
}
|
|
17
128
|
return names;
|
|
18
129
|
}
|
|
19
|
-
function parseProgram(source) {
|
|
20
|
-
for (const parserName of ["tsx", "babel"]) try {
|
|
21
|
-
const ast = createPrepassParser(parserName).parse(source);
|
|
22
|
-
return ast.program ?? ast;
|
|
23
|
-
} catch {}
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
130
|
function collectStylexNamedExports(program, stmt, stylexUsage, names) {
|
|
27
131
|
if (stmt.type !== "ExportNamedDeclaration") return;
|
|
28
132
|
const declaration = stmt.declaration;
|
|
@@ -107,36 +211,6 @@ function candidateUsesStylex(candidate, stylexUsage) {
|
|
|
107
211
|
function findLocalBindingNode(program, localName) {
|
|
108
212
|
for (const binding of localBindings(program)) if (binding.name === localName) return binding.node;
|
|
109
213
|
}
|
|
110
|
-
function localBindings(program) {
|
|
111
|
-
const bindings = [];
|
|
112
|
-
for (const stmt of programBody(program)) {
|
|
113
|
-
const declaration = stmt.type === "ExportNamedDeclaration" ? stmt.declaration : stmt;
|
|
114
|
-
if (!declaration) continue;
|
|
115
|
-
const directBinding = localBindingFromDeclaration(declaration);
|
|
116
|
-
if (directBinding) {
|
|
117
|
-
bindings.push(directBinding);
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
if (declaration.type === "VariableDeclaration") for (const declarator of astArray(declaration.declarations)) {
|
|
121
|
-
const name = nodeName(declarator.id);
|
|
122
|
-
const init = declarator.init;
|
|
123
|
-
if (name && init) bindings.push({
|
|
124
|
-
name,
|
|
125
|
-
node: init
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return bindings;
|
|
130
|
-
}
|
|
131
|
-
function localBindingFromDeclaration(declaration) {
|
|
132
|
-
if (declaration.type !== "FunctionDeclaration" && declaration.type !== "ClassDeclaration") return null;
|
|
133
|
-
const name = nodeName(declaration.id);
|
|
134
|
-
const body = declaration.body;
|
|
135
|
-
return name && body ? {
|
|
136
|
-
name,
|
|
137
|
-
node: body
|
|
138
|
-
} : null;
|
|
139
|
-
}
|
|
140
214
|
function referencedLocalNames(program, node) {
|
|
141
215
|
const localNameSet = new Set(localBindings(program).map((binding) => binding.name));
|
|
142
216
|
const referenced = /* @__PURE__ */ new Set();
|
|
@@ -179,63 +253,9 @@ function isStylexSxAttribute(node, styleObjectNames) {
|
|
|
179
253
|
if (!value) return false;
|
|
180
254
|
return nodeReferencesLocalNames(value.type === "JSXExpressionContainer" ? value.expression : value, styleObjectNames);
|
|
181
255
|
}
|
|
256
|
+
/** StyleX surface checks treat a missing node as not referencing the names. */
|
|
182
257
|
function nodeReferencesLocalNames(node, localNames) {
|
|
183
|
-
|
|
184
|
-
let found = false;
|
|
185
|
-
walkValueAst(node, (candidate) => {
|
|
186
|
-
if (!found && isNamedReference(candidate, localNames)) found = true;
|
|
187
|
-
});
|
|
188
|
-
return found;
|
|
189
|
-
}
|
|
190
|
-
function walkValueAst(root, visitor) {
|
|
191
|
-
const visit = (node) => {
|
|
192
|
-
if (!node || typeof node !== "object") return;
|
|
193
|
-
if (Array.isArray(node)) {
|
|
194
|
-
for (const child of node) visit(child);
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
const astNode = node;
|
|
198
|
-
visitor(astNode);
|
|
199
|
-
for (const key of Object.keys(astNode)) {
|
|
200
|
-
if (shouldSkipChild(astNode, key)) continue;
|
|
201
|
-
const child = astNode[key];
|
|
202
|
-
if (child && typeof child === "object") visit(child);
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
visit(root);
|
|
206
|
-
}
|
|
207
|
-
function shouldSkipChild(node, key) {
|
|
208
|
-
if ([
|
|
209
|
-
"loc",
|
|
210
|
-
"comments",
|
|
211
|
-
"leadingComments",
|
|
212
|
-
"trailingComments"
|
|
213
|
-
].includes(key)) return true;
|
|
214
|
-
if ([
|
|
215
|
-
"typeAnnotation",
|
|
216
|
-
"typeParameters",
|
|
217
|
-
"returnType"
|
|
218
|
-
].includes(key)) return true;
|
|
219
|
-
if (key === "key" && (node.type === "ObjectProperty" || node.type === "Property") && node.computed !== true) return true;
|
|
220
|
-
if (key === "property" && node.type === "MemberExpression" && node.computed !== true) return true;
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
function isNamedReference(node, localNames) {
|
|
224
|
-
if (node.type === "Identifier" || node.type === "JSXIdentifier") return typeof node.name === "string" && localNames.has(node.name);
|
|
225
|
-
return false;
|
|
226
|
-
}
|
|
227
|
-
function programBody(program) {
|
|
228
|
-
return astArray(program.body);
|
|
229
|
-
}
|
|
230
|
-
function astArray(value) {
|
|
231
|
-
return Array.isArray(value) ? value.filter(isAstNode) : [];
|
|
232
|
-
}
|
|
233
|
-
function isAstNode(value) {
|
|
234
|
-
return Boolean(value && typeof value === "object");
|
|
235
|
-
}
|
|
236
|
-
function nodeName(node) {
|
|
237
|
-
if (!node) return;
|
|
238
|
-
if (node.type === "Identifier" || node.type === "JSXIdentifier" || node.type === "StringLiteral") return typeof node.name === "string" ? node.name : typeof node.value === "string" ? node.value : void 0;
|
|
258
|
+
return nodeReferencesLocalNames$1(node, localNames, false);
|
|
239
259
|
}
|
|
240
260
|
//#endregion
|
|
241
261
|
//#region src/internal/utilities/jsx-static-literal.ts
|
|
@@ -316,4 +336,4 @@ function getExhaustiveObservedStaticValues(info, propName) {
|
|
|
316
336
|
return values.length === propUsage.values.length ? values : null;
|
|
317
337
|
}
|
|
318
338
|
//#endregion
|
|
319
|
-
export { mergeComponentPropUsage as a, getExhaustiveObservedStaticValues as i, createComponentPropUsageInfo as n, readStaticJsxLiteral as o, formatObservedVariantCondition as r, collectStylexExportNames as s, KNOWN_NON_ELEMENT_PROPS as t };
|
|
339
|
+
export { mergeComponentPropUsage as a, astArray as c, nodeReferencesLocalNames$1 as d, parseProgram as f, getExhaustiveObservedStaticValues as i, localBindings as l, createComponentPropUsageInfo as n, readStaticJsxLiteral as o, programBody as p, formatObservedVariantCondition as r, collectStylexExportNames as s, KNOWN_NON_ELEMENT_PROPS as t, nodeName as u };
|