@venizia/dev-configs 0.5.0-11 → 0.5.0-12
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/README.md +2 -2
- package/dist/cli/codemod/class-renames.d.ts +9 -2
- package/dist/cli/codemod/class-renames.js +92 -17
- package/dist/cli/codemod/class-renames.js.map +1 -1
- package/dist/cli/codemod/index.js +7 -0
- package/dist/cli/codemod/index.js.map +1 -1
- package/dist/cli/codemod/namespace-functions/mapping.d.ts +6 -0
- package/dist/cli/codemod/namespace-functions/mapping.js.map +1 -1
- package/dist/cli/codemod/namespace-functions/mappings/connectors.d.ts +2 -0
- package/dist/cli/codemod/namespace-functions/mappings/connectors.js +19 -1
- package/dist/cli/codemod/namespace-functions/mappings/connectors.js.map +1 -1
- package/dist/cli/codemod/namespace-functions/mappings/guards.d.ts +4 -0
- package/dist/cli/codemod/namespace-functions/mappings/guards.js +15 -0
- package/dist/cli/codemod/namespace-functions/mappings/guards.js.map +1 -0
- package/dist/cli/codemod/namespace-functions/mappings/helpers.d.ts +3 -2
- package/dist/cli/codemod/namespace-functions/mappings/helpers.js +24 -3
- package/dist/cli/codemod/namespace-functions/mappings/helpers.js.map +1 -1
- package/dist/cli/codemod/namespace-functions/mappings/inversion.d.ts +6 -2
- package/dist/cli/codemod/namespace-functions/mappings/inversion.js +42 -3
- package/dist/cli/codemod/namespace-functions/mappings/inversion.js.map +1 -1
- package/dist/cli/codemod/namespace-functions/mappings/kernel.d.ts +4 -2
- package/dist/cli/codemod/namespace-functions/mappings/kernel.js +16 -3
- package/dist/cli/codemod/namespace-functions/mappings/kernel.js.map +1 -1
- package/dist/cli/codemod/namespace-functions/rewriter.d.ts +7 -0
- package/dist/cli/codemod/namespace-functions/rewriter.js +75 -8
- package/dist/cli/codemod/namespace-functions/rewriter.js.map +1 -1
- package/dist/cli/codemod/public-names.d.ts +25 -0
- package/dist/cli/codemod/public-names.js +134 -0
- package/dist/cli/codemod/public-names.js.map +1 -0
- package/dist/cli/index.js +1 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/linters/house/framework-api-patterns.js +1 -1
- package/dist/linters/house/framework-api-patterns.js.map +1 -1
- package/dist/linters/house/no-shadow-framework-type.rule.d.ts +1 -1
- package/dist/linters/house/no-shadow-framework-type.rule.js +1 -1
- package/dist/linters/house/no-shadow-framework-type.rule.js.map +1 -1
- package/dist/linters/rules/naming-convention.rule.js +1 -1
- package/dist/linters/rules/naming-convention.rule.js.map +1 -1
- package/package.json +1 -1
|
@@ -36,8 +36,10 @@ class NamespaceFunctions {
|
|
|
36
36
|
const declarationsOf = (name) => (identifiers.get(name) ?? []).filter((identifier) => NamespaceFunctions.isDeclarationName({ typescript, identifier }));
|
|
37
37
|
const edits = [];
|
|
38
38
|
const removals = new Set();
|
|
39
|
-
/** The imports that lose an old name. */
|
|
39
|
+
/** The imports that lose an old name or the `type` of a class. */
|
|
40
40
|
const trimmed = new Set();
|
|
41
|
+
/** The `type` imports of a class that a rewritten call needs as a value. */
|
|
42
|
+
const untyped = new Set();
|
|
41
43
|
const additions = new Map();
|
|
42
44
|
const newImports = new Map();
|
|
43
45
|
/** The class names this run imports, and from which module. */
|
|
@@ -67,22 +69,35 @@ class NamespaceFunctions {
|
|
|
67
69
|
});
|
|
68
70
|
continue;
|
|
69
71
|
}
|
|
70
|
-
|
|
72
|
+
// Every entry a type guard row lists exports the same class, so a class imported from one serves them all.
|
|
73
|
+
const classModules = mapping.newModules ?? (mapping.isTypeGuard ? mapping.modules : [binding.module]);
|
|
71
74
|
const isNamespaceReach = !binding.specifier && classModules.includes(binding.module);
|
|
72
75
|
let classReference = `${binding.local}.${mapping.className}`;
|
|
73
76
|
let needsImport = false;
|
|
77
|
+
let typeImport;
|
|
74
78
|
if (!isNamespaceReach) {
|
|
75
|
-
const
|
|
79
|
+
const valueImport = NamespaceFunctions.findClassImport({
|
|
76
80
|
typescript,
|
|
77
81
|
sourceFile,
|
|
78
82
|
className: mapping.className,
|
|
79
83
|
modules: classModules,
|
|
80
84
|
});
|
|
85
|
+
typeImport =
|
|
86
|
+
valueImport || !mapping.isTypeGuard
|
|
87
|
+
? undefined
|
|
88
|
+
: NamespaceFunctions.findClassTypeImport({
|
|
89
|
+
typescript,
|
|
90
|
+
sourceFile,
|
|
91
|
+
className: mapping.className,
|
|
92
|
+
modules: classModules,
|
|
93
|
+
});
|
|
94
|
+
// An `import type { ClassName }` brings no value: the class moves to a value import.
|
|
95
|
+
const existing = valueImport ?? (typeImport?.isWholeImport ? undefined : typeImport?.specifier.name);
|
|
81
96
|
const plannedModule = planned.get(mapping.className);
|
|
82
97
|
const conflict = existing
|
|
83
98
|
? declarationsOf(existing.text).find((identifier) => identifier !== existing)
|
|
84
99
|
: plannedModule === undefined
|
|
85
|
-
? declarationsOf(mapping.className)
|
|
100
|
+
? declarationsOf(mapping.className).find((identifier) => identifier !== typeImport?.specifier.name)
|
|
86
101
|
: undefined;
|
|
87
102
|
if (conflict) {
|
|
88
103
|
report({
|
|
@@ -123,6 +138,10 @@ class NamespaceFunctions {
|
|
|
123
138
|
if (count === 0) {
|
|
124
139
|
continue;
|
|
125
140
|
}
|
|
141
|
+
if (typeImport) {
|
|
142
|
+
(typeImport.isWholeImport ? removals : untyped).add(typeImport.specifier);
|
|
143
|
+
trimmed.add(typeImport.declaration);
|
|
144
|
+
}
|
|
126
145
|
if (needsImport) {
|
|
127
146
|
const sameDeclaration = binding.specifier && classModules.includes(binding.module)
|
|
128
147
|
? binding.declaration
|
|
@@ -134,7 +153,7 @@ class NamespaceFunctions {
|
|
|
134
153
|
planned.set(mapping.className, sameDeclaration ? binding.module : NamespaceFunctions.moduleOf({ declaration }));
|
|
135
154
|
}
|
|
136
155
|
else {
|
|
137
|
-
const module =
|
|
156
|
+
const module = mapping.newModules?.[0] ?? binding.module;
|
|
138
157
|
const entry = newImports.get(module) ?? {
|
|
139
158
|
anchor: binding.declaration,
|
|
140
159
|
names: new Set(),
|
|
@@ -158,6 +177,7 @@ class NamespaceFunctions {
|
|
|
158
177
|
sourceFile,
|
|
159
178
|
declaration,
|
|
160
179
|
removals,
|
|
180
|
+
untyped,
|
|
161
181
|
additions: [...(additions.get(declaration) ?? [])],
|
|
162
182
|
report,
|
|
163
183
|
}));
|
|
@@ -356,6 +376,10 @@ class NamespaceFunctions {
|
|
|
356
376
|
if (typescript.isBindingElement(parent)) {
|
|
357
377
|
return parent.propertyName !== identifier;
|
|
358
378
|
}
|
|
379
|
+
// `isClass` of `import { isClass as other }` names the export, not a binding of this file.
|
|
380
|
+
if (typescript.isImportSpecifier(parent)) {
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
359
383
|
if (typescript.isExportSpecifier(parent)) {
|
|
360
384
|
return (!parent.parent.parent.moduleSpecifier && (parent.propertyName ?? parent.name) === identifier);
|
|
361
385
|
}
|
|
@@ -464,6 +488,38 @@ class NamespaceFunctions {
|
|
|
464
488
|
}
|
|
465
489
|
return undefined;
|
|
466
490
|
}
|
|
491
|
+
/**
|
|
492
|
+
* The import that brings the class in from `modules` as a type only: a `{ type ClassName }` specifier of a value
|
|
493
|
+
* import, else an unaliased name of an `import type`.
|
|
494
|
+
*/
|
|
495
|
+
static findClassTypeImport(opts) {
|
|
496
|
+
const { typescript, sourceFile, className, modules } = opts;
|
|
497
|
+
let wholeImport;
|
|
498
|
+
for (const statement of sourceFile.statements) {
|
|
499
|
+
if (!typescript.isImportDeclaration(statement) ||
|
|
500
|
+
!typescript.isStringLiteral(statement.moduleSpecifier) ||
|
|
501
|
+
!modules.includes(statement.moduleSpecifier.text)) {
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
const clause = statement.importClause;
|
|
505
|
+
const named = clause?.namedBindings;
|
|
506
|
+
if (!clause || !named || !typescript.isNamedImports(named)) {
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
const isWholeImport = clause.isTypeOnly;
|
|
510
|
+
const specifier = named.elements.find((candidate) => isWholeImport
|
|
511
|
+
? !candidate.propertyName && candidate.name.text === className
|
|
512
|
+
: candidate.isTypeOnly && (candidate.propertyName ?? candidate.name).text === className);
|
|
513
|
+
if (!specifier) {
|
|
514
|
+
continue;
|
|
515
|
+
}
|
|
516
|
+
if (!isWholeImport) {
|
|
517
|
+
return { declaration: statement, specifier, isWholeImport };
|
|
518
|
+
}
|
|
519
|
+
wholeImport ??= { declaration: statement, specifier, isWholeImport };
|
|
520
|
+
}
|
|
521
|
+
return wholeImport;
|
|
522
|
+
}
|
|
467
523
|
/** The first value import with braces from one of `modules`, to add a class to. */
|
|
468
524
|
static findNamedImport(opts) {
|
|
469
525
|
const { typescript, sourceFile, modules } = opts;
|
|
@@ -499,6 +555,7 @@ class NamespaceFunctions {
|
|
|
499
555
|
*/
|
|
500
556
|
static planImport(opts) {
|
|
501
557
|
const { typescript, sourceFile, declaration, removals, additions, report } = opts;
|
|
558
|
+
const untyped = opts.untyped ?? new Set();
|
|
502
559
|
const clause = declaration.importClause;
|
|
503
560
|
const named = clause?.namedBindings;
|
|
504
561
|
if (!clause || !named || !typescript.isNamedImports(named)) {
|
|
@@ -507,6 +564,9 @@ class NamespaceFunctions {
|
|
|
507
564
|
const source = sourceFile.text;
|
|
508
565
|
const elements = [...named.elements];
|
|
509
566
|
const braces = source.slice(named.getStart(sourceFile), named.end);
|
|
567
|
+
const textOf = (element) => untyped.has(element)
|
|
568
|
+
? source.slice((element.propertyName ?? element.name).getStart(sourceFile), element.end)
|
|
569
|
+
: element.getText(sourceFile);
|
|
510
570
|
if (/\/\*|\/\//.test(braces)) {
|
|
511
571
|
for (const element of elements.filter((candidate) => removals.has(candidate))) {
|
|
512
572
|
report({
|
|
@@ -514,17 +574,24 @@ class NamespaceFunctions {
|
|
|
514
574
|
reason: `the braces of this import hold a comment, so \`${element.name.text}\` stays imported; remove it by hand`,
|
|
515
575
|
});
|
|
516
576
|
}
|
|
577
|
+
const retyped = elements
|
|
578
|
+
.filter((candidate) => untyped.has(candidate))
|
|
579
|
+
.map((element) => ({
|
|
580
|
+
start: element.getStart(sourceFile),
|
|
581
|
+
end: element.end,
|
|
582
|
+
text: textOf(element),
|
|
583
|
+
}));
|
|
517
584
|
const last = elements[elements.length - 1];
|
|
518
585
|
if (!last || additions.length === 0) {
|
|
519
|
-
return
|
|
586
|
+
return retyped;
|
|
520
587
|
}
|
|
521
|
-
return [{ start: last.end, end: last.end, text: `, ${additions.join(', ')}` }];
|
|
588
|
+
return [...retyped, { start: last.end, end: last.end, text: `, ${additions.join(', ')}` }];
|
|
522
589
|
}
|
|
523
590
|
const items = [];
|
|
524
591
|
let isPlaced = false;
|
|
525
592
|
for (const element of elements) {
|
|
526
593
|
if (!removals.has(element)) {
|
|
527
|
-
items.push(element
|
|
594
|
+
items.push(textOf(element));
|
|
528
595
|
continue;
|
|
529
596
|
}
|
|
530
597
|
if (!isPlaced) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rewriter.js","sourceRoot":"","sources":["../../../../src/cli/codemod/namespace-functions/rewriter.ts"],"names":[],"mappings":";;;AA6CA;;;;;GAKG;AACH,MAAa,kBAAkB;IAC7B,MAAM,CAAC,OAAO,CAAC,IAKd;QACC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QACxD,MAAM,UAAU,GAAG,UAAU,CAAC,gBAAgB,CAC5C,QAAQ,EACR,MAAM,EACN,UAAU,CAAC,YAAY,CAAC,MAAM,EAC9B,IAAI,CACL,CAAC;QACF,MAAM,OAAO,GAAgC,EAAE,CAAC;QAEhD,MAAM,MAAM,GAAG,CAAC,UAA6C,EAAE,EAAE;YAC/D,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,UAAU,CAAC,6BAA6B,CAClE,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CACrC,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,GAAG,CAAC,EAAE,MAAM,EAAE,SA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AAI,MAAM,IAAI;YAC5B,CAAC,CAAC,GAAG,SAAS,IAAI,MAAM,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;IACvD,CAAC;CACF;AAnxBD,gDAmxBC","sourcesContent":["import type ts from 'typescript';\nimport type { INamespaceMapping } from './mapping';\n\ntype TTypeScript = typeof ts;\n\nexport interface INamespaceFunctionsReport {\n line: number;\n column: number;\n reason: string;\n}\n\nexport interface INamespaceFunctionsResult {\n output: string;\n changed: boolean;\n /** How many calls were rewritten. */\n rewritten: number;\n /** What the codemod found and left for a person, with where. */\n reports: INamespaceFunctionsReport[];\n}\n\ninterface IEdit {\n start: number;\n end: number;\n text: string;\n}\n\n/** One way the file reaches an old name: a named import of it, or a namespace import of its module. */\ninterface IBinding {\n mapping: INamespaceMapping;\n declaration: ts.ImportDeclaration;\n module: string;\n /** The local name: of the imported function, or of the namespace. */\n local: string;\n /** The identifier that declares `local`. */\n declarationName: ts.Identifier;\n /** The named import; `undefined` for `import * as name`. */\n specifier?: ts.ImportSpecifier;\n}\n\n/** A matched use of an old name: a call to rewrite, or any other use, which is reported. */\ninterface IUses {\n calls: ts.CallExpression[];\n values: ts.Node[];\n}\n\n/**\n * Rewrites the calls of functions that moved into a class, `oldName(a, b)` to\n * `ClassName.method({ first: a, second: b })`, from a mapping table. Syntactic: it reads one file and\n * needs no type checker, so it only follows names imported from a module the table lists. Every edit\n * is a text edit by position: the argument text, its comments and the untouched code stay as they are.\n */\nexport class NamespaceFunctions {\n static rewrite(opts: {\n typescript: TTypeScript;\n fileName: string;\n source: string;\n mappings: ReadonlyArray<INamespaceMapping>;\n }): INamespaceFunctionsResult {\n const { typescript, fileName, source, mappings } = opts;\n const sourceFile = typescript.createSourceFile(\n fileName,\n source,\n typescript.ScriptTarget.Latest,\n true,\n );\n const reports: INamespaceFunctionsReport[] = [];\n\n const report = (reportOpts: { node: ts.Node; reason: string }) => {\n const { line, character } = sourceFile.getLineAndCharacterOfPosition(\n reportOpts.node.getStart(sourceFile),\n );\n reports.push({ line: line + 1, column: character + 1, reason: reportOpts.reason });\n };\n\n const lineOf = (node: ts.Node) =>\n sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;\n\n const byModule = new Map<string, INamespaceMapping[]>();\n\n for (const mapping of mappings) {\n for (const module of mapping.modules) {\n byModule.set(module, [...(byModule.get(module) ?? []), mapping]);\n }\n }\n\n const bindings = NamespaceFunctions.findBindings({\n typescript,\n sourceFile,\n byModule,\n report,\n });\n\n if (bindings.length === 0) {\n return { output: source, changed: false, rewritten: 0, reports };\n }\n\n const identifiers = NamespaceFunctions.collectIdentifiers({ typescript, sourceFile });\n const declarationsOf = (name: string) =>\n (identifiers.get(name) ?? []).filter((identifier) =>\n NamespaceFunctions.isDeclarationName({ typescript, identifier }),\n );\n\n const edits: IEdit[] = [];\n const removals = new Set<ts.ImportSpecifier>();\n /** The imports that lose an old name. */\n const trimmed = new Set<ts.ImportDeclaration>();\n const additions = new Map<ts.ImportDeclaration, Set<string>>();\n const newImports = new Map<string, { anchor: ts.ImportDeclaration; names: Set<string> }>();\n /** The class names this run imports, and from which module. */\n const planned = new Map<string, string>();\n let rewritten = 0;\n\n for (const binding of bindings) {\n const { mapping } = binding;\n const uses = NamespaceFunctions.findUses({ typescript, binding, identifiers });\n\n if (uses.calls.length === 0 && uses.values.length === 0) {\n continue;\n }\n\n const target = NamespaceFunctions.describeTarget({ mapping });\n\n for (const value of uses.values) {\n report({\n node: value,\n reason: `\\`${mapping.oldName}\\` is used as a value (passed, stored, exported or in typeof), so its import stays; change it by hand to ${mapping.className}.${mapping.method}`,\n });\n }\n\n if (uses.calls.length === 0) {\n continue;\n }\n\n const shadow = declarationsOf(binding.local).find(\n (identifier) => identifier !== binding.declarationName,\n );\n\n if (shadow) {\n report({\n node: shadow,\n reason: `\\`${binding.local}\\` is declared again in this file, so a call cannot be told apart from the import; rewrite the calls of \\`${mapping.oldName}\\` by hand as ${target}`,\n });\n continue;\n }\n\n const classModules = mapping.newModules ?? [binding.module];\n const isNamespaceReach = !binding.specifier && classModules.includes(binding.module);\n let classReference = `${binding.local}.${mapping.className}`;\n let needsImport = false;\n\n if (!isNamespaceReach) {\n const existing = NamespaceFunctions.findClassImport({\n typescript,\n sourceFile,\n className: mapping.className,\n modules: classModules,\n });\n const plannedModule = planned.get(mapping.className);\n const conflict = existing\n ? declarationsOf(existing.text).find((identifier) => identifier !== existing)\n : plannedModule === undefined\n ? declarationsOf(mapping.className)[0]\n : undefined;\n\n if (conflict) {\n report({\n node: uses.calls[0] ?? conflict,\n reason: `the name \\`${conflict.text}\\` is already declared in this file (line ${lineOf(conflict)}), so \\`${mapping.oldName}\\` is left; rewrite its calls by hand as ${target}`,\n });\n continue;\n }\n\n if (!existing && plannedModule !== undefined && !classModules.includes(plannedModule)) {\n report({\n node: uses.calls[0] ?? binding.declaration,\n reason: `\\`${mapping.className}\\` would be imported from both ${plannedModule} and ${classModules[0]}; rewrite the calls of \\`${mapping.oldName}\\` by hand as ${target}`,\n });\n continue;\n }\n\n classReference = existing?.text ?? mapping.className;\n needsImport = !existing && plannedModule === undefined;\n }\n\n let count = 0;\n let left = uses.values.length;\n\n for (const call of uses.calls) {\n const problem = NamespaceFunctions.checkCall({ typescript, call, mapping });\n\n if (problem) {\n left += 1;\n report({ node: call, reason: `${problem}; rewrite it by hand as ${target}` });\n continue;\n }\n\n edits.push(\n ...NamespaceFunctions.planCall({\n typescript,\n sourceFile,\n call,\n mapping,\n callee: `${classReference}.${mapping.method}`,\n }),\n );\n count += 1;\n }\n\n rewritten += count;\n\n if (count === 0) {\n continue;\n }\n\n if (needsImport) {\n const sameDeclaration =\n binding.specifier && classModules.includes(binding.module)\n ? binding.declaration\n : undefined;\n const declaration =\n sameDeclaration ??\n NamespaceFunctions.findNamedImport({ typescript, sourceFile, modules: classModules });\n\n if (declaration) {\n additions.set(\n declaration,\n new Set([...(additions.get(declaration) ?? []), mapping.className]),\n );\n planned.set(\n mapping.className,\n sameDeclaration ? binding.module : NamespaceFunctions.moduleOf({ declaration }),\n );\n } else {\n const module = classModules[0] ?? binding.module;\n const entry = newImports.get(module) ?? {\n anchor: binding.declaration,\n names: new Set<string>(),\n };\n entry.names.add(mapping.className);\n newImports.set(module, entry);\n planned.set(mapping.className, module);\n }\n }\n\n if (binding.specifier && left === 0) {\n removals.add(binding.specifier);\n trimmed.add(binding.declaration);\n }\n }\n\n if (rewritten === 0) {\n return { output: source, changed: false, rewritten: 0, reports };\n }\n\n for (const declaration of new Set([...additions.keys(), ...trimmed])) {\n edits.push(\n ...NamespaceFunctions.planImport({\n typescript,\n sourceFile,\n declaration,\n removals,\n additions: [...(additions.get(declaration) ?? [])],\n report,\n }),\n );\n }\n\n for (const [module, { anchor, names }] of newImports) {\n const quote = source.charAt(anchor.moduleSpecifier.getStart(sourceFile));\n edits.push({\n start: anchor.getStart(sourceFile),\n end: anchor.getStart(sourceFile),\n text: `import { ${[...names].join(', ')} } from ${quote}${module}${quote};\\n`,\n });\n }\n\n // At one position a replacement (the longer range) is applied before an insertion, so the\n // inserted key of an outer call lands in front of the rewritten callee of an inner one.\n let output = source;\n\n for (const edit of edits.sort((a, b) => b.start - a.start || b.end - a.end)) {\n output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);\n }\n\n return { output, changed: output !== source, rewritten, reports };\n }\n\n /** The named and namespace imports of an old name; reports the type-only imports and the re-exports. */\n private static findBindings(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n byModule: Map<string, INamespaceMapping[]>;\n report: (reportOpts: { node: ts.Node; reason: string }) => void;\n }): IBinding[] {\n const { typescript, sourceFile, byModule, report } = opts;\n const bindings: IBinding[] = [];\n\n for (const statement of sourceFile.statements) {\n if (\n typescript.isExportDeclaration(statement) &&\n statement.moduleSpecifier &&\n typescript.isStringLiteral(statement.moduleSpecifier) &&\n statement.exportClause &&\n typescript.isNamedExports(statement.exportClause)\n ) {\n const candidates = byModule.get(statement.moduleSpecifier.text) ?? [];\n\n for (const element of statement.exportClause.elements) {\n const name = (element.propertyName ?? element.name).text;\n const mapping = candidates.find((candidate) => candidate.oldName === name);\n\n if (mapping) {\n report({\n node: element,\n reason: `re-exports \\`${name}\\`; re-export ${mapping.className} as well, by hand`,\n });\n }\n }\n\n continue;\n }\n\n if (\n !typescript.isImportDeclaration(statement) ||\n !typescript.isStringLiteral(statement.moduleSpecifier) ||\n !statement.importClause\n ) {\n continue;\n }\n\n const module = statement.moduleSpecifier.text;\n const candidates = byModule.get(module);\n const clause = statement.importClause;\n const named = clause.namedBindings;\n\n if (!candidates || !named) {\n continue;\n }\n\n if (typescript.isNamespaceImport(named)) {\n if (clause.isTypeOnly) {\n continue;\n }\n\n for (const mapping of candidates) {\n bindings.push({\n mapping,\n declaration: statement,\n module,\n local: named.name.text,\n declarationName: named.name,\n });\n }\n\n continue;\n }\n\n for (const element of named.elements) {\n const imported = (element.propertyName ?? element.name).text;\n const mapping = candidates.find((candidate) => candidate.oldName === imported);\n\n if (!mapping) {\n continue;\n }\n\n if (clause.isTypeOnly || element.isTypeOnly) {\n report({\n node: element,\n reason: `\\`${imported}\\` is imported as a type only; change it by hand to \\`typeof ${mapping.className}.${mapping.method}\\``,\n });\n continue;\n }\n\n bindings.push({\n mapping,\n declaration: statement,\n module,\n local: element.name.text,\n declarationName: element.name,\n specifier: element,\n });\n }\n }\n\n return bindings;\n }\n\n /** Every identifier of the file by its text; JSDoc is not walked, so a `{@link name}` never counts. */\n private static collectIdentifiers(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n }): Map<string, ts.Identifier[]> {\n const { typescript, sourceFile } = opts;\n const identifiers = new Map<string, ts.Identifier[]>();\n\n const walk = (node: ts.Node): void => {\n if (typescript.isIdentifier(node)) {\n identifiers.set(node.text, [...(identifiers.get(node.text) ?? []), node]);\n }\n\n typescript.forEachChild(node, walk);\n };\n\n walk(sourceFile);\n\n return identifiers;\n }\n\n /** The calls of the old name, and every other use of it. */\n private static findUses(opts: {\n typescript: TTypeScript;\n binding: IBinding;\n identifiers: Map<string, ts.Identifier[]>;\n }): IUses {\n const { typescript, binding, identifiers } = opts;\n const uses: IUses = { calls: [], values: [] };\n\n for (const identifier of identifiers.get(binding.local) ?? []) {\n if (\n identifier === binding.declarationName ||\n !NamespaceFunctions.isReference({ typescript, identifier })\n ) {\n continue;\n }\n\n if (!binding.specifier) {\n const parent = identifier.parent;\n const isMember =\n typescript.isPropertyAccessExpression(parent) &&\n parent.expression === identifier &&\n parent.name.text === binding.mapping.oldName;\n\n if (isMember) {\n const call = parent.parent;\n\n if (typescript.isCallExpression(call) && call.expression === parent) {\n uses.calls.push(call);\n } else {\n uses.values.push(parent);\n }\n\n continue;\n }\n\n if (\n typescript.isQualifiedName(parent) &&\n parent.left === identifier &&\n parent.right.text === binding.mapping.oldName\n ) {\n uses.values.push(parent);\n }\n\n continue;\n }\n\n const parent = identifier.parent;\n\n if (typescript.isCallExpression(parent) && parent.expression === identifier) {\n uses.calls.push(parent);\n continue;\n }\n\n uses.values.push(identifier);\n }\n\n return uses;\n }\n\n /** The identifier names a declaration: a variable, a parameter, a function, a class, an import, a type. */\n private static isDeclarationName(opts: {\n typescript: TTypeScript;\n identifier: ts.Identifier;\n }): boolean {\n const { typescript, identifier } = opts;\n const parent = identifier.parent;\n\n if (\n typescript.isVariableDeclaration(parent) ||\n typescript.isParameter(parent) ||\n typescript.isBindingElement(parent) ||\n typescript.isFunctionDeclaration(parent) ||\n typescript.isFunctionExpression(parent) ||\n typescript.isClassDeclaration(parent) ||\n typescript.isClassExpression(parent) ||\n typescript.isEnumDeclaration(parent) ||\n typescript.isInterfaceDeclaration(parent) ||\n typescript.isTypeAliasDeclaration(parent) ||\n typescript.isModuleDeclaration(parent) ||\n typescript.isImportSpecifier(parent) ||\n typescript.isImportClause(parent) ||\n typescript.isNamespaceImport(parent) ||\n typescript.isImportEqualsDeclaration(parent) ||\n typescript.isTypeParameterDeclaration(parent)\n ) {\n return parent.name === identifier;\n }\n\n return false;\n }\n\n /** The identifier reads a binding: not a property name, a label, a declaration or a lowercase JSX tag. */\n private static isReference(opts: {\n typescript: TTypeScript;\n identifier: ts.Identifier;\n }): boolean {\n const { typescript, identifier } = opts;\n const parent = identifier.parent;\n\n if (NamespaceFunctions.isDeclarationName({ typescript, identifier })) {\n return false;\n }\n\n if (typescript.isPropertyAccessExpression(parent) || typescript.isQualifiedName(parent)) {\n return typescript.isPropertyAccessExpression(parent)\n ? parent.name !== identifier\n : parent.right !== identifier;\n }\n\n if (\n typescript.isPropertyAssignment(parent) ||\n typescript.isPropertyDeclaration(parent) ||\n typescript.isPropertySignature(parent) ||\n typescript.isMethodDeclaration(parent) ||\n typescript.isMethodSignature(parent) ||\n typescript.isGetAccessorDeclaration(parent) ||\n typescript.isSetAccessorDeclaration(parent) ||\n typescript.isEnumMember(parent) ||\n typescript.isJsxAttribute(parent)\n ) {\n return parent.name !== identifier;\n }\n\n if (typescript.isBindingElement(parent)) {\n return parent.propertyName !== identifier;\n }\n\n if (typescript.isExportSpecifier(parent)) {\n return (\n !parent.parent.parent.moduleSpecifier && (parent.propertyName ?? parent.name) === identifier\n );\n }\n\n if (\n typescript.isLabeledStatement(parent) ||\n typescript.isBreakOrContinueStatement(parent) ||\n typescript.isMetaProperty(parent)\n ) {\n return false;\n }\n\n if (\n (typescript.isJsxOpeningElement(parent) ||\n typescript.isJsxSelfClosingElement(parent) ||\n typescript.isJsxClosingElement(parent)) &&\n parent.tagName === identifier\n ) {\n return !/^[a-z]/.test(identifier.text);\n }\n\n return true;\n }\n\n /** Why a call cannot be rewritten, or `undefined` when it can. */\n private static checkCall(opts: {\n typescript: TTypeScript;\n call: ts.CallExpression;\n mapping: INamespaceMapping;\n }): string | undefined {\n const { typescript, call, mapping } = opts;\n const { params, restKey, oldName } = mapping;\n const count = call.arguments.length;\n\n if (mapping.keepsOptions) {\n return undefined;\n }\n\n if (call.arguments.some((argument) => typescript.isSpreadElement(argument))) {\n return `this call of \\`${oldName}\\` has a spread argument`;\n }\n\n const required = params.reduce(\n (last, parameter, index) => (parameter.optional ? last : index + 1),\n 0,\n );\n\n if (count < required) {\n return `this call of \\`${oldName}\\` passes ${count} argument(s), fewer than the ${required} it needs`;\n }\n\n if (restKey === undefined && count > params.length) {\n return `this call of \\`${oldName}\\` passes ${count} argument(s), more than its ${params.length} parameter(s)`;\n }\n\n return undefined;\n }\n\n /** The edits that turn one call into the class form; the arguments keep their text and comments. */\n private static planCall(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n call: ts.CallExpression;\n mapping: INamespaceMapping;\n callee: string;\n }): IEdit[] {\n const { typescript, sourceFile, call, mapping, callee } = opts;\n const { params, restKey } = mapping;\n const edits: IEdit[] = [\n { start: call.expression.getStart(sourceFile), end: call.expression.end, text: callee },\n ];\n\n if (call.questionDotToken) {\n edits.push({\n start: call.questionDotToken.getStart(sourceFile),\n end: call.questionDotToken.end,\n text: '',\n });\n }\n\n if (mapping.keepsOptions) {\n return edits;\n }\n\n const argumentList = [...call.arguments];\n\n if (argumentList.length === 0) {\n if (params.length > 0 || restKey !== undefined) {\n const text = restKey === undefined ? '{}' : `{ ${restKey}: [] }`;\n edits.push({ start: call.arguments.pos, end: call.arguments.pos, text });\n }\n\n return edits;\n }\n\n const insert = (insertOpts: { at: number; text: string }) => {\n if (insertOpts.text !== '') {\n edits.push({ start: insertOpts.at, end: insertOpts.at, text: insertOpts.text });\n }\n };\n\n const positional = argumentList.slice(0, params.length);\n const rest = argumentList.slice(params.length);\n\n positional.forEach((argument, index) => {\n const key = params[index]?.key ?? '';\n const isShorthand = typescript.isIdentifier(argument) && argument.text === key;\n insert({\n at: argument.getStart(sourceFile),\n text: `${index === 0 ? '{ ' : ''}${isShorthand ? '' : `${key}: `}`,\n });\n });\n\n const first = rest[0];\n const last = argumentList[argumentList.length - 1];\n let suffix = ' }';\n\n if (first && restKey !== undefined) {\n insert({\n at: first.getStart(sourceFile),\n text: `${positional.length === 0 ? '{ ' : ''}${restKey}: [`,\n });\n suffix = '] }';\n } else if (restKey !== undefined) {\n suffix = `, ${restKey}: [] }`;\n }\n\n insert({ at: last?.end ?? call.arguments.end, text: suffix });\n\n return edits;\n }\n\n /** The local name of a value import of the class from one of `modules`. */\n private static findClassImport(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n className: string;\n modules: string[];\n }): ts.Identifier | undefined {\n const { typescript, sourceFile, className, modules } = opts;\n\n for (const statement of sourceFile.statements) {\n const declaration = NamespaceFunctions.asValueImport({ typescript, statement, modules });\n const named = declaration?.importClause?.namedBindings;\n\n if (!named || !typescript.isNamedImports(named)) {\n continue;\n }\n\n const element = named.elements.find(\n (candidate) =>\n !candidate.isTypeOnly && (candidate.propertyName ?? candidate.name).text === className,\n );\n\n if (element) {\n return element.name;\n }\n }\n\n return undefined;\n }\n\n /** The first value import with braces from one of `modules`, to add a class to. */\n static findNamedImport(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n modules: string[];\n }): ts.ImportDeclaration | undefined {\n const { typescript, sourceFile, modules } = opts;\n\n for (const statement of sourceFile.statements) {\n const declaration = NamespaceFunctions.asValueImport({ typescript, statement, modules });\n const named = declaration?.importClause?.namedBindings;\n\n if (declaration && named && typescript.isNamedImports(named)) {\n return declaration;\n }\n }\n\n return undefined;\n }\n\n /** `statement` as an import that is not `import type`, from one of `modules`. */\n private static asValueImport(opts: {\n typescript: TTypeScript;\n statement: ts.Statement;\n modules: string[];\n }): ts.ImportDeclaration | undefined {\n const { typescript, statement, modules } = opts;\n\n if (\n typescript.isImportDeclaration(statement) &&\n typescript.isStringLiteral(statement.moduleSpecifier) &&\n modules.includes(statement.moduleSpecifier.text) &&\n statement.importClause &&\n !statement.importClause.isTypeOnly\n ) {\n return statement;\n }\n\n return undefined;\n }\n\n private static moduleOf(opts: { declaration: ts.ImportDeclaration }): string {\n const specifier = opts.declaration.moduleSpecifier;\n\n return 'text' in specifier && typeof specifier.text === 'string' ? specifier.text : '';\n }\n\n /**\n * The edit of one import's braces: the removed old names go, the added classes take the place of\n * the first removed one. Braces that hold a comment are not rewritten: the classes are appended\n * and the old names stay, reported. An import left with nothing is removed.\n */\n static planImport(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n declaration: ts.ImportDeclaration;\n removals: Set<ts.ImportSpecifier>;\n additions: string[];\n report: (reportOpts: { node: ts.Node; reason: string }) => void;\n }): IEdit[] {\n const { typescript, sourceFile, declaration, removals, additions, report } = opts;\n const clause = declaration.importClause;\n const named = clause?.namedBindings;\n\n if (!clause || !named || !typescript.isNamedImports(named)) {\n return [];\n }\n\n const source = sourceFile.text;\n const elements = [...named.elements];\n const braces = source.slice(named.getStart(sourceFile), named.end);\n\n if (/\\/\\*|\\/\\//.test(braces)) {\n for (const element of elements.filter((candidate) => removals.has(candidate))) {\n report({\n node: element,\n reason: `the braces of this import hold a comment, so \\`${element.name.text}\\` stays imported; remove it by hand`,\n });\n }\n\n const last = elements[elements.length - 1];\n\n if (!last || additions.length === 0) {\n return [];\n }\n\n return [{ start: last.end, end: last.end, text: `, ${additions.join(', ')}` }];\n }\n\n const items: string[] = [];\n let isPlaced = false;\n\n for (const element of elements) {\n if (!removals.has(element)) {\n items.push(element.getText(sourceFile));\n continue;\n }\n\n if (!isPlaced) {\n items.push(...additions);\n isPlaced = true;\n }\n }\n\n if (!isPlaced) {\n items.push(...additions);\n }\n\n if (items.length > 0) {\n const start = named.getStart(sourceFile);\n const lineStart = source.lastIndexOf('\\n', declaration.getStart(sourceFile)) + 1;\n const indent = /^[ \\t]*/.exec(source.slice(lineStart))?.[0] ?? '';\n const text = braces.includes('\\n')\n ? `{\\n${indent} ${items.join(`,\\n${indent} `)},\\n${indent}}`\n : `{ ${items.join(', ')} }`;\n\n return [{ start, end: named.end, text }];\n }\n\n if (clause.name) {\n return [{ start: clause.name.end, end: named.end, text: '' }];\n }\n\n const start = declaration.getStart(sourceFile);\n const newline = /^\\r?\\n/.exec(source.slice(declaration.end))?.[0] ?? '';\n\n return [{ start, end: declaration.end + newline.length, text: '' }];\n }\n\n /** The call the old one becomes, for a report: `ParseUtility.toFloat({ input, digit })`. */\n private static describeTarget(opts: { mapping: INamespaceMapping }): string {\n const { className, method, params, restKey } = opts.mapping;\n const keys = [...params.map((parameter) => parameter.key), ...(restKey ? [restKey] : [])];\n\n return keys.length === 0\n ? `${className}.${method}()`\n : `${className}.${method}({ ${keys.join(', ')} })`;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"rewriter.js","sourceRoot":"","sources":["../../../../src/cli/codemod/namespace-functions/rewriter.ts"],"names":[],"mappings":";;;AAqDA;;;;;GAKG;AACH,MAAa,kBAAkB;IAC7B,MAAM,CAAC,OAAO,CAAC,IAKd;QACC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QACxD,MAAM,UAAU,GAAG,UAAU,CAAC,gBAAgB,CAC5C,QAAQ,EACR,MAAM,EACN,UAAU,CAAC,YAAY,CAAC,MAAM,EAC9B,IAAI,CACL,CAAC;QACF,MAAM,OAAO,GAAgC,EAAE,CAAC;QAEhD,MAAM,MAAM,GAAG,CAAC,UAA6C,EAAE,EAAE;YAC/D,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,UAAU,CAAC,6BAA6B,CAClE,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CACrC,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,GAAG,CAAC,EAAE,MAAM,EAAE,SAAS,GAAG,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;QACrF,CAAC,CAAC;QAEF,MAAM,MAAM,GAAG,CAAC,IAAa,EAAE,EAAE,CAC/B,UAAU,CAAC,6BAA6B,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC;QAE/E,MAAM,QAAQ,GAAG,IA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AChE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5D,MAAM,IAAI,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAE1F,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC;YACtB,CAAC,CAAC,GAAG,SAAS,IAAI,MAAM,IAAI;YAC5B,CAAC,CAAC,GAAG,SAAS,IAAI,MAAM,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;IACvD,CAAC;CACF;AAj3BD,gDAi3BC","sourcesContent":["import type ts from 'typescript';\nimport type { INamespaceMapping } from './mapping';\n\ntype TTypeScript = typeof ts;\n\nexport interface INamespaceFunctionsReport {\n line: number;\n column: number;\n reason: string;\n}\n\nexport interface INamespaceFunctionsResult {\n output: string;\n changed: boolean;\n /** How many calls were rewritten. */\n rewritten: number;\n /** What the codemod found and left for a person, with where. */\n reports: INamespaceFunctionsReport[];\n}\n\ninterface IEdit {\n start: number;\n end: number;\n text: string;\n}\n\n/** One way the file reaches an old name: a named import of it, or a namespace import of its module. */\ninterface IBinding {\n mapping: INamespaceMapping;\n declaration: ts.ImportDeclaration;\n module: string;\n /** The local name: of the imported function, or of the namespace. */\n local: string;\n /** The identifier that declares `local`. */\n declarationName: ts.Identifier;\n /** The named import; `undefined` for `import * as name`. */\n specifier?: ts.ImportSpecifier;\n}\n\n/** An import that brings a class in as a type only. */\ninterface IClassTypeImport {\n declaration: ts.ImportDeclaration;\n specifier: ts.ImportSpecifier;\n /** Whether the whole declaration is `import type`. */\n isWholeImport: boolean;\n}\n\n/** A matched use of an old name: a call to rewrite, or any other use, which is reported. */\ninterface IUses {\n calls: ts.CallExpression[];\n values: ts.Node[];\n}\n\n/**\n * Rewrites the calls of functions that moved into a class, `oldName(a, b)` to\n * `ClassName.method({ first: a, second: b })`, from a mapping table. Syntactic: it reads one file and\n * needs no type checker, so it only follows names imported from a module the table lists. Every edit\n * is a text edit by position: the argument text, its comments and the untouched code stay as they are.\n */\nexport class NamespaceFunctions {\n static rewrite(opts: {\n typescript: TTypeScript;\n fileName: string;\n source: string;\n mappings: ReadonlyArray<INamespaceMapping>;\n }): INamespaceFunctionsResult {\n const { typescript, fileName, source, mappings } = opts;\n const sourceFile = typescript.createSourceFile(\n fileName,\n source,\n typescript.ScriptTarget.Latest,\n true,\n );\n const reports: INamespaceFunctionsReport[] = [];\n\n const report = (reportOpts: { node: ts.Node; reason: string }) => {\n const { line, character } = sourceFile.getLineAndCharacterOfPosition(\n reportOpts.node.getStart(sourceFile),\n );\n reports.push({ line: line + 1, column: character + 1, reason: reportOpts.reason });\n };\n\n const lineOf = (node: ts.Node) =>\n sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;\n\n const byModule = new Map<string, INamespaceMapping[]>();\n\n for (const mapping of mappings) {\n for (const module of mapping.modules) {\n byModule.set(module, [...(byModule.get(module) ?? []), mapping]);\n }\n }\n\n const bindings = NamespaceFunctions.findBindings({\n typescript,\n sourceFile,\n byModule,\n report,\n });\n\n if (bindings.length === 0) {\n return { output: source, changed: false, rewritten: 0, reports };\n }\n\n const identifiers = NamespaceFunctions.collectIdentifiers({ typescript, sourceFile });\n const declarationsOf = (name: string) =>\n (identifiers.get(name) ?? []).filter((identifier) =>\n NamespaceFunctions.isDeclarationName({ typescript, identifier }),\n );\n\n const edits: IEdit[] = [];\n const removals = new Set<ts.ImportSpecifier>();\n /** The imports that lose an old name or the `type` of a class. */\n const trimmed = new Set<ts.ImportDeclaration>();\n /** The `type` imports of a class that a rewritten call needs as a value. */\n const untyped = new Set<ts.ImportSpecifier>();\n const additions = new Map<ts.ImportDeclaration, Set<string>>();\n const newImports = new Map<string, { anchor: ts.ImportDeclaration; names: Set<string> }>();\n /** The class names this run imports, and from which module. */\n const planned = new Map<string, string>();\n let rewritten = 0;\n\n for (const binding of bindings) {\n const { mapping } = binding;\n const uses = NamespaceFunctions.findUses({ typescript, binding, identifiers });\n\n if (uses.calls.length === 0 && uses.values.length === 0) {\n continue;\n }\n\n const target = NamespaceFunctions.describeTarget({ mapping });\n\n for (const value of uses.values) {\n report({\n node: value,\n reason: `\\`${mapping.oldName}\\` is used as a value (passed, stored, exported or in typeof), so its import stays; change it by hand to ${mapping.className}.${mapping.method}`,\n });\n }\n\n if (uses.calls.length === 0) {\n continue;\n }\n\n const shadow = declarationsOf(binding.local).find(\n (identifier) => identifier !== binding.declarationName,\n );\n\n if (shadow) {\n report({\n node: shadow,\n reason: `\\`${binding.local}\\` is declared again in this file, so a call cannot be told apart from the import; rewrite the calls of \\`${mapping.oldName}\\` by hand as ${target}`,\n });\n continue;\n }\n\n // Every entry a type guard row lists exports the same class, so a class imported from one serves them all.\n const classModules =\n mapping.newModules ?? (mapping.isTypeGuard ? mapping.modules : [binding.module]);\n const isNamespaceReach = !binding.specifier && classModules.includes(binding.module);\n let classReference = `${binding.local}.${mapping.className}`;\n let needsImport = false;\n let typeImport: IClassTypeImport | undefined;\n\n if (!isNamespaceReach) {\n const valueImport = NamespaceFunctions.findClassImport({\n typescript,\n sourceFile,\n className: mapping.className,\n modules: classModules,\n });\n typeImport =\n valueImport || !mapping.isTypeGuard\n ? undefined\n : NamespaceFunctions.findClassTypeImport({\n typescript,\n sourceFile,\n className: mapping.className,\n modules: classModules,\n });\n // An `import type { ClassName }` brings no value: the class moves to a value import.\n const existing =\n valueImport ?? (typeImport?.isWholeImport ? undefined : typeImport?.specifier.name);\n const plannedModule = planned.get(mapping.className);\n const conflict = existing\n ? declarationsOf(existing.text).find((identifier) => identifier !== existing)\n : plannedModule === undefined\n ? declarationsOf(mapping.className).find(\n (identifier) => identifier !== typeImport?.specifier.name,\n )\n : undefined;\n\n if (conflict) {\n report({\n node: uses.calls[0] ?? conflict,\n reason: `the name \\`${conflict.text}\\` is already declared in this file (line ${lineOf(conflict)}), so \\`${mapping.oldName}\\` is left; rewrite its calls by hand as ${target}`,\n });\n continue;\n }\n\n if (!existing && plannedModule !== undefined && !classModules.includes(plannedModule)) {\n report({\n node: uses.calls[0] ?? binding.declaration,\n reason: `\\`${mapping.className}\\` would be imported from both ${plannedModule} and ${classModules[0]}; rewrite the calls of \\`${mapping.oldName}\\` by hand as ${target}`,\n });\n continue;\n }\n\n classReference = existing?.text ?? mapping.className;\n needsImport = !existing && plannedModule === undefined;\n }\n\n let count = 0;\n let left = uses.values.length;\n\n for (const call of uses.calls) {\n const problem = NamespaceFunctions.checkCall({ typescript, call, mapping });\n\n if (problem) {\n left += 1;\n report({ node: call, reason: `${problem}; rewrite it by hand as ${target}` });\n continue;\n }\n\n edits.push(\n ...NamespaceFunctions.planCall({\n typescript,\n sourceFile,\n call,\n mapping,\n callee: `${classReference}.${mapping.method}`,\n }),\n );\n count += 1;\n }\n\n rewritten += count;\n\n if (count === 0) {\n continue;\n }\n\n if (typeImport) {\n (typeImport.isWholeImport ? removals : untyped).add(typeImport.specifier);\n trimmed.add(typeImport.declaration);\n }\n\n if (needsImport) {\n const sameDeclaration =\n binding.specifier && classModules.includes(binding.module)\n ? binding.declaration\n : undefined;\n const declaration =\n sameDeclaration ??\n NamespaceFunctions.findNamedImport({ typescript, sourceFile, modules: classModules });\n\n if (declaration) {\n additions.set(\n declaration,\n new Set([...(additions.get(declaration) ?? []), mapping.className]),\n );\n planned.set(\n mapping.className,\n sameDeclaration ? binding.module : NamespaceFunctions.moduleOf({ declaration }),\n );\n } else {\n const module = mapping.newModules?.[0] ?? binding.module;\n const entry = newImports.get(module) ?? {\n anchor: binding.declaration,\n names: new Set<string>(),\n };\n entry.names.add(mapping.className);\n newImports.set(module, entry);\n planned.set(mapping.className, module);\n }\n }\n\n if (binding.specifier && left === 0) {\n removals.add(binding.specifier);\n trimmed.add(binding.declaration);\n }\n }\n\n if (rewritten === 0) {\n return { output: source, changed: false, rewritten: 0, reports };\n }\n\n for (const declaration of new Set([...additions.keys(), ...trimmed])) {\n edits.push(\n ...NamespaceFunctions.planImport({\n typescript,\n sourceFile,\n declaration,\n removals,\n untyped,\n additions: [...(additions.get(declaration) ?? [])],\n report,\n }),\n );\n }\n\n for (const [module, { anchor, names }] of newImports) {\n const quote = source.charAt(anchor.moduleSpecifier.getStart(sourceFile));\n edits.push({\n start: anchor.getStart(sourceFile),\n end: anchor.getStart(sourceFile),\n text: `import { ${[...names].join(', ')} } from ${quote}${module}${quote};\\n`,\n });\n }\n\n // At one position a replacement (the longer range) is applied before an insertion, so the\n // inserted key of an outer call lands in front of the rewritten callee of an inner one.\n let output = source;\n\n for (const edit of edits.sort((a, b) => b.start - a.start || b.end - a.end)) {\n output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);\n }\n\n return { output, changed: output !== source, rewritten, reports };\n }\n\n /** The named and namespace imports of an old name; reports the type-only imports and the re-exports. */\n private static findBindings(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n byModule: Map<string, INamespaceMapping[]>;\n report: (reportOpts: { node: ts.Node; reason: string }) => void;\n }): IBinding[] {\n const { typescript, sourceFile, byModule, report } = opts;\n const bindings: IBinding[] = [];\n\n for (const statement of sourceFile.statements) {\n if (\n typescript.isExportDeclaration(statement) &&\n statement.moduleSpecifier &&\n typescript.isStringLiteral(statement.moduleSpecifier) &&\n statement.exportClause &&\n typescript.isNamedExports(statement.exportClause)\n ) {\n const candidates = byModule.get(statement.moduleSpecifier.text) ?? [];\n\n for (const element of statement.exportClause.elements) {\n const name = (element.propertyName ?? element.name).text;\n const mapping = candidates.find((candidate) => candidate.oldName === name);\n\n if (mapping) {\n report({\n node: element,\n reason: `re-exports \\`${name}\\`; re-export ${mapping.className} as well, by hand`,\n });\n }\n }\n\n continue;\n }\n\n if (\n !typescript.isImportDeclaration(statement) ||\n !typescript.isStringLiteral(statement.moduleSpecifier) ||\n !statement.importClause\n ) {\n continue;\n }\n\n const module = statement.moduleSpecifier.text;\n const candidates = byModule.get(module);\n const clause = statement.importClause;\n const named = clause.namedBindings;\n\n if (!candidates || !named) {\n continue;\n }\n\n if (typescript.isNamespaceImport(named)) {\n if (clause.isTypeOnly) {\n continue;\n }\n\n for (const mapping of candidates) {\n bindings.push({\n mapping,\n declaration: statement,\n module,\n local: named.name.text,\n declarationName: named.name,\n });\n }\n\n continue;\n }\n\n for (const element of named.elements) {\n const imported = (element.propertyName ?? element.name).text;\n const mapping = candidates.find((candidate) => candidate.oldName === imported);\n\n if (!mapping) {\n continue;\n }\n\n if (clause.isTypeOnly || element.isTypeOnly) {\n report({\n node: element,\n reason: `\\`${imported}\\` is imported as a type only; change it by hand to \\`typeof ${mapping.className}.${mapping.method}\\``,\n });\n continue;\n }\n\n bindings.push({\n mapping,\n declaration: statement,\n module,\n local: element.name.text,\n declarationName: element.name,\n specifier: element,\n });\n }\n }\n\n return bindings;\n }\n\n /** Every identifier of the file by its text; JSDoc is not walked, so a `{@link name}` never counts. */\n private static collectIdentifiers(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n }): Map<string, ts.Identifier[]> {\n const { typescript, sourceFile } = opts;\n const identifiers = new Map<string, ts.Identifier[]>();\n\n const walk = (node: ts.Node): void => {\n if (typescript.isIdentifier(node)) {\n identifiers.set(node.text, [...(identifiers.get(node.text) ?? []), node]);\n }\n\n typescript.forEachChild(node, walk);\n };\n\n walk(sourceFile);\n\n return identifiers;\n }\n\n /** The calls of the old name, and every other use of it. */\n private static findUses(opts: {\n typescript: TTypeScript;\n binding: IBinding;\n identifiers: Map<string, ts.Identifier[]>;\n }): IUses {\n const { typescript, binding, identifiers } = opts;\n const uses: IUses = { calls: [], values: [] };\n\n for (const identifier of identifiers.get(binding.local) ?? []) {\n if (\n identifier === binding.declarationName ||\n !NamespaceFunctions.isReference({ typescript, identifier })\n ) {\n continue;\n }\n\n if (!binding.specifier) {\n const parent = identifier.parent;\n const isMember =\n typescript.isPropertyAccessExpression(parent) &&\n parent.expression === identifier &&\n parent.name.text === binding.mapping.oldName;\n\n if (isMember) {\n const call = parent.parent;\n\n if (typescript.isCallExpression(call) && call.expression === parent) {\n uses.calls.push(call);\n } else {\n uses.values.push(parent);\n }\n\n continue;\n }\n\n if (\n typescript.isQualifiedName(parent) &&\n parent.left === identifier &&\n parent.right.text === binding.mapping.oldName\n ) {\n uses.values.push(parent);\n }\n\n continue;\n }\n\n const parent = identifier.parent;\n\n if (typescript.isCallExpression(parent) && parent.expression === identifier) {\n uses.calls.push(parent);\n continue;\n }\n\n uses.values.push(identifier);\n }\n\n return uses;\n }\n\n /** The identifier names a declaration: a variable, a parameter, a function, a class, an import, a type. */\n private static isDeclarationName(opts: {\n typescript: TTypeScript;\n identifier: ts.Identifier;\n }): boolean {\n const { typescript, identifier } = opts;\n const parent = identifier.parent;\n\n if (\n typescript.isVariableDeclaration(parent) ||\n typescript.isParameter(parent) ||\n typescript.isBindingElement(parent) ||\n typescript.isFunctionDeclaration(parent) ||\n typescript.isFunctionExpression(parent) ||\n typescript.isClassDeclaration(parent) ||\n typescript.isClassExpression(parent) ||\n typescript.isEnumDeclaration(parent) ||\n typescript.isInterfaceDeclaration(parent) ||\n typescript.isTypeAliasDeclaration(parent) ||\n typescript.isModuleDeclaration(parent) ||\n typescript.isImportSpecifier(parent) ||\n typescript.isImportClause(parent) ||\n typescript.isNamespaceImport(parent) ||\n typescript.isImportEqualsDeclaration(parent) ||\n typescript.isTypeParameterDeclaration(parent)\n ) {\n return parent.name === identifier;\n }\n\n return false;\n }\n\n /** The identifier reads a binding: not a property name, a label, a declaration or a lowercase JSX tag. */\n private static isReference(opts: {\n typescript: TTypeScript;\n identifier: ts.Identifier;\n }): boolean {\n const { typescript, identifier } = opts;\n const parent = identifier.parent;\n\n if (NamespaceFunctions.isDeclarationName({ typescript, identifier })) {\n return false;\n }\n\n if (typescript.isPropertyAccessExpression(parent) || typescript.isQualifiedName(parent)) {\n return typescript.isPropertyAccessExpression(parent)\n ? parent.name !== identifier\n : parent.right !== identifier;\n }\n\n if (\n typescript.isPropertyAssignment(parent) ||\n typescript.isPropertyDeclaration(parent) ||\n typescript.isPropertySignature(parent) ||\n typescript.isMethodDeclaration(parent) ||\n typescript.isMethodSignature(parent) ||\n typescript.isGetAccessorDeclaration(parent) ||\n typescript.isSetAccessorDeclaration(parent) ||\n typescript.isEnumMember(parent) ||\n typescript.isJsxAttribute(parent)\n ) {\n return parent.name !== identifier;\n }\n\n if (typescript.isBindingElement(parent)) {\n return parent.propertyName !== identifier;\n }\n\n // `isClass` of `import { isClass as other }` names the export, not a binding of this file.\n if (typescript.isImportSpecifier(parent)) {\n return false;\n }\n\n if (typescript.isExportSpecifier(parent)) {\n return (\n !parent.parent.parent.moduleSpecifier && (parent.propertyName ?? parent.name) === identifier\n );\n }\n\n if (\n typescript.isLabeledStatement(parent) ||\n typescript.isBreakOrContinueStatement(parent) ||\n typescript.isMetaProperty(parent)\n ) {\n return false;\n }\n\n if (\n (typescript.isJsxOpeningElement(parent) ||\n typescript.isJsxSelfClosingElement(parent) ||\n typescript.isJsxClosingElement(parent)) &&\n parent.tagName === identifier\n ) {\n return !/^[a-z]/.test(identifier.text);\n }\n\n return true;\n }\n\n /** Why a call cannot be rewritten, or `undefined` when it can. */\n private static checkCall(opts: {\n typescript: TTypeScript;\n call: ts.CallExpression;\n mapping: INamespaceMapping;\n }): string | undefined {\n const { typescript, call, mapping } = opts;\n const { params, restKey, oldName } = mapping;\n const count = call.arguments.length;\n\n if (mapping.keepsOptions) {\n return undefined;\n }\n\n if (call.arguments.some((argument) => typescript.isSpreadElement(argument))) {\n return `this call of \\`${oldName}\\` has a spread argument`;\n }\n\n const required = params.reduce(\n (last, parameter, index) => (parameter.optional ? last : index + 1),\n 0,\n );\n\n if (count < required) {\n return `this call of \\`${oldName}\\` passes ${count} argument(s), fewer than the ${required} it needs`;\n }\n\n if (restKey === undefined && count > params.length) {\n return `this call of \\`${oldName}\\` passes ${count} argument(s), more than its ${params.length} parameter(s)`;\n }\n\n return undefined;\n }\n\n /** The edits that turn one call into the class form; the arguments keep their text and comments. */\n private static planCall(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n call: ts.CallExpression;\n mapping: INamespaceMapping;\n callee: string;\n }): IEdit[] {\n const { typescript, sourceFile, call, mapping, callee } = opts;\n const { params, restKey } = mapping;\n const edits: IEdit[] = [\n { start: call.expression.getStart(sourceFile), end: call.expression.end, text: callee },\n ];\n\n if (call.questionDotToken) {\n edits.push({\n start: call.questionDotToken.getStart(sourceFile),\n end: call.questionDotToken.end,\n text: '',\n });\n }\n\n if (mapping.keepsOptions) {\n return edits;\n }\n\n const argumentList = [...call.arguments];\n\n if (argumentList.length === 0) {\n if (params.length > 0 || restKey !== undefined) {\n const text = restKey === undefined ? '{}' : `{ ${restKey}: [] }`;\n edits.push({ start: call.arguments.pos, end: call.arguments.pos, text });\n }\n\n return edits;\n }\n\n const insert = (insertOpts: { at: number; text: string }) => {\n if (insertOpts.text !== '') {\n edits.push({ start: insertOpts.at, end: insertOpts.at, text: insertOpts.text });\n }\n };\n\n const positional = argumentList.slice(0, params.length);\n const rest = argumentList.slice(params.length);\n\n positional.forEach((argument, index) => {\n const key = params[index]?.key ?? '';\n const isShorthand = typescript.isIdentifier(argument) && argument.text === key;\n insert({\n at: argument.getStart(sourceFile),\n text: `${index === 0 ? '{ ' : ''}${isShorthand ? '' : `${key}: `}`,\n });\n });\n\n const first = rest[0];\n const last = argumentList[argumentList.length - 1];\n let suffix = ' }';\n\n if (first && restKey !== undefined) {\n insert({\n at: first.getStart(sourceFile),\n text: `${positional.length === 0 ? '{ ' : ''}${restKey}: [`,\n });\n suffix = '] }';\n } else if (restKey !== undefined) {\n suffix = `, ${restKey}: [] }`;\n }\n\n insert({ at: last?.end ?? call.arguments.end, text: suffix });\n\n return edits;\n }\n\n /** The local name of a value import of the class from one of `modules`. */\n private static findClassImport(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n className: string;\n modules: string[];\n }): ts.Identifier | undefined {\n const { typescript, sourceFile, className, modules } = opts;\n\n for (const statement of sourceFile.statements) {\n const declaration = NamespaceFunctions.asValueImport({ typescript, statement, modules });\n const named = declaration?.importClause?.namedBindings;\n\n if (!named || !typescript.isNamedImports(named)) {\n continue;\n }\n\n const element = named.elements.find(\n (candidate) =>\n !candidate.isTypeOnly && (candidate.propertyName ?? candidate.name).text === className,\n );\n\n if (element) {\n return element.name;\n }\n }\n\n return undefined;\n }\n\n /**\n * The import that brings the class in from `modules` as a type only: a `{ type ClassName }` specifier of a value\n * import, else an unaliased name of an `import type`.\n */\n private static findClassTypeImport(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n className: string;\n modules: string[];\n }): IClassTypeImport | undefined {\n const { typescript, sourceFile, className, modules } = opts;\n let wholeImport: IClassTypeImport | undefined;\n\n for (const statement of sourceFile.statements) {\n if (\n !typescript.isImportDeclaration(statement) ||\n !typescript.isStringLiteral(statement.moduleSpecifier) ||\n !modules.includes(statement.moduleSpecifier.text)\n ) {\n continue;\n }\n\n const clause = statement.importClause;\n const named = clause?.namedBindings;\n\n if (!clause || !named || !typescript.isNamedImports(named)) {\n continue;\n }\n\n const isWholeImport = clause.isTypeOnly;\n const specifier = named.elements.find((candidate) =>\n isWholeImport\n ? !candidate.propertyName && candidate.name.text === className\n : candidate.isTypeOnly && (candidate.propertyName ?? candidate.name).text === className,\n );\n\n if (!specifier) {\n continue;\n }\n\n if (!isWholeImport) {\n return { declaration: statement, specifier, isWholeImport };\n }\n\n wholeImport ??= { declaration: statement, specifier, isWholeImport };\n }\n\n return wholeImport;\n }\n\n /** The first value import with braces from one of `modules`, to add a class to. */\n static findNamedImport(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n modules: string[];\n }): ts.ImportDeclaration | undefined {\n const { typescript, sourceFile, modules } = opts;\n\n for (const statement of sourceFile.statements) {\n const declaration = NamespaceFunctions.asValueImport({ typescript, statement, modules });\n const named = declaration?.importClause?.namedBindings;\n\n if (declaration && named && typescript.isNamedImports(named)) {\n return declaration;\n }\n }\n\n return undefined;\n }\n\n /** `statement` as an import that is not `import type`, from one of `modules`. */\n private static asValueImport(opts: {\n typescript: TTypeScript;\n statement: ts.Statement;\n modules: string[];\n }): ts.ImportDeclaration | undefined {\n const { typescript, statement, modules } = opts;\n\n if (\n typescript.isImportDeclaration(statement) &&\n typescript.isStringLiteral(statement.moduleSpecifier) &&\n modules.includes(statement.moduleSpecifier.text) &&\n statement.importClause &&\n !statement.importClause.isTypeOnly\n ) {\n return statement;\n }\n\n return undefined;\n }\n\n private static moduleOf(opts: { declaration: ts.ImportDeclaration }): string {\n const specifier = opts.declaration.moduleSpecifier;\n\n return 'text' in specifier && typeof specifier.text === 'string' ? specifier.text : '';\n }\n\n /**\n * The edit of one import's braces: the removed old names go, the added classes take the place of\n * the first removed one. Braces that hold a comment are not rewritten: the classes are appended\n * and the old names stay, reported. An import left with nothing is removed.\n */\n static planImport(opts: {\n typescript: TTypeScript;\n sourceFile: ts.SourceFile;\n declaration: ts.ImportDeclaration;\n removals: Set<ts.ImportSpecifier>;\n /** Specifiers that lose their `type`. */\n untyped?: Set<ts.ImportSpecifier>;\n additions: string[];\n report: (reportOpts: { node: ts.Node; reason: string }) => void;\n }): IEdit[] {\n const { typescript, sourceFile, declaration, removals, additions, report } = opts;\n const untyped = opts.untyped ?? new Set<ts.ImportSpecifier>();\n const clause = declaration.importClause;\n const named = clause?.namedBindings;\n\n if (!clause || !named || !typescript.isNamedImports(named)) {\n return [];\n }\n\n const source = sourceFile.text;\n const elements = [...named.elements];\n const braces = source.slice(named.getStart(sourceFile), named.end);\n const textOf = (element: ts.ImportSpecifier) =>\n untyped.has(element)\n ? source.slice((element.propertyName ?? element.name).getStart(sourceFile), element.end)\n : element.getText(sourceFile);\n\n if (/\\/\\*|\\/\\//.test(braces)) {\n for (const element of elements.filter((candidate) => removals.has(candidate))) {\n report({\n node: element,\n reason: `the braces of this import hold a comment, so \\`${element.name.text}\\` stays imported; remove it by hand`,\n });\n }\n\n const retyped = elements\n .filter((candidate) => untyped.has(candidate))\n .map((element) => ({\n start: element.getStart(sourceFile),\n end: element.end,\n text: textOf(element),\n }));\n const last = elements[elements.length - 1];\n\n if (!last || additions.length === 0) {\n return retyped;\n }\n\n return [...retyped, { start: last.end, end: last.end, text: `, ${additions.join(', ')}` }];\n }\n\n const items: string[] = [];\n let isPlaced = false;\n\n for (const element of elements) {\n if (!removals.has(element)) {\n items.push(textOf(element));\n continue;\n }\n\n if (!isPlaced) {\n items.push(...additions);\n isPlaced = true;\n }\n }\n\n if (!isPlaced) {\n items.push(...additions);\n }\n\n if (items.length > 0) {\n const start = named.getStart(sourceFile);\n const lineStart = source.lastIndexOf('\\n', declaration.getStart(sourceFile)) + 1;\n const indent = /^[ \\t]*/.exec(source.slice(lineStart))?.[0] ?? '';\n const text = braces.includes('\\n')\n ? `{\\n${indent} ${items.join(`,\\n${indent} `)},\\n${indent}}`\n : `{ ${items.join(', ')} }`;\n\n return [{ start, end: named.end, text }];\n }\n\n if (clause.name) {\n return [{ start: clause.name.end, end: named.end, text: '' }];\n }\n\n const start = declaration.getStart(sourceFile);\n const newline = /^\\r?\\n/.exec(source.slice(declaration.end))?.[0] ?? '';\n\n return [{ start, end: declaration.end + newline.length, text: '' }];\n }\n\n /** The call the old one becomes, for a report: `ParseUtility.toFloat({ input, digit })`. */\n private static describeTarget(opts: { mapping: INamespaceMapping }): string {\n const { className, method, params, restKey } = opts.mapping;\n const keys = [...params.map((parameter) => parameter.key), ...(restKey ? [restKey] : [])];\n\n return keys.length === 0\n ? `${className}.${method}()`\n : `${className}.${method}({ ${keys.join(', ')} })`;\n }\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { IClassRename, ICodemodRewrite } from './class-renames';
|
|
2
|
+
export declare class PublicNamesTable {
|
|
3
|
+
static readonly TYPE_ROWS: ReadonlyArray<IClassRename>;
|
|
4
|
+
}
|
|
5
|
+
export declare class PublicNames {
|
|
6
|
+
/** Whether `specifier` exports `name` as one of the old names this codemod moves. */
|
|
7
|
+
private static isOldName;
|
|
8
|
+
/** The `import x = require('...')` lines of a `.cts` file whose `x` reaches an old name: neither pass rewrites them. */
|
|
9
|
+
private static findRequireImports;
|
|
10
|
+
/** The guards first: the type pass reads their output, so both land in one write. */
|
|
11
|
+
static rewrite(opts: {
|
|
12
|
+
typescript: typeof import('typescript');
|
|
13
|
+
fileName: string;
|
|
14
|
+
source: string;
|
|
15
|
+
}): ICodemodRewrite;
|
|
16
|
+
}
|
|
17
|
+
/** `devz codemod public-names [paths...]`: the type and type guard renames, with the file handling of `class-renames`. */
|
|
18
|
+
export declare class PublicNamesCommand {
|
|
19
|
+
static readonly USAGE = "Usage: devz codemod public-names [paths...] [--write [--all] | --check]\n\nOne run for the public renames of types and type guards:\n\n - ValueOf -> TValueOf, ValueOrPromise -> TValueOrPromise, TConstructor -> TClass,\n TAbstractConstructor -> TAbstractClass, imported from @venizia/ignis-inversion, @venizia/ignis-helpers\n (and /common) or @venizia/ignis. An aliased import keeps its alias.\n - a type guard function becomes a static method of the same name, such as isPromiseLike(value) ->\n Execution.isPromiseLike(value). The table is in namespace-functions/mappings/guards.ts.\n\nA name your file declares itself, or imports from another package, is left alone. It reads .ts, .tsx, .mts and\n.cts files. It lists, with the line, and leaves to you: a guard used as a value (passed to filter, in typeof),\na re-export or a type-only import of a guard, a type whose name is declared again further down the file, an\n\"import x = require('...')\" that reaches an old name through x. It does\nnot list, so run your typecheck afterwards: .js files, import('pkg').Name, a guard read from a namespace import\nof a package that does not export its class, and a name that reaches a file through a barrel of your own.\n\n --write write the changed files (without it, nothing is written); it needs a path, or --all\n --all with --write and no path: rewrite every source file under the working directory\n --check dry run that exits 1 while a file would change or a line is left to you (for CI)\n --help print this text and exit\n\nThere is no --reverse: TConstructor and TClass became one name.";
|
|
20
|
+
static run(opts: {
|
|
21
|
+
root: string;
|
|
22
|
+
args: string[];
|
|
23
|
+
}): Promise<number>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=public-names.d.ts.map
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PublicNamesCommand = exports.PublicNames = exports.PublicNamesTable = void 0;
|
|
4
|
+
const class_renames_1 = require("./class-renames");
|
|
5
|
+
const guards_1 = require("./namespace-functions/mappings/guards");
|
|
6
|
+
const rewriter_1 = require("./namespace-functions/rewriter");
|
|
7
|
+
const USAGE = `Usage: devz codemod public-names [paths...] [--write [--all] | --check]
|
|
8
|
+
|
|
9
|
+
One run for the public renames of types and type guards:
|
|
10
|
+
|
|
11
|
+
- ValueOf -> TValueOf, ValueOrPromise -> TValueOrPromise, TConstructor -> TClass,
|
|
12
|
+
TAbstractConstructor -> TAbstractClass, imported from @venizia/ignis-inversion, @venizia/ignis-helpers
|
|
13
|
+
(and /common) or @venizia/ignis. An aliased import keeps its alias.
|
|
14
|
+
- a type guard function becomes a static method of the same name, such as isPromiseLike(value) ->
|
|
15
|
+
Execution.isPromiseLike(value). The table is in namespace-functions/mappings/guards.ts.
|
|
16
|
+
|
|
17
|
+
A name your file declares itself, or imports from another package, is left alone. It reads .ts, .tsx, .mts and
|
|
18
|
+
.cts files. It lists, with the line, and leaves to you: a guard used as a value (passed to filter, in typeof),
|
|
19
|
+
a re-export or a type-only import of a guard, a type whose name is declared again further down the file, an
|
|
20
|
+
"import x = require('...')" that reaches an old name through x. It does
|
|
21
|
+
not list, so run your typecheck afterwards: .js files, import('pkg').Name, a guard read from a namespace import
|
|
22
|
+
of a package that does not export its class, and a name that reaches a file through a barrel of your own.
|
|
23
|
+
|
|
24
|
+
--write write the changed files (without it, nothing is written); it needs a path, or --all
|
|
25
|
+
--all with --write and no path: rewrite every source file under the working directory
|
|
26
|
+
--check dry run that exits 1 while a file would change or a line is left to you (for CI)
|
|
27
|
+
--help print this text and exit
|
|
28
|
+
|
|
29
|
+
There is no --reverse: TConstructor and TClass became one name.`;
|
|
30
|
+
/** The packages that export the renamed types; their sub-paths count. */
|
|
31
|
+
const TYPE_PACKAGES = ['@venizia/ignis-inversion', '@venizia/ignis-helpers', '@venizia/ignis'];
|
|
32
|
+
class PublicNamesTable {
|
|
33
|
+
static { this.TYPE_ROWS = [
|
|
34
|
+
{ oldName: 'ValueOf', newName: 'TValueOf', packages: TYPE_PACKAGES },
|
|
35
|
+
{ oldName: 'ValueOrPromise', newName: 'TValueOrPromise', packages: TYPE_PACKAGES },
|
|
36
|
+
{ oldName: 'TConstructor', newName: 'TClass', packages: TYPE_PACKAGES },
|
|
37
|
+
{ oldName: 'TAbstractConstructor', newName: 'TAbstractClass', packages: TYPE_PACKAGES },
|
|
38
|
+
]; }
|
|
39
|
+
}
|
|
40
|
+
exports.PublicNamesTable = PublicNamesTable;
|
|
41
|
+
class PublicNames {
|
|
42
|
+
/** Whether `specifier` exports `name` as one of the old names this codemod moves. */
|
|
43
|
+
static isOldName(opts) {
|
|
44
|
+
const { specifier, name } = opts;
|
|
45
|
+
return (guards_1.GUARD_MAPPINGS.some((mapping) => mapping.oldName === name && mapping.modules.includes(specifier)) ||
|
|
46
|
+
PublicNamesTable.TYPE_ROWS.some((row) => row.oldName === name &&
|
|
47
|
+
row.packages.some((owner) => specifier === owner || specifier.startsWith(`${owner}/`))));
|
|
48
|
+
}
|
|
49
|
+
/** The `import x = require('...')` lines of a `.cts` file whose `x` reaches an old name: neither pass rewrites them. */
|
|
50
|
+
static findRequireImports(opts) {
|
|
51
|
+
const { typescript: ts, fileName, source } = opts;
|
|
52
|
+
const file = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true);
|
|
53
|
+
const reached = new Map();
|
|
54
|
+
const walk = (node) => {
|
|
55
|
+
const pair = ts.isPropertyAccessExpression(node)
|
|
56
|
+
? [node.expression, node.name]
|
|
57
|
+
: ts.isQualifiedName(node)
|
|
58
|
+
? [node.left, node.right]
|
|
59
|
+
: undefined;
|
|
60
|
+
const [scope, member] = pair ?? [];
|
|
61
|
+
if (scope && member && ts.isIdentifier(scope)) {
|
|
62
|
+
reached.set(scope.text, (reached.get(scope.text) ?? new Set()).add(member.getText(file)));
|
|
63
|
+
}
|
|
64
|
+
ts.forEachChild(node, walk);
|
|
65
|
+
};
|
|
66
|
+
walk(file);
|
|
67
|
+
return file.statements.flatMap((statement) => {
|
|
68
|
+
if (!ts.isImportEqualsDeclaration(statement) ||
|
|
69
|
+
!ts.isExternalModuleReference(statement.moduleReference) ||
|
|
70
|
+
!ts.isStringLiteralLike(statement.moduleReference.expression)) {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
const specifier = statement.moduleReference.expression.text;
|
|
74
|
+
const names = [...(reached.get(statement.name.text) ?? [])].filter((name) => PublicNames.isOldName({ specifier, name }));
|
|
75
|
+
if (names.length === 0) {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
const { line } = file.getLineAndCharacterOfPosition(statement.getStart(file));
|
|
79
|
+
const uses = names.map((name) => `\`${statement.name.text}.${name}\``).join(', ');
|
|
80
|
+
return [
|
|
81
|
+
{
|
|
82
|
+
line: line + 1,
|
|
83
|
+
note: `\`import ${statement.name.text} = require('${specifier}')\` is not rewritten: change ${uses} to the new names by hand`,
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/** The guards first: the type pass reads their output, so both land in one write. */
|
|
89
|
+
static rewrite(opts) {
|
|
90
|
+
const { typescript, fileName, source } = opts;
|
|
91
|
+
const guards = rewriter_1.NamespaceFunctions.rewrite({
|
|
92
|
+
typescript,
|
|
93
|
+
fileName,
|
|
94
|
+
source,
|
|
95
|
+
mappings: guards_1.GUARD_MAPPINGS,
|
|
96
|
+
});
|
|
97
|
+
const types = class_renames_1.ClassRenames.rewrite({
|
|
98
|
+
typescript,
|
|
99
|
+
fileName,
|
|
100
|
+
source: guards.output,
|
|
101
|
+
rows: PublicNamesTable.TYPE_ROWS,
|
|
102
|
+
});
|
|
103
|
+
return {
|
|
104
|
+
output: types.output,
|
|
105
|
+
changed: types.output !== source,
|
|
106
|
+
rewritten: guards.rewritten + types.rewritten,
|
|
107
|
+
manual: [
|
|
108
|
+
...PublicNames.findRequireImports(opts),
|
|
109
|
+
...guards.reports.map((report) => ({ line: report.line, note: report.reason })),
|
|
110
|
+
...types.manual,
|
|
111
|
+
],
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.PublicNames = PublicNames;
|
|
116
|
+
const CODEMOD = {
|
|
117
|
+
name: 'public-names',
|
|
118
|
+
usage: USAGE,
|
|
119
|
+
isReversible: false,
|
|
120
|
+
marks: () => [
|
|
121
|
+
...PublicNamesTable.TYPE_ROWS.map((row) => row.oldName),
|
|
122
|
+
...guards_1.GUARD_MAPPINGS.map((mapping) => mapping.oldName),
|
|
123
|
+
],
|
|
124
|
+
rewrite: (input) => PublicNames.rewrite(input),
|
|
125
|
+
};
|
|
126
|
+
/** `devz codemod public-names [paths...]`: the type and type guard renames, with the file handling of `class-renames`. */
|
|
127
|
+
class PublicNamesCommand {
|
|
128
|
+
static { this.USAGE = USAGE; }
|
|
129
|
+
static async run(opts) {
|
|
130
|
+
return class_renames_1.ClassRenamesCommand.run({ ...opts, codemod: CODEMOD });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.PublicNamesCommand = PublicNamesCommand;
|
|
134
|
+
//# sourceMappingURL=public-names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-names.js","sourceRoot":"","sources":["../../../src/cli/codemod/public-names.ts"],"names":[],"mappings":";;;AAAA,mDAAoE;AAEpE,kEAAuE;AACvE,6DAAoE;AAEpE,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;gEAsBkD,CAAC;AAEjE,yEAAyE;AACzE,MAAM,aAAa,GA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G,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;IAChE,CAAC;;AALH,gDAMC","sourcesContent":["import { ClassRenames, ClassRenamesCommand } from './class-renames';\nimport type { IClassRename, ICodemodRewrite, IFileCodemod } from './class-renames';\nimport { GUARD_MAPPINGS } from './namespace-functions/mappings/guards';\nimport { NamespaceFunctions } from './namespace-functions/rewriter';\n\nconst USAGE = `Usage: devz codemod public-names [paths...] [--write [--all] | --check]\n\nOne run for the public renames of types and type guards:\n\n - ValueOf -> TValueOf, ValueOrPromise -> TValueOrPromise, TConstructor -> TClass,\n TAbstractConstructor -> TAbstractClass, imported from @venizia/ignis-inversion, @venizia/ignis-helpers\n (and /common) or @venizia/ignis. An aliased import keeps its alias.\n - a type guard function becomes a static method of the same name, such as isPromiseLike(value) ->\n Execution.isPromiseLike(value). The table is in namespace-functions/mappings/guards.ts.\n\nA name your file declares itself, or imports from another package, is left alone. It reads .ts, .tsx, .mts and\n.cts files. It lists, with the line, and leaves to you: a guard used as a value (passed to filter, in typeof),\na re-export or a type-only import of a guard, a type whose name is declared again further down the file, an\n\"import x = require('...')\" that reaches an old name through x. It does\nnot list, so run your typecheck afterwards: .js files, import('pkg').Name, a guard read from a namespace import\nof a package that does not export its class, and a name that reaches a file through a barrel of your own.\n\n --write write the changed files (without it, nothing is written); it needs a path, or --all\n --all with --write and no path: rewrite every source file under the working directory\n --check dry run that exits 1 while a file would change or a line is left to you (for CI)\n --help print this text and exit\n\nThere is no --reverse: TConstructor and TClass became one name.`;\n\n/** The packages that export the renamed types; their sub-paths count. */\nconst TYPE_PACKAGES = ['@venizia/ignis-inversion', '@venizia/ignis-helpers', '@venizia/ignis'];\n\nexport class PublicNamesTable {\n static readonly TYPE_ROWS: ReadonlyArray<IClassRename> = [\n { oldName: 'ValueOf', newName: 'TValueOf', packages: TYPE_PACKAGES },\n { oldName: 'ValueOrPromise', newName: 'TValueOrPromise', packages: TYPE_PACKAGES },\n { oldName: 'TConstructor', newName: 'TClass', packages: TYPE_PACKAGES },\n { oldName: 'TAbstractConstructor', newName: 'TAbstractClass', packages: TYPE_PACKAGES },\n ];\n}\n\nexport class PublicNames {\n /** Whether `specifier` exports `name` as one of the old names this codemod moves. */\n private static isOldName(opts: { specifier: string; name: string }): boolean {\n const { specifier, name } = opts;\n\n return (\n GUARD_MAPPINGS.some(\n (mapping) => mapping.oldName === name && mapping.modules.includes(specifier),\n ) ||\n PublicNamesTable.TYPE_ROWS.some(\n (row) =>\n row.oldName === name &&\n row.packages.some((owner) => specifier === owner || specifier.startsWith(`${owner}/`)),\n )\n );\n }\n\n /** The `import x = require('...')` lines of a `.cts` file whose `x` reaches an old name: neither pass rewrites them. */\n private static findRequireImports(opts: {\n typescript: typeof import('typescript');\n fileName: string;\n source: string;\n }): ICodemodRewrite['manual'] {\n const { typescript: ts, fileName, source } = opts;\n const file = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true);\n const reached = new Map<string, Set<string>>();\n\n const walk = (node: import('typescript').Node): void => {\n const pair = ts.isPropertyAccessExpression(node)\n ? [node.expression, node.name]\n : ts.isQualifiedName(node)\n ? [node.left, node.right]\n : undefined;\n const [scope, member] = pair ?? [];\n\n if (scope && member && ts.isIdentifier(scope)) {\n reached.set(scope.text, (reached.get(scope.text) ?? new Set()).add(member.getText(file)));\n }\n\n ts.forEachChild(node, walk);\n };\n\n walk(file);\n\n return file.statements.flatMap((statement) => {\n if (\n !ts.isImportEqualsDeclaration(statement) ||\n !ts.isExternalModuleReference(statement.moduleReference) ||\n !ts.isStringLiteralLike(statement.moduleReference.expression)\n ) {\n return [];\n }\n\n const specifier = statement.moduleReference.expression.text;\n const names = [...(reached.get(statement.name.text) ?? [])].filter((name) =>\n PublicNames.isOldName({ specifier, name }),\n );\n\n if (names.length === 0) {\n return [];\n }\n\n const { line } = file.getLineAndCharacterOfPosition(statement.getStart(file));\n const uses = names.map((name) => `\\`${statement.name.text}.${name}\\``).join(', ');\n\n return [\n {\n line: line + 1,\n note: `\\`import ${statement.name.text} = require('${specifier}')\\` is not rewritten: change ${uses} to the new names by hand`,\n },\n ];\n });\n }\n\n /** The guards first: the type pass reads their output, so both land in one write. */\n static rewrite(opts: {\n typescript: typeof import('typescript');\n fileName: string;\n source: string;\n }): ICodemodRewrite {\n const { typescript, fileName, source } = opts;\n const guards = NamespaceFunctions.rewrite({\n typescript,\n fileName,\n source,\n mappings: GUARD_MAPPINGS,\n });\n const types = ClassRenames.rewrite({\n typescript,\n fileName,\n source: guards.output,\n rows: PublicNamesTable.TYPE_ROWS,\n });\n\n return {\n output: types.output,\n changed: types.output !== source,\n rewritten: guards.rewritten + types.rewritten,\n manual: [\n ...PublicNames.findRequireImports(opts),\n ...guards.reports.map((report) => ({ line: report.line, note: report.reason })),\n ...types.manual,\n ],\n };\n }\n}\n\nconst CODEMOD: IFileCodemod = {\n name: 'public-names',\n usage: USAGE,\n isReversible: false,\n marks: () => [\n ...PublicNamesTable.TYPE_ROWS.map((row) => row.oldName),\n ...GUARD_MAPPINGS.map((mapping) => mapping.oldName),\n ],\n rewrite: (input) => PublicNames.rewrite(input),\n};\n\n/** `devz codemod public-names [paths...]`: the type and type guard renames, with the file handling of `class-renames`. */\nexport class PublicNamesCommand {\n static readonly USAGE = USAGE;\n\n static async run(opts: { root: string; args: string[] }): Promise<number> {\n return ClassRenamesCommand.run({ ...opts, codemod: CODEMOD });\n }\n}\n"]}
|
package/dist/cli/index.js
CHANGED
|
@@ -20,6 +20,7 @@ Commands:
|
|
|
20
20
|
codemod connector-imports [paths...] move @venizia/ignis/<connector sub-path> imports to @venizia/ignis-connectors (dry run unless --write)
|
|
21
21
|
codemod env-get [paths...] strip the type arguments of AppEnvs.get() for the string-reading get() (dry run unless --write)
|
|
22
22
|
codemod any-aliases [paths...] replace the removed AnyType and AnyObject aliases by what they stood for, any (--strict: unknown and Record<string, unknown>; dry run unless --write)
|
|
23
|
+
codemod public-names [paths...] rename ValueOf, ValueOrPromise, TConstructor and TAbstractConstructor and move the type guard functions to their class (dry run unless --write)
|
|
23
24
|
|
|
24
25
|
Run \`devz clean --help\` or \`devz codemod --help\` for a command's options.`;
|
|
25
26
|
const main = async (opts) => {
|