import type { BindingPattern, Expression, Program, Statement } from "./ast.ts"; import { type ValueType } from "./types.ts"; import { type LoweringHints } from "./contracts.ts"; import type { CompilerEmbeddedJavaScriptModule, CompilerEmitterOptions } from "./extension.ts"; import { type SourceText, type Span } from "./source.ts"; export declare class JavaScriptEmitter { private readonly typeDeclarations; private readonly runtimeTypes; private readonly expandedRuntimeTypes; /** Whether a runtime Type can revisit the same value through its declared type graph. */ private readonly runtimeTypeTraversalGuards; /** * D55 rule 121: the type parameters of the generic record currently being * emitted. Inside that body a `T`-typed position is checked by the argument * predicate the instantiation supplied, which is the only reading of `T` a * validator can have once the type is erased. */ private genericTypeParameters; /** Hoisted `function __velarTypeOf_N()` bodies for instantiations written outside a generic. */ private readonly hoistedGenericInstances; /** * D90 rule R5: one hoisted `function __velarCopyPlanN` per distinct copy * plan, found by the plan's own emitted text. The memo a copy keeps is keyed * by source object *and* plan, so a plan needs an identity that is the same * object at every visit; a module-level function declaration is that identity * and the element callback in one, and it hoists past any temporal dead zone. */ private readonly copyPlans; private readonly copyPlanDeclarations; /** * The copy plans of the generic record currently being emitted. A plan that * reads `__velarArguments` cannot hoist to module level and must not be * shared between instantiations, so it is interned onto the instantiation's * own arguments object instead — one array per instantiation, built once. */ private genericCopyPlans; private genericCopyPlanNames; /** * The plan array the generic record whose copy was emitted last needs on its * arguments object, empty when every one of its plans hoisted to module level. */ private pendingGenericCopyPlans; /** Whether a copy plan is being asked about rather than emitted, so nothing is interned. */ private copyPlanProbe; private readonly externModuleExports; private needsExternExportHelper; protected readonly hints: LoweringHints; private readonly forcedFunctionExports; private readonly sharedRuntimeModules; private readonly requiredRuntimeModules; private needsIndexHelpers; private needsBinaryHelpers; private needsBitwiseHelpers; private needsCollectionHelpers; private needsPrimitiveHelpers; private needsRecordHelpers; private needsObjectBindingHelpers; private needsListBindingHelpers; private needsDirectCollectionInfrastructure; private needsRuntimeTypeHelpers; private needsNumberHelper; private needsThrownValueHelper; private needsErrorCodeHelper; private readonly requiredHostErrorClasses; private needsDetachedTaskHelper; private needsDisposalHelper; private needsIntegrityFailureHelper; private needsRequiredValueHelper; private needsNarrowingErrorClass; private needsAssertionErrorClass; private readonly suppressedPromiseValues; private nextJavaScriptNodeId; private readonly javaScriptNodeSpans; private readonly typeCheckDeclarations; private generatedMappings; private generatedCode; private readonly sourcePath; private readonly authorSource; private readonly executeMain; private readonly embeddedJavaScript; private readonly statements; private readonly expressions; private readonly helperNames; private readonly classEmitter; private readonly matching; private readonly validators; private readonly typeChecks; private readonly runtimeImports; private readonly sourceMapper; /** * The one object every collaborator is handed. Its properties are live reads * and writes of the emitter: a family that records "this module needs the * collection helpers" must set the emitter's own flag, because `emit()` reads * it after every family has run. */ private emitterHost; /** * The half of the host that is plain function values: every call a family * makes back into the emitter or into another family. They are values, not * accessors, so `emitterHost` spreads them; the state half has to stay * accessors there, because the emitter's flags move while a family runs. */ private emitterCallHost; constructor(hints: LoweringHints, forcedFunctionExports?: ReadonlySet, options?: CompilerEmitterOptions); emit(program: Program): string; /** * Phase one of the runtime-import selection: the namespaces a builtin value * reference imports, the binary, bitwise and duration helpers, the reactive * bridge and its closure, and the scan of emitted identifiers every later * phase asks its questions of. */ private selectSourceHelpers; /** * Phase two: the helpers a lowering needs to read a field through its guard, * narrow at run time, normalize a Promise, or expose an extern module's * exports. */ private selectFieldAndNarrowingHelpers; /** * Phase three: the error and task channel — structural async pull, detached * tasks, disposal, the three compiler-raised error classes, error * normalization, and the named capability errors a source reference names. */ private selectErrorAndTaskHelpers; /** * Phase four: the collection and runtime-`Type` infrastructure, whether it * arrives as a shared runtime module or as helpers emitted into this module. */ private selectCollectionHelpers; /** * Phase five: record construction and projection, the two binding-pattern * helpers, and the number helper — the lowerings whose helpers depend on * which record and binding names the emitted code actually used. */ private selectRecordAndBindingHelpers; /** * The two record constructors: the plain one, and the asynchronous one that * awaits its field values before the record is sealed. */ private selectRecordConstructionHelpers; /** * The duration arithmetic an extension lowered: one helper pair emitted * whenever any call in the module was resolved to it. */ private selectDurationHelpers; /** * The two binding-pattern helpers a destructuring emits, and the number * helper a numeric method lowers through. */ private selectBindingHelpers; /** * AS-U2: where a compiler-injected guard fires, as `file:line:column` — the * position every other report uses; a byte offset sat directly above a stack * frame spelling the same place readably. The file is its base name, so the * emitted module stays byte-identical wherever the project is checked out. */ runtimeLocation(offset: number): string; sourceMap(source: SourceText): string; embeddedModules(source: SourceText, emitSourceMap?: boolean): readonly CompilerEmbeddedJavaScriptModule[]; runtimeModules(): readonly string[]; protected emitMappedJavaScript(sourceSpan: Span, render: () => string): string; protected additionalHelpers(_program: Program): readonly string[]; protected reactiveBridgeHelpers(needsJavaScriptCallBoundary: boolean, needsCollections: boolean, usedIdentifiers?: ReadonlySet): readonly string[]; protected usesSharedRuntimeModules(): boolean; protected detachedTaskHelpers(): readonly string[]; /** * D43 item 69 rule 8: a release that fails while an error is already in * flight must not replace it. The original error keeps the throw; the release * failure is normalized and reported through the host channel. The reporter * itself never fails outward, for the same reason the detached-task reporter * does not — a throw inside it would end the process. */ protected disposalHelpers(): readonly string[]; /** * D51 rule 103: the three failures that mean "this program has a bug", by the * one name each of them stamps on itself. A forged name can only make a * failure propagate instead of becoming `null`, which is the safe direction: * `try` never hides a guard, and `catch` still receives everything. */ protected integrityFailureHelpers(): readonly string[]; /** * D86 rule 212: `value!` raises the same `AssertionError` an * `assert value != null` raises, so the integrity check above keeps letting * it through `try` — a broken assertion is a bug, never a "not found". */ protected requiredValueHelpers(): readonly string[]; protected requireRuntimeModule(source: string): void; protected includesErrorNormalizationRuntime(): boolean; protected visitExtensionRuntimeExpression(_expression: Expression, _visitExpression: (expression: Expression) => void): boolean; protected visitExtensionRuntimeStatement(_statement: Statement, _visitExpression: (expression: Expression) => void, _visitStatement: (statement: Statement) => void): boolean; protected extensionExpressionContainsDirectAwait(_expression: Expression, _contains: (expression: Expression) => boolean): boolean | undefined; protected extensionStatementContainsDirectAwait(_statement: Statement, _containsExpression: (expression: Expression) => boolean, _containsBlock: (statements: readonly Statement[]) => boolean): boolean | undefined; protected emitMappedStatement(statement: Statement, depth: number): string; /** * D43 item 69: a `using` binding owns the rest of its block, so a statement * list is emitted as a whole. Everything after the binding moves inside the * release frame; a second `using` nests inside the first, which is what makes * release order the reverse of declaration order. */ protected emitStatementLines(statements: readonly Statement[], depth: number): readonly string[]; protected emitStatement(statement: Statement, depth: number): string; protected emitTypeCheck(type: ValueType, value: string, state?: string): string; protected emitIsCheck(type: ValueType, value: string): string; protected emitNarrowingCheck(type: ValueType, value: string, state?: string): string; /** * D55 rule 121: the name a module writes for a generic record is a JavaScript * binding holding its instantiation factory — declared here, or imported from * the module that declares it. Nothing else may be written into `.of(...)`. */ protected genericTypeBinding(name: string): boolean; /** * D60 rule 148: a `named` ValueType carries the type's *display* name, which * is a runtime binding only when this module really has a Type object under * it — a local `type` declaration, an imported one, an enum, or a class. An * unresolved generic formats to type text (`Component<(label: string) -> * WebNode>`) that is not even a JavaScript identifier, and an extension host * scalar (`Color`, `Length`, `WebNode`) has no binding at all. Writing either * into the output is how `velar check` passed and `velar build` then failed * to parse its own emission; the narrowing path (FLW-U1) already asks this * question, and every other check path now asks it too. */ protected runtimeTypeBinding(name: string): boolean; /** Source-visible nominal bindings; imported signature owners are resolved by TypeCheckEmitter. */ protected nominalRuntimeReceiver(type: Extract): string | null; protected emitParameter(name: string, defaultValue: Expression | null, rest?: boolean): string; protected emitMappedExpression(expression: Expression, normalizeNull?: boolean): string; private emitMappedAssignmentTarget; protected emitExpression(expression: Expression): string; protected emitCondition(expression: Expression): string; protected expressionContainsDirectAwait(expression: Expression): boolean; protected emitObjectKey(name: string): string; protected emitBindingPatternStatements(pattern: BindingPattern, value: string, binding: "const" | "let", exported: boolean, depth: number, label: string): readonly string[]; protected blockAlwaysReturns(statements: readonly Statement[]): boolean; } //# sourceMappingURL=emitter.d.ts.map