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