| 76 | } |
| 77 | |
| 78 | export class TcbForLoopTrackTranslator extends TcbExpressionTranslator { |
| 79 | private allowedVariables: Set<Variable>; |
| 80 | |
| 81 | constructor( |
| 82 | tcb: Context, |
| 83 | scope: Scope, |
| 84 | private block: ForLoopBlock, |
| 85 | ) { |
| 86 | super(tcb, scope); |
| 87 | |
| 88 | // Tracking expressions are only allowed to read the `$index`, |
| 89 | // the item and properties off the component instance. |
| 90 | this.allowedVariables = new Set([block.item]); |
| 91 | for (const variable of block.contextVariables) { |
| 92 | if (variable.value === '$index') { |
| 93 | this.allowedVariables.add(variable); |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | protected override resolve(ast: AST): TcbExpr | null { |
| 99 | if ( |
| 100 | ast instanceof PropertyRead && |
| 101 | (ast.receiver instanceof ImplicitReceiver || ast.receiver instanceof ThisReceiver) |
| 102 | ) { |
| 103 | const target = this.tcb.boundTarget.getExpressionTarget(ast); |
| 104 | |
| 105 | if ( |
| 106 | target !== null && |
| 107 | !(target instanceof ArrowFunctionIdentifierParameter) && |
| 108 | (!(target instanceof Variable) || !this.allowedVariables.has(target)) |
| 109 | ) { |
| 110 | this.tcb.oobRecorder.illegalForLoopTrackAccess(this.tcb.id, this.block, ast); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | return super.resolve(ast); |
| 115 | } |
| 116 | } |
nothing calls this directly
no outgoing calls
no test coverage detected