@vaadin/hilla-generator-utils 24.4.6 → 24.5.0-alpha10

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/ast.d.ts CHANGED
@@ -3,4 +3,5 @@ export type TemplateSelector<T> = (statements: readonly Statement[]) => T;
3
3
  export declare function template(code: string, transformers?: ReadonlyArray<TransformerFactory<SourceFile>>): readonly Statement[];
4
4
  export declare function template<T>(code: string, selector: TemplateSelector<T>, transformers?: ReadonlyArray<TransformerFactory<SourceFile>>): T;
5
5
  export declare function transform<T extends Node>(transformer: (node: Node) => VisitResult<Node | undefined>): TransformerFactory<T>;
6
+ export declare function traverse<T extends Node>(node: Node, visitor: (node: Node) => T | undefined): T | undefined;
6
7
  //# sourceMappingURL=ast.d.ts.map
package/ast.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["src/ast.ts"],"names":[],"mappings":"AAAA,OAAW,EACT,KAAK,IAAI,EACT,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,SAAS,EAEd,KAAK,kBAAkB,EACxB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,KAAK,CAAC,CAAC;AAE1E,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,aAAa,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC,GAC3D,SAAS,SAAS,EAAE,CAAC;AACxB,wBAAgB,QAAQ,CAAC,CAAC,EACxB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAC7B,YAAY,CAAC,EAAE,aAAa,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC,GAC3D,CAAC,CAAC;AA2BL,wBAAgB,SAAS,CAAC,CAAC,SAAS,IAAI,EACtC,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,WAAW,CAAC,IAAI,GAAG,SAAS,CAAC,GACzD,kBAAkB,CAAC,CAAC,CAAC,CAavB"}
1
+ {"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["src/ast.ts"],"names":[],"mappings":"AAAA,OAAW,EACT,KAAK,IAAI,EACT,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,SAAS,EAEd,KAAK,kBAAkB,EACxB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,KAAK,CAAC,CAAC;AAE1E,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,aAAa,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC,GAC3D,SAAS,SAAS,EAAE,CAAC;AACxB,wBAAgB,QAAQ,CAAC,CAAC,EACxB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAC7B,YAAY,CAAC,EAAE,aAAa,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC,GAC3D,CAAC,CAAC;AA2BL,wBAAgB,SAAS,CAAC,CAAC,SAAS,IAAI,EACtC,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,WAAW,CAAC,IAAI,GAAG,SAAS,CAAC,GACzD,kBAAkB,CAAC,CAAC,CAAC,CAavB;AAED,wBAAgB,QAAQ,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC,GAAG,SAAS,GAAG,CAAC,GAAG,SAAS,CAM1G"}
package/ast.js CHANGED
@@ -28,8 +28,15 @@ function transform(transformer) {
28
28
  return ts.visitEachChild(root, visitor, context);
29
29
  };
30
30
  }
31
+ function traverse(node, visitor) {
32
+ function _visitor(n) {
33
+ return visitor(n) ?? ts.forEachChild(n, _visitor);
34
+ }
35
+ return _visitor(node);
36
+ }
31
37
  export {
32
38
  template,
33
- transform
39
+ transform,
40
+ traverse
34
41
  };
35
42
  //# sourceMappingURL=ast.js.map
package/ast.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["src/ast.ts"],
4
- "sourcesContent": ["import ts, {\n type Node,\n type VisitResult,\n type SourceFile,\n type Statement,\n type TransformationContext,\n type TransformerFactory,\n} from 'typescript';\n\nexport type TemplateSelector<T> = (statements: readonly Statement[]) => T;\n\nexport function template(\n code: string,\n transformers?: ReadonlyArray<TransformerFactory<SourceFile>>,\n): readonly Statement[];\nexport function template<T>(\n code: string,\n selector: TemplateSelector<T>,\n transformers?: ReadonlyArray<TransformerFactory<SourceFile>>,\n): T;\nexport function template<T>(\n code: string,\n selectorOrTransformers?: ReadonlyArray<TransformerFactory<SourceFile>> | TemplateSelector<T>,\n transformers?: ReadonlyArray<TransformerFactory<SourceFile>>,\n): T | readonly Statement[] {\n let selector: TemplateSelector<T> | undefined;\n\n if (Array.isArray(selectorOrTransformers)) {\n // eslint-disable-next-line no-param-reassign\n transformers = selectorOrTransformers;\n } else {\n selector = selectorOrTransformers as TemplateSelector<T>;\n }\n\n let sourceFile = ts.createSourceFile('f.ts', code, ts.ScriptTarget.Latest, false);\n\n if (transformers) {\n [sourceFile] = ts.transform<SourceFile>(\n sourceFile,\n transformers as Array<TransformerFactory<SourceFile>>,\n ).transformed;\n }\n\n return selector?.(sourceFile.statements) ?? sourceFile.statements;\n}\n\nexport function transform<T extends Node>(\n transformer: (node: Node) => VisitResult<Node | undefined>,\n): TransformerFactory<T> {\n return (context: TransformationContext) => (root: T) => {\n const visitor = (node: Node): VisitResult<Node | undefined> => {\n const transformed = transformer(node);\n\n if (transformed !== node) {\n return transformed;\n }\n\n return ts.visitEachChild(transformed, visitor, context);\n };\n return ts.visitEachChild(root, visitor, context);\n };\n}\n"],
5
- "mappings": "AAAA,OAAO;AAAA,OAOA;AAaA,SAAS,SACd,MACA,wBACA,cAC0B;AAC1B,MAAI;AAEJ,MAAI,MAAM,QAAQ,sBAAsB,GAAG;AAEzC,mBAAe;AAAA,EACjB,OAAO;AACL,eAAW;AAAA,EACb;AAEA,MAAI,aAAa,GAAG,iBAAiB,QAAQ,MAAM,GAAG,aAAa,QAAQ,KAAK;AAEhF,MAAI,cAAc;AAChB,KAAC,UAAU,IAAI,GAAG;AAAA,MAChB;AAAA,MACA;AAAA,IACF,EAAE;AAAA,EACJ;AAEA,SAAO,WAAW,WAAW,UAAU,KAAK,WAAW;AACzD;AAEO,SAAS,UACd,aACuB;AACvB,SAAO,CAAC,YAAmC,CAAC,SAAY;AACtD,UAAM,UAAU,CAAC,SAA8C;AAC7D,YAAM,cAAc,YAAY,IAAI;AAEpC,UAAI,gBAAgB,MAAM;AACxB,eAAO;AAAA,MACT;AAEA,aAAO,GAAG,eAAe,aAAa,SAAS,OAAO;AAAA,IACxD;AACA,WAAO,GAAG,eAAe,MAAM,SAAS,OAAO;AAAA,EACjD;AACF;",
4
+ "sourcesContent": ["import ts, {\n type Node,\n type VisitResult,\n type SourceFile,\n type Statement,\n type TransformationContext,\n type TransformerFactory,\n} from 'typescript';\n\nexport type TemplateSelector<T> = (statements: readonly Statement[]) => T;\n\nexport function template(\n code: string,\n transformers?: ReadonlyArray<TransformerFactory<SourceFile>>,\n): readonly Statement[];\nexport function template<T>(\n code: string,\n selector: TemplateSelector<T>,\n transformers?: ReadonlyArray<TransformerFactory<SourceFile>>,\n): T;\nexport function template<T>(\n code: string,\n selectorOrTransformers?: ReadonlyArray<TransformerFactory<SourceFile>> | TemplateSelector<T>,\n transformers?: ReadonlyArray<TransformerFactory<SourceFile>>,\n): T | readonly Statement[] {\n let selector: TemplateSelector<T> | undefined;\n\n if (Array.isArray(selectorOrTransformers)) {\n // eslint-disable-next-line no-param-reassign\n transformers = selectorOrTransformers;\n } else {\n selector = selectorOrTransformers as TemplateSelector<T>;\n }\n\n let sourceFile = ts.createSourceFile('f.ts', code, ts.ScriptTarget.Latest, false);\n\n if (transformers) {\n [sourceFile] = ts.transform<SourceFile>(\n sourceFile,\n transformers as Array<TransformerFactory<SourceFile>>,\n ).transformed;\n }\n\n return selector?.(sourceFile.statements) ?? sourceFile.statements;\n}\n\nexport function transform<T extends Node>(\n transformer: (node: Node) => VisitResult<Node | undefined>,\n): TransformerFactory<T> {\n return (context: TransformationContext) => (root: T) => {\n const visitor = (node: Node): VisitResult<Node | undefined> => {\n const transformed = transformer(node);\n\n if (transformed !== node) {\n return transformed;\n }\n\n return ts.visitEachChild(transformed, visitor, context);\n };\n return ts.visitEachChild(root, visitor, context);\n };\n}\n\nexport function traverse<T extends Node>(node: Node, visitor: (node: Node) => T | undefined): T | undefined {\n function _visitor(n: Node): T | undefined {\n return visitor(n) ?? ts.forEachChild(n, _visitor);\n }\n\n return _visitor(node);\n}\n"],
5
+ "mappings": "AAAA,OAAO;AAAA,OAOA;AAaA,SAAS,SACd,MACA,wBACA,cAC0B;AAC1B,MAAI;AAEJ,MAAI,MAAM,QAAQ,sBAAsB,GAAG;AAEzC,mBAAe;AAAA,EACjB,OAAO;AACL,eAAW;AAAA,EACb;AAEA,MAAI,aAAa,GAAG,iBAAiB,QAAQ,MAAM,GAAG,aAAa,QAAQ,KAAK;AAEhF,MAAI,cAAc;AAChB,KAAC,UAAU,IAAI,GAAG;AAAA,MAChB;AAAA,MACA;AAAA,IACF,EAAE;AAAA,EACJ;AAEA,SAAO,WAAW,WAAW,UAAU,KAAK,WAAW;AACzD;AAEO,SAAS,UACd,aACuB;AACvB,SAAO,CAAC,YAAmC,CAAC,SAAY;AACtD,UAAM,UAAU,CAAC,SAA8C;AAC7D,YAAM,cAAc,YAAY,IAAI;AAEpC,UAAI,gBAAgB,MAAM;AACxB,eAAO;AAAA,MACT;AAEA,aAAO,GAAG,eAAe,aAAa,SAAS,OAAO;AAAA,IACxD;AACA,WAAO,GAAG,eAAe,MAAM,SAAS,OAAO;AAAA,EACjD;AACF;AAEO,SAAS,SAAyB,MAAY,SAAuD;AAC1G,WAAS,SAAS,GAAwB;AACxC,WAAO,QAAQ,CAAC,KAAK,GAAG,aAAa,GAAG,QAAQ;AAAA,EAClD;AAEA,SAAO,SAAS,IAAI;AACtB;",
6
6
  "names": []
7
7
  }
@@ -1,6 +1,6 @@
1
1
  import ts, {} from "typescript";
2
2
  function createSourceFile(statements, fileName) {
3
- const sourceFile = ts.createSourceFile(fileName, "", ts.ScriptTarget.ES2019, void 0, ts.ScriptKind.TS);
3
+ const sourceFile = ts.createSourceFile(fileName, "", ts.ScriptTarget.ES2021, void 0, ts.ScriptKind.TS);
4
4
  return ts.factory.updateSourceFile(sourceFile, statements);
5
5
  }
6
6
  export {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["src/createSourceFile.ts"],
4
- "sourcesContent": ["import ts, { type SourceFile, type Statement } from 'typescript';\n\nexport default function createSourceFile(statements: readonly Statement[], fileName: string): SourceFile {\n const sourceFile = ts.createSourceFile(fileName, '', ts.ScriptTarget.ES2019, undefined, ts.ScriptKind.TS);\n return ts.factory.updateSourceFile(sourceFile, statements);\n}\n"],
4
+ "sourcesContent": ["import ts, { type SourceFile, type Statement } from 'typescript';\n\nexport default function createSourceFile(statements: readonly Statement[], fileName: string): SourceFile {\n const sourceFile = ts.createSourceFile(fileName, '', ts.ScriptTarget.ES2021, undefined, ts.ScriptKind.TS);\n return ts.factory.updateSourceFile(sourceFile, statements);\n}\n"],
5
5
  "mappings": "AAAA,OAAO,YAA6C;AAErC,SAAR,iBAAkC,YAAkC,UAA8B;AACvG,QAAM,aAAa,GAAG,iBAAiB,UAAU,IAAI,GAAG,aAAa,QAAQ,QAAW,GAAG,WAAW,EAAE;AACxG,SAAO,GAAG,QAAQ,iBAAiB,YAAY,UAAU;AAC3D;",
6
6
  "names": []
7
7
  }
@@ -5,32 +5,38 @@ export declare class NamedImportManager extends StatementRecordManager<ImportDec
5
5
  #private;
6
6
  constructor(collator: Intl.Collator);
7
7
  add(path: string, specifier: string, isType?: boolean, uniqueId?: Identifier): Identifier;
8
+ remove(path: string, specifier: string): void;
8
9
  clear(): void;
9
10
  getIdentifier(path: string, specifier: string): Identifier | undefined;
10
- identifiers(): IterableIterator<readonly [path: string, specifier: string, id: Identifier, isType: boolean]>;
11
+ iter(): IterableIterator<readonly [path: string, specifier: string, id: Identifier, isType: boolean]>;
11
12
  isType(path: string, specifier: string): boolean | undefined;
12
13
  paths(): IterableIterator<string>;
13
14
  specifiers(): IterableIterator<readonly [path: string, specifier: string]>;
14
15
  statementRecords(): IterableIterator<StatementRecord<ImportDeclaration>>;
16
+ [Symbol.iterator](): IterableIterator<readonly [path: string, specifier: string, id: Identifier, isType: boolean]>;
15
17
  }
16
18
  export declare class NamespaceImportManager extends StatementRecordManager<ImportDeclaration> {
17
19
  #private;
18
20
  add(path: string, name: string, uniqueId?: Identifier): Identifier;
19
21
  clear(): void;
20
22
  getIdentifier(path: string): Identifier | undefined;
21
- identifiers(): IterableIterator<Identifier>;
23
+ iter(): IterableIterator<readonly [path: string, id: Identifier]>;
22
24
  paths(): IterableIterator<string>;
23
25
  statementRecords(): IterableIterator<StatementRecord<ImportDeclaration>>;
26
+ remove(path: string): void;
27
+ [Symbol.iterator](): IterableIterator<readonly [path: string, id: Identifier]>;
24
28
  }
25
29
  export declare class DefaultImportManager extends StatementRecordManager<ImportDeclaration> {
26
30
  #private;
27
31
  add(path: string, name: string, isType?: boolean, uniqueId?: Identifier): Identifier;
28
32
  getIdentifier(path: string): Identifier | undefined;
33
+ remove(path: string): void;
29
34
  clear(): void;
30
- identifiers(): IterableIterator<readonly [id: Identifier, isType: boolean]>;
35
+ iter(): IterableIterator<readonly [path: string, id: Identifier, isType: boolean]>;
31
36
  isType(path: string): boolean | undefined;
32
37
  paths(): IterableIterator<string>;
33
38
  statementRecords(): IterableIterator<StatementRecord<ImportDeclaration>>;
39
+ [Symbol.iterator](): IterableIterator<readonly [path: string, id: Identifier, isType: boolean]>;
34
40
  }
35
41
  export default class ImportManager implements CodeConvertable<readonly Statement[]> {
36
42
  #private;
@@ -1 +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,kBAAmB,SAAQ,sBAAsB,CAAC,iBAAiB,CAAC;;gBAInE,QAAQ,EAAE,IAAI,CAAC,QAAQ;IAKnC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,UAAU,GAAG,UAAU;IAYhF,KAAK,IAAI,IAAI;IAItB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAIrE,WAAW,IAAI,gBAAgB,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAQ7G,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAI5D,KAAK,IAAI,gBAAgB,CAAC,MAAM,CAAC;IAIhC,UAAU,IAAI,gBAAgB,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAQjE,gBAAgB,IAAI,gBAAgB,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC;CAyBnF;AAED,qBAAa,sBAAuB,SAAQ,sBAAsB,CAAC,iBAA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AU,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAIlF,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;IAajF,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;CAKjG;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"}
@@ -18,18 +18,23 @@ class NamedImportManager extends StatementRecordManager {
18
18
  }
19
19
  return record.id;
20
20
  }
21
+ remove(path, specifier) {
22
+ const specifiers = this.#map.get(path);
23
+ if (specifiers) {
24
+ specifiers.delete(specifier);
25
+ if (specifiers.size === 0) {
26
+ this.#map.delete(path);
27
+ }
28
+ }
29
+ }
21
30
  clear() {
22
31
  this.#map.clear();
23
32
  }
24
33
  getIdentifier(path, specifier) {
25
34
  return this.#map.get(path)?.get(specifier)?.id;
26
35
  }
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
- }
36
+ iter() {
37
+ return this[Symbol.iterator]();
33
38
  }
34
39
  isType(path, specifier) {
35
40
  return this.#map.get(path)?.get(specifier)?.isType;
@@ -67,6 +72,13 @@ class NamedImportManager extends StatementRecordManager {
67
72
  ];
68
73
  }
69
74
  }
75
+ *[Symbol.iterator]() {
76
+ for (const [path, specifiers] of this.#map) {
77
+ for (const [specifier, { id, isType }] of specifiers) {
78
+ yield [path, specifier, id, isType];
79
+ }
80
+ }
81
+ }
70
82
  }
71
83
  class NamespaceImportManager extends StatementRecordManager {
72
84
  #map = /* @__PURE__ */ new Map();
@@ -81,10 +93,8 @@ class NamespaceImportManager extends StatementRecordManager {
81
93
  getIdentifier(path) {
82
94
  return this.#map.get(path);
83
95
  }
84
- *identifiers() {
85
- for (const id of this.#map.values()) {
86
- yield id;
87
- }
96
+ iter() {
97
+ return this[Symbol.iterator]();
88
98
  }
89
99
  paths() {
90
100
  return this.#map.keys();
@@ -101,6 +111,14 @@ class NamespaceImportManager extends StatementRecordManager {
101
111
  ];
102
112
  }
103
113
  }
114
+ remove(path) {
115
+ this.#map.delete(path);
116
+ }
117
+ *[Symbol.iterator]() {
118
+ for (const [path, id] of this.#map) {
119
+ yield [path, id];
120
+ }
121
+ }
104
122
  }
105
123
  class DefaultImportManager extends StatementRecordManager {
106
124
  #map = /* @__PURE__ */ new Map();
@@ -112,13 +130,16 @@ class DefaultImportManager extends StatementRecordManager {
112
130
  getIdentifier(path) {
113
131
  return this.#map.get(path)?.id;
114
132
  }
133
+ remove(path) {
134
+ if (this.#map.has(path)) {
135
+ this.#map.delete(path);
136
+ }
137
+ }
115
138
  clear() {
116
139
  this.#map.clear();
117
140
  }
118
- *identifiers() {
119
- for (const { id, isType } of this.#map.values()) {
120
- yield [id, isType];
121
- }
141
+ iter() {
142
+ return this[Symbol.iterator]();
122
143
  }
123
144
  isType(path) {
124
145
  return this.#map.get(path)?.isType;
@@ -138,6 +159,11 @@ class DefaultImportManager extends StatementRecordManager {
138
159
  ];
139
160
  }
140
161
  }
162
+ *[Symbol.iterator]() {
163
+ for (const [path, { id, isType }] of this.#map) {
164
+ yield [path, id, isType];
165
+ }
166
+ }
141
167
  }
142
168
  class ImportManager {
143
169
  default;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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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,EACnB;AAAA,EAEA,SAA+B;AAC7B,UAAM,UAAU;AAAA,MACd,GAAG,KAAK,QAAQ,iBAAiB;AAAA,MACjC,GAAG,KAAK,MAAM,iBAAiB;AAAA,MAC/B,GAAG,KAAK,UAAU,iBAAiB;AAAA,IACrC;AACA,YAAQ,KAAK,uBAAuB,iBAAiB,KAAK,SAAS,CAAC;AAEpE,WAAO,QAAQ,IAAI,CAAC,CAAC,EAAE,SAAS,MAAM,SAAS;AAAA,EACjD;AAAA,EAEA,SAAS,QAA6B;AACpC,SAAK,QAAQ,MAAM;AACnB,SAAK,MAAM,MAAM;AACjB,SAAK,UAAU,MAAM;AAErB,UAAM,UAAU,OAAO,WAAW;AAAA,MAAO,CAAC,cACxC,GAAG,oBAAoB,SAAS;AAAA,IAClC;AAEA,eAAW,EAAE,cAAc,gBAAgB,KAAK,SAAS;AACvD,UAAI,CAAC,cAAc;AAEjB;AAAA,MACF;AAEA,YAAM,EAAE,MAAM,cAAc,IAAI;AAChC,YAAM,OAAQ,gBAAqC;AAEnD,UAAI,eAAe;AACjB,YAAI,GAAG,kBAAkB,aAAa,GAAG;AACvC,eAAK,UAAU,IAAI,MAAM,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;",
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 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 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 *[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 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 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 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;AA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AO,WAAW;AAAA,MAAO,CAAC,cACxC,GAAG,oBAAoB,SAAS;AAAA,IAClC;AAEA,eAAW,EAAE,cAAc,gBAAgB,KAAK,SAAS;AACvD,UAAI,CAAC,cAAc;AAEjB;AAAA,MACF;AAEA,YAAM,EAAE,MAAM,cAAc,IAAI;AAChC,YAAM,OAAQ,gBAAqC;AAEnD,UAAI,eAAe;AACjB,YAAI,GAAG,kBAAkB,aAAa,GAAG;AACvC,eAAK,UAAU,IAAI,MAAM,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
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/hilla-generator-utils",
3
- "version": "24.4.6",
3
+ "version": "24.5.0-alpha10",
4
4
  "description": "A set of utils for developing Hilla generator plugins",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -16,7 +16,7 @@
16
16
  "lint": "eslint src test",
17
17
  "lint:fix": "eslint src test --fix",
18
18
  "test": "mocha test/**/*.spec.ts --config ../../../.mocharc.cjs",
19
- "test:coverage": "c8 -c ../../../.c8rc.json npm test",
19
+ "test:coverage": "c8 --experimental-monocart -c ../../../.c8rc.json npm test",
20
20
  "typecheck": "tsc --noEmit"
21
21
  },
22
22
  "exports": {
@@ -59,7 +59,7 @@
59
59
  "dependencies": {
60
60
  "pino": "^8.15.1",
61
61
  "pino-pretty": "^10.2.0",
62
- "typescript": "5.3.2"
62
+ "typescript": "5.5.2"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@types/chai": "^4.3.6",
@@ -67,11 +67,13 @@
67
67
  "@types/node": "^20.7.1",
68
68
  "@types/sinon": "^10.0.17",
69
69
  "@types/sinon-chai": "^3.2.10",
70
- "c8": "^8.0.1",
70
+ "c8": "^10.1.2",
71
71
  "chai": "^4.3.10",
72
+ "chai-like": "^1.1.1",
72
73
  "concurrently": "^8.2.1",
73
74
  "copyfiles": "^2.4.1",
74
75
  "mocha": "^10.2.0",
76
+ "monocart-coverage-reports": "^2.8.4",
75
77
  "sinon": "^16.0.0",
76
78
  "sinon-chai": "^3.7.0",
77
79
  "type-fest": "^4.3.2"
@@ -1,4 +1,3 @@
1
- /// <reference types="chai" />
2
1
  declare global {
3
2
  export namespace Chai {
4
3
  interface Assertion {
@@ -1 +1 @@
1
- {"version":3,"file":"snapshotMatcher.d.ts","sourceRoot":"","sources":["../src/testing/snapshotMatcher.ts"],"names":[],"mappings":";AAMA,OAAO,CAAC,MAAM,CAAC;IAEb,MAAM,WAAW,IAAI,CAAC;QACpB,UAAU,SAAS;YACjB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;SAC7E;KACF;CACF;AAED,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,GAAG,IAAI,CA0B1F"}
1
+ {"version":3,"file":"snapshotMatcher.d.ts","sourceRoot":"","sources":["../src/testing/snapshotMatcher.ts"],"names":[],"mappings":"AAMA,OAAO,CAAC,MAAM,CAAC;IAEb,MAAM,WAAW,IAAI,CAAC;QACpB,UAAU,SAAS;YACjB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;SAC7E;KACF;CACF;AAED,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,GAAG,IAAI,CA0B1F"}