/** * The control-flow statement forms: `@main`, `return`, `throw`, `assert`, * `if`, `try`, an expression on its own line, `detach`, and a `test` block — * plus the three refusals an expression statement earns when its result goes * nowhere. * * D114 R1f: these leave `analyzer.ts` together because they are the statements * whose whole job is where control goes next; the flow *facts* they push and * merge already live under `flow/`, and this module only decides which branch * they belong to. */ import { type DetachStatement, type Expression, type Statement, type TestDeclaration } from "../../ast.ts"; import { type CollectionOperation, type PrimitiveOperation } from "../../contracts.ts"; import { type Diagnostic, type DiagnosticFix } from "../../diagnostic.ts"; import { type Span } from "../../source.ts"; import { type ValueType } from "../../types.ts"; import { type FlowFactInvalidations, type FlowFactsSnapshot } from "../flow/facts.ts"; import { type ReturnContext } from "../functions.ts"; import { type EmptyCollectionTarget } from "../expressions/contextual.ts"; import { type Binding, type BuiltinTypeNamePosition, type MutableCellTarget, type VisibleScopeDepth } from "../scopes.ts"; /** The lowering facts a control statement records for the emitter. */ export interface ControlLoweringFacts { readonly asyncResolvedValues: Set; readonly collectionCalls: Map; readonly primitiveCalls: Map; } /** * Everything the control statements ask of the analyzer that hosts them, and * nothing more. The frame state a `test` block and a `try` move — the function, * flow and loop depths, the finally-loop stack, the return contexts — arrives * as live accessors, because the body being analyzed is what changes them. */ export interface ControlStatementsHost { analyzeBlock(statements: readonly Statement[], narrowed?: ReadonlyMap): ReadonlyMap; analyzeIsolatedFlow(snapshot: FlowFactsSnapshot, analyze: () => void): FlowFactInvalidations; analyzeStatements(statements: readonly Statement[]): void; applyFlowInvalidations(branches: readonly FlowFactInvalidations[], includeBaseline?: boolean): void; readonly asynchronousFunctions: boolean[]; blockAlwaysExits(statements: readonly Statement[]): boolean; blockAlwaysReturns(statements: readonly Statement[]): boolean; collectResultHoleSources(expression: Expression, causes: Set): boolean; commonNarrowings(branches: readonly ReadonlyMap[]): ReadonlyMap; readonly constructorDepth: number; declareBinding(name: string, mutable: boolean, type: ValueType, declarationSpan: Span, internal?: boolean, declaredType?: ValueType, importSource?: string, typeNamePosition?: BuiltinTypeNamePosition): void; readonly declaredTestTitles: Set; deferredExecutionDepth: number; readonly diagnostics: Diagnostic[]; enterScope(): void; readonly executeMain: boolean; exitScope(): void; expandAliases(type: ValueType, seen?: ReadonlySet): ValueType; extensionOwnsFunctionlessReturn(): boolean; finallyLoopDepths: number[]; flowFrameDepth: number; flowSnapshotAfterInvalidations(baseline: FlowFactsSnapshot, invalidations: readonly FlowFactInvalidations[]): FlowFactsSnapshot; functionDepth: number; inferExpression(expression: Expression, contextualType?: ValueType): ValueType; inferNarrowedExpression(expression: Expression, narrowed: ReadonlyMap, contextualType: ValueType): ValueType; inModuleInitializationPosition(): boolean; isSubclassOf(actual: string, expected: string): boolean; loopDepth: number; readonly lowering: ControlLoweringFacts; readonly modulePath: string | null; narrowingFor(expression: Expression, knownType?: ValueType): ReadonlyMap; narrowingsForVisibleBindings(visible: VisibleScopeDepth): ReadonlyMap; negativeNarrowingFor(expression: Expression, knownType?: ValueType): ReadonlyMap; persistNarrowings(narrowed: ReadonlyMap): void; promiseResolutionHazard(type: ValueType): string | null; promiseResolutionNeedsRuntimeGuard(type: ValueType): boolean; rejectOwnedResourceEscape(expression: Expression | null, action: string, errorSpan: Span): boolean; reportPromiseResolutionHazard(type: ValueType, errorSpan: Span): void; requireAssignable(actual: ValueType, expected: ValueType, valueSpan: Span, mutableCell?: MutableCellTarget | null): void; requireCondition(type: ValueType, condition: Expression): void; requireSettledCollectionElement(initializer: Expression, declared: ValueType, annotated: boolean, target?: EmptyCollectionTarget | null): boolean; resolvedAsyncResult(type: ValueType): ValueType; restoreFlowFacts(snapshot: FlowFactsSnapshot): void; readonly returnContexts: ReturnContext[]; readonly scopes: Map[]; snapshotFlowFacts(): FlowFactsSnapshot; readonly testExpectOperands: ReadonlyMap; typeError(message: string, errorSpan: Span, fix?: DiagnosticFix): void; readonly unreachableDiagnosticDepth: number; visibleBindings(): VisibleScopeDepth; } export declare class ControlStatements { private readonly host; constructor(host: ControlStatementsHost); analyzeMainBlock(statement: Extract): void; analyzeReturnStatement(statement: Extract): void; analyzeThrowStatement(statement: Extract): void; analyzeAssertStatement(statement: Extract): void; analyzeIfStatement(statement: Extract): void; analyzeTryStatement(statement: Extract): void; analyzeExpressionStatement(statement: Extract): void; private checkFloatingPromiseStatement; private checkDiscardedExpressionResult; private carriesPromise; private checkDiscardedPureResult; private callSpelling; analyzeDetachStatement(statement: DetachStatement): void; /** * D39 item 53: `test "name":` is one test. Its body is an async frame — a * test awaits its own work — and its name is the product specification a * person reads, so it must be present, unique in the module, and declared * where the runner actually looks. */ analyzeTestDeclaration(statement: TestDeclaration): void; } //# sourceMappingURL=control.d.ts.map