Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 256x 119x 119x 137x 110x 27x | /**
* What a value binding declares, for the rules that ask about the
* declaration rather than the value: is it const, what does it initialize
* to, is it a parameter (#1668).
*
* Program's binder answers WHICH declaration a spelling means; this reads the
* two kinds that carry one -- a local's declaration and a variable's symbol --
* so no rule re-derives the switch between them.
*/
import type TValueBinding from "../../../types/TValueBinding";
interface IBoundDeclaration {
readonly isConst: boolean;
readonly isParameter: boolean;
/** The initializer's text, or null */
readonly initialValue: string | null;
}
class BoundDeclaration {
/** A local's or a variable's declaration, or null for anything else */
static of(binding: TValueBinding | null): IBoundDeclaration | null {
if (binding?.kind === "local") {
const declaration = binding.declaration;
return {
isConst: declaration.isConst,
isParameter: declaration.kind === "parameter",
initialValue: declaration.initialValue,
};
}
if (binding?.kind === "variable") {
return {
isConst: binding.symbol.isConst,
isParameter: false,
initialValue: binding.symbol.initialValue ?? null,
};
}
return null;
}
}
export default BoundDeclaration;
|