/** * The migration off `velar/collections`: which of its exports retired into * which List member, the one report each retired name earns, and the rewrite * that moves a module off the module in one pass. * * D115 §三: this was the tail of `analysis/collections.ts`, which owns what a * collection *is*. What a retired import spelling becomes is a different * subject — it reads the module's imports and its call sites, not any * collection's members — so it is its own module of the collection directory, * which keeps only the roster question `retiredCollectionExport` answers. */ import { type Program } from "../../ast.ts"; import { type Diagnostic } from "../../diagnostic.ts"; import { type Span } from "../../source.ts"; /** * D114 S3 / D35: `velar/collections` retired. Twelve of its exports duplicated * a List method word for word, four were `get`/`slice` under other names, three * survived only because the method side lacked `min(by=)`, `max(by=)` and a * descending order, and the rest are List members now. `range` is unaffected — * it was already the Core prelude name, and its import keeps the VEL3008 the * roster above reports. * * Each entry carries the retired function's own parameter names, so a * named-argument call can be read back into positions before it is rewritten, * and the member call that replaces it. A `rewrite` of null is guidance only: * `enumerate`'s `{index, value}` records have consumers no edit can reach. */ export interface RetiredCollectionExport { /** The retired function's declared parameters, first one being the receiver. */ readonly parameters: readonly string[]; readonly guidance: string; readonly rewrite: { readonly member: string; /** Literal arguments the member call leads with, e.g. `get(0)` for `first`. */ readonly fixedArguments: readonly string[]; /** The name each remaining retired argument is passed under; null is positional. */ readonly argumentNames: readonly (string | null)[]; /** `repeat(value, count)` repeats a one-element List, so its receiver is `[value]`. */ readonly receiverIsListOfArgument?: true; } | null; } export declare const RETIRED_COLLECTION_MODULE = "velar/collections"; /** * D114 item 11: exported because the Core surface digest hashes the retired * spellings. A retirement is a published fact — the name is refused and the * message names its successor — so changing one moves the `core` counter. */ export declare const retiredCollectionExports: ReadonlyMap; export declare function retiredCollectionExport(source: string, name: string): RetiredCollectionExport | null; /** What the migration asks of the analyzer that hosts it, and nothing more. */ export interface RetiredCollectionMigrationHost { readonly diagnostics: Diagnostic[]; readonly sourceText: string; renderNamedImport(source: string, specifiers: readonly { readonly imported: string; readonly local: string; }[]): string; } export declare class RetiredCollectionMigration { private readonly host; constructor(host: RetiredCollectionMigrationHost); readonly importOrigins: Map; readonly importReads: { readonly local: string; readonly imported: string; readonly span: Span; }[]; readonly calls: Map; register(program: Program): void; /** * D114 S3: one report per retired name, carrying the rewrite when the whole * migration of that name is mechanical — every call site in the module plus * the specifier itself. One name at a time, because that is the unit an * author reads; the *rewrite* is the whole line's, for the reason `migration` * gives. * * The reports are recovered: the import binds as an unchecked value, so a * retirement produces one diagnostic per name instead of that plus a call * error at every site it left behind. */ report(program: Program): void; /** * The whole migration of one import line, as one rewrite. * * Every mechanically migratable name in the line carries the *same* edit * list, because the import statement is one span and two rewrites of it * cannot both be applied against one snapshot: per-name import edits would * make `velar fix` migrate one name per pass and run out of passes on a line * that imports more than a handful. Identical edit lists deduplicate in * `applyMechanicalFixes`, so the pass applies the migration once and the line * is left holding exactly the names no edit can rewrite. * * D114 0.28.0 D-D1: the line's call sites are planned as one set rather than * name by name, because two of them can be the same expression. `velar fix` * splices edits into one snapshot and nothing there composes two that * overlap, so an outer `sum(...)` and an inner `unique(...)` used to be * written over each other — the file was left with an unbalanced ')' , the * inner call unrewritten, its import already deleted, and the command * reporting success. Only the outermost call of each nest is edited now, and * its replacement text is built from the *rewritten* text of everything * inside it, so one nest is one edit whose result parses. */ private migration; /** * Every call one retired name leaves behind, or null when any read of it is * not mechanically rewritable: a read that is not a call, a spread, an * argument plan with a hole, or a rewrite that would erase an authored * comment. A name with no reads left behind answers with no calls, and its * specifier still leaves the import. * * The shape question is asked against the source as written — nesting cannot * make a call rewritable or unrewritable — so this is what decides which * names migrate, before any composed text exists. */ private callSites; /** The planned calls no other planned call encloses — one edit each. */ private outermost; /** * One planned call as its member call, with every planned call inside it * already rewritten. `callSites` proved the shape, so the fallback to the * original text is unreachable; it is written rather than asserted because a * migration may never emit text it did not build. */ private composedCallText; /** * The source of `span` with every outermost planned call inside it replaced * by what it becomes. Applied from the right so the offsets of the edits * still to come stay the ones the source has. */ private rewrittenSpan; /** * The member call one retired function call becomes, or null when it is not * that shape. `written` renders one sub-expression: the source as it stands * while the shape is being decided, and the composed text once it is. */ private callText; /** * A receiver keeps its parentheses when a `.member` suffix would otherwise * bind tighter than the expression it is attached to — a ternary, an * operator chain, an arrow, an `await`. The decision is the receiver's * *shape*, so it is the same whether the text is the original or a rewrite * composed inside it: a call stays a call. */ private postfixReceiverText; private written; /** Both line and block comments withhold a rewrite rather than erasing prose. */ private rewriteErasesComment; } //# sourceMappingURL=retired.d.ts.map