@vaadin/hilla-generator-utils 25.3.0-alpha7 → 25.3.0-alpha9
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 +1 -1
- package/ast.js +1 -1
- package/ast.js.map +1 -1
- package/createFullyUniqueIdentifier.d.ts +1 -1
- package/createFullyUniqueIdentifier.js +1 -1
- package/createFullyUniqueIdentifier.js.map +1 -1
- package/createSourceFile.d.ts +1 -1
- package/createSourceFile.js +1 -1
- package/createSourceFile.js.map +1 -1
- package/dependencies/ExportManager.d.ts +1 -1
- package/dependencies/ExportManager.js +1 -1
- package/dependencies/ExportManager.js.map +1 -1
- package/dependencies/ImportManager.d.ts +1 -1
- package/dependencies/ImportManager.js +1 -1
- package/dependencies/ImportManager.js.map +1 -1
- package/dependencies/StatementRecordManager.d.ts +1 -1
- package/dependencies/StatementRecordManager.js.map +1 -1
- package/dependencies/utils.d.ts +1 -1
- package/dependencies/utils.js.map +1 -1
- package/package.json +3 -3
- package/tsc-template.d.ts +1 -1
- package/tsc-template.js +1 -1
- package/tsc-template.js.map +1 -1
package/ast.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Node, type VisitResult, type SourceFile, type Statement, type TransformerFactory } from "typescript";
|
|
1
|
+
import { type Node, type VisitResult, type SourceFile, type Statement, type TransformerFactory } from "@typescript/typescript6";
|
|
2
2
|
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;
|
package/ast.js
CHANGED
package/ast.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,OAAO,
|
|
1
|
+
{"mappings":"AAAA,OAAO,iCAO0B;AAajC,OAAO,SAAS,SACdA,MACAC,wBACAC,cAC0B;CAC1B,IAAIC;AAEJ,KAAI,MAAM,QAAQ,uBAAuB,EAAE;AAEzC,iBAAe;CAChB,OAAM;AACL,aAAW;CACZ;CAED,IAAI,aAAa,GAAG,iBAAiB,QAAQ,MAAM,GAAG,aAAa,QAAQ,MAAM;AAEjF,KAAI,cAAc;AAChB,GAAC,WAAW,GAAG,GAAG,UAAU,YAAY,aAAsD,CAAC;CAChG;AAED,QAAO,WAAW,WAAW,WAAW,IAAI,WAAW;AACxD;AAED,OAAO,SAAS,UACdC,aACuB;AACvB,QAAO,CAACC,YAAmC,CAACC,SAAY;EACtD,MAAM,UAAU,CAACC,SAA8C;GAC7D,MAAM,cAAc,YAAY,KAAK;AAErC,OAAI,gBAAgB,MAAM;AACxB,WAAO;GACR;AAED,UAAO,GAAG,eAAe,aAAa,SAAS,QAAQ;EACxD;AACD,SAAO,GAAG,eAAe,MAAM,SAAS,QAAQ;CACjD;AACF;AAED,OAAO,SAAS,SAAYA,MAAYC,SAAuD;CAC7F,SAAS,SAASC,GAAwB;AACxC,SAAO,QAAQ,EAAE,IAAI,GAAG,aAAa,GAAG,SAAS;CAClD;AAED,QAAO,SAAS,KAAK;AACtB","names":["code: string","selectorOrTransformers?: ReadonlyArray<TransformerFactory<SourceFile>> | TemplateSelector<T>","transformers?: ReadonlyArray<TransformerFactory<SourceFile>>","selector: TemplateSelector<T> | undefined","transformer: (node: Node) => VisitResult<Node | undefined>","context: TransformationContext","root: T","node: Node","visitor: (node: Node) => T | undefined","n: Node"],"sources":["/opt/agent/work/649c11185a3798db/packages/ts/generator-utils/src/ast.ts"],"sourcesContent":["import ts, {\n type Node,\n type VisitResult,\n type SourceFile,\n type Statement,\n type TransformationContext,\n type TransformerFactory,\n} from '@typescript/typescript6';\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, transformers as Array<TransformerFactory<SourceFile>>).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>(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"],"version":3}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type GeneratedIdentifierFlags, type Identifier } from "typescript";
|
|
1
|
+
import { type GeneratedIdentifierFlags, type Identifier } from "@typescript/typescript6";
|
|
2
2
|
export default function createFullyUniqueIdentifier(name: string, flags?: GeneratedIdentifierFlags): Identifier;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,OAAO,
|
|
1
|
+
{"mappings":"AAAA,OAAO,iCAAsF;AAE7F,eAAe,SAAS,4BAA4BA,MAAcC,OAA8C;AAC9G,QAAO,GAAG,QAAQ;EAChB;;EAEA,SAAS,GAAG,yBAAyB,aAAa,GAAG,yBAAyB;CAC/E;AACF","names":["name: string","flags?: GeneratedIdentifierFlags"],"sources":["/opt/agent/work/649c11185a3798db/packages/ts/generator-utils/src/createFullyUniqueIdentifier.ts"],"sourcesContent":["import ts, { type GeneratedIdentifierFlags, type Identifier } from '@typescript/typescript6';\n\nexport default function createFullyUniqueIdentifier(name: string, flags?: GeneratedIdentifierFlags): Identifier {\n return ts.factory.createUniqueName(\n name,\n // eslint-disable-next-line no-bitwise\n flags ?? ts.GeneratedIdentifierFlags.Optimistic & ts.GeneratedIdentifierFlags.FileLevel,\n );\n}\n"],"version":3}
|
package/createSourceFile.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type SourceFile, type Statement } from "typescript";
|
|
1
|
+
import { type SourceFile, type Statement } from "@typescript/typescript6";
|
|
2
2
|
export default function createSourceFile(statements: readonly Statement[], fileName: string): SourceFile;
|
package/createSourceFile.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
1
|
+
import ts from "@typescript/typescript6";
|
|
2
2
|
export default function createSourceFile(statements, fileName) {
|
|
3
3
|
const sourceFile = ts.createSourceFile(fileName, "", ts.ScriptTarget.ES2021, undefined, ts.ScriptKind.TS);
|
|
4
4
|
return ts.factory.updateSourceFile(sourceFile, statements);
|
package/createSourceFile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,OAAO,
|
|
1
|
+
{"mappings":"AAAA,OAAO,iCAAuE;AAE9E,eAAe,SAAS,iBAAiBA,YAAkCC,UAA8B;CACvG,MAAM,aAAa,GAAG,iBAAiB,UAAU,IAAI,GAAG,aAAa,QAAQ,WAAW,GAAG,WAAW,GAAG;AACzG,QAAO,GAAG,QAAQ,iBAAiB,YAAY,WAAW;AAC3D","names":["statements: readonly Statement[]","fileName: string"],"sources":["/opt/agent/work/649c11185a3798db/packages/ts/generator-utils/src/createSourceFile.ts"],"sourcesContent":["import ts, { type SourceFile, type Statement } from '@typescript/typescript6';\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"],"version":3}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ExportAssignment, type ExportDeclaration, type Identifier, type Statement } from "typescript";
|
|
1
|
+
import { type ExportAssignment, type ExportDeclaration, type Identifier, type Statement } from "@typescript/typescript6";
|
|
2
2
|
import type CodeConvertable from "./CodeConvertable.js";
|
|
3
3
|
import StatementRecordManager, { type StatementRecord } from "./StatementRecordManager.js";
|
|
4
4
|
export declare class NamedExportManager implements CodeConvertable<ExportDeclaration | undefined> {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
1
|
+
import ts from "@typescript/typescript6";
|
|
2
2
|
import createFullyUniqueIdentifier from "../createFullyUniqueIdentifier.js";
|
|
3
3
|
import StatementRecordManager from "./StatementRecordManager.js";
|
|
4
4
|
import { createDependencyRecord } from "./utils.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,OAAO,
|
|
1
|
+
{"mappings":"AAAA,OAAO,iCAK0B;AACjC,OAAO,oEAAqE;AAE5E,OAAO,yDAAoF;AAC3F,SAAS,0CAAkE;AAE3E,OAAO,MAAM,mBAA6E;CACxF,AAAS;CACT,AAASA,OAAO,IAAI;CAEpB,IAAI,OAAe;AACjB,SAAO,KAAKA,KAAK;CAClB;CAED,YAAYC,UAAyB;AACnC,OAAK,WAAW;CACjB;CAED,IAAIC,MAAcC,QAAkBC,UAAmC;EACrE,MAAM,KAAK,YAAY,4BAA4B,KAAK;AACxD,OAAKJ,KAAK,IAAI,MAAM,uBAAuB,IAAI,OAAO,CAAC;AACvD,SAAO;CACR;CAED,cAAcE,MAAsC;AAClD,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,GAAG,oBAAoB;AAEnC,MAAI,kBAAkB;AACpB,UAAO,KAAK,iBAAiB;EAC9B;AAED,SAAO;CACR;AACF","names":["#map","collator: Intl.Collator","name: string","isType?: boolean","uniqueId?: Identifier","path: string","#id","id: Identifier | string","result: Statement[]"],"sources":["/opt/agent/work/649c11185a3798db/packages/ts/generator-utils/src/dependencies/ExportManager.ts"],"sourcesContent":["import ts, {\n type ExportAssignment,\n type ExportDeclaration,\n type Identifier,\n type Statement,\n} from '@typescript/typescript6';\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 get size(): number {\n return this.#map.size;\n }\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 get size(): number {\n return this.#map.size;\n }\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 get isEmpty(): boolean {\n return !this.#id;\n }\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: DefaultExportManager = new DefaultExportManager();\n readonly named: NamedExportManager;\n readonly namespace: NamespaceExportManager;\n\n get size(): number {\n return (this.default.isEmpty ? 0 : 1) + this.named.size + this.namespace.size;\n }\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"],"version":3}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ts, { type Identifier, type ImportDeclaration, type Statement } from "typescript";
|
|
1
|
+
import ts, { type Identifier, type ImportDeclaration, type Statement } from "@typescript/typescript6";
|
|
2
2
|
import type CodeConvertable from "./CodeConvertable.js";
|
|
3
3
|
import StatementRecordManager, { type StatementRecord } from "./StatementRecordManager.js";
|
|
4
4
|
export declare class NamedImportManager extends StatementRecordManager<ImportDeclaration> {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
1
|
+
import ts from "@typescript/typescript6";
|
|
2
2
|
import createFullyUniqueIdentifier from "../createFullyUniqueIdentifier.js";
|
|
3
3
|
import StatementRecordManager, { createComparator } from "./StatementRecordManager.js";
|
|
4
4
|
import { createDependencyRecord } from "./utils.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,OAAO,oBAAkF;AACzF,OAAO,oEAAqE;AAE5E,OAAO,0BAA0B,qDAA4E;AAC7G,SAAS,0CAAkE;AAE3E,OAAO,MAAM,2BAA2B,uBAA0C;CAChF,AAASA,OAAO,IAAI;CAEpB,IAAI,OAAe;AACjB,SAAO,KAAKA,KAAK;CAClB;CAED,IAAIC,MAAcC,WAAmBC,QAAkBC,UAAmC;EACxF,MAAM,SAAS,uBAAuB,YAAY,4BAA4B,UAAU,EAAE,OAAO;AAEjG,MAAI,KAAKJ,KAAK,IAAI,KAAK,EAAE;AACvB,QAAKA,KAAK,IAAI,KAAK,CAAE,IAAI,WAAW,OAAO;EAC5C,OAAM;AACL,QAAKA,KAAK,IAAI,M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IAAI,OAAe;AACjB,SAAO,KAAK,QAAQ,OAAO,KAAK,MAAM,OAAO,KAAK,UAAU;CAC7D;CAED,SAA+B;EAC7B,MAAM,UAAU;GACd,GAAG,KAAK,QAAQ,kBAAkB;GAClC,GAAG,KAAK,MAAM,kBAAkB;GAChC,GAAG,KAAK,UAAU,kBAAkB;EACrC;AACD,UAAQ,KAAK,iBAAiB,KAAK,SAAS,CAAC;AAE7C,SAAO,QAAQ,IAAI,CAAC,GAAG,UAAU,KAAK,UAAU;CACjD;CAED,SAASC,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":["#map","path: string","specifier: string","isType?: boolean","uniqueId?: Identifier","name: string","collator: Intl.Collator","source: ts.SourceFile"],"sources":["/opt/agent/work/649c11185a3798db/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, { createComparator, type StatementRecord } from './StatementRecordManager.js';\nimport { createDependencyRecord, type DependencyRecord } from './utils.js';\n\nexport class NamedImportManager extends StatementRecordManager<ImportDeclaration> {\n readonly #map = new Map<string, Map<string, DependencyRecord>>();\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 collator: Intl.Collator;\n readonly default: DefaultImportManager;\n readonly named: NamedImportManager;\n readonly namespace: NamespaceImportManager;\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(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
|
+
{"mappings":"AAAA,OAAO,iCAA+F;AACtG,OAAO,oEAAqE;AAE5E,OAAO,0BAA0B,qDAA4E;AAC7G,SAAS,0CAAkE;AAE3E,OAAO,MAAM,2BAA2B,uBAA0C;CAChF,AAASA,OAAO,IAAI;CAEpB,IAAI,OAAe;AACjB,SAAO,KAAKA,KAAK;CAClB;CAED,IAAIC,MAAcC,WAAmBC,QAAkBC,UAAmC;EACxF,MAAM,SAAS,uBAAuB,YAAY,4BAA4B,UAAU,EAAE,OAAO;AAEjG,MAAI,KAAKJ,KAAK,IAAI,KAAK,EAAE;AACvB,QAAKA,KAAK,IAAI,KAAK,CAAE,IAAI,WAAW,OAAO;EAC5C,OAAM;AACL,QAAKA,KAAK,IAAI,MAAM,IAAI,IAAI,CAAC,CAAC,WAAW,MAAO,CAAC,GAAE;EACpD;AAED,SAAO,OAAO;CACf;CAED,OAAOC,MAAcC,WAAyB;EAC5C,MAAM,aAAa,KAAKF,KAAK,IAAI,KAAK;AAEtC,MAAI,YAAY;AACd,cAAW,OAAO,UAAU;AAE5B,OAAI,WAAW,SAAS,GAAG;AACzB,SAAKA,KAAK,OAAO,KAAK;GACvB;EACF;CACF;CAED,AAAS,QAAc;AACrB,OAAKA,KAAK,OAAO;CAClB;CAED,cAAcC,MAAcC,WAA2C;AACrE,SAAO,KAAKF,KAAK,IAAI,KAAK,EAAE,IAAI,UAAU,EAAE;CAC7C;CAED,OAAsG;AACpG,SAAO,KAAK,OAAO,WAAW;CAC/B;CAED,OAAOC,MAAcC,WAAwC;AAC3D,SAAO,KAAKF,KAAK,IAAI,KAAK,EAAE,IAAI,UAAU,EAAE;CAC7C;CAED,QAAkC;AAChC,SAAO,KAAKA,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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":["#map","path: string","specifier: string","isType?: boolean","uniqueId?: Identifier","name: string","collator: Intl.Collator","source: ts.SourceFile"],"sources":["/opt/agent/work/649c11185a3798db/packages/ts/generator-utils/src/dependencies/ImportManager.ts"],"sourcesContent":["import ts, { type Identifier, type ImportDeclaration, type Statement } from '@typescript/typescript6';\nimport createFullyUniqueIdentifier from '../createFullyUniqueIdentifier.js';\nimport type CodeConvertable from './CodeConvertable.js';\nimport StatementRecordManager, { createComparator, type StatementRecord } from './StatementRecordManager.js';\nimport { createDependencyRecord, type DependencyRecord } from './utils.js';\n\nexport class NamedImportManager extends StatementRecordManager<ImportDeclaration> {\n readonly #map = new Map<string, Map<string, DependencyRecord>>();\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 collator: Intl.Collator;\n readonly default: DefaultImportManager;\n readonly named: NamedImportManager;\n readonly namespace: NamespaceImportManager;\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(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,4 +1,4 @@
|
|
|
1
|
-
import type { Statement } from "typescript";
|
|
1
|
+
import type { Statement } from "@typescript/typescript6";
|
|
2
2
|
import type CodeConvertable from "./CodeConvertable.js";
|
|
3
3
|
export type StatementRecord<T extends Statement> = readonly [path: string, declaration: T];
|
|
4
4
|
export declare function createComparator<T extends Statement>(collator: Intl.Collator): (recordA: StatementRecord<T>, recordB: StatementRecord<T>) => number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAKA,OAAO,SAAS,iBACdA,UACsE;AACtE,QAAO,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,KAAK;AAC3B,MAAI,MAAM,WAAW,IAAI,KAAK,MAAM,WAAW,IAAI,EAAE;AACnD,UAAO;EACR;AAED,OAAK,MAAM,WAAW,IAAI,IAAI,MAAM,WAAW,IAAI,EAAE;AACnD,WAAQ;EACT;AAED,SAAO,SAAS,QAAQ,OAAO,MAAM;CACtC;AACF;AAED,eAAe,MAAe,uBAAqF;CACjH,AAAS;CAET,YAAYA,UAAyB;AACnC,OAAK,WAAW;CACjB;CAID,SAAuB;EACrB,MAAM,UAAU,CAAC,GAAG,KAAK,kBAAkB,AAAC;AAC5C,UAAQ,KAAK,iBAAiB,KAAK,SAAS,CAAC;AAE7C,SAAO,QAAQ,IAAI,CAAC,GAAG,UAAU,KAAK,UAAU;CACjD;AAGF","names":["collator: Intl.Collator"],"sources":["/opt/agent/work/649c11185a3798db/packages/ts/generator-utils/src/dependencies/StatementRecordManager.ts"],"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 function 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\nexport default abstract class StatementRecordManager<T extends Statement> implements CodeConvertable<readonly T[]> {\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(createComparator(this.collator));\n\n return records.map(([, statement]) => statement);\n }\n\n abstract clear(): void;\n}\n"],"version":3}
|
|
1
|
+
{"mappings":"AAKA,OAAO,SAAS,iBACdA,UACsE;AACtE,QAAO,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,KAAK;AAC3B,MAAI,MAAM,WAAW,IAAI,KAAK,MAAM,WAAW,IAAI,EAAE;AACnD,UAAO;EACR;AAED,OAAK,MAAM,WAAW,IAAI,IAAI,MAAM,WAAW,IAAI,EAAE;AACnD,WAAQ;EACT;AAED,SAAO,SAAS,QAAQ,OAAO,MAAM;CACtC;AACF;AAED,eAAe,MAAe,uBAAqF;CACjH,AAAS;CAET,YAAYA,UAAyB;AACnC,OAAK,WAAW;CACjB;CAID,SAAuB;EACrB,MAAM,UAAU,CAAC,GAAG,KAAK,kBAAkB,AAAC;AAC5C,UAAQ,KAAK,iBAAiB,KAAK,SAAS,CAAC;AAE7C,SAAO,QAAQ,IAAI,CAAC,GAAG,UAAU,KAAK,UAAU;CACjD;AAGF","names":["collator: Intl.Collator"],"sources":["/opt/agent/work/649c11185a3798db/packages/ts/generator-utils/src/dependencies/StatementRecordManager.ts"],"sourcesContent":["import type { Statement } from '@typescript/typescript6';\nimport type CodeConvertable from './CodeConvertable.js';\n\nexport type StatementRecord<T extends Statement> = readonly [path: string, declaration: T];\n\nexport function 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\nexport default abstract class StatementRecordManager<T extends Statement> implements CodeConvertable<readonly T[]> {\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(createComparator(this.collator));\n\n return records.map(([, statement]) => statement);\n }\n\n abstract clear(): void;\n}\n"],"version":3}
|
package/dependencies/utils.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAOA,OAAO,SAAS,uBAAuBA,IAAgB,SAAS,OAAyB;AACvF,QAAO;EACL;EACA;CACD;AACF","names":["id: Identifier"],"sources":["/opt/agent/work/649c11185a3798db/packages/ts/generator-utils/src/dependencies/utils.ts"],"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"],"version":3}
|
|
1
|
+
{"mappings":"AAOA,OAAO,SAAS,uBAAuBA,IAAgB,SAAS,OAAyB;AACvF,QAAO;EACL;EACA;CACD;AACF","names":["id: Identifier"],"sources":["/opt/agent/work/649c11185a3798db/packages/ts/generator-utils/src/dependencies/utils.ts"],"sourcesContent":["import type { Identifier } from '@typescript/typescript6';\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"],"version":3}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/hilla-generator-utils",
|
|
3
|
-
"version": "25.3.0-
|
|
3
|
+
"version": "25.3.0-alpha9",
|
|
4
4
|
"description": "A set of utils for developing Hilla generator plugins",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
+
"@typescript/typescript6": "6.0.2",
|
|
60
61
|
"pino": "9.6.0",
|
|
61
|
-
"pino-pretty": "10.3.1"
|
|
62
|
-
"typescript": "6.0.3"
|
|
62
|
+
"pino-pretty": "10.3.1"
|
|
63
63
|
}
|
|
64
64
|
}
|
package/tsc-template.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Node, type SourceFile, type TransformerFactory, type VisitResult } from "typescript";
|
|
1
|
+
import { type Node, type SourceFile, type TransformerFactory, type VisitResult } from "@typescript/typescript6";
|
|
2
2
|
export type Transformer = (node: Node) => VisitResult<Node | undefined>;
|
|
3
3
|
export declare function createTransformer(transformer: Transformer): TransformerFactory<SourceFile>;
|
|
4
4
|
declare const $templateResult: unique symbol;
|
package/tsc-template.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createSourceFile, forEachChild, isIdentifier, ScriptKind, ScriptTarget, transform, visitEachChild } from "typescript";
|
|
1
|
+
import { createSourceFile, forEachChild, isIdentifier, ScriptKind, ScriptTarget, transform, visitEachChild } from "@typescript/typescript6";
|
|
2
2
|
export function createTransformer(transformer) {
|
|
3
3
|
return (context) => (root) => {
|
|
4
4
|
const visitor = (node) => {
|
package/tsc-template.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAOA,SACE,kBACA,cACA,cAEA,YACA,cAEA,WAEA
|
|
1
|
+
{"mappings":"AAOA,SACE,kBACA,cACA,cAEA,YACA,cAEA,WAEA,+CAE+B;AAIjC,OAAO,SAAS,kBAAkBA,aAA0D;AAC1F,QAAO,CAAC,YAAY,CAAC,SAAS;EAC5B,MAAM,UAAU,CAACC,SAA8C;GAC7D,MAAM,cAAc,YAAY,KAAK;AACrC,OAAI,gBAAgB,MAAM;AACxB,WAAO;GACR;AACD,UAAO,eAAe,aAAa,SAAS,QAAQ;EACrD;AACD,SAAO,eAAe,MAAM,SAAS,QAAQ;CAC9C;AACF;AAED,MAAMC,kBAAiC,OAAO,iBAAiB;AAQ/D,SAAS,iBAAiBC,OAAyC;AACjE,eAAc,UAAU,YAAY,UAAU,QAAQ,WAAW,SAAS,MAAM,UAAU;AAC3F;AAID,MAAM,eAAe;AACrB,MAAM,aAAa;AAEnB,SAAS,gBAAgBC,KAAqB;CAC5C,MAAM,aAAa,aAAa,KAAK,IAAI;CACzC,MAAM,aAAa,aAAa,IAAI,MAAM,WAAW,QAAQ,WAAW,GAAG,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AAc,EAC/D;AACA,QAAM,IAAI,MAAM;CACjB;CAED,MAAM,CAAC,OAAO,GAAG,UACf,iBAAiB,IAAI,MAAM,aAAa,QAAQ,OAAO,WAAW,IAAI,EACtE,aACD,CAAC;AACF,QAAO;EAAE,OAAO;EAAiB,MAAM,aAAa,OAAO;EAAE;CAAQ;AACtE","names":["transformer: Transformer","node: Node","$templateResult: unique symbol","value: unknown","str: string","file: SourceFile","latest: Node","parts: TemplateStringsArray","transformers: Array<TransformerFactory<SourceFile>>"],"sources":["/opt/agent/work/649c11185a3798db/packages/ts/generator-utils/src/tsc-template.ts"],"sourcesContent":["/*\n * Adapted from `tsc-template` (https://github.com/ausginer/tsc-template),\n * © 2024 Vlad Rindevich, Apache-2.0 licensed.\n *\n * Inlined here so Hilla packages don't carry an external dependency whose\n * peerDependency on TypeScript lags behind ours.\n */\nimport {\n createSourceFile,\n forEachChild,\n isIdentifier,\n type Node,\n ScriptKind,\n ScriptTarget,\n type SourceFile,\n transform,\n type TransformerFactory,\n visitEachChild,\n type VisitResult,\n} from '@typescript/typescript6';\n\nexport type Transformer = (node: Node) => VisitResult<Node | undefined>;\n\nexport function createTransformer(transformer: Transformer): TransformerFactory<SourceFile> {\n return (context) => (root) => {\n const visitor = (node: Node): VisitResult<Node | undefined> => {\n const transformed = transformer(node);\n if (transformed !== node) {\n return transformed;\n }\n return visitEachChild(transformed, visitor, context);\n };\n return visitEachChild(root, visitor, context);\n };\n}\n\nconst $templateResult: unique symbol = Symbol('TemplateResult');\n\nexport type TemplateResult = Readonly<{\n brand: typeof $templateResult;\n node: Node;\n source: SourceFile;\n}>;\n\nfunction isTemplateResult(value: unknown): value is TemplateResult {\n return typeof value === 'object' && value !== null && 'brand' in value && value.brand === $templateResult;\n}\n\n// Anchored, fixed-length patterns — no nested or overlapping quantifiers, so\n// matching is linear in the input length (no ReDoS surface).\nconst START_MARKER = /\\/\\*\\*\\s*@START\\s*\\*\\//iu;\nconst END_MARKER = /\\/\\*\\*\\s*@END\\s*\\*\\//iu;\n\nfunction extractCodePart(str: string): string {\n const startMatch = START_MARKER.exec(str);\n const afterStart = startMatch ? str.slice(startMatch.index + startMatch[0].length) : str;\n const endMatch = END_MARKER.exec(afterStart);\n const codePart = endMatch ? afterStart.slice(0, endMatch.index) : afterStart;\n return codePart.trim();\n}\n\nfunction isInjectedNode(node: Node): boolean {\n return node.pos < 0 || node.end < 0;\n}\n\nfunction findBestNode(file: SourceFile): Node {\n const codePart = extractCodePart(file.getText());\n let latest: Node = file;\n const find = (node: Node): Node | undefined => {\n if (!isInjectedNode(node) && node.getText(file) === codePart) {\n latest = node;\n } else if (latest !== file) {\n return latest;\n }\n return forEachChild(node, find);\n };\n return forEachChild(file, find) ?? latest;\n}\n\nexport default function ast(\n parts: TemplateStringsArray,\n ...fillers: ReadonlyArray<TemplateResult | Node | string | null | undefined>\n): TemplateResult {\n let code = '';\n const transformers: Array<TransformerFactory<SourceFile>> = [];\n\n for (let i = 0; i < parts.length; i++) {\n const filler = fillers[i];\n code += parts[i];\n if (filler != null) {\n if (typeof filler === 'string') {\n code += filler;\n } else {\n const id = `$${crypto.randomUUID().replaceAll('-', '_')}`;\n code += id;\n transformers.push(\n createTransformer((n) =>\n isIdentifier(n) && n.text === id ? (isTemplateResult(filler) ? filler.node : filler) : n,\n ),\n );\n }\n }\n }\n\n if (code.includes('%{') || code.includes('}%')) {\n code = code.replaceAll('%{', '/** @START */').replaceAll('}%', '/** @END */');\n }\n\n if (\n code.indexOf('/** @START */') !== code.lastIndexOf('/** @START */') ||\n code.indexOf('/** @END */') !== code.lastIndexOf('/** @END */')\n ) {\n throw new Error('Only one set of code extractors is allowed: %{ ... }% or /** @START */ ... /** @END */');\n }\n\n const [source] = transform(\n createSourceFile('', code, ScriptTarget.Latest, false, ScriptKind.TSX),\n transformers,\n ).transformed;\n return { brand: $templateResult, node: findBestNode(source), source };\n}\n"],"version":3}
|