@kubb/ast 5.23.3 → 5.23.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/factory.cjs +2 -2
- package/dist/factory.d.cts +4 -4
- package/dist/factory.d.ts +4 -4
- package/dist/factory.js +2 -2
- package/dist/{file-KunZhFIV.d.cts → file-B269mZh4.d.cts} +67 -33
- package/dist/file-Bq2GPaxh.js +427 -0
- package/dist/file-Bq2GPaxh.js.map +1 -0
- package/dist/file-C4pqV8yl.cjs +469 -0
- package/dist/file-C4pqV8yl.cjs.map +1 -0
- package/dist/{file-Dj9lsbJu.js → file-D_ih0x7q.js} +15 -11
- package/dist/file-D_ih0x7q.js.map +1 -0
- package/dist/{file-BAICym_L.cjs → file-DiPZBLSP.cjs} +15 -11
- package/dist/file-DiPZBLSP.cjs.map +1 -0
- package/dist/{file-DkFGn_Os.d.ts → file-oLlejzZV.d.ts} +67 -33
- package/dist/file.cjs +5 -2
- package/dist/file.d.cts +2 -2
- package/dist/file.d.ts +2 -2
- package/dist/file.js +3 -1
- package/dist/graph.d.cts +1 -1
- package/dist/graph.d.ts +1 -1
- package/dist/{guards-C6w6KQSY.d.ts → guards-RCnH6re9.d.ts} +1 -1
- package/dist/{guards-COBkDtgu.d.cts → guards-u-dAAtl8.d.cts} +1 -1
- package/dist/http.d.cts +2 -2
- package/dist/http.d.ts +2 -2
- package/dist/{index-CX7yfAGI.d.ts → index-2TMYDLjK.d.ts} +1 -1
- package/dist/index-6-ZZCX9W.d.ts +24 -0
- package/dist/index-B2nnOQjf.d.cts +24 -0
- package/dist/{index-DkThxxxq.d.cts → index-BgFaJtnv.d.ts} +9 -3
- package/dist/index-Bj7a0aSM.d.cts +5 -0
- package/dist/{index-dgiKWRpD.d.cts → index-Bw2oMIM1.d.cts} +3 -3
- package/dist/{index-gDZYBeJw.d.cts → index-C1za72gL.d.cts} +1 -1
- package/dist/index-CW-ztJjd.d.ts +5 -0
- package/dist/{index-DjThtAn4.d.ts → index-DF7CbpYW.d.ts} +2 -2
- package/dist/{index-CPXo4cA8.d.cts → index-D_WLsIMP.d.cts} +2 -2
- package/dist/{index-B5w-X5V6.d.ts → index-DbAnYRRM.d.ts} +1 -1
- package/dist/{index-jWtEIa7j.d.ts → index-DbQ-J072.d.cts} +9 -3
- package/dist/{index-CnY3KmAg.d.ts → index-DfRcRYF2.d.ts} +1 -1
- package/dist/{index-DZe5evGM.d.cts → index-DpnCCtXt.d.cts} +1 -1
- package/dist/{index-CwFC71XK.d.ts → index-DzHcy3vy.d.ts} +2 -2
- package/dist/{index-9l1xMEl_.d.ts → index-UwSVys3m.d.ts} +3 -3
- package/dist/{index-Dr81DOsC.d.cts → index-c9FD2S5f.d.cts} +2 -2
- package/dist/{index-D-BjRrJo.d.cts → index-sdprVPKQ.d.cts} +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +15 -15
- package/dist/index.d.ts +15 -15
- package/dist/index.js +2 -2
- package/dist/json.d.cts +1 -1
- package/dist/json.d.ts +1 -1
- package/dist/macro.d.cts +1 -1
- package/dist/macro.d.ts +1 -1
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/{nodes-CwYIFVt5.js → nodes-ClL1C158.js} +2 -2
- package/dist/nodes-ClL1C158.js.map +1 -0
- package/dist/{nodes-BT2Ocq0x.cjs → nodes-DEQjVliP.cjs} +2 -2
- package/dist/nodes-DEQjVliP.cjs.map +1 -0
- package/dist/{operation-BUhPuZMY.d.cts → operation-AFw8tzIN.d.cts} +21 -5
- package/dist/{operation-jxEr2No4.d.ts → operation-Cu4XSaJQ.d.ts} +21 -5
- package/dist/ref.d.cts +1 -1
- package/dist/ref.d.ts +1 -1
- package/dist/schema-gSjYgaCl.cjs.map +1 -1
- package/dist/schema-tH14gE6i.js.map +1 -1
- package/dist/schema.d.cts +3 -3
- package/dist/schema.d.ts +3 -3
- package/dist/{visitor-CFbuH7BY.d.ts → visitor-CpmsR8o5.d.ts} +2 -2
- package/dist/{visitor-DxhkIQyP.d.cts → visitor-DnBK2MNl.d.cts} +2 -2
- package/package.json +1 -1
- package/dist/file-BAICym_L.cjs.map +0 -1
- package/dist/file-DUFttt26.js +0 -293
- package/dist/file-DUFttt26.js.map +0 -1
- package/dist/file-Dj9lsbJu.js.map +0 -1
- package/dist/file-Dz1HPMld.cjs +0 -329
- package/dist/file-Dz1HPMld.cjs.map +0 -1
- package/dist/index-Be5d4Zcl.d.ts +0 -24
- package/dist/index-CI6Tu2c7.d.ts +0 -5
- package/dist/index-DuDvNFQ8.d.cts +0 -5
- package/dist/index-ss1YqjpW.d.cts +0 -24
- package/dist/nodes-BT2Ocq0x.cjs.map +0 -1
- package/dist/nodes-CwYIFVt5.js.map +0 -1
package/dist/factory.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_schema = require("./schema-gSjYgaCl.cjs");
|
|
3
|
-
const require_file = require("./file-
|
|
4
|
-
const require_nodes = require("./nodes-
|
|
3
|
+
const require_file = require("./file-C4pqV8yl.cjs");
|
|
4
|
+
const require_nodes = require("./nodes-DEQjVliP.cjs");
|
|
5
5
|
exports.createArrowFunction = require_nodes.createArrowFunction;
|
|
6
6
|
exports.createBreak = require_nodes.createBreak;
|
|
7
7
|
exports.createConst = require_nodes.createConst;
|
package/dist/factory.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as createJsx,
|
|
2
|
-
import {
|
|
3
|
-
import { t as Node } from "./index-
|
|
4
|
-
export { Node, type UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createImport, createInput, createJsx, createOperation, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType };
|
|
1
|
+
import { C as createArrowFunction, D as createJsx, E as createFunction, O as createText, T as createConst, c as Space, d as createFile, f as createImport, i as ImportInput, k as createType, l as UserFileNode, o as ModuleName, p as createSource, t as ExportInput, u as createExport, w as createBreak } from "./file-B269mZh4.cjs";
|
|
2
|
+
import { Q as createProperty, X as createSchema, a as createOperation, d as createRequestBody, h as createParameter, k as createInput, l as createResponse, y as createContent } from "./operation-AFw8tzIN.cjs";
|
|
3
|
+
import { t as Node } from "./index-B2nnOQjf.cjs";
|
|
4
|
+
export { type ExportInput, type ImportInput, type ModuleName, Node, type Space, type UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createImport, createInput, createJsx, createOperation, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType };
|
package/dist/factory.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as createJsx,
|
|
2
|
-
import {
|
|
3
|
-
import { t as Node } from "./index-
|
|
4
|
-
export { Node, type UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createImport, createInput, createJsx, createOperation, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType };
|
|
1
|
+
import { C as createArrowFunction, D as createJsx, E as createFunction, O as createText, T as createConst, c as Space, d as createFile, f as createImport, i as ImportInput, k as createType, l as UserFileNode, o as ModuleName, p as createSource, t as ExportInput, u as createExport, w as createBreak } from "./file-oLlejzZV.js";
|
|
2
|
+
import { Q as createProperty, X as createSchema, a as createOperation, d as createRequestBody, h as createParameter, k as createInput, l as createResponse, y as createContent } from "./operation-Cu4XSaJQ.js";
|
|
3
|
+
import { t as Node } from "./index-6-ZZCX9W.js";
|
|
4
|
+
export { type ExportInput, type ImportInput, type ModuleName, Node, type Space, type UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createImport, createInput, createJsx, createOperation, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType };
|
package/dist/factory.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { t as createSchema } from "./schema-tH14gE6i.js";
|
|
2
|
-
import { i as createSource, n as createFile, r as createImport, t as createExport } from "./file-
|
|
3
|
-
import { a as createOperation, c as createContent, d as createConst, f as createFunction, h as createType, i as createParameter, l as createArrowFunction, m as createText, n as createResponse, o as createRequestBody, p as createJsx, r as createProperty, s as createInput, u as createBreak } from "./nodes-
|
|
2
|
+
import { i as createSource, n as createFile, r as createImport, t as createExport } from "./file-Bq2GPaxh.js";
|
|
3
|
+
import { a as createOperation, c as createContent, d as createConst, f as createFunction, h as createType, i as createParameter, l as createArrowFunction, m as createText, n as createResponse, o as createRequestBody, p as createJsx, r as createProperty, s as createInput, u as createBreak } from "./nodes-ClL1C158.js";
|
|
4
4
|
export { createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createImport, createInput, createJsx, createOperation, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType };
|
|
@@ -315,39 +315,61 @@ type ImportName = string | Array<string | {
|
|
|
315
315
|
propertyName: string;
|
|
316
316
|
name?: string;
|
|
317
317
|
}>;
|
|
318
|
+
/**
|
|
319
|
+
* Whether a declaration exists only at compile time (`'type'`) or also at runtime (`'value'`).
|
|
320
|
+
*/
|
|
321
|
+
type Space = 'type' | 'value';
|
|
322
|
+
/**
|
|
323
|
+
* One name an import or export brings across, as in the ECMAScript `ImportEntry` record.
|
|
324
|
+
*/
|
|
325
|
+
type ModuleName = {
|
|
326
|
+
/**
|
|
327
|
+
* Name in the other module: `'default'` for its default export, `'*'` for the whole module.
|
|
328
|
+
*/
|
|
329
|
+
name: string;
|
|
330
|
+
/**
|
|
331
|
+
* Local name for an import, or the exported name for an export.
|
|
332
|
+
*/
|
|
333
|
+
alias?: string | null;
|
|
334
|
+
/**
|
|
335
|
+
* Type or value.
|
|
336
|
+
* @default 'value'
|
|
337
|
+
*/
|
|
338
|
+
space?: Space | null;
|
|
339
|
+
};
|
|
318
340
|
/**
|
|
319
341
|
* Represents a language-agnostic import/dependency declaration.
|
|
320
342
|
*
|
|
321
343
|
* @example Named import (TypeScript: `import { useState } from 'react'`)
|
|
322
344
|
* ```ts
|
|
323
|
-
* createImport({ name:
|
|
345
|
+
* createImport({ names: [{ name: 'useState' }], path: 'react' })
|
|
324
346
|
* ```
|
|
325
347
|
*
|
|
326
348
|
* @example Default import (TypeScript: `import React from 'react'`)
|
|
327
349
|
* ```ts
|
|
328
|
-
* createImport({ name: 'React', path: 'react' })
|
|
350
|
+
* createImport({ names: [{ name: 'default', alias: 'React' }], path: 'react' })
|
|
329
351
|
* ```
|
|
330
352
|
*
|
|
331
353
|
* @example Type-only import (TypeScript: `import type { FC } from 'react'`)
|
|
332
354
|
* ```ts
|
|
333
|
-
* createImport({ name:
|
|
355
|
+
* createImport({ names: [{ name: 'FC', space: 'type' }], path: 'react' })
|
|
334
356
|
* ```
|
|
335
357
|
*
|
|
336
358
|
* @example Namespace import (TypeScript: `import * as React from 'react'`)
|
|
337
359
|
* ```ts
|
|
338
|
-
* createImport({ name: '
|
|
360
|
+
* createImport({ names: [{ name: '*', alias: 'React' }], path: 'react' })
|
|
339
361
|
* ```
|
|
340
362
|
*/
|
|
341
363
|
type ImportNode = BaseNode & {
|
|
342
364
|
kind: 'Import';
|
|
365
|
+
/**
|
|
366
|
+
* The names the import brings in. `ast.file.getNames` also reads the deprecated fields.
|
|
367
|
+
*/
|
|
368
|
+
names?: Array<ModuleName> | null;
|
|
343
369
|
/**
|
|
344
370
|
* Import name(s) to be used.
|
|
345
371
|
*
|
|
346
|
-
* @
|
|
347
|
-
* `['useState']`
|
|
348
|
-
*
|
|
349
|
-
* @example Default import
|
|
350
|
-
* `'React'`
|
|
372
|
+
* @deprecated Use `names`. Removed in Kubb v6.
|
|
351
373
|
*/
|
|
352
374
|
name: ImportName;
|
|
353
375
|
/**
|
|
@@ -359,14 +381,14 @@ type ImportNode = BaseNode & {
|
|
|
359
381
|
path: string;
|
|
360
382
|
/**
|
|
361
383
|
* Add a type-only import prefix.
|
|
362
|
-
*
|
|
363
|
-
*
|
|
384
|
+
*
|
|
385
|
+
* @deprecated Set `space: 'type'` on each name. Removed in Kubb v6.
|
|
364
386
|
*/
|
|
365
387
|
isTypeOnly?: boolean | null;
|
|
366
388
|
/**
|
|
367
389
|
* Import the entire module as a namespace.
|
|
368
|
-
*
|
|
369
|
-
*
|
|
390
|
+
*
|
|
391
|
+
* @deprecated Use `{ name: '*', alias }` in `names`. Removed in Kubb v6.
|
|
370
392
|
*/
|
|
371
393
|
isNameSpace?: boolean | null;
|
|
372
394
|
/**
|
|
@@ -379,34 +401,34 @@ type ImportNode = BaseNode & {
|
|
|
379
401
|
*
|
|
380
402
|
* @example Named export (TypeScript: `export { Pets } from './Pets'`)
|
|
381
403
|
* ```ts
|
|
382
|
-
* createExport({ name:
|
|
404
|
+
* createExport({ names: [{ name: 'Pets' }], path: './Pets' })
|
|
383
405
|
* ```
|
|
384
406
|
*
|
|
385
407
|
* @example Type-only export (TypeScript: `export type { Pet } from './Pet'`)
|
|
386
408
|
* ```ts
|
|
387
|
-
* createExport({ name:
|
|
409
|
+
* createExport({ names: [{ name: 'Pet', space: 'type' }], path: './Pet' })
|
|
388
410
|
* ```
|
|
389
411
|
*
|
|
390
412
|
* @example Wildcard export (TypeScript: `export * from './utils'`)
|
|
391
413
|
* ```ts
|
|
392
|
-
* createExport({ path: './utils' })
|
|
414
|
+
* createExport({ names: [{ name: '*' }], path: './utils' })
|
|
393
415
|
* ```
|
|
394
416
|
*
|
|
395
417
|
* @example Namespace alias (TypeScript: `export * as utils from './utils'`)
|
|
396
418
|
* ```ts
|
|
397
|
-
* createExport({ name: '
|
|
419
|
+
* createExport({ names: [{ name: '*', alias: 'utils' }], path: './utils' })
|
|
398
420
|
* ```
|
|
399
421
|
*/
|
|
400
422
|
type ExportNode = BaseNode & {
|
|
401
423
|
kind: 'Export';
|
|
424
|
+
/**
|
|
425
|
+
* The names the export passes on. `ast.file.getNames` also reads the deprecated fields.
|
|
426
|
+
*/
|
|
427
|
+
names?: Array<ModuleName> | null;
|
|
402
428
|
/**
|
|
403
429
|
* Export name(s) to be used. When omitted, generates a wildcard export.
|
|
404
430
|
*
|
|
405
|
-
* @
|
|
406
|
-
* `['useState']`
|
|
407
|
-
*
|
|
408
|
-
* @example Single export
|
|
409
|
-
* `'React'`
|
|
431
|
+
* @deprecated Use `names`. Removed in Kubb v6.
|
|
410
432
|
*/
|
|
411
433
|
name?: string | Array<string> | null;
|
|
412
434
|
/**
|
|
@@ -418,14 +440,14 @@ type ExportNode = BaseNode & {
|
|
|
418
440
|
path: string;
|
|
419
441
|
/**
|
|
420
442
|
* Add a type-only export prefix.
|
|
421
|
-
*
|
|
422
|
-
*
|
|
443
|
+
*
|
|
444
|
+
* @deprecated Set `space: 'type'` on each name. Removed in Kubb v6.
|
|
423
445
|
*/
|
|
424
446
|
isTypeOnly?: boolean | null;
|
|
425
447
|
/**
|
|
426
448
|
* Export as an aliased namespace.
|
|
427
|
-
*
|
|
428
|
-
*
|
|
449
|
+
*
|
|
450
|
+
* @deprecated Use `{ name: '*', alias }` in `names`. Removed in Kubb v6.
|
|
429
451
|
*/
|
|
430
452
|
asAlias?: boolean | null;
|
|
431
453
|
};
|
|
@@ -448,8 +470,14 @@ type SourceNode = BaseNode & {
|
|
|
448
470
|
* Optional name identifying this source (used for deduplication and barrel generation).
|
|
449
471
|
*/
|
|
450
472
|
name?: string | null;
|
|
473
|
+
/**
|
|
474
|
+
* Type or value. When unset, a source whose first node is a `Type` is a type.
|
|
475
|
+
*/
|
|
476
|
+
space?: Space | null;
|
|
451
477
|
/**
|
|
452
478
|
* Mark this source as a type-only export.
|
|
479
|
+
*
|
|
480
|
+
* @deprecated Use `space: 'type'`. Removed in Kubb v6.
|
|
453
481
|
*/
|
|
454
482
|
isTypeOnly?: boolean | null;
|
|
455
483
|
/**
|
|
@@ -570,26 +598,32 @@ type FileNode<TMeta extends object = object> = BaseNode & {
|
|
|
570
598
|
*/
|
|
571
599
|
inline?: boolean | null;
|
|
572
600
|
};
|
|
601
|
+
type ImportInput = Omit<ImportNode, 'kind' | 'name'> & {
|
|
602
|
+
name?: ImportName;
|
|
603
|
+
};
|
|
604
|
+
type ExportInput = Omit<ExportNode, 'kind'>;
|
|
573
605
|
/**
|
|
574
|
-
* Creates an `ImportNode`
|
|
606
|
+
* Creates an `ImportNode`. A node built from `names` also gets the deprecated fields. A deprecated `name` or
|
|
607
|
+
* `isTypeOnly` that differs from the one `names` gives overrides it, so `{ ...imp, isTypeOnly: true }` still works.
|
|
575
608
|
*
|
|
576
609
|
* @example Named import
|
|
577
610
|
* ```ts
|
|
578
|
-
* createImport({ name:
|
|
611
|
+
* createImport({ names: [{ name: 'useState' }], path: 'react' })
|
|
579
612
|
* // import { useState } from 'react'
|
|
580
613
|
* ```
|
|
581
614
|
*/
|
|
582
|
-
declare
|
|
615
|
+
declare function createImport(input: ImportInput): ImportNode;
|
|
583
616
|
/**
|
|
584
|
-
* Creates an `ExportNode`
|
|
617
|
+
* Creates an `ExportNode`. A node built from `names` also gets the deprecated fields. A deprecated `name` or
|
|
618
|
+
* `isTypeOnly` that differs from the one `names` gives overrides it.
|
|
585
619
|
*
|
|
586
620
|
* @example Named export
|
|
587
621
|
* ```ts
|
|
588
|
-
* createExport({ name:
|
|
622
|
+
* createExport({ names: [{ name: 'Pet' }], path: './Pet' })
|
|
589
623
|
* // export { Pet } from './Pet'
|
|
590
624
|
* ```
|
|
591
625
|
*/
|
|
592
|
-
declare
|
|
626
|
+
declare function createExport(input: ExportInput): ExportNode;
|
|
593
627
|
/**
|
|
594
628
|
* Creates a `SourceNode` representing a fragment of source code within a file.
|
|
595
629
|
*
|
|
@@ -643,4 +677,4 @@ type UserFileNode<TMeta extends object = object> = Omit<FileNode<TMeta>, 'kind'
|
|
|
643
677
|
* ```
|
|
644
678
|
*/
|
|
645
679
|
declare function createFile<TMeta extends object = object>(input: UserFileNode<TMeta>): FileNode<TMeta>;
|
|
646
|
-
export {
|
|
680
|
+
export { createArrowFunction as C, createJsx as D, createFunction as E, createText as O, TypeNode as S, createConst as T, ConstNode as _, ImportNode as a, JsxNode as b, Space as c, createFile as d, createImport as f, CodeNode as g, BreakNode as h, ImportInput as i, createType as k, UserFileNode as l, ArrowFunctionNode as m, ExportNode as n, ModuleName as o, createSource as p, FileNode as r, SourceNode as s, ExportInput as t, createExport as u, FunctionNode as v, createBreak as w, TextNode as x, JSDocNode as y };
|
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import "./rolldown-runtime-BYyVTPww.js";
|
|
2
|
+
import { hash } from "node:crypto";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { t as nodeKinds } from "./constants-BTTus9ee.js";
|
|
5
|
+
import { t as memo } from "./promise-B3YkZ4C8.js";
|
|
6
|
+
import { n as getNodeText } from "./nodeText-BSYvDZOH.js";
|
|
7
|
+
// src/utils/moduleNames.ts
|
|
8
|
+
/**
|
|
9
|
+
* Returns the names an import or export brings across. A node built with the deprecated fields gets them from
|
|
10
|
+
* those, each with an explicit `space`, so it prints exactly as before.
|
|
11
|
+
*/
|
|
12
|
+
function getNames(node) {
|
|
13
|
+
if (node.names) return node.names;
|
|
14
|
+
return node.kind === "Import" ? fromDeprecatedImport(node) : fromDeprecatedExport(node);
|
|
15
|
+
}
|
|
16
|
+
function getSpace(source) {
|
|
17
|
+
if (source.space) return source.space;
|
|
18
|
+
if (source.isTypeOnly != null) return source.isTypeOnly ? "type" : "value";
|
|
19
|
+
return source.nodes?.[0]?.kind === "Type" ? "type" : "value";
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Converts a node built with `name`, `isTypeOnly` and `isNameSpace` to `names`. Removed in Kubb v6.
|
|
23
|
+
*/
|
|
24
|
+
function fromDeprecatedImport({ name, isTypeOnly, isNameSpace }) {
|
|
25
|
+
const space = isTypeOnly ? "type" : "value";
|
|
26
|
+
if (!Array.isArray(name)) return [{
|
|
27
|
+
name: isNameSpace ? "*" : "default",
|
|
28
|
+
alias: name,
|
|
29
|
+
space
|
|
30
|
+
}];
|
|
31
|
+
return name.map((item) => typeof item === "string" ? {
|
|
32
|
+
name: item,
|
|
33
|
+
space
|
|
34
|
+
} : {
|
|
35
|
+
name: item.propertyName,
|
|
36
|
+
...item.name ? { alias: item.name } : {},
|
|
37
|
+
space
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated Converts a node built with `name`, `isTypeOnly` and `asAlias` to `names`. Removed in Kubb v6.
|
|
42
|
+
*/
|
|
43
|
+
function fromDeprecatedExport({ name, isTypeOnly, asAlias }) {
|
|
44
|
+
const space = isTypeOnly ? "type" : "value";
|
|
45
|
+
if (name == null) return [{
|
|
46
|
+
name: "*",
|
|
47
|
+
space
|
|
48
|
+
}];
|
|
49
|
+
if (!Array.isArray(name)) return [asAlias ? {
|
|
50
|
+
name: "*",
|
|
51
|
+
alias: name,
|
|
52
|
+
space
|
|
53
|
+
} : {
|
|
54
|
+
name,
|
|
55
|
+
space
|
|
56
|
+
}];
|
|
57
|
+
return name.map((item) => ({
|
|
58
|
+
name: item,
|
|
59
|
+
space
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* @deprecated The old import fields for `names`, for code that still reads them. Removed in Kubb v6.
|
|
64
|
+
*/
|
|
65
|
+
function toDeprecatedImport(names) {
|
|
66
|
+
const isTypeOnly = names.length > 0 && names.every((item) => item.space === "type");
|
|
67
|
+
const [first] = names;
|
|
68
|
+
if (names.length === 1 && first?.alias && (first.name === "*" || first.name === "default")) return {
|
|
69
|
+
name: first.alias,
|
|
70
|
+
isTypeOnly,
|
|
71
|
+
isNameSpace: first.name === "*"
|
|
72
|
+
};
|
|
73
|
+
return {
|
|
74
|
+
name: names.map((item) => item.alias ? {
|
|
75
|
+
propertyName: item.name,
|
|
76
|
+
name: item.alias
|
|
77
|
+
} : item.name),
|
|
78
|
+
isTypeOnly,
|
|
79
|
+
isNameSpace: false
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @deprecated The old export fields for `names`; an alias stands in for its name. Removed in Kubb v6.
|
|
84
|
+
*/
|
|
85
|
+
function toDeprecatedExport(names) {
|
|
86
|
+
const isTypeOnly = names.length > 0 && names.every((item) => item.space === "type");
|
|
87
|
+
const [first] = names;
|
|
88
|
+
if (names.length === 1 && first?.name === "*") return first.alias ? {
|
|
89
|
+
name: first.alias,
|
|
90
|
+
isTypeOnly,
|
|
91
|
+
asAlias: true
|
|
92
|
+
} : {
|
|
93
|
+
isTypeOnly,
|
|
94
|
+
asAlias: false
|
|
95
|
+
};
|
|
96
|
+
return {
|
|
97
|
+
name: names.map((item) => item.alias ?? item.name),
|
|
98
|
+
isTypeOnly,
|
|
99
|
+
asAlias: false
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
// src/utils/combineFileMembers.ts
|
|
103
|
+
/**
|
|
104
|
+
* File-member merging. `combineImports` and `combineExports` deduplicate and sort the import and
|
|
105
|
+
* export entries of one file, while `combineSources` deduplicates source entries in original order.
|
|
106
|
+
* `combineImports` also drops imports nothing references. This works on a file's members, not on
|
|
107
|
+
* schema content.
|
|
108
|
+
*/
|
|
109
|
+
const IDENTIFIER_RUN = /[\w$]+/g;
|
|
110
|
+
/**
|
|
111
|
+
* How many imports a file needs before indexing the source beats scanning it once per name.
|
|
112
|
+
*/
|
|
113
|
+
const INDEX_ABOVE_IMPORTS = 128;
|
|
114
|
+
const importForm = (item) => item.alias && (item.name === "*" || item.name === "default") ? item.name : "named";
|
|
115
|
+
const exportForm = (item) => item.name === "*" ? "*" : "named";
|
|
116
|
+
const label = (item) => item.alias ? `${item.name} as ${item.alias}` : item.name;
|
|
117
|
+
function statementKey({ path, form, space, names }) {
|
|
118
|
+
return form === "named" ? `${path}\0named\0${space}` : `${path}\0${form}\0${names[0]?.alias ?? ""}\0${space}`;
|
|
119
|
+
}
|
|
120
|
+
function toStatements(nodes, formOf) {
|
|
121
|
+
return nodes.flatMap((node) => {
|
|
122
|
+
const statements = /* @__PURE__ */ new Map();
|
|
123
|
+
for (const item of getNames(node)) {
|
|
124
|
+
const statement = {
|
|
125
|
+
path: node.path,
|
|
126
|
+
root: node.kind === "Import" ? node.root : void 0,
|
|
127
|
+
form: formOf(item),
|
|
128
|
+
space: item.space ?? "value",
|
|
129
|
+
names: []
|
|
130
|
+
};
|
|
131
|
+
const key = statementKey({
|
|
132
|
+
...statement,
|
|
133
|
+
names: [item]
|
|
134
|
+
});
|
|
135
|
+
const existing = statements.get(key) ?? statement;
|
|
136
|
+
statements.set(key, existing);
|
|
137
|
+
existing.names.push(item);
|
|
138
|
+
}
|
|
139
|
+
return [...statements.values()];
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Relative specifiers by `root`, then `path`. `createFile` sorts a file's imports again on every
|
|
144
|
+
* merge, and the path math dominated that sort on large specs. Two levels keep the existing strings
|
|
145
|
+
* as keys, so lookups reuse their hashes instead of hashing a new joined key each time.
|
|
146
|
+
*/
|
|
147
|
+
const specifierCache = memo.create({ max: 1e4 });
|
|
148
|
+
/**
|
|
149
|
+
* Returns the specifier a member is written with: POSIX and relative to the importing file when it
|
|
150
|
+
* has a `root`, like `getRelativePath` in parser-ts. Sorting on it keeps the order the same on every OS.
|
|
151
|
+
*/
|
|
152
|
+
function specifier(node) {
|
|
153
|
+
const { root, path: target } = node;
|
|
154
|
+
if (!root) return target;
|
|
155
|
+
const byPath = memo(specifierCache, root, () => /* @__PURE__ */ new Map());
|
|
156
|
+
return memo(byPath, target, () => {
|
|
157
|
+
const relative = path.relative(path.dirname(root), target).replaceAll("\\", "/");
|
|
158
|
+
return relative.startsWith("../") ? relative : `./${relative}`;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function sortKey(statement) {
|
|
162
|
+
return `${statement.form === "named" ? "1" : "0"}:${statement.space === "type" ? "0" : "1"}:${specifier(statement)}:${statement.names.map(label).toSorted().join("\0")}`;
|
|
163
|
+
}
|
|
164
|
+
function mergeStatements(statements, keep = () => true) {
|
|
165
|
+
const merged = /* @__PURE__ */ new Map();
|
|
166
|
+
const sorted = statements.map((statement) => ({
|
|
167
|
+
statement,
|
|
168
|
+
key: sortKey(statement)
|
|
169
|
+
})).sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0);
|
|
170
|
+
for (const { statement } of sorted) {
|
|
171
|
+
const key = statementKey(statement);
|
|
172
|
+
const entry = merged.get(key) ?? {
|
|
173
|
+
statement: {
|
|
174
|
+
...statement,
|
|
175
|
+
names: []
|
|
176
|
+
},
|
|
177
|
+
seen: /* @__PURE__ */ new Set()
|
|
178
|
+
};
|
|
179
|
+
merged.set(key, entry);
|
|
180
|
+
for (const item of statement.names) {
|
|
181
|
+
const id = item.alias ?? item.name;
|
|
182
|
+
if (entry.seen.has(id) || !keep(item, statement)) continue;
|
|
183
|
+
entry.seen.add(id);
|
|
184
|
+
entry.statement.names.push(item);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const result = [...merged.values()].map(({ statement }) => statement);
|
|
188
|
+
const bound = ({ path, item }) => `${path}\0${item.alias ?? item.name}`;
|
|
189
|
+
const values = new Set(result.filter(({ space }) => space === "value").flatMap(({ path, names }) => names.map((item) => bound({
|
|
190
|
+
path,
|
|
191
|
+
item
|
|
192
|
+
}))));
|
|
193
|
+
return result.map((statement) => statement.space === "type" ? {
|
|
194
|
+
...statement,
|
|
195
|
+
names: statement.names.filter((item) => !values.has(bound({
|
|
196
|
+
path: statement.path,
|
|
197
|
+
item
|
|
198
|
+
})))
|
|
199
|
+
} : statement).filter((statement) => statement.names.length > 0);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Deduplicates `SourceNode` objects by `name + export + space`, keeping the first of each
|
|
203
|
+
* key. An unnamed source only drops when the same node appears twice, so markdown can repeat a
|
|
204
|
+
* paragraph or a table. Returns the deduplicated array in original order.
|
|
205
|
+
*/
|
|
206
|
+
function combineSources(sources) {
|
|
207
|
+
const seen = /* @__PURE__ */ new Set();
|
|
208
|
+
return sources.filter((source) => {
|
|
209
|
+
const key = source.name != null ? `${source.name}:${source.export ?? source.isExportable ?? false}:${getSpace(source)}` : source;
|
|
210
|
+
if (seen.has(key)) return false;
|
|
211
|
+
seen.add(key);
|
|
212
|
+
return true;
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Deduplicates and merges `ExportNode` objects: one export per path, form and space. Returns a sorted array.
|
|
217
|
+
*/
|
|
218
|
+
function combineExports(exports) {
|
|
219
|
+
return mergeStatements(toStatements(exports, exportForm)).map(({ path, names }) => ({
|
|
220
|
+
kind: "Export",
|
|
221
|
+
path,
|
|
222
|
+
...toDeprecatedExport(names),
|
|
223
|
+
names
|
|
224
|
+
}));
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Deduplicates and merges `ImportNode` objects, filtering out unused imports.
|
|
228
|
+
*
|
|
229
|
+
* Retains imports that are referenced in `source` or re-exported. One import per path, form and space. Returns
|
|
230
|
+
* a sorted, deduplicated, filtered array.
|
|
231
|
+
*/
|
|
232
|
+
function combineImports(imports, exports, source) {
|
|
233
|
+
const exportedNames = new Set(exports.flatMap((node) => getNames(node).map((item) => item.alias ?? item.name)));
|
|
234
|
+
const identifiers = source && imports.length > INDEX_ABOVE_IMPORTS ? new Set(source.match(IDENTIFIER_RUN)) : null;
|
|
235
|
+
const isUsed = (importName) => !source || identifiers?.has(importName) || source.includes(importName) || exportedNames.has(importName);
|
|
236
|
+
const statements = toStatements(imports.filter((node) => node.path !== node.root), importForm);
|
|
237
|
+
const pathsWithUsedNamedImport = new Set(statements.filter(({ form, names }) => form === "named" && names.some((item) => isUsed(item.alias ?? item.name))).map(({ path }) => path));
|
|
238
|
+
const keep = (item, { form, path }) => isUsed(item.alias ?? item.name) || form !== "named" && pathsWithUsedNamedImport.has(path);
|
|
239
|
+
return mergeStatements(statements, keep).map(({ path, root, names }) => ({
|
|
240
|
+
kind: "Import",
|
|
241
|
+
path,
|
|
242
|
+
...root != null ? { root } : {},
|
|
243
|
+
...toDeprecatedImport(names),
|
|
244
|
+
names
|
|
245
|
+
}));
|
|
246
|
+
}
|
|
247
|
+
// src/nodes/base.ts
|
|
248
|
+
/** Builds a `createX` factory for a node whose only computed field is `kind`. */
|
|
249
|
+
function nodeFactory(kind) {
|
|
250
|
+
return (input) => {
|
|
251
|
+
return {
|
|
252
|
+
...input,
|
|
253
|
+
kind
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
// src/nodes/file.ts
|
|
258
|
+
function overrideSpace(names, { value, derived }) {
|
|
259
|
+
if (value == null || value === derived) return names;
|
|
260
|
+
const space = value ? "type" : "value";
|
|
261
|
+
return names.map((item) => ({
|
|
262
|
+
...item,
|
|
263
|
+
space
|
|
264
|
+
}));
|
|
265
|
+
}
|
|
266
|
+
const isOverride = ({ value, derived }) => value !== void 0 && JSON.stringify(value) !== JSON.stringify(derived);
|
|
267
|
+
/**
|
|
268
|
+
* Creates an `ImportNode`. A node built from `names` also gets the deprecated fields. A deprecated `name` or
|
|
269
|
+
* `isTypeOnly` that differs from the one `names` gives overrides it, so `{ ...imp, isTypeOnly: true }` still works.
|
|
270
|
+
*
|
|
271
|
+
* @example Named import
|
|
272
|
+
* ```ts
|
|
273
|
+
* createImport({ names: [{ name: 'useState' }], path: 'react' })
|
|
274
|
+
* // import { useState } from 'react'
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
function createImport(input) {
|
|
278
|
+
if (!input.names) return {
|
|
279
|
+
...input,
|
|
280
|
+
name: input.name ?? [],
|
|
281
|
+
kind: nodeKinds.import
|
|
282
|
+
};
|
|
283
|
+
const derived = toDeprecatedImport(input.names);
|
|
284
|
+
if (isOverride({
|
|
285
|
+
value: input.name,
|
|
286
|
+
derived: derived.name
|
|
287
|
+
})) return {
|
|
288
|
+
...input,
|
|
289
|
+
names: null,
|
|
290
|
+
name: input.name ?? [],
|
|
291
|
+
kind: nodeKinds.import
|
|
292
|
+
};
|
|
293
|
+
const names = overrideSpace(input.names, {
|
|
294
|
+
value: input.isTypeOnly,
|
|
295
|
+
derived: derived.isTypeOnly
|
|
296
|
+
});
|
|
297
|
+
return {
|
|
298
|
+
...input,
|
|
299
|
+
...toDeprecatedImport(names),
|
|
300
|
+
names,
|
|
301
|
+
kind: nodeKinds.import
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Creates an `ExportNode`. A node built from `names` also gets the deprecated fields. A deprecated `name` or
|
|
306
|
+
* `isTypeOnly` that differs from the one `names` gives overrides it.
|
|
307
|
+
*
|
|
308
|
+
* @example Named export
|
|
309
|
+
* ```ts
|
|
310
|
+
* createExport({ names: [{ name: 'Pet' }], path: './Pet' })
|
|
311
|
+
* // export { Pet } from './Pet'
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
function createExport(input) {
|
|
315
|
+
if (!input.names) return {
|
|
316
|
+
...input,
|
|
317
|
+
kind: nodeKinds.export
|
|
318
|
+
};
|
|
319
|
+
const derived = toDeprecatedExport(input.names);
|
|
320
|
+
if (isOverride({
|
|
321
|
+
value: input.name,
|
|
322
|
+
derived: derived.name
|
|
323
|
+
})) return {
|
|
324
|
+
...input,
|
|
325
|
+
names: null,
|
|
326
|
+
kind: nodeKinds.export
|
|
327
|
+
};
|
|
328
|
+
const names = overrideSpace(input.names, {
|
|
329
|
+
value: input.isTypeOnly,
|
|
330
|
+
derived: derived.isTypeOnly
|
|
331
|
+
});
|
|
332
|
+
return {
|
|
333
|
+
...input,
|
|
334
|
+
...toDeprecatedExport(names),
|
|
335
|
+
names,
|
|
336
|
+
kind: nodeKinds.export
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Creates a `SourceNode` representing a fragment of source code within a file.
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```ts
|
|
344
|
+
* createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], export: true })
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
const createSource = nodeFactory(nodeKinds.source);
|
|
348
|
+
/**
|
|
349
|
+
* Creates a fully resolved `FileNode` from a file input descriptor.
|
|
350
|
+
*
|
|
351
|
+
* Computes:
|
|
352
|
+
* - `id` SHA256 hash of the file path
|
|
353
|
+
* - `name` `baseName` without extension
|
|
354
|
+
* - `extname` extension extracted from `baseName`
|
|
355
|
+
*
|
|
356
|
+
* Deduplicates:
|
|
357
|
+
* - `sources` via `combineSources`
|
|
358
|
+
* - `exports` via `combineExports`
|
|
359
|
+
* - `imports` via `combineImports` (also filters unused imports)
|
|
360
|
+
*
|
|
361
|
+
* @throws {Error} when `baseName` has no extension.
|
|
362
|
+
*
|
|
363
|
+
* @example
|
|
364
|
+
* ```ts
|
|
365
|
+
* const file = createFile({
|
|
366
|
+
* baseName: 'petStore.ts',
|
|
367
|
+
* path: 'src/models/petStore.ts',
|
|
368
|
+
* sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],
|
|
369
|
+
* imports: [createImport({ name: ['z'], path: 'zod' })],
|
|
370
|
+
* exports: [createExport({ name: ['Pet'], path: './petStore' })],
|
|
371
|
+
* })
|
|
372
|
+
* // file.id = SHA256 hash of 'src/models/petStore.ts'
|
|
373
|
+
* // file.name = 'petStore'
|
|
374
|
+
* // file.extname = '.ts'
|
|
375
|
+
* ```
|
|
376
|
+
*
|
|
377
|
+
* @example Copy a real file into the output
|
|
378
|
+
* ```ts
|
|
379
|
+
* const file = createFile({
|
|
380
|
+
* baseName: 'client.ts',
|
|
381
|
+
* path: 'src/gen/client.ts',
|
|
382
|
+
* copy: '/abs/path/to/templates/client.ts',
|
|
383
|
+
* })
|
|
384
|
+
* ```
|
|
385
|
+
*/
|
|
386
|
+
function createFile(input) {
|
|
387
|
+
const extname = path.extname(input.baseName);
|
|
388
|
+
if (!extname) throw new Error(`No extname found for ${input.baseName}`);
|
|
389
|
+
const resolvedExports = input.exports?.length ? combineExports(input.exports) : [];
|
|
390
|
+
const resolvedSources = input.sources?.length ? combineSources(input.sources) : [];
|
|
391
|
+
const resolvedImports = (() => {
|
|
392
|
+
if (!input.imports?.length) return [];
|
|
393
|
+
const sourceParts = [];
|
|
394
|
+
const localNames = /* @__PURE__ */ new Set();
|
|
395
|
+
for (const item of resolvedSources) {
|
|
396
|
+
const extracted = item.nodes && getNodeText(item.nodes);
|
|
397
|
+
if (extracted) sourceParts.push(extracted);
|
|
398
|
+
if (item.name) localNames.add(item.name);
|
|
399
|
+
}
|
|
400
|
+
const source = sourceParts.join("\n") || void 0;
|
|
401
|
+
return combineImports(input.imports, resolvedExports, source).flatMap((imp) => {
|
|
402
|
+
if (imp.path === input.path) return [];
|
|
403
|
+
const names = getNames(imp);
|
|
404
|
+
const kept = names.filter((item) => !localNames.has(item.alias ?? item.name));
|
|
405
|
+
if (!kept.length) return [];
|
|
406
|
+
return [kept.length === names.length ? imp : createImport({
|
|
407
|
+
path: imp.path,
|
|
408
|
+
...imp.root != null ? { root: imp.root } : {},
|
|
409
|
+
names: kept
|
|
410
|
+
})];
|
|
411
|
+
});
|
|
412
|
+
})();
|
|
413
|
+
return {
|
|
414
|
+
...input,
|
|
415
|
+
kind: nodeKinds.file,
|
|
416
|
+
id: hash("sha256", input.path, "hex"),
|
|
417
|
+
name: path.basename(input.baseName, extname),
|
|
418
|
+
extname,
|
|
419
|
+
imports: resolvedImports,
|
|
420
|
+
exports: resolvedExports,
|
|
421
|
+
sources: resolvedSources,
|
|
422
|
+
meta: input.meta ?? {}
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
export { nodeFactory as a, createSource as i, createFile as n, getNames as o, createImport as r, getSpace as s, createExport as t };
|
|
426
|
+
|
|
427
|
+
//# sourceMappingURL=file-Bq2GPaxh.js.map
|