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