@yahoo/uds 3.112.1 → 3.114.0-beta.1
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/automated-config/dist/mapTextVariantFixtureToValue.cjs +12 -1
- package/dist/automated-config/dist/mapTextVariantFixtureToValue.js +12 -1
- package/dist/automated-config/dist/properties.cjs +1 -1
- package/dist/automated-config/dist/properties.js +1 -1
- package/dist/automated-config/dist/utils/getConfigVariantProperties.d.cts +2 -2
- package/dist/automated-config/dist/utils/getConfigVariantProperties.d.ts +2 -2
- package/dist/cli/commands/sync.cjs +1 -3
- package/dist/cli/commands/sync.d.cts +1 -1
- package/dist/cli/commands/sync.d.ts +1 -1
- package/dist/cli/commands/sync.js +1 -3
- package/dist/cli/commands/version.cjs +0 -2
- package/dist/cli/commands/version.d.cts +1 -1
- package/dist/cli/commands/version.d.ts +1 -1
- package/dist/cli/commands/version.js +0 -2
- package/dist/cli/dist/cli.cjs +1 -1
- package/dist/cli/dist/cli.js +1 -1
- package/dist/cli/dist/commands/editor-rules.cjs +2 -2
- package/dist/cli/dist/commands/editor-rules.js +2 -2
- package/dist/cli/dist/lib/logger.cjs +66 -0
- package/dist/cli/dist/lib/logger.js +66 -0
- package/dist/cli/dist/utils/rules/config.cjs +1 -1
- package/dist/cli/dist/utils/rules/config.js +1 -1
- package/dist/cli/runner.cjs +11 -2
- package/dist/cli/runner.js +11 -2
- package/dist/components/client/Menu/Menu.ItemCheckbox.d.cts +1 -1
- package/dist/components/client/Menu/Menu.ItemCheckbox.d.ts +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/styles/styler.d.cts +11 -11
- package/dist/styles/styler.d.ts +11 -11
- package/dist/styles/variants.cjs +278 -278
- package/dist/styles/variants.js +278 -278
- package/dist/tailwind/dist/commands/css.cjs +79 -0
- package/dist/tailwind/dist/commands/css.d.ts +3 -0
- package/dist/tailwind/dist/commands/css.helpers.cjs +32 -0
- package/dist/tailwind/dist/commands/css.helpers.js +28 -0
- package/dist/tailwind/dist/commands/css.js +79 -0
- package/dist/tailwind/dist/commands/generateComponentData.cjs +33 -31
- package/dist/tailwind/dist/commands/generateComponentData.d.ts +1 -1
- package/dist/tailwind/dist/commands/generateComponentData.js +33 -31
- package/dist/tailwind/dist/commands/generatePurgeCSSData.d.ts +1 -1
- package/dist/tailwind/dist/commands/purge.cjs +3 -4
- package/dist/tailwind/dist/commands/purge.d.ts +1 -1
- package/dist/tailwind/dist/commands/purge.js +3 -4
- package/dist/tailwind/dist/css/generate.cjs +116 -0
- package/dist/tailwind/dist/css/generate.d.cts +30 -0
- package/dist/tailwind/dist/css/generate.d.ts +31 -0
- package/dist/tailwind/dist/css/generate.helpers.cjs +112 -0
- package/dist/tailwind/dist/css/generate.helpers.js +100 -0
- package/dist/tailwind/dist/css/generate.js +111 -0
- package/dist/tailwind/dist/css/postcss.cjs +35 -0
- package/dist/tailwind/dist/css/postcss.helpers.cjs +27 -0
- package/dist/tailwind/dist/css/postcss.helpers.js +26 -0
- package/dist/tailwind/dist/css/postcss.js +35 -0
- package/dist/tailwind/dist/css/runner.cjs +277 -0
- package/dist/tailwind/dist/css/runner.helpers.cjs +26 -0
- package/dist/tailwind/dist/css/runner.helpers.js +23 -0
- package/dist/tailwind/dist/css/runner.js +274 -0
- package/dist/tailwind/dist/css/theme.cjs +12 -0
- package/dist/tailwind/dist/css/theme.d.cts +66 -0
- package/dist/tailwind/dist/css/theme.d.ts +66 -0
- package/dist/tailwind/dist/css/theme.js +11 -0
- package/dist/tailwind/dist/css/utils.cjs +234 -0
- package/dist/tailwind/dist/css/utils.js +223 -0
- package/dist/tailwind/dist/index.d.cts +1 -0
- package/dist/tailwind/dist/index.d.ts +5 -3
- package/dist/tailwind/dist/purger/legacy/purgeCSS.cjs +4 -3
- package/dist/tailwind/dist/purger/legacy/purgeCSS.js +4 -3
- package/dist/tailwind/dist/purger/optimized/ast/expressions.cjs +122 -125
- package/dist/tailwind/dist/purger/optimized/ast/expressions.js +122 -125
- package/dist/tailwind/dist/purger/optimized/ast/jsx.cjs +1 -8
- package/dist/tailwind/dist/purger/optimized/ast/jsx.js +1 -8
- package/dist/tailwind/dist/purger/optimized/purge.cjs +11 -10
- package/dist/tailwind/dist/purger/optimized/purge.js +10 -9
- package/dist/tailwind/dist/purger/optimized/purgeFromCode.cjs +232 -127
- package/dist/tailwind/dist/purger/optimized/purgeFromCode.js +232 -127
- package/dist/tailwind/dist/purger/optimized/utils/componentAnalyzer.cjs +313 -251
- package/dist/tailwind/dist/purger/optimized/utils/componentAnalyzer.js +313 -251
- package/dist/tailwind/dist/purger/optimized/utils/files.cjs +4 -3
- package/dist/tailwind/dist/purger/optimized/utils/files.js +4 -3
- package/dist/tailwind/dist/purger/optimized/utils/safelist.cjs +13 -21
- package/dist/tailwind/dist/purger/optimized/utils/safelist.js +13 -21
- package/dist/tailwind/dist/tailwind/plugins/typography.cjs +41 -13
- package/dist/tailwind/dist/tailwind/plugins/typography.js +41 -13
- package/dist/tailwind/dist/tailwind/utils/composeTailwindPlugins.cjs +4 -2
- package/dist/tailwind/dist/tailwind/utils/composeTailwindPlugins.d.cts +10 -1
- package/dist/tailwind/dist/tailwind/utils/composeTailwindPlugins.d.ts +10 -1
- package/dist/tailwind/dist/tailwind/utils/composeTailwindPlugins.js +4 -2
- package/dist/tailwind/dist/tailwind/utils/getFontStyles.d.cts +1 -1
- package/dist/tailwind/dist/tailwind/utils/getFontStyles.d.ts +1 -1
- package/dist/tailwind/dist/utils/optimizeCSS.cjs +405 -0
- package/dist/tailwind/dist/utils/optimizeCSS.js +403 -0
- package/dist/tailwind/dist/utils/postcssPreserveVars.cjs +67 -0
- package/dist/tailwind/dist/utils/postcssPreserveVars.js +65 -0
- package/dist/tailwind/dist/utils/tsMorph.cjs +1 -1
- package/dist/uds/generated/componentData.cjs +1168 -1153
- package/dist/uds/generated/componentData.js +1168 -1153
- package/dist/uds/package.cjs +10 -4
- package/dist/uds/package.js +10 -4
- package/generated/componentData.json +2397 -0
- package/generated/tailwindPurge.ts +4560 -0
- package/package.json +7 -4
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
|
|
2
2
|
const require_runtime = require('../../../../../_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
const require_index = require('../../../../../motion-tokens/dist/index.cjs');
|
|
4
|
+
let ts_morph = require("ts-morph");
|
|
5
|
+
let node_fs = require("node:fs");
|
|
4
6
|
let node_path = require("node:path");
|
|
5
7
|
node_path = require_runtime.__toESM(node_path);
|
|
6
|
-
let ts_morph = require("ts-morph");
|
|
7
8
|
|
|
8
9
|
//#region ../tailwind/dist/purger/optimized/utils/componentAnalyzer.js
|
|
9
10
|
/*! © 2026 Yahoo, Inc. UDS Tailwind and Purger v0.0.0-development */
|
|
@@ -18,7 +19,7 @@ let componentPaths = null;
|
|
|
18
19
|
/**
|
|
19
20
|
* Scan src/components to build a map of all component files
|
|
20
21
|
*/
|
|
21
|
-
async
|
|
22
|
+
const scanComponentFiles = async (componentsDir) => {
|
|
22
23
|
if (componentPaths) return componentPaths;
|
|
23
24
|
componentPaths = /* @__PURE__ */ new Map();
|
|
24
25
|
knownComponents = /* @__PURE__ */ new Set();
|
|
@@ -35,7 +36,7 @@ async function scanComponentFiles(componentsDir) {
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
return componentPaths;
|
|
38
|
-
}
|
|
39
|
+
};
|
|
39
40
|
/**
|
|
40
41
|
* Analyze an object literal for variant key mappings.
|
|
41
42
|
* Handles:
|
|
@@ -43,60 +44,64 @@ async function scanComponentFiles(componentsDir) {
|
|
|
43
44
|
* - Nullish coalescing: { fontSize: fontSize ?? variant } -> variant maps to fontSize
|
|
44
45
|
* - Conditional spreads: ...(condition ? { props } : {}) -> recursively analyze props
|
|
45
46
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (initializer && ts_morph.Node.isStringLiteral(initializer)) getStylesLiterals.set(variantKey, initializer.getLiteralValue());
|
|
52
|
-
if (initializer && ts_morph.Node.isIdentifier(initializer)) {
|
|
53
|
-
const propName = initializer.getText();
|
|
54
|
-
const existing = propToVariantKeys.get(propName) ?? [];
|
|
55
|
-
if (!existing.includes(variantKey)) {
|
|
56
|
-
existing.push(variantKey);
|
|
57
|
-
propToVariantKeys.set(propName, existing);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (initializer && ts_morph.Node.isBinaryExpression(initializer)) {
|
|
61
|
-
const operatorToken = initializer.getOperatorToken();
|
|
62
|
-
if (operatorToken.getKind() === ts_morph.SyntaxKind.QuestionQuestionToken || operatorToken.getKind() === ts_morph.SyntaxKind.BarBarToken) {
|
|
63
|
-
const rightSide = initializer.getRight();
|
|
64
|
-
if (ts_morph.Node.isIdentifier(rightSide)) {
|
|
65
|
-
const fallbackPropName = rightSide.getText();
|
|
66
|
-
const existing = propToVariantKeys.get(fallbackPropName) ?? [];
|
|
67
|
-
if (!existing.includes(variantKey)) {
|
|
68
|
-
existing.push(variantKey);
|
|
69
|
-
propToVariantKeys.set(fallbackPropName, existing);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
47
|
+
const analyzeObjectForVariantMappings = (objLiteral, styleProps, getStylesLiterals, propToVariantKeys, sourceFile) => {
|
|
48
|
+
objLiteral.getProperties().forEach((prop) => {
|
|
49
|
+
if (ts_morph.Node.isPropertyAssignment(prop)) {
|
|
50
|
+
analyzeVariantPropertyAssignment(prop, styleProps, getStylesLiterals, propToVariantKeys);
|
|
51
|
+
return;
|
|
73
52
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
53
|
+
if (ts_morph.Node.isSpreadAssignment(prop)) analyzeVariantSpreadAssignment(prop, styleProps, getStylesLiterals, propToVariantKeys, sourceFile);
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
const addStyleProp = (styleProps, variantKey) => {
|
|
57
|
+
if (!styleProps.includes(variantKey)) styleProps.push(variantKey);
|
|
58
|
+
};
|
|
59
|
+
const addPropToVariantKeyMapping = (propToVariantKeys, propName, variantKey) => {
|
|
60
|
+
const existing = propToVariantKeys.get(propName) ?? [];
|
|
61
|
+
if (!existing.includes(variantKey)) propToVariantKeys.set(propName, [...existing, variantKey]);
|
|
62
|
+
};
|
|
63
|
+
const extractFallbackIdentifier = (initializer) => {
|
|
64
|
+
if (!ts_morph.Node.isBinaryExpression(initializer)) return null;
|
|
65
|
+
const operatorKind = initializer.getOperatorToken().getKind();
|
|
66
|
+
if (!(operatorKind === ts_morph.SyntaxKind.QuestionQuestionToken || operatorKind === ts_morph.SyntaxKind.BarBarToken) || !ts_morph.Node.isIdentifier(initializer.getRight())) return null;
|
|
67
|
+
return initializer.getRight().getText();
|
|
68
|
+
};
|
|
69
|
+
const analyzeVariantPropertyAssignment = (prop, styleProps, getStylesLiterals, propToVariantKeys) => {
|
|
70
|
+
const variantKey = prop.getName();
|
|
71
|
+
addStyleProp(styleProps, variantKey);
|
|
72
|
+
const initializer = prop.getInitializer();
|
|
73
|
+
if (!initializer) return;
|
|
74
|
+
if (ts_morph.Node.isStringLiteral(initializer)) getStylesLiterals.set(variantKey, initializer.getLiteralValue());
|
|
75
|
+
if (ts_morph.Node.isIdentifier(initializer)) addPropToVariantKeyMapping(propToVariantKeys, initializer.getText(), variantKey);
|
|
76
|
+
const fallbackIdentifier = extractFallbackIdentifier(initializer);
|
|
77
|
+
if (fallbackIdentifier) addPropToVariantKeyMapping(propToVariantKeys, fallbackIdentifier, variantKey);
|
|
78
|
+
};
|
|
79
|
+
const findVariableObjectLiteral = (sourceFile, variableName) => {
|
|
80
|
+
const initializer = sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.VariableDeclaration).find((candidate) => candidate.getName() === variableName)?.getInitializer();
|
|
81
|
+
return initializer && ts_morph.Node.isObjectLiteralExpression(initializer) ? initializer : null;
|
|
82
|
+
};
|
|
83
|
+
const analyzeVariantSpreadAssignment = (prop, styleProps, getStylesLiterals, propToVariantKeys, sourceFile) => {
|
|
84
|
+
const spreadExpr = prop.getExpression();
|
|
85
|
+
if (ts_morph.Node.isParenthesizedExpression(spreadExpr)) {
|
|
86
|
+
const conditionalExpr = spreadExpr.getExpression();
|
|
87
|
+
if (ts_morph.Node.isConditionalExpression(conditionalExpr)) {
|
|
88
|
+
const whenTrue = conditionalExpr.getWhenTrue();
|
|
89
|
+
if (!ts_morph.Node.isObjectLiteralExpression(whenTrue)) return;
|
|
90
|
+
analyzeObjectForVariantMappings(whenTrue, styleProps, getStylesLiterals, propToVariantKeys, sourceFile);
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
|
-
|
|
93
|
+
if (ts_morph.Node.isIdentifier(spreadExpr)) {
|
|
94
|
+
const objectLiteral = findVariableObjectLiteral(sourceFile, spreadExpr.getText());
|
|
95
|
+
if (objectLiteral) analyzeObjectForVariantMappings(objectLiteral, styleProps, getStylesLiterals, propToVariantKeys, sourceFile);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
93
98
|
/**
|
|
94
99
|
* Analyzes a UDS component file to extract:
|
|
95
100
|
* 1. Default prop values (e.g., display = 'flex')
|
|
96
101
|
* 2. Props passed to getStyles()
|
|
97
102
|
* 3. Internal UDS component usage
|
|
98
103
|
*/
|
|
99
|
-
|
|
104
|
+
const analyzeComponent = (project, componentPath) => {
|
|
100
105
|
const sourceFile = project.getSourceFile(componentPath);
|
|
101
106
|
if (!sourceFile) return null;
|
|
102
107
|
const componentName = node_path.default.basename(componentPath, ".tsx");
|
|
@@ -108,98 +113,9 @@ function analyzeComponent(project, componentPath) {
|
|
|
108
113
|
const internalComponents = [];
|
|
109
114
|
const internalComponentProps = /* @__PURE__ */ new Map();
|
|
110
115
|
const propToVariantKeys = /* @__PURE__ */ new Map();
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
})];
|
|
115
|
-
for (const fn of functions) {
|
|
116
|
-
if (ts_morph.Node.isVariableDeclaration(fn)) {
|
|
117
|
-
const init = fn.getInitializer();
|
|
118
|
-
if (!init) continue;
|
|
119
|
-
if (ts_morph.Node.isCallExpression(init)) {
|
|
120
|
-
const args = init.getArguments();
|
|
121
|
-
for (const arg of args) if (ts_morph.Node.isFunctionExpression(arg) || ts_morph.Node.isArrowFunction(arg)) {
|
|
122
|
-
extractDefaultsFromFunction(arg, defaultProps);
|
|
123
|
-
extractAllPropNames(arg, componentPropNames);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
if (ts_morph.Node.isArrowFunction(init)) {
|
|
127
|
-
extractDefaultsFromFunction(init, defaultProps);
|
|
128
|
-
extractAllPropNames(init, componentPropNames);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (ts_morph.Node.isFunctionDeclaration(fn)) {
|
|
132
|
-
extractDefaultsFromFunction(fn, defaultProps);
|
|
133
|
-
extractAllPropNames(fn, componentPropNames);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
const getStylesCalls = sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.CallExpression).filter((call) => call.getExpression().getText() === "getStyles");
|
|
137
|
-
for (const call of getStylesCalls) {
|
|
138
|
-
const args = call.getArguments();
|
|
139
|
-
if (args.length > 0 && ts_morph.Node.isObjectLiteralExpression(args[0])) {
|
|
140
|
-
const objLiteral = args[0];
|
|
141
|
-
for (const prop of objLiteral.getProperties()) if (ts_morph.Node.isPropertyAssignment(prop)) {
|
|
142
|
-
const variantKey = prop.getName();
|
|
143
|
-
if (variantKey && !styleProps.includes(variantKey)) styleProps.push(variantKey);
|
|
144
|
-
const initializer = prop.getInitializer();
|
|
145
|
-
if (initializer && ts_morph.Node.isStringLiteral(initializer)) getStylesLiterals.set(variantKey, initializer.getLiteralValue());
|
|
146
|
-
if (initializer && ts_morph.Node.isIdentifier(initializer)) {
|
|
147
|
-
const propName = initializer.getText();
|
|
148
|
-
const existing = propToVariantKeys.get(propName) ?? [];
|
|
149
|
-
if (!existing.includes(variantKey)) {
|
|
150
|
-
existing.push(variantKey);
|
|
151
|
-
propToVariantKeys.set(propName, existing);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (initializer && ts_morph.Node.isBinaryExpression(initializer)) {
|
|
155
|
-
const operatorToken = initializer.getOperatorToken();
|
|
156
|
-
if (operatorToken.getKind() === ts_morph.SyntaxKind.QuestionQuestionToken || operatorToken.getKind() === ts_morph.SyntaxKind.BarBarToken) {
|
|
157
|
-
const rightSide = initializer.getRight();
|
|
158
|
-
if (ts_morph.Node.isIdentifier(rightSide)) {
|
|
159
|
-
const fallbackPropName = rightSide.getText();
|
|
160
|
-
const existing = propToVariantKeys.get(fallbackPropName) ?? [];
|
|
161
|
-
if (!existing.includes(variantKey)) {
|
|
162
|
-
existing.push(variantKey);
|
|
163
|
-
propToVariantKeys.set(fallbackPropName, existing);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (initializer && ts_morph.Node.isConditionalExpression(initializer)) {
|
|
169
|
-
const whenTrue = initializer.getWhenTrue();
|
|
170
|
-
const whenFalse = initializer.getWhenFalse();
|
|
171
|
-
const extractLiterals = (node) => {
|
|
172
|
-
const literals = [];
|
|
173
|
-
if (ts_morph.Node.isStringLiteral(node)) literals.push(node.getLiteralValue());
|
|
174
|
-
else if (ts_morph.Node.isConditionalExpression(node)) {
|
|
175
|
-
literals.push(...extractLiterals(node.getWhenTrue()));
|
|
176
|
-
literals.push(...extractLiterals(node.getWhenFalse()));
|
|
177
|
-
}
|
|
178
|
-
return literals;
|
|
179
|
-
};
|
|
180
|
-
[...extractLiterals(whenTrue), ...extractLiterals(whenFalse)].forEach((value, index) => {
|
|
181
|
-
const literalKey = index === 0 ? variantKey : `${variantKey}:${index}`;
|
|
182
|
-
getStylesLiterals.set(literalKey, value);
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
} else if (ts_morph.Node.isShorthandPropertyAssignment(prop)) {
|
|
186
|
-
const propName = prop.getName();
|
|
187
|
-
if (propName && !styleProps.includes(propName)) styleProps.push(propName);
|
|
188
|
-
} else if (ts_morph.Node.isSpreadAssignment(prop)) {
|
|
189
|
-
const spreadExpr = prop.getExpression();
|
|
190
|
-
if (ts_morph.Node.isIdentifier(spreadExpr)) {
|
|
191
|
-
const varName = spreadExpr.getText();
|
|
192
|
-
const varDecl = sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.VariableDeclaration).find((v) => v.getName() === varName);
|
|
193
|
-
if (varDecl) {
|
|
194
|
-
const varInit = varDecl.getInitializer();
|
|
195
|
-
if (varInit && ts_morph.Node.isObjectLiteralExpression(varInit)) analyzeObjectForVariantMappings(varInit, styleProps, getStylesLiterals, propToVariantKeys, sourceFile);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
const cxCalls = sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.CallExpression).filter((call) => call.getExpression().getText() === "cx");
|
|
202
|
-
for (const call of cxCalls) for (const arg of call.getArguments()) extractCxStringLiterals(arg, cxLiterals);
|
|
116
|
+
collectComponentDefaultsAndProps(sourceFile, defaultProps, componentPropNames);
|
|
117
|
+
collectGetStylesMetadata(sourceFile, styleProps, getStylesLiterals, propToVariantKeys);
|
|
118
|
+
collectCxLiterals(sourceFile, cxLiterals);
|
|
203
119
|
extractInternalComponents(sourceFile, internalComponents, internalComponentProps, propToVariantKeys, componentPropNames);
|
|
204
120
|
return {
|
|
205
121
|
name: componentName,
|
|
@@ -213,96 +129,194 @@ function analyzeComponent(project, componentPath) {
|
|
|
213
129
|
propToVariantKeys,
|
|
214
130
|
motionVarPrefixes: extractMotionVarPrefixes(sourceFile)
|
|
215
131
|
};
|
|
216
|
-
}
|
|
132
|
+
};
|
|
133
|
+
const getComponentFunctionNodes = (sourceFile) => [...sourceFile.getFunctions(), ...sourceFile.getVariableDeclarations().filter((declaration) => {
|
|
134
|
+
const initializer = declaration.getInitializer();
|
|
135
|
+
return initializer && (ts_morph.Node.isArrowFunction(initializer) || ts_morph.Node.isCallExpression(initializer));
|
|
136
|
+
})];
|
|
137
|
+
const collectComponentDefaultsAndProps = (sourceFile, defaultProps, componentPropNames) => {
|
|
138
|
+
getComponentFunctionNodes(sourceFile).forEach((fn) => {
|
|
139
|
+
if (ts_morph.Node.isFunctionDeclaration(fn)) {
|
|
140
|
+
extractDefaultsFromFunction(fn, defaultProps);
|
|
141
|
+
extractAllPropNames(fn, componentPropNames);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (!ts_morph.Node.isVariableDeclaration(fn)) return;
|
|
145
|
+
const initializer = fn.getInitializer();
|
|
146
|
+
if (!initializer) return;
|
|
147
|
+
if (ts_morph.Node.isCallExpression(initializer)) initializer.getArguments().forEach((arg) => {
|
|
148
|
+
if (ts_morph.Node.isFunctionExpression(arg) || ts_morph.Node.isArrowFunction(arg)) {
|
|
149
|
+
extractDefaultsFromFunction(arg, defaultProps);
|
|
150
|
+
extractAllPropNames(arg, componentPropNames);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
if (ts_morph.Node.isArrowFunction(initializer)) {
|
|
154
|
+
extractDefaultsFromFunction(initializer, defaultProps);
|
|
155
|
+
extractAllPropNames(initializer, componentPropNames);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
const extractConditionalStringLiterals = (node) => {
|
|
160
|
+
if (ts_morph.Node.isStringLiteral(node)) return [node.getLiteralValue()];
|
|
161
|
+
if (ts_morph.Node.isConditionalExpression(node)) return [...extractConditionalStringLiterals(node.getWhenTrue()), ...extractConditionalStringLiterals(node.getWhenFalse())];
|
|
162
|
+
return [];
|
|
163
|
+
};
|
|
164
|
+
const storeVariantLiteralValues = (variantKey, literalValues, getStylesLiterals) => {
|
|
165
|
+
literalValues.forEach((value, index) => {
|
|
166
|
+
const literalKey = index === 0 ? variantKey : `${variantKey}:${index}`;
|
|
167
|
+
getStylesLiterals.set(literalKey, value);
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
const handleGetStylesPropertyAssignment = (prop, styleProps, getStylesLiterals, propToVariantKeys) => {
|
|
171
|
+
const variantKey = prop.getName();
|
|
172
|
+
addStyleProp(styleProps, variantKey);
|
|
173
|
+
const initializer = prop.getInitializer();
|
|
174
|
+
if (!initializer) return;
|
|
175
|
+
if (ts_morph.Node.isStringLiteral(initializer)) getStylesLiterals.set(variantKey, initializer.getLiteralValue());
|
|
176
|
+
if (ts_morph.Node.isIdentifier(initializer)) addPropToVariantKeyMapping(propToVariantKeys, initializer.getText(), variantKey);
|
|
177
|
+
const fallbackIdentifier = extractFallbackIdentifier(initializer);
|
|
178
|
+
if (fallbackIdentifier) addPropToVariantKeyMapping(propToVariantKeys, fallbackIdentifier, variantKey);
|
|
179
|
+
if (ts_morph.Node.isConditionalExpression(initializer)) storeVariantLiteralValues(variantKey, [...extractConditionalStringLiterals(initializer.getWhenTrue()), ...extractConditionalStringLiterals(initializer.getWhenFalse())], getStylesLiterals);
|
|
180
|
+
};
|
|
181
|
+
const handleGetStylesObjectProperty = (prop, styleProps, getStylesLiterals, propToVariantKeys, sourceFile) => {
|
|
182
|
+
if (ts_morph.Node.isPropertyAssignment(prop)) {
|
|
183
|
+
handleGetStylesPropertyAssignment(prop, styleProps, getStylesLiterals, propToVariantKeys);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (ts_morph.Node.isShorthandPropertyAssignment(prop)) {
|
|
187
|
+
addStyleProp(styleProps, prop.getName());
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (ts_morph.Node.isSpreadAssignment(prop) && ts_morph.Node.isIdentifier(prop.getExpression())) {
|
|
191
|
+
const objectLiteral = findVariableObjectLiteral(sourceFile, prop.getExpression().getText());
|
|
192
|
+
if (objectLiteral) analyzeObjectForVariantMappings(objectLiteral, styleProps, getStylesLiterals, propToVariantKeys, sourceFile);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
const collectGetStylesMetadata = (sourceFile, styleProps, getStylesLiterals, propToVariantKeys) => {
|
|
196
|
+
sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.CallExpression).filter((call) => call.getExpression().getText() === "getStyles").forEach((call) => {
|
|
197
|
+
const args = call.getArguments();
|
|
198
|
+
if (args.length === 0 || !ts_morph.Node.isObjectLiteralExpression(args[0])) return;
|
|
199
|
+
args[0].getProperties().forEach((prop) => {
|
|
200
|
+
handleGetStylesObjectProperty(prop, styleProps, getStylesLiterals, propToVariantKeys, sourceFile);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
const collectCxLiterals = (sourceFile, cxLiterals) => {
|
|
205
|
+
sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.CallExpression).filter((call) => call.getExpression().getText() === "cx").forEach((call) => {
|
|
206
|
+
call.getArguments().forEach((arg) => extractCxStringLiterals(arg, cxLiterals));
|
|
207
|
+
});
|
|
208
|
+
};
|
|
217
209
|
/**
|
|
218
210
|
* Extract UDS components used internally in the file and their prop values.
|
|
219
211
|
* Also detects prop aliasing (e.g., columnGap={gap} means gap -> columnGap).
|
|
220
212
|
*/
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
213
|
+
const extractInternalComponents = (sourceFile, internalComponents, internalComponentProps, propToVariantKeys, componentProps) => {
|
|
214
|
+
collectImportedInternalComponents(sourceFile, internalComponents);
|
|
215
|
+
collectInternalComponentUsages(sourceFile, internalComponents, internalComponentProps, propToVariantKeys, componentProps);
|
|
216
|
+
};
|
|
217
|
+
const isInternalUdsModule = (moduleSpec) => {
|
|
218
|
+
return (moduleSpec.startsWith("@yahoo/uds") || moduleSpec.startsWith("../") || moduleSpec.startsWith("./")) && (moduleSpec.includes("/components/") || moduleSpec === "@yahoo/uds");
|
|
219
|
+
};
|
|
220
|
+
const pushUniqueComponentName = (components, name) => {
|
|
221
|
+
if (/^[A-Z]/.test(name) && !components.includes(name)) components.push(name);
|
|
222
|
+
};
|
|
223
|
+
const collectImportedInternalComponents = (sourceFile, internalComponents) => {
|
|
224
|
+
sourceFile.getImportDeclarations().forEach((importDecl) => {
|
|
225
|
+
if (!isInternalUdsModule(importDecl.getModuleSpecifierValue())) return;
|
|
226
|
+
importDecl.getNamedImports().forEach((namedImport) => pushUniqueComponentName(internalComponents, namedImport.getName()));
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
const getOrCreateComponentPropsMap = (internalComponentProps, componentName) => {
|
|
230
|
+
const existing = internalComponentProps.get(componentName);
|
|
231
|
+
if (existing) return existing;
|
|
232
|
+
const created = /* @__PURE__ */ new Map();
|
|
233
|
+
internalComponentProps.set(componentName, created);
|
|
234
|
+
return created;
|
|
235
|
+
};
|
|
236
|
+
const extractJsxAttributeLiteralValues = (attr, componentProps, propToVariantKeys) => {
|
|
237
|
+
if (!ts_morph.Node.isJsxAttribute(attr)) return null;
|
|
238
|
+
const propName = attr.getNameNode().getText();
|
|
239
|
+
const initializer = attr.getInitializer();
|
|
240
|
+
if (!initializer) return {
|
|
241
|
+
propName,
|
|
242
|
+
values: []
|
|
243
|
+
};
|
|
244
|
+
if (ts_morph.Node.isStringLiteral(initializer)) return {
|
|
245
|
+
propName,
|
|
246
|
+
values: [initializer.getLiteralValue()]
|
|
247
|
+
};
|
|
248
|
+
if (!ts_morph.Node.isJsxExpression(initializer)) return {
|
|
249
|
+
propName,
|
|
250
|
+
values: []
|
|
251
|
+
};
|
|
252
|
+
const expr = initializer.getExpression();
|
|
253
|
+
if (expr && ts_morph.Node.isStringLiteral(expr)) return {
|
|
254
|
+
propName,
|
|
255
|
+
values: [expr.getLiteralValue()]
|
|
256
|
+
};
|
|
257
|
+
if (expr && ts_morph.Node.isIdentifier(expr)) {
|
|
258
|
+
const identifierName = expr.getText();
|
|
259
|
+
if (componentProps.has(identifierName) && identifierName !== propName) addPropToVariantKeyMapping(propToVariantKeys, identifierName, propName);
|
|
230
260
|
}
|
|
231
|
-
|
|
232
|
-
|
|
261
|
+
return {
|
|
262
|
+
propName,
|
|
263
|
+
values: []
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
const collectInternalComponentUsages = (sourceFile, internalComponents, internalComponentProps, propToVariantKeys, componentProps) => {
|
|
267
|
+
[...sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.JsxSelfClosingElement), ...sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.JsxOpeningElement)].forEach((element) => {
|
|
233
268
|
const tagName = element.getTagNameNode().getText();
|
|
234
|
-
if (!/^[A-Z]/.test(tagName))
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
else if (expr && ts_morph.Node.isIdentifier(expr)) {
|
|
247
|
-
const identifierName = expr.getText();
|
|
248
|
-
if (componentProps.has(identifierName) && identifierName !== propName) {
|
|
249
|
-
const existing = propToVariantKeys.get(identifierName) ?? [];
|
|
250
|
-
if (!existing.includes(propName)) {
|
|
251
|
-
existing.push(propName);
|
|
252
|
-
propToVariantKeys.set(identifierName, existing);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
if (values.length > 0) {
|
|
259
|
-
let componentPropsMap = internalComponentProps.get(tagName);
|
|
260
|
-
if (!componentPropsMap) {
|
|
261
|
-
componentPropsMap = /* @__PURE__ */ new Map();
|
|
262
|
-
internalComponentProps.set(tagName, componentPropsMap);
|
|
263
|
-
}
|
|
264
|
-
const existingValues = componentPropsMap.get(propName) ?? [];
|
|
265
|
-
for (const v of values) if (!existingValues.includes(v)) existingValues.push(v);
|
|
266
|
-
componentPropsMap.set(propName, existingValues);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
269
|
+
if (!/^[A-Z]/.test(tagName)) return;
|
|
270
|
+
pushUniqueComponentName(internalComponents, tagName);
|
|
271
|
+
element.getAttributes().forEach((attr) => {
|
|
272
|
+
const extracted = extractJsxAttributeLiteralValues(attr, componentProps, propToVariantKeys);
|
|
273
|
+
if (!extracted || extracted.values.length === 0) return;
|
|
274
|
+
const componentPropsMap = getOrCreateComponentPropsMap(internalComponentProps, tagName);
|
|
275
|
+
const existingValues = componentPropsMap.get(extracted.propName) ?? [];
|
|
276
|
+
const mergedValues = [...new Set([...existingValues, ...extracted.values])];
|
|
277
|
+
componentPropsMap.set(extracted.propName, mergedValues);
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
};
|
|
271
281
|
/**
|
|
272
282
|
* Extract default prop values from a function's parameter destructuring
|
|
273
283
|
*/
|
|
274
|
-
|
|
284
|
+
const extractDefaultsFromFunction = (fn, defaults) => {
|
|
275
285
|
let params = [];
|
|
276
286
|
if (ts_morph.Node.isFunctionDeclaration(fn) || ts_morph.Node.isFunctionExpression(fn)) params = fn.getParameters();
|
|
277
287
|
else if (ts_morph.Node.isArrowFunction(fn)) params = fn.getParameters();
|
|
278
|
-
|
|
279
|
-
if (!ts_morph.Node.isParameterDeclaration(param))
|
|
288
|
+
params.forEach((param) => {
|
|
289
|
+
if (!ts_morph.Node.isParameterDeclaration(param)) return;
|
|
280
290
|
const nameNode = param.getNameNode();
|
|
281
|
-
if (!nameNode || !ts_morph.Node.isObjectBindingPattern(nameNode))
|
|
282
|
-
|
|
291
|
+
if (!nameNode || !ts_morph.Node.isObjectBindingPattern(nameNode)) return;
|
|
292
|
+
nameNode.getElements().forEach((element) => {
|
|
283
293
|
const propName = element.getPropertyNameNode()?.getText() || element.getName();
|
|
284
294
|
const initializer = element.getInitializer();
|
|
285
295
|
if (initializer && ts_morph.Node.isStringLiteral(initializer)) defaults.set(propName, initializer.getLiteralValue());
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
296
|
+
else if (initializer && ts_morph.Node.isIdentifier(initializer)) {
|
|
297
|
+
const resolved = resolveIdentifierToStringLiteral(initializer);
|
|
298
|
+
if (resolved) defaults.set(propName, resolved);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
};
|
|
289
303
|
/**
|
|
290
304
|
* Extract ALL prop names from a function's parameter destructuring (not just defaults)
|
|
291
305
|
*/
|
|
292
|
-
|
|
306
|
+
const extractAllPropNames = (fn, propNames) => {
|
|
293
307
|
let params = [];
|
|
294
308
|
if (ts_morph.Node.isFunctionDeclaration(fn) || ts_morph.Node.isFunctionExpression(fn)) params = fn.getParameters();
|
|
295
309
|
else if (ts_morph.Node.isArrowFunction(fn)) params = fn.getParameters();
|
|
296
|
-
|
|
297
|
-
if (!ts_morph.Node.isParameterDeclaration(param))
|
|
310
|
+
params.forEach((param) => {
|
|
311
|
+
if (!ts_morph.Node.isParameterDeclaration(param)) return;
|
|
298
312
|
const nameNode = param.getNameNode();
|
|
299
|
-
if (!nameNode || !ts_morph.Node.isObjectBindingPattern(nameNode))
|
|
300
|
-
|
|
313
|
+
if (!nameNode || !ts_morph.Node.isObjectBindingPattern(nameNode)) return;
|
|
314
|
+
nameNode.getElements().forEach((element) => {
|
|
301
315
|
const propName = element.getPropertyNameNode()?.getText() || element.getName();
|
|
302
316
|
propNames.add(propName);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
};
|
|
306
320
|
/**
|
|
307
321
|
* Extract string literals from cx() call arguments.
|
|
308
322
|
* Handles:
|
|
@@ -310,22 +324,25 @@ function extractAllPropNames(fn, propNames) {
|
|
|
310
324
|
* - Object keys: cx({ 'class1': condition, 'class2': true })
|
|
311
325
|
* - Nested calls and arrays
|
|
312
326
|
*/
|
|
313
|
-
|
|
314
|
-
if (ts_morph.Node.isStringLiteral(node)) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
327
|
+
const extractCxStringLiterals = (node, literals) => {
|
|
328
|
+
if (ts_morph.Node.isStringLiteral(node)) node.getLiteralValue().split(/\s+/).filter(Boolean).forEach((cls) => {
|
|
329
|
+
if (!literals.includes(cls)) literals.push(cls);
|
|
330
|
+
});
|
|
331
|
+
else if (ts_morph.Node.isObjectLiteralExpression(node)) node.getProperties().forEach((prop) => {
|
|
332
|
+
if (ts_morph.Node.isPropertyAssignment(prop)) {
|
|
319
333
|
const nameNode = prop.getNameNode();
|
|
320
|
-
if (ts_morph.Node.isStringLiteral(nameNode)) {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
334
|
+
if (ts_morph.Node.isStringLiteral(nameNode)) nameNode.getLiteralValue().split(/\s+/).filter(Boolean).forEach((cls) => {
|
|
335
|
+
if (!literals.includes(cls)) literals.push(cls);
|
|
336
|
+
});
|
|
337
|
+
else if (ts_morph.Node.isIdentifier(nameNode)) {
|
|
324
338
|
const cls = nameNode.getText();
|
|
325
339
|
if (!literals.includes(cls)) literals.push(cls);
|
|
326
340
|
}
|
|
327
341
|
}
|
|
328
|
-
}
|
|
342
|
+
});
|
|
343
|
+
else if (ts_morph.Node.isArrayLiteralExpression(node)) node.getElements().forEach((element) => {
|
|
344
|
+
extractCxStringLiterals(element, literals);
|
|
345
|
+
});
|
|
329
346
|
else if (ts_morph.Node.isConditionalExpression(node)) {
|
|
330
347
|
extractCxStringLiterals(node.getWhenTrue(), literals);
|
|
331
348
|
extractCxStringLiterals(node.getWhenFalse(), literals);
|
|
@@ -333,59 +350,54 @@ function extractCxStringLiterals(node, literals) {
|
|
|
333
350
|
extractCxStringLiterals(node.getLeft(), literals);
|
|
334
351
|
extractCxStringLiterals(node.getRight(), literals);
|
|
335
352
|
}
|
|
336
|
-
}
|
|
353
|
+
};
|
|
337
354
|
/**
|
|
338
355
|
* Try to resolve an identifier to its initializer value (for const declarations)
|
|
339
356
|
*/
|
|
340
|
-
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
357
|
-
return null;
|
|
358
|
-
}
|
|
357
|
+
const resolveIdentifierToObject = (sourceFile, identifier) => {
|
|
358
|
+
const decl = sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.VariableDeclaration).find((candidate) => candidate.getName() === identifier);
|
|
359
|
+
if (!decl) return null;
|
|
360
|
+
let initializer = decl.getInitializer();
|
|
361
|
+
if (!initializer) return null;
|
|
362
|
+
if (ts_morph.Node.isAsExpression(initializer)) initializer = initializer.getExpression();
|
|
363
|
+
if (!ts_morph.Node.isObjectLiteralExpression(initializer)) return null;
|
|
364
|
+
const result = {};
|
|
365
|
+
initializer.getProperties().forEach((prop) => {
|
|
366
|
+
if (!ts_morph.Node.isPropertyAssignment(prop)) return;
|
|
367
|
+
const propName = prop.getName();
|
|
368
|
+
const propInit = prop.getInitializer();
|
|
369
|
+
if (propInit && ts_morph.Node.isStringLiteral(propInit)) result[propName] = propInit.getLiteralValue();
|
|
370
|
+
});
|
|
371
|
+
return result;
|
|
372
|
+
};
|
|
359
373
|
/**
|
|
360
374
|
* Extract motion CSS variable prefixes from SpringMotionConfig usage.
|
|
361
375
|
* Returns prefixes like ['--uds-motion-bouncy-4-', '--uds-motion-smooth-3-']
|
|
362
376
|
*/
|
|
363
|
-
|
|
377
|
+
const extractMotionVarPrefixes = (sourceFile) => {
|
|
364
378
|
const prefixes = [];
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
if (element.getTagNameNode().getText() !== "SpringMotionConfig") continue;
|
|
379
|
+
[...sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.JsxSelfClosingElement), ...sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.JsxOpeningElement)].forEach((element) => {
|
|
380
|
+
if (element.getTagNameNode().getText() !== "SpringMotionConfig") return;
|
|
368
381
|
const props = {
|
|
369
382
|
layoutVariant: null,
|
|
370
383
|
layoutSpeed: null,
|
|
371
384
|
colorVariant: null,
|
|
372
385
|
colorSpeed: null
|
|
373
386
|
};
|
|
374
|
-
|
|
375
|
-
for (const attr of attrs) {
|
|
387
|
+
element.getAttributes().forEach((attr) => {
|
|
376
388
|
if (ts_morph.Node.isJsxSpreadAttribute(attr)) {
|
|
377
389
|
const expr = attr.getExpression();
|
|
378
390
|
if (ts_morph.Node.isIdentifier(expr)) {
|
|
379
391
|
const spreadObj = resolveIdentifierToObject(sourceFile, expr.getText());
|
|
380
|
-
if (spreadObj) {
|
|
381
|
-
|
|
382
|
-
}
|
|
392
|
+
if (spreadObj) Object.keys(props).forEach((key) => {
|
|
393
|
+
if (key in spreadObj) props[key] = spreadObj[key];
|
|
394
|
+
});
|
|
383
395
|
}
|
|
384
|
-
|
|
396
|
+
return;
|
|
385
397
|
}
|
|
386
|
-
if (!ts_morph.Node.isJsxAttribute(attr))
|
|
398
|
+
if (!ts_morph.Node.isJsxAttribute(attr)) return;
|
|
387
399
|
const propName = attr.getNameNode().getText();
|
|
388
|
-
if (!(propName in props))
|
|
400
|
+
if (!(propName in props)) return;
|
|
389
401
|
const initializer = attr.getInitializer();
|
|
390
402
|
if (initializer) {
|
|
391
403
|
if (ts_morph.Node.isStringLiteral(initializer)) props[propName] = initializer.getLiteralValue();
|
|
@@ -394,14 +406,64 @@ function extractMotionVarPrefixes(sourceFile) {
|
|
|
394
406
|
if (expr && ts_morph.Node.isStringLiteral(expr)) props[propName] = expr.getLiteralValue();
|
|
395
407
|
}
|
|
396
408
|
}
|
|
397
|
-
}
|
|
409
|
+
});
|
|
398
410
|
const layoutPrefix = `--uds-motion-${props.layoutVariant ?? require_index.SPRING_MOTION_DEFAULTS.layoutVariant}-${props.layoutSpeed ?? require_index.SPRING_MOTION_DEFAULTS.layoutSpeed}-`;
|
|
399
411
|
if (!prefixes.includes(layoutPrefix)) prefixes.push(layoutPrefix);
|
|
400
412
|
const colorPrefix = `--uds-motion-${props.colorVariant ?? require_index.SPRING_MOTION_DEFAULTS.colorVariant}-${props.colorSpeed ?? require_index.SPRING_MOTION_DEFAULTS.colorSpeed}-`;
|
|
401
413
|
if (!prefixes.includes(colorPrefix)) prefixes.push(colorPrefix);
|
|
402
|
-
}
|
|
414
|
+
});
|
|
403
415
|
return prefixes;
|
|
404
|
-
}
|
|
416
|
+
};
|
|
417
|
+
const resolveIdentifierToStringLiteral = (identifier) => {
|
|
418
|
+
if (!ts_morph.Node.isIdentifier(identifier)) return null;
|
|
419
|
+
const symbol = identifier.getSymbol();
|
|
420
|
+
if (!symbol) return resolveImportedIdentifier(identifier);
|
|
421
|
+
const resolvedDeclarationValue = symbol.getDeclarations().reduce((resolved, declaration) => {
|
|
422
|
+
if (resolved) return resolved;
|
|
423
|
+
if (ts_morph.Node.isVariableDeclaration(declaration)) {
|
|
424
|
+
let initializer = declaration.getInitializer();
|
|
425
|
+
if (initializer && ts_morph.Node.isAsExpression(initializer)) initializer = initializer.getExpression();
|
|
426
|
+
if (initializer && ts_morph.Node.isStringLiteral(initializer)) return initializer.getLiteralValue();
|
|
427
|
+
}
|
|
428
|
+
if (ts_morph.Node.isEnumMember(declaration)) {
|
|
429
|
+
const initializer = declaration.getInitializer();
|
|
430
|
+
if (initializer && ts_morph.Node.isStringLiteral(initializer)) return initializer.getLiteralValue();
|
|
431
|
+
}
|
|
432
|
+
}, void 0);
|
|
433
|
+
if (resolvedDeclarationValue) return resolvedDeclarationValue;
|
|
434
|
+
return resolveImportedIdentifier(identifier);
|
|
435
|
+
};
|
|
436
|
+
const resolveImportedIdentifier = (identifier) => {
|
|
437
|
+
if (!ts_morph.Node.isIdentifier(identifier)) return null;
|
|
438
|
+
const name = identifier.getText();
|
|
439
|
+
const sourceFile = identifier.getSourceFile();
|
|
440
|
+
const project = sourceFile.getProject();
|
|
441
|
+
const baseDir = node_path.default.dirname(sourceFile.getFilePath());
|
|
442
|
+
const importResolution = sourceFile.getImportDeclarations().reduce((resolvedImport, importDecl) => {
|
|
443
|
+
if (resolvedImport) return resolvedImport;
|
|
444
|
+
if (!importDecl.getNamedImports().find((n) => n.getName() === name)) return;
|
|
445
|
+
const moduleSpec = importDecl.getModuleSpecifierValue();
|
|
446
|
+
if (!moduleSpec.startsWith(".")) return;
|
|
447
|
+
const resolvedBase = node_path.default.resolve(baseDir, moduleSpec);
|
|
448
|
+
return [
|
|
449
|
+
resolvedBase,
|
|
450
|
+
`${resolvedBase}.ts`,
|
|
451
|
+
`${resolvedBase}.tsx`
|
|
452
|
+
].reduce((resolvedCandidate, candidate) => {
|
|
453
|
+
if (resolvedCandidate) return resolvedCandidate;
|
|
454
|
+
if (!(0, node_fs.existsSync)(candidate)) return;
|
|
455
|
+
const importedFile = project.addSourceFileAtPathIfExists(candidate);
|
|
456
|
+
if (!importedFile) return;
|
|
457
|
+
const varDecl = importedFile.getVariableDeclaration(name);
|
|
458
|
+
if (!varDecl) return;
|
|
459
|
+
let initializer = varDecl.getInitializer();
|
|
460
|
+
if (initializer && ts_morph.Node.isAsExpression(initializer)) initializer = initializer.getExpression();
|
|
461
|
+
return initializer && ts_morph.Node.isStringLiteral(initializer) ? initializer.getLiteralValue() : void 0;
|
|
462
|
+
}, void 0);
|
|
463
|
+
}, void 0);
|
|
464
|
+
if (importResolution) return importResolution;
|
|
465
|
+
return null;
|
|
466
|
+
};
|
|
405
467
|
|
|
406
468
|
//#endregion
|
|
407
469
|
exports.analyzeComponent = analyzeComponent;
|