nalloc 0.2.2 → 0.5.0
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 +326 -178
- package/build/codemod-cli.cjs +153 -0
- package/build/codemod-cli.cjs.map +1 -0
- package/build/codemod-cli.d.ts +2 -0
- package/build/codemod-cli.js +103 -0
- package/build/codemod-cli.js.map +1 -0
- package/build/codemod.cjs +652 -0
- package/build/codemod.cjs.map +1 -0
- package/build/codemod.d.ts +29 -0
- package/build/codemod.js +634 -0
- package/build/codemod.js.map +1 -0
- package/build/eslint.cjs +221 -0
- package/build/eslint.cjs.map +1 -0
- package/build/eslint.d.ts +36 -0
- package/build/eslint.js +198 -0
- package/build/eslint.js.map +1 -0
- package/build/http.cjs +31 -0
- package/build/http.cjs.map +1 -0
- package/build/http.d.ts +31 -0
- package/build/http.js +13 -0
- package/build/http.js.map +1 -0
- package/build/nonempty.cjs +35 -0
- package/build/nonempty.cjs.map +1 -0
- package/build/nonempty.d.ts +34 -0
- package/build/nonempty.js +14 -0
- package/build/nonempty.js.map +1 -0
- package/build/option.cjs +1 -1
- package/build/option.cjs.map +1 -1
- package/build/option.d.ts +2 -2
- package/build/option.js +1 -1
- package/build/option.js.map +1 -1
- package/build/result.cjs +10 -18
- package/build/result.cjs.map +1 -1
- package/build/result.d.ts +3 -34
- package/build/result.js +10 -15
- package/build/result.js.map +1 -1
- package/build/safe.cjs +8 -0
- package/build/safe.cjs.map +1 -1
- package/build/safe.d.ts +3 -0
- package/build/safe.js +2 -0
- package/build/safe.js.map +1 -1
- package/build/schema.cjs +32 -0
- package/build/schema.cjs.map +1 -0
- package/build/schema.d.ts +44 -0
- package/build/schema.js +14 -0
- package/build/schema.js.map +1 -0
- package/package.json +63 -10
- package/src/__tests__/codemod.ts +211 -0
- package/src/__tests__/eslint.ts +99 -0
- package/src/__tests__/fixtures/tsconfig.json +10 -0
- package/src/__tests__/http.ts +64 -0
- package/src/__tests__/iter.ts +18 -0
- package/src/__tests__/nonempty.ts +46 -0
- package/src/__tests__/nonempty.types.ts +38 -0
- package/src/__tests__/option.ts +4 -0
- package/src/__tests__/result.ts +104 -129
- package/src/__tests__/result.types.ts +2 -2
- package/src/__tests__/schema.ts +58 -0
- package/src/codemod-cli.ts +108 -0
- package/src/codemod.ts +623 -0
- package/src/eslint.ts +145 -0
- package/src/http.ts +42 -0
- package/src/nonempty.ts +48 -0
- package/src/option.ts +3 -4
- package/src/result.ts +18 -49
- package/src/safe.ts +3 -0
- package/src/schema.ts +52 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/codemod.ts"],"sourcesContent":["import { parseSync } from 'oxc-parser';\n\n/** A call site the codemod refused to convert, with the reason for manual review. */\nexport interface SkippedSite {\n readonly file: string;\n readonly line: number;\n readonly reason: 'result-async' | 'safe-try' | 'unsupported' | 'namespace-import';\n readonly text: string;\n}\n\nexport interface MigrateFileResult {\n readonly output: string;\n readonly changed: boolean;\n readonly converted: number;\n readonly skipped: SkippedSite[];\n}\n\ninterface Node {\n type: string;\n start: number;\n end: number;\n [key: string]: unknown;\n}\n\ninterface Edit {\n start: number;\n end: number;\n text: string;\n}\n\n/** neverthrow instance method -> nalloc Result function. Ambiguous names (shared with Array/other types) convert only with provenance. */\nconst INSTANCE_METHODS: ReadonlyMap<string, { readonly fn: string; readonly ambiguous?: boolean }> = new Map([\n ['map', { fn: 'map', ambiguous: true }],\n ['mapErr', { fn: 'mapErr' }],\n ['andThen', { fn: 'flatMap' }],\n ['orElse', { fn: 'orElse' }],\n ['match', { fn: 'match' }],\n ['unwrapOr', { fn: 'unwrapOr' }],\n ['isOk', { fn: 'isOk' }],\n ['isErr', { fn: 'isErr' }],\n ['andTee', { fn: 'tap' }],\n ['orTee', { fn: 'tapErr' }],\n ['_unsafeUnwrap', { fn: 'unwrap' }],\n ['_unsafeUnwrapErr', { fn: 'unwrapErr' }],\n]);\n\nconst ASYNC_INSTANCE_METHODS: ReadonlySet<string> = new Set(['asyncMap', 'asyncAndThen', 'asyncAndThrough']);\nconst UNSUPPORTED_INSTANCE_METHODS: ReadonlySet<string> = new Set(['andThrough', 'safeUnwrap']);\n\n/** neverthrow module-level names that produce ResultAsync - left on neverthrow, reported for manual genAsync migration. */\nconst ASYNC_IMPORTS: ReadonlySet<string> = new Set(['ResultAsync', 'okAsync', 'errAsync', 'fromSafePromise', 'fromAsyncThrowable']);\n\nconst STATIC_METHODS: ReadonlyMap<string, string> = new Map([\n ['fromThrowable', 'wrap'],\n ['combine', 'all'],\n ['combineWithAllErrors', 'collectAll'],\n]);\n\nfunction isNode(value: unknown): value is Node {\n return typeof value === 'object' && value !== null && typeof (value as Node).type === 'string';\n}\n\nfunction eachChild(node: Node, visit: (child: Node) => void): void {\n for (const key of Object.keys(node)) {\n const value = node[key];\n if (Array.isArray(value)) {\n for (const item of value) {\n if (isNode(item)) visit(item);\n }\n } else if (isNode(value)) {\n visit(value);\n }\n }\n}\n\nfunction annotationTypeName(id: Node): string | undefined {\n const annotation = id.typeAnnotation as Node | null;\n const ref = annotation?.typeAnnotation as Node | undefined;\n if (ref?.type !== 'TSTypeReference') return undefined;\n const typeName = ref.typeName as Node;\n return typeName.type === 'Identifier' ? (typeName.name as string) : undefined;\n}\n\ninterface ImportedNames {\n /** local name -> imported name, for every value imported from neverthrow */\n readonly locals: Map<string, string>;\n /** import declarations to replace */\n readonly declarations: Node[];\n readonly hasNamespace: boolean;\n}\n\nfunction collectImports(program: Node): ImportedNames {\n const locals = new Map<string, string>();\n const declarations: Node[] = [];\n let hasNamespace = false;\n for (const stmt of program.body as Node[]) {\n if (stmt.type !== 'ImportDeclaration' || (stmt.source as Node & { value: string }).value !== 'neverthrow') continue;\n declarations.push(stmt);\n for (const spec of stmt.specifiers as Node[]) {\n if (spec.type === 'ImportNamespaceSpecifier') {\n hasNamespace = true;\n } else if (spec.type === 'ImportSpecifier') {\n const imported = spec.imported as Node;\n if (imported.type === 'Identifier') {\n locals.set((spec.local as Node).name as string, imported.name as string);\n }\n }\n }\n }\n return { locals, declarations, hasNamespace };\n}\n\nclass FileMigration {\n readonly edits: Edit[] = [];\n readonly skipped: SkippedSite[] = [];\n /** identifiers proven to hold a (migrated) Result */\n readonly resultIds = new Set<string>();\n /** identifiers holding neverthrow ResultAsync values - never convert methods on these */\n readonly asyncIds = new Set<string>();\n /** identifiers bound to fromThrowable-wrapped functions - their call results are Results */\n readonly wrappedFns = new Set<string>();\n /** local functions declared to return Result */\n readonly resultFns = new Set<string>();\n /** identifiers also bound to something unclassifiable - provenance dropped */\n readonly conflicted = new Set<string>();\n readonly residualNames = new Set<string>();\n converted = 0;\n needsNamespace = false;\n needsPipe = false;\n needsResultType = false;\n readonly usedTypeNames = new Set<string>();\n\n constructor(\n readonly file: string,\n readonly source: string,\n readonly imports: ImportedNames,\n ) {}\n\n importedAs(local: string): string | undefined {\n return this.imports.locals.get(local);\n }\n\n isFromPromiseCall(node: Node): boolean {\n return (\n node.type === 'CallExpression' && (node.callee as Node).type === 'Identifier' && this.importedAs((node.callee as Node).name as string) === 'fromPromise'\n );\n }\n\n lineOf(offset: number): number {\n let line = 1;\n for (let i = 0; i < offset; i++) {\n if (this.source.charCodeAt(i) === 10) line++;\n }\n return line;\n }\n\n report(reason: SkippedSite['reason'], node: Node): void {\n this.skipped.push({\n file: this.file,\n line: this.lineOf(node.start),\n reason,\n text: this.source.slice(node.start, Math.min(node.end, node.start + 120)),\n });\n }\n\n /** Classifies an expression as a migrated Result ('result'), a neverthrow ResultAsync ('async'), or unknown. */\n classify(node: Node): 'result' | 'async' | undefined {\n if (node.type === 'Identifier') {\n const name = node.name as string;\n if (this.conflicted.has(name)) return undefined;\n if (this.asyncIds.has(name)) return 'async';\n if (this.resultIds.has(name)) return 'result';\n return undefined;\n }\n if (node.type === 'AwaitExpression') {\n // a directly-awaited fromPromise is converted to Result.fromPromise, so its result is a migrated Result;\n // awaiting any other ResultAsync yields a neverthrow Result instance, which must stay on neverthrow\n if (this.isFromPromiseCall(node.argument as Node)) return 'result';\n return this.classify(node.argument as Node) === 'async' ? 'async' : undefined;\n }\n if (node.type === 'CallExpression') {\n const callee = node.callee as Node;\n if (callee.type === 'Identifier') {\n const name = callee.name as string;\n const imported = this.importedAs(name);\n if (imported === 'ok' || imported === 'err' || imported === 'combine' || imported === 'combineWithAllErrors') return 'result';\n if (imported !== undefined && (ASYNC_IMPORTS.has(imported) || imported === 'fromPromise')) return 'async';\n if (this.wrappedFns.has(name) || this.resultFns.has(name)) return 'result';\n return undefined;\n }\n if (callee.type === 'MemberExpression' && !(callee.computed as boolean)) {\n const property = callee.property as Node;\n const object = callee.object as Node;\n if (property.type !== 'Identifier') return undefined;\n const method = property.name as string;\n if (object.type === 'Identifier') {\n const objImported = this.importedAs(object.name as string);\n if (objImported === 'Result' && STATIC_METHODS.has(method)) {\n return method === 'fromThrowable' ? undefined : 'result';\n }\n if (objImported === 'ResultAsync') return 'async';\n }\n const receiver = this.classify(object);\n if (receiver === 'async') return 'async';\n if (receiver === 'result') {\n if (ASYNC_INSTANCE_METHODS.has(method)) return 'async';\n if (INSTANCE_METHODS.has(method)) return 'result';\n }\n return undefined;\n }\n }\n return undefined;\n }\n\n classifyBinding(id: Node, init: Node | null): void {\n if (id.type !== 'Identifier') return;\n const name = id.name as string;\n const typeName = annotationTypeName(id);\n const annotated = typeName !== undefined ? this.importedAs(typeName) : undefined;\n const fromInit = ((): 'result' | 'async' | 'wrapped' | undefined => {\n if (init === null) return undefined;\n if (init.type === 'CallExpression') {\n const callee = init.callee as Node;\n const calleeImported = callee.type === 'Identifier' ? this.importedAs(callee.name as string) : undefined;\n if (calleeImported === 'fromThrowable') return 'wrapped';\n if (callee.type === 'MemberExpression') {\n const object = callee.object as Node;\n const property = callee.property as Node;\n if (\n object.type === 'Identifier' &&\n property.type === 'Identifier' &&\n this.importedAs(object.name as string) === 'Result' &&\n property.name === 'fromThrowable'\n ) {\n return 'wrapped';\n }\n }\n }\n return this.classify(init);\n })();\n const kind = annotated === 'Result' || annotated === 'Ok' || annotated === 'Err' ? 'result' : annotated === 'ResultAsync' ? 'async' : fromInit;\n if (kind === 'result') {\n this.addClassified(name, this.resultIds);\n } else if (kind === 'async') {\n this.addClassified(name, this.asyncIds);\n } else if (kind === 'wrapped') {\n this.addClassified(name, this.wrappedFns);\n } else {\n // a second, unclassifiable binding of a known name poisons its provenance\n if (this.resultIds.has(name) || this.asyncIds.has(name) || this.wrappedFns.has(name)) {\n this.conflicted.add(name);\n }\n }\n }\n\n addClassified(name: string, target: Set<string>): void {\n if ((this.resultIds.has(name) || this.asyncIds.has(name) || this.wrappedFns.has(name)) && !target.has(name)) {\n this.conflicted.add(name);\n return;\n }\n target.add(name);\n }\n\n collectProvenance(node: Node): void {\n if (node.type === 'VariableDeclarator') {\n this.classifyBinding(node.id as Node, node.init as Node | null);\n } else if (node.type === 'AssignmentExpression' && node.operator === '=') {\n this.classifyBinding(node.left as Node, node.right as Node);\n } else if (node.type === 'FunctionDeclaration' || node.type === 'TSDeclareFunction') {\n const id = node.id as Node | null;\n const returnType = node.returnType as Node | null;\n if (id?.type === 'Identifier' && returnType !== null) {\n const ref = returnType.typeAnnotation as Node;\n if (ref.type === 'TSTypeReference' && (ref.typeName as Node).type === 'Identifier') {\n const imported = this.importedAs((ref.typeName as Node).name as string);\n if (imported === 'Result') this.resultFns.add(id.name as string);\n }\n }\n for (const param of node.params as Node[]) {\n this.classifyBinding(param, null);\n }\n } else if (node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression') {\n for (const param of node.params as Node[]) {\n this.classifyBinding(param, null);\n }\n }\n eachChild(node, (child) => this.collectProvenance(child));\n }\n\n /** Removes and returns collected edits falling inside a span. */\n takeEditsWithin(start: number, end: number): Edit[] {\n const inside: Edit[] = [];\n for (let i = this.edits.length - 1; i >= 0; i--) {\n const edit = this.edits[i];\n if (edit.start >= start && edit.end <= end) {\n inside.push(edit);\n this.edits.splice(i, 1);\n }\n }\n return inside;\n }\n\n /** Renders a source span with any already-collected nested edits applied. */\n render(start: number, end: number): string {\n const inside = this.takeEditsWithin(start, end).sort((a, b) => b.start - a.start);\n let text = this.source.slice(start, end);\n for (const edit of inside) {\n text = text.slice(0, edit.start - start) + edit.text + text.slice(edit.end - start);\n }\n return text;\n }\n\n renderArgs(args: Node[]): string {\n if (args.length === 0) return '';\n return this.render(args[0].start, args[args.length - 1].end);\n }\n\n convert(node: Node, parent: Node | undefined, grandparent: Node | undefined): void {\n if (node.type === 'TSTypeReference') {\n const typeName = node.typeName as Node;\n if (typeName.type === 'Identifier') {\n const imported = this.importedAs(typeName.name as string);\n if (imported === 'Result') {\n this.edits.push({ start: typeName.start, end: typeName.end, text: 'ResultType' });\n this.needsResultType = true;\n } else if (imported === 'Ok' || imported === 'Err') {\n this.usedTypeNames.add(imported);\n }\n }\n }\n\n if (node.type === 'CallExpression') {\n // an outer convertible chain link processes this node itself; skip to avoid double conversion\n const consumedByOuterChain =\n parent?.type === 'MemberExpression' &&\n parent.object === node &&\n !(parent.computed as boolean) &&\n (parent.property as Node).type === 'Identifier' &&\n grandparent?.type === 'CallExpression' &&\n grandparent.callee === parent &&\n (INSTANCE_METHODS.has((parent.property as Node).name as string) ||\n ASYNC_INSTANCE_METHODS.has((parent.property as Node).name as string) ||\n UNSUPPORTED_INSTANCE_METHODS.has((parent.property as Node).name as string));\n if (!consumedByOuterChain && this.convertCall(node)) return;\n }\n\n eachChild(node, (child) => this.convert(child, node, parent));\n }\n\n /** Returns true when the node was fully handled (children already converted as needed). */\n convertCall(node: Node): boolean {\n const callee = node.callee as Node;\n\n if (callee.type === 'Identifier') {\n const imported = this.importedAs(callee.name as string);\n if (imported === undefined) return false;\n if (imported === 'fromThrowable' || imported === 'combine' || imported === 'combineWithAllErrors') {\n this.edits.push({ start: callee.start, end: callee.end, text: `Result.${STATIC_METHODS.get(imported)}` });\n this.needsNamespace = true;\n this.converted++;\n return false;\n }\n if (imported === 'safeTry') {\n this.report('safe-try', node);\n this.residualNames.add(callee.name as string);\n return false;\n }\n if (ASYNC_IMPORTS.has(imported)) {\n this.report('result-async', node);\n this.residualNames.add(callee.name as string);\n return false;\n }\n return false;\n }\n\n if (callee.type !== 'MemberExpression' || (callee.computed as boolean) || (callee.property as Node).type !== 'Identifier') {\n return false;\n }\n const object = callee.object as Node;\n const method = (callee.property as Node).name as string;\n\n if (object.type === 'Identifier') {\n const objImported = this.importedAs(object.name as string);\n if (objImported === 'Result' && STATIC_METHODS.has(method)) {\n this.edits.push({ start: callee.start, end: callee.end, text: `Result.${STATIC_METHODS.get(method)}` });\n this.needsNamespace = true;\n this.converted++;\n return false;\n }\n if (objImported === 'ResultAsync') {\n this.report('result-async', node);\n this.residualNames.add(object.name as string);\n return false;\n }\n }\n\n if (!INSTANCE_METHODS.has(method) && !ASYNC_INSTANCE_METHODS.has(method) && !UNSUPPORTED_INSTANCE_METHODS.has(method)) {\n return false;\n }\n\n // collect the full chain from this outermost call down to its base receiver\n const links: { call: Node; method: string }[] = [];\n let current: Node = node;\n let blocked: SkippedSite['reason'] | undefined;\n while (true) {\n const currentCallee = current.callee as Node;\n const currentMethod = (currentCallee.property as Node).name as string;\n if (ASYNC_INSTANCE_METHODS.has(currentMethod)) {\n blocked = 'result-async';\n break;\n }\n if (UNSUPPORTED_INSTANCE_METHODS.has(currentMethod)) {\n blocked = 'unsupported';\n break;\n }\n links.unshift({ call: current, method: currentMethod });\n const receiver = currentCallee.object as Node;\n if (\n receiver.type === 'CallExpression' &&\n (receiver.callee as Node).type === 'MemberExpression' &&\n !((receiver.callee as Node).computed as boolean) &&\n ((receiver.callee as Node).property as Node).type === 'Identifier' &&\n (INSTANCE_METHODS.has(((receiver.callee as Node).property as Node).name as string) ||\n ASYNC_INSTANCE_METHODS.has(((receiver.callee as Node).property as Node).name as string) ||\n UNSUPPORTED_INSTANCE_METHODS.has(((receiver.callee as Node).property as Node).name as string))\n ) {\n current = receiver;\n continue;\n }\n break;\n }\n\n if (blocked !== undefined) {\n // converting inner links would leave a neverthrow method called on a nalloc value\n this.report(blocked, node);\n const blockedCall = current;\n eachChild(node, (child) => {\n if (child !== blockedCall) this.convert(child, node, undefined);\n });\n return true;\n }\n\n const base = (links[0].call.callee as Node).object as Node;\n const baseKind = this.classify(base);\n if (baseKind === 'async') {\n this.report('result-async', node);\n return true;\n }\n const hasExclusive = links.some((link) => !INSTANCE_METHODS.get(link.method)!.ambiguous);\n if (baseKind !== 'result' && !hasExclusive) {\n // unprovable receiver and only ambiguous methods (e.g. bare .map) - almost certainly not a Result\n return false;\n }\n\n // convert nested code inside the base and every argument first, so render() picks the edits up\n this.convert(base, undefined, undefined);\n for (const link of links) {\n for (const arg of link.call.arguments as Node[]) {\n this.convert(arg, link.call, undefined);\n }\n }\n\n const baseText = this.render(base.start, base.end);\n this.needsNamespace = true;\n this.converted += links.length;\n const replacement = ((): string => {\n if (links.length === 1) {\n const { fn } = INSTANCE_METHODS.get(links[0].method)!;\n const args = this.renderArgs(links[0].call.arguments as Node[]);\n return `Result.${fn}(${baseText}${args.length > 0 ? `, ${args}` : ''})`;\n }\n this.needsPipe = true;\n const steps = links.map((link) => {\n const { fn } = INSTANCE_METHODS.get(link.method)!;\n const args = this.renderArgs(link.call.arguments as Node[]);\n return `($r) => Result.${fn}($r${args.length > 0 ? `, ${args}` : ''})`;\n });\n return `pipe(${baseText}, ${steps.join(', ')})`;\n })();\n this.edits.push({ start: node.start, end: node.end, text: replacement });\n return true;\n }\n\n readonly awaitedFromPromise = new Set<Node>();\n\n /** Direct `await fromPromise(...)` resolves to a plain Result and maps 1:1 to nalloc. */\n convertAwaitedFromPromise(node: Node): void {\n if (node.type === 'AwaitExpression' && this.isFromPromiseCall(node.argument as Node)) {\n const call = node.argument as Node;\n this.edits.push({ start: (call.callee as Node).start, end: (call.callee as Node).end, text: 'Result.fromPromise' });\n this.awaitedFromPromise.add(call);\n this.needsNamespace = true;\n this.converted++;\n }\n eachChild(node, (child) => this.convertAwaitedFromPromise(child));\n }\n\n reportUnconvertedFromPromise(node: Node): void {\n if (this.isFromPromiseCall(node) && !this.awaitedFromPromise.has(node)) {\n this.report('result-async', node);\n this.residualNames.add((node.callee as Node).name as string);\n }\n eachChild(node, (child) => this.reportUnconvertedFromPromise(child));\n }\n\n rewriteImports(): void {\n const valueNames: string[] = [];\n const typeNames: string[] = [];\n for (const [local, imported] of this.imports.locals) {\n if (imported === 'ok' || imported === 'err') {\n valueNames.push(imported === local ? imported : `${imported} as ${local}`);\n }\n }\n if (this.needsNamespace) valueNames.push('Result');\n if (this.needsPipe) valueNames.push('pipe');\n if (this.needsResultType) typeNames.push('type ResultType');\n for (const name of this.usedTypeNames) typeNames.push(`type ${name}`);\n\n const statements: string[] = [];\n const names = [...valueNames, ...typeNames];\n if (names.length > 0) {\n statements.push(`import { ${names.join(', ')} } from 'nalloc';`);\n }\n const residual = [...this.residualNames].map((local) => {\n const imported = this.importedAs(local)!;\n return imported === local ? imported : `${imported} as ${local}`;\n });\n if (residual.length > 0) {\n statements.push(`import { ${residual.join(', ')} } from 'neverthrow';`);\n }\n\n const [first, ...rest] = this.imports.declarations;\n this.edits.push({ start: first.start, end: first.end, text: statements.join('\\n') });\n for (const decl of rest) {\n const end = this.source.charCodeAt(decl.end) === 10 ? decl.end + 1 : decl.end;\n this.edits.push({ start: decl.start, end, text: '' });\n }\n }\n\n apply(): string {\n const sorted = [...this.edits].sort((a, b) => b.start - a.start);\n let output = this.source;\n for (const edit of sorted) {\n output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);\n }\n return output;\n }\n}\n\n/**\n * Migrates one source file from neverthrow to nalloc.\n * Pure function: parses, rewrites provable sites via text splices (formatting preserved),\n * and reports everything it refuses to convert.\n * @param source - The file's source text\n * @param file - File path used in the report\n * @returns The migrated source, whether it changed, and the skipped sites\n */\nexport function migrateSource(source: string, file: string): MigrateFileResult {\n const parsed = parseSync(file, source);\n if (parsed.errors.some((e) => e.severity === 'Error')) {\n return {\n output: source,\n changed: false,\n converted: 0,\n skipped: [{ file, line: 1, reason: 'unsupported', text: 'file has parse errors' }],\n };\n }\n const program = parsed.program as unknown as Node;\n const imports = collectImports(program);\n if (imports.declarations.length === 0) {\n return { output: source, changed: false, converted: 0, skipped: [] };\n }\n const migration = new FileMigration(file, source, imports);\n if (imports.hasNamespace) {\n migration.report('namespace-import', imports.declarations[0]);\n return { output: source, changed: false, converted: 0, skipped: migration.skipped };\n }\n migration.collectProvenance(program);\n migration.convertAwaitedFromPromise(program);\n migration.convert(program, undefined, undefined);\n migration.reportUnconvertedFromPromise(program);\n migration.rewriteImports();\n const output = migration.apply();\n return {\n output,\n changed: output !== source,\n converted: migration.converted,\n skipped: migration.skipped,\n };\n}\n\nexport interface MigrationReport {\n readonly filesChanged: number;\n readonly converted: number;\n readonly skipped: readonly SkippedSite[];\n}\n\n/** Renders the skipped-site report as markdown for --report. */\nexport function renderReport(report: MigrationReport): string {\n const lines = [\n '# nalloc migration report',\n '',\n `Files changed: ${report.filesChanged}. Sites converted: ${report.converted}. Sites needing manual review: ${report.skipped.length}.`,\n '',\n ];\n const byFile = new Map<string, SkippedSite[]>();\n for (const site of report.skipped) {\n const sites = byFile.get(site.file);\n if (sites === undefined) {\n byFile.set(site.file, [site]);\n } else {\n sites.push(site);\n }\n }\n for (const [file, sites] of byFile) {\n lines.push(`## ${file}`, '');\n for (const site of sites) {\n lines.push(`- line ${site.line} [${site.reason}]: \\`${site.text}\\``);\n }\n lines.push('');\n }\n return lines.join('\\n');\n}\n"],"names":["migrateSource","renderReport","INSTANCE_METHODS","Map","fn","ambiguous","ASYNC_INSTANCE_METHODS","Set","UNSUPPORTED_INSTANCE_METHODS","ASYNC_IMPORTS","STATIC_METHODS","isNode","value","type","eachChild","node","visit","key","Object","keys","Array","isArray","item","annotationTypeName","id","annotation","typeAnnotation","ref","undefined","typeName","name","collectImports","program","locals","declarations","hasNamespace","stmt","body","source","push","spec","specifiers","imported","set","local","FileMigration","edits","skipped","resultIds","asyncIds","wrappedFns","resultFns","conflicted","residualNames","converted","needsNamespace","needsPipe","needsResultType","usedTypeNames","file","imports","importedAs","get","isFromPromiseCall","callee","lineOf","offset","line","i","charCodeAt","report","reason","start","text","slice","Math","min","end","classify","has","argument","computed","property","object","method","objImported","receiver","classifyBinding","init","annotated","fromInit","calleeImported","kind","addClassified","add","target","collectProvenance","operator","left","right","returnType","param","params","child","takeEditsWithin","inside","length","edit","splice","render","sort","a","b","renderArgs","args","convert","parent","grandparent","consumedByOuterChain","convertCall","links","current","blocked","currentCallee","currentMethod","unshift","call","blockedCall","base","baseKind","hasExclusive","some","link","arg","arguments","baseText","replacement","steps","map","join","awaitedFromPromise","convertAwaitedFromPromise","reportUnconvertedFromPromise","rewriteImports","valueNames","typeNames","statements","names","residual","first","rest","decl","apply","sorted","output","parsed","parseSync","errors","e","severity","changed","migration","lines","filesChanged","byFile","site","sites"],"mappings":";;;;;;;;;;;QA6iBgBA;eAAAA;;QAyCAC;eAAAA;;;2BAtlBU;AA+B1B,MAAMC,mBAA+F,IAAIC,IAAI;IAC3G;QAAC;QAAO;YAAEC,IAAI;YAAOC,WAAW;QAAK;KAAE;IACvC;QAAC;QAAU;YAAED,IAAI;QAAS;KAAE;IAC5B;QAAC;QAAW;YAAEA,IAAI;QAAU;KAAE;IAC9B;QAAC;QAAU;YAAEA,IAAI;QAAS;KAAE;IAC5B;QAAC;QAAS;YAAEA,IAAI;QAAQ;KAAE;IAC1B;QAAC;QAAY;YAAEA,IAAI;QAAW;KAAE;IAChC;QAAC;QAAQ;YAAEA,IAAI;QAAO;KAAE;IACxB;QAAC;QAAS;YAAEA,IAAI;QAAQ;KAAE;IAC1B;QAAC;QAAU;YAAEA,IAAI;QAAM;KAAE;IACzB;QAAC;QAAS;YAAEA,IAAI;QAAS;KAAE;IAC3B;QAAC;QAAiB;YAAEA,IAAI;QAAS;KAAE;IACnC;QAAC;QAAoB;YAAEA,IAAI;QAAY;KAAE;CAC1C;AAED,MAAME,yBAA8C,IAAIC,IAAI;IAAC;IAAY;IAAgB;CAAkB;AAC3G,MAAMC,+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YAAY,CAAC,mBAAmB,EAAE7F,OAAOhB,SAAS,CAAC,+BAA+B,EAAEgB,OAAOvB,OAAO,CAAC2D,MAAM,CAAC,CAAC,CAAC;QACrI;KACD;IACD,MAAM0D,SAAS,IAAIjK;IACnB,KAAK,MAAMkK,QAAQ/F,OAAOvB,OAAO,CAAE;QACjC,MAAMuH,QAAQF,OAAOtG,GAAG,CAACuG,KAAK1G,IAAI;QAClC,IAAI2G,UAAU1I,WAAW;YACvBwI,OAAOzH,GAAG,CAAC0H,KAAK1G,IAAI,EAAE;gBAAC0G;aAAK;QAC9B,OAAO;YACLC,MAAM/H,IAAI,CAAC8H;QACb;IACF;IACA,KAAK,MAAM,CAAC1G,MAAM2G,MAAM,IAAIF,OAAQ;QAClCF,MAAM3H,IAAI,CAAC,CAAC,GAAG,EAAEoB,MAAM,EAAE;QACzB,KAAK,MAAM0G,QAAQC,MAAO;YACxBJ,MAAM3H,IAAI,CAAC,CAAC,OAAO,EAAE8H,KAAKlG,IAAI,CAAC,EAAE,EAAEkG,KAAK9F,MAAM,CAAC,KAAK,EAAE8F,KAAK5F,IAAI,CAAC,EAAE,CAAC;QACrE;QACAyF,MAAM3H,IAAI,CAAC;IACb;IACA,OAAO2H,MAAMvB,IAAI,CAAC;AACpB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** A call site the codemod refused to convert, with the reason for manual review. */
|
|
2
|
+
export interface SkippedSite {
|
|
3
|
+
readonly file: string;
|
|
4
|
+
readonly line: number;
|
|
5
|
+
readonly reason: 'result-async' | 'safe-try' | 'unsupported' | 'namespace-import';
|
|
6
|
+
readonly text: string;
|
|
7
|
+
}
|
|
8
|
+
export interface MigrateFileResult {
|
|
9
|
+
readonly output: string;
|
|
10
|
+
readonly changed: boolean;
|
|
11
|
+
readonly converted: number;
|
|
12
|
+
readonly skipped: SkippedSite[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Migrates one source file from neverthrow to nalloc.
|
|
16
|
+
* Pure function: parses, rewrites provable sites via text splices (formatting preserved),
|
|
17
|
+
* and reports everything it refuses to convert.
|
|
18
|
+
* @param source - The file's source text
|
|
19
|
+
* @param file - File path used in the report
|
|
20
|
+
* @returns The migrated source, whether it changed, and the skipped sites
|
|
21
|
+
*/
|
|
22
|
+
export declare function migrateSource(source: string, file: string): MigrateFileResult;
|
|
23
|
+
export interface MigrationReport {
|
|
24
|
+
readonly filesChanged: number;
|
|
25
|
+
readonly converted: number;
|
|
26
|
+
readonly skipped: readonly SkippedSite[];
|
|
27
|
+
}
|
|
28
|
+
/** Renders the skipped-site report as markdown for --report. */
|
|
29
|
+
export declare function renderReport(report: MigrationReport): string;
|