import type { TSESTree } from '@typescript-eslint/types'; import type { Construct } from '../../constructs/construct.js'; import { loadOxcParser } from '../oxc-parser.js'; /** Why a file, a construct or a value cannot be edited; the message is shown to the user as the reason it was skipped. */ export declare class WriteBackSkipped extends Error { } export type Node = TSESTree.Node; /** A token or a comment of the parsed file: only its kind and where it sits are read. */ export interface SourceToken { kind: 'token' | 'comment'; /** The token's text; empty for a comment. */ value: string; range: [number, number]; } /** * A parsed file with its comments, which the splicer needs to tell a comma * of the source from one inside a comment. */ export interface ParsedSource { /** The text the program was parsed from; every range below indexes it. */ text: string; program: TSESTree.Program; /** The `[start, end)` of every comment, in source order. */ comments: Array<[number, number]>; } /** A replacement of the bytes `[start, end)` of the parsed text. */ export interface Splice { start: number; end: number; text: string; } /** * The tokens and comments lying within `[start, end)`, read off the text of * a gap between two nodes, such as between a list's last member and its * closing bracket, or between `import` and a specifier. Such a gap holds * only whitespace, comments, punctuation and keywords or names (`from`, a * default import), never a string or a regular expression, so outside the * parser's comments each run of word characters is one token and every * other non-space character is a one-character token. */ export declare function gapTokens(source: ParsedSource, start: number, end: number): SourceToken[]; /** The one module that exports the constructs and their helpers by name. */ export declare const CONSTRUCTS_MODULE = "checkly/constructs"; export declare function parseSource(filePath: string, text: string, loadParser?: typeof loadOxcParser): ParsedSource; /** * Every node below (and including) `root`, in source order: a parent before * its children, and siblings by where they start, whatever order the parser * put their keys in. Only object-valued keys are followed, which covers every * ESTree child slot. */ export declare function walk(root: Node): Generator; /** The string a literal argument spells, for a plain string literal or a template with no `${}` in it. */ export declare function stringOf(node: Node | null | undefined): string | undefined; /** * The local names this file binds to the given exported names of a checkly * package: `import { ApiCheck } from 'checkly/constructs'`, * `import { ApiCheck as Api } from 'checkly'`, and the top-level * `const { ApiCheck } = require('checkly/constructs')` (with or without a * rename). Anything bound another way — a namespace import, a re-export from * the user's own module, a wrapper class — is not a construct call this * module can recognise, which keeps it from editing the options of a class * that merely shares the name. A type-only import (`import type`, or a * `type` specifier) binds nothing at runtime and is not a binding here. * Scope is not tracked: a local that shadows the import inside a function * is taken for it, which the logical id and the later read-back of the edit * bound. */ export declare function checklyBindings(program: TSESTree.Program, exportedNames: ReadonlySet): Set; /** The one local name the file binds an exported name to, if any (the first when several). */ export declare function localBinding(program: TSESTree.Program, name: string): string | undefined; /** * The splice that appends `members` to a multi-line list after its last * member: one per line at `indentation`, after the line the last member * (or its comma) ends on, so a comment on that line stays with that * member — unless a comment runs on past that line end, in which case they * go right after the member's comma rather than into the comment. The * trailing comma is kept when the list has one, and added to the last * member when it has none; `close` is the offset of the closing bracket. */ export declare function appendAfterLast(source: ParsedSource, last: Node, close: number, members: readonly string[], indentation: string, lineEnding: string): Splice; export declare function isChecklyRequire(node: Node | null | undefined): boolean; /** A name that can be written as an identifier: a variable, or an object key without quotes. */ export declare const IDENTIFIER: RegExp; /** The names `checkly/constructs` exports for a construct's class; empty for a class of the user's own. */ export declare function exportedNamesOf(construct: Construct): Set; /** * The options object literal of the one `new ('', { … })` * in the file, where `` is bound to one of `exportedNames` from a * checkly package. * * @throws WriteBackSkipped when the file has no such call, several of them, * or its options are not a plain object literal (a variable, a spread, a call, * a TypeScript `as`/`satisfies` wrapper): anything the rewriter cannot edit * without guessing what the code means. */ export declare function findConstructOptions({ program }: ParsedSource, logicalId: string, exportedNames: ReadonlySet): TSESTree.ObjectExpression; /** * The name of the top-level variable the file initialises with its one * `new ('', …)`, exported or not, where `` is bound * to one of `exportedNames` from a checkly package. None when the construct * is not declared that way (made inside a function or a loop, passed straight * to another call, destructured), or when several declarations match. */ export declare function findConstructVariable({ program }: ParsedSource, logicalId: string, exportedNames: ReadonlySet): string | undefined; /** The name of a plain `key: value` member, or undefined for a spread, method, accessor or computed key. */ export declare function memberName(property: TSESTree.ObjectExpressionProperty | TSESTree.SpreadElement): string | undefined; /** * The properties a construct's options literal spells out, as the dotted * paths `ContextOptions.spelledOut` takes: every plain `key: value` member, * the members of an object value under its key, the members of the one * object argument of a call or `new` (a builder such as * `RetryStrategyBuilder.linearStrategy({ … })`) under the property's key, * and, for an object element of an array with a string `key` property, its * members under `[]`. Spreads, computed keys, methods and * elements without such a key add nothing, and neither do the arguments of a * call with several (`AlertEscalationBuilder.runBasedEscalation(1, { … })`): * the codegen could not tell which value they stand for. */ export declare function spelledOutPaths(options: TSESTree.ObjectExpression): Set; /** * Whether `name` is used as an identifier anywhere in the program: a * declaration, an import, a reference, a type name. Member and property * names (`x.name`, `{ name: 1 }`) are not identifiers of the name. `walk` * yields a parent before its children, so the key or property node to * ignore is known by the time it comes up. */ /** * Whether the program binds `name` at its top level: an import, a variable, * function or class declaration. A global such as `Date` that a file binds * to something of its own is not the global there. */ export declare function declaresName(program: TSESTree.Program, name: string): boolean; export declare function usesIdentifier(root: Node, name: string): boolean;