diff --git a/package-lock.json b/package-lock.json index 560f9a6..d60c388 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1154,6 +1154,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "engines": { "node": ">= 6" } @@ -1194,7 +1195,6 @@ "integrity": "sha512-d7fGCyB96w9BnWQrOsJtpyiSaBcAYYr75bnK6ZRjDbql2cGLj/3GsL5OYmLPNq76l7Gf2q4Rv9J2o6h5CrD9sA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "undici-types": "~6.19.2" } @@ -1212,7 +1212,6 @@ "integrity": "sha512-BWf7hqninZav6nerxXj+NeZT/mTpDeG6Lk2zREHAy63CrnXoOGPGtNqTFYFN/sqpSaREDP5otVV88axIXmKfGA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/prop-types": "*", "@types/scheduler": "^0.16", @@ -1282,7 +1281,6 @@ "integrity": "sha512-tK3GPFWbirvNgsNKto+UmB/cRtn6TZfyw0D6IKrW55n6Vbs7KJoZtI//kpTKzE/DUmmnAFD8/Ca46s7Obs92/w==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "8.46.4", "@typescript-eslint/types": "8.46.4", @@ -1692,7 +1690,8 @@ "deprecated": "Use your platform's native atob() and btoa() methods instead", "dev": true, "license": "BSD-3-Clause", - "optional": true + "optional": true, + "peer": true }, "node_modules/acorn": { "version": "7.4.1", @@ -1715,6 +1714,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "acorn": "^7.1.1", "acorn-walk": "^7.1.1" @@ -1737,6 +1737,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "engines": { "node": ">=0.4.0" } @@ -1748,6 +1749,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "debug": "4" }, @@ -1968,7 +1970,8 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", "dev": true, "license": "MIT", - "optional": true + "optional": true, + "peer": true }, "node_modules/available-typed-arrays": { "version": "1.0.7", @@ -2032,7 +2035,8 @@ "integrity": "sha512-9o5UecI3GhkpM6DrXr69PblIuWxPKk9Y0jHBRhdocZ2y7YECBFCsHm79Pr3OyR2AvjhDkabFJaDJMYRazHgsow==", "dev": true, "license": "BSD-2-Clause", - "optional": true + "optional": true, + "peer": true }, "node_modules/browserslist": { "version": "4.28.0", @@ -2054,7 +2058,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "baseline-browser-mapping": "^2.8.25", "caniuse-lite": "^1.0.30001754", @@ -2361,6 +2364,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "delayed-stream": "~1.0.0" }, @@ -2431,7 +2435,8 @@ "integrity": "sha512-p3pvU7r1MyyqbTk+WbNJIgJjG2VmTIaB10rI93LzVPrmDJKkzKYMtxxyAvQXR/NS6otuzveI7+7BBq3SjBS2mw==", "dev": true, "license": "MIT", - "optional": true + "optional": true, + "peer": true }, "node_modules/cssstyle": { "version": "2.3.0", @@ -2440,6 +2445,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "cssom": "~0.3.6" }, @@ -2453,7 +2459,8 @@ "integrity": "sha512-b0tGHbfegbhPJpxpiBPU2sCkigAqtM9O121le6bbOlgyV+NyGyCmVfJ6QW9eRjz8CpNfWEOYBIMIGRYkLwsIYg==", "dev": true, "license": "MIT", - "optional": true + "optional": true, + "peer": true }, "node_modules/csstype": { "version": "3.1.3", @@ -2469,6 +2476,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "abab": "^2.0.3", "whatwg-mimetype": "^2.3.0", @@ -2556,7 +2564,8 @@ "integrity": "sha512-8vDa8Qxvr/+d94hSh5P3IJwI5t8/c0KsMp+g8bNw9cY2icONa5aPfvKeieW1WlG0WQYwwhJ7mjui2xtiePQSXw==", "dev": true, "license": "MIT", - "optional": true + "optional": true, + "peer": true }, "node_modules/deep-eql": { "version": "5.0.2", @@ -2617,6 +2626,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "engines": { "node": ">=0.4.0" } @@ -2642,6 +2652,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "webidl-conversions": "^5.0.0" }, @@ -2656,6 +2667,7 @@ "dev": true, "license": "BSD-2-Clause", "optional": true, + "peer": true, "engines": { "node": ">=8" } @@ -2959,6 +2971,7 @@ "dev": true, "license": "BSD-2-Clause", "optional": true, + "peer": true, "dependencies": { "esprima": "^4.0.1", "estraverse": "^5.2.0", @@ -2981,7 +2994,6 @@ "integrity": "sha512-BhHmn2yNOFA9H9JmmIVKJmd288g9hrVRDkdoIgRCRuSySRUHH7r/DI6aAXW9T1WwUuY3DFgrcaqB+deURBLR5g==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.1", @@ -3042,7 +3054,6 @@ "integrity": "sha512-82GZUjRS0p/jganf6q1rEO25VSoHH0hKPCTrgillPjdI/3bgBhAE1QzHrHTizjpRvy6pGAvKjDJtk2pF9NDq8w==", "dev": true, "license": "MIT", - "peer": true, "bin": { "eslint-config-prettier": "bin/cli.js" }, @@ -3301,6 +3312,7 @@ "dev": true, "license": "BSD-2-Clause", "optional": true, + "peer": true, "bin": { "esparse": "bin/esparse.js", "esvalidate": "bin/esvalidate.js" @@ -3565,6 +3577,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -3932,6 +3945,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "whatwg-encoding": "^1.0.5" }, @@ -3953,6 +3967,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "@tootallnate/once": "1", "agent-base": "6", @@ -3969,6 +3984,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "agent-base": "6", "debug": "4" @@ -4000,6 +4016,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "safer-buffer": ">= 2.1.2 < 3" }, @@ -4353,7 +4370,8 @@ "integrity": "sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==", "dev": true, "license": "MIT", - "optional": true + "optional": true, + "peer": true }, "node_modules/is-regex": { "version": "1.2.1", @@ -4614,6 +4632,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "abab": "^2.0.5", "acorn": "^8.2.4", @@ -4662,6 +4681,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -4999,7 +5019,8 @@ "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "dev": true, "license": "MIT", - "optional": true + "optional": true, + "peer": true }, "node_modules/lodash.merge": { "version": "4.6.2", @@ -5199,6 +5220,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "engines": { "node": ">= 0.6" } @@ -5210,6 +5232,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "mime-db": "1.52.0" }, @@ -5305,7 +5328,8 @@ "integrity": "sha512-F1I/bimDpj3ncaNDhfyMWuFqmQDBwDB0Fogc2qpL3BWvkQteFD/8BzWuIRl83rq0DXfm8SGt/HFhLXZyljTXcQ==", "dev": true, "license": "MIT", - "optional": true + "optional": true, + "peer": true }, "node_modules/object-assign": { "version": "4.1.1", @@ -5535,7 +5559,8 @@ "integrity": "sha512-Ofn/CTFzRGTTxwpNEs9PP93gXShHcTq255nzRYSKe8AkVpZY7e1fpmTfOyoIvjP5HG7Z2ZM7VS9PPhQGW2pOpw==", "dev": true, "license": "MIT", - "optional": true + "optional": true, + "peer": true }, "node_modules/pascal-case": { "version": "3.1.2", @@ -5719,7 +5744,6 @@ "integrity": "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==", "dev": true, "license": "MIT", - "peer": true, "bin": { "prettier": "bin/prettier.cjs" }, @@ -5762,6 +5786,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "punycode": "^2.3.1" }, @@ -5785,7 +5810,8 @@ "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==", "dev": true, "license": "MIT", - "optional": true + "optional": true, + "peer": true }, "node_modules/queue-microtask": { "version": "1.2.3", @@ -5901,7 +5927,8 @@ "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==", "dev": true, "license": "MIT", - "optional": true + "optional": true, + "peer": true }, "node_modules/resolve": { "version": "2.0.0-next.5", @@ -6106,7 +6133,8 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true, "license": "MIT", - "optional": true + "optional": true, + "peer": true }, "node_modules/saxes": { "version": "5.0.1", @@ -6115,6 +6143,7 @@ "dev": true, "license": "ISC", "optional": true, + "peer": true, "dependencies": { "xmlchars": "^2.2.0" }, @@ -6355,6 +6384,7 @@ "dev": true, "license": "BSD-3-Clause", "optional": true, + "peer": true, "engines": { "node": ">=0.10.0" } @@ -6670,7 +6700,8 @@ "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==", "dev": true, "license": "MIT", - "optional": true + "optional": true, + "peer": true }, "node_modules/synckit": { "version": "0.11.11", @@ -6737,7 +6768,6 @@ "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz", "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==", "dev": true, - "peer": true, "engines": { "node": ">=12" }, @@ -6793,6 +6823,7 @@ "dev": true, "license": "BSD-3-Clause", "optional": true, + "peer": true, "dependencies": { "psl": "^1.1.33", "punycode": "^2.1.1", @@ -6810,6 +6841,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "punycode": "^2.1.1" }, @@ -6933,7 +6965,6 @@ "integrity": "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A==", "dev": true, "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -6999,6 +7030,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "engines": { "node": ">= 4.0.0" } @@ -7069,6 +7101,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "querystringify": "^2.1.1", "requires-port": "^1.0.0" @@ -7121,7 +7154,6 @@ "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz", "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==", "dev": true, - "peer": true, "engines": { "node": ">=12" }, @@ -7204,12 +7236,29 @@ } } }, + "node_modules/vite-node/node_modules/yaml": { + "version": "2.8.2", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.2.tgz", + "integrity": "sha512-mplynKqc1C2hTVYxd0PU2xQAc22TI1vShAYGksCCfxbn/dFwnHTNi1bvYsBTkhdUNtGIf5xNOg938rrSSYvS9A==", + "dev": true, + "license": "ISC", + "optional": true, + "peer": true, + "bin": { + "yaml": "bin.mjs" + }, + "engines": { + "node": ">= 14.6" + }, + "funding": { + "url": "https://github.com/sponsors/eemeli" + } + }, "node_modules/vitest": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/vitest/-/vitest-3.1.3.tgz", "integrity": "sha512-188iM4hAHQ0km23TN/adso1q5hhwKqUpv+Sd6p5sOuh6FhQnRNW3IsiIpvxqahtBabsJ2SLZgmGSpcYK4wQYJw==", "dev": true, - "peer": true, "dependencies": { "@vitest/expect": "3.1.3", "@vitest/mocker": "3.1.3", @@ -7327,7 +7376,6 @@ "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz", "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==", "dev": true, - "peer": true, "engines": { "node": ">=12" }, @@ -7341,7 +7389,6 @@ "integrity": "sha512-+Oxm7q9hDoLMyJOYfUYBuHQo+dkAloi33apOPP56pzj+vsdJDzr+j1NISE5pyaAuKL4A3UD34qd0lx5+kfKp2g==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "esbuild": "^0.25.0", "fdir": "^6.4.4", @@ -7411,6 +7458,24 @@ } } }, + "node_modules/vitest/node_modules/yaml": { + "version": "2.8.2", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.2.tgz", + "integrity": "sha512-mplynKqc1C2hTVYxd0PU2xQAc22TI1vShAYGksCCfxbn/dFwnHTNi1bvYsBTkhdUNtGIf5xNOg938rrSSYvS9A==", + "dev": true, + "license": "ISC", + "optional": true, + "peer": true, + "bin": { + "yaml": "bin.mjs" + }, + "engines": { + "node": ">= 14.6" + }, + "funding": { + "url": "https://github.com/sponsors/eemeli" + } + }, "node_modules/w3c-hr-time": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/w3c-hr-time/-/w3c-hr-time-1.0.2.tgz", @@ -7419,6 +7484,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "browser-process-hrtime": "^1.0.0" } @@ -7430,6 +7496,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "xml-name-validator": "^3.0.0" }, @@ -7444,6 +7511,7 @@ "dev": true, "license": "BSD-2-Clause", "optional": true, + "peer": true, "engines": { "node": ">=10.4" } @@ -7455,6 +7523,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "iconv-lite": "0.4.24" } @@ -7465,7 +7534,8 @@ "integrity": "sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g==", "dev": true, "license": "MIT", - "optional": true + "optional": true, + "peer": true }, "node_modules/whatwg-url": { "version": "8.7.0", @@ -7474,6 +7544,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "lodash": "^4.7.0", "tr46": "^2.1.0", @@ -7733,6 +7804,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "engines": { "node": ">=8.3.0" }, @@ -7755,7 +7827,8 @@ "integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==", "dev": true, "license": "Apache-2.0", - "optional": true + "optional": true, + "peer": true }, "node_modules/xmlchars": { "version": "2.2.0", @@ -7763,7 +7836,8 @@ "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==", "dev": true, "license": "MIT", - "optional": true + "optional": true, + "peer": true }, "node_modules/yaml": { "version": "2.3.1", diff --git a/src/components/object-definition.ts b/src/components/object-definition.ts index 90da30e..35bd6bb 100644 --- a/src/components/object-definition.ts +++ b/src/components/object-definition.ts @@ -5,6 +5,17 @@ import type { TypeDefinition, UnionTypeDefinition, ValueDescription } from './in import { extractDeclaration, isOptional, stringifyType } from '../shared/type-utils'; import { extractValueDescriptions } from './extract-value-descriptions'; +function getOriginalTypeName(rawTypeNode: ts.TypeNode) { + // If the type node is a type reference (like `ButtonGroupProps.Variant`), get its text + if (ts.isTypeReferenceNode(rawTypeNode) || ts.isQualifiedName(rawTypeNode)) { + return rawTypeNode.getText(); + } +} + +function trimQuotes(s: string) { + return s.replace(/^"(.+)"$/, '$1'); +} + function isArrayType(type: ts.Type) { const symbol = type.getSymbol(); if (!symbol) { @@ -21,6 +32,22 @@ export function getObjectDefinition( ): { type: string; inlineType?: TypeDefinition } { const realType = rawType.getNonNullableType(); const realTypeName = stringifyType(realType, checker); + + if (realType.flags & ts.TypeFlags.StringLiteral) { + // For string literals, try to get the original type name from the type node. + // This preserves user-defined type aliases like `ButtonGroupProps.Variant` + const name = (rawTypeNode && getOriginalTypeName(rawTypeNode)) || trimQuotes(realTypeName); + + return { + type: 'string', + inlineType: { + name, + type: 'union', + values: [trimQuotes(type)], + }, + }; + } + if ( realType.flags & ts.TypeFlags.String || realType.flags & ts.TypeFlags.Literal || diff --git a/test/components/complex-types.test.ts b/test/components/complex-types.test.ts index 89a1c63..09e3e4a 100644 --- a/test/components/complex-types.test.ts +++ b/test/components/complex-types.test.ts @@ -225,7 +225,12 @@ test('should parse string literal type as single-value union', () => { { name: 'alwaysSomething', optional: false, - type: '"something"', + type: 'string', + inlineType: { + name: 'something', + type: 'union', + values: ['something'], + }, }, ], }, @@ -233,7 +238,12 @@ test('should parse string literal type as single-value union', () => { { name: 'variant', description: 'This is variant', - type: '"icon"', + type: 'string', + inlineType: { + name: 'ButtonGroupProps.Variant', + type: 'union', + values: ['icon'], + }, optional: false, }, ]);