@yahoo/uds 3.114.0 → 3.115.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/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/commands/editor-rules.cjs +1 -1
- package/dist/cli/dist/commands/editor-rules.js +1 -1
- package/dist/cli/dist/lib/logger.cjs +66 -0
- package/dist/cli/dist/lib/logger.js +66 -0
- package/dist/cli/runner.cjs +9 -0
- package/dist/cli/runner.js +9 -0
- 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 +29 -29
- package/dist/styles/styler.d.ts +29 -29
- 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.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/purge.cjs +3 -4
- package/dist/tailwind/dist/commands/purge.js +3 -4
- package/dist/tailwind/dist/css/generate.cjs +121 -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 +116 -0
- package/dist/tailwind/dist/css/nodeUtils.cjs +156 -0
- package/dist/tailwind/dist/css/nodeUtils.js +149 -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 +279 -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 +276 -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 +72 -0
- package/dist/tailwind/dist/css/utils.js +69 -0
- package/dist/tailwind/dist/index.d.cts +1 -0
- package/dist/tailwind/dist/index.d.ts +2 -4
- package/dist/tailwind/dist/purger/legacy/purgeCSS.cjs +2 -1
- package/dist/tailwind/dist/purger/legacy/purgeCSS.js +2 -1
- 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 +9 -8
- package/dist/tailwind/dist/purger/optimized/purge.js +9 -8
- package/dist/tailwind/dist/purger/optimized/purgeFromCode.cjs +238 -127
- package/dist/tailwind/dist/purger/optimized/purgeFromCode.js +238 -127
- package/dist/tailwind/dist/purger/optimized/utils/componentAnalyzer.cjs +352 -260
- package/dist/tailwind/dist/purger/optimized/utils/componentAnalyzer.js +351 -260
- 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 +12 -20
- package/dist/tailwind/dist/purger/optimized/utils/safelist.js +12 -20
- package/dist/tailwind/dist/tailwind/components/getResponsiveTextStyles.cjs +1 -1
- package/dist/tailwind/dist/tailwind/components/getResponsiveTextStyles.js +1 -1
- package/dist/tailwind/dist/tailwind/plugins/breakpoints.cjs +1 -1
- package/dist/tailwind/dist/tailwind/plugins/breakpoints.js +1 -1
- 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/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 +1218 -1182
- package/dist/uds/generated/componentData.js +1218 -1182
- package/dist/uds/package.cjs +10 -4
- package/dist/uds/package.js +10 -4
- package/generated/componentData.json +2683 -0
- package/generated/tailwindPurge.ts +4591 -0
- package/package.json +7 -4
- package/dist/tailwind/dist/commands/generatePurgeCSSData.d.ts +0 -3
- package/dist/tailwind/dist/commands/purge.d.ts +0 -4
- package/dist/tailwind/dist/purger/legacy/purgeCSS.d.ts +0 -2
|
@@ -20,174 +20,171 @@ let ts_morph = require("ts-morph");
|
|
|
20
20
|
* @param visited Set of visited nodes to prevent infinite recursion
|
|
21
21
|
* @returns Array of extracted string literal values
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
const extractStringLiterals = (node, visited = /* @__PURE__ */ new Set()) => {
|
|
24
24
|
if (visited.has(node)) return [];
|
|
25
25
|
visited.add(node);
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (typeof propValue === "string") values.push(propValue);
|
|
68
|
-
}
|
|
69
|
-
return values;
|
|
70
|
-
}
|
|
71
|
-
if (ts_morph.Node.isElementAccessExpression(node)) {
|
|
72
|
-
const typeValues = extractLiteralValuesFromType(node);
|
|
73
|
-
if (typeValues.length > 0) {
|
|
74
|
-
values.push(...typeValues);
|
|
75
|
-
return values;
|
|
76
|
-
}
|
|
77
|
-
return values;
|
|
26
|
+
const directValues = extractDirectLiteralValues(node);
|
|
27
|
+
if (directValues) return directValues;
|
|
28
|
+
const templateValues = extractTemplateExpressionValues(node, visited);
|
|
29
|
+
if (templateValues) return templateValues;
|
|
30
|
+
if (ts_morph.Node.isConditionalExpression(node)) return [...extractStringLiterals(node.getWhenTrue(), visited), ...extractStringLiterals(node.getWhenFalse(), visited)];
|
|
31
|
+
const binaryValues = extractBinaryExpressionValues(node, visited);
|
|
32
|
+
if (binaryValues) return binaryValues;
|
|
33
|
+
const wrappedExpressionValues = extractWrappedExpressionValues(node, visited);
|
|
34
|
+
if (wrappedExpressionValues) return wrappedExpressionValues;
|
|
35
|
+
const propertyAccessValues = extractPropertyAccessValues(node, visited);
|
|
36
|
+
if (propertyAccessValues) return propertyAccessValues;
|
|
37
|
+
const elementAccessValues = extractElementAccessValues(node);
|
|
38
|
+
if (elementAccessValues) return elementAccessValues;
|
|
39
|
+
const callExpressionValues = extractCallExpressionValues(node, visited);
|
|
40
|
+
if (callExpressionValues) return callExpressionValues;
|
|
41
|
+
const identifierValues = extractIdentifierValues(node, visited);
|
|
42
|
+
if (identifierValues) return identifierValues;
|
|
43
|
+
return [];
|
|
44
|
+
};
|
|
45
|
+
const extractDirectLiteralValues = (node) => {
|
|
46
|
+
if (ts_morph.Node.isStringLiteral(node) || ts_morph.Node.isNoSubstitutionTemplateLiteral(node)) return [node.getLiteralValue()];
|
|
47
|
+
return null;
|
|
48
|
+
};
|
|
49
|
+
const extractTemplateExpressionValues = (node, visited) => {
|
|
50
|
+
if (!ts_morph.Node.isTemplateExpression(node)) return null;
|
|
51
|
+
const parts = [[node.getHead().getLiteralText()]];
|
|
52
|
+
node.getTemplateSpans().forEach((span) => {
|
|
53
|
+
const exprValues = extractStringLiterals(span.getExpression(), visited);
|
|
54
|
+
const literalText = span.getLiteral().getLiteralText();
|
|
55
|
+
parts.push(exprValues.length > 0 ? exprValues.map((value) => `${value}${literalText}`) : ["", literalText]);
|
|
56
|
+
});
|
|
57
|
+
return parts.reduce((acc, segment) => acc.flatMap((base) => segment.map((frag) => `${base}${frag}`)), [""]).filter((value) => value.length > 0);
|
|
58
|
+
};
|
|
59
|
+
const extractBinaryExpressionValues = (node, visited) => {
|
|
60
|
+
if (!ts_morph.Node.isBinaryExpression(node)) return null;
|
|
61
|
+
const operator = node.getOperatorToken().getText();
|
|
62
|
+
if (operator === "+") {
|
|
63
|
+
const left = extractStringLiterals(node.getLeft(), visited);
|
|
64
|
+
const right = extractStringLiterals(node.getRight(), visited);
|
|
65
|
+
const combined = left.flatMap((l) => right.map((r) => `${l}${r}`));
|
|
66
|
+
return combined.length > 0 ? combined : [];
|
|
78
67
|
}
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
68
|
+
if (operator === "||" || operator === "??") return [...extractStringLiterals(node.getLeft(), visited), ...extractStringLiterals(node.getRight(), visited)];
|
|
69
|
+
return [];
|
|
70
|
+
};
|
|
71
|
+
const extractWrappedExpressionValues = (node, visited) => {
|
|
72
|
+
if (ts_morph.Node.isParenthesizedExpression(node) || ts_morph.Node.isAsExpression(node)) return extractStringLiterals(node.getExpression(), visited);
|
|
73
|
+
return null;
|
|
74
|
+
};
|
|
75
|
+
const extractPropertyAccessValues = (node, visited) => {
|
|
76
|
+
if (!ts_morph.Node.isPropertyAccessExpression(node)) return null;
|
|
77
|
+
const typeValues = extractLiteralValuesFromType(node);
|
|
78
|
+
if (typeValues.length > 0) return typeValues;
|
|
79
|
+
const propertyName = node.getName();
|
|
80
|
+
return extractObjectValues(node.getExpression(), visited).filter((value) => typeof value === "object" && value !== null && propertyName in value).map((value) => value[propertyName]).filter((value) => typeof value === "string");
|
|
81
|
+
};
|
|
82
|
+
const extractElementAccessValues = (node) => {
|
|
83
|
+
if (!ts_morph.Node.isElementAccessExpression(node)) return null;
|
|
84
|
+
return extractLiteralValuesFromType(node);
|
|
85
|
+
};
|
|
86
|
+
const extractCallExpressionValues = (node, visited) => {
|
|
87
|
+
if (!ts_morph.Node.isCallExpression(node)) return null;
|
|
88
|
+
const expression = node.getExpression();
|
|
89
|
+
const fromDefinitions = ts_morph.Node.isIdentifier(expression) ? expression.getDefinitionNodes().flatMap((definition) => {
|
|
90
|
+
if (ts_morph.Node.isFunctionDeclaration(definition)) return definition.getDescendantsOfKind(ts_morph.SyntaxKind.ReturnStatement).flatMap((returnStmt) => {
|
|
91
|
+
const expression = returnStmt.getExpression();
|
|
92
|
+
return expression ? extractStringLiterals(expression, visited) : [];
|
|
93
|
+
});
|
|
94
|
+
if (ts_morph.Node.isVariableDeclaration(definition)) {
|
|
95
|
+
const initializer = definition.getInitializer();
|
|
96
|
+
return initializer ? extractFromFunctionLike(initializer, visited) : [];
|
|
90
97
|
}
|
|
91
|
-
return
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
if (ts_morph.Node.isParameterDeclaration(definition)) {
|
|
104
|
-
const initializer = definition.getInitializer();
|
|
105
|
-
if (initializer) {
|
|
106
|
-
foundInitializer = true;
|
|
107
|
-
values.push(...extractStringLiterals(initializer, visited));
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
if (ts_morph.Node.isBindingElement(definition)) {
|
|
111
|
-
const initializer = definition.getInitializer();
|
|
112
|
-
if (initializer) {
|
|
113
|
-
foundInitializer = true;
|
|
114
|
-
values.push(...extractStringLiterals(initializer, visited));
|
|
115
|
-
}
|
|
116
|
-
}
|
|
98
|
+
return [];
|
|
99
|
+
}) : [];
|
|
100
|
+
const fromArguments = node.getArguments().flatMap((arg) => extractStringLiterals(arg, visited));
|
|
101
|
+
return [...fromDefinitions, ...fromArguments];
|
|
102
|
+
};
|
|
103
|
+
const extractIdentifierValues = (node, visited) => {
|
|
104
|
+
if (!ts_morph.Node.isIdentifier(node)) return null;
|
|
105
|
+
const values = node.getDefinitionNodes().flatMap((definition) => {
|
|
106
|
+
if (ts_morph.Node.isVariableDeclaration(definition) || ts_morph.Node.isParameterDeclaration(definition) || ts_morph.Node.isBindingElement(definition)) {
|
|
107
|
+
const initializer = definition.getInitializer();
|
|
108
|
+
return initializer ? extractStringLiterals(initializer, visited) : [];
|
|
117
109
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
110
|
+
return [];
|
|
111
|
+
});
|
|
112
|
+
return values.length > 0 ? values : extractLiteralValuesFromType(node);
|
|
113
|
+
};
|
|
123
114
|
/**
|
|
124
115
|
* Extract string literals from arrow functions or function expressions
|
|
125
116
|
*/
|
|
126
|
-
|
|
117
|
+
const extractFromFunctionLike = (node, visited) => {
|
|
127
118
|
const values = [];
|
|
128
119
|
if (ts_morph.Node.isArrowFunction(node)) {
|
|
129
120
|
const body = node.getBody();
|
|
130
|
-
if (ts_morph.Node.isBlock(body))
|
|
121
|
+
if (ts_morph.Node.isBlock(body)) body.getDescendantsOfKind(ts_morph.SyntaxKind.ReturnStatement).forEach((returnStmt) => {
|
|
131
122
|
const returnExpr = returnStmt.getExpression();
|
|
132
123
|
if (returnExpr) values.push(...extractStringLiterals(returnExpr, visited));
|
|
133
|
-
}
|
|
124
|
+
});
|
|
134
125
|
else values.push(...extractStringLiterals(body, visited));
|
|
135
|
-
} else if (ts_morph.Node.isFunctionExpression(node))
|
|
126
|
+
} else if (ts_morph.Node.isFunctionExpression(node)) node.getDescendantsOfKind(ts_morph.SyntaxKind.ReturnStatement).forEach((returnStmt) => {
|
|
136
127
|
const returnExpr = returnStmt.getExpression();
|
|
137
128
|
if (returnExpr) values.push(...extractStringLiterals(returnExpr, visited));
|
|
138
|
-
}
|
|
129
|
+
});
|
|
139
130
|
return values;
|
|
140
|
-
}
|
|
131
|
+
};
|
|
141
132
|
/**
|
|
142
133
|
* Extract object literal values from an expression.
|
|
143
134
|
* Returns an array of all possible object values (for union types or indexed access).
|
|
144
135
|
*/
|
|
145
|
-
|
|
136
|
+
const extractObjectValues = (node, visited) => {
|
|
146
137
|
if (visited.has(node)) return [];
|
|
147
138
|
visited.add(node);
|
|
148
139
|
const values = [];
|
|
149
140
|
if (ts_morph.Node.isObjectLiteralExpression(node)) {
|
|
150
141
|
const obj = {};
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
142
|
+
node.getProperties().forEach((prop) => {
|
|
143
|
+
if (ts_morph.Node.isPropertyAssignment(prop)) {
|
|
144
|
+
const name = prop.getName();
|
|
145
|
+
const init = prop.getInitializer();
|
|
146
|
+
if (init && ts_morph.Node.isStringLiteral(init)) obj[name] = init.getLiteralValue();
|
|
147
|
+
else if (init && ts_morph.Node.isObjectLiteralExpression(init)) {
|
|
148
|
+
const nestedValues = extractObjectValues(init, visited);
|
|
149
|
+
if (nestedValues.length > 0) obj[name] = nestedValues[0];
|
|
150
|
+
}
|
|
158
151
|
}
|
|
159
|
-
}
|
|
152
|
+
});
|
|
160
153
|
values.push(obj);
|
|
161
154
|
return values;
|
|
162
155
|
}
|
|
163
156
|
if (ts_morph.Node.isIdentifier(node)) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
157
|
+
node.getDefinitionNodes().forEach((definition) => {
|
|
158
|
+
if (ts_morph.Node.isVariableDeclaration(definition)) {
|
|
159
|
+
const initializer = definition.getInitializer();
|
|
160
|
+
if (initializer) if (ts_morph.Node.isAsExpression(initializer)) {
|
|
161
|
+
const inner = initializer.getExpression();
|
|
162
|
+
values.push(...extractObjectValues(inner, visited));
|
|
163
|
+
} else values.push(...extractObjectValues(initializer, visited));
|
|
164
|
+
}
|
|
165
|
+
});
|
|
171
166
|
return values;
|
|
172
167
|
}
|
|
173
168
|
if (ts_morph.Node.isElementAccessExpression(node)) {
|
|
174
|
-
|
|
175
|
-
|
|
169
|
+
extractObjectValues(node.getExpression(), visited).forEach((obj) => {
|
|
170
|
+
if (typeof obj === "object" && obj !== null) Object.values(obj).forEach((value) => values.push(value));
|
|
171
|
+
});
|
|
176
172
|
return values;
|
|
177
173
|
}
|
|
178
174
|
return values;
|
|
179
|
-
}
|
|
175
|
+
};
|
|
180
176
|
/**
|
|
181
177
|
* Extract literal values from a TypeScript type (for union types like 'brand' | 'secondary')
|
|
182
178
|
*/
|
|
183
|
-
|
|
179
|
+
const extractLiteralValuesFromType = (node) => {
|
|
184
180
|
const values = [];
|
|
185
181
|
const nodeType = node.getType();
|
|
186
|
-
if (nodeType.isUnion()) {
|
|
187
|
-
|
|
188
|
-
}
|
|
182
|
+
if (nodeType.isUnion()) nodeType.getUnionTypes().forEach((unionMember) => {
|
|
183
|
+
if (unionMember.isStringLiteral()) values.push(unionMember.getLiteralValue());
|
|
184
|
+
});
|
|
185
|
+
else if (nodeType.isStringLiteral()) values.push(nodeType.getLiteralValue());
|
|
189
186
|
return values;
|
|
190
|
-
}
|
|
187
|
+
};
|
|
191
188
|
|
|
192
189
|
//#endregion
|
|
193
190
|
exports.extractStringLiterals = extractStringLiterals;
|
|
@@ -19,174 +19,171 @@ import { Node, SyntaxKind } from "ts-morph";
|
|
|
19
19
|
* @param visited Set of visited nodes to prevent infinite recursion
|
|
20
20
|
* @returns Array of extracted string literal values
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
const extractStringLiterals = (node, visited = /* @__PURE__ */ new Set()) => {
|
|
23
23
|
if (visited.has(node)) return [];
|
|
24
24
|
visited.add(node);
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (typeof propValue === "string") values.push(propValue);
|
|
67
|
-
}
|
|
68
|
-
return values;
|
|
69
|
-
}
|
|
70
|
-
if (Node.isElementAccessExpression(node)) {
|
|
71
|
-
const typeValues = extractLiteralValuesFromType(node);
|
|
72
|
-
if (typeValues.length > 0) {
|
|
73
|
-
values.push(...typeValues);
|
|
74
|
-
return values;
|
|
75
|
-
}
|
|
76
|
-
return values;
|
|
25
|
+
const directValues = extractDirectLiteralValues(node);
|
|
26
|
+
if (directValues) return directValues;
|
|
27
|
+
const templateValues = extractTemplateExpressionValues(node, visited);
|
|
28
|
+
if (templateValues) return templateValues;
|
|
29
|
+
if (Node.isConditionalExpression(node)) return [...extractStringLiterals(node.getWhenTrue(), visited), ...extractStringLiterals(node.getWhenFalse(), visited)];
|
|
30
|
+
const binaryValues = extractBinaryExpressionValues(node, visited);
|
|
31
|
+
if (binaryValues) return binaryValues;
|
|
32
|
+
const wrappedExpressionValues = extractWrappedExpressionValues(node, visited);
|
|
33
|
+
if (wrappedExpressionValues) return wrappedExpressionValues;
|
|
34
|
+
const propertyAccessValues = extractPropertyAccessValues(node, visited);
|
|
35
|
+
if (propertyAccessValues) return propertyAccessValues;
|
|
36
|
+
const elementAccessValues = extractElementAccessValues(node);
|
|
37
|
+
if (elementAccessValues) return elementAccessValues;
|
|
38
|
+
const callExpressionValues = extractCallExpressionValues(node, visited);
|
|
39
|
+
if (callExpressionValues) return callExpressionValues;
|
|
40
|
+
const identifierValues = extractIdentifierValues(node, visited);
|
|
41
|
+
if (identifierValues) return identifierValues;
|
|
42
|
+
return [];
|
|
43
|
+
};
|
|
44
|
+
const extractDirectLiteralValues = (node) => {
|
|
45
|
+
if (Node.isStringLiteral(node) || Node.isNoSubstitutionTemplateLiteral(node)) return [node.getLiteralValue()];
|
|
46
|
+
return null;
|
|
47
|
+
};
|
|
48
|
+
const extractTemplateExpressionValues = (node, visited) => {
|
|
49
|
+
if (!Node.isTemplateExpression(node)) return null;
|
|
50
|
+
const parts = [[node.getHead().getLiteralText()]];
|
|
51
|
+
node.getTemplateSpans().forEach((span) => {
|
|
52
|
+
const exprValues = extractStringLiterals(span.getExpression(), visited);
|
|
53
|
+
const literalText = span.getLiteral().getLiteralText();
|
|
54
|
+
parts.push(exprValues.length > 0 ? exprValues.map((value) => `${value}${literalText}`) : ["", literalText]);
|
|
55
|
+
});
|
|
56
|
+
return parts.reduce((acc, segment) => acc.flatMap((base) => segment.map((frag) => `${base}${frag}`)), [""]).filter((value) => value.length > 0);
|
|
57
|
+
};
|
|
58
|
+
const extractBinaryExpressionValues = (node, visited) => {
|
|
59
|
+
if (!Node.isBinaryExpression(node)) return null;
|
|
60
|
+
const operator = node.getOperatorToken().getText();
|
|
61
|
+
if (operator === "+") {
|
|
62
|
+
const left = extractStringLiterals(node.getLeft(), visited);
|
|
63
|
+
const right = extractStringLiterals(node.getRight(), visited);
|
|
64
|
+
const combined = left.flatMap((l) => right.map((r) => `${l}${r}`));
|
|
65
|
+
return combined.length > 0 ? combined : [];
|
|
77
66
|
}
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
67
|
+
if (operator === "||" || operator === "??") return [...extractStringLiterals(node.getLeft(), visited), ...extractStringLiterals(node.getRight(), visited)];
|
|
68
|
+
return [];
|
|
69
|
+
};
|
|
70
|
+
const extractWrappedExpressionValues = (node, visited) => {
|
|
71
|
+
if (Node.isParenthesizedExpression(node) || Node.isAsExpression(node)) return extractStringLiterals(node.getExpression(), visited);
|
|
72
|
+
return null;
|
|
73
|
+
};
|
|
74
|
+
const extractPropertyAccessValues = (node, visited) => {
|
|
75
|
+
if (!Node.isPropertyAccessExpression(node)) return null;
|
|
76
|
+
const typeValues = extractLiteralValuesFromType(node);
|
|
77
|
+
if (typeValues.length > 0) return typeValues;
|
|
78
|
+
const propertyName = node.getName();
|
|
79
|
+
return extractObjectValues(node.getExpression(), visited).filter((value) => typeof value === "object" && value !== null && propertyName in value).map((value) => value[propertyName]).filter((value) => typeof value === "string");
|
|
80
|
+
};
|
|
81
|
+
const extractElementAccessValues = (node) => {
|
|
82
|
+
if (!Node.isElementAccessExpression(node)) return null;
|
|
83
|
+
return extractLiteralValuesFromType(node);
|
|
84
|
+
};
|
|
85
|
+
const extractCallExpressionValues = (node, visited) => {
|
|
86
|
+
if (!Node.isCallExpression(node)) return null;
|
|
87
|
+
const expression = node.getExpression();
|
|
88
|
+
const fromDefinitions = Node.isIdentifier(expression) ? expression.getDefinitionNodes().flatMap((definition) => {
|
|
89
|
+
if (Node.isFunctionDeclaration(definition)) return definition.getDescendantsOfKind(SyntaxKind.ReturnStatement).flatMap((returnStmt) => {
|
|
90
|
+
const expression = returnStmt.getExpression();
|
|
91
|
+
return expression ? extractStringLiterals(expression, visited) : [];
|
|
92
|
+
});
|
|
93
|
+
if (Node.isVariableDeclaration(definition)) {
|
|
94
|
+
const initializer = definition.getInitializer();
|
|
95
|
+
return initializer ? extractFromFunctionLike(initializer, visited) : [];
|
|
89
96
|
}
|
|
90
|
-
return
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
if (Node.isParameterDeclaration(definition)) {
|
|
103
|
-
const initializer = definition.getInitializer();
|
|
104
|
-
if (initializer) {
|
|
105
|
-
foundInitializer = true;
|
|
106
|
-
values.push(...extractStringLiterals(initializer, visited));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if (Node.isBindingElement(definition)) {
|
|
110
|
-
const initializer = definition.getInitializer();
|
|
111
|
-
if (initializer) {
|
|
112
|
-
foundInitializer = true;
|
|
113
|
-
values.push(...extractStringLiterals(initializer, visited));
|
|
114
|
-
}
|
|
115
|
-
}
|
|
97
|
+
return [];
|
|
98
|
+
}) : [];
|
|
99
|
+
const fromArguments = node.getArguments().flatMap((arg) => extractStringLiterals(arg, visited));
|
|
100
|
+
return [...fromDefinitions, ...fromArguments];
|
|
101
|
+
};
|
|
102
|
+
const extractIdentifierValues = (node, visited) => {
|
|
103
|
+
if (!Node.isIdentifier(node)) return null;
|
|
104
|
+
const values = node.getDefinitionNodes().flatMap((definition) => {
|
|
105
|
+
if (Node.isVariableDeclaration(definition) || Node.isParameterDeclaration(definition) || Node.isBindingElement(definition)) {
|
|
106
|
+
const initializer = definition.getInitializer();
|
|
107
|
+
return initializer ? extractStringLiterals(initializer, visited) : [];
|
|
116
108
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
109
|
+
return [];
|
|
110
|
+
});
|
|
111
|
+
return values.length > 0 ? values : extractLiteralValuesFromType(node);
|
|
112
|
+
};
|
|
122
113
|
/**
|
|
123
114
|
* Extract string literals from arrow functions or function expressions
|
|
124
115
|
*/
|
|
125
|
-
|
|
116
|
+
const extractFromFunctionLike = (node, visited) => {
|
|
126
117
|
const values = [];
|
|
127
118
|
if (Node.isArrowFunction(node)) {
|
|
128
119
|
const body = node.getBody();
|
|
129
|
-
if (Node.isBlock(body))
|
|
120
|
+
if (Node.isBlock(body)) body.getDescendantsOfKind(SyntaxKind.ReturnStatement).forEach((returnStmt) => {
|
|
130
121
|
const returnExpr = returnStmt.getExpression();
|
|
131
122
|
if (returnExpr) values.push(...extractStringLiterals(returnExpr, visited));
|
|
132
|
-
}
|
|
123
|
+
});
|
|
133
124
|
else values.push(...extractStringLiterals(body, visited));
|
|
134
|
-
} else if (Node.isFunctionExpression(node))
|
|
125
|
+
} else if (Node.isFunctionExpression(node)) node.getDescendantsOfKind(SyntaxKind.ReturnStatement).forEach((returnStmt) => {
|
|
135
126
|
const returnExpr = returnStmt.getExpression();
|
|
136
127
|
if (returnExpr) values.push(...extractStringLiterals(returnExpr, visited));
|
|
137
|
-
}
|
|
128
|
+
});
|
|
138
129
|
return values;
|
|
139
|
-
}
|
|
130
|
+
};
|
|
140
131
|
/**
|
|
141
132
|
* Extract object literal values from an expression.
|
|
142
133
|
* Returns an array of all possible object values (for union types or indexed access).
|
|
143
134
|
*/
|
|
144
|
-
|
|
135
|
+
const extractObjectValues = (node, visited) => {
|
|
145
136
|
if (visited.has(node)) return [];
|
|
146
137
|
visited.add(node);
|
|
147
138
|
const values = [];
|
|
148
139
|
if (Node.isObjectLiteralExpression(node)) {
|
|
149
140
|
const obj = {};
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
141
|
+
node.getProperties().forEach((prop) => {
|
|
142
|
+
if (Node.isPropertyAssignment(prop)) {
|
|
143
|
+
const name = prop.getName();
|
|
144
|
+
const init = prop.getInitializer();
|
|
145
|
+
if (init && Node.isStringLiteral(init)) obj[name] = init.getLiteralValue();
|
|
146
|
+
else if (init && Node.isObjectLiteralExpression(init)) {
|
|
147
|
+
const nestedValues = extractObjectValues(init, visited);
|
|
148
|
+
if (nestedValues.length > 0) obj[name] = nestedValues[0];
|
|
149
|
+
}
|
|
157
150
|
}
|
|
158
|
-
}
|
|
151
|
+
});
|
|
159
152
|
values.push(obj);
|
|
160
153
|
return values;
|
|
161
154
|
}
|
|
162
155
|
if (Node.isIdentifier(node)) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
156
|
+
node.getDefinitionNodes().forEach((definition) => {
|
|
157
|
+
if (Node.isVariableDeclaration(definition)) {
|
|
158
|
+
const initializer = definition.getInitializer();
|
|
159
|
+
if (initializer) if (Node.isAsExpression(initializer)) {
|
|
160
|
+
const inner = initializer.getExpression();
|
|
161
|
+
values.push(...extractObjectValues(inner, visited));
|
|
162
|
+
} else values.push(...extractObjectValues(initializer, visited));
|
|
163
|
+
}
|
|
164
|
+
});
|
|
170
165
|
return values;
|
|
171
166
|
}
|
|
172
167
|
if (Node.isElementAccessExpression(node)) {
|
|
173
|
-
|
|
174
|
-
|
|
168
|
+
extractObjectValues(node.getExpression(), visited).forEach((obj) => {
|
|
169
|
+
if (typeof obj === "object" && obj !== null) Object.values(obj).forEach((value) => values.push(value));
|
|
170
|
+
});
|
|
175
171
|
return values;
|
|
176
172
|
}
|
|
177
173
|
return values;
|
|
178
|
-
}
|
|
174
|
+
};
|
|
179
175
|
/**
|
|
180
176
|
* Extract literal values from a TypeScript type (for union types like 'brand' | 'secondary')
|
|
181
177
|
*/
|
|
182
|
-
|
|
178
|
+
const extractLiteralValuesFromType = (node) => {
|
|
183
179
|
const values = [];
|
|
184
180
|
const nodeType = node.getType();
|
|
185
|
-
if (nodeType.isUnion()) {
|
|
186
|
-
|
|
187
|
-
}
|
|
181
|
+
if (nodeType.isUnion()) nodeType.getUnionTypes().forEach((unionMember) => {
|
|
182
|
+
if (unionMember.isStringLiteral()) values.push(unionMember.getLiteralValue());
|
|
183
|
+
});
|
|
184
|
+
else if (nodeType.isStringLiteral()) values.push(nodeType.getLiteralValue());
|
|
188
185
|
return values;
|
|
189
|
-
}
|
|
186
|
+
};
|
|
190
187
|
|
|
191
188
|
//#endregion
|
|
192
189
|
export { extractStringLiterals };
|
|
@@ -7,14 +7,7 @@ let ts_morph = require("ts-morph");
|
|
|
7
7
|
/**
|
|
8
8
|
* Find all JSX usages of a component from its identifier
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
const elements = [];
|
|
12
|
-
for (const reference of identifier.findReferencesAsNodes()) {
|
|
13
|
-
const node = reference.getFirstAncestor((n) => ts_morph.Node.isJsxOpeningElement(n) || ts_morph.Node.isJsxSelfClosingElement(n));
|
|
14
|
-
if (node && (ts_morph.Node.isJsxOpeningElement(node) || ts_morph.Node.isJsxSelfClosingElement(node))) elements.push(node);
|
|
15
|
-
}
|
|
16
|
-
return elements;
|
|
17
|
-
}
|
|
10
|
+
const findJsxReferences = (identifier) => identifier.findReferencesAsNodes().map((reference) => reference.getFirstAncestor((n) => ts_morph.Node.isJsxOpeningElement(n) || ts_morph.Node.isJsxSelfClosingElement(n))).filter((node) => Boolean(node) && (ts_morph.Node.isJsxOpeningElement(node) || ts_morph.Node.isJsxSelfClosingElement(node)));
|
|
18
11
|
|
|
19
12
|
//#endregion
|
|
20
13
|
exports.findJsxReferences = findJsxReferences;
|
|
@@ -6,14 +6,7 @@ import { Node, SyntaxKind } from "ts-morph";
|
|
|
6
6
|
/**
|
|
7
7
|
* Find all JSX usages of a component from its identifier
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
const elements = [];
|
|
11
|
-
for (const reference of identifier.findReferencesAsNodes()) {
|
|
12
|
-
const node = reference.getFirstAncestor((n) => Node.isJsxOpeningElement(n) || Node.isJsxSelfClosingElement(n));
|
|
13
|
-
if (node && (Node.isJsxOpeningElement(node) || Node.isJsxSelfClosingElement(node))) elements.push(node);
|
|
14
|
-
}
|
|
15
|
-
return elements;
|
|
16
|
-
}
|
|
9
|
+
const findJsxReferences = (identifier) => identifier.findReferencesAsNodes().map((reference) => reference.getFirstAncestor((n) => Node.isJsxOpeningElement(n) || Node.isJsxSelfClosingElement(n))).filter((node) => Boolean(node) && (Node.isJsxOpeningElement(node) || Node.isJsxSelfClosingElement(node)));
|
|
17
10
|
|
|
18
11
|
//#endregion
|
|
19
12
|
export { findJsxReferences };
|