@renr/parcel-reporter-docgen 0.1.0-beta.11 → 0.1.0-beta.13
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/README.md +45 -1
- package/dist/esm/cli.mjs +12 -6
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/generate-props.d.mts +3 -1
- package/dist/esm/generate-props.d.mts.map +1 -1
- package/dist/esm/generate-props.mjs +112 -34
- package/dist/esm/generate-props.mjs.map +1 -1
- package/dist/esm/index.d.mts +2 -1
- package/dist/esm/type-expander.d.mts +15 -0
- package/dist/esm/type-expander.d.mts.map +1 -0
- package/dist/esm/type-expander.mjs +472 -0
- package/dist/esm/type-expander.mjs.map +1 -0
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -5,8 +5,9 @@ A Parcel reporter plugin that extracts UI component documentation and prop types
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- **Automated Prop Extraction**: Parses component props, types, descriptions, default values, and required status.
|
|
8
|
+
- **Structured Expanded Types**: Emits `type.expanded` metadata for generic mapped unions (`T | { [K in Keys]?: T }`), type aliases, utility objects (`Partial<Record<...>>`, `Omit<...>`), unions, and function signatures while keeping React/DOM stop types (`ReactNode`, `ElementType`, `Ref`, etc.) compact.
|
|
8
9
|
- **Compound Component Support**: Handles dot-notation subcomponents (`Dialog.Title`) and `Object.assign` assignment patterns (`Object.assign(Base, { Sub })`).
|
|
9
|
-
- **Incremental Caching**: Tracks
|
|
10
|
+
- **Incremental Caching**: Tracks modification times (`mtime`) across component sources, `tsconfig.json`, and the reporter itself to only reparse changed components (with a `--force` escape hatch).
|
|
10
11
|
- **Configurable TSConfig**: Supports custom `tsconfig.json` paths for complex workspaces.
|
|
11
12
|
|
|
12
13
|
## Installation
|
|
@@ -54,6 +55,22 @@ Add the `@renr/parcel-reporter-docgen` configuration object to your `package.jso
|
|
|
54
55
|
| `output` | `string` | No | `"docgen"` | Directory where JSON documentation files will be saved |
|
|
55
56
|
| `tsconfig` | `string` | No | `"./tsconfig.json"` | Relative path to the TypeScript config file to use for docgen parsing |
|
|
56
57
|
|
|
58
|
+
## CLI
|
|
59
|
+
|
|
60
|
+
You can also invoke the generator directly via `parcel-docgen` (reads defaults from `.parcelrc` or `package.json`):
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pnpm parcel-docgen --force
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
| Flag | Short | Description |
|
|
67
|
+
| ------------------- | ----- | ------------------------------------------------------------------- |
|
|
68
|
+
| `--source <glob>` | `-s` | Glob pattern for component source files |
|
|
69
|
+
| `--output <dir>` | `-o` | Output directory for generated JSON files |
|
|
70
|
+
| `--tsconfig <path>` | `-t` | Path to `tsconfig.json` |
|
|
71
|
+
| `--root <dir>` | `-r` | Project root directory (defaults to current working directory) |
|
|
72
|
+
| `--force` | `-f` | Regenerate all matching files, ignoring incremental `mtime` caching |
|
|
73
|
+
|
|
57
74
|
## Output Format
|
|
58
75
|
|
|
59
76
|
For each component, a JSON file `<ComponentName>.json` is generated:
|
|
@@ -72,6 +89,24 @@ For each component, a JSON file `<ComponentName>.json` is generated:
|
|
|
72
89
|
"defaultValue": { "value": "0" },
|
|
73
90
|
"description": "Initial number to start counting from.",
|
|
74
91
|
"shortPropTypeName": "number"
|
|
92
|
+
},
|
|
93
|
+
"align": {
|
|
94
|
+
"name": "align",
|
|
95
|
+
"required": false,
|
|
96
|
+
"type": {
|
|
97
|
+
"name": "MappedValue<\"center\" | \"end\" | \"start\", SlotKey> | undefined",
|
|
98
|
+
"expanded": {
|
|
99
|
+
"kind": "mapped-union",
|
|
100
|
+
"alias": "MappedValue",
|
|
101
|
+
"values": ["\"center\"", "\"end\"", "\"start\""],
|
|
102
|
+
"valueType": "\"center\" | \"end\" | \"start\"",
|
|
103
|
+
"keys": ["base", "compact", "wide"],
|
|
104
|
+
"formatted": "{\n base?: \"center\" | \"end\" | \"start\";\n compact?: \"center\" | \"end\" | \"start\";\n wide?: \"center\" | \"end\" | \"start\";\n}"
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"defaultValue": { "value": "start" },
|
|
108
|
+
"description": "Item alignment.",
|
|
109
|
+
"shortPropTypeName": "MappedValue"
|
|
75
110
|
}
|
|
76
111
|
},
|
|
77
112
|
"subcomponents": {
|
|
@@ -83,6 +118,15 @@ For each component, a JSON file `<ComponentName>.json` is generated:
|
|
|
83
118
|
}
|
|
84
119
|
```
|
|
85
120
|
|
|
121
|
+
### Expanded Type Metadata (`type.expanded`)
|
|
122
|
+
|
|
123
|
+
When TypeScript resolution adds clarity beyond the raw type name, `type.expanded` is emitted with one of the following shapes:
|
|
124
|
+
|
|
125
|
+
- **`mapped-union`**: Matches `T | { [K in Keys]?: T }` patterns. Includes `alias` (if named), `valueType`, `values` (when all scalar members are literals), `keys` in declaration order, and `formatted` as the resolved object shape.
|
|
126
|
+
- **`alias` | `object` | `union` | `function`**: Includes `formatted` with the resolved TypeScript type string.
|
|
127
|
+
|
|
128
|
+
Built-in and React stop types (such as `ReactNode`, `ElementType`, `Ref`, `CSSProperties`, and DOM elements) are kept unexpanded.
|
|
129
|
+
|
|
86
130
|
## License
|
|
87
131
|
|
|
88
132
|
MIT
|
package/dist/esm/cli.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { generateProps } from "./generate-props.mjs";
|
|
3
|
+
import fsSync from "fs";
|
|
3
4
|
import path from "path";
|
|
4
|
-
import fs from "fs";
|
|
5
5
|
import { parseArgs } from "util";
|
|
6
6
|
//#region src/cli.ts
|
|
7
7
|
const origin = "@renr/parcel-reporter-docgen";
|
|
8
8
|
function loadParcelRcConfig(rootDir) {
|
|
9
9
|
const parcelRcPath = path.join(rootDir, ".parcelrc");
|
|
10
|
-
if (!
|
|
10
|
+
if (!fsSync.existsSync(parcelRcPath)) return;
|
|
11
11
|
try {
|
|
12
|
-
const raw = JSON.parse(
|
|
12
|
+
const raw = JSON.parse(fsSync.readFileSync(parcelRcPath, "utf-8"));
|
|
13
13
|
if (Array.isArray(raw.reporters)) {
|
|
14
14
|
for (const entry of raw.reporters) if (typeof entry === "object" && entry !== null && entry.plugin === origin && entry.config) return entry.config;
|
|
15
15
|
}
|
|
@@ -17,9 +17,9 @@ function loadParcelRcConfig(rootDir) {
|
|
|
17
17
|
}
|
|
18
18
|
function loadPackageConfig(rootDir) {
|
|
19
19
|
const pkgPath = path.join(rootDir, "package.json");
|
|
20
|
-
if (!
|
|
20
|
+
if (!fsSync.existsSync(pkgPath)) return;
|
|
21
21
|
try {
|
|
22
|
-
return JSON.parse(
|
|
22
|
+
return JSON.parse(fsSync.readFileSync(pkgPath, "utf-8"));
|
|
23
23
|
} catch (_unused2) {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
@@ -43,6 +43,11 @@ async function main() {
|
|
|
43
43
|
root: {
|
|
44
44
|
type: "string",
|
|
45
45
|
short: "r"
|
|
46
|
+
},
|
|
47
|
+
force: {
|
|
48
|
+
type: "boolean",
|
|
49
|
+
short: "f",
|
|
50
|
+
default: false
|
|
46
51
|
}
|
|
47
52
|
},
|
|
48
53
|
strict: false
|
|
@@ -53,8 +58,9 @@ async function main() {
|
|
|
53
58
|
const source = (_ref = (_ref2 = typeof values.source === "string" ? values.source : void 0) !== null && _ref2 !== void 0 ? _ref2 : rcConfig === null || rcConfig === void 0 ? void 0 : rcConfig.source) !== null && _ref !== void 0 ? _ref : pkgConfig === null || pkgConfig === void 0 || (_pkgConfig$origin = pkgConfig[origin]) === null || _pkgConfig$origin === void 0 ? void 0 : _pkgConfig$origin.source;
|
|
54
59
|
const output = (_ref3 = (_ref4 = typeof values.output === "string" ? values.output : void 0) !== null && _ref4 !== void 0 ? _ref4 : rcConfig === null || rcConfig === void 0 ? void 0 : rcConfig.output) !== null && _ref3 !== void 0 ? _ref3 : pkgConfig === null || pkgConfig === void 0 || (_pkgConfig$origin2 = pkgConfig[origin]) === null || _pkgConfig$origin2 === void 0 ? void 0 : _pkgConfig$origin2.output;
|
|
55
60
|
const tsconfig = (_ref5 = (_ref6 = typeof values.tsconfig === "string" ? values.tsconfig : void 0) !== null && _ref6 !== void 0 ? _ref6 : rcConfig === null || rcConfig === void 0 ? void 0 : rcConfig.tsconfig) !== null && _ref5 !== void 0 ? _ref5 : pkgConfig === null || pkgConfig === void 0 || (_pkgConfig$origin3 = pkgConfig[origin]) === null || _pkgConfig$origin3 === void 0 ? void 0 : _pkgConfig$origin3.tsconfig;
|
|
61
|
+
const force = values.force === true;
|
|
56
62
|
if (!source) throw new Error(`No "${origin}" source found in .parcelrc or package.json.`);
|
|
57
|
-
await generateProps(source, rootDir, output || "docgen", (...args) => console.info(args.join(" ")), tsconfig);
|
|
63
|
+
await generateProps(source, rootDir, output || "docgen", (...args) => console.info(args.join(" ")), tsconfig, force);
|
|
58
64
|
}
|
|
59
65
|
main().catch((error) => {
|
|
60
66
|
console.error(error instanceof Error ? error.message : String(error));
|
package/dist/esm/cli.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.mjs","names":[],"sources":["../../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport fs from \"fs\";\nimport path from \"path\";\nimport { parseArgs } from \"util\";\nimport { generateProps } from \"./generate-props.js\";\n\nconst origin = \"@renr/parcel-reporter-docgen\";\n\ninterface DocgenPluginConfig {\n source?: string;\n output?: string;\n tsconfig?: string;\n}\n\ninterface PackageConfig {\n [origin]?: DocgenPluginConfig;\n}\n\nfunction loadParcelRcConfig(rootDir: string): DocgenPluginConfig | undefined {\n const parcelRcPath = path.join(rootDir, \".parcelrc\");\n if (!fs.existsSync(parcelRcPath)) {\n return undefined;\n }\n try {\n const raw = JSON.parse(fs.readFileSync(parcelRcPath, \"utf-8\")) as {\n reporters?: Array<\n string | { plugin?: string; config?: DocgenPluginConfig }\n >;\n };\n if (Array.isArray(raw.reporters)) {\n for (const entry of raw.reporters) {\n if (\n typeof entry === \"object\" &&\n entry !== null &&\n entry.plugin === origin &&\n entry.config\n ) {\n return entry.config;\n }\n }\n }\n } catch {\n // ignore parse errors\n }\n return undefined;\n}\n\nfunction loadPackageConfig(rootDir: string): PackageConfig | undefined {\n const pkgPath = path.join(rootDir, \"package.json\");\n if (!fs.existsSync(pkgPath)) {\n return undefined;\n }\n try {\n return JSON.parse(fs.readFileSync(pkgPath, \"utf-8\")) as PackageConfig;\n } catch {\n return undefined;\n }\n}\n\nasync function main() {\n const { values } = parseArgs({\n options: {\n source: { type: \"string\", short: \"s\" },\n output: { type: \"string\", short: \"o\" },\n tsconfig: { type: \"string\", short: \"t\" },\n root: { type: \"string\", short: \"r\" },\n },\n strict: false,\n });\n\n const rootDir =\n typeof values.root === \"string\"\n ? path.resolve(process.cwd(), values.root)\n : process.cwd();\n\n const rcConfig = loadParcelRcConfig(rootDir);\n const pkgConfig = loadPackageConfig(rootDir);\n\n const source =\n (typeof values.source === \"string\" ? values.source : undefined) ??\n rcConfig?.source ??\n pkgConfig?.[origin]?.source;\n\n const output =\n (typeof values.output === \"string\" ? values.output : undefined) ??\n rcConfig?.output ??\n pkgConfig?.[origin]?.output;\n\n const tsconfig =\n (typeof values.tsconfig === \"string\" ? values.tsconfig : undefined) ??\n rcConfig?.tsconfig ??\n pkgConfig?.[origin]?.tsconfig;\n\n if (!source) {\n throw new Error(\n `No \"${origin}\" source found in .parcelrc or package.json.`\n );\n }\n\n await generateProps(\n source,\n rootDir,\n output || \"docgen\",\n (...args) => console.info(args.join(\" \")),\n tsconfig\n );\n}\n\nmain().catch((error: unknown) => {\n console.error(error instanceof Error ? error.message : String(error));\n process.exit(1);\n});\n"],"mappings":";;;;;;AAMA,MAAM,SAAS;AAYf,SAAS,mBAAmB,SAAiD;CAC3E,MAAM,eAAe,KAAK,KAAK,SAAS,WAAW;CACnD,IAAI,
|
|
1
|
+
{"version":3,"file":"cli.mjs","names":["fs"],"sources":["../../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport fs from \"fs\";\nimport path from \"path\";\nimport { parseArgs } from \"util\";\nimport { generateProps } from \"./generate-props.js\";\n\nconst origin = \"@renr/parcel-reporter-docgen\";\n\ninterface DocgenPluginConfig {\n source?: string;\n output?: string;\n tsconfig?: string;\n}\n\ninterface PackageConfig {\n [origin]?: DocgenPluginConfig;\n}\n\nfunction loadParcelRcConfig(rootDir: string): DocgenPluginConfig | undefined {\n const parcelRcPath = path.join(rootDir, \".parcelrc\");\n if (!fs.existsSync(parcelRcPath)) {\n return undefined;\n }\n try {\n const raw = JSON.parse(fs.readFileSync(parcelRcPath, \"utf-8\")) as {\n reporters?: Array<\n string | { plugin?: string; config?: DocgenPluginConfig }\n >;\n };\n if (Array.isArray(raw.reporters)) {\n for (const entry of raw.reporters) {\n if (\n typeof entry === \"object\" &&\n entry !== null &&\n entry.plugin === origin &&\n entry.config\n ) {\n return entry.config;\n }\n }\n }\n } catch {\n // ignore parse errors\n }\n return undefined;\n}\n\nfunction loadPackageConfig(rootDir: string): PackageConfig | undefined {\n const pkgPath = path.join(rootDir, \"package.json\");\n if (!fs.existsSync(pkgPath)) {\n return undefined;\n }\n try {\n return JSON.parse(fs.readFileSync(pkgPath, \"utf-8\")) as PackageConfig;\n } catch {\n return undefined;\n }\n}\n\nasync function main() {\n const { values } = parseArgs({\n options: {\n source: { type: \"string\", short: \"s\" },\n output: { type: \"string\", short: \"o\" },\n tsconfig: { type: \"string\", short: \"t\" },\n root: { type: \"string\", short: \"r\" },\n force: { type: \"boolean\", short: \"f\", default: false },\n },\n strict: false,\n });\n\n const rootDir =\n typeof values.root === \"string\"\n ? path.resolve(process.cwd(), values.root)\n : process.cwd();\n\n const rcConfig = loadParcelRcConfig(rootDir);\n const pkgConfig = loadPackageConfig(rootDir);\n\n const source =\n (typeof values.source === \"string\" ? values.source : undefined) ??\n rcConfig?.source ??\n pkgConfig?.[origin]?.source;\n\n const output =\n (typeof values.output === \"string\" ? values.output : undefined) ??\n rcConfig?.output ??\n pkgConfig?.[origin]?.output;\n\n const tsconfig =\n (typeof values.tsconfig === \"string\" ? values.tsconfig : undefined) ??\n rcConfig?.tsconfig ??\n pkgConfig?.[origin]?.tsconfig;\n\n const force = values.force === true;\n\n if (!source) {\n throw new Error(\n `No \"${origin}\" source found in .parcelrc or package.json.`\n );\n }\n\n await generateProps(\n source,\n rootDir,\n output || \"docgen\",\n (...args) => console.info(args.join(\" \")),\n tsconfig,\n force\n );\n}\n\nmain().catch((error: unknown) => {\n console.error(error instanceof Error ? error.message : String(error));\n process.exit(1);\n});\n"],"mappings":";;;;;;AAMA,MAAM,SAAS;AAYf,SAAS,mBAAmB,SAAiD;CAC3E,MAAM,eAAe,KAAK,KAAK,SAAS,WAAW;CACnD,IAAI,CAACA,OAAG,WAAW,YAAY,GAC7B;CAEF,IAAI;EACF,MAAM,MAAM,KAAK,MAAMA,OAAG,aAAa,cAAc,OAAO,CAAC;EAK7D,IAAI,MAAM,QAAQ,IAAI,SAAS,GACxB;QAAA,MAAM,SAAS,IAAI,WACtB,IACE,OAAO,UAAU,YACjB,UAAU,QACV,MAAM,WAAW,UACjB,MAAM,QAEN,OAAO,MAAM;EAAA;CAIrB,SAAA,SAAQ,CAER;AAEF;AAEA,SAAS,kBAAkB,SAA4C;CACrE,MAAM,UAAU,KAAK,KAAK,SAAS,cAAc;CACjD,IAAI,CAACA,OAAG,WAAW,OAAO,GACxB;CAEF,IAAI;EACF,OAAO,KAAK,MAAMA,OAAG,aAAa,SAAS,OAAO,CAAC;CACrD,SAAA,UAAQ;EACN;CACF;AACF;AAEA,eAAe,OAAO;;CACpB,MAAM,EAAE,WAAW,UAAU;EAC3B,SAAS;GACP,QAAQ;IAAE,MAAM;IAAU,OAAO;GAAI;GACrC,QAAQ;IAAE,MAAM;IAAU,OAAO;GAAI;GACrC,UAAU;IAAE,MAAM;IAAU,OAAO;GAAI;GACvC,MAAM;IAAE,MAAM;IAAU,OAAO;GAAI;GACnC,OAAO;IAAE,MAAM;IAAW,OAAO;IAAK,SAA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GAAG,CAAC,GACxC,UACA,KACF;AACF;AAEA,KAAK,CAAC,CAAC,OAAO,UAAmB;CAC/B,QAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;CACpE,QAAQ,KAAK,CAAC;AAChB,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { ExpandedPropType } from "./type-expander.mjs";
|
|
1
2
|
//#region src/generate-props.d.ts
|
|
2
|
-
export declare function generateProps(pagesPattern: string, rootDir: string, outputPath?: string, log?: (...args: unknown[]) => void, customTsconfigPath?: string): Promise<void>;
|
|
3
|
+
export declare function generateProps(pagesPattern: string, rootDir: string, outputPath?: string, log?: (...args: unknown[]) => void, customTsconfigPath?: string, force?: boolean): Promise<void>;
|
|
3
4
|
//#endregion
|
|
5
|
+
export type { ExpandedPropType };
|
|
4
6
|
//# sourceMappingURL=generate-props.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-props.d.mts","names":[],"sources":["../../src/generate-props.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate-props.d.mts","names":[],"sources":["../../src/generate-props.ts"],"mappings":";;wBAuEsB,cACpB,sBACA,iBACA,qBACA,UAAS,0BACT,6BACA,kBAAsB"}
|
|
@@ -1,14 +1,35 @@
|
|
|
1
|
+
import { compareStrings, expandPropType, normalizeDisplayType, resolveComponentPropTypes, splitTopLevelUnion, stripTopLevelUndefined } from "./type-expander.mjs";
|
|
2
|
+
import fsSync from "fs";
|
|
1
3
|
import fs from "fs/promises";
|
|
2
4
|
import path from "path";
|
|
3
|
-
import {
|
|
5
|
+
import { withCompilerOptions } from "react-docgen-typescript";
|
|
4
6
|
import { glob } from "tinyglobby";
|
|
5
7
|
import ts from "typescript";
|
|
6
8
|
import { fileURLToPath } from "url";
|
|
7
9
|
//#region src/generate-props.ts
|
|
8
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
-
path.dirname(__filename);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
10
12
|
const fileMtimeCache = /* @__PURE__ */ new Map();
|
|
11
|
-
|
|
13
|
+
function loadCompilerOptions(tsconfigPath) {
|
|
14
|
+
const basePath = path.dirname(tsconfigPath);
|
|
15
|
+
const { config, error } = ts.readConfigFile(tsconfigPath, (filename) => fsSync.readFileSync(filename, "utf8"));
|
|
16
|
+
if (error !== void 0) throw new Error(`Cannot load custom tsconfig.json from provided path: ${tsconfigPath}, with error code: ${error.code}, message: ${ts.flattenDiagnosticMessageText(error.messageText, "\n")}`);
|
|
17
|
+
const parsed = ts.parseJsonConfigFileContent(config, ts.sys, basePath, {}, tsconfigPath);
|
|
18
|
+
if (parsed.errors && parsed.errors.length > 0) {
|
|
19
|
+
const first = parsed.errors[0];
|
|
20
|
+
throw new Error(`TS${first.code}: ${ts.flattenDiagnosticMessageText(first.messageText, "\n")}`);
|
|
21
|
+
}
|
|
22
|
+
return parsed.options;
|
|
23
|
+
}
|
|
24
|
+
async function getMaxExistingMtimeMs(paths) {
|
|
25
|
+
let maxMtime = 0;
|
|
26
|
+
for (const targetPath of paths) try {
|
|
27
|
+
const stat = await fs.stat(targetPath);
|
|
28
|
+
if (stat.mtimeMs > maxMtime) maxMtime = stat.mtimeMs;
|
|
29
|
+
} catch (_unused) {}
|
|
30
|
+
return maxMtime;
|
|
31
|
+
}
|
|
32
|
+
async function generateProps(pagesPattern, rootDir, outputPath = "docgen", log = console.log, customTsconfigPath, force = false) {
|
|
12
33
|
const files = (await glob(pagesPattern, { cwd: rootDir })).sort(compareStrings);
|
|
13
34
|
if (files.length === 0) {
|
|
14
35
|
log(`No files found for pattern: ${pagesPattern}`);
|
|
@@ -16,6 +37,13 @@ async function generateProps(pagesPattern, rootDir, outputPath = "docgen", log =
|
|
|
16
37
|
}
|
|
17
38
|
const resolvedOutputPath = path.resolve(rootDir, outputPath);
|
|
18
39
|
await fs.mkdir(resolvedOutputPath, { recursive: true });
|
|
40
|
+
const resolvedTsconfigPath = customTsconfigPath ? path.resolve(rootDir, customTsconfigPath) : path.resolve(rootDir, "./tsconfig.json");
|
|
41
|
+
const ext = path.extname(__filename);
|
|
42
|
+
const dependencyMtimeMs = force ? 0 : await getMaxExistingMtimeMs([
|
|
43
|
+
resolvedTsconfigPath,
|
|
44
|
+
__filename,
|
|
45
|
+
path.join(__dirname, `type-expander${ext}`)
|
|
46
|
+
]);
|
|
19
47
|
const filesToProcess = [];
|
|
20
48
|
for (const file of files) {
|
|
21
49
|
const filePath = path.resolve(rootDir, file);
|
|
@@ -23,31 +51,34 @@ async function generateProps(pagesPattern, rootDir, outputPath = "docgen", log =
|
|
|
23
51
|
const outputFilePath = path.join(resolvedOutputPath, `${componentName}.json`);
|
|
24
52
|
try {
|
|
25
53
|
const sourceStat = await fs.stat(filePath);
|
|
26
|
-
const
|
|
54
|
+
const requiredMtimeMs = Math.max(sourceStat.mtimeMs, dependencyMtimeMs);
|
|
55
|
+
const cacheKey = `${filePath}\0${outputFilePath}`;
|
|
56
|
+
const cachedMtime = fileMtimeCache.get(cacheKey);
|
|
27
57
|
let isUpToDate = false;
|
|
28
|
-
try {
|
|
58
|
+
if (!force) try {
|
|
29
59
|
const outStat = await fs.stat(outputFilePath);
|
|
30
|
-
if (cachedMtime !== void 0 && cachedMtime ===
|
|
60
|
+
if (cachedMtime !== void 0 && cachedMtime === requiredMtimeMs || outStat.mtimeMs >= requiredMtimeMs) {
|
|
31
61
|
isUpToDate = true;
|
|
32
|
-
fileMtimeCache.set(
|
|
62
|
+
fileMtimeCache.set(cacheKey, requiredMtimeMs);
|
|
33
63
|
}
|
|
34
|
-
} catch (
|
|
64
|
+
} catch (_unused2) {}
|
|
35
65
|
if (isUpToDate) continue;
|
|
36
66
|
filesToProcess.push({
|
|
37
67
|
relFile: file,
|
|
38
68
|
absPath: filePath,
|
|
39
69
|
componentName
|
|
40
70
|
});
|
|
41
|
-
fileMtimeCache.set(
|
|
42
|
-
} catch (
|
|
71
|
+
fileMtimeCache.set(cacheKey, requiredMtimeMs);
|
|
72
|
+
} catch (_unused3) {}
|
|
43
73
|
}
|
|
44
74
|
if (filesToProcess.length === 0) return;
|
|
45
75
|
log(`Found ${filesToProcess.length} changed file(s) for pattern: ${pagesPattern}`);
|
|
46
|
-
const
|
|
47
|
-
const docgenParser =
|
|
76
|
+
const compilerOptions = loadCompilerOptions(resolvedTsconfigPath);
|
|
77
|
+
const docgenParser = withCompilerOptions(compilerOptions, {
|
|
48
78
|
shouldExtractLiteralValuesFromEnum: true,
|
|
49
79
|
shouldSortUnions: true,
|
|
50
80
|
savePropValueAsString: true,
|
|
81
|
+
shouldIncludeExpression: true,
|
|
51
82
|
propFilter: (prop) => {
|
|
52
83
|
if (Array.isArray(prop.declarations) && prop.declarations[0]) {
|
|
53
84
|
if (prop.declarations[0].fileName.includes("node_modules/@types/react")) {
|
|
@@ -59,7 +90,20 @@ async function generateProps(pagesPattern, rootDir, outputPath = "docgen", log =
|
|
|
59
90
|
});
|
|
60
91
|
try {
|
|
61
92
|
const absPaths = filesToProcess.map((f) => f.absPath);
|
|
62
|
-
const
|
|
93
|
+
const program = ts.createProgram(absPaths, compilerOptions);
|
|
94
|
+
const checker = program.getTypeChecker();
|
|
95
|
+
const allDocs = docgenParser.parseWithProgramProvider(absPaths, () => program);
|
|
96
|
+
const propTypesByDoc = /* @__PURE__ */ new WeakMap();
|
|
97
|
+
const getPropTypesForDoc = (doc) => {
|
|
98
|
+
if (!doc) return void 0;
|
|
99
|
+
let cached = propTypesByDoc.get(doc);
|
|
100
|
+
if (!cached) {
|
|
101
|
+
var _doc$expression;
|
|
102
|
+
cached = resolveComponentPropTypes((_doc$expression = doc.expression) !== null && _doc$expression !== void 0 ? _doc$expression : doc.rootExpression, checker);
|
|
103
|
+
propTypesByDoc.set(doc, cached);
|
|
104
|
+
}
|
|
105
|
+
return cached;
|
|
106
|
+
};
|
|
63
107
|
const docsByFilePath = /* @__PURE__ */ new Map();
|
|
64
108
|
for (const doc of allDocs) if (doc.filePath) {
|
|
65
109
|
const key = path.resolve(doc.filePath);
|
|
@@ -75,11 +119,15 @@ async function generateProps(pagesPattern, rootDir, outputPath = "docgen", log =
|
|
|
75
119
|
let primaryDoc = fileDocs.find((d) => d.displayName === componentName) || (assignedInfo.baseIdentifier ? fileDocs.find((d) => d.displayName === assignedInfo.baseIdentifier) : void 0);
|
|
76
120
|
if (primaryDoc) usedDocs.add(primaryDoc);
|
|
77
121
|
let primaryProps = primaryDoc ? primaryDoc.props : {};
|
|
122
|
+
let primaryPropsDoc = primaryDoc;
|
|
78
123
|
if (assignedInfo.baseIdentifier) {
|
|
79
124
|
const baseDoc = fileDocs.find((d) => d.displayName === assignedInfo.baseIdentifier);
|
|
80
125
|
if (baseDoc) {
|
|
81
126
|
if (assignedInfo.baseIdentifier !== assignedInfo.subcomponentsMap.get("Root")) usedDocs.add(baseDoc);
|
|
82
|
-
if (primaryDoc && Object.keys(baseDoc.props).length > Object.keys(primaryProps).length)
|
|
127
|
+
if (primaryDoc && Object.keys(baseDoc.props).length > Object.keys(primaryProps).length) {
|
|
128
|
+
primaryProps = baseDoc.props;
|
|
129
|
+
primaryPropsDoc = baseDoc;
|
|
130
|
+
}
|
|
83
131
|
}
|
|
84
132
|
}
|
|
85
133
|
const subcomponents = {};
|
|
@@ -91,7 +139,7 @@ async function generateProps(pagesPattern, rootDir, outputPath = "docgen", log =
|
|
|
91
139
|
subcomponents[subName] = {
|
|
92
140
|
name: `${componentName}.${subName}`,
|
|
93
141
|
description: subDoc.description || void 0,
|
|
94
|
-
props: formatProps(subDoc.props)
|
|
142
|
+
props: formatProps(subDoc.props, getPropTypesForDoc(subDoc), checker)
|
|
95
143
|
};
|
|
96
144
|
}
|
|
97
145
|
}
|
|
@@ -109,7 +157,7 @@ async function generateProps(pagesPattern, rootDir, outputPath = "docgen", log =
|
|
|
109
157
|
subcomponents[subName] = {
|
|
110
158
|
name: `${componentName}.${subName}`,
|
|
111
159
|
description: doc.description || void 0,
|
|
112
|
-
props: formatProps(doc.props)
|
|
160
|
+
props: formatProps(doc.props, getPropTypesForDoc(doc), checker)
|
|
113
161
|
};
|
|
114
162
|
}
|
|
115
163
|
}
|
|
@@ -118,8 +166,9 @@ async function generateProps(pagesPattern, rootDir, outputPath = "docgen", log =
|
|
|
118
166
|
else if (!primaryDoc) {
|
|
119
167
|
primaryDoc = fileDocs.find((d) => Object.keys(d.props).length > 0) || fileDocs[0];
|
|
120
168
|
primaryProps = primaryDoc ? primaryDoc.props : {};
|
|
169
|
+
primaryPropsDoc = primaryDoc;
|
|
121
170
|
}
|
|
122
|
-
const formattedPrimaryProps = promotedRoot ? promotedRoot.props : formatProps(primaryProps);
|
|
171
|
+
const formattedPrimaryProps = promotedRoot ? promotedRoot.props : formatProps(primaryProps, getPropTypesForDoc(primaryPropsDoc), checker);
|
|
123
172
|
const componentJSON = JSON.stringify({
|
|
124
173
|
name: promotedRoot ? promotedRoot.name : componentName,
|
|
125
174
|
description: (promotedRoot ? promotedRoot.description : primaryDoc === null || primaryDoc === void 0 ? void 0 : primaryDoc.description) || void 0,
|
|
@@ -136,7 +185,7 @@ async function generateProps(pagesPattern, rootDir, outputPath = "docgen", log =
|
|
|
136
185
|
log(`Error generating props: ${err.message}`);
|
|
137
186
|
}
|
|
138
187
|
}
|
|
139
|
-
function getShortPropType(name, type) {
|
|
188
|
+
function getShortPropType(name, type, expanded) {
|
|
140
189
|
if (/^(on|get)[A-Z].*/.test(name)) return {
|
|
141
190
|
type: "function",
|
|
142
191
|
detailedType: true
|
|
@@ -153,7 +202,16 @@ function getShortPropType(name, type) {
|
|
|
153
202
|
type: "ReactElement | function",
|
|
154
203
|
detailedType: true
|
|
155
204
|
};
|
|
156
|
-
if (
|
|
205
|
+
if ((expanded === null || expanded === void 0 ? void 0 : expanded.kind) === "mapped-union") {
|
|
206
|
+
var _expanded$alias;
|
|
207
|
+
return {
|
|
208
|
+
type: (_expanded$alias = expanded.alias) !== null && _expanded$alias !== void 0 ? _expanded$alias : "Union",
|
|
209
|
+
detailedType: true
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
const cleanType = stripTopLevelUndefined(type);
|
|
213
|
+
const topLevelParts = splitTopLevelUnion(cleanType);
|
|
214
|
+
if (name.endsWith("Ref") || name === "children" || cleanType === "boolean" || cleanType === "string" || cleanType === "number" || topLevelParts.length <= 1 || topLevelParts.length < 3 && cleanType.length < 30) return {
|
|
157
215
|
type,
|
|
158
216
|
detailedType: false
|
|
159
217
|
};
|
|
@@ -162,11 +220,7 @@ function getShortPropType(name, type) {
|
|
|
162
220
|
detailedType: true
|
|
163
221
|
};
|
|
164
222
|
}
|
|
165
|
-
function
|
|
166
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
167
|
-
}
|
|
168
|
-
function sortUnionString(str) {
|
|
169
|
-
if (!str.includes("|")) return str;
|
|
223
|
+
function splitTopLevelCommas(str) {
|
|
170
224
|
const parts = [];
|
|
171
225
|
let current = "";
|
|
172
226
|
let depthParen = 0;
|
|
@@ -181,7 +235,7 @@ function sortUnionString(str) {
|
|
|
181
235
|
if (ch === inQuote && str[i - 1] !== "\\") inQuote = null;
|
|
182
236
|
continue;
|
|
183
237
|
}
|
|
184
|
-
if (ch === "\"" || ch === "'") {
|
|
238
|
+
if (ch === "\"" || ch === "'" || ch === "`") {
|
|
185
239
|
inQuote = ch;
|
|
186
240
|
current += ch;
|
|
187
241
|
continue;
|
|
@@ -194,13 +248,28 @@ function sortUnionString(str) {
|
|
|
194
248
|
else if (ch === "}") depthBrace = Math.max(0, depthBrace - 1);
|
|
195
249
|
else if (ch === "[") depthBracket++;
|
|
196
250
|
else if (ch === "]") depthBracket = Math.max(0, depthBracket - 1);
|
|
197
|
-
if (ch === "
|
|
251
|
+
if (ch === "," && depthParen === 0 && depthAngle === 0 && depthBrace === 0 && depthBracket === 0) {
|
|
198
252
|
parts.push(current.trim());
|
|
199
253
|
current = "";
|
|
200
254
|
} else current += ch;
|
|
201
255
|
}
|
|
202
256
|
parts.push(current.trim());
|
|
203
|
-
|
|
257
|
+
return parts;
|
|
258
|
+
}
|
|
259
|
+
function sortGenericTypeArgs(str) {
|
|
260
|
+
const openIdx = str.indexOf("<");
|
|
261
|
+
if (openIdx === -1 || !str.endsWith(">")) return str;
|
|
262
|
+
const prefix = str.slice(0, openIdx);
|
|
263
|
+
if (!/^[A-Za-z_$][A-Za-z0-9_$.]*$/.test(prefix)) return str;
|
|
264
|
+
return `${prefix}<${splitTopLevelCommas(str.slice(openIdx + 1, -1)).map((arg) => sortUnionString(arg)).join(", ")}>`;
|
|
265
|
+
}
|
|
266
|
+
function sortUnionString(str) {
|
|
267
|
+
if (!str.includes("|")) return str;
|
|
268
|
+
const parts = splitTopLevelUnion(str).map((part) => sortGenericTypeArgs(part));
|
|
269
|
+
if (parts.length <= 1) {
|
|
270
|
+
var _parts$;
|
|
271
|
+
return (_parts$ = parts[0]) !== null && _parts$ !== void 0 ? _parts$ : str;
|
|
272
|
+
}
|
|
204
273
|
parts.sort((a, b) => {
|
|
205
274
|
if (a === "undefined" && b !== "undefined") return 1;
|
|
206
275
|
if (b === "undefined" && a !== "undefined") return -1;
|
|
@@ -208,20 +277,29 @@ function sortUnionString(str) {
|
|
|
208
277
|
});
|
|
209
278
|
return parts.join(" | ");
|
|
210
279
|
}
|
|
211
|
-
function formatProps(rawProps) {
|
|
280
|
+
function formatProps(rawProps, propTypes, checker) {
|
|
212
281
|
const props = {};
|
|
213
282
|
const sortedPropNames = Object.keys(rawProps).sort(compareStrings);
|
|
214
283
|
for (const propName of sortedPropNames) {
|
|
215
284
|
const rawProp = rawProps[propName];
|
|
216
285
|
if (!rawProp) continue;
|
|
217
|
-
const prop = {
|
|
286
|
+
const prop = {
|
|
287
|
+
...rawProp,
|
|
288
|
+
type: { ...rawProp.type },
|
|
289
|
+
shortPropTypeName: null
|
|
290
|
+
};
|
|
218
291
|
if (prop.type && prop.type.name) {
|
|
219
|
-
|
|
220
|
-
if (typeof prop.type.raw === "string") prop.type.raw = sortUnionString(prop.type.raw);
|
|
221
|
-
const sortedTypeName = sortUnionString(prop.type.name);
|
|
222
|
-
const
|
|
292
|
+
var _prop$type$raw;
|
|
293
|
+
if (typeof prop.type.raw === "string") prop.type.raw = sortUnionString(normalizeDisplayType(prop.type.raw));
|
|
294
|
+
const sortedTypeName = sortUnionString(normalizeDisplayType(prop.type.name));
|
|
295
|
+
const resolved = propTypes === null || propTypes === void 0 ? void 0 : propTypes.get(propName);
|
|
296
|
+
const expanded = resolved && checker ? expandPropType(resolved.type, (_prop$type$raw = prop.type.raw) !== null && _prop$type$raw !== void 0 ? _prop$type$raw : sortedTypeName, prop.type.name === "enum", checker, resolved.locationNode) : void 0;
|
|
297
|
+
if (expanded) prop.type.expanded = expanded;
|
|
298
|
+
const { type: shortPropTypeName, detailedType } = getShortPropType(propName, sortedTypeName, expanded);
|
|
223
299
|
const hasExpandedType = Boolean(detailedType);
|
|
224
|
-
|
|
300
|
+
const topLevelParts = splitTopLevelUnion(sortedTypeName);
|
|
301
|
+
const nonUndefTopLevelCount = topLevelParts.filter((part) => part !== "undefined").length;
|
|
302
|
+
prop.type.name = hasExpandedType && nonUndefTopLevelCount > 3 ? topLevelParts.map((line) => `| ${line}\n`).join("") : sortedTypeName;
|
|
225
303
|
prop.shortPropTypeName = hasExpandedType ? shortPropTypeName : null;
|
|
226
304
|
}
|
|
227
305
|
props[propName] = prop;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-props.mjs","names":[],"sources":["../../src/generate-props.ts"],"sourcesContent":["import fs from \"fs/promises\";\nimport path from \"path\";\nimport { PropItem, withCustomConfig } from \"react-docgen-typescript\";\nimport { glob } from \"tinyglobby\";\nimport ts from \"typescript\";\nimport { fileURLToPath } from \"url\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\n// cache for watch mode across buildStart events\nconst fileMtimeCache = new Map<string, number>();\n\nexport async function generateProps(\n pagesPattern: string,\n rootDir: string,\n outputPath: string = \"docgen\",\n log: (...args: unknown[]) => void = console.log,\n customTsconfigPath?: string\n) {\n const files = (\n await glob(pagesPattern, {\n cwd: rootDir,\n })\n ).sort(compareStrings);\n\n if (files.length === 0) {\n log(`No files found for pattern: ${pagesPattern}`);\n return;\n }\n\n const resolvedOutputPath = path.resolve(rootDir, outputPath);\n await fs.mkdir(resolvedOutputPath, { recursive: true });\n\n const filesToProcess: {\n relFile: string;\n absPath: string;\n componentName: string;\n }[] = [];\n\n for (const file of files) {\n const filePath = path.resolve(rootDir, file);\n const componentName = path.basename(file, path.extname(file));\n const outputFilePath = path.join(\n resolvedOutputPath,\n `${componentName}.json`\n );\n\n try {\n const sourceStat = await fs.stat(filePath);\n const cachedMtime = fileMtimeCache.get(filePath);\n\n let isUpToDate = false;\n try {\n const outStat = await fs.stat(outputFilePath);\n if (\n (cachedMtime !== undefined && cachedMtime === sourceStat.mtimeMs) ||\n outStat.mtimeMs >= sourceStat.mtimeMs\n ) {\n isUpToDate = true;\n fileMtimeCache.set(filePath, sourceStat.mtimeMs);\n }\n } catch {\n // output file does not exist\n }\n\n if (isUpToDate) {\n continue;\n }\n\n filesToProcess.push({\n relFile: file,\n absPath: filePath,\n componentName,\n });\n fileMtimeCache.set(filePath, sourceStat.mtimeMs);\n } catch {\n // source file not accessible\n }\n }\n\n if (filesToProcess.length === 0) {\n return;\n }\n\n log(\n `Found ${filesToProcess.length} changed file(s) for pattern: ${pagesPattern}`\n );\n\n const resolvedTsconfigPath = customTsconfigPath\n ? path.resolve(rootDir, customTsconfigPath)\n : path.resolve(rootDir, \"./tsconfig.json\");\n\n const docgenParser = withCustomConfig(resolvedTsconfigPath, {\n shouldExtractLiteralValuesFromEnum: true,\n shouldSortUnions: true,\n savePropValueAsString: true,\n propFilter: (prop) => {\n if (Array.isArray(prop.declarations) && prop.declarations[0]) {\n const declaration = prop.declarations[0];\n\n if (declaration.fileName.includes(\"node_modules/@types/react\")) {\n if (prop.name !== \"ref\" && prop.name !== \"className\") {\n return false;\n }\n }\n }\n return true;\n },\n });\n\n try {\n const absPaths = filesToProcess.map((f) => f.absPath);\n const allDocs = docgenParser.parse(absPaths);\n\n const docsByFilePath = new Map<string, typeof allDocs>();\n for (const doc of allDocs) {\n if (doc.filePath) {\n const key = path.resolve(doc.filePath);\n const list = docsByFilePath.get(key) || [];\n list.push(doc);\n docsByFilePath.set(key, list);\n }\n }\n\n await Promise.all(\n filesToProcess.map(async ({ relFile, absPath, componentName }) => {\n log(`parsing file: : ${relFile}`);\n\n const fileDocs = docsByFilePath.get(path.resolve(absPath)) || [];\n\n // Check if the component was composed using Object.assign or exports compound parts\n const sourceText = await fs.readFile(absPath, \"utf-8\");\n const assignedInfo = getAssignedInfo(sourceText, componentName);\n\n const usedDocs = new Set<(typeof fileDocs)[number]>();\n\n // 1. Identify explicit primary component doc matching componentName or assigned base\n let primaryDoc =\n fileDocs.find((d) => d.displayName === componentName) ||\n (assignedInfo.baseIdentifier\n ? fileDocs.find(\n (d) => d.displayName === assignedInfo.baseIdentifier\n )\n : undefined);\n\n if (primaryDoc) {\n usedDocs.add(primaryDoc);\n }\n\n // If primaryDoc was created by Object.assign and lost props, recover from base\n let primaryProps = primaryDoc ? primaryDoc.props : {};\n if (assignedInfo.baseIdentifier) {\n const baseDoc = fileDocs.find(\n (d) => d.displayName === assignedInfo.baseIdentifier\n );\n if (baseDoc) {\n if (\n assignedInfo.baseIdentifier !==\n assignedInfo.subcomponentsMap.get(\"Root\")\n ) {\n usedDocs.add(baseDoc);\n }\n if (\n primaryDoc &&\n Object.keys(baseDoc.props).length >\n Object.keys(primaryProps).length\n ) {\n primaryProps = baseDoc.props;\n }\n }\n }\n\n // 2. Identify subcomponents (including Root if present)\n const subcomponents: Record<\n string,\n {\n name: string;\n description?: string;\n props: ReturnType<typeof formatProps>;\n }\n > = {};\n\n // a) Handle subcomponents explicitly assigned or exported\n for (const [subName, targetName] of assignedInfo.subcomponentsMap) {\n if (subName === componentName) continue;\n const subDoc = fileDocs.find(\n (d) =>\n d.displayName === targetName ||\n d.displayName === `${componentName}.${subName}` ||\n d.displayName === `${componentName}${subName}` ||\n d.displayName === subName\n );\n if (subDoc) {\n usedDocs.add(subDoc);\n subcomponents[subName] = {\n name: `${componentName}.${subName}`,\n description: subDoc.description || undefined,\n props: formatProps(subDoc.props),\n };\n }\n }\n\n const hasRoot =\n Boolean(subcomponents.Root) ||\n fileDocs.some(\n (d) =>\n d.displayName === \"Root\" ||\n d.displayName === `${componentName}Root` ||\n d.displayName === `${componentName}.Root`\n );\n\n // b) Handle subcomponents matching standard React dot notation or component prefix\n for (const doc of fileDocs) {\n if (usedDocs.has(doc)) continue;\n\n let subName: string | undefined;\n if (doc.displayName.startsWith(`${componentName}.`)) {\n subName = doc.displayName.slice(componentName.length + 1);\n } else if (\n doc.displayName.startsWith(componentName) &&\n doc.displayName.length > componentName.length\n ) {\n subName = doc.displayName.slice(componentName.length);\n } else if (hasRoot) {\n subName = doc.displayName;\n }\n\n if (subName && subName !== componentName) {\n const existing = subcomponents[subName];\n if (\n existing &&\n Object.keys(existing.props).length >=\n Object.keys(doc.props).length\n ) {\n continue;\n }\n\n usedDocs.add(doc);\n subcomponents[subName] = {\n name: `${componentName}.${subName}`,\n description: doc.description || undefined,\n props: formatProps(doc.props),\n };\n }\n }\n\n const hasDistinctPrimary =\n Boolean(primaryDoc) &&\n Object.keys(primaryProps).length > 0 &&\n primaryDoc?.displayName !== \"Root\" &&\n primaryDoc?.displayName !== `${componentName}Root` &&\n primaryDoc?.displayName !== `${componentName}.Root` &&\n assignedInfo.baseIdentifier !==\n assignedInfo.subcomponentsMap.get(\"Root\");\n\n // Promote Root subcomponent to primary component only when no distinct primary component exists\n const promotedRoot =\n !hasDistinctPrimary && subcomponents.Root\n ? subcomponents.Root\n : undefined;\n if (promotedRoot) {\n delete subcomponents.Root;\n } else if (!primaryDoc) {\n primaryDoc =\n fileDocs.find((d) => Object.keys(d.props).length > 0) ||\n fileDocs[0];\n primaryProps = primaryDoc ? primaryDoc.props : {};\n }\n\n const formattedPrimaryProps = promotedRoot\n ? promotedRoot.props\n : formatProps(primaryProps);\n\n const componentJSON = JSON.stringify(\n {\n name: promotedRoot ? promotedRoot.name : componentName,\n description:\n (promotedRoot\n ? promotedRoot.description\n : primaryDoc?.description) || undefined,\n path: relFile.replace(/\\\\/g, \"/\"),\n fileName: path.basename(relFile),\n props: formattedPrimaryProps,\n subcomponents:\n Object.keys(subcomponents).length > 0 ? subcomponents : undefined,\n },\n null,\n 2\n );\n\n const outputFilePath = path.join(\n resolvedOutputPath,\n `${componentName}.json`\n );\n await fs.writeFile(outputFilePath, componentJSON + \"\\n\", \"utf-8\");\n\n log(`Generated props for ${componentName}`);\n })\n );\n } catch (err) {\n log(`Error generating props: ${(err as Error).message}`);\n }\n}\n\n// based on https://github.com/mui/base-ui/blob/master/docs/src/components/ReferenceTable/PropsReferenceAccordion.tsx\nfunction getShortPropType(name: string, type: string) {\n if (/^(on|get)[A-Z].*/.test(name)) {\n return { type: \"function\", detailedType: true };\n }\n\n if (type === undefined || type === null) {\n return { type: String(type), detailedType: false };\n }\n\n if (name === \"className\") {\n return { type: \"string | function\", detailedType: true };\n }\n\n if (name === \"render\") {\n return { type: \"ReactElement | function\", detailedType: true };\n }\n\n if (\n name.endsWith(\"Ref\") ||\n name === \"children\" ||\n type === \"boolean\" ||\n type === \"string\" ||\n type === \"number\" ||\n type.indexOf(\" | \") === -1 ||\n (type.split(\"|\").length < 3 && type.length < 30)\n ) {\n return { type, detailedType: false };\n }\n\n return { type: \"Union\", detailedType: true };\n}\n\nfunction compareStrings(a: string, b: string): number {\n return a < b ? -1 : a > b ? 1 : 0;\n}\n\nfunction sortUnionString(str: string): string {\n if (!str.includes(\"|\")) {\n return str;\n }\n\n const parts: string[] = [];\n let current = \"\";\n let depthParen = 0;\n let depthAngle = 0;\n let depthBrace = 0;\n let depthBracket = 0;\n let inQuote: string | null = null;\n\n for (let i = 0; i < str.length; i++) {\n const ch = str[i]!;\n if (inQuote) {\n current += ch;\n if (ch === inQuote && str[i - 1] !== \"\\\\\") {\n inQuote = null;\n }\n continue;\n }\n\n if (ch === '\"' || ch === \"'\") {\n inQuote = ch;\n current += ch;\n continue;\n }\n\n if (ch === \"(\") depthParen++;\n else if (ch === \")\") depthParen = Math.max(0, depthParen - 1);\n else if (ch === \"<\") depthAngle++;\n else if (ch === \">\" && str[i - 1] !== \"=\")\n depthAngle = Math.max(0, depthAngle - 1);\n else if (ch === \"{\") depthBrace++;\n else if (ch === \"}\") depthBrace = Math.max(0, depthBrace - 1);\n else if (ch === \"[\") depthBracket++;\n else if (ch === \"]\") depthBracket = Math.max(0, depthBracket - 1);\n\n if (\n ch === \"|\" &&\n depthParen === 0 &&\n depthAngle === 0 &&\n depthBrace === 0 &&\n depthBracket === 0\n ) {\n parts.push(current.trim());\n current = \"\";\n } else {\n current += ch;\n }\n }\n\n parts.push(current.trim());\n\n if (parts.length <= 1) {\n return str;\n }\n\n parts.sort((a, b) => {\n if (a === \"undefined\" && b !== \"undefined\") return 1;\n if (b === \"undefined\" && a !== \"undefined\") return -1;\n return compareStrings(a, b);\n });\n\n return parts.join(\" | \");\n}\n\nfunction formatProps(rawProps: Record<string, PropItem>) {\n const props: Record<\n string,\n PropItem & {\n shortPropTypeName: string | null;\n }\n > = {};\n\n const sortedPropNames = Object.keys(rawProps).sort(compareStrings);\n\n for (const propName of sortedPropNames) {\n const rawProp = rawProps[propName];\n if (!rawProp) {\n continue;\n }\n\n const prop = { ...rawProp } as PropItem & {\n shortPropTypeName: string | null;\n };\n\n if (prop.type && prop.type.name) {\n prop.type = { ...prop.type };\n\n if (typeof prop.type.raw === \"string\") {\n prop.type.raw = sortUnionString(prop.type.raw);\n }\n\n const sortedTypeName = sortUnionString(prop.type.name);\n const { type: shortPropTypeName, detailedType } = getShortPropType(\n propName,\n sortedTypeName\n );\n\n const hasExpandedType = Boolean(detailedType);\n\n prop.type.name =\n hasExpandedType && sortedTypeName.split(\"|\").length > 3\n ? sortedTypeName\n .split(\"|\")\n .map((line) => `| ${line}\\n`)\n .join(\"\")\n : sortedTypeName;\n\n prop.shortPropTypeName = hasExpandedType ? shortPropTypeName : null;\n }\n\n props[propName] = prop;\n }\n\n return props;\n}\n\nfunction getAssignedInfo(sourceText: string, compName: string) {\n const sourceFile = ts.createSourceFile(\n \"temp.tsx\",\n sourceText,\n ts.ScriptTarget.Latest,\n true\n );\n let baseIdentifier: string | null = null;\n const subcomponentsMap = new Map<string, string>();\n\n ts.forEachChild(sourceFile, (node) => {\n // 1. export { Local as Exported, ... }\n if (ts.isExportDeclaration(node)) {\n if (\n !node.isTypeOnly &&\n node.exportClause &&\n ts.isNamedExports(node.exportClause)\n ) {\n for (const element of node.exportClause.elements) {\n if (!element.isTypeOnly && element.propertyName) {\n const exportName = element.name.getText(sourceFile);\n const localName = element.propertyName.getText(sourceFile);\n if (exportName === compName) {\n baseIdentifier = localName;\n } else if (/^[A-Z]/.test(exportName)) {\n subcomponentsMap.set(exportName, localName);\n }\n }\n }\n }\n }\n\n // 2. export const Comp = Object.assign(Base, { SubName: Target, ... })\n if (ts.isVariableStatement(node)) {\n for (const decl of node.declarationList.declarations) {\n if (\n decl.name.getText(sourceFile) === compName &&\n decl.initializer &&\n ts.isCallExpression(decl.initializer)\n ) {\n const call = decl.initializer;\n const exprText = call.expression.getText(sourceFile);\n if (\n (exprText === \"Object.assign\" || exprText.endsWith(\".assign\")) &&\n call.arguments.length > 0\n ) {\n const firstArg = call.arguments[0];\n if (firstArg) {\n baseIdentifier = firstArg.getText(sourceFile);\n }\n if (\n call.arguments.length > 1 &&\n ts.isObjectLiteralExpression(call.arguments[1]!)\n ) {\n for (const prop of call.arguments[1]!.properties) {\n if (ts.isPropertyAssignment(prop)) {\n const propName = prop.name.getText(sourceFile);\n const initName = prop.initializer.getText(sourceFile);\n subcomponentsMap.set(propName, initName);\n } else if (ts.isShorthandPropertyAssignment(prop)) {\n const propName = prop.name.getText(sourceFile);\n subcomponentsMap.set(propName, propName);\n }\n }\n }\n }\n }\n }\n }\n\n // 3. Comp.Sub = Target\n if (\n ts.isExpressionStatement(node) &&\n ts.isBinaryExpression(node.expression)\n ) {\n const bin = node.expression;\n if (\n bin.operatorToken.kind === ts.SyntaxKind.EqualsToken &&\n ts.isPropertyAccessExpression(bin.left)\n ) {\n const objText = bin.left.expression.getText(sourceFile);\n const propText = bin.left.name.getText(sourceFile);\n if (objText === compName && /^[A-Z]/.test(propText)) {\n const targetName = bin.right.getText(sourceFile);\n subcomponentsMap.set(propText, targetName);\n }\n }\n }\n });\n\n return { baseIdentifier, subcomponentsMap };\n}\n"],"mappings":";;;;;;;AAOA,MAAM,aAAa,cAAc,YAAY,GAAG;AAC9B,KAAK,QAAQ,UAAU;AAGzC,MAAM,iCAAiB,IAAI,IAAoB;AAE/C,eAAsB,cACpB,cACA,SACA,aAAqB,UACrB,MAAoC,QAAQ,KAC5C,oBACA;CACA,MAAM,SACJ,MAAM,KAAK,cAAc,EACvB,KAAK,QACP,CAAC,EAAA,CACD,KAAK,cAAc;CAErB,IAAI,MAAM,WAAW,GAAG;EACtB,IAAI,+BAA+B,cAAc;EACjD;CACF;CAEA,MAAM,qBAAqB,KAAK,QAAQ,SAAS,UAAU;CAC3D,MAAM,GAAG,MAAM,oBAAoB,EAAE,WAAW,KAAK,CAAC;CAEtD,MAAM,iBAIA,CAAC;CAEP,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,WAAW,KAAK,QAAQ,SAAS,IAAI;EAC3C,MAAM,gBAAgB,KAAK,SAAS,MAAM,KAAK,QAAQ,IAAI,CAAC;EAC5D,MAAM,iBAAiB,KAAK,KAC1B,oBACA,GAAG,cAAc,MACnB;EAEA,IAAI;GACF,MAAM,aAAa,MAAM,GAAG,KAAK,QAAQ;GACzC,MAAM,cAAc,eAAe,IAAI,QAAQ;GAE/C,IAAI,aAAa;GACjB,IAAI;IACF,MAAM,UAAU,MAAM,GAAG,KAAK,cAAc;IAC5C,IACG,gBAAgB,KAAA,KAAa,gBAAgB,WAAW,WACzD,QAAQ,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EAAgB;CAAiB;AAC5C"}
|
|
1
|
+
{"version":3,"file":"generate-props.mjs","names":[],"sources":["../../src/generate-props.ts"],"sourcesContent":["import fsSync from \"fs\";\nimport fs from \"fs/promises\";\nimport path from \"path\";\nimport {\n type ComponentDoc,\n type PropItem,\n withCompilerOptions,\n} from \"react-docgen-typescript\";\nimport { glob } from \"tinyglobby\";\nimport ts from \"typescript\";\nimport { fileURLToPath } from \"url\";\nimport {\n compareStrings,\n expandPropType,\n normalizeDisplayType,\n resolveComponentPropTypes,\n splitTopLevelUnion,\n stripTopLevelUndefined,\n type ExpandedPropType,\n} from \"./type-expander.js\";\n\nexport type { ExpandedPropType };\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\n// cache for watch mode across buildStart events\nconst fileMtimeCache = new Map<string, number>();\n\nfunction loadCompilerOptions(tsconfigPath: string): ts.CompilerOptions {\n const basePath = path.dirname(tsconfigPath);\n const { config, error } = ts.readConfigFile(tsconfigPath, (filename) =>\n fsSync.readFileSync(filename, \"utf8\")\n );\n if (error !== undefined) {\n throw new Error(\n `Cannot load custom tsconfig.json from provided path: ${tsconfigPath}, with error code: ${error.code}, message: ${ts.flattenDiagnosticMessageText(error.messageText, \"\\n\")}`\n );\n }\n\n const parsed = ts.parseJsonConfigFileContent(\n config,\n ts.sys,\n basePath,\n {},\n tsconfigPath\n );\n if (parsed.errors && parsed.errors.length > 0) {\n const first = parsed.errors[0]!;\n throw new Error(\n `TS${first.code}: ${ts.flattenDiagnosticMessageText(first.messageText, \"\\n\")}`\n );\n }\n return parsed.options;\n}\n\nasync function getMaxExistingMtimeMs(paths: string[]): Promise<number> {\n let maxMtime = 0;\n for (const targetPath of paths) {\n try {\n const stat = await fs.stat(targetPath);\n if (stat.mtimeMs > maxMtime) {\n maxMtime = stat.mtimeMs;\n }\n } catch {\n // ignore missing paths\n }\n }\n return maxMtime;\n}\n\nexport async function generateProps(\n pagesPattern: string,\n rootDir: string,\n outputPath: string = \"docgen\",\n log: (...args: unknown[]) => void = console.log,\n customTsconfigPath?: string,\n force: boolean = false\n) {\n const files = (\n await glob(pagesPattern, {\n cwd: rootDir,\n })\n ).sort(compareStrings);\n\n if (files.length === 0) {\n log(`No files found for pattern: ${pagesPattern}`);\n return;\n }\n\n const resolvedOutputPath = path.resolve(rootDir, outputPath);\n await fs.mkdir(resolvedOutputPath, { recursive: true });\n\n const resolvedTsconfigPath = customTsconfigPath\n ? path.resolve(rootDir, customTsconfigPath)\n : path.resolve(rootDir, \"./tsconfig.json\");\n\n const ext = path.extname(__filename);\n const dependencyMtimeMs = force\n ? 0\n : await getMaxExistingMtimeMs([\n resolvedTsconfigPath,\n __filename,\n path.join(__dirname, `type-expander${ext}`),\n ]);\n\n const filesToProcess: {\n relFile: string;\n absPath: string;\n componentName: string;\n }[] = [];\n\n for (const file of files) {\n const filePath = path.resolve(rootDir, file);\n const componentName = path.basename(file, path.extname(file));\n const outputFilePath = path.join(\n resolvedOutputPath,\n `${componentName}.json`\n );\n\n try {\n const sourceStat = await fs.stat(filePath);\n const requiredMtimeMs = Math.max(sourceStat.mtimeMs, dependencyMtimeMs);\n const cacheKey = `${filePath}\\0${outputFilePath}`;\n const cachedMtime = fileMtimeCache.get(cacheKey);\n\n let isUpToDate = false;\n if (!force) {\n try {\n const outStat = await fs.stat(outputFilePath);\n if (\n (cachedMtime !== undefined && cachedMtime === requiredMtimeMs) ||\n outStat.mtimeMs >= requiredMtimeMs\n ) {\n isUpToDate = true;\n fileMtimeCache.set(cacheKey, requiredMtimeMs);\n }\n } catch {\n // output file does not exist\n }\n }\n\n if (isUpToDate) {\n continue;\n }\n\n filesToProcess.push({\n relFile: file,\n absPath: filePath,\n componentName,\n });\n fileMtimeCache.set(cacheKey, requiredMtimeMs);\n } catch {\n // source file not accessible\n }\n }\n\n if (filesToProcess.length === 0) {\n return;\n }\n\n log(\n `Found ${filesToProcess.length} changed file(s) for pattern: ${pagesPattern}`\n );\n\n const compilerOptions = loadCompilerOptions(resolvedTsconfigPath);\n const docgenParser = withCompilerOptions(compilerOptions, {\n shouldExtractLiteralValuesFromEnum: true,\n shouldSortUnions: true,\n savePropValueAsString: true,\n shouldIncludeExpression: true,\n propFilter: (prop) => {\n if (Array.isArray(prop.declarations) && prop.declarations[0]) {\n const declaration = prop.declarations[0];\n\n if (declaration.fileName.includes(\"node_modules/@types/react\")) {\n if (prop.name !== \"ref\" && prop.name !== \"className\") {\n return false;\n }\n }\n }\n return true;\n },\n });\n\n try {\n const absPaths = filesToProcess.map((f) => f.absPath);\n const program = ts.createProgram(absPaths, compilerOptions);\n const checker = program.getTypeChecker();\n const allDocs = docgenParser.parseWithProgramProvider(\n absPaths,\n () => program\n );\n\n const propTypesByDoc = new WeakMap<\n ComponentDoc,\n Map<string, { type: ts.Type; locationNode?: ts.Node }>\n >();\n const getPropTypesForDoc = (doc: ComponentDoc | undefined) => {\n if (!doc) return undefined;\n let cached = propTypesByDoc.get(doc);\n if (!cached) {\n cached = resolveComponentPropTypes(\n doc.expression ?? doc.rootExpression,\n checker\n );\n propTypesByDoc.set(doc, cached);\n }\n return cached;\n };\n\n const docsByFilePath = new Map<string, typeof allDocs>();\n for (const doc of allDocs) {\n if (doc.filePath) {\n const key = path.resolve(doc.filePath);\n const list = docsByFilePath.get(key) || [];\n list.push(doc);\n docsByFilePath.set(key, list);\n }\n }\n\n await Promise.all(\n filesToProcess.map(async ({ relFile, absPath, componentName }) => {\n log(`parsing file: : ${relFile}`);\n\n const fileDocs = docsByFilePath.get(path.resolve(absPath)) || [];\n\n // Check if the component was composed using Object.assign or exports compound parts\n const sourceText = await fs.readFile(absPath, \"utf-8\");\n const assignedInfo = getAssignedInfo(sourceText, componentName);\n\n const usedDocs = new Set<(typeof fileDocs)[number]>();\n\n // 1. Identify explicit primary component doc matching componentName or assigned base\n let primaryDoc =\n fileDocs.find((d) => d.displayName === componentName) ||\n (assignedInfo.baseIdentifier\n ? fileDocs.find(\n (d) => d.displayName === assignedInfo.baseIdentifier\n )\n : undefined);\n\n if (primaryDoc) {\n usedDocs.add(primaryDoc);\n }\n\n // If primaryDoc was created by Object.assign and lost props, recover from base\n let primaryProps = primaryDoc ? primaryDoc.props : {};\n let primaryPropsDoc: ComponentDoc | undefined = primaryDoc;\n if (assignedInfo.baseIdentifier) {\n const baseDoc = fileDocs.find(\n (d) => d.displayName === assignedInfo.baseIdentifier\n );\n if (baseDoc) {\n if (\n assignedInfo.baseIdentifier !==\n assignedInfo.subcomponentsMap.get(\"Root\")\n ) {\n usedDocs.add(baseDoc);\n }\n if (\n primaryDoc &&\n Object.keys(baseDoc.props).length >\n Object.keys(primaryProps).length\n ) {\n primaryProps = baseDoc.props;\n primaryPropsDoc = baseDoc;\n }\n }\n }\n\n // 2. Identify subcomponents (including Root if present)\n const subcomponents: Record<\n string,\n {\n name: string;\n description?: string;\n props: ReturnType<typeof formatProps>;\n }\n > = {};\n\n // a) Handle subcomponents explicitly assigned or exported\n for (const [subName, targetName] of assignedInfo.subcomponentsMap) {\n if (subName === componentName) continue;\n const subDoc = fileDocs.find(\n (d) =>\n d.displayName === targetName ||\n d.displayName === `${componentName}.${subName}` ||\n d.displayName === `${componentName}${subName}` ||\n d.displayName === subName\n );\n if (subDoc) {\n usedDocs.add(subDoc);\n subcomponents[subName] = {\n name: `${componentName}.${subName}`,\n description: subDoc.description || undefined,\n props: formatProps(\n subDoc.props,\n getPropTypesForDoc(subDoc),\n checker\n ),\n };\n }\n }\n\n const hasRoot =\n Boolean(subcomponents.Root) ||\n fileDocs.some(\n (d) =>\n d.displayName === \"Root\" ||\n d.displayName === `${componentName}Root` ||\n d.displayName === `${componentName}.Root`\n );\n\n // b) Handle subcomponents matching standard React dot notation or component prefix\n for (const doc of fileDocs) {\n if (usedDocs.has(doc)) continue;\n\n let subName: string | undefined;\n if (doc.displayName.startsWith(`${componentName}.`)) {\n subName = doc.displayName.slice(componentName.length + 1);\n } else if (\n doc.displayName.startsWith(componentName) &&\n doc.displayName.length > componentName.length\n ) {\n subName = doc.displayName.slice(componentName.length);\n } else if (hasRoot) {\n subName = doc.displayName;\n }\n\n if (subName && subName !== componentName) {\n const existing = subcomponents[subName];\n if (\n existing &&\n Object.keys(existing.props).length >=\n Object.keys(doc.props).length\n ) {\n continue;\n }\n\n usedDocs.add(doc);\n subcomponents[subName] = {\n name: `${componentName}.${subName}`,\n description: doc.description || undefined,\n props: formatProps(doc.props, getPropTypesForDoc(doc), checker),\n };\n }\n }\n\n const hasDistinctPrimary =\n Boolean(primaryDoc) &&\n Object.keys(primaryProps).length > 0 &&\n primaryDoc?.displayName !== \"Root\" &&\n primaryDoc?.displayName !== `${componentName}Root` &&\n primaryDoc?.displayName !== `${componentName}.Root` &&\n assignedInfo.baseIdentifier !==\n assignedInfo.subcomponentsMap.get(\"Root\");\n\n // Promote Root subcomponent to primary component only when no distinct primary component exists\n const promotedRoot =\n !hasDistinctPrimary && subcomponents.Root\n ? subcomponents.Root\n : undefined;\n if (promotedRoot) {\n delete subcomponents.Root;\n } else if (!primaryDoc) {\n primaryDoc =\n fileDocs.find((d) => Object.keys(d.props).length > 0) ||\n fileDocs[0];\n primaryProps = primaryDoc ? primaryDoc.props : {};\n primaryPropsDoc = primaryDoc;\n }\n\n const formattedPrimaryProps = promotedRoot\n ? promotedRoot.props\n : formatProps(\n primaryProps,\n getPropTypesForDoc(primaryPropsDoc),\n checker\n );\n\n const componentJSON = JSON.stringify(\n {\n name: promotedRoot ? promotedRoot.name : componentName,\n description:\n (promotedRoot\n ? promotedRoot.description\n : primaryDoc?.description) || undefined,\n path: relFile.replace(/\\\\/g, \"/\"),\n fileName: path.basename(relFile),\n props: formattedPrimaryProps,\n subcomponents:\n Object.keys(subcomponents).length > 0 ? subcomponents : undefined,\n },\n null,\n 2\n );\n\n const outputFilePath = path.join(\n resolvedOutputPath,\n `${componentName}.json`\n );\n await fs.writeFile(outputFilePath, componentJSON + \"\\n\", \"utf-8\");\n\n log(`Generated props for ${componentName}`);\n })\n );\n } catch (err) {\n log(`Error generating props: ${(err as Error).message}`);\n }\n}\n\n// based on https://github.com/mui/base-ui/blob/master/docs/src/components/ReferenceTable/PropsReferenceAccordion.tsx\nfunction getShortPropType(\n name: string,\n type: string,\n expanded?: ExpandedPropType\n) {\n if (/^(on|get)[A-Z].*/.test(name)) {\n return { type: \"function\", detailedType: true };\n }\n\n if (type === undefined || type === null) {\n return { type: String(type), detailedType: false };\n }\n\n if (name === \"className\") {\n return { type: \"string | function\", detailedType: true };\n }\n\n if (name === \"render\") {\n return { type: \"ReactElement | function\", detailedType: true };\n }\n\n if (expanded?.kind === \"mapped-union\") {\n return {\n type: expanded.alias ?? \"Union\",\n detailedType: true,\n };\n }\n\n const cleanType = stripTopLevelUndefined(type);\n const topLevelParts = splitTopLevelUnion(cleanType);\n\n if (\n name.endsWith(\"Ref\") ||\n name === \"children\" ||\n cleanType === \"boolean\" ||\n cleanType === \"string\" ||\n cleanType === \"number\" ||\n topLevelParts.length <= 1 ||\n (topLevelParts.length < 3 && cleanType.length < 30)\n ) {\n return { type, detailedType: false };\n }\n\n return { type: \"Union\", detailedType: true };\n}\n\nfunction splitTopLevelCommas(str: string): string[] {\n const parts: string[] = [];\n let current = \"\";\n let depthParen = 0;\n let depthAngle = 0;\n let depthBrace = 0;\n let depthBracket = 0;\n let inQuote: string | null = null;\n\n for (let i = 0; i < str.length; i++) {\n const ch = str[i]!;\n if (inQuote) {\n current += ch;\n if (ch === inQuote && str[i - 1] !== \"\\\\\") {\n inQuote = null;\n }\n continue;\n }\n\n if (ch === '\"' || ch === \"'\" || ch === \"`\") {\n inQuote = ch;\n current += ch;\n continue;\n }\n\n if (ch === \"(\") depthParen++;\n else if (ch === \")\") depthParen = Math.max(0, depthParen - 1);\n else if (ch === \"<\") depthAngle++;\n else if (ch === \">\" && str[i - 1] !== \"=\")\n depthAngle = Math.max(0, depthAngle - 1);\n else if (ch === \"{\") depthBrace++;\n else if (ch === \"}\") depthBrace = Math.max(0, depthBrace - 1);\n else if (ch === \"[\") depthBracket++;\n else if (ch === \"]\") depthBracket = Math.max(0, depthBracket - 1);\n\n if (\n ch === \",\" &&\n depthParen === 0 &&\n depthAngle === 0 &&\n depthBrace === 0 &&\n depthBracket === 0\n ) {\n parts.push(current.trim());\n current = \"\";\n } else {\n current += ch;\n }\n }\n\n parts.push(current.trim());\n return parts;\n}\n\nfunction sortGenericTypeArgs(str: string): string {\n const openIdx = str.indexOf(\"<\");\n if (openIdx === -1 || !str.endsWith(\">\")) {\n return str;\n }\n\n const prefix = str.slice(0, openIdx);\n if (!/^[A-Za-z_$][A-Za-z0-9_$.]*$/.test(prefix)) {\n return str;\n }\n\n const inner = str.slice(openIdx + 1, -1);\n const args = splitTopLevelCommas(inner).map((arg) => sortUnionString(arg));\n return `${prefix}<${args.join(\", \")}>`;\n}\n\nfunction sortUnionString(str: string): string {\n if (!str.includes(\"|\")) {\n return str;\n }\n\n const parts = splitTopLevelUnion(str).map((part) =>\n sortGenericTypeArgs(part)\n );\n\n if (parts.length <= 1) {\n return parts[0] ?? str;\n }\n\n parts.sort((a, b) => {\n if (a === \"undefined\" && b !== \"undefined\") return 1;\n if (b === \"undefined\" && a !== \"undefined\") return -1;\n return compareStrings(a, b);\n });\n\n return parts.join(\" | \");\n}\n\ntype FormattedPropItem = PropItem & {\n type: PropItem[\"type\"] & {\n expanded?: ExpandedPropType;\n };\n shortPropTypeName: string | null;\n};\n\nfunction formatProps(\n rawProps: Record<string, PropItem>,\n propTypes?: Map<string, { type: ts.Type; locationNode?: ts.Node }>,\n checker?: ts.TypeChecker\n) {\n const props: Record<string, FormattedPropItem> = {};\n\n const sortedPropNames = Object.keys(rawProps).sort(compareStrings);\n\n for (const propName of sortedPropNames) {\n const rawProp = rawProps[propName];\n if (!rawProp) {\n continue;\n }\n\n const prop: FormattedPropItem = {\n ...rawProp,\n type: { ...rawProp.type },\n shortPropTypeName: null,\n };\n\n if (prop.type && prop.type.name) {\n if (typeof prop.type.raw === \"string\") {\n prop.type.raw = sortUnionString(normalizeDisplayType(prop.type.raw));\n }\n\n const sortedTypeName = sortUnionString(\n normalizeDisplayType(prop.type.name)\n );\n\n const resolved = propTypes?.get(propName);\n const expanded =\n resolved && checker\n ? expandPropType(\n resolved.type,\n prop.type.raw ?? sortedTypeName,\n prop.type.name === \"enum\",\n checker,\n resolved.locationNode\n )\n : undefined;\n\n if (expanded) {\n prop.type.expanded = expanded;\n }\n\n const { type: shortPropTypeName, detailedType } = getShortPropType(\n propName,\n sortedTypeName,\n expanded\n );\n\n const hasExpandedType = Boolean(detailedType);\n const topLevelParts = splitTopLevelUnion(sortedTypeName);\n const nonUndefTopLevelCount = topLevelParts.filter(\n (part) => part !== \"undefined\"\n ).length;\n\n prop.type.name =\n hasExpandedType && nonUndefTopLevelCount > 3\n ? topLevelParts.map((line) => `| ${line}\\n`).join(\"\")\n : sortedTypeName;\n\n prop.shortPropTypeName = hasExpandedType ? shortPropTypeName : null;\n }\n\n props[propName] = prop;\n }\n\n return props;\n}\n\nfunction getAssignedInfo(sourceText: string, compName: string) {\n const sourceFile = ts.createSourceFile(\n \"temp.tsx\",\n sourceText,\n ts.ScriptTarget.Latest,\n true\n );\n let baseIdentifier: string | null = null;\n const subcomponentsMap = new Map<string, string>();\n\n ts.forEachChild(sourceFile, (node) => {\n // 1. export { Local as Exported, ... }\n if (ts.isExportDeclaration(node)) {\n if (\n !node.isTypeOnly &&\n node.exportClause &&\n ts.isNamedExports(node.exportClause)\n ) {\n for (const element of node.exportClause.elements) {\n if (!element.isTypeOnly && element.propertyName) {\n const exportName = element.name.getText(sourceFile);\n const localName = element.propertyName.getText(sourceFile);\n if (exportName === compName) {\n baseIdentifier = localName;\n } else if (/^[A-Z]/.test(exportName)) {\n subcomponentsMap.set(exportName, localName);\n }\n }\n }\n }\n }\n\n // 2. export const Comp = Object.assign(Base, { SubName: Target, ... })\n if (ts.isVariableStatement(node)) {\n for (const decl of node.declarationList.declarations) {\n if (\n decl.name.getText(sourceFile) === compName &&\n decl.initializer &&\n ts.isCallExpression(decl.initializer)\n ) {\n const call = decl.initializer;\n const exprText = call.expression.getText(sourceFile);\n if (\n (exprText === \"Object.assign\" || exprText.endsWith(\".assign\")) &&\n call.arguments.length > 0\n ) {\n const firstArg = call.arguments[0];\n if (firstArg) {\n baseIdentifier = firstArg.getText(sourceFile);\n }\n if (\n call.arguments.length > 1 &&\n ts.isObjectLiteralExpression(call.arguments[1]!)\n ) {\n for (const prop of call.arguments[1]!.properties) {\n if (ts.isPropertyAssignment(prop)) {\n const propName = prop.name.getText(sourceFile);\n const initName = prop.initializer.getText(sourceFile);\n subcomponentsMap.set(propName, initName);\n } else if (ts.isShorthandPropertyAssignment(prop)) {\n const propName = prop.name.getText(sourceFile);\n subcomponentsMap.set(propName, propName);\n }\n }\n }\n }\n }\n }\n }\n\n // 3. Comp.Sub = Target\n if (\n ts.isExpressionStatement(node) &&\n ts.isBinaryExpression(node.expression)\n ) {\n const bin = node.expression;\n if (\n bin.operatorToken.kind === ts.SyntaxKind.EqualsToken &&\n ts.isPropertyAccessExpression(bin.left)\n ) {\n const objText = bin.left.expression.getText(sourceFile);\n const propText = bin.left.name.getText(sourceFile);\n if (objText === compName && /^[A-Z]/.test(propText)) {\n const targetName = bin.right.getText(sourceFile);\n subcomponentsMap.set(propText, targetName);\n }\n }\n }\n });\n\n return { baseIdentifier, subcomponentsMap };\n}\n"],"mappings":";;;;;;;;;AAuBA,MAAM,aAAa,cAAc,YAAY,GAAG;AAChD,MAAM,YAAY,KAAK,QAAQ,UAAU;AAGzC,MAAM,iCAAiB,IAAI,IAAoB;AAE/C,SAAS,oBAAoB,cAA0C;CACrE,MAAM,WAAW,KAAK,QAAQ,YAAY;CAC1C,MAAM,EAAE,QAAQ,UAAU,GAAG,eAAe,eAAe,aACzD,OAAO,aAAa,UAAU,MAAM,CACtC;CACA,IAAI,UAAU,KAAA,GACZ,MAAM,IAAI,MACR,wDAAwD,aAAa,qBAAqB,MAAM,KAAK,aAAa,GAAG,6BAA6B,MAAM,aAAa,IAAI,GAC3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AY,QAAQ,UAAU;OACpD,iBAAiB,IAAI,UAAU,QAAQ;MACzC,OAAO,IAAI,GAAG,8BAA8B,IAAI,GAAG;OACjD,MAAM,WAAW,KAAK,KAAK,QAAQ,UAAU;OAC7C,iBAAiB,IAAI,UAAU,QAAQ;MACzC;;IAGN;GACF;;EAKJ,IACE,GAAG,sBAAsB,IAAI,KAC7B,GAAG,mBAAmB,KAAK,UAAU,GACrC;GACA,MAAM,MAAM,KAAK;GACjB,IACE,IAAI,cAAc,SAAS,GAAG,WAAW,eACzC,GAAG,2BAA2B,IAAI,IAAI,GACtC;IACA,MAAM,UAAU,IAAI,KAAK,WAAW,QAAQ,UAAU;IACtD,MAAM,WAAW,IAAI,KAAK,KAAK,QAAQ,UAAU;IACjD,IAAI,YAAY,YAAY,SAAS,KAAK,QAAQ,GAAG;KACnD,MAAM,aAAa,IAAI,MAAM,QAAQ,UAAU;KAC/C,iBAAiB,IAAI,UAAU,UAAU;IAC3C;GACF;EACF;CACF,CAAC;CAED,OAAO;EAAE;EAAgB;CAAiB;AAC5C"}
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
//#region src/type-expander.d.ts
|
|
3
|
+
export type ExpandedPropType = {
|
|
4
|
+
kind: "mapped-union";
|
|
5
|
+
alias?: string;
|
|
6
|
+
values?: string[];
|
|
7
|
+
valueType: string;
|
|
8
|
+
keys: string[];
|
|
9
|
+
formatted: string;
|
|
10
|
+
} | {
|
|
11
|
+
kind: "alias" | "object" | "union" | "function";
|
|
12
|
+
formatted: string;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
//# sourceMappingURL=type-expander.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-expander.d.mts","names":[],"sources":["../../src/type-expander.ts"],"mappings":";;YAEY;EAEN;EACA;EACA;EACA;EACA;EACA;;EAGA;EACA"}
|
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
//#region src/type-expander.ts
|
|
3
|
+
const STOP_TYPE_NAMES = /* @__PURE__ */ new Set([
|
|
4
|
+
"ReactNode",
|
|
5
|
+
"ReactElement",
|
|
6
|
+
"ReactPortal",
|
|
7
|
+
"ReactFragment",
|
|
8
|
+
"Element",
|
|
9
|
+
"JSX.Element",
|
|
10
|
+
"CSSProperties",
|
|
11
|
+
"ElementType",
|
|
12
|
+
"ComponentType",
|
|
13
|
+
"ComponentProps",
|
|
14
|
+
"ComponentPropsWithRef",
|
|
15
|
+
"ComponentPropsWithoutRef",
|
|
16
|
+
"Ref",
|
|
17
|
+
"RefObject",
|
|
18
|
+
"MutableRefObject",
|
|
19
|
+
"ForwardedRef",
|
|
20
|
+
"LegacyRef",
|
|
21
|
+
"HTMLAttributes",
|
|
22
|
+
"SVGAttributes",
|
|
23
|
+
"DOMAttributes",
|
|
24
|
+
"SyntheticEvent",
|
|
25
|
+
"MouseEvent",
|
|
26
|
+
"KeyboardEvent",
|
|
27
|
+
"FocusEvent",
|
|
28
|
+
"ChangeEvent",
|
|
29
|
+
"PointerEvent",
|
|
30
|
+
"TouchEvent",
|
|
31
|
+
"UIEvent",
|
|
32
|
+
"Event",
|
|
33
|
+
"Date",
|
|
34
|
+
"RegExp",
|
|
35
|
+
"Promise",
|
|
36
|
+
"Map",
|
|
37
|
+
"Set",
|
|
38
|
+
"WeakMap",
|
|
39
|
+
"WeakSet",
|
|
40
|
+
"URL",
|
|
41
|
+
"File",
|
|
42
|
+
"Blob",
|
|
43
|
+
"FormData",
|
|
44
|
+
"Error"
|
|
45
|
+
]);
|
|
46
|
+
const UTILITY_ALIAS_NAMES = /* @__PURE__ */ new Set([
|
|
47
|
+
"Partial",
|
|
48
|
+
"Required",
|
|
49
|
+
"Readonly",
|
|
50
|
+
"Record",
|
|
51
|
+
"Pick",
|
|
52
|
+
"Omit",
|
|
53
|
+
"NonNullable",
|
|
54
|
+
"Exclude",
|
|
55
|
+
"Extract"
|
|
56
|
+
]);
|
|
57
|
+
const VALID_IDENTIFIER_RE = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
58
|
+
const MAX_MAPPED_KEYS = 24;
|
|
59
|
+
const MAX_OBJECT_PROPS = 14;
|
|
60
|
+
const MAX_EXPAND_DEPTH = 2;
|
|
61
|
+
function compareStrings(a, b) {
|
|
62
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Splits a TypeScript type string on top-level `|` operators only,
|
|
66
|
+
* preserving `|` inside `<...>`, `{...}`, `(...)`, `[...]`, and string literals.
|
|
67
|
+
*/
|
|
68
|
+
function splitTopLevelUnion(str) {
|
|
69
|
+
if (!str.includes("|")) return [str.trim()];
|
|
70
|
+
const parts = [];
|
|
71
|
+
let current = "";
|
|
72
|
+
let depthParen = 0;
|
|
73
|
+
let depthAngle = 0;
|
|
74
|
+
let depthBrace = 0;
|
|
75
|
+
let depthBracket = 0;
|
|
76
|
+
let inQuote = null;
|
|
77
|
+
for (let i = 0; i < str.length; i++) {
|
|
78
|
+
const ch = str[i];
|
|
79
|
+
if (inQuote) {
|
|
80
|
+
current += ch;
|
|
81
|
+
if (ch === inQuote && str[i - 1] !== "\\") inQuote = null;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (ch === "\"" || ch === "'" || ch === "`") {
|
|
85
|
+
inQuote = ch;
|
|
86
|
+
current += ch;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (ch === "(") depthParen++;
|
|
90
|
+
else if (ch === ")") depthParen = Math.max(0, depthParen - 1);
|
|
91
|
+
else if (ch === "<") depthAngle++;
|
|
92
|
+
else if (ch === ">" && str[i - 1] !== "=") depthAngle = Math.max(0, depthAngle - 1);
|
|
93
|
+
else if (ch === "{") depthBrace++;
|
|
94
|
+
else if (ch === "}") depthBrace = Math.max(0, depthBrace - 1);
|
|
95
|
+
else if (ch === "[") depthBracket++;
|
|
96
|
+
else if (ch === "]") depthBracket = Math.max(0, depthBracket - 1);
|
|
97
|
+
if (ch === "|" && depthParen === 0 && depthAngle === 0 && depthBrace === 0 && depthBracket === 0) {
|
|
98
|
+
parts.push(current.trim());
|
|
99
|
+
current = "";
|
|
100
|
+
} else current += ch;
|
|
101
|
+
}
|
|
102
|
+
parts.push(current.trim());
|
|
103
|
+
return parts.filter((part) => part.length > 0);
|
|
104
|
+
}
|
|
105
|
+
function stripTopLevelUndefined(str) {
|
|
106
|
+
return splitTopLevelUnion(str).filter((p) => p !== "undefined").join(" | ");
|
|
107
|
+
}
|
|
108
|
+
function sortUnionMembers(members) {
|
|
109
|
+
return [...members].sort((a, b) => {
|
|
110
|
+
if (a === "undefined" && b !== "undefined") return 1;
|
|
111
|
+
if (b === "undefined" && a !== "undefined") return -1;
|
|
112
|
+
if (a === "null" && b !== "null") return 1;
|
|
113
|
+
if (b === "null" && a !== "null") return -1;
|
|
114
|
+
return compareStrings(a, b);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function formatPropertyKey(name) {
|
|
118
|
+
return VALID_IDENTIFIER_RE.test(name) ? name : JSON.stringify(name);
|
|
119
|
+
}
|
|
120
|
+
function isDeclarationInExternalLibs(decl) {
|
|
121
|
+
if (!decl) return false;
|
|
122
|
+
const fileName = decl.getSourceFile().fileName.replace(/\\/g, "/");
|
|
123
|
+
return fileName.includes("/node_modules/@types/react/") || fileName.includes("/node_modules/typescript/lib/lib.");
|
|
124
|
+
}
|
|
125
|
+
function isPropertyInheritedFromExternalLibs(prop) {
|
|
126
|
+
const decls = prop.getDeclarations();
|
|
127
|
+
if (!decls || decls.length === 0) return false;
|
|
128
|
+
return decls.every((d) => isDeclarationInExternalLibs(d));
|
|
129
|
+
}
|
|
130
|
+
const DEFAULT_ELEMENT_TYPE_RE = /\b(?:React\.)?ElementType<any,\s*keyof\s+(?:JSX\.)?IntrinsicElements>/g;
|
|
131
|
+
function normalizeDisplayType(str) {
|
|
132
|
+
return str.replace(DEFAULT_ELEMENT_TYPE_RE, "React.ElementType");
|
|
133
|
+
}
|
|
134
|
+
const PRIMITIVE_DISPLAY_NAMES = /* @__PURE__ */ new Set([
|
|
135
|
+
"string",
|
|
136
|
+
"number",
|
|
137
|
+
"boolean",
|
|
138
|
+
"null",
|
|
139
|
+
"undefined",
|
|
140
|
+
"symbol",
|
|
141
|
+
"bigint",
|
|
142
|
+
"void",
|
|
143
|
+
"never",
|
|
144
|
+
"unknown",
|
|
145
|
+
"any"
|
|
146
|
+
]);
|
|
147
|
+
function isStopTypeName(typeStr) {
|
|
148
|
+
const trimmed = typeStr.trim();
|
|
149
|
+
if (!trimmed) return false;
|
|
150
|
+
const genericIdx = trimmed.indexOf("<");
|
|
151
|
+
const baseName = (genericIdx === -1 ? trimmed : trimmed.slice(0, genericIdx)).trim();
|
|
152
|
+
if (STOP_TYPE_NAMES.has(baseName)) return true;
|
|
153
|
+
const dotIdx = baseName.lastIndexOf(".");
|
|
154
|
+
if (dotIdx !== -1 && STOP_TYPE_NAMES.has(baseName.slice(dotIdx + 1))) return true;
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
function isStopDisplayType(displayBase) {
|
|
158
|
+
const parts = splitTopLevelUnion(displayBase).filter((p) => p !== "undefined");
|
|
159
|
+
if (parts.length === 0) return false;
|
|
160
|
+
let hasStopType = false;
|
|
161
|
+
for (const part of parts) if (isStopTypeName(part)) hasStopType = true;
|
|
162
|
+
else if (!PRIMITIVE_DISPLAY_NAMES.has(part)) return false;
|
|
163
|
+
return hasStopType;
|
|
164
|
+
}
|
|
165
|
+
function getTypeDisplayName(type, checker) {
|
|
166
|
+
return normalizeDisplayType(checker.typeToString(type, void 0, ts.TypeFormatFlags.NoTruncation));
|
|
167
|
+
}
|
|
168
|
+
function isStopType(type, checker) {
|
|
169
|
+
var _type$aliasSymbol;
|
|
170
|
+
if (checker && (getArrayElementType(type, checker) || checker.isTupleType(type))) return false;
|
|
171
|
+
const aliasName = (_type$aliasSymbol = type.aliasSymbol) === null || _type$aliasSymbol === void 0 ? void 0 : _type$aliasSymbol.getName();
|
|
172
|
+
if (aliasName && STOP_TYPE_NAMES.has(aliasName)) return true;
|
|
173
|
+
const symbol = type.getSymbol();
|
|
174
|
+
if (symbol) {
|
|
175
|
+
var _symbol$valueDeclarat, _symbol$declarations;
|
|
176
|
+
const name = symbol.getName();
|
|
177
|
+
if (name === "Array" || name === "ReadonlyArray") return false;
|
|
178
|
+
if (STOP_TYPE_NAMES.has(name)) return true;
|
|
179
|
+
const decl = (_symbol$valueDeclarat = symbol.valueDeclaration) !== null && _symbol$valueDeclarat !== void 0 ? _symbol$valueDeclarat : (_symbol$declarations = symbol.declarations) === null || _symbol$declarations === void 0 ? void 0 : _symbol$declarations[0];
|
|
180
|
+
if (decl && isDeclarationInExternalLibs(decl) && !(aliasName && UTILITY_ALIAS_NAMES.has(aliasName)) && name !== "__type" && name !== "__object") return true;
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
function isPrimitiveOrIntrinsic(type) {
|
|
185
|
+
return Boolean(type.flags & (ts.TypeFlags.String | ts.TypeFlags.Number | ts.TypeFlags.Boolean | ts.TypeFlags.BigInt | ts.TypeFlags.ESSymbol | ts.TypeFlags.UniqueESSymbol | ts.TypeFlags.Void | ts.TypeFlags.Undefined | ts.TypeFlags.Null | ts.TypeFlags.Never | ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.NonPrimitive));
|
|
186
|
+
}
|
|
187
|
+
function isLiteralType(type) {
|
|
188
|
+
return Boolean(type.flags & (ts.TypeFlags.StringLiteral | ts.TypeFlags.NumberLiteral | ts.TypeFlags.BigIntLiteral | ts.TypeFlags.EnumLiteral));
|
|
189
|
+
}
|
|
190
|
+
function isPlainAnonymousObject(type, checker) {
|
|
191
|
+
if (!(type.flags & ts.TypeFlags.Object)) return false;
|
|
192
|
+
if (checker.isArrayType(type) || checker.isTupleType(type)) return false;
|
|
193
|
+
if (type.getCallSignatures().length > 0) return false;
|
|
194
|
+
if (type.getConstructSignatures().length > 0) return false;
|
|
195
|
+
if (isStopType(type)) return false;
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
function isReadonlyArrayType(type) {
|
|
199
|
+
const symbol = type.getSymbol();
|
|
200
|
+
return (symbol === null || symbol === void 0 ? void 0 : symbol.getName()) === "ReadonlyArray";
|
|
201
|
+
}
|
|
202
|
+
function getArrayElementType(type, checker) {
|
|
203
|
+
if (isReadonlyArrayType(type)) {
|
|
204
|
+
const typeArgs = checker.getTypeArguments(type);
|
|
205
|
+
if (typeArgs[0]) return {
|
|
206
|
+
elementType: typeArgs[0],
|
|
207
|
+
readonly: true
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
if (checker.isArrayType(type)) {
|
|
211
|
+
const typeArgs = checker.getTypeArguments(type);
|
|
212
|
+
if (typeArgs[0]) return {
|
|
213
|
+
elementType: typeArgs[0],
|
|
214
|
+
readonly: false
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Formats a list of union member types into canonical sorted strings,
|
|
221
|
+
* collapsing `false` + `true` boolean literals back into `boolean`.
|
|
222
|
+
*/
|
|
223
|
+
function formatUnionMembersCanonical(types, checker, depth, seen) {
|
|
224
|
+
let hasTrue = false;
|
|
225
|
+
let hasFalse = false;
|
|
226
|
+
const rest = [];
|
|
227
|
+
for (const t of types) {
|
|
228
|
+
if (t.flags & ts.TypeFlags.Undefined) continue;
|
|
229
|
+
if (t.flags & ts.TypeFlags.BooleanLiteral) {
|
|
230
|
+
const str = checker.typeToString(t);
|
|
231
|
+
if (str === "true") hasTrue = true;
|
|
232
|
+
else if (str === "false") hasFalse = true;
|
|
233
|
+
else rest.push(t);
|
|
234
|
+
} else rest.push(t);
|
|
235
|
+
}
|
|
236
|
+
const formatted = [];
|
|
237
|
+
let allLiterals = true;
|
|
238
|
+
if (hasTrue && hasFalse) {
|
|
239
|
+
formatted.push("boolean");
|
|
240
|
+
allLiterals = false;
|
|
241
|
+
} else {
|
|
242
|
+
if (hasFalse) formatted.push("false");
|
|
243
|
+
if (hasTrue) formatted.push("true");
|
|
244
|
+
}
|
|
245
|
+
for (const t of rest) {
|
|
246
|
+
if (!isLiteralType(t)) allLiterals = false;
|
|
247
|
+
formatted.push(formatTypeNode(t, checker, depth, seen));
|
|
248
|
+
}
|
|
249
|
+
const unique = Array.from(new Set(formatted));
|
|
250
|
+
return {
|
|
251
|
+
members: sortUnionMembers(unique),
|
|
252
|
+
allLiterals: allLiterals && unique.length > 0
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function getPropType(prop, checker, fallbackNode) {
|
|
256
|
+
var _ref, _prop$valueDeclaratio, _prop$declarations;
|
|
257
|
+
const decl = (_ref = (_prop$valueDeclaratio = prop.valueDeclaration) !== null && _prop$valueDeclaratio !== void 0 ? _prop$valueDeclaratio : (_prop$declarations = prop.declarations) === null || _prop$declarations === void 0 ? void 0 : _prop$declarations[0]) !== null && _ref !== void 0 ? _ref : fallbackNode;
|
|
258
|
+
if (decl) return checker.getTypeOfSymbolAtLocation(prop, decl);
|
|
259
|
+
return checker.getTypeOfSymbol(prop);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Detects the structural `T | { [K in Keys]?: T }` pattern, returning the
|
|
263
|
+
* scalar `valueType`, declaration-ordered keys, and formatted object shape.
|
|
264
|
+
*/
|
|
265
|
+
function detectMappedUnion(rawType, rawTypeName, checker, locationNode) {
|
|
266
|
+
var _rawType$aliasSymbol;
|
|
267
|
+
if (!rawType.isUnion()) return null;
|
|
268
|
+
const nonUndefined = rawType.types.filter((t) => !(t.flags & ts.TypeFlags.Undefined));
|
|
269
|
+
if (nonUndefined.length < 2) return null;
|
|
270
|
+
const plainObjects = [];
|
|
271
|
+
const scalars = [];
|
|
272
|
+
for (const member of nonUndefined) if (isPlainAnonymousObject(member, checker)) plainObjects.push(member);
|
|
273
|
+
else scalars.push(member);
|
|
274
|
+
if (plainObjects.length !== 1 || scalars.length === 0) return null;
|
|
275
|
+
const objType = plainObjects[0];
|
|
276
|
+
const objProps = checker.getPropertiesOfType(objType);
|
|
277
|
+
if (objProps.length === 0 || objProps.length > MAX_MAPPED_KEYS) return null;
|
|
278
|
+
const { members: scalarMembers, allLiterals } = formatUnionMembersCanonical(scalars, checker, 1, /* @__PURE__ */ new Set([rawType, objType]));
|
|
279
|
+
if (scalarMembers.length === 0) return null;
|
|
280
|
+
const scalarKey = scalarMembers.join(" | ");
|
|
281
|
+
const keyEntries = [];
|
|
282
|
+
for (const prop of objProps) {
|
|
283
|
+
const propType = getPropType(prop, checker, locationNode);
|
|
284
|
+
const nonUndefPropTypes = (propType.isUnion() ? propType.types : [propType]).filter((t) => !(t.flags & ts.TypeFlags.Undefined));
|
|
285
|
+
if (nonUndefPropTypes.length === 0) return null;
|
|
286
|
+
const { members: propMembers } = formatUnionMembersCanonical(nonUndefPropTypes, checker, 1, /* @__PURE__ */ new Set([rawType, objType]));
|
|
287
|
+
if (propMembers.join(" | ") !== scalarKey) return null;
|
|
288
|
+
keyEntries.push({
|
|
289
|
+
name: prop.getName(),
|
|
290
|
+
optional: (prop.flags & ts.SymbolFlags.Optional) !== 0
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
const valueType = scalarKey;
|
|
294
|
+
const cleanRaw = stripTopLevelUndefined(rawTypeName);
|
|
295
|
+
const aliasFromSymbol = (_rawType$aliasSymbol = rawType.aliasSymbol) === null || _rawType$aliasSymbol === void 0 ? void 0 : _rawType$aliasSymbol.getName();
|
|
296
|
+
const aliasMatch = /^([A-Za-z_$][A-Za-z0-9_$]*)<.+>$/.exec(cleanRaw);
|
|
297
|
+
const alias = aliasFromSymbol !== null && aliasFromSymbol !== void 0 ? aliasFromSymbol : aliasMatch === null || aliasMatch === void 0 ? void 0 : aliasMatch[1];
|
|
298
|
+
const formatted = `{\n${keyEntries.map(({ name, optional }) => ` ${formatPropertyKey(name)}${optional ? "?" : ""}: ${valueType};`).join("\n")}\n}`;
|
|
299
|
+
return {
|
|
300
|
+
kind: "mapped-union",
|
|
301
|
+
...alias ? { alias } : {},
|
|
302
|
+
...allLiterals ? { values: scalarMembers } : {},
|
|
303
|
+
valueType,
|
|
304
|
+
keys: keyEntries.map((k) => k.name),
|
|
305
|
+
formatted
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
function indentBlock(str, spaces) {
|
|
309
|
+
const pad = " ".repeat(spaces);
|
|
310
|
+
return str.split("\n").map((line, i) => i === 0 ? line : `${pad}${line}`).join("\n");
|
|
311
|
+
}
|
|
312
|
+
function formatTypeNode(type, checker, depth, seen, locationNode) {
|
|
313
|
+
if (type.isStringLiteral()) return JSON.stringify(type.value);
|
|
314
|
+
if (type.isNumberLiteral()) return String(type.value);
|
|
315
|
+
if (type.flags & ts.TypeFlags.BigIntLiteral) return getTypeDisplayName(type, checker);
|
|
316
|
+
if (type.flags & ts.TypeFlags.BooleanLiteral) return checker.typeToString(type);
|
|
317
|
+
if (isPrimitiveOrIntrinsic(type)) return getTypeDisplayName(type, checker);
|
|
318
|
+
if (depth > MAX_EXPAND_DEPTH || seen.has(type)) return getTypeDisplayName(type, checker);
|
|
319
|
+
const nextSeen = new Set(seen);
|
|
320
|
+
nextSeen.add(type);
|
|
321
|
+
const arrayInfo = getArrayElementType(type, checker);
|
|
322
|
+
if (arrayInfo) {
|
|
323
|
+
const inner = formatTypeNode(arrayInfo.elementType, checker, depth, nextSeen, locationNode);
|
|
324
|
+
const wrapped = splitTopLevelUnion(inner).length > 1 || inner.includes("=>") || inner.includes(" & ") ? `(${inner})` : inner;
|
|
325
|
+
return arrayInfo.readonly ? `readonly ${wrapped}[]` : `${wrapped}[]`;
|
|
326
|
+
}
|
|
327
|
+
if (checker.isTupleType(type)) return `[${checker.getTypeArguments(type).map((arg) => formatTypeNode(arg, checker, depth + 1, nextSeen, locationNode)).join(", ")}]`;
|
|
328
|
+
const displayName = getTypeDisplayName(type, checker);
|
|
329
|
+
if (isStopType(type, checker) || isStopDisplayType(displayName)) return displayName;
|
|
330
|
+
if (type.isIntersection()) {
|
|
331
|
+
const str = getTypeDisplayName(type, checker);
|
|
332
|
+
return depth > 0 && str.includes(" & ") && !str.startsWith("(") ? `(${str})` : str;
|
|
333
|
+
}
|
|
334
|
+
if (type.isUnion()) {
|
|
335
|
+
if (depth > 0) {
|
|
336
|
+
const nestedMapped = detectMappedUnion(type, getTypeDisplayName(type, checker), checker, locationNode);
|
|
337
|
+
if (nestedMapped) return nestedMapped.alias ? `${nestedMapped.alias}<${nestedMapped.valueType}>` : `${nestedMapped.valueType} | { ${nestedMapped.keys.map((k) => `${formatPropertyKey(k)}?`).join(", ")} }`;
|
|
338
|
+
}
|
|
339
|
+
const { members } = formatUnionMembersCanonical(type.types, checker, depth + 1, nextSeen);
|
|
340
|
+
if (type.types.some((t) => (t.flags & ts.TypeFlags.Undefined) !== 0) && depth > 0) members.push("undefined");
|
|
341
|
+
const inline = members.join(" | ");
|
|
342
|
+
if (depth === 0 && (members.length > 4 || inline.length > 60)) return members.map((m) => `| ${m}`).join("\n");
|
|
343
|
+
return inline;
|
|
344
|
+
}
|
|
345
|
+
const callSigs = type.getCallSignatures();
|
|
346
|
+
if (callSigs.length > 0 && checker.getPropertiesOfType(type).length === 0) {
|
|
347
|
+
const sig = callSigs[0];
|
|
348
|
+
const params = sig.getParameters().map((param) => {
|
|
349
|
+
const pType = getPropType(param, checker, locationNode);
|
|
350
|
+
const isOptional = (param.flags & ts.SymbolFlags.Optional) !== 0;
|
|
351
|
+
const pTypeStr = formatTypeNode(isOptional && !isStopType(pType) ? stripUndefinedFromTsType(pType, checker) : pType, checker, depth + 1, nextSeen, locationNode);
|
|
352
|
+
return `${param.getName()}${isOptional ? "?" : ""}: ${pTypeStr}`;
|
|
353
|
+
});
|
|
354
|
+
const retStr = formatTypeNode(sig.getReturnType(), checker, depth + 1, nextSeen, locationNode);
|
|
355
|
+
return `(${params.join(", ")}) => ${retStr}`;
|
|
356
|
+
}
|
|
357
|
+
if (isPlainAnonymousObject(type, checker)) {
|
|
358
|
+
const allProps = checker.getPropertiesOfType(type);
|
|
359
|
+
if (allProps.length === 0) return getTypeDisplayName(type, checker);
|
|
360
|
+
const ownProps = allProps.filter((p) => !isPropertyInheritedFromExternalLibs(p));
|
|
361
|
+
const inheritedCount = allProps.length - ownProps.length;
|
|
362
|
+
if (ownProps.length === 0) return getTypeDisplayName(type, checker);
|
|
363
|
+
const sortedProps = [...ownProps].sort((a, b) => compareStrings(a.getName(), b.getName()));
|
|
364
|
+
const visibleProps = sortedProps.slice(0, MAX_OBJECT_PROPS);
|
|
365
|
+
const hiddenOwnCount = sortedProps.length - visibleProps.length;
|
|
366
|
+
const lines = visibleProps.map((prop) => {
|
|
367
|
+
const isOptional = (prop.flags & ts.SymbolFlags.Optional) !== 0;
|
|
368
|
+
const rawPType = getPropType(prop, checker, locationNode);
|
|
369
|
+
const indentedType = indentBlock(formatTypeNode(isOptional && rawPType.isUnion() && !isStopType(rawPType) ? stripUndefinedFromTsType(rawPType, checker) : rawPType, checker, depth + 1, nextSeen, locationNode), 2);
|
|
370
|
+
return ` ${formatPropertyKey(prop.getName())}${isOptional ? "?" : ""}: ${indentedType};`;
|
|
371
|
+
});
|
|
372
|
+
if (hiddenOwnCount > 0) lines.push(` // ...${hiddenOwnCount} more properties`);
|
|
373
|
+
if (inheritedCount > 0) lines.push(` // ...HTML attributes`);
|
|
374
|
+
return `{\n${lines.join("\n")}\n}`;
|
|
375
|
+
}
|
|
376
|
+
return getTypeDisplayName(type, checker);
|
|
377
|
+
}
|
|
378
|
+
function stripUndefinedFromTsType(type, checker) {
|
|
379
|
+
if (!type.isUnion()) return type;
|
|
380
|
+
const nonUndef = type.types.filter((t) => !(t.flags & ts.TypeFlags.Undefined));
|
|
381
|
+
if (nonUndef.length === 1) return nonUndef[0];
|
|
382
|
+
return checker.getNonNullableType(type);
|
|
383
|
+
}
|
|
384
|
+
function normalizeForComparison(str) {
|
|
385
|
+
return str.replace(/^\|\s*/gm, "").replace(/\s*\n\s*/g, " | ").replace(/\s+/g, " ").replace(/^\((.+)\)$/, "$1").trim();
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Inspects a prop's resolved TypeScript type and returns structured expanded
|
|
389
|
+
* type metadata when expansion adds meaningful clarity beyond the display name.
|
|
390
|
+
*/
|
|
391
|
+
function expandPropType(rawPropType, displayedTypeName, isEnum, checker, locationNode) {
|
|
392
|
+
var _rawPropType$getConst;
|
|
393
|
+
if (isEnum) return void 0;
|
|
394
|
+
const displayBase = stripTopLevelUndefined(normalizeDisplayType(displayedTypeName));
|
|
395
|
+
if (isStopDisplayType(displayBase)) return;
|
|
396
|
+
const propType = (_rawPropType$getConst = rawPropType.getConstraint()) !== null && _rawPropType$getConst !== void 0 ? _rawPropType$getConst : rawPropType;
|
|
397
|
+
const mappedUnion = detectMappedUnion(propType, displayedTypeName, checker, locationNode);
|
|
398
|
+
if (mappedUnion) return mappedUnion;
|
|
399
|
+
const nonUndefMembers = propType.isUnion() ? propType.types.filter((t) => !(t.flags & ts.TypeFlags.Undefined)) : [propType];
|
|
400
|
+
if (nonUndefMembers.length === 0) return void 0;
|
|
401
|
+
const coreType = nonUndefMembers.length === 1 ? nonUndefMembers[0] : propType;
|
|
402
|
+
if (isPrimitiveOrIntrinsic(coreType) || isStopType(coreType, checker)) return;
|
|
403
|
+
let formatted;
|
|
404
|
+
let kind;
|
|
405
|
+
if (nonUndefMembers.length > 1) {
|
|
406
|
+
const { members } = formatUnionMembersCanonical(nonUndefMembers, checker, 1, /* @__PURE__ */ new Set([propType]));
|
|
407
|
+
const inline = members.join(" | ");
|
|
408
|
+
formatted = members.length > 4 || inline.length > 60 ? members.map((m) => `| ${m}`).join("\n") : inline;
|
|
409
|
+
kind = "union";
|
|
410
|
+
} else {
|
|
411
|
+
formatted = formatTypeNode(coreType, checker, 0, /* @__PURE__ */ new Set(), locationNode);
|
|
412
|
+
if (coreType.getCallSignatures().length > 0 && checker.getPropertiesOfType(coreType).length === 0) kind = "function";
|
|
413
|
+
else if (isPlainAnonymousObject(coreType, checker)) kind = "object";
|
|
414
|
+
else kind = "alias";
|
|
415
|
+
}
|
|
416
|
+
if (normalizeForComparison(formatted) === normalizeForComparison(displayBase)) return;
|
|
417
|
+
if (formatted.includes("{ ...; }")) return;
|
|
418
|
+
return {
|
|
419
|
+
kind,
|
|
420
|
+
formatted
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Resolves a map of `propName -> { type, locationNode }` for a parsed component
|
|
425
|
+
* expression symbol using the shared TypeScript `TypeChecker`.
|
|
426
|
+
*/
|
|
427
|
+
function resolveComponentPropTypes(expression, checker) {
|
|
428
|
+
var _target$valueDeclarat, _target$declarations, _ref2, _propsSymbol$valueDec, _propsSymbol$declarat;
|
|
429
|
+
const result = /* @__PURE__ */ new Map();
|
|
430
|
+
if (!expression) return result;
|
|
431
|
+
let target = expression;
|
|
432
|
+
if (target.flags & ts.SymbolFlags.Alias) target = checker.getAliasedSymbol(target);
|
|
433
|
+
const decl = (_target$valueDeclarat = target.valueDeclaration) !== null && _target$valueDeclarat !== void 0 ? _target$valueDeclarat : (_target$declarations = target.declarations) === null || _target$declarations === void 0 ? void 0 : _target$declarations[0];
|
|
434
|
+
if (!decl) return result;
|
|
435
|
+
const compType = checker.getTypeOfSymbolAtLocation(target, decl);
|
|
436
|
+
let propsSymbol;
|
|
437
|
+
for (const sig of compType.getCallSignatures()) {
|
|
438
|
+
const params = sig.getParameters();
|
|
439
|
+
if (params.length === 0) continue;
|
|
440
|
+
const first = params[0];
|
|
441
|
+
if (first.name === "props" || params.length === 1) {
|
|
442
|
+
propsSymbol = first;
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (!propsSymbol) for (const sig of compType.getConstructSignatures()) {
|
|
447
|
+
const prop = sig.getReturnType().getProperty("props");
|
|
448
|
+
if (prop) {
|
|
449
|
+
propsSymbol = prop;
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
if (!propsSymbol) return result;
|
|
454
|
+
const propsDecl = (_ref2 = (_propsSymbol$valueDec = propsSymbol.valueDeclaration) !== null && _propsSymbol$valueDec !== void 0 ? _propsSymbol$valueDec : (_propsSymbol$declarat = propsSymbol.declarations) === null || _propsSymbol$declarat === void 0 ? void 0 : _propsSymbol$declarat[0]) !== null && _ref2 !== void 0 ? _ref2 : decl;
|
|
455
|
+
const propsType = checker.getTypeOfSymbolAtLocation(propsSymbol, propsDecl);
|
|
456
|
+
const propSymbols = [...propsType.getApparentProperties()];
|
|
457
|
+
if (propsType.isUnionOrIntersection()) for (const memberType of propsType.types) propSymbols.push(...memberType.getApparentProperties());
|
|
458
|
+
for (const prop of propSymbols) {
|
|
459
|
+
const name = prop.getName();
|
|
460
|
+
if (result.has(name)) continue;
|
|
461
|
+
const propType = checker.getTypeOfSymbolAtLocation(prop, propsDecl);
|
|
462
|
+
result.set(name, {
|
|
463
|
+
type: propType,
|
|
464
|
+
locationNode: propsDecl
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
return result;
|
|
468
|
+
}
|
|
469
|
+
//#endregion
|
|
470
|
+
export { compareStrings, expandPropType, normalizeDisplayType, resolveComponentPropTypes, splitTopLevelUnion, stripTopLevelUndefined };
|
|
471
|
+
|
|
472
|
+
//# sourceMappingURL=type-expander.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-expander.mjs","names":[],"sources":["../../src/type-expander.ts"],"sourcesContent":["import ts from \"typescript\";\n\nexport type ExpandedPropType =\n | {\n kind: \"mapped-union\";\n alias?: string;\n values?: string[];\n valueType: string;\n keys: string[];\n formatted: string;\n }\n | {\n kind: \"alias\" | \"object\" | \"union\" | \"function\";\n formatted: string;\n };\n\nconst STOP_TYPE_NAMES = new Set([\n \"ReactNode\",\n \"ReactElement\",\n \"ReactPortal\",\n \"ReactFragment\",\n \"Element\",\n \"JSX.Element\",\n \"CSSProperties\",\n \"ElementType\",\n \"ComponentType\",\n \"ComponentProps\",\n \"ComponentPropsWithRef\",\n \"ComponentPropsWithoutRef\",\n \"Ref\",\n \"RefObject\",\n \"MutableRefObject\",\n \"ForwardedRef\",\n \"LegacyRef\",\n \"HTMLAttributes\",\n \"SVGAttributes\",\n \"DOMAttributes\",\n \"SyntheticEvent\",\n \"MouseEvent\",\n \"KeyboardEvent\",\n \"FocusEvent\",\n \"ChangeEvent\",\n \"PointerEvent\",\n \"TouchEvent\",\n \"UIEvent\",\n \"Event\",\n \"Date\",\n \"RegExp\",\n \"Promise\",\n \"Map\",\n \"Set\",\n \"WeakMap\",\n \"WeakSet\",\n \"URL\",\n \"File\",\n \"Blob\",\n \"FormData\",\n \"Error\",\n]);\n\nconst UTILITY_ALIAS_NAMES = new Set([\n \"Partial\",\n \"Required\",\n \"Readonly\",\n \"Record\",\n \"Pick\",\n \"Omit\",\n \"NonNullable\",\n \"Exclude\",\n \"Extract\",\n]);\n\nconst VALID_IDENTIFIER_RE = /^[A-Za-z_$][A-Za-z0-9_$]*$/;\n\nconst MAX_MAPPED_KEYS = 24;\nconst MAX_OBJECT_PROPS = 14;\nconst MAX_EXPAND_DEPTH = 2;\n\nexport function compareStrings(a: string, b: string): number {\n return a < b ? -1 : a > b ? 1 : 0;\n}\n\n/**\n * Splits a TypeScript type string on top-level `|` operators only,\n * preserving `|` inside `<...>`, `{...}`, `(...)`, `[...]`, and string literals.\n */\nexport function splitTopLevelUnion(str: string): string[] {\n if (!str.includes(\"|\")) {\n return [str.trim()];\n }\n\n const parts: string[] = [];\n let current = \"\";\n let depthParen = 0;\n let depthAngle = 0;\n let depthBrace = 0;\n let depthBracket = 0;\n let inQuote: string | null = null;\n\n for (let i = 0; i < str.length; i++) {\n const ch = str[i]!;\n if (inQuote) {\n current += ch;\n if (ch === inQuote && str[i - 1] !== \"\\\\\") {\n inQuote = null;\n }\n continue;\n }\n\n if (ch === '\"' || ch === \"'\" || ch === \"`\") {\n inQuote = ch;\n current += ch;\n continue;\n }\n\n if (ch === \"(\") depthParen++;\n else if (ch === \")\") depthParen = Math.max(0, depthParen - 1);\n else if (ch === \"<\") depthAngle++;\n else if (ch === \">\" && str[i - 1] !== \"=\")\n depthAngle = Math.max(0, depthAngle - 1);\n else if (ch === \"{\") depthBrace++;\n else if (ch === \"}\") depthBrace = Math.max(0, depthBrace - 1);\n else if (ch === \"[\") depthBracket++;\n else if (ch === \"]\") depthBracket = Math.max(0, depthBracket - 1);\n\n if (\n ch === \"|\" &&\n depthParen === 0 &&\n depthAngle === 0 &&\n depthBrace === 0 &&\n depthBracket === 0\n ) {\n parts.push(current.trim());\n current = \"\";\n } else {\n current += ch;\n }\n }\n\n parts.push(current.trim());\n return parts.filter((part) => part.length > 0);\n}\n\nexport function stripTopLevelUndefined(str: string): string {\n const parts = splitTopLevelUnion(str).filter((p) => p !== \"undefined\");\n return parts.join(\" | \");\n}\n\nfunction sortUnionMembers(members: string[]): string[] {\n return [...members].sort((a, b) => {\n if (a === \"undefined\" && b !== \"undefined\") return 1;\n if (b === \"undefined\" && a !== \"undefined\") return -1;\n if (a === \"null\" && b !== \"null\") return 1;\n if (b === \"null\" && a !== \"null\") return -1;\n return compareStrings(a, b);\n });\n}\n\nfunction formatPropertyKey(name: string): string {\n return VALID_IDENTIFIER_RE.test(name) ? name : JSON.stringify(name);\n}\n\nfunction isDeclarationInExternalLibs(\n decl: ts.Declaration | undefined\n): boolean {\n if (!decl) return false;\n const fileName = decl.getSourceFile().fileName.replace(/\\\\/g, \"/\");\n return (\n fileName.includes(\"/node_modules/@types/react/\") ||\n fileName.includes(\"/node_modules/typescript/lib/lib.\")\n );\n}\n\nfunction isPropertyInheritedFromExternalLibs(prop: ts.Symbol): boolean {\n const decls = prop.getDeclarations();\n if (!decls || decls.length === 0) return false;\n return decls.every((d) => isDeclarationInExternalLibs(d));\n}\n\nconst DEFAULT_ELEMENT_TYPE_RE =\n /\\b(?:React\\.)?ElementType<any,\\s*keyof\\s+(?:JSX\\.)?IntrinsicElements>/g;\n\nexport function normalizeDisplayType(str: string): string {\n return str.replace(DEFAULT_ELEMENT_TYPE_RE, \"React.ElementType\");\n}\n\nconst PRIMITIVE_DISPLAY_NAMES = new Set([\n \"string\",\n \"number\",\n \"boolean\",\n \"null\",\n \"undefined\",\n \"symbol\",\n \"bigint\",\n \"void\",\n \"never\",\n \"unknown\",\n \"any\",\n]);\n\nfunction isStopTypeName(typeStr: string): boolean {\n const trimmed = typeStr.trim();\n if (!trimmed) return false;\n const genericIdx = trimmed.indexOf(\"<\");\n const baseName = (\n genericIdx === -1 ? trimmed : trimmed.slice(0, genericIdx)\n ).trim();\n if (STOP_TYPE_NAMES.has(baseName)) {\n return true;\n }\n const dotIdx = baseName.lastIndexOf(\".\");\n if (dotIdx !== -1 && STOP_TYPE_NAMES.has(baseName.slice(dotIdx + 1))) {\n return true;\n }\n return false;\n}\n\nfunction isStopDisplayType(displayBase: string): boolean {\n const parts = splitTopLevelUnion(displayBase).filter(\n (p) => p !== \"undefined\"\n );\n if (parts.length === 0) return false;\n let hasStopType = false;\n for (const part of parts) {\n if (isStopTypeName(part)) {\n hasStopType = true;\n } else if (!PRIMITIVE_DISPLAY_NAMES.has(part)) {\n return false;\n }\n }\n return hasStopType;\n}\n\nfunction getTypeDisplayName(type: ts.Type, checker: ts.TypeChecker): string {\n return normalizeDisplayType(\n checker.typeToString(type, undefined, ts.TypeFormatFlags.NoTruncation)\n );\n}\n\nfunction isStopType(type: ts.Type, checker?: ts.TypeChecker): boolean {\n if (\n checker &&\n (getArrayElementType(type, checker) || checker.isTupleType(type))\n ) {\n return false;\n }\n\n const aliasName = type.aliasSymbol?.getName();\n if (aliasName && STOP_TYPE_NAMES.has(aliasName)) {\n return true;\n }\n\n const symbol = type.getSymbol();\n if (symbol) {\n const name = symbol.getName();\n if (name === \"Array\" || name === \"ReadonlyArray\") {\n return false;\n }\n if (STOP_TYPE_NAMES.has(name)) {\n return true;\n }\n\n // Nominal DOM / built-in / React interfaces (e.g. HTMLElement, HTMLDivElement, SVGElement)\n const decl = symbol.valueDeclaration ?? symbol.declarations?.[0];\n if (\n decl &&\n isDeclarationInExternalLibs(decl) &&\n !(aliasName && UTILITY_ALIAS_NAMES.has(aliasName)) &&\n name !== \"__type\" &&\n name !== \"__object\"\n ) {\n return true;\n }\n }\n\n return false;\n}\n\nfunction isPrimitiveOrIntrinsic(type: ts.Type): boolean {\n return Boolean(\n type.flags &\n (ts.TypeFlags.String |\n ts.TypeFlags.Number |\n ts.TypeFlags.Boolean |\n ts.TypeFlags.BigInt |\n ts.TypeFlags.ESSymbol |\n ts.TypeFlags.UniqueESSymbol |\n ts.TypeFlags.Void |\n ts.TypeFlags.Undefined |\n ts.TypeFlags.Null |\n ts.TypeFlags.Never |\n ts.TypeFlags.Any |\n ts.TypeFlags.Unknown |\n ts.TypeFlags.NonPrimitive)\n );\n}\n\nfunction isLiteralType(type: ts.Type): boolean {\n return Boolean(\n type.flags &\n (ts.TypeFlags.StringLiteral |\n ts.TypeFlags.NumberLiteral |\n ts.TypeFlags.BigIntLiteral |\n ts.TypeFlags.EnumLiteral)\n );\n}\n\nfunction isPlainAnonymousObject(\n type: ts.Type,\n checker: ts.TypeChecker\n): boolean {\n if (!(type.flags & ts.TypeFlags.Object)) return false;\n if (checker.isArrayType(type) || checker.isTupleType(type)) return false;\n if (type.getCallSignatures().length > 0) return false;\n if (type.getConstructSignatures().length > 0) return false;\n if (isStopType(type)) return false;\n return true;\n}\n\nfunction isReadonlyArrayType(type: ts.Type): boolean {\n const symbol = type.getSymbol();\n return symbol?.getName() === \"ReadonlyArray\";\n}\n\nfunction getArrayElementType(\n type: ts.Type,\n checker: ts.TypeChecker\n): { elementType: ts.Type; readonly: boolean } | null {\n if (isReadonlyArrayType(type)) {\n const typeArgs = checker.getTypeArguments(type as ts.TypeReference);\n if (typeArgs[0]) {\n return { elementType: typeArgs[0], readonly: true };\n }\n }\n if (checker.isArrayType(type)) {\n const typeArgs = checker.getTypeArguments(type as ts.TypeReference);\n if (typeArgs[0]) {\n return { elementType: typeArgs[0], readonly: false };\n }\n }\n return null;\n}\n\n/**\n * Formats a list of union member types into canonical sorted strings,\n * collapsing `false` + `true` boolean literals back into `boolean`.\n */\nfunction formatUnionMembersCanonical(\n types: readonly ts.Type[],\n checker: ts.TypeChecker,\n depth: number,\n seen: Set<ts.Type>\n): { members: string[]; allLiterals: boolean } {\n let hasTrue = false;\n let hasFalse = false;\n const rest: ts.Type[] = [];\n\n for (const t of types) {\n if (t.flags & ts.TypeFlags.Undefined) continue;\n if (t.flags & ts.TypeFlags.BooleanLiteral) {\n const str = checker.typeToString(t);\n if (str === \"true\") hasTrue = true;\n else if (str === \"false\") hasFalse = true;\n else rest.push(t);\n } else {\n rest.push(t);\n }\n }\n\n const formatted: string[] = [];\n let allLiterals = true;\n\n if (hasTrue && hasFalse) {\n formatted.push(\"boolean\");\n allLiterals = false;\n } else {\n if (hasFalse) formatted.push(\"false\");\n if (hasTrue) formatted.push(\"true\");\n }\n\n for (const t of rest) {\n if (!isLiteralType(t)) {\n allLiterals = false;\n }\n formatted.push(formatTypeNode(t, checker, depth, seen));\n }\n\n const unique = Array.from(new Set(formatted));\n return {\n members: sortUnionMembers(unique),\n allLiterals: allLiterals && unique.length > 0,\n };\n}\n\nfunction getPropType(\n prop: ts.Symbol,\n checker: ts.TypeChecker,\n fallbackNode?: ts.Node\n): ts.Type {\n const decl = prop.valueDeclaration ?? prop.declarations?.[0] ?? fallbackNode;\n if (decl) {\n return checker.getTypeOfSymbolAtLocation(prop, decl);\n }\n return checker.getTypeOfSymbol(prop);\n}\n\n/**\n * Detects the structural `T | { [K in Keys]?: T }` pattern, returning the\n * scalar `valueType`, declaration-ordered keys, and formatted object shape.\n */\nfunction detectMappedUnion(\n rawType: ts.Type,\n rawTypeName: string,\n checker: ts.TypeChecker,\n locationNode?: ts.Node\n): Extract<ExpandedPropType, { kind: \"mapped-union\" }> | null {\n if (!rawType.isUnion()) return null;\n\n const nonUndefined = rawType.types.filter(\n (t) => !(t.flags & ts.TypeFlags.Undefined)\n );\n if (nonUndefined.length < 2) return null;\n\n const plainObjects: ts.Type[] = [];\n const scalars: ts.Type[] = [];\n\n for (const member of nonUndefined) {\n if (isPlainAnonymousObject(member, checker)) {\n plainObjects.push(member);\n } else {\n scalars.push(member);\n }\n }\n\n if (plainObjects.length !== 1 || scalars.length === 0) {\n return null;\n }\n\n const objType = plainObjects[0]!;\n const objProps = checker.getPropertiesOfType(objType);\n if (objProps.length === 0 || objProps.length > MAX_MAPPED_KEYS) {\n return null;\n }\n\n const { members: scalarMembers, allLiterals } = formatUnionMembersCanonical(\n scalars,\n checker,\n 1,\n new Set([rawType, objType])\n );\n if (scalarMembers.length === 0) return null;\n\n const scalarKey = scalarMembers.join(\" | \");\n const keyEntries: { name: string; optional: boolean }[] = [];\n\n for (const prop of objProps) {\n const propType = getPropType(prop, checker, locationNode);\n const propTypes = propType.isUnion() ? propType.types : [propType];\n const nonUndefPropTypes = propTypes.filter(\n (t) => !(t.flags & ts.TypeFlags.Undefined)\n );\n if (nonUndefPropTypes.length === 0) {\n return null;\n }\n\n const { members: propMembers } = formatUnionMembersCanonical(\n nonUndefPropTypes,\n checker,\n 1,\n new Set([rawType, objType])\n );\n if (propMembers.join(\" | \") !== scalarKey) {\n return null;\n }\n\n keyEntries.push({\n name: prop.getName(),\n optional: (prop.flags & ts.SymbolFlags.Optional) !== 0,\n });\n }\n\n const valueType = scalarKey;\n\n const cleanRaw = stripTopLevelUndefined(rawTypeName);\n const aliasFromSymbol = rawType.aliasSymbol?.getName();\n const aliasMatch = /^([A-Za-z_$][A-Za-z0-9_$]*)<.+>$/.exec(cleanRaw);\n const alias = aliasFromSymbol ?? aliasMatch?.[1];\n\n const objectLines = keyEntries.map(\n ({ name, optional }) =>\n ` ${formatPropertyKey(name)}${optional ? \"?\" : \"\"}: ${valueType};`\n );\n const formatted = `{\\n${objectLines.join(\"\\n\")}\\n}`;\n\n return {\n kind: \"mapped-union\",\n ...(alias ? { alias } : {}),\n ...(allLiterals ? { values: scalarMembers } : {}),\n valueType,\n keys: keyEntries.map((k) => k.name),\n formatted,\n };\n}\n\nfunction indentBlock(str: string, spaces: number): string {\n const pad = \" \".repeat(spaces);\n return str\n .split(\"\\n\")\n .map((line, i) => (i === 0 ? line : `${pad}${line}`))\n .join(\"\\n\");\n}\n\nfunction formatTypeNode(\n type: ts.Type,\n checker: ts.TypeChecker,\n depth: number,\n seen: Set<ts.Type>,\n locationNode?: ts.Node\n): string {\n if (type.isStringLiteral()) {\n return JSON.stringify(type.value);\n }\n if (type.isNumberLiteral()) {\n return String(type.value);\n }\n if (type.flags & ts.TypeFlags.BigIntLiteral) {\n return getTypeDisplayName(type, checker);\n }\n if (type.flags & ts.TypeFlags.BooleanLiteral) {\n return checker.typeToString(type);\n }\n if (isPrimitiveOrIntrinsic(type)) {\n return getTypeDisplayName(type, checker);\n }\n\n if (depth > MAX_EXPAND_DEPTH || seen.has(type)) {\n return getTypeDisplayName(type, checker);\n }\n\n const nextSeen = new Set(seen);\n nextSeen.add(type);\n\n // Array / ReadonlyArray (must run before isStopType since Array/ReadonlyArray live in lib.es5.d.ts)\n const arrayInfo = getArrayElementType(type, checker);\n if (arrayInfo) {\n const inner = formatTypeNode(\n arrayInfo.elementType,\n checker,\n depth,\n nextSeen,\n locationNode\n );\n const needsParens =\n splitTopLevelUnion(inner).length > 1 ||\n inner.includes(\"=>\") ||\n inner.includes(\" & \");\n const wrapped = needsParens ? `(${inner})` : inner;\n return arrayInfo.readonly ? `readonly ${wrapped}[]` : `${wrapped}[]`;\n }\n\n // Tuple\n if (checker.isTupleType(type)) {\n const args = checker.getTypeArguments(type as ts.TypeReference);\n const formattedArgs = args.map((arg) =>\n formatTypeNode(arg, checker, depth + 1, nextSeen, locationNode)\n );\n return `[${formattedArgs.join(\", \")}]`;\n }\n\n const displayName = getTypeDisplayName(type, checker);\n if (isStopType(type, checker) || isStopDisplayType(displayName)) {\n return displayName;\n }\n\n // Intersection\n if (type.isIntersection()) {\n const str = getTypeDisplayName(type, checker);\n return depth > 0 && str.includes(\" & \") && !str.startsWith(\"(\")\n ? `(${str})`\n : str;\n }\n\n // Union\n if (type.isUnion()) {\n if (depth > 0) {\n const nestedMapped = detectMappedUnion(\n type,\n getTypeDisplayName(type, checker),\n checker,\n locationNode\n );\n if (nestedMapped) {\n return nestedMapped.alias\n ? `${nestedMapped.alias}<${nestedMapped.valueType}>`\n : `${nestedMapped.valueType} | { ${nestedMapped.keys.map((k) => `${formatPropertyKey(k)}?`).join(\", \")} }`;\n }\n }\n\n const { members } = formatUnionMembersCanonical(\n type.types,\n checker,\n depth + 1,\n nextSeen\n );\n const hasUndefined = type.types.some(\n (t) => (t.flags & ts.TypeFlags.Undefined) !== 0\n );\n if (hasUndefined && depth > 0) {\n members.push(\"undefined\");\n }\n const inline = members.join(\" | \");\n if (depth === 0 && (members.length > 4 || inline.length > 60)) {\n return members.map((m) => `| ${m}`).join(\"\\n\");\n }\n return inline;\n }\n\n // Function type (callable without non-method properties)\n const callSigs = type.getCallSignatures();\n if (callSigs.length > 0 && checker.getPropertiesOfType(type).length === 0) {\n const sig = callSigs[0]!;\n const params = sig.getParameters().map((param) => {\n const pType = getPropType(param, checker, locationNode);\n const isOptional = (param.flags & ts.SymbolFlags.Optional) !== 0;\n const effectivePType =\n isOptional && !isStopType(pType)\n ? stripUndefinedFromTsType(pType, checker)\n : pType;\n const pTypeStr = formatTypeNode(\n effectivePType,\n checker,\n depth + 1,\n nextSeen,\n locationNode\n );\n return `${param.getName()}${isOptional ? \"?\" : \"\"}: ${pTypeStr}`;\n });\n const retStr = formatTypeNode(\n sig.getReturnType(),\n checker,\n depth + 1,\n nextSeen,\n locationNode\n );\n return `(${params.join(\", \")}) => ${retStr}`;\n }\n\n // Plain / mapped / utility object type\n if (isPlainAnonymousObject(type, checker)) {\n const allProps = checker.getPropertiesOfType(type);\n if (allProps.length === 0) {\n return getTypeDisplayName(type, checker);\n }\n\n const ownProps = allProps.filter(\n (p) => !isPropertyInheritedFromExternalLibs(p)\n );\n const inheritedCount = allProps.length - ownProps.length;\n\n // If an object consists purely of external DOM/React props, don't expand it.\n if (ownProps.length === 0) {\n return getTypeDisplayName(type, checker);\n }\n\n const sortedProps = [...ownProps].sort((a, b) =>\n compareStrings(a.getName(), b.getName())\n );\n const visibleProps = sortedProps.slice(0, MAX_OBJECT_PROPS);\n const hiddenOwnCount = sortedProps.length - visibleProps.length;\n\n const lines = visibleProps.map((prop) => {\n const isOptional = (prop.flags & ts.SymbolFlags.Optional) !== 0;\n const rawPType = getPropType(prop, checker, locationNode);\n const effectivePType =\n isOptional && rawPType.isUnion() && !isStopType(rawPType)\n ? stripUndefinedFromTsType(rawPType, checker)\n : rawPType;\n const formattedPropType = formatTypeNode(\n effectivePType,\n checker,\n depth + 1,\n nextSeen,\n locationNode\n );\n const indentedType = indentBlock(formattedPropType, 2);\n return ` ${formatPropertyKey(prop.getName())}${isOptional ? \"?\" : \"\"}: ${indentedType};`;\n });\n\n if (hiddenOwnCount > 0) {\n lines.push(` // ...${hiddenOwnCount} more properties`);\n }\n if (inheritedCount > 0) {\n lines.push(` // ...HTML attributes`);\n }\n\n return `{\\n${lines.join(\"\\n\")}\\n}`;\n }\n\n return getTypeDisplayName(type, checker);\n}\n\nfunction stripUndefinedFromTsType(\n type: ts.Type,\n checker: ts.TypeChecker\n): ts.Type {\n if (!type.isUnion()) return type;\n const nonUndef = type.types.filter(\n (t) => !(t.flags & ts.TypeFlags.Undefined)\n );\n if (nonUndef.length === 1) return nonUndef[0]!;\n return checker.getNonNullableType(type);\n}\n\nfunction normalizeForComparison(str: string): string {\n return str\n .replace(/^\\|\\s*/gm, \"\")\n .replace(/\\s*\\n\\s*/g, \" | \")\n .replace(/\\s+/g, \" \")\n .replace(/^\\((.+)\\)$/, \"$1\")\n .trim();\n}\n\n/**\n * Inspects a prop's resolved TypeScript type and returns structured expanded\n * type metadata when expansion adds meaningful clarity beyond the display name.\n */\nexport function expandPropType(\n rawPropType: ts.Type,\n displayedTypeName: string,\n isEnum: boolean,\n checker: ts.TypeChecker,\n locationNode?: ts.Node\n): ExpandedPropType | undefined {\n // Flat literal enums already carry all their values in `type.value`.\n if (isEnum) return undefined;\n\n const displayBase = stripTopLevelUndefined(\n normalizeDisplayType(displayedTypeName)\n );\n\n // Stop-type union aliases (e.g. `ElementType | undefined`, `Ref<T> | undefined`)\n // lose their `aliasSymbol` when TypeScript flattens `| undefined` into a union.\n if (isStopDisplayType(displayBase)) {\n return undefined;\n }\n\n const propType = rawPropType.getConstraint() ?? rawPropType;\n\n // 1. Structural `T | { [K in Keys]?: T }` mapped union\n const mappedUnion = detectMappedUnion(\n propType,\n displayedTypeName,\n checker,\n locationNode\n );\n if (mappedUnion) {\n return mappedUnion;\n }\n\n // 2. Unwrap optional `| undefined` for general expansion\n const nonUndefMembers = propType.isUnion()\n ? propType.types.filter((t) => !(t.flags & ts.TypeFlags.Undefined))\n : [propType];\n\n if (nonUndefMembers.length === 0) return undefined;\n\n const coreType =\n nonUndefMembers.length === 1 ? nonUndefMembers[0]! : propType;\n\n if (isPrimitiveOrIntrinsic(coreType) || isStopType(coreType, checker)) {\n return undefined;\n }\n\n // Format the resolved type\n let formatted: string;\n let kind: \"alias\" | \"object\" | \"union\" | \"function\";\n\n if (nonUndefMembers.length > 1) {\n const { members } = formatUnionMembersCanonical(\n nonUndefMembers,\n checker,\n 1,\n new Set([propType])\n );\n const inline = members.join(\" | \");\n formatted =\n members.length > 4 || inline.length > 60\n ? members.map((m) => `| ${m}`).join(\"\\n\")\n : inline;\n kind = \"union\";\n } else {\n formatted = formatTypeNode(coreType, checker, 0, new Set(), locationNode);\n if (\n coreType.getCallSignatures().length > 0 &&\n checker.getPropertiesOfType(coreType).length === 0\n ) {\n kind = \"function\";\n } else if (isPlainAnonymousObject(coreType, checker)) {\n kind = \"object\";\n } else {\n kind = \"alias\";\n }\n }\n\n // Only emit `expanded` if it genuinely adds information over `displayBase`\n if (\n normalizeForComparison(formatted) === normalizeForComparison(displayBase)\n ) {\n return undefined;\n }\n\n // Don't emit noisy expansion if formatting failed to resolve beyond `{ ...; }`\n if (formatted.includes(\"{ ...; }\")) {\n return undefined;\n }\n\n return { kind, formatted };\n}\n\n/**\n * Resolves a map of `propName -> { type, locationNode }` for a parsed component\n * expression symbol using the shared TypeScript `TypeChecker`.\n */\nexport function resolveComponentPropTypes(\n expression: ts.Symbol | undefined,\n checker: ts.TypeChecker\n): Map<string, { type: ts.Type; locationNode?: ts.Node }> {\n const result = new Map<string, { type: ts.Type; locationNode?: ts.Node }>();\n if (!expression) return result;\n\n let target = expression;\n if (target.flags & ts.SymbolFlags.Alias) {\n target = checker.getAliasedSymbol(target);\n }\n\n const decl = target.valueDeclaration ?? target.declarations?.[0];\n if (!decl) return result;\n\n const compType = checker.getTypeOfSymbolAtLocation(target, decl);\n\n // Stateless function component: first parameter of call signature\n let propsSymbol: ts.Symbol | undefined;\n for (const sig of compType.getCallSignatures()) {\n const params = sig.getParameters();\n if (params.length === 0) continue;\n const first = params[0]!;\n if (first.name === \"props\" || params.length === 1) {\n propsSymbol = first;\n break;\n }\n }\n\n // Stateful class component: `props` property on constructed instance\n if (!propsSymbol) {\n for (const sig of compType.getConstructSignatures()) {\n const prop = sig.getReturnType().getProperty(\"props\");\n if (prop) {\n propsSymbol = prop;\n break;\n }\n }\n }\n\n if (!propsSymbol) return result;\n\n const propsDecl =\n propsSymbol.valueDeclaration ?? propsSymbol.declarations?.[0] ?? decl;\n const propsType = checker.getTypeOfSymbolAtLocation(propsSymbol, propsDecl);\n\n const propSymbols: ts.Symbol[] = [...propsType.getApparentProperties()];\n if (propsType.isUnionOrIntersection()) {\n for (const memberType of propsType.types) {\n propSymbols.push(...memberType.getApparentProperties());\n }\n }\n\n for (const prop of propSymbols) {\n const name = prop.getName();\n if (result.has(name)) continue;\n const propType = checker.getTypeOfSymbolAtLocation(prop, propsDecl);\n result.set(name, { type: propType, locationNode: propsDecl });\n }\n\n return result;\n}\n"],"mappings":";;AAgBA,MAAM,kCAAkB,IAAI,IAAI;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,sCAAsB,IAAI,IAAI;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,sBAAsB;AAE5B,MAAM,kBAAkB;AACxB,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;AAEzB,SAAgB,eAAe,GAAW,GAAmB;CAC3D,OAAO,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI;AAClC;;;;;AAMA,SAAgB,mBAAmB,KAAuB;CACxD,IAAI,CAAC,IAAI,SAAS,GAAG,GACnB,OAAO,CAAC,IAAI,KAAK,CAAC;CAGpB,MAAM,QAAkB,CAAC;CACzB,IAAI,UAAU;CACd,IAAI,aAAa;CACjB,IAAI,aAAa;CACjB,IAAI,aAAa;CACjB,IAAI,eAAe;CACnB,IAAI,UAAyB;CAE7B,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;EACnC,MAAM,KAAK,IAAI;EACf,IAAI,SAAS;GACX,WAAW;GACX,IAAI,OAAO,WAAW,IAAI,IAAI,OAAO,MACnC,UAAU;GAEZ;EACF;EAEA,IAAI,OAAO,QAAO,OAAO,OAAO,OAAO,KAAK;GAC1C,UAAU;GACV,WAAW;GACX;EACF;EAEA,IAAI,OAAO,KAAK;OACX,IAAI,OAAO,KAAK,aAAa,KAAK,IAAI,GAAG,aAAa,CAAC;OACvD,IAAI,OAAO,KAAK;OAChB,IAAI,OAAO,OAAO,IAAI,IAAI,OA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AAA,yBAAA,wBAAoB,YAAY,kBAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAe,QAAA,QAAA,UAAA,KAAA,IAAA,QAAM;CACnE,MAAM,YAAY,QAAQ,0BAA0B,aAAa,SAAS;CAE1E,MAAM,cAA2B,CAAC,GAAG,UAAU,sBAAsB,CAAC;CACtE,IAAI,UAAU,sBAAsB,GAClC,KAAK,MAAM,cAAc,UAAU,OACjC,YAAY,KAAK,GAAG,WAAW,sBAAsB,CAAC;CAI1D,KAAK,MAAM,QAAQ,aAAa;EAC9B,MAAM,OAAO,KAAK,QAAQ;EAC1B,IAAI,OAAO,IAAI,IAAI,GAAG;EACtB,MAAM,WAAW,QAAQ,0BAA0B,MAAM,SAAS;EAClE,OAAO,IAAI,MAAM;GAAE,MAAM;GAAU,cAAc;EAAU,CAAC;CAC9D;CAEA,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@renr/parcel-reporter-docgen",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.13",
|
|
4
4
|
"author": "Ren Rizzolo",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Parcel reporter that generates ui docs via react-docgen-typescript",
|
|
@@ -68,13 +68,13 @@
|
|
|
68
68
|
"access": "public"
|
|
69
69
|
},
|
|
70
70
|
"optionalDependencies": {
|
|
71
|
-
"@renr/parcel-reporter-docgen-darwin-arm64": "0.1.0-beta.
|
|
72
|
-
"@renr/parcel-reporter-docgen-darwin-x64": "0.1.0-beta.
|
|
73
|
-
"@renr/parcel-reporter-docgen-win32-x64-msvc": "0.1.0-beta.
|
|
74
|
-
"@renr/parcel-reporter-docgen-win32-arm64-msvc": "0.1.0-beta.
|
|
75
|
-
"@renr/parcel-reporter-docgen-linux-x64-gnu": "0.1.0-beta.
|
|
76
|
-
"@renr/parcel-reporter-docgen-linux-arm64-gnu": "0.1.0-beta.
|
|
77
|
-
"@renr/parcel-reporter-docgen-linux-x64-musl": "0.1.0-beta.
|
|
78
|
-
"@renr/parcel-reporter-docgen-linux-arm64-musl": "0.1.0-beta.
|
|
71
|
+
"@renr/parcel-reporter-docgen-darwin-arm64": "0.1.0-beta.13",
|
|
72
|
+
"@renr/parcel-reporter-docgen-darwin-x64": "0.1.0-beta.13",
|
|
73
|
+
"@renr/parcel-reporter-docgen-win32-x64-msvc": "0.1.0-beta.13",
|
|
74
|
+
"@renr/parcel-reporter-docgen-win32-arm64-msvc": "0.1.0-beta.13",
|
|
75
|
+
"@renr/parcel-reporter-docgen-linux-x64-gnu": "0.1.0-beta.13",
|
|
76
|
+
"@renr/parcel-reporter-docgen-linux-arm64-gnu": "0.1.0-beta.13",
|
|
77
|
+
"@renr/parcel-reporter-docgen-linux-x64-musl": "0.1.0-beta.13",
|
|
78
|
+
"@renr/parcel-reporter-docgen-linux-arm64-musl": "0.1.0-beta.13"
|
|
79
79
|
}
|
|
80
80
|
}
|