@vaadin/hilla-generator-utils 24.7.0-alpha9 → 24.7.0-beta1

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 (54) hide show
  1. package/LoggerFactory.d.ts +7 -8
  2. package/LoggerFactory.js +24 -32
  3. package/LoggerFactory.js.map +1 -7
  4. package/PluginError.d.ts +1 -2
  5. package/PluginError.js +5 -8
  6. package/PluginError.js.map +1 -7
  7. package/ast.d.ts +1 -2
  8. package/ast.js +30 -39
  9. package/ast.js.map +1 -7
  10. package/createFullyUniqueIdentifier.d.ts +1 -2
  11. package/createFullyUniqueIdentifier.js +8 -11
  12. package/createFullyUniqueIdentifier.js.map +1 -7
  13. package/createSourceFile.d.ts +1 -2
  14. package/createSourceFile.js +5 -8
  15. package/createSourceFile.js.map +1 -7
  16. package/dependencies/CodeConvertable.d.ts +2 -2
  17. package/dependencies/DependencyManager.d.ts +7 -8
  18. package/dependencies/DependencyManager.js +10 -13
  19. package/dependencies/DependencyManager.js.map +1 -7
  20. package/dependencies/ExportManager.d.ts +33 -34
  21. package/dependencies/ExportManager.js +115 -136
  22. package/dependencies/ExportManager.js.map +1 -7
  23. package/dependencies/ImportManager.d.ts +45 -46
  24. package/dependencies/ImportManager.js +202 -232
  25. package/dependencies/ImportManager.js.map +1 -7
  26. package/dependencies/PathManager.d.ts +9 -10
  27. package/dependencies/PathManager.js +37 -43
  28. package/dependencies/PathManager.js.map +1 -7
  29. package/dependencies/StatementRecordManager.d.ts +9 -10
  30. package/dependencies/StatementRecordManager.js +22 -25
  31. package/dependencies/StatementRecordManager.js.map +1 -7
  32. package/dependencies/utils.d.ts +3 -4
  33. package/dependencies/utils.js +6 -9
  34. package/dependencies/utils.js.map +1 -7
  35. package/memoize.d.ts +0 -1
  36. package/memoize.js +11 -14
  37. package/memoize.js.map +1 -7
  38. package/package.json +7 -26
  39. package/testing/snapshotMatcher.d.ts +5 -6
  40. package/testing/snapshotMatcher.js +23 -29
  41. package/testing/snapshotMatcher.js.map +1 -7
  42. package/LoggerFactory.d.ts.map +0 -1
  43. package/PluginError.d.ts.map +0 -1
  44. package/ast.d.ts.map +0 -1
  45. package/createFullyUniqueIdentifier.d.ts.map +0 -1
  46. package/createSourceFile.d.ts.map +0 -1
  47. package/dependencies/DependencyManager.d.ts.map +0 -1
  48. package/dependencies/ExportManager.d.ts.map +0 -1
  49. package/dependencies/ImportManager.d.ts.map +0 -1
  50. package/dependencies/PathManager.d.ts.map +0 -1
  51. package/dependencies/StatementRecordManager.d.ts.map +0 -1
  52. package/dependencies/utils.d.ts.map +0 -1
  53. package/memoize.d.ts.map +0 -1
  54. package/testing/snapshotMatcher.d.ts.map +0 -1
@@ -1,238 +1,208 @@
1
- import ts, {} from "typescript";
1
+ import ts from "typescript";
2
2
  import createFullyUniqueIdentifier from "../createFullyUniqueIdentifier.js";
3
- import StatementRecordManager, {} from "./StatementRecordManager.js";
3
+ import StatementRecordManager from "./StatementRecordManager.js";
4
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
- get size() {
13
- return this.#map.size;
14
- }
15
- add(path, specifier, isType, uniqueId) {
16
- const record = createDependencyRecord(uniqueId ?? createFullyUniqueIdentifier(specifier), isType);
17
- if (this.#map.has(path)) {
18
- this.#map.get(path).set(specifier, record);
19
- } else {
20
- this.#map.set(path, /* @__PURE__ */ new Map([[specifier, record]]));
21
- }
22
- return record.id;
23
- }
24
- remove(path, specifier) {
25
- const specifiers = this.#map.get(path);
26
- if (specifiers) {
27
- specifiers.delete(specifier);
28
- if (specifiers.size === 0) {
29
- this.#map.delete(path);
30
- }
31
- }
32
- }
33
- clear() {
34
- this.#map.clear();
35
- }
36
- getIdentifier(path, specifier) {
37
- return this.#map.get(path)?.get(specifier)?.id;
38
- }
39
- iter() {
40
- return this[Symbol.iterator]();
41
- }
42
- isType(path, specifier) {
43
- return this.#map.get(path)?.get(specifier)?.isType;
44
- }
45
- paths() {
46
- return this.#map.keys();
47
- }
48
- *specifiers() {
49
- for (const [path, specifiers] of this.#map) {
50
- for (const specifier of specifiers.keys()) {
51
- yield [path, specifier];
52
- }
53
- }
54
- }
55
- *statementRecords() {
56
- for (const [path, specifiers] of this.#map) {
57
- const names = [...specifiers.keys()];
58
- names.sort(this.#collator.compare);
59
- const isTypeOnly = names.every((name) => specifiers.get(name).isType);
60
- yield [
61
- path,
62
- ts.factory.createImportDeclaration(
63
- void 0,
64
- ts.factory.createImportClause(
65
- isTypeOnly,
66
- void 0,
67
- ts.factory.createNamedImports(
68
- names.map((name) => {
69
- const { id, isType } = specifiers.get(name);
70
- return ts.factory.createImportSpecifier(
71
- isTypeOnly ? false : isType,
72
- ts.factory.createIdentifier(name),
73
- id
74
- );
75
- })
76
- )
77
- ),
78
- ts.factory.createStringLiteral(path)
79
- )
80
- ];
81
- }
82
- }
83
- *[Symbol.iterator]() {
84
- for (const [path, specifiers] of this.#map) {
85
- for (const [specifier, { id, isType }] of specifiers) {
86
- yield [path, specifier, id, isType];
87
- }
88
- }
89
- }
5
+ export class NamedImportManager extends StatementRecordManager {
6
+ #collator;
7
+ #map = new Map();
8
+ constructor(collator) {
9
+ super(collator);
10
+ this.#collator = collator;
11
+ }
12
+ get size() {
13
+ return this.#map.size;
14
+ }
15
+ add(path, specifier, isType, uniqueId) {
16
+ const record = createDependencyRecord(uniqueId ?? createFullyUniqueIdentifier(specifier), isType);
17
+ if (this.#map.has(path)) {
18
+ this.#map.get(path).set(specifier, record);
19
+ } else {
20
+ this.#map.set(path, new Map([[specifier, record]]));
21
+ }
22
+ return record.id;
23
+ }
24
+ remove(path, specifier) {
25
+ const specifiers = this.#map.get(path);
26
+ if (specifiers) {
27
+ specifiers.delete(specifier);
28
+ if (specifiers.size === 0) {
29
+ this.#map.delete(path);
30
+ }
31
+ }
32
+ }
33
+ clear() {
34
+ this.#map.clear();
35
+ }
36
+ getIdentifier(path, specifier) {
37
+ return this.#map.get(path)?.get(specifier)?.id;
38
+ }
39
+ iter() {
40
+ return this[Symbol.iterator]();
41
+ }
42
+ isType(path, specifier) {
43
+ return this.#map.get(path)?.get(specifier)?.isType;
44
+ }
45
+ paths() {
46
+ return this.#map.keys();
47
+ }
48
+ *specifiers() {
49
+ for (const [path, specifiers] of this.#map) {
50
+ for (const specifier of specifiers.keys()) {
51
+ yield [path, specifier];
52
+ }
53
+ }
54
+ }
55
+ *statementRecords() {
56
+ for (const [path, specifiers] of this.#map) {
57
+ const names = [...specifiers.keys()];
58
+ names.sort(this.#collator.compare);
59
+ const isTypeOnly = names.every((name) => specifiers.get(name).isType);
60
+ yield [path, ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(isTypeOnly, undefined, ts.factory.createNamedImports(names.map((name) => {
61
+ const { id, isType } = specifiers.get(name);
62
+ return ts.factory.createImportSpecifier(isTypeOnly ? false : isType, ts.factory.createIdentifier(name), id);
63
+ }))), ts.factory.createStringLiteral(path))];
64
+ }
65
+ }
66
+ *[Symbol.iterator]() {
67
+ for (const [path, specifiers] of this.#map) {
68
+ for (const [specifier, { id, isType }] of specifiers) {
69
+ yield [
70
+ path,
71
+ specifier,
72
+ id,
73
+ isType
74
+ ];
75
+ }
76
+ }
77
+ }
90
78
  }
91
- class NamespaceImportManager extends StatementRecordManager {
92
- #map = /* @__PURE__ */ new Map();
93
- get size() {
94
- return this.#map.size;
95
- }
96
- add(path, name, uniqueId) {
97
- const id = uniqueId ?? createFullyUniqueIdentifier(name);
98
- this.#map.set(path, id);
99
- return id;
100
- }
101
- clear() {
102
- this.#map.clear();
103
- }
104
- getIdentifier(path) {
105
- return this.#map.get(path);
106
- }
107
- iter() {
108
- return this[Symbol.iterator]();
109
- }
110
- paths() {
111
- return this.#map.keys();
112
- }
113
- *statementRecords() {
114
- for (const [path, id] of this.#map) {
115
- yield [
116
- path,
117
- ts.factory.createImportDeclaration(
118
- void 0,
119
- ts.factory.createImportClause(false, void 0, ts.factory.createNamespaceImport(id)),
120
- ts.factory.createStringLiteral(path)
121
- )
122
- ];
123
- }
124
- }
125
- remove(path) {
126
- this.#map.delete(path);
127
- }
128
- *[Symbol.iterator]() {
129
- for (const [path, id] of this.#map) {
130
- yield [path, id];
131
- }
132
- }
79
+ export class NamespaceImportManager extends StatementRecordManager {
80
+ #map = new Map();
81
+ get size() {
82
+ return this.#map.size;
83
+ }
84
+ add(path, name, uniqueId) {
85
+ const id = uniqueId ?? createFullyUniqueIdentifier(name);
86
+ this.#map.set(path, id);
87
+ return id;
88
+ }
89
+ clear() {
90
+ this.#map.clear();
91
+ }
92
+ getIdentifier(path) {
93
+ return this.#map.get(path);
94
+ }
95
+ iter() {
96
+ return this[Symbol.iterator]();
97
+ }
98
+ paths() {
99
+ return this.#map.keys();
100
+ }
101
+ *statementRecords() {
102
+ for (const [path, id] of this.#map) {
103
+ yield [path, ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(false, undefined, ts.factory.createNamespaceImport(id)), ts.factory.createStringLiteral(path))];
104
+ }
105
+ }
106
+ remove(path) {
107
+ this.#map.delete(path);
108
+ }
109
+ *[Symbol.iterator]() {
110
+ for (const [path, id] of this.#map) {
111
+ yield [path, id];
112
+ }
113
+ }
133
114
  }
134
- class DefaultImportManager extends StatementRecordManager {
135
- #map = /* @__PURE__ */ new Map();
136
- get size() {
137
- return this.#map.size;
138
- }
139
- add(path, name, isType, uniqueId) {
140
- const id = uniqueId ?? createFullyUniqueIdentifier(name);
141
- this.#map.set(path, createDependencyRecord(id, isType));
142
- return id;
143
- }
144
- getIdentifier(path) {
145
- return this.#map.get(path)?.id;
146
- }
147
- remove(path) {
148
- if (this.#map.has(path)) {
149
- this.#map.delete(path);
150
- }
151
- }
152
- clear() {
153
- this.#map.clear();
154
- }
155
- iter() {
156
- return this[Symbol.iterator]();
157
- }
158
- isType(path) {
159
- return this.#map.get(path)?.isType;
160
- }
161
- paths() {
162
- return this.#map.keys();
163
- }
164
- *statementRecords() {
165
- for (const [path, { id, isType }] of this.#map) {
166
- yield [
167
- path,
168
- ts.factory.createImportDeclaration(
169
- void 0,
170
- ts.factory.createImportClause(isType, id, void 0),
171
- ts.factory.createStringLiteral(path)
172
- )
173
- ];
174
- }
175
- }
176
- *[Symbol.iterator]() {
177
- for (const [path, { id, isType }] of this.#map) {
178
- yield [path, id, isType];
179
- }
180
- }
115
+ export class DefaultImportManager extends StatementRecordManager {
116
+ #map = new Map();
117
+ get size() {
118
+ return this.#map.size;
119
+ }
120
+ add(path, name, isType, uniqueId) {
121
+ const id = uniqueId ?? createFullyUniqueIdentifier(name);
122
+ this.#map.set(path, createDependencyRecord(id, isType));
123
+ return id;
124
+ }
125
+ getIdentifier(path) {
126
+ return this.#map.get(path)?.id;
127
+ }
128
+ remove(path) {
129
+ if (this.#map.has(path)) {
130
+ this.#map.delete(path);
131
+ }
132
+ }
133
+ clear() {
134
+ this.#map.clear();
135
+ }
136
+ iter() {
137
+ return this[Symbol.iterator]();
138
+ }
139
+ isType(path) {
140
+ return this.#map.get(path)?.isType;
141
+ }
142
+ paths() {
143
+ return this.#map.keys();
144
+ }
145
+ *statementRecords() {
146
+ for (const [path, { id, isType }] of this.#map) {
147
+ yield [path, ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(isType, id, undefined), ts.factory.createStringLiteral(path))];
148
+ }
149
+ }
150
+ *[Symbol.iterator]() {
151
+ for (const [path, { id, isType }] of this.#map) {
152
+ yield [
153
+ path,
154
+ id,
155
+ isType
156
+ ];
157
+ }
158
+ }
181
159
  }
182
- class ImportManager {
183
- default;
184
- named;
185
- namespace;
186
- #collator;
187
- constructor(collator) {
188
- this.default = new DefaultImportManager(collator);
189
- this.named = new NamedImportManager(collator);
190
- this.namespace = new NamespaceImportManager(collator);
191
- this.#collator = collator;
192
- }
193
- get size() {
194
- return this.default.size + this.named.size + this.namespace.size;
195
- }
196
- toCode() {
197
- const records = [
198
- ...this.default.statementRecords(),
199
- ...this.named.statementRecords(),
200
- ...this.namespace.statementRecords()
201
- ];
202
- records.sort(StatementRecordManager.createComparator(this.#collator));
203
- return records.map(([, statement]) => statement);
204
- }
205
- fromCode(source) {
206
- this.default.clear();
207
- this.named.clear();
208
- this.namespace.clear();
209
- const imports = source.statements.filter(
210
- (statement) => ts.isImportDeclaration(statement)
211
- );
212
- for (const { importClause, moduleSpecifier } of imports) {
213
- if (!importClause) {
214
- continue;
215
- }
216
- const { name, namedBindings } = importClause;
217
- const path = moduleSpecifier.text;
218
- if (namedBindings) {
219
- if (ts.isNamespaceImport(namedBindings)) {
220
- this.namespace.add(path, namedBindings.name.text, namedBindings.name);
221
- } else {
222
- for (const { isTypeOnly, name: specifier } of namedBindings.elements) {
223
- this.named.add(path, specifier.text, isTypeOnly, specifier);
224
- }
225
- }
226
- } else if (name) {
227
- this.default.add(path, name.text, importClause.isTypeOnly, name);
228
- }
229
- }
230
- }
160
+ export default class ImportManager {
161
+ default;
162
+ named;
163
+ namespace;
164
+ #collator;
165
+ constructor(collator) {
166
+ this.default = new DefaultImportManager(collator);
167
+ this.named = new NamedImportManager(collator);
168
+ this.namespace = new NamespaceImportManager(collator);
169
+ this.#collator = collator;
170
+ }
171
+ get size() {
172
+ return this.default.size + this.named.size + this.namespace.size;
173
+ }
174
+ toCode() {
175
+ const records = [
176
+ ...this.default.statementRecords(),
177
+ ...this.named.statementRecords(),
178
+ ...this.namespace.statementRecords()
179
+ ];
180
+ records.sort(StatementRecordManager.createComparator(this.#collator));
181
+ return records.map(([, statement]) => statement);
182
+ }
183
+ fromCode(source) {
184
+ this.default.clear();
185
+ this.named.clear();
186
+ this.namespace.clear();
187
+ const imports = source.statements.filter((statement) => ts.isImportDeclaration(statement));
188
+ for (const { importClause, moduleSpecifier } of imports) {
189
+ if (!importClause) {
190
+ continue;
191
+ }
192
+ const { name, namedBindings } = importClause;
193
+ const path = moduleSpecifier.text;
194
+ if (namedBindings) {
195
+ if (ts.isNamespaceImport(namedBindings)) {
196
+ this.namespace.add(path, namedBindings.name.text, namedBindings.name);
197
+ } else {
198
+ for (const { isTypeOnly, name: specifier } of namedBindings.elements) {
199
+ this.named.add(path, specifier.text, isTypeOnly, specifier);
200
+ }
201
+ }
202
+ } else if (name) {
203
+ this.default.add(path, name.text, importClause.isTypeOnly, name);
204
+ }
205
+ }
206
+ }
231
207
  }
232
- export {
233
- DefaultImportManager,
234
- NamedImportManager,
235
- NamespaceImportManager,
236
- ImportManager as default
237
- };
238
- //# sourceMappingURL=ImportManager.js.map
208
+ //# sourceMappingURL=./ImportManager.js.map
@@ -1,7 +1 @@
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 get size(): number {\n return this.#map.size;\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 remove(path: string, specifier: string): void {\n const specifiers = this.#map.get(path);\n\n if (specifiers) {\n specifiers.delete(specifier);\n\n if (specifiers.size === 0) {\n this.#map.delete(path);\n }\n }\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 iter(): IterableIterator<readonly [path: string, specifier: string, id: Identifier, isType: boolean]> {\n return this[Symbol.iterator]();\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 const isTypeOnly = names.every((name) => specifiers.get(name)!.isType);\n\n yield [\n path,\n ts.factory.createImportDeclaration(\n undefined,\n ts.factory.createImportClause(\n isTypeOnly,\n undefined,\n ts.factory.createNamedImports(\n names.map((name) => {\n const { id, isType } = specifiers.get(name)!;\n return ts.factory.createImportSpecifier(\n isTypeOnly ? false : isType,\n ts.factory.createIdentifier(name),\n id,\n );\n }),\n ),\n ),\n ts.factory.createStringLiteral(path),\n ),\n ];\n }\n }\n\n *[Symbol.iterator](): 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\nexport class NamespaceImportManager extends StatementRecordManager<ImportDeclaration> {\n readonly #map = new Map<string, Identifier>();\n\n get size(): number {\n return this.#map.size;\n }\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 iter(): IterableIterator<readonly [path: string, id: Identifier]> {\n return this[Symbol.iterator]();\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 remove(path: string): void {\n this.#map.delete(path);\n }\n\n *[Symbol.iterator](): IterableIterator<readonly [path: string, id: Identifier]> {\n for (const [path, id] of this.#map) {\n yield [path, id];\n }\n }\n}\n\nexport class DefaultImportManager extends StatementRecordManager<ImportDeclaration> {\n readonly #map = new Map<string, DependencyRecord>();\n\n get size(): number {\n return this.#map.size;\n }\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 remove(path: string): void {\n if (this.#map.has(path)) {\n this.#map.delete(path);\n }\n }\n\n override clear(): void {\n this.#map.clear();\n }\n\n iter(): IterableIterator<readonly [path: string, id: Identifier, isType: boolean]> {\n return this[Symbol.iterator]();\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 *[Symbol.iterator](): IterableIterator<readonly [path: string, id: Identifier, isType: boolean]> {\n for (const [path, { id, isType }] of this.#map) {\n yield [path, id, isType];\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 get size(): number {\n return this.default.size + this.named.size + this.namespace.size;\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,OAAe;AACjB,WAAO,KAAK,KAAK;AAAA,EACnB;AAAA,EAEA,IAAI,MAAc,WAAmB,QAAkB,UAAmC;AACxF,UAAM,SAAS,uBAAuB,YAAY,4BAA4B,SAAS,GAAG,MAAM;AAEhG,QAAI,KAAK,KAAK,IAAI,I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UAAU;GACd,GAAG,KAAK,QAAQ,kBAAkB;GAClC,GAAG,KAAK,MAAM,kBAAkB;GAChC,GAAG,KAAK,UAAU,kBAAkB;EACrC;AACD,UAAQ,KAAK,uBAAuB,iBAAiB,KAAKA,UAAU,CAAC;AAErE,SAAO,QAAQ,IAAI,CAAC,GAAG,UAAU,KAAK,UAAU;CACjD;CAED,SAASQ,QAA6B;AACpC,OAAK,QAAQ,OAAO;AACpB,OAAK,MAAM,OAAO;AAClB,OAAK,UAAU,OAAO;EAEtB,MAAM,UAAU,OAAO,WAAW,OAAO,CAAC,cACxC,GAAG,oBAAoB,UAAU,CAClC;AAED,OAAK,MAAM,EAAE,cAAc,iBAAiB,IAAI,SAAS;AACvD,QAAK,cAAc;AAEjB;GACD;GAED,MAAM,EAAE,MAAM,eAAe,GAAG;GAChC,MAAM,OAAQ,gBAAqC;AAEnD,OAAI,eAAe;AACjB,QAAI,GAAG,kBAAkB,cAAc,EAAE;AACvC,UAAK,UAAU,IAAI,MAAM,cAAc,KAAK,MAAM,cAAc,KAAK;IACtE,OAAM;AACL,UAAK,MAAM,EAAE,YAAY,MAAM,WAAW,IAAI,cAAc,UAAU;AACpE,WAAK,MAAM,IAAI,MAAM,UAAU,MAAM,YAAY,UAAU;KAC5D;IACF;GACF,WAAU,MAAM;AACf,SAAK,QAAQ,IAAI,MAAM,KAAK,MAAM,aAAa,YAAY,KAAK;GACjE;EACF;CACF;AACF","names":["#collator","#map","collator: Intl.Collator","path: string","specifier: string","isType?: boolean","uniqueId?: Identifier","name: string","source: ts.SourceFile"],"sources":["/opt/agent/work/1af72d8adc613024/hilla/packages/ts/generator-utils/src/dependencies/ImportManager.ts"],"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 get size(): number {\n return this.#map.size;\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 remove(path: string, specifier: string): void {\n const specifiers = this.#map.get(path);\n\n if (specifiers) {\n specifiers.delete(specifier);\n\n if (specifiers.size === 0) {\n this.#map.delete(path);\n }\n }\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 iter(): IterableIterator<readonly [path: string, specifier: string, id: Identifier, isType: boolean]> {\n return this[Symbol.iterator]();\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 const isTypeOnly = names.every((name) => specifiers.get(name)!.isType);\n\n yield [\n path,\n ts.factory.createImportDeclaration(\n undefined,\n ts.factory.createImportClause(\n isTypeOnly,\n undefined,\n ts.factory.createNamedImports(\n names.map((name) => {\n const { id, isType } = specifiers.get(name)!;\n return ts.factory.createImportSpecifier(\n isTypeOnly ? false : isType,\n ts.factory.createIdentifier(name),\n id,\n );\n }),\n ),\n ),\n ts.factory.createStringLiteral(path),\n ),\n ];\n }\n }\n\n *[Symbol.iterator](): 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\nexport class NamespaceImportManager extends StatementRecordManager<ImportDeclaration> {\n readonly #map = new Map<string, Identifier>();\n\n get size(): number {\n return this.#map.size;\n }\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 iter(): IterableIterator<readonly [path: string, id: Identifier]> {\n return this[Symbol.iterator]();\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 remove(path: string): void {\n this.#map.delete(path);\n }\n\n *[Symbol.iterator](): IterableIterator<readonly [path: string, id: Identifier]> {\n for (const [path, id] of this.#map) {\n yield [path, id];\n }\n }\n}\n\nexport class DefaultImportManager extends StatementRecordManager<ImportDeclaration> {\n readonly #map = new Map<string, DependencyRecord>();\n\n get size(): number {\n return this.#map.size;\n }\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 remove(path: string): void {\n if (this.#map.has(path)) {\n this.#map.delete(path);\n }\n }\n\n override clear(): void {\n this.#map.clear();\n }\n\n iter(): IterableIterator<readonly [path: string, id: Identifier, isType: boolean]> {\n return this[Symbol.iterator]();\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 *[Symbol.iterator](): IterableIterator<readonly [path: string, id: Identifier, isType: boolean]> {\n for (const [path, { id, isType }] of this.#map) {\n yield [path, id, isType];\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 get size(): number {\n return this.default.size + this.named.size + this.namespace.size;\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"],"version":3}
@@ -1,14 +1,13 @@
1
1
  export type PathManagerOptions = Readonly<{
2
- aliasRoot?: string;
3
- extension?: string;
4
- relativeTo?: URL | string;
2
+ aliasRoot?: string
3
+ extension?: string
4
+ relativeTo?: URL | string
5
5
  }>;
6
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: URL | string, fileExtension?: string, relativeTo?: string | URL): string;
12
- createTSAliasModulePath(path: string, root?: string | undefined): string;
7
+ #private;
8
+ constructor(options?: PathManagerOptions);
9
+ get aliasRoot(): string | undefined;
10
+ createBareModulePath(path: string, isFile?: boolean): string;
11
+ createRelativePath(path: URL | string, fileExtension?: string, relativeTo?: string | URL): string;
12
+ createTSAliasModulePath(path: string, root?: string | undefined): string;
13
13
  }
14
- //# sourceMappingURL=PathManager.d.ts.map
@@ -1,46 +1,40 @@
1
1
  import { basename, dirname, posix, relative, sep } from "node:path";
2
2
  import { fileURLToPath } from "node:url";
3
- class PathManager {
4
- #options;
5
- constructor(options) {
6
- let extension;
7
- if (options?.extension) {
8
- extension = options.extension.startsWith(".") ? options.extension : `.${options.extension}`;
9
- }
10
- this.#options = {
11
- ...options,
12
- extension,
13
- relativeTo: options?.relativeTo ?? "."
14
- };
15
- }
16
- get aliasRoot() {
17
- return this.#options.aliasRoot;
18
- }
19
- createBareModulePath(path, isFile = false) {
20
- const { extension } = this.#options;
21
- if (extension && isFile) {
22
- return `${path}.${extension}`;
23
- }
24
- return path;
25
- }
26
- createRelativePath(path, fileExtension, relativeTo = this.#options.relativeTo) {
27
- const { extension } = this.#options;
28
- const _path = path instanceof URL ? fileURLToPath(path) : path;
29
- let result = _path;
30
- if (extension && !_path.endsWith(extension)) {
31
- result = `${dirname(result)}/${basename(result, fileExtension)}${extension}`;
32
- }
33
- result = relative(relativeTo instanceof URL ? fileURLToPath(relativeTo) : relativeTo, result).replaceAll(
34
- sep,
35
- posix.sep
36
- );
37
- return result.startsWith(".") ? result : `./${result}`;
38
- }
39
- createTSAliasModulePath(path, root = this.#options.aliasRoot) {
40
- return root ? `${root}/${path}` : path;
41
- }
3
+ export default class PathManager {
4
+ #options;
5
+ constructor(options) {
6
+ let extension;
7
+ if (options?.extension) {
8
+ extension = options.extension.startsWith(".") ? options.extension : `.${options.extension}`;
9
+ }
10
+ this.#options = {
11
+ ...options,
12
+ extension,
13
+ relativeTo: options?.relativeTo ?? "."
14
+ };
15
+ }
16
+ get aliasRoot() {
17
+ return this.#options.aliasRoot;
18
+ }
19
+ createBareModulePath(path, isFile = false) {
20
+ const { extension } = this.#options;
21
+ if (extension && isFile) {
22
+ return `${path}.${extension}`;
23
+ }
24
+ return path;
25
+ }
26
+ createRelativePath(path, fileExtension, relativeTo = this.#options.relativeTo) {
27
+ const { extension } = this.#options;
28
+ const _path = path instanceof URL ? fileURLToPath(path) : path;
29
+ let result = _path;
30
+ if (extension && !_path.endsWith(extension)) {
31
+ result = `${dirname(result)}/${basename(result, fileExtension)}${extension}`;
32
+ }
33
+ result = relative(relativeTo instanceof URL ? fileURLToPath(relativeTo) : relativeTo, result).replaceAll(sep, posix.sep);
34
+ return result.startsWith(".") ? result : `./${result}`;
35
+ }
36
+ createTSAliasModulePath(path, root = this.#options.aliasRoot) {
37
+ return root ? `${root}/${path}` : path;
38
+ }
42
39
  }
43
- export {
44
- PathManager as default
45
- };
46
- //# sourceMappingURL=PathManager.js.map
40
+ //# sourceMappingURL=./PathManager.js.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/dependencies/PathManager.ts"],
4
- "sourcesContent": ["import { basename, dirname, posix, relative, sep } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { SetRequired } from 'type-fest';\n\nexport type PathManagerOptions = Readonly<{\n aliasRoot?: string;\n extension?: string;\n relativeTo?: URL | 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: URL | string, fileExtension?: string, relativeTo = this.#options.relativeTo): string {\n const { extension } = this.#options;\n const _path = path instanceof URL ? fileURLToPath(path) : path;\n let result = _path;\n\n if (extension && !_path.endsWith(extension)) {\n result = `${dirname(result)}/${basename(result, fileExtension)}${extension}`;\n }\n\n result = relative(relativeTo instanceof URL ? fileURLToPath(relativeTo) : relativeTo, result).replaceAll(\n sep,\n posix.sep,\n );\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,UAAU,SAAS,OAAO,UAAU,WAAW;AACxD,SAAS,qBAAqB;AAS9B,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,S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AAE,WAAW,GAAG,KAAKH;AAE3B,MAAI,aAAa,QAAQ;AACvB,WAAQ,EAAE,KAAK,GAAG,UAAU;EAC7B;AAED,SAAO;CACR;CAED,mBACEI,MACAC,eACAC,aAA2B,KAAKN,SAAS,YACjC;EACR,MAAM,EAAE,WAAW,GAAG,KAAKA;EAC3B,MAAM,QAAQ,gBAAgB,MAAM,cAAc,KAAK,GAAG;EAC1D,IAAI,SAAS;AAEb,MAAI,cAAc,MAAM,SAAS,UAAU,EAAE;AAC3C,aAAU,EAAE,QAAQ,OAAO,CAAC,GAAG,SAAS,QAAQ,cAAc,CAAC,EAAE,UAAU;EAC5E;AAED,WAAS,SAAS,sBAAsB,MAAM,cAAc,WAAW,GAAG,YAAY,OAAO,CAAC,WAC5F,KACA,MAAM,IACP;AACD,SAAO,OAAO,WAAW,IAAI,GAAG,UAAU,IAAI,OAAO;CACtD;CAED,wBAAwBG,MAAcI,OAA2B,KAAKP,SAAS,WAAmB;AAChG,SAAO,QAAQ,EAAE,KAAK,GAAG,KAAK,IAAI;CACnC;AACF","names":["#options","options?: PathManagerOptions","extension: string | undefined","path: string","path: URL | string","fileExtension?: string","relativeTo: string | URL","root: string | undefined"],"sources":["/opt/agent/work/1af72d8adc613024/hilla/packages/ts/generator-utils/src/dependencies/PathManager.ts"],"sourcesContent":["import { basename, dirname, posix, relative, sep } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { SetRequired } from 'type-fest';\n\nexport type PathManagerOptions = Readonly<{\n aliasRoot?: string;\n extension?: string;\n relativeTo?: URL | 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(\n path: URL | string,\n fileExtension?: string,\n relativeTo: string | URL = this.#options.relativeTo,\n ): string {\n const { extension } = this.#options;\n const _path = path instanceof URL ? fileURLToPath(path) : path;\n let result = _path;\n\n if (extension && !_path.endsWith(extension)) {\n result = `${dirname(result)}/${basename(result, fileExtension)}${extension}`;\n }\n\n result = relative(relativeTo instanceof URL ? fileURLToPath(relativeTo) : relativeTo, result).replaceAll(\n sep,\n posix.sep,\n );\n return result.startsWith('.') ? result : `./${result}`;\n }\n\n createTSAliasModulePath(path: string, root: string | undefined = this.#options.aliasRoot): string {\n return root ? `${root}/${path}` : path;\n }\n}\n"],"version":3}