import type { Children } from "@alloy-js/core"; import { Declaration as CoreDeclaration, createSymbolSlot, Name, Show, } from "@alloy-js/core"; import { useTSNamePolicy } from "../name-policy.js"; import { createValueSymbol } from "../symbols/index.js"; import { TSSymbolFlags } from "../symbols/ts-output-symbol.js"; import type { CommonDeclarationProps } from "./Declaration.js"; import { JSDoc } from "./JSDoc.jsx"; import { TypeRefContext } from "./TypeRefContext.jsx"; export interface VarDeclarationProps extends CommonDeclarationProps { const?: boolean; let?: boolean; var?: boolean; initializer?: Children; type?: Children; nullish?: boolean; } export function VarDeclaration(props: VarDeclarationProps) { const TypeSymbolSlot = createSymbolSlot(); const ValueTypeSymbolSlot = createSymbolSlot(); const sym = createValueSymbol(props.name, { refkeys: props.refkey, default: props.default, export: props.export, metadata: props.metadata, tsFlags: props.nullish ? TSSymbolFlags.Nullish : TSSymbolFlags.None, type: props.type ? TypeSymbolSlot.firstSymbol : undefined, namePolicy: useTSNamePolicy().for("variable"), }); if (!props.type) { ValueTypeSymbolSlot.moveMembersTo(sym); } const keyword = props.var ? "var" : props.let ? "let" : "const"; const type = props.type ? ( : {props.type} ) : undefined; return ( <> {props.export ? "export " : ""} {props.default ? "default " : ""} {keyword} {type} {" = "} {props.initializer ?? props.children} ); }