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