@vaadin/hilla-generator-utils 24.4.0-alpha1

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.
Files changed (59) hide show
  1. package/.lintstagedrc.js +6 -0
  2. package/LICENSE +201 -0
  3. package/LoggerFactory.d.ts +13 -0
  4. package/LoggerFactory.d.ts.map +1 -0
  5. package/LoggerFactory.js +34 -0
  6. package/LoggerFactory.js.map +7 -0
  7. package/PluginError.d.ts +4 -0
  8. package/PluginError.d.ts.map +1 -0
  9. package/PluginError.js +9 -0
  10. package/PluginError.js.map +7 -0
  11. package/README.md +1 -0
  12. package/ast.d.ts +6 -0
  13. package/ast.d.ts.map +1 -0
  14. package/ast.js +29 -0
  15. package/ast.js.map +7 -0
  16. package/createFullyUniqueIdentifier.d.ts +3 -0
  17. package/createFullyUniqueIdentifier.d.ts.map +1 -0
  18. package/createFullyUniqueIdentifier.js +12 -0
  19. package/createFullyUniqueIdentifier.js.map +7 -0
  20. package/createSourceFile.d.ts +3 -0
  21. package/createSourceFile.d.ts.map +1 -0
  22. package/createSourceFile.js +9 -0
  23. package/createSourceFile.js.map +7 -0
  24. package/dependencies/CodeConvertable.d.js +1 -0
  25. package/dependencies/CodeConvertable.d.js.map +7 -0
  26. package/dependencies/CodeConvertable.d.ts +3 -0
  27. package/dependencies/DependencyManager.d.ts +10 -0
  28. package/dependencies/DependencyManager.d.ts.map +1 -0
  29. package/dependencies/DependencyManager.js +16 -0
  30. package/dependencies/DependencyManager.js.map +7 -0
  31. package/dependencies/ExportManager.d.ts +38 -0
  32. package/dependencies/ExportManager.d.ts.map +1 -0
  33. package/dependencies/ExportManager.js +130 -0
  34. package/dependencies/ExportManager.js.map +7 -0
  35. package/dependencies/ImportManager.d.ts +44 -0
  36. package/dependencies/ImportManager.d.ts.map +1 -0
  37. package/dependencies/ImportManager.js +195 -0
  38. package/dependencies/ImportManager.js.map +7 -0
  39. package/dependencies/PathManager.d.ts +14 -0
  40. package/dependencies/PathManager.d.ts.map +1 -0
  41. package/dependencies/PathManager.js +41 -0
  42. package/dependencies/PathManager.js.map +7 -0
  43. package/dependencies/StatementRecordManager.d.ts +13 -0
  44. package/dependencies/StatementRecordManager.d.ts.map +1 -0
  45. package/dependencies/StatementRecordManager.js +26 -0
  46. package/dependencies/StatementRecordManager.js.map +7 -0
  47. package/dependencies/utils.d.ts +7 -0
  48. package/dependencies/utils.d.ts.map +1 -0
  49. package/dependencies/utils.js +10 -0
  50. package/dependencies/utils.js.map +7 -0
  51. package/memoize.d.ts +2 -0
  52. package/memoize.d.ts.map +1 -0
  53. package/memoize.js +15 -0
  54. package/memoize.js.map +7 -0
  55. package/package.json +102 -0
  56. package/testing/snapshotMatcher.d.ts +10 -0
  57. package/testing/snapshotMatcher.d.ts.map +1 -0
  58. package/testing/snapshotMatcher.js +34 -0
  59. package/testing/snapshotMatcher.js.map +7 -0
@@ -0,0 +1,130 @@
1
+ import ts, {} from "typescript";
2
+ import createFullyUniqueIdentifier from "../createFullyUniqueIdentifier.js";
3
+ import StatementRecordManager, {} from "./StatementRecordManager.js";
4
+ import { createDependencyRecord } from "./utils.js";
5
+ class NamedExportManager {
6
+ #collator;
7
+ #map = /* @__PURE__ */ new Map();
8
+ constructor(collator) {
9
+ this.#collator = collator;
10
+ }
11
+ add(name, isType, uniqueId) {
12
+ const id = uniqueId ?? createFullyUniqueIdentifier(name);
13
+ this.#map.set(name, createDependencyRecord(id, isType));
14
+ return id;
15
+ }
16
+ getIdentifier(name) {
17
+ return this.#map.get(name)?.id;
18
+ }
19
+ *identifiers() {
20
+ for (const { id, isType } of this.#map.values()) {
21
+ yield [id, isType];
22
+ }
23
+ }
24
+ isType(name) {
25
+ return this.#map.get(name)?.isType;
26
+ }
27
+ names() {
28
+ return this.#map.keys();
29
+ }
30
+ toCode() {
31
+ if (this.#map.size === 0) {
32
+ return void 0;
33
+ }
34
+ const names = [...this.#map.keys()];
35
+ names.sort(this.#collator.compare);
36
+ return ts.factory.createExportDeclaration(
37
+ void 0,
38
+ false,
39
+ ts.factory.createNamedExports(
40
+ names.map((name) => {
41
+ const { id, isType } = this.#map.get(name);
42
+ return ts.factory.createExportSpecifier(isType, id, ts.factory.createIdentifier(name));
43
+ })
44
+ ),
45
+ void 0
46
+ );
47
+ }
48
+ }
49
+ class NamespaceExportManager extends StatementRecordManager {
50
+ #map = /* @__PURE__ */ new Map();
51
+ addCombined(path, name, uniqueId) {
52
+ const id = uniqueId ?? createFullyUniqueIdentifier(name);
53
+ this.#map.set(path, id);
54
+ return id;
55
+ }
56
+ addSpread(path) {
57
+ this.#map.set(path, null);
58
+ }
59
+ clear() {
60
+ this.#map.clear();
61
+ }
62
+ getIdentifier(path) {
63
+ return this.#map.get(path);
64
+ }
65
+ identifiers() {
66
+ return this.#map.values();
67
+ }
68
+ isCombined(path) {
69
+ return this.#map.has(path) ? this.#map.get(path) !== null : void 0;
70
+ }
71
+ isSpread(path) {
72
+ return this.#map.has(path) ? this.#map.get(path) === null : void 0;
73
+ }
74
+ paths() {
75
+ return this.#map.keys();
76
+ }
77
+ *statementRecords() {
78
+ for (const [path, id] of this.#map) {
79
+ yield [
80
+ path,
81
+ ts.factory.createExportDeclaration(
82
+ void 0,
83
+ false,
84
+ id !== null ? ts.factory.createNamespaceExport(id) : void 0,
85
+ ts.factory.createStringLiteral(path)
86
+ )
87
+ ];
88
+ }
89
+ }
90
+ }
91
+ class DefaultExportManager {
92
+ #id;
93
+ set(id) {
94
+ this.#id = typeof id === "string" ? ts.factory.createIdentifier(id) : id;
95
+ return this.#id;
96
+ }
97
+ toCode() {
98
+ return this.#id ? ts.factory.createExportAssignment(void 0, void 0, this.#id) : void 0;
99
+ }
100
+ }
101
+ class ExportManager {
102
+ default = new DefaultExportManager();
103
+ named;
104
+ namespace;
105
+ constructor(collator) {
106
+ this.named = new NamedExportManager(collator);
107
+ this.namespace = new NamespaceExportManager(collator);
108
+ }
109
+ toCode() {
110
+ const defaultStatement = this.default.toCode();
111
+ const namedStatement = this.named.toCode();
112
+ const namespaceStatements = this.namespace.toCode();
113
+ const result = [];
114
+ if (namedStatement) {
115
+ result.push(namedStatement);
116
+ }
117
+ result.push(...namespaceStatements);
118
+ if (defaultStatement) {
119
+ result.push(defaultStatement);
120
+ }
121
+ return result;
122
+ }
123
+ }
124
+ export {
125
+ DefaultExportManager,
126
+ NamedExportManager,
127
+ NamespaceExportManager,
128
+ ExportManager as default
129
+ };
130
+ //# sourceMappingURL=ExportManager.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/dependencies/ExportManager.ts"],
4
+ "sourcesContent": ["import ts, { type ExportAssignment, type ExportDeclaration, type Identifier, type Statement } from 'typescript';\nimport createFullyUniqueIdentifier from '../createFullyUniqueIdentifier.js';\nimport type CodeConvertable from './CodeConvertable.js';\nimport StatementRecordManager, { type StatementRecord } from './StatementRecordManager.js';\nimport { createDependencyRecord, type DependencyRecord } from './utils.js';\n\nexport class NamedExportManager implements CodeConvertable<ExportDeclaration | undefined> {\n readonly #collator: Intl.Collator;\n readonly #map = new Map<string, DependencyRecord>();\n\n constructor(collator: Intl.Collator) {\n this.#collator = collator;\n }\n\n add(name: string, isType?: boolean, uniqueId?: Identifier): Identifier {\n const id = uniqueId ?? createFullyUniqueIdentifier(name);\n this.#map.set(name, createDependencyRecord(id, isType));\n return id;\n }\n\n getIdentifier(name: string): Identifier | undefined {\n return this.#map.get(name)?.id;\n }\n\n *identifiers(): IterableIterator<readonly [id: Identifier, isType: boolean]> {\n for (const { id, isType } of this.#map.values()) {\n yield [id, isType];\n }\n }\n\n isType(name: string): boolean | undefined {\n return this.#map.get(name)?.isType;\n }\n\n names(): IterableIterator<string> {\n return this.#map.keys();\n }\n\n toCode(): ExportDeclaration | undefined {\n if (this.#map.size === 0) {\n return undefined;\n }\n\n const names = [...this.#map.keys()];\n // eslint-disable-next-line @typescript-eslint/unbound-method\n names.sort(this.#collator.compare);\n\n return ts.factory.createExportDeclaration(\n undefined,\n false,\n ts.factory.createNamedExports(\n names.map((name) => {\n const { id, isType } = this.#map.get(name)!;\n return ts.factory.createExportSpecifier(isType, id, ts.factory.createIdentifier(name));\n }),\n ),\n undefined,\n );\n }\n}\n\nexport class NamespaceExportManager extends StatementRecordManager<ExportDeclaration> {\n readonly #map = new Map<string, Identifier | null>();\n\n addCombined(path: string, name: string, uniqueId?: Identifier): Identifier {\n const id = uniqueId ?? createFullyUniqueIdentifier(name);\n this.#map.set(path, id);\n return id;\n }\n\n addSpread(path: string): void {\n this.#map.set(path, null);\n }\n\n override clear(): void {\n this.#map.clear();\n }\n\n getIdentifier(path: string): Identifier | null | undefined {\n return this.#map.get(path);\n }\n\n identifiers(): IterableIterator<Identifier | null> {\n return this.#map.values();\n }\n\n isCombined(path: string): boolean | undefined {\n return this.#map.has(path) ? this.#map.get(path) !== null : undefined;\n }\n\n isSpread(path: string): boolean | undefined {\n return this.#map.has(path) ? this.#map.get(path) === null : undefined;\n }\n\n paths(): IterableIterator<string> {\n return this.#map.keys();\n }\n\n override *statementRecords(): IterableIterator<StatementRecord<ExportDeclaration>> {\n for (const [path, id] of this.#map) {\n yield [\n path,\n ts.factory.createExportDeclaration(\n undefined,\n false,\n id !== null ? ts.factory.createNamespaceExport(id) : undefined,\n ts.factory.createStringLiteral(path),\n ),\n ];\n }\n }\n}\n\nexport class DefaultExportManager implements CodeConvertable<ExportAssignment | undefined> {\n #id?: Identifier;\n\n set(id: Identifier | string): Identifier {\n this.#id = typeof id === 'string' ? ts.factory.createIdentifier(id) : id;\n return this.#id;\n }\n\n toCode(): ExportAssignment | undefined {\n return this.#id ? ts.factory.createExportAssignment(undefined, undefined, this.#id) : undefined;\n }\n}\n\nexport default class ExportManager implements CodeConvertable<readonly Statement[]> {\n readonly default = new DefaultExportManager();\n readonly named: NamedExportManager;\n readonly namespace: NamespaceExportManager;\n\n constructor(collator: Intl.Collator) {\n this.named = new NamedExportManager(collator);\n this.namespace = new NamespaceExportManager(collator);\n }\n\n toCode(): readonly Statement[] {\n const defaultStatement = this.default.toCode();\n const namedStatement = this.named.toCode();\n const namespaceStatements = this.namespace.toCode();\n\n const result: Statement[] = [];\n\n if (namedStatement) {\n result.push(namedStatement);\n }\n\n result.push(...namespaceStatements);\n\n if (defaultStatement) {\n result.push(defaultStatement);\n }\n\n return result;\n }\n}\n"],
5
+ "mappings": "AAAA,OAAO,YAA4F;AACnG,OAAO,iCAAiC;AAExC,OAAO,gCAAsD;AAC7D,SAAS,8BAAqD;AAEvD,MAAM,mBAA6E;AAAA,EAC/E;AAAA,EACA,OAAO,oBAAI,IAA8B;AAAA,EAElD,YAAY,UAAyB;AACnC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,IAAI,MAAc,QAAkB,UAAmC;AACrE,UAAM,KAAK,YAAY,4BAA4B,IAAI;AACvD,SAAK,KAAK,IAAI,MAAM,uBAAuB,IAAI,MAAM,CAAC;AACtD,WAAO;AAAA,EACT;AAAA,EAEA,cAAc,MAAsC;AAClD,WAAO,KAAK,KAAK,IAAI,IAAI,GAAG;AAAA,EAC9B;AAAA,EAEA,CAAC,cAA4E;AAC3E,eAAW,EAAE,IAAI,OAAO,KAAK,KAAK,KAAK,OAAO,GAAG;AAC/C,YAAM,CAAC,IAAI,MAAM;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,OAAO,MAAmC;AACxC,WAAO,KAAK,KAAK,IAAI,IAAI,GAAG;AAAA,EAC9B;AAAA,EAEA,QAAkC;AAChC,WAAO,KAAK,KAAK,KAAK;AAAA,EACxB;AAAA,EAEA,SAAwC;AACtC,QAAI,KAAK,KAAK,SAAS,GAAG;AACxB,aAAO;AAAA,IACT;AAEA,UAAM,QAAQ,CAAC,GAAG,KAAK,KAAK,KAAK,CAAC;AAElC,UAAM,KAAK,KAAK,UAAU,OAAO;AAEjC,WAAO,GAAG,QAAQ;AAAA,MAChB;AAAA,MACA;AAAA,MACA,GAAG,QAAQ;AAAA,QACT,MAAM,IAAI,CAAC,SAAS;AAClB,gBAAM,EA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AA,EACF;AACF;AAEO,MAAM,qBAA8E;AAAA,EACzF;AAAA,EAEA,IAAI,IAAqC;AACvC,SAAK,MAAM,OAAO,OAAO,WAAW,GAAG,QAAQ,iBAAiB,EAAE,IAAI;AACtE,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,SAAuC;AACrC,WAAO,KAAK,MAAM,GAAG,QAAQ,uBAAuB,QAAW,QAAW,KAAK,GAAG,IAAI;AAAA,EACxF;AACF;AAEA,MAAO,cAA6E;AAAA,EACzE,UAAU,IAAI,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EAET,YAAY,UAAyB;AACnC,SAAK,QAAQ,IAAI,mBAAmB,QAAQ;AAC5C,SAAK,YAAY,IAAI,uBAAuB,QAAQ;AAAA,EACtD;AAAA,EAEA,SAA+B;AAC7B,UAAM,mBAAmB,KAAK,QAAQ,OAAO;AAC7C,UAAM,iBAAiB,KAAK,MAAM,OAAO;AACzC,UAAM,sBAAsB,KAAK,UAAU,OAAO;AAElD,UAAM,SAAsB,CAAC;AAE7B,QAAI,gBAAgB;AAClB,aAAO,KAAK,cAAc;AAAA,IAC5B;AAEA,WAAO,KAAK,GAAG,mBAAmB;AAElC,QAAI,kBAAkB;AACpB,aAAO,KAAK,gBAAgB;AAAA,IAC9B;AAEA,WAAO;AAAA,EACT;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,44 @@
1
+ import ts, { type Identifier, type ImportDeclaration, type Statement } from 'typescript';
2
+ import type CodeConvertable from './CodeConvertable.js';
3
+ import StatementRecordManager, { type StatementRecord } from './StatementRecordManager.js';
4
+ export declare class NamedImportManager extends StatementRecordManager<ImportDeclaration> {
5
+ #private;
6
+ constructor(collator: Intl.Collator);
7
+ add(path: string, specifier: string, isType?: boolean, uniqueId?: Identifier): Identifier;
8
+ clear(): void;
9
+ getIdentifier(path: string, specifier: string): Identifier | undefined;
10
+ identifiers(): IterableIterator<readonly [path: string, specifier: string, id: Identifier, isType: boolean]>;
11
+ isType(path: string, specifier: string): boolean | undefined;
12
+ paths(): IterableIterator<string>;
13
+ specifiers(): IterableIterator<readonly [path: string, specifier: string]>;
14
+ statementRecords(): IterableIterator<StatementRecord<ImportDeclaration>>;
15
+ }
16
+ export declare class NamespaceImportManager extends StatementRecordManager<ImportDeclaration> {
17
+ #private;
18
+ add(path: string, name: string, uniqueId?: Identifier): Identifier;
19
+ clear(): void;
20
+ getIdentifier(path: string): Identifier | undefined;
21
+ identifiers(): IterableIterator<Identifier>;
22
+ paths(): IterableIterator<string>;
23
+ statementRecords(): IterableIterator<StatementRecord<ImportDeclaration>>;
24
+ }
25
+ export declare class DefaultImportManager extends StatementRecordManager<ImportDeclaration> {
26
+ #private;
27
+ add(path: string, name: string, isType?: boolean, uniqueId?: Identifier): Identifier;
28
+ getIdentifier(path: string): Identifier | undefined;
29
+ clear(): void;
30
+ identifiers(): IterableIterator<readonly [id: Identifier, isType: boolean]>;
31
+ isType(path: string): boolean | undefined;
32
+ paths(): IterableIterator<string>;
33
+ statementRecords(): IterableIterator<StatementRecord<ImportDeclaration>>;
34
+ }
35
+ export default class ImportManager implements CodeConvertable<readonly Statement[]> {
36
+ #private;
37
+ readonly default: DefaultImportManager;
38
+ readonly named: NamedImportManager;
39
+ readonly namespace: NamespaceImportManager;
40
+ constructor(collator: Intl.Collator);
41
+ toCode(): readonly Statement[];
42
+ fromCode(source: ts.SourceFile): void;
43
+ }
44
+ //# sourceMappingURL=ImportManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImportManager.d.ts","sourceRoot":"","sources":["../src/dependencies/ImportManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,KAAK,UAAU,EAAE,KAAK,iBAAiB,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAEzF,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AACxD,OAAO,sBAAsB,EAAE,EAAE,KAAK,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAG3F,qBAAa,k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AsB,CAAC,iBAAiB,CAAC;;IAGjF,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,UAAU,GAAG,UAAU;IAMpF,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAI1C,KAAK,IAAI,IAAI;IAIrB,WAAW,IAAI,gBAAgB,CAAC,SAAS,CAAC,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAM5E,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAIzC,KAAK,IAAI,gBAAgB,CAAC,MAAM,CAAC;IAIvB,gBAAgB,IAAI,gBAAgB,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC;CAYnF;AAED,MAAM,CAAC,OAAO,OAAO,aAAc,YAAW,eAAe,CAAC,SAAS,SAAS,EAAE,CAAC;;IACjF,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,sBAAsB,CAAC;gBAI/B,QAAQ,EAAE,IAAI,CAAC,QAAQ;IAOnC,MAAM,IAAI,SAAS,SAAS,EAAE;IAW9B,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,GAAG,IAAI;CA+BtC"}
@@ -0,0 +1,195 @@
1
+ import ts, {} from "typescript";
2
+ import createFullyUniqueIdentifier from "../createFullyUniqueIdentifier.js";
3
+ import StatementRecordManager, {} from "./StatementRecordManager.js";
4
+ import { createDependencyRecord } from "./utils.js";
5
+ class NamedImportManager extends StatementRecordManager {
6
+ #collator;
7
+ #map = /* @__PURE__ */ new Map();
8
+ constructor(collator) {
9
+ super(collator);
10
+ this.#collator = collator;
11
+ }
12
+ add(path, specifier, isType, uniqueId) {
13
+ const record = createDependencyRecord(uniqueId ?? createFullyUniqueIdentifier(specifier), isType);
14
+ if (this.#map.has(path)) {
15
+ this.#map.get(path).set(specifier, record);
16
+ } else {
17
+ this.#map.set(path, /* @__PURE__ */ new Map([[specifier, record]]));
18
+ }
19
+ return record.id;
20
+ }
21
+ clear() {
22
+ this.#map.clear();
23
+ }
24
+ getIdentifier(path, specifier) {
25
+ return this.#map.get(path)?.get(specifier)?.id;
26
+ }
27
+ *identifiers() {
28
+ for (const [path, specifiers] of this.#map) {
29
+ for (const [specifier, { id, isType }] of specifiers) {
30
+ yield [path, specifier, id, isType];
31
+ }
32
+ }
33
+ }
34
+ isType(path, specifier) {
35
+ return this.#map.get(path)?.get(specifier)?.isType;
36
+ }
37
+ paths() {
38
+ return this.#map.keys();
39
+ }
40
+ *specifiers() {
41
+ for (const [path, specifiers] of this.#map) {
42
+ for (const specifier of specifiers.keys()) {
43
+ yield [path, specifier];
44
+ }
45
+ }
46
+ }
47
+ *statementRecords() {
48
+ for (const [path, specifiers] of this.#map) {
49
+ const names = [...specifiers.keys()];
50
+ names.sort(this.#collator.compare);
51
+ yield [
52
+ path,
53
+ ts.factory.createImportDeclaration(
54
+ void 0,
55
+ ts.factory.createImportClause(
56
+ false,
57
+ void 0,
58
+ ts.factory.createNamedImports(
59
+ names.map((name) => {
60
+ const { id, isType } = specifiers.get(name);
61
+ return ts.factory.createImportSpecifier(isType, ts.factory.createIdentifier(name), id);
62
+ })
63
+ )
64
+ ),
65
+ ts.factory.createStringLiteral(path)
66
+ )
67
+ ];
68
+ }
69
+ }
70
+ }
71
+ class NamespaceImportManager extends StatementRecordManager {
72
+ #map = /* @__PURE__ */ new Map();
73
+ add(path, name, uniqueId) {
74
+ const id = uniqueId ?? createFullyUniqueIdentifier(name);
75
+ this.#map.set(path, id);
76
+ return id;
77
+ }
78
+ clear() {
79
+ this.#map.clear();
80
+ }
81
+ getIdentifier(path) {
82
+ return this.#map.get(path);
83
+ }
84
+ *identifiers() {
85
+ for (const id of this.#map.values()) {
86
+ yield id;
87
+ }
88
+ }
89
+ paths() {
90
+ return this.#map.keys();
91
+ }
92
+ *statementRecords() {
93
+ for (const [path, id] of this.#map) {
94
+ yield [
95
+ path,
96
+ ts.factory.createImportDeclaration(
97
+ void 0,
98
+ ts.factory.createImportClause(false, void 0, ts.factory.createNamespaceImport(id)),
99
+ ts.factory.createStringLiteral(path)
100
+ )
101
+ ];
102
+ }
103
+ }
104
+ }
105
+ class DefaultImportManager extends StatementRecordManager {
106
+ #map = /* @__PURE__ */ new Map();
107
+ add(path, name, isType, uniqueId) {
108
+ const id = uniqueId ?? createFullyUniqueIdentifier(name);
109
+ this.#map.set(path, createDependencyRecord(id, isType));
110
+ return id;
111
+ }
112
+ getIdentifier(path) {
113
+ return this.#map.get(path)?.id;
114
+ }
115
+ clear() {
116
+ this.#map.clear();
117
+ }
118
+ *identifiers() {
119
+ for (const { id, isType } of this.#map.values()) {
120
+ yield [id, isType];
121
+ }
122
+ }
123
+ isType(path) {
124
+ return this.#map.get(path)?.isType;
125
+ }
126
+ paths() {
127
+ return this.#map.keys();
128
+ }
129
+ *statementRecords() {
130
+ for (const [path, { id, isType }] of this.#map) {
131
+ yield [
132
+ path,
133
+ ts.factory.createImportDeclaration(
134
+ void 0,
135
+ ts.factory.createImportClause(isType, id, void 0),
136
+ ts.factory.createStringLiteral(path)
137
+ )
138
+ ];
139
+ }
140
+ }
141
+ }
142
+ class ImportManager {
143
+ default;
144
+ named;
145
+ namespace;
146
+ #collator;
147
+ constructor(collator) {
148
+ this.default = new DefaultImportManager(collator);
149
+ this.named = new NamedImportManager(collator);
150
+ this.namespace = new NamespaceImportManager(collator);
151
+ this.#collator = collator;
152
+ }
153
+ toCode() {
154
+ const records = [
155
+ ...this.default.statementRecords(),
156
+ ...this.named.statementRecords(),
157
+ ...this.namespace.statementRecords()
158
+ ];
159
+ records.sort(StatementRecordManager.createComparator(this.#collator));
160
+ return records.map(([, statement]) => statement);
161
+ }
162
+ fromCode(source) {
163
+ this.default.clear();
164
+ this.named.clear();
165
+ this.namespace.clear();
166
+ const imports = source.statements.filter(
167
+ (statement) => ts.isImportDeclaration(statement)
168
+ );
169
+ for (const { importClause, moduleSpecifier } of imports) {
170
+ if (!importClause) {
171
+ continue;
172
+ }
173
+ const { name, namedBindings } = importClause;
174
+ const path = moduleSpecifier.text;
175
+ if (namedBindings) {
176
+ if (ts.isNamespaceImport(namedBindings)) {
177
+ this.namespace.add(path, namedBindings.name.text, namedBindings.name);
178
+ } else {
179
+ for (const { isTypeOnly, name: specifier } of namedBindings.elements) {
180
+ this.named.add(path, specifier.text, isTypeOnly, specifier);
181
+ }
182
+ }
183
+ } else if (name) {
184
+ this.default.add(path, name.text, importClause.isTypeOnly, name);
185
+ }
186
+ }
187
+ }
188
+ }
189
+ export {
190
+ DefaultImportManager,
191
+ NamedImportManager,
192
+ NamespaceImportManager,
193
+ ImportManager as default
194
+ };
195
+ //# sourceMappingURL=ImportManager.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/dependencies/ImportManager.ts"],
4
+ "sourcesContent": ["import ts, { type Identifier, type ImportDeclaration, type Statement } from 'typescript';\nimport createFullyUniqueIdentifier from '../createFullyUniqueIdentifier.js';\nimport type CodeConvertable from './CodeConvertable.js';\nimport StatementRecordManager, { type StatementRecord } from './StatementRecordManager.js';\nimport { createDependencyRecord, type DependencyRecord } from './utils.js';\n\nexport class NamedImportManager extends StatementRecordManager<ImportDeclaration> {\n readonly #collator: Intl.Collator;\n readonly #map = new Map<string, Map<string, DependencyRecord>>();\n\n constructor(collator: Intl.Collator) {\n super(collator);\n this.#collator = collator;\n }\n\n add(path: string, specifier: string, isType?: boolean, uniqueId?: Identifier): Identifier {\n const record = createDependencyRecord(uniqueId ?? createFullyUniqueIdentifier(specifier), isType);\n\n if (this.#map.has(path)) {\n this.#map.get(path)!.set(specifier, record);\n } else {\n this.#map.set(path, new Map([[specifier, record]]));\n }\n\n return record.id;\n }\n\n override clear(): void {\n this.#map.clear();\n }\n\n getIdentifier(path: string, specifier: string): Identifier | undefined {\n return this.#map.get(path)?.get(specifier)?.id;\n }\n\n *identifiers(): IterableIterator<readonly [path: string, specifier: string, id: Identifier, isType: boolean]> {\n for (const [path, specifiers] of this.#map) {\n for (const [specifier, { id, isType }] of specifiers) {\n yield [path, specifier, id, isType];\n }\n }\n }\n\n isType(path: string, specifier: string): boolean | undefined {\n return this.#map.get(path)?.get(specifier)?.isType;\n }\n\n paths(): IterableIterator<string> {\n return this.#map.keys();\n }\n\n *specifiers(): IterableIterator<readonly [path: string, specifier: string]> {\n for (const [path, specifiers] of this.#map) {\n for (const specifier of specifiers.keys()) {\n yield [path, specifier];\n }\n }\n }\n\n override *statementRecords(): IterableIterator<StatementRecord<ImportDeclaration>> {\n for (const [path, specifiers] of this.#map) {\n const names = [...specifiers.keys()];\n // eslint-disable-next-line @typescript-eslint/unbound-method\n names.sort(this.#collator.compare);\n\n yield [\n path,\n ts.factory.createImportDeclaration(\n undefined,\n ts.factory.createImportClause(\n false,\n undefined,\n ts.factory.createNamedImports(\n names.map((name) => {\n const { id, isType } = specifiers.get(name)!;\n return ts.factory.createImportSpecifier(isType, ts.factory.createIdentifier(name), id);\n }),\n ),\n ),\n ts.factory.createStringLiteral(path),\n ),\n ];\n }\n }\n}\n\nexport class NamespaceImportManager extends StatementRecordManager<ImportDeclaration> {\n readonly #map = new Map<string, Identifier>();\n\n add(path: string, name: string, uniqueId?: Identifier): Identifier {\n const id = uniqueId ?? createFullyUniqueIdentifier(name);\n this.#map.set(path, id);\n return id;\n }\n\n override clear(): void {\n this.#map.clear();\n }\n\n getIdentifier(path: string): Identifier | undefined {\n return this.#map.get(path);\n }\n\n *identifiers(): IterableIterator<Identifier> {\n for (const id of this.#map.values()) {\n yield id;\n }\n }\n\n paths(): IterableIterator<string> {\n return this.#map.keys();\n }\n\n override *statementRecords(): IterableIterator<StatementRecord<ImportDeclaration>> {\n for (const [path, id] of this.#map) {\n yield [\n path,\n ts.factory.createImportDeclaration(\n undefined,\n ts.factory.createImportClause(false, undefined, ts.factory.createNamespaceImport(id)),\n ts.factory.createStringLiteral(path),\n ),\n ];\n }\n }\n}\n\nexport class DefaultImportManager extends StatementRecordManager<ImportDeclaration> {\n readonly #map = new Map<string, DependencyRecord>();\n\n add(path: string, name: string, isType?: boolean, uniqueId?: Identifier): Identifier {\n const id = uniqueId ?? createFullyUniqueIdentifier(name);\n this.#map.set(path, createDependencyRecord(id, isType));\n return id;\n }\n\n getIdentifier(path: string): Identifier | undefined {\n return this.#map.get(path)?.id;\n }\n\n override clear(): void {\n this.#map.clear();\n }\n\n *identifiers(): IterableIterator<readonly [id: Identifier, isType: boolean]> {\n for (const { id, isType } of this.#map.values()) {\n yield [id, isType];\n }\n }\n\n isType(path: string): boolean | undefined {\n return this.#map.get(path)?.isType;\n }\n\n paths(): IterableIterator<string> {\n return this.#map.keys();\n }\n\n override *statementRecords(): IterableIterator<StatementRecord<ImportDeclaration>> {\n for (const [path, { id, isType }] of this.#map) {\n yield [\n path,\n ts.factory.createImportDeclaration(\n undefined,\n ts.factory.createImportClause(isType, id, undefined),\n ts.factory.createStringLiteral(path),\n ),\n ];\n }\n }\n}\n\nexport default class ImportManager implements CodeConvertable<readonly Statement[]> {\n readonly default: DefaultImportManager;\n readonly named: NamedImportManager;\n readonly namespace: NamespaceImportManager;\n\n readonly #collator: Intl.Collator;\n\n constructor(collator: Intl.Collator) {\n this.default = new DefaultImportManager(collator);\n this.named = new NamedImportManager(collator);\n this.namespace = new NamespaceImportManager(collator);\n this.#collator = collator;\n }\n\n toCode(): readonly Statement[] {\n const records = [\n ...this.default.statementRecords(),\n ...this.named.statementRecords(),\n ...this.namespace.statementRecords(),\n ];\n records.sort(StatementRecordManager.createComparator(this.#collator));\n\n return records.map(([, statement]) => statement);\n }\n\n fromCode(source: ts.SourceFile): void {\n this.default.clear();\n this.named.clear();\n this.namespace.clear();\n\n const imports = source.statements.filter((statement): statement is ImportDeclaration =>\n ts.isImportDeclaration(statement),\n );\n\n for (const { importClause, moduleSpecifier } of imports) {\n if (!importClause) {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n const { name, namedBindings } = importClause;\n const path = (moduleSpecifier as ts.StringLiteral).text;\n\n if (namedBindings) {\n if (ts.isNamespaceImport(namedBindings)) {\n this.namespace.add(path, namedBindings.name.text, namedBindings.name);\n } else {\n for (const { isTypeOnly, name: specifier } of namedBindings.elements) {\n this.named.add(path, specifier.text, isTypeOnly, specifier);\n }\n }\n } else if (name) {\n this.default.add(path, name.text, importClause.isTypeOnly, name);\n }\n }\n }\n}\n"],
5
+ "mappings": "AAAA,OAAO,YAAqE;AAC5E,OAAO,iCAAiC;AAExC,OAAO,gCAAsD;AAC7D,SAAS,8BAAqD;AAEvD,MAAM,2BAA2B,uBAA0C;AAAA,EACvE;AAAA,EACA,OAAO,oBAAI,IAA2C;AAAA,EAE/D,YAAY,UAAyB;AACnC,UAAM,QAAQ;AACd,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,IAAI,MAAc,WAAmB,QAAkB,UAAmC;AACxF,UAAM,SAAS,uBAAuB,YAAY,4BAA4B,SAAS,GAAG,MAAM;AAEhG,QAAI,KAAK,KAAK,IAAI,IAAI,GAAG;AACvB,WAAK,KAAK,IAAI,IAAI,EAAG,IAAI,WAAW,MAAM;AAAA,IAC5C,OAAO;AACL,WAAK,KAAK,IAAI,MAAM,oBAAI,IAAI,CAAC,CAAC,WAAW,MAAM,CAAC,CAAC,CAAC;AAAA,IACpD;AAEA,WAAO,OAAO;AAAA,EAChB;AAAA,EAES,QAAc;AACrB,SAAK,KAAK,MAAM;AAAA,EAClB;AAAA,EAEA,cAAc,MAAc,WAA2C;AACrE,WAAO,KAAK,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,GAAG;AAAA,EAC9C;AAAA,EAEA,CAAC,cAA6G;AAC5G,eAAW,CAAC,MAAM,UAAU,KAAK,KAAK,MAAM;AAC1C,iBAAW,CAAC,WAAW,EAAE,IAAI,OAAO,CAAC,KAAK,Y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AAM,cAAc,KAAK,MAAM,cAAc,IAAI;AAAA,QACtE,OAAO;AACL,qBAAW,EAAE,YAAY,MAAM,UAAU,KAAK,cAAc,UAAU;AACpE,iBAAK,MAAM,IAAI,MAAM,UAAU,MAAM,YAAY,SAAS;AAAA,UAC5D;AAAA,QACF;AAAA,MACF,WAAW,MAAM;AACf,aAAK,QAAQ,IAAI,MAAM,KAAK,MAAM,aAAa,YAAY,IAAI;AAAA,MACjE;AAAA,IACF;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,14 @@
1
+ export type PathManagerOptions = Readonly<{
2
+ aliasRoot?: string;
3
+ extension?: string;
4
+ relativeTo?: string;
5
+ }>;
6
+ export default class PathManager {
7
+ #private;
8
+ constructor(options?: PathManagerOptions);
9
+ get aliasRoot(): string | undefined;
10
+ createBareModulePath(path: string, isFile?: boolean): string;
11
+ createRelativePath(path: string, relativeTo?: string): string;
12
+ createTSAliasModulePath(path: string, root?: string | undefined): string;
13
+ }
14
+ //# sourceMappingURL=PathManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PathManager.d.ts","sourceRoot":"","sources":["../src/dependencies/PathManager.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC,CAAC;AAEH,MAAM,CAAC,OAAO,OAAO,WAAW;;gBAGlB,OAAO,CAAC,EAAE,kBAAkB;IAcxC,IAAI,SAAS,IAAI,MAAM,GAAG,SAAS,CAElC;IAED,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,UAAQ,GAAG,MAAM;IAU1D,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,SAA2B,GAAG,MAAM;IAY/E,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,qBAA0B,GAAG,MAAM;CAG9E"}
@@ -0,0 +1,41 @@
1
+ import { posix } from "path";
2
+ class PathManager {
3
+ #options;
4
+ constructor(options) {
5
+ let extension;
6
+ if (options?.extension) {
7
+ extension = options.extension.startsWith(".") ? options.extension : `.${options.extension}`;
8
+ }
9
+ this.#options = {
10
+ ...options,
11
+ extension,
12
+ relativeTo: options?.relativeTo ?? "."
13
+ };
14
+ }
15
+ get aliasRoot() {
16
+ return this.#options.aliasRoot;
17
+ }
18
+ createBareModulePath(path, isFile = false) {
19
+ const { extension } = this.#options;
20
+ if (extension && isFile) {
21
+ return `${path}.${extension}`;
22
+ }
23
+ return path;
24
+ }
25
+ createRelativePath(path, relativeTo = this.#options.relativeTo) {
26
+ const { extension } = this.#options;
27
+ let result = path;
28
+ if (extension && !path.endsWith(extension)) {
29
+ result = `${result}${extension}`;
30
+ }
31
+ result = posix.relative(relativeTo, result);
32
+ return result.startsWith(".") ? result : `./${result}`;
33
+ }
34
+ createTSAliasModulePath(path, root = this.#options.aliasRoot) {
35
+ return root ? `${root}/${path}` : path;
36
+ }
37
+ }
38
+ export {
39
+ PathManager as default
40
+ };
41
+ //# sourceMappingURL=PathManager.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/dependencies/PathManager.ts"],
4
+ "sourcesContent": ["import { posix } from 'path';\nimport type { SetRequired } from 'type-fest';\n\nexport type PathManagerOptions = Readonly<{\n aliasRoot?: string;\n extension?: string;\n relativeTo?: string;\n}>;\n\nexport default class PathManager {\n readonly #options: SetRequired<PathManagerOptions, 'relativeTo'>;\n\n constructor(options?: PathManagerOptions) {\n let extension: string | undefined;\n\n if (options?.extension) {\n extension = options.extension.startsWith('.') ? options.extension : `.${options.extension}`;\n }\n\n this.#options = {\n ...options,\n extension,\n relativeTo: options?.relativeTo ?? '.',\n };\n }\n\n get aliasRoot(): string | undefined {\n return this.#options.aliasRoot;\n }\n\n createBareModulePath(path: string, isFile = false): string {\n const { extension } = this.#options;\n\n if (extension && isFile) {\n return `${path}.${extension}`;\n }\n\n return path;\n }\n\n createRelativePath(path: string, relativeTo = this.#options.relativeTo): string {\n const { extension } = this.#options;\n let result = path;\n\n if (extension && !path.endsWith(extension)) {\n result = `${result}${extension}`;\n }\n\n result = posix.relative(relativeTo, result);\n return result.startsWith('.') ? result : `./${result}`;\n }\n\n createTSAliasModulePath(path: string, root = this.#options.aliasRoot): string {\n return root ? `${root}/${path}` : path;\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,aAAa;AAStB,MAAO,YAA0B;AAAA,EACtB;AAAA,EAET,YAAY,SAA8B;AACxC,QAAI;AAEJ,QAAI,SAAS,WAAW;AACtB,kBAAY,QAAQ,UAAU,WAAW,GAAG,IAAI,QAAQ,YAAY,IAAI,QAAQ,SAAS;AAAA,IAC3F;AAEA,SAAK,WAAW;AAAA,MACd,GAAG;AAAA,MACH;AAAA,MACA,YAAY,SAAS,cAAc;AAAA,IACrC;AAAA,EACF;AAAA,EAEA,IAAI,YAAgC;AAClC,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAEA,qBAAqB,MAAc,SAAS,OAAe;AACzD,UAAM,EAAE,UAAU,IAAI,KAAK;AAE3B,QAAI,aAAa,QAAQ;AACvB,aAAO,GAAG,IAAI,IAAI,SAAS;AAAA,IAC7B;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,mBAAmB,MAAc,aAAa,KAAK,SAAS,YAAoB;AAC9E,UAAM,EAAE,UAAU,IAAI,KAAK;AAC3B,QAAI,SAAS;AAEb,QAAI,aAAa,CAAC,KAAK,SAAS,SAAS,GAAG;AAC1C,eAAS,GAAG,MAAM,GAAG,SAAS;AAAA,IAChC;AAEA,aAAS,MAAM,SAAS,YAAY,MAAM;AAC1C,WAAO,OAAO,WAAW,GAAG,IAAI,SAAS,KAAK,MAAM;AAAA,EACtD;AAAA,EAEA,wBAAwB,MAAc,OAAO,KAAK,SAAS,WAAmB;AAC5E,WAAO,OAAO,GAAG,IAAI,IAAI,IAAI,KAAK;AAAA,EACpC;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,13 @@
1
+ import type { Statement } from 'typescript';
2
+ import type CodeConvertable from './CodeConvertable.js';
3
+ export type StatementRecord<T extends Statement> = readonly [path: string, declaration: T];
4
+ export default abstract class StatementRecordManager<T extends Statement> implements CodeConvertable<readonly T[]> {
5
+ #private;
6
+ static createComparator<T extends Statement>(collator: Intl.Collator): (recordA: StatementRecord<T>, recordB: StatementRecord<T>) => number;
7
+ ['constructor']: typeof StatementRecordManager;
8
+ constructor(collator: Intl.Collator);
9
+ abstract statementRecords(): IterableIterator<StatementRecord<T>>;
10
+ toCode(): readonly T[];
11
+ abstract clear(): void;
12
+ }
13
+ //# sourceMappingURL=StatementRecordManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StatementRecordManager.d.ts","sourceRoot":"","sources":["../src/dependencies/StatementRecordManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AAExD,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,SAAS,IAAI,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;AAE3F,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,sBAAsB,CAAC,CAAC,SAAS,SAAS,CAAE,YAAW,eAAe,CAAC,SAAS,CAAC,EAAE,CAAC;;IAChH,MAAM,CAAC,gBAAgB,CAAC,CAAC,SAAS,SAAS,EACzC,QAAQ,EAAE,IAAI,CAAC,QAAQ,GACtB,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,MAAM;IAc/D,CAAC,aAAa,CAAC,EAAE,OAAO,sBAAsB,CAAC;gBAG3C,QAAQ,EAAE,IAAI,CAAC,QAAQ;IAInC,QAAQ,CAAC,gBAAgB,IAAI,gBAAgB,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IAEjE,MAAM,IAAI,SAAS,CAAC,EAAE;IAOtB,QAAQ,CAAC,KAAK,IAAI,IAAI;CACvB"}
@@ -0,0 +1,26 @@
1
+ class StatementRecordManager {
2
+ static createComparator(collator) {
3
+ return ([pathA], [pathB]) => {
4
+ if (pathA.startsWith(".") && !pathB.startsWith(".")) {
5
+ return 1;
6
+ }
7
+ if (!pathA.startsWith(".") && pathB.startsWith(".")) {
8
+ return -1;
9
+ }
10
+ return collator.compare(pathA, pathB);
11
+ };
12
+ }
13
+ #collator;
14
+ constructor(collator) {
15
+ this.#collator = collator;
16
+ }
17
+ toCode() {
18
+ const records = [...this.statementRecords()];
19
+ records.sort(this.constructor.createComparator(this.#collator));
20
+ return records.map(([, statement]) => statement);
21
+ }
22
+ }
23
+ export {
24
+ StatementRecordManager as default
25
+ };
26
+ //# sourceMappingURL=StatementRecordManager.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/dependencies/StatementRecordManager.ts"],
4
+ "sourcesContent": ["import type { Statement } from 'typescript';\nimport type CodeConvertable from './CodeConvertable.js';\n\nexport type StatementRecord<T extends Statement> = readonly [path: string, declaration: T];\n\nexport default abstract class StatementRecordManager<T extends Statement> implements CodeConvertable<readonly T[]> {\n static createComparator<T extends Statement>(\n collator: Intl.Collator,\n ): (recordA: StatementRecord<T>, recordB: StatementRecord<T>) => number {\n return ([pathA], [pathB]) => {\n if (pathA.startsWith('.') && !pathB.startsWith('.')) {\n return 1;\n }\n\n if (!pathA.startsWith('.') && pathB.startsWith('.')) {\n return -1;\n }\n\n return collator.compare(pathA, pathB);\n };\n }\n\n declare ['constructor']: typeof StatementRecordManager;\n readonly #collator: Intl.Collator;\n\n constructor(collator: Intl.Collator) {\n this.#collator = collator;\n }\n\n abstract statementRecords(): IterableIterator<StatementRecord<T>>;\n\n toCode(): readonly T[] {\n const records = [...this.statementRecords()];\n records.sort(this.constructor.createComparator(this.#collator));\n\n return records.map(([, statement]) => statement);\n }\n\n abstract clear(): void;\n}\n"],
5
+ "mappings": "AAKA,MAAO,uBAA4G;AAAA,EACjH,OAAO,iBACL,UACsE;AACtE,WAAO,CAAC,CAAC,KAAK,GAAG,CAAC,KAAK,MAAM;AAC3B,UAAI,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,WAAW,GAAG,GAAG;AACnD,eAAO;AAAA,MACT;AAEA,UAAI,CAAC,MAAM,WAAW,GAAG,KAAK,MAAM,WAAW,GAAG,GAAG;AACnD,eAAO;AAAA,MACT;AAEA,aAAO,SAAS,QAAQ,OAAO,KAAK;AAAA,IACtC;AAAA,EACF;AAAA,EAGS;AAAA,EAET,YAAY,UAAyB;AACnC,SAAK,YAAY;AAAA,EACnB;AAAA,EAIA,SAAuB;AACrB,UAAM,UAAU,CAAC,GAAG,KAAK,iBAAiB,CAAC;AAC3C,YAAQ,KAAK,KAAK,YAAY,iBAAiB,KAAK,SAAS,CAAC;AAE9D,WAAO,QAAQ,IAAI,CAAC,CAAC,EAAE,SAAS,MAAM,SAAS;AAAA,EACjD;AAGF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ import type { Identifier } from 'typescript';
2
+ export type DependencyRecord = Readonly<{
3
+ id: Identifier;
4
+ isType: boolean;
5
+ }>;
6
+ export declare function createDependencyRecord(id: Identifier, isType?: boolean): DependencyRecord;
7
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/dependencies/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC;IACtC,EAAE,EAAE,UAAU,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC,CAAC;AAEH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,UAAU,EAAE,MAAM,UAAQ,GAAG,gBAAgB,CAKvF"}
@@ -0,0 +1,10 @@
1
+ function createDependencyRecord(id, isType = false) {
2
+ return {
3
+ id,
4
+ isType
5
+ };
6
+ }
7
+ export {
8
+ createDependencyRecord
9
+ };
10
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/dependencies/utils.ts"],
4
+ "sourcesContent": ["import type { Identifier } from 'typescript';\n\nexport type DependencyRecord = Readonly<{\n id: Identifier;\n isType: boolean;\n}>;\n\nexport function createDependencyRecord(id: Identifier, isType = false): DependencyRecord {\n return {\n id,\n isType,\n };\n}\n"],
5
+ "mappings": "AAOO,SAAS,uBAAuB,IAAgB,SAAS,OAAyB;AACvF,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
package/memoize.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export default function memoize<T>(func: () => T): () => T;
2
+ //# sourceMappingURL=memoize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memoize.d.ts","sourceRoot":"","sources":["src/memoize.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,CAWzD"}
package/memoize.js ADDED
@@ -0,0 +1,15 @@
1
+ function memoize(func) {
2
+ let result;
3
+ let hasResult = false;
4
+ return () => {
5
+ if (!hasResult) {
6
+ result = func();
7
+ hasResult = true;
8
+ }
9
+ return result;
10
+ };
11
+ }
12
+ export {
13
+ memoize as default
14
+ };
15
+ //# sourceMappingURL=memoize.js.map
package/memoize.js.map ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/memoize.ts"],
4
+ "sourcesContent": ["export default function memoize<T>(func: () => T): () => T {\n let result: T | undefined;\n let hasResult = false;\n\n return () => {\n if (!hasResult) {\n result = func();\n hasResult = true;\n }\n return result!;\n };\n}\n"],
5
+ "mappings": "AAAe,SAAR,QAA4B,MAAwB;AACzD,MAAI;AACJ,MAAI,YAAY;AAEhB,SAAO,MAAM;AACX,QAAI,CAAC,WAAW;AACd,eAAS,KAAK;AACd,kBAAY;AAAA,IACd;AACA,WAAO;AAAA,EACT;AACF;",
6
+ "names": []
7
+ }