(node, outermostLabeledStatement, convertedLoopBodyStatements)
| 100249 | /*multiLine*/ true), 48 /* EmitFlags.NoSourceMap */ | 384 /* EmitFlags.NoTokenSourceMaps */); |
| 100250 | } |
| 100251 | function convertForOfStatementForArray(node, outermostLabeledStatement, convertedLoopBodyStatements) { |
| 100252 | // The following ES6 code: |
| 100253 | // |
| 100254 | // for (let v of expr) { } |
| 100255 | // |
| 100256 | // should be emitted as |
| 100257 | // |
| 100258 | // for (var _i = 0, _a = expr; _i < _a.length; _i++) { |
| 100259 | // var v = _a[_i]; |
| 100260 | // } |
| 100261 | // |
| 100262 | // where _a and _i are temps emitted to capture the RHS and the counter, |
| 100263 | // respectively. |
| 100264 | // When the left hand side is an expression instead of a let declaration, |
| 100265 | // the "let v" is not emitted. |
| 100266 | // When the left hand side is a let/const, the v is renamed if there is |
| 100267 | // another v in scope. |
| 100268 | // Note that all assignments to the LHS are emitted in the body, including |
| 100269 | // all destructuring. |
| 100270 | // Note also that because an extra statement is needed to assign to the LHS, |
| 100271 | // for-of bodies are always emitted as blocks. |
| 100272 | var expression = ts.visitNode(node.expression, visitor, ts.isExpression); |
| 100273 | // In the case where the user wrote an identifier as the RHS, like this: |
| 100274 | // |
| 100275 | // for (let v of arr) { } |
| 100276 | // |
| 100277 | // we don't want to emit a temporary variable for the RHS, just use it directly. |
| 100278 | var counter = factory.createLoopVariable(); |
| 100279 | var rhsReference = ts.isIdentifier(expression) ? factory.getGeneratedNameForNode(expression) : factory.createTempVariable(/*recordTempVariable*/ undefined); |
| 100280 | // The old emitter does not emit source maps for the expression |
| 100281 | ts.setEmitFlags(expression, 48 /* EmitFlags.NoSourceMap */ | ts.getEmitFlags(expression)); |
| 100282 | var forStatement = ts.setTextRange(factory.createForStatement( |
| 100283 | /*initializer*/ ts.setEmitFlags(ts.setTextRange(factory.createVariableDeclarationList([ |
| 100284 | ts.setTextRange(factory.createVariableDeclaration(counter, /*exclamationToken*/ undefined, /*type*/ undefined, factory.createNumericLiteral(0)), ts.moveRangePos(node.expression, -1)), |
| 100285 | ts.setTextRange(factory.createVariableDeclaration(rhsReference, /*exclamationToken*/ undefined, /*type*/ undefined, expression), node.expression) |
| 100286 | ]), node.expression), 2097152 /* EmitFlags.NoHoisting */), |
| 100287 | /*condition*/ ts.setTextRange(factory.createLessThan(counter, factory.createPropertyAccessExpression(rhsReference, "length")), node.expression), |
| 100288 | /*incrementor*/ ts.setTextRange(factory.createPostfixIncrement(counter), node.expression), |
| 100289 | /*statement*/ convertForOfStatementHead(node, factory.createElementAccessExpression(rhsReference, counter), convertedLoopBodyStatements)), |
| 100290 | /*location*/ node); |
| 100291 | // Disable trailing source maps for the OpenParenToken to align source map emit with the old emitter. |
| 100292 | ts.setEmitFlags(forStatement, 256 /* EmitFlags.NoTokenTrailingSourceMaps */); |
| 100293 | ts.setTextRange(forStatement, node); |
| 100294 | return factory.restoreEnclosingLabel(forStatement, outermostLabeledStatement, convertedLoopState && resetLabel); |
| 100295 | } |
| 100296 | function convertForOfStatementForIterable(node, outermostLabeledStatement, convertedLoopBodyStatements, ancestorFacts) { |
| 100297 | var expression = ts.visitNode(node.expression, visitor, ts.isExpression); |
| 100298 | var iterator = ts.isIdentifier(expression) ? factory.getGeneratedNameForNode(expression) : factory.createTempVariable(/*recordTempVariable*/ undefined); |
nothing calls this directly
no test coverage detected