* Returns an expression of all template guards that apply to this scope, including those of * parent scopes. If no guards have been applied, null is returned.
()
| 342 | * parent scopes. If no guards have been applied, null is returned. |
| 343 | */ |
| 344 | guards(): TcbExpr | null { |
| 345 | let parentGuards: TcbExpr | null = null; |
| 346 | if (this.parent !== null) { |
| 347 | // Start with the guards from the parent scope, if present. |
| 348 | parentGuards = this.parent.guards(); |
| 349 | } |
| 350 | |
| 351 | if (this.guard === null) { |
| 352 | // This scope does not have a guard, so return the parent's guards as is. |
| 353 | return parentGuards; |
| 354 | } else if (parentGuards === null) { |
| 355 | // There's no guards from the parent scope, so this scope's guard represents all available |
| 356 | // guards. |
| 357 | return typeof this.guard === 'string' ? new TcbExpr(this.guard) : this.guard; |
| 358 | } else { |
| 359 | // Both the parent scope and this scope provide a guard, so create a combination of the two. |
| 360 | // It is important that the parent guard is used as left operand, given that it may provide |
| 361 | // narrowing that is required for this scope's guard to be valid. |
| 362 | const guard = typeof this.guard === 'string' ? this.guard : this.guard.print(); |
| 363 | return new TcbExpr(`(${parentGuards.print()}) && (${guard})`); |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | /** Returns whether a template symbol is defined locally within the current scope. */ |
| 368 | isLocal(node: Variable | LetDeclaration | Reference): boolean { |
no test coverage detected