From a2774c10d50a4f820ab824a9688ccc308253a962 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 4 Feb 2016 13:18:34 -0800 Subject: [PATCH] port PR #6898 --- src/compiler/checker.ts | 44 +++ src/compiler/emitter.ts | 147 +++++++-- src/compiler/types.ts | 1 + .../blockScopedBindingsReassignedInLoop1.js | 22 ++ ...ockScopedBindingsReassignedInLoop1.symbols | 17 + ...blockScopedBindingsReassignedInLoop1.types | 32 ++ .../blockScopedBindingsReassignedInLoop2.js | 120 +++++++ ...ockScopedBindingsReassignedInLoop2.symbols | 98 ++++++ ...blockScopedBindingsReassignedInLoop2.types | 160 ++++++++++ .../blockScopedBindingsReassignedInLoop3.js | 247 ++++++++++++++ ...ockScopedBindingsReassignedInLoop3.symbols | 203 ++++++++++++ ...blockScopedBindingsReassignedInLoop3.types | 301 ++++++++++++++++++ .../blockScopedBindingsReassignedInLoop4.js | 34 ++ ...ockScopedBindingsReassignedInLoop4.symbols | 28 ++ ...blockScopedBindingsReassignedInLoop4.types | 43 +++ .../blockScopedBindingsReassignedInLoop5.js | 27 ++ ...ockScopedBindingsReassignedInLoop5.symbols | 23 ++ ...blockScopedBindingsReassignedInLoop5.types | 37 +++ .../blockScopedBindingsReassignedInLoop6.js | 74 +++++ ...ockScopedBindingsReassignedInLoop6.symbols | 74 +++++ ...blockScopedBindingsReassignedInLoop6.types | 110 +++++++ .../reference/capturedLetConstInLoop11.js | 2 +- .../reference/capturedLetConstInLoop5.js | 40 +-- .../reference/capturedLetConstInLoop8.js | 4 +- .../reference/capturedLetConstInLoop9.js | 2 +- .../reference/nestedBlockScopedBindings3.js | 6 + .../reference/nestedBlockScopedBindings4.js | 12 + .../reference/nestedBlockScopedBindings5.js | 9 + .../reference/nestedBlockScopedBindings6.js | 6 + .../blockScopedBindingsReassignedInLoop1.ts | 7 + .../blockScopedBindingsReassignedInLoop2.ts | 41 +++ .../blockScopedBindingsReassignedInLoop3.ts | 91 ++++++ .../blockScopedBindingsReassignedInLoop4.ts | 11 + .../blockScopedBindingsReassignedInLoop5.ts | 7 + .../blockScopedBindingsReassignedInLoop6.ts | 28 ++ 35 files changed, 2063 insertions(+), 45 deletions(-) create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop1.js create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop1.symbols create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop1.types create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop2.js create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop2.symbols create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop2.types create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop3.js create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop3.symbols create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop3.types create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop4.js create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop4.symbols create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop4.types create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop5.js create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop5.symbols create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop5.types create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop6.js create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop6.symbols create mode 100644 tests/baselines/reference/blockScopedBindingsReassignedInLoop6.types create mode 100644 tests/cases/compiler/blockScopedBindingsReassignedInLoop1.ts create mode 100644 tests/cases/compiler/blockScopedBindingsReassignedInLoop2.ts create mode 100644 tests/cases/compiler/blockScopedBindingsReassignedInLoop3.ts create mode 100644 tests/cases/compiler/blockScopedBindingsReassignedInLoop4.ts create mode 100644 tests/cases/compiler/blockScopedBindingsReassignedInLoop5.ts create mode 100644 tests/cases/compiler/blockScopedBindingsReassignedInLoop6.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 655ed2bda77..7a8dc4f4563 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7242,6 +7242,15 @@ namespace ts { // mark iteration statement as containing block-scoped binding captured in some function getNodeLinks(current).flags |= NodeCheckFlags.LoopWithCapturedBlockScopedBinding; } + + // mark variables that are declared in loop initializer and reassigned inside the body of ForStatement. + // if body of ForStatement will be converted to function then we'll need a extra machinery to propagate reassigned values back. + if (container.kind === SyntaxKind.ForStatement && + getAncestor(symbol.valueDeclaration, SyntaxKind.VariableDeclarationList).parent === container && + isAssignedInBodyOfForStatement(node, container)) { + getNodeLinks(symbol.valueDeclaration).flags |= NodeCheckFlags.NeedsLoopOutParameter; + } + // set 'declared inside loop' bit on the block-scoped binding getNodeLinks(symbol.valueDeclaration).flags |= NodeCheckFlags.BlockScopedBindingInLoop; } @@ -7251,6 +7260,41 @@ namespace ts { } } + function isAssignedInBodyOfForStatement(node: Identifier, container: ForStatement): boolean { + let current: Node = node; + // skip parenthesized nodes + while (current.parent.kind === SyntaxKind.ParenthesizedExpression) { + current = current.parent; + } + + // check if node is used as LHS in some assignment expression + let isAssigned = false; + if (current.parent.kind === SyntaxKind.BinaryExpression) { + isAssigned = (current.parent).left === current && isAssignmentOperator((current.parent).operatorToken.kind); + } + + if ((current.parent.kind === SyntaxKind.PrefixUnaryExpression || current.parent.kind === SyntaxKind.PostfixUnaryExpression)) { + const expr = current.parent; + isAssigned = expr.operator === SyntaxKind.PlusPlusToken || expr.operator === SyntaxKind.MinusMinusToken; + } + + if (!isAssigned) { + return false; + } + + // at this point we know that node is the target of assignment + // now check that modification happens inside the statement part of the ForStatement + while (current !== container) { + if (current === container.statement) { + return true; + } + else { + current = current.parent; + } + } + return false; + } + function captureLexicalThis(node: Node, container: Node): void { getNodeLinks(node).flags |= NodeCheckFlags.LexicalThis; if (container.kind === SyntaxKind.PropertyDeclaration || container.kind === SyntaxKind.Constructor) { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 98ad7c874d6..35b9bc6eb18 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -287,6 +287,54 @@ namespace ts { _i = 0x10000000, // Use/preference flag for '_i' } + const enum CopyDirection { + ToOriginal, + ToOutParameter + } + + /** + * If loop contains block scoped binding captured in some function then loop body is converted to a function. + * Lexical bindings declared in loop initializer will be passed into the loop body function as parameters, + * however if this binding is modified inside the body - this new value should be propagated back to the original binding. + * This is done by declaring new variable (out parameter holder) outside of the loop for every binding that is reassigned inside the body. + * On every iteration this variable is initialized with value of corresponding binding. + * At every point where control flow leaves the loop either explicitly (break/continue) or implicitly (at the end of loop body) + * we copy the value inside the loop to the out parameter holder. + * + * for (let x;;) { + * let a = 1; + * let b = () => a; + * x++ + * if (...) break; + * ... + * } + * + * will be converted to + * + * var out_x; + * var loop = function(x) { + * var a = 1; + * var b = function() { return a; } + * x++; + * if (...) return out_x = x, "break"; + * ... + * out_x = x; + * } + * for (var x;;) { + * out_x = x; + * var state = loop(x); + * x = out_x; + * if (state === "break") break; + * } + * + * NOTE: values to out parameters are not copies if loop is abrupted with 'return' - in this case this will end the entire enclosing function + * so nobody can observe this new value. + */ + interface LoopOutParameter { + originalName: Identifier; + outParamName: string; + } + // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile: SourceFile): EmitResult { // emit output for the __extends helper function @@ -419,6 +467,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge * for (var x;;) loop(x); */ hoistedLocalVariables?: Identifier[]; + + /** + * List of loop out parameters - detailed descripion can be found in the comment to LoopOutParameter + */ + loopOutParameters?: LoopOutParameter[]; } function setLabeledJump(state: ConvertedLoopState, isBreak: boolean, labelText: string, labelMarker: string): void { @@ -2944,11 +2997,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } let loopParameters: string[]; + let loopOutParameters: LoopOutParameter[]; if (loopInitializer && (getCombinedNodeFlags(loopInitializer) & NodeFlags.BlockScoped)) { // if loop initializer contains block scoped variables - they should be passed to converted loop body as parameters loopParameters = []; for (const varDeclaration of loopInitializer.declarations) { - collectNames(varDeclaration.name); + processVariableDeclaration(varDeclaration.name); } } @@ -2958,14 +3012,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge writeLine(); write(`var ${functionName} = function(${paramList})`); - if (!bodyIsBlock) { - write(" {"); - writeLine(); - increaseIndent(); - } - const convertedOuterLoopState = convertedLoopState; - convertedLoopState = {}; + convertedLoopState = { loopOutParameters }; if (convertedOuterLoopState) { // convertedOuterLoopState !== undefined means that this converted loop is nested in another converted loop. @@ -2989,16 +3037,38 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } } - emitEmbeddedStatement(node.statement); + write(" {"); + writeLine(); + increaseIndent(); - if (!bodyIsBlock) { - decreaseIndent(); - writeLine(); - write("}"); + if (bodyIsBlock) { + emitLines((node.statement).statements); } - write(";"); + else { + emit(node.statement); + } + + writeLine(); + // end of loop body -> copy out parameter + copyLoopOutParameters(convertedLoopState, CopyDirection.ToOutParameter, /*emitAsStatements*/true); + + decreaseIndent(); + writeLine(); + write("};"); writeLine(); + if (loopOutParameters) { + // declare variables to hold out params for loop body + write(`var `); + for (let i = 0; i < loopOutParameters.length; i++) { + if (i !== 0) { + write(", "); + } + write(loopOutParameters[i].outParamName); + } + write(";"); + writeLine(); + } if (convertedLoopState.argumentsName) { // if alias for arguments is set if (convertedOuterLoopState) { @@ -3062,14 +3132,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge return { functionName, paramList, state: currentLoopState }; - function collectNames(name: Identifier | BindingPattern): void { + function processVariableDeclaration(name: Identifier | BindingPattern): void { if (name.kind === SyntaxKind.Identifier) { - const nameText = isNameOfNestedBlockScopedRedeclarationOrCapturedBinding(name) ? getGeneratedNameForNode(name) : (name).text; + const nameText = isNameOfNestedBlockScopedRedeclarationOrCapturedBinding(name) + ? getGeneratedNameForNode(name) + : (name).text; + loopParameters.push(nameText); + if (resolver.getNodeCheckFlags(name.parent) & NodeCheckFlags.NeedsLoopOutParameter) { + const reassignedVariable = { originalName: name, outParamName: makeUniqueName(`out_${nameText}`) }; + (loopOutParameters || (loopOutParameters = [])).push(reassignedVariable); + } } else { for (const element of (name).elements) { - collectNames(element.name); + processVariableDeclaration(element.name); } } } @@ -3100,6 +3177,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } } + function copyLoopOutParameters(state: ConvertedLoopState, copyDirection: CopyDirection, emitAsStatements: boolean) { + if (state.loopOutParameters) { + for (const outParam of state.loopOutParameters) { + if (copyDirection === CopyDirection.ToOriginal) { + emitIdentifier(outParam.originalName); + write(` = ${outParam.outParamName}`); + } + else { + write(`${outParam.outParamName} = `); + emitIdentifier(outParam.originalName); + } + if (emitAsStatements) { + write(";"); + writeLine(); + } + else { + write(", "); + } + } + } + } + function emitConvertedLoopCall(loop: ConvertedLoop, emitAsBlock: boolean): void { if (emitAsBlock) { write(" {"); @@ -3120,6 +3219,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } write(`${loop.functionName}(${loop.paramList});`); + writeLine(); + + copyLoopOutParameters(loop.state, CopyDirection.ToOriginal, /*emitAsStatements*/ true); if (!isSimpleLoop) { // for non simple loops we need to store result returned from converted loop function and use it to do dispatching @@ -3138,7 +3240,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } else { // top level converted loop - return unwrapped value - write(`return ${loopResult}.value`); + write(`return ${loopResult}.value;`); } writeLine(); } @@ -3439,14 +3541,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge (!node.label && (convertedLoopState.allowedNonLabeledJumps & jump)); if (!canUseBreakOrContinue) { + write ("return "); + // explicit exit from loop -> copy out parameters + copyLoopOutParameters(convertedLoopState, CopyDirection.ToOutParameter, /*emitAsStatements*/ false); if (!node.label) { if (node.kind === SyntaxKind.BreakStatement) { convertedLoopState.nonLocalJumps |= Jump.Break; - write(`return "break";`); + write(`"break";`); } else { convertedLoopState.nonLocalJumps |= Jump.Continue; - write(`return "continue";`); + write(`"continue";`); } } else { @@ -3459,7 +3564,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge labelMarker = `continue-${node.label.text}`; setLabeledJump(convertedLoopState, /*isBreak*/ false, node.label.text, labelMarker); } - write(`return "${labelMarker}";`); + write(`"${labelMarker}";`); } return; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ce3dbe7f459..737c4a7587b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2071,6 +2071,7 @@ namespace ts { HasSeenSuperCall = 0x00080000, // Set during the binding when encounter 'super' ClassWithBodyScopedClassBinding = 0x00100000, // Decorated class that contains a binding to itself inside of the class body. BodyScopedClassBinding = 0x00200000, // Binding to a decorated class inside of the class's body. + NeedsLoopOutParameter = 0x00400000, // Block scoped binding whose value should be explicitly copied outside of the converted loop } /* @internal */ diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.js b/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.js new file mode 100644 index 00000000000..609d353fbc7 --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.js @@ -0,0 +1,22 @@ +//// [blockScopedBindingsReassignedInLoop1.ts] +declare function use(n: number): void; +(function () { + 'use strict' + for (let i = 0; i < 9; ++i) { + (() => use(++i))(); + } +})(); + +//// [blockScopedBindingsReassignedInLoop1.js] +(function () { + 'use strict'; + var _loop_1 = function(i) { + (function () { return use(++i); })(); + out_i_1 = i; + }; + var out_i_1; + for (var i = 0; i < 9; ++i) { + _loop_1(i); + i = out_i_1; + } +})(); diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.symbols b/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.symbols new file mode 100644 index 00000000000..8024124b04e --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop1.ts === +declare function use(n: number): void; +>use : Symbol(use, Decl(blockScopedBindingsReassignedInLoop1.ts, 0, 0)) +>n : Symbol(n, Decl(blockScopedBindingsReassignedInLoop1.ts, 0, 21)) + +(function () { + 'use strict' + for (let i = 0; i < 9; ++i) { +>i : Symbol(i, Decl(blockScopedBindingsReassignedInLoop1.ts, 3, 10)) +>i : Symbol(i, Decl(blockScopedBindingsReassignedInLoop1.ts, 3, 10)) +>i : Symbol(i, Decl(blockScopedBindingsReassignedInLoop1.ts, 3, 10)) + + (() => use(++i))(); +>use : Symbol(use, Decl(blockScopedBindingsReassignedInLoop1.ts, 0, 0)) +>i : Symbol(i, Decl(blockScopedBindingsReassignedInLoop1.ts, 3, 10)) + } +})(); diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.types b/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.types new file mode 100644 index 00000000000..7ced53508e6 --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop1.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop1.ts === +declare function use(n: number): void; +>use : (n: number) => void +>n : number + +(function () { +>(function () { 'use strict' for (let i = 0; i < 9; ++i) { (() => use(++i))(); }})() : void +>(function () { 'use strict' for (let i = 0; i < 9; ++i) { (() => use(++i))(); }}) : () => void +>function () { 'use strict' for (let i = 0; i < 9; ++i) { (() => use(++i))(); }} : () => void + + 'use strict' +>'use strict' : string + + for (let i = 0; i < 9; ++i) { +>i : number +>0 : number +>i < 9 : boolean +>i : number +>9 : number +>++i : number +>i : number + + (() => use(++i))(); +>(() => use(++i))() : void +>(() => use(++i)) : () => void +>() => use(++i) : () => void +>use(++i) : void +>use : (n: number) => void +>++i : number +>i : number + } +})(); diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.js b/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.js new file mode 100644 index 00000000000..c48ecd96ffe --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.js @@ -0,0 +1,120 @@ +//// [blockScopedBindingsReassignedInLoop2.ts] +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + break; + } + else { + y = 5; + } +} + +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + continue; + } + else { + y = 5; + } +} + +loop: +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + break loop; + } + else { + y = 5; + } +} + +loop: +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + continue loop; + } + else { + y = 5; + } +} + +//// [blockScopedBindingsReassignedInLoop2.js] +var _loop_1 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) { + return out_x_1 = x, out_y_1 = y, "break"; + } + else { + y = 5; + } + out_x_1 = x; + out_y_1 = y; +}; +var out_x_1, out_y_1; +for (var x = 1, y = 2; x < y; ++x, --y) { + var state_1 = _loop_1(x, y); + x = out_x_1; + y = out_y_1; + if (state_1 === "break") break; +} +var _loop_2 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) { + return out_x_2 = x, out_y_2 = y, "continue"; + } + else { + y = 5; + } + out_x_2 = x; + out_y_2 = y; +}; +var out_x_2, out_y_2; +for (var x = 1, y = 2; x < y; ++x, --y) { + var state_2 = _loop_2(x, y); + x = out_x_2; + y = out_y_2; + if (state_2 === "continue") continue; +} +var _loop_3 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) { + return out_x_3 = x, out_y_3 = y, "break-loop"; + } + else { + y = 5; + } + out_x_3 = x; + out_y_3 = y; +}; +var out_x_3, out_y_3; +loop: for (var x = 1, y = 2; x < y; ++x, --y) { + var state_3 = _loop_3(x, y); + x = out_x_3; + y = out_y_3; + switch(state_3) { + case "break-loop": break loop; + } +} +var _loop_4 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) { + return out_x_4 = x, out_y_4 = y, "continue-loop"; + } + else { + y = 5; + } + out_x_4 = x; + out_y_4 = y; +}; +var out_x_4, out_y_4; +loop: for (var x = 1, y = 2; x < y; ++x, --y) { + var state_4 = _loop_4(x, y); + x = out_x_4; + y = out_y_4; + switch(state_4) { + case "continue-loop": continue loop; + } +} diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.symbols b/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.symbols new file mode 100644 index 00000000000..fcaea39564f --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.symbols @@ -0,0 +1,98 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop2.ts === +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 0, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 0, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 0, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 0, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 0, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 0, 15)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop2.ts, 1, 7)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 0, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 0, 15)) + + if (x == 1) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 0, 8)) + + break; + } + else { + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 0, 15)) + } +} + +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 10, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 10, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 10, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 10, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 10, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 10, 15)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop2.ts, 11, 7)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 10, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 10, 15)) + + if (x == 1) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 10, 8)) + + continue; + } + else { + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 10, 15)) + } +} + +loop: +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 21, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 21, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 21, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 21, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 21, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 21, 15)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop2.ts, 22, 7)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 21, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 21, 15)) + + if (x == 1) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 21, 8)) + + break loop; + } + else { + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 21, 15)) + } +} + +loop: +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 32, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 32, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 32, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 32, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 32, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 32, 15)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop2.ts, 33, 7)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 32, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 32, 15)) + + if (x == 1) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop2.ts, 32, 8)) + + continue loop; + } + else { + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop2.ts, 32, 15)) + } +} diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.types b/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.types new file mode 100644 index 00000000000..244160dcc6b --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.types @@ -0,0 +1,160 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop2.ts === +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : number +>1 : number +>y : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) { +>x == 1 : boolean +>x : number +>1 : number + + break; + } + else { + y = 5; +>y = 5 : number +>y : number +>5 : number + } +} + +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : number +>1 : number +>y : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) { +>x == 1 : boolean +>x : number +>1 : number + + continue; + } + else { + y = 5; +>y = 5 : number +>y : number +>5 : number + } +} + +loop: +>loop : any + +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : number +>1 : number +>y : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) { +>x == 1 : boolean +>x : number +>1 : number + + break loop; +>loop : any + } + else { + y = 5; +>y = 5 : number +>y : number +>5 : number + } +} + +loop: +>loop : any + +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : number +>1 : number +>y : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) { +>x == 1 : boolean +>x : number +>1 : number + + continue loop; +>loop : any + } + else { + y = 5; +>y = 5 : number +>y : number +>5 : number + } +} diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.js b/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.js new file mode 100644 index 00000000000..10160202621 --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.js @@ -0,0 +1,247 @@ +//// [blockScopedBindingsReassignedInLoop3.ts] + +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + break; + } + else { + for (let a = 1; a < 5; --a) { + let f = () => a; + if (a) { + a = x; + break; + } + else { + y++; + } + } + + y = 5; + } +} + + +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + continue; + } + else { + for (let a = 1; a < 5; --a) { + let f = () => a; + if (a) { + a = x; + continue; + } + else { + y++; + } + } + + y = 5; + } +} + +loop2: +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + break loop2; + } + else { + loop1: + for (let a = 1; a < 5; --a) { + let f = () => a; + if (a) { + a = x; + break loop1; + } + else { + y++; + break loop2 + } + } + + y = 5; + } +} + +loop2: +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + continue loop2; + } + else { + loop1: + for (let a = 1; a < 5; --a) { + let f = () => a; + if (a) { + a = x; + continue loop1; + } + else { + y++; + continue loop2 + } + } + + y = 5; + } +} + + +//// [blockScopedBindingsReassignedInLoop3.js] +var _loop_1 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) { + return out_x_1 = x, out_y_1 = y, "break"; + } + else { + var _loop_2 = function(a_1) { + var f = function () { return a_1; }; + if (a_1) { + a_1 = x; + return out_a_1_1 = a_1, "break"; + } + else { + y++; + } + out_a_1_1 = a_1; + }; + var out_a_1_1; + for (var a_1 = 1; a_1 < 5; --a_1) { + var state_1 = _loop_2(a_1); + a_1 = out_a_1_1; + if (state_1 === "break") break; + } + y = 5; + } + out_x_1 = x; + out_y_1 = y; +}; +var out_x_1, out_y_1; +for (var x = 1, y = 2; x < y; ++x, --y) { + var state_2 = _loop_1(x, y); + x = out_x_1; + y = out_y_1; + if (state_2 === "break") break; +} +var _loop_3 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) { + return out_x_2 = x, out_y_2 = y, "continue"; + } + else { + var _loop_4 = function(a_2) { + var f = function () { return a_2; }; + if (a_2) { + a_2 = x; + return out_a_2_1 = a_2, "continue"; + } + else { + y++; + } + out_a_2_1 = a_2; + }; + var out_a_2_1; + for (var a_2 = 1; a_2 < 5; --a_2) { + var state_3 = _loop_4(a_2); + a_2 = out_a_2_1; + if (state_3 === "continue") continue; + } + y = 5; + } + out_x_2 = x; + out_y_2 = y; +}; +var out_x_2, out_y_2; +for (var x = 1, y = 2; x < y; ++x, --y) { + var state_4 = _loop_3(x, y); + x = out_x_2; + y = out_y_2; + if (state_4 === "continue") continue; +} +var _loop_5 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) { + return out_x_3 = x, out_y_3 = y, "break-loop2"; + } + else { + var _loop_6 = function(a_3) { + var f = function () { return a_3; }; + if (a_3) { + a_3 = x; + return out_a_3_1 = a_3, "break-loop1"; + } + else { + y++; + return out_a_3_1 = a_3, "break-loop2"; + } + out_a_3_1 = a_3; + }; + var out_a_3_1; + loop1: for (var a_3 = 1; a_3 < 5; --a_3) { + var state_5 = _loop_6(a_3); + a_3 = out_a_3_1; + switch(state_5) { + case "break-loop1": break loop1; + case "break-loop2": return state_5; + } + } + y = 5; + } + out_x_3 = x; + out_y_3 = y; +}; +var out_x_3, out_y_3; +loop2: for (var x = 1, y = 2; x < y; ++x, --y) { + var state_6 = _loop_5(x, y); + x = out_x_3; + y = out_y_3; + switch(state_6) { + case "break-loop2": break loop2; + } +} +var _loop_7 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) { + return out_x_4 = x, out_y_4 = y, "continue-loop2"; + } + else { + var _loop_8 = function(a_4) { + var f = function () { return a_4; }; + if (a_4) { + a_4 = x; + return out_a_4_1 = a_4, "continue-loop1"; + } + else { + y++; + return out_a_4_1 = a_4, "continue-loop2"; + } + out_a_4_1 = a_4; + }; + var out_a_4_1; + loop1: for (var a_4 = 1; a_4 < 5; --a_4) { + var state_7 = _loop_8(a_4); + a_4 = out_a_4_1; + switch(state_7) { + case "continue-loop1": continue loop1; + case "continue-loop2": return state_7; + } + } + y = 5; + } + out_x_4 = x; + out_y_4 = y; +}; +var out_x_4, out_y_4; +loop2: for (var x = 1, y = 2; x < y; ++x, --y) { + var state_8 = _loop_7(x, y); + x = out_x_4; + y = out_y_4; + switch(state_8) { + case "continue-loop2": continue loop2; + } +} diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.symbols b/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.symbols new file mode 100644 index 00000000000..f78cd684c3a --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.symbols @@ -0,0 +1,203 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop3.ts === + +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 15)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 2, 7)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 15)) + + if (x == 1) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 8)) + + break; + } + else { + for (let a = 1; a < 5; --a) { +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 7, 16)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 7, 16)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 7, 16)) + + let f = () => a; +>f : Symbol(f, Decl(blockScopedBindingsReassignedInLoop3.ts, 8, 15)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 7, 16)) + + if (a) { +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 7, 16)) + + a = x; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 7, 16)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 8)) + + break; + } + else { + y++; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 15)) + } + } + + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 1, 15)) + } +} + + +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 15)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 24, 7)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 15)) + + if (x == 1) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 8)) + + continue; + } + else { + for (let a = 1; a < 5; --a) { +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 29, 16)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 29, 16)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 29, 16)) + + let f = () => a; +>f : Symbol(f, Decl(blockScopedBindingsReassignedInLoop3.ts, 30, 15)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 29, 16)) + + if (a) { +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 29, 16)) + + a = x; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 29, 16)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 8)) + + continue; + } + else { + y++; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 15)) + } + } + + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 23, 15)) + } +} + +loop2: +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 15)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 46, 7)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 15)) + + if (x == 1) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 8)) + + break loop2; + } + else { + loop1: + for (let a = 1; a < 5; --a) { +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 52, 16)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 52, 16)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 52, 16)) + + let f = () => a; +>f : Symbol(f, Decl(blockScopedBindingsReassignedInLoop3.ts, 53, 15)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 52, 16)) + + if (a) { +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 52, 16)) + + a = x; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 52, 16)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 8)) + + break loop1; + } + else { + y++; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 15)) + + break loop2 + } + } + + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 45, 15)) + } +} + +loop2: +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 15)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 70, 7)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 15)) + + if (x == 1) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 8)) + + continue loop2; + } + else { + loop1: + for (let a = 1; a < 5; --a) { +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 76, 16)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 76, 16)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 76, 16)) + + let f = () => a; +>f : Symbol(f, Decl(blockScopedBindingsReassignedInLoop3.ts, 77, 15)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 76, 16)) + + if (a) { +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 76, 16)) + + a = x; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop3.ts, 76, 16)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 8)) + + continue loop1; + } + else { + y++; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 15)) + + continue loop2 + } + } + + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop3.ts, 69, 15)) + } +} + diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.types b/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.types new file mode 100644 index 00000000000..0753391d5c2 --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.types @@ -0,0 +1,301 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop3.ts === + +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : number +>1 : number +>y : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) { +>x == 1 : boolean +>x : number +>1 : number + + break; + } + else { + for (let a = 1; a < 5; --a) { +>a : number +>1 : number +>a < 5 : boolean +>a : number +>5 : number +>--a : number +>a : number + + let f = () => a; +>f : () => number +>() => a : () => number +>a : number + + if (a) { +>a : number + + a = x; +>a = x : number +>a : number +>x : number + + break; + } + else { + y++; +>y++ : number +>y : number + } + } + + y = 5; +>y = 5 : number +>y : number +>5 : number + } +} + + +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : number +>1 : number +>y : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) { +>x == 1 : boolean +>x : number +>1 : number + + continue; + } + else { + for (let a = 1; a < 5; --a) { +>a : number +>1 : number +>a < 5 : boolean +>a : number +>5 : number +>--a : number +>a : number + + let f = () => a; +>f : () => number +>() => a : () => number +>a : number + + if (a) { +>a : number + + a = x; +>a = x : number +>a : number +>x : number + + continue; + } + else { + y++; +>y++ : number +>y : number + } + } + + y = 5; +>y = 5 : number +>y : number +>5 : number + } +} + +loop2: +>loop2 : any + +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : number +>1 : number +>y : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) { +>x == 1 : boolean +>x : number +>1 : number + + break loop2; +>loop2 : any + } + else { + loop1: +>loop1 : any + + for (let a = 1; a < 5; --a) { +>a : number +>1 : number +>a < 5 : boolean +>a : number +>5 : number +>--a : number +>a : number + + let f = () => a; +>f : () => number +>() => a : () => number +>a : number + + if (a) { +>a : number + + a = x; +>a = x : number +>a : number +>x : number + + break loop1; +>loop1 : any + } + else { + y++; +>y++ : number +>y : number + + break loop2 +>loop2 : any + } + } + + y = 5; +>y = 5 : number +>y : number +>5 : number + } +} + +loop2: +>loop2 : any + +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : number +>1 : number +>y : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) { +>x == 1 : boolean +>x : number +>1 : number + + continue loop2; +>loop2 : any + } + else { + loop1: +>loop1 : any + + for (let a = 1; a < 5; --a) { +>a : number +>1 : number +>a < 5 : boolean +>a : number +>5 : number +>--a : number +>a : number + + let f = () => a; +>f : () => number +>() => a : () => number +>a : number + + if (a) { +>a : number + + a = x; +>a = x : number +>a : number +>x : number + + continue loop1; +>loop1 : any + } + else { + y++; +>y++ : number +>y : number + + continue loop2 +>loop2 : any + } + } + + y = 5; +>y = 5 : number +>y : number +>5 : number + } +} + diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.js b/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.js new file mode 100644 index 00000000000..8bff867dc95 --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.js @@ -0,0 +1,34 @@ +//// [blockScopedBindingsReassignedInLoop4.ts] +function f1() { + for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + return 1; + } + else { + y = 5; + } + } +} + +//// [blockScopedBindingsReassignedInLoop4.js] +function f1() { + var _loop_1 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) { + return { value: 1 }; + } + else { + y = 5; + } + out_x_1 = x; + out_y_1 = y; + }; + var out_x_1, out_y_1; + for (var x = 1, y = 2; x < y; ++x, --y) { + var state_1 = _loop_1(x, y); + x = out_x_1; + y = out_y_1; + if (typeof state_1 === "object") return state_1.value; + } +} diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.symbols b/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.symbols new file mode 100644 index 00000000000..90c63914b9f --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.symbols @@ -0,0 +1,28 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop4.ts === +function f1() { +>f1 : Symbol(f1, Decl(blockScopedBindingsReassignedInLoop4.ts, 0, 0)) + + for (let x = 1, y = 2; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop4.ts, 1, 12)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop4.ts, 1, 19)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop4.ts, 1, 12)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop4.ts, 1, 19)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop4.ts, 1, 12)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop4.ts, 1, 19)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop4.ts, 2, 11)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop4.ts, 1, 12)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop4.ts, 1, 19)) + + if (x == 1) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop4.ts, 1, 12)) + + return 1; + } + else { + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop4.ts, 1, 19)) + } + } +} diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.types b/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.types new file mode 100644 index 00000000000..006f536ccca --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.types @@ -0,0 +1,43 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop4.ts === +function f1() { +>f1 : () => number + + for (let x = 1, y = 2; x < y; ++x, --y) { +>x : number +>1 : number +>y : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) { +>x == 1 : boolean +>x : number +>1 : number + + return 1; +>1 : number + } + else { + y = 5; +>y = 5 : number +>y : number +>5 : number + } + } +} diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.js b/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.js new file mode 100644 index 00000000000..a891147317d --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.js @@ -0,0 +1,27 @@ +//// [blockScopedBindingsReassignedInLoop5.ts] +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) + break; + else + y = 5; +} + + +//// [blockScopedBindingsReassignedInLoop5.js] +var _loop_1 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) + return out_x_1 = x, out_y_1 = y, "break"; + else + y = 5; + out_x_1 = x; + out_y_1 = y; +}; +var out_x_1, out_y_1; +for (var x = 1, y = 2; x < y; ++x, --y) { + var state_1 = _loop_1(x, y); + x = out_x_1; + y = out_y_1; + if (state_1 === "break") break; +} diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.symbols b/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.symbols new file mode 100644 index 00000000000..0edc6abe34d --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.symbols @@ -0,0 +1,23 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop5.ts === +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop5.ts, 0, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop5.ts, 0, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop5.ts, 0, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop5.ts, 0, 15)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop5.ts, 0, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop5.ts, 0, 15)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop5.ts, 1, 7)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop5.ts, 0, 8)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop5.ts, 0, 15)) + + if (x == 1) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop5.ts, 0, 8)) + + break; + else + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop5.ts, 0, 15)) +} + diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.types b/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.types new file mode 100644 index 00000000000..530978dc722 --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop5.ts === +for (let x = 1, y = 2; x < y; ++x, --y) { +>x : number +>1 : number +>y : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) +>x == 1 : boolean +>x : number +>1 : number + + break; + else + y = 5; +>y = 5 : number +>y : number +>5 : number +} + diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.js b/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.js new file mode 100644 index 00000000000..a2a074ed4df --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.js @@ -0,0 +1,74 @@ +//// [blockScopedBindingsReassignedInLoop6.ts] +function f1() { + for (let [x, y] = [1, 2]; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) + break; + else if (y == 2) + y = 5; + else + return; + } +} + +function f2() { + for (let [{a: x, b: {c: y}}] = [{a: 1, b: {c: 2}}]; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) + break; + else if (y == 2) + y = 5; + else + return; + } +} + + + + + + + +//// [blockScopedBindingsReassignedInLoop6.js] +function f1() { + var _loop_1 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) + return out_x_1 = x, out_y_1 = y, "break"; + else if (y == 2) + y = 5; + else + return { value: void 0 }; + out_x_1 = x; + out_y_1 = y; + }; + var out_x_1, out_y_1; + for (var _a = [1, 2], x = _a[0], y = _a[1]; x < y; ++x, --y) { + var state_1 = _loop_1(x, y); + x = out_x_1; + y = out_y_1; + if (typeof state_1 === "object") return state_1.value; + if (state_1 === "break") break; + } +} +function f2() { + var _loop_2 = function(x, y) { + var a = function () { return x++ + y++; }; + if (x == 1) + return out_x_2 = x, out_y_2 = y, "break"; + else if (y == 2) + y = 5; + else + return { value: void 0 }; + out_x_2 = x; + out_y_2 = y; + }; + var out_x_2, out_y_2; + for (var _a = [{ a: 1, b: { c: 2 } }][0], x = _a.a, y = _a.b.c; x < y; ++x, --y) { + var state_2 = _loop_2(x, y); + x = out_x_2; + y = out_y_2; + if (typeof state_2 === "object") return state_2.value; + if (state_2 === "break") break; + } +} diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.symbols b/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.symbols new file mode 100644 index 00000000000..8dda6eedd47 --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.symbols @@ -0,0 +1,74 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop6.ts === +function f1() { +>f1 : Symbol(f1, Decl(blockScopedBindingsReassignedInLoop6.ts, 0, 0)) + + for (let [x, y] = [1, 2]; x < y; ++x, --y) { +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 14)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 16)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 14)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 16)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 14)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 16)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop6.ts, 2, 11)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 14)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 16)) + + if (x == 1) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 14)) + + break; + else if (y == 2) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 16)) + + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 1, 16)) + + else + return; + } +} + +function f2() { +>f2 : Symbol(f2, Decl(blockScopedBindingsReassignedInLoop6.ts, 10, 1)) + + for (let [{a: x, b: {c: y}}] = [{a: 1, b: {c: 2}}]; x < y; ++x, --y) { +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 37)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 15)) +>b : Symbol(b, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 42)) +>c : Symbol(c, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 47)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 25)) +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 37)) +>b : Symbol(b, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 42)) +>c : Symbol(c, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 47)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 15)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 25)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 15)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 25)) + + let a = () => x++ + y++; +>a : Symbol(a, Decl(blockScopedBindingsReassignedInLoop6.ts, 14, 11)) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 15)) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 25)) + + if (x == 1) +>x : Symbol(x, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 15)) + + break; + else if (y == 2) +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 25)) + + y = 5; +>y : Symbol(y, Decl(blockScopedBindingsReassignedInLoop6.ts, 13, 25)) + + else + return; + } +} + + + + + + diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.types b/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.types new file mode 100644 index 00000000000..673c0788a03 --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.types @@ -0,0 +1,110 @@ +=== tests/cases/compiler/blockScopedBindingsReassignedInLoop6.ts === +function f1() { +>f1 : () => void + + for (let [x, y] = [1, 2]; x < y; ++x, --y) { +>x : number +>y : number +>[1, 2] : [number, number] +>1 : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) +>x == 1 : boolean +>x : number +>1 : number + + break; + else if (y == 2) +>y == 2 : boolean +>y : number +>2 : number + + y = 5; +>y = 5 : number +>y : number +>5 : number + + else + return; + } +} + +function f2() { +>f2 : () => void + + for (let [{a: x, b: {c: y}}] = [{a: 1, b: {c: 2}}]; x < y; ++x, --y) { +>a : any +>x : number +>b : any +>c : any +>y : number +>[{a: 1, b: {c: 2}}] : [{ a: number; b: { c: number; }; }] +>{a: 1, b: {c: 2}} : { a: number; b: { c: number; }; } +>a : number +>1 : number +>b : { c: number; } +>{c: 2} : { c: number; } +>c : number +>2 : number +>x < y : boolean +>x : number +>y : number +>++x, --y : number +>++x : number +>x : number +>--y : number +>y : number + + let a = () => x++ + y++; +>a : () => number +>() => x++ + y++ : () => number +>x++ + y++ : number +>x++ : number +>x : number +>y++ : number +>y : number + + if (x == 1) +>x == 1 : boolean +>x : number +>1 : number + + break; + else if (y == 2) +>y == 2 : boolean +>y : number +>2 : number + + y = 5; +>y = 5 : number +>y : number +>5 : number + + else + return; + } +} + + + + + + diff --git a/tests/baselines/reference/capturedLetConstInLoop11.js b/tests/baselines/reference/capturedLetConstInLoop11.js index fa295739d02..9190dd3ec02 100644 --- a/tests/baselines/reference/capturedLetConstInLoop11.js +++ b/tests/baselines/reference/capturedLetConstInLoop11.js @@ -30,6 +30,6 @@ function foo() { }; for (;;) { var state_2 = _loop_2(); - if (typeof state_2 === "object") return state_2.value + if (typeof state_2 === "object") return state_2.value; } } diff --git a/tests/baselines/reference/capturedLetConstInLoop5.js b/tests/baselines/reference/capturedLetConstInLoop5.js index 7807edd122e..a1a4d4b0a8f 100644 --- a/tests/baselines/reference/capturedLetConstInLoop5.js +++ b/tests/baselines/reference/capturedLetConstInLoop5.js @@ -294,7 +294,7 @@ function foo0(x) { for (var _i = 0, _a = []; _i < _a.length; _i++) { var x_1 = _a[_i]; var state_1 = _loop_1(x_1); - if (typeof state_1 === "object") return state_1.value + if (typeof state_1 === "object") return state_1.value; } use(v); } @@ -310,7 +310,7 @@ function foo00(x) { var v; for (var x_2 in []) { var state_2 = _loop_2(x_2); - if (typeof state_2 === "object") return state_2.value + if (typeof state_2 === "object") return state_2.value; } use(v); } @@ -326,7 +326,7 @@ function foo1(x) { var v; for (var x_3 = 0; x_3 < 1; ++x_3) { var state_3 = _loop_3(x_3); - if (typeof state_3 === "object") return state_3.value + if (typeof state_3 === "object") return state_3.value; } use(v); } @@ -343,7 +343,7 @@ function foo2(x) { var v; while (1 === 1) { var state_4 = _loop_4(); - if (typeof state_4 === "object") return state_4.value + if (typeof state_4 === "object") return state_4.value; } use(v); } @@ -359,7 +359,7 @@ function foo3(x) { var v; do { var state_5 = _loop_5(); - if (typeof state_5 === "object") return state_5.value + if (typeof state_5 === "object") return state_5.value; } while (1 === 1); use(v); } @@ -376,7 +376,7 @@ function foo4(x) { var v; for (var y = 0; y < 1; ++y) { var state_6 = _loop_6(y); - if (typeof state_6 === "object") return state_6.value + if (typeof state_6 === "object") return state_6.value; } use(v); } @@ -392,7 +392,7 @@ function foo5(x) { var v; for (var x_7 = 0, y = 1; x_7 < 1; ++x_7) { var state_7 = _loop_7(x_7, y); - if (typeof state_7 === "object") return state_7.value + if (typeof state_7 === "object") return state_7.value; } use(v); } @@ -409,7 +409,7 @@ function foo6(x) { var v; while (1 === 1) { var state_8 = _loop_8(); - if (typeof state_8 === "object") return state_8.value + if (typeof state_8 === "object") return state_8.value; } ; use(v); @@ -427,7 +427,7 @@ function foo7(x) { var v; do { var state_9 = _loop_9(); - if (typeof state_9 === "object") return state_9.value + if (typeof state_9 === "object") return state_9.value; } while (1 === 1); use(v); } @@ -444,7 +444,7 @@ function foo8(x) { var v; for (var y = 0; y < 1; ++y) { var state_10 = _loop_10(y); - if (typeof state_10 === "object") return state_10.value + if (typeof state_10 === "object") return state_10.value; } use(v); } @@ -462,7 +462,7 @@ function foo0_c(x) { for (var _i = 0, _a = []; _i < _a.length; _i++) { var x_11 = _a[_i]; var state_11 = _loop_11(x_11); - if (typeof state_11 === "object") return state_11.value + if (typeof state_11 === "object") return state_11.value; } use(v); } @@ -478,7 +478,7 @@ function foo00_c(x) { var v; for (var x_12 in []) { var state_12 = _loop_12(x_12); - if (typeof state_12 === "object") return state_12.value + if (typeof state_12 === "object") return state_12.value; } use(v); } @@ -494,7 +494,7 @@ function foo1_c(x) { var v; for (var x_13 = 0; x_13 < 1;) { var state_13 = _loop_13(x_13); - if (typeof state_13 === "object") return state_13.value + if (typeof state_13 === "object") return state_13.value; } use(v); } @@ -511,7 +511,7 @@ function foo2_c(x) { var v; while (1 === 1) { var state_14 = _loop_14(); - if (typeof state_14 === "object") return state_14.value + if (typeof state_14 === "object") return state_14.value; } use(v); } @@ -527,7 +527,7 @@ function foo3_c(x) { var v; do { var state_15 = _loop_15(); - if (typeof state_15 === "object") return state_15.value + if (typeof state_15 === "object") return state_15.value; } while (1 === 1); use(v); } @@ -544,7 +544,7 @@ function foo4_c(x) { var v; for (var y = 0; y < 1;) { var state_16 = _loop_16(y); - if (typeof state_16 === "object") return state_16.value + if (typeof state_16 === "object") return state_16.value; } use(v); } @@ -560,7 +560,7 @@ function foo5_c(x) { var v; for (var x_17 = 0, y = 1; x_17 < 1;) { var state_17 = _loop_17(x_17, y); - if (typeof state_17 === "object") return state_17.value + if (typeof state_17 === "object") return state_17.value; } use(v); } @@ -577,7 +577,7 @@ function foo6_c(x) { var v; while (1 === 1) { var state_18 = _loop_18(); - if (typeof state_18 === "object") return state_18.value + if (typeof state_18 === "object") return state_18.value; } use(v); } @@ -594,7 +594,7 @@ function foo7_c(x) { var v; do { var state_19 = _loop_19(); - if (typeof state_19 === "object") return state_19.value + if (typeof state_19 === "object") return state_19.value; } while (1 === 1); use(v); } @@ -611,7 +611,7 @@ function foo8_c(x) { var v; for (var y = 0; y < 1;) { var state_20 = _loop_20(y); - if (typeof state_20 === "object") return state_20.value + if (typeof state_20 === "object") return state_20.value; } use(v); } diff --git a/tests/baselines/reference/capturedLetConstInLoop8.js b/tests/baselines/reference/capturedLetConstInLoop8.js index b10beb7b44e..560b99bb566 100644 --- a/tests/baselines/reference/capturedLetConstInLoop8.js +++ b/tests/baselines/reference/capturedLetConstInLoop8.js @@ -198,7 +198,7 @@ function foo() { }; l1: for (var x = 0; x < 1; ++x) { var state_2 = _loop_1(x); - if (typeof state_2 === "object") return state_2.value + if (typeof state_2 === "object") return state_2.value; if (state_2 === "break") break; if (state_2 === "continue") continue; switch(state_2) { @@ -280,7 +280,7 @@ function foo_c() { }; l1: for (var x = 0; x < 1;) { var state_4 = _loop_3(x); - if (typeof state_4 === "object") return state_4.value + if (typeof state_4 === "object") return state_4.value; if (state_4 === "break") break; if (state_4 === "continue") continue; switch(state_4) { diff --git a/tests/baselines/reference/capturedLetConstInLoop9.js b/tests/baselines/reference/capturedLetConstInLoop9.js index cbd4f7efe79..1f79b1694cb 100644 --- a/tests/baselines/reference/capturedLetConstInLoop9.js +++ b/tests/baselines/reference/capturedLetConstInLoop9.js @@ -225,7 +225,7 @@ function foo() { l0: for (var _f = 0, _g = []; _f < _g.length; _f++) { var a = _g[_f]; var state_4 = _loop_3(a); - if (typeof state_4 === "object") return state_4.value + if (typeof state_4 === "object") return state_4.value; if (state_4 === "break") break; switch(state_4) { case "break-l0": break l0; diff --git a/tests/baselines/reference/nestedBlockScopedBindings3.js b/tests/baselines/reference/nestedBlockScopedBindings3.js index 97fba2da301..f9474381816 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings3.js +++ b/tests/baselines/reference/nestedBlockScopedBindings3.js @@ -123,9 +123,12 @@ function a4() { var _loop_5 = function(x) { x = x + 1; (function () { return x; }); + out_x_1 = x; }; + var out_x_1; for (var x = void 0; x < 1;) { _loop_5(x); + x = out_x_1; } switch (1) { case 1: @@ -137,9 +140,12 @@ function a5() { var _loop_6 = function(x) { x = x + 1; (function () { return x; }); + out_x_2 = x; }; + var out_x_2; for (var x = void 0; x < 1;) { _loop_6(x); + x = out_x_2; } switch (1) { case 1: diff --git a/tests/baselines/reference/nestedBlockScopedBindings4.js b/tests/baselines/reference/nestedBlockScopedBindings4.js index 51cddcf676d..6b391070d93 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings4.js +++ b/tests/baselines/reference/nestedBlockScopedBindings4.js @@ -53,9 +53,12 @@ function a1() { var _loop_1 = function(x) { x = x + 1; (function () { return x; }); + out_x_1 = x; }; + var out_x_1; for (var x = void 0; x < 1;) { _loop_1(x); + x = out_x_1; } for (var x = void 0;;) { x = x + 2; @@ -68,24 +71,33 @@ function a2() { var _loop_2 = function(x) { x = x + 2; (function () { return x; }); + out_x_2 = x; }; + var out_x_2; for (var x = void 0;;) { _loop_2(x); + x = out_x_2; } } function a3() { var _loop_3 = function(x) { x = x + 1; (function () { return x; }); + out_x_3 = x; }; + var out_x_3; for (var x = void 0; x < 1;) { _loop_3(x); + x = out_x_3; } var _loop_4 = function(x) { x = x + 2; (function () { return x; }); + out_x_4 = x; }; + var out_x_4; for (var x = void 0;;) { _loop_4(x); + x = out_x_4; } } diff --git a/tests/baselines/reference/nestedBlockScopedBindings5.js b/tests/baselines/reference/nestedBlockScopedBindings5.js index c80c72c0ed6..df4fcf76423 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings5.js +++ b/tests/baselines/reference/nestedBlockScopedBindings5.js @@ -108,9 +108,12 @@ function a2() { var _loop_2 = function(x) { x = x + 2; (function () { return x; }); + out_x_1 = x; }; + var out_x_1; for (var x = void 0;;) { _loop_2(x); + x = out_x_1; } } function a3() { @@ -124,9 +127,12 @@ function a3() { var _loop_4 = function(x) { x = x + 2; (function () { return x; }); + out_x_2 = x; }; + var out_x_2; for (var x = void 0; false;) { _loop_4(x); + x = out_x_2; } switch (1) { case 1: @@ -157,9 +163,12 @@ function a5() { var _loop_5 = function(x) { x = x + 2; (function () { return x; }); + out_x_3 = x; }; + var out_x_3; for (var x = void 0; false;) { _loop_5(x); + x = out_x_3; } switch (1) { case 1: diff --git a/tests/baselines/reference/nestedBlockScopedBindings6.js b/tests/baselines/reference/nestedBlockScopedBindings6.js index 78207b98fcd..be9771471e9 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings6.js +++ b/tests/baselines/reference/nestedBlockScopedBindings6.js @@ -119,9 +119,12 @@ function a2() { var _loop_2 = function(x) { x = x + 2; (function () { return x; }); + out_x_1 = x; }; + var out_x_1; for (var x = void 0;;) { _loop_2(x); + x = out_x_1; } } function a3() { @@ -136,9 +139,12 @@ function a3() { var _loop_4 = function(x) { x = x + 2; (function () { return x; }); + out_x_2 = x; }; + var out_x_2; for (var x = void 0;;) { _loop_4(x); + x = out_x_2; } } function a4() { diff --git a/tests/cases/compiler/blockScopedBindingsReassignedInLoop1.ts b/tests/cases/compiler/blockScopedBindingsReassignedInLoop1.ts new file mode 100644 index 00000000000..e052702bce2 --- /dev/null +++ b/tests/cases/compiler/blockScopedBindingsReassignedInLoop1.ts @@ -0,0 +1,7 @@ +declare function use(n: number): void; +(function () { + 'use strict' + for (let i = 0; i < 9; ++i) { + (() => use(++i))(); + } +})(); \ No newline at end of file diff --git a/tests/cases/compiler/blockScopedBindingsReassignedInLoop2.ts b/tests/cases/compiler/blockScopedBindingsReassignedInLoop2.ts new file mode 100644 index 00000000000..84d9f8d214b --- /dev/null +++ b/tests/cases/compiler/blockScopedBindingsReassignedInLoop2.ts @@ -0,0 +1,41 @@ +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + break; + } + else { + y = 5; + } +} + +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + continue; + } + else { + y = 5; + } +} + +loop: +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + break loop; + } + else { + y = 5; + } +} + +loop: +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + continue loop; + } + else { + y = 5; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/blockScopedBindingsReassignedInLoop3.ts b/tests/cases/compiler/blockScopedBindingsReassignedInLoop3.ts new file mode 100644 index 00000000000..a68c708193a --- /dev/null +++ b/tests/cases/compiler/blockScopedBindingsReassignedInLoop3.ts @@ -0,0 +1,91 @@ + +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + break; + } + else { + for (let a = 1; a < 5; --a) { + let f = () => a; + if (a) { + a = x; + break; + } + else { + y++; + } + } + + y = 5; + } +} + + +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + continue; + } + else { + for (let a = 1; a < 5; --a) { + let f = () => a; + if (a) { + a = x; + continue; + } + else { + y++; + } + } + + y = 5; + } +} + +loop2: +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + break loop2; + } + else { + loop1: + for (let a = 1; a < 5; --a) { + let f = () => a; + if (a) { + a = x; + break loop1; + } + else { + y++; + break loop2 + } + } + + y = 5; + } +} + +loop2: +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + continue loop2; + } + else { + loop1: + for (let a = 1; a < 5; --a) { + let f = () => a; + if (a) { + a = x; + continue loop1; + } + else { + y++; + continue loop2 + } + } + + y = 5; + } +} diff --git a/tests/cases/compiler/blockScopedBindingsReassignedInLoop4.ts b/tests/cases/compiler/blockScopedBindingsReassignedInLoop4.ts new file mode 100644 index 00000000000..82f4bcc5dd0 --- /dev/null +++ b/tests/cases/compiler/blockScopedBindingsReassignedInLoop4.ts @@ -0,0 +1,11 @@ +function f1() { + for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) { + return 1; + } + else { + y = 5; + } + } +} \ No newline at end of file diff --git a/tests/cases/compiler/blockScopedBindingsReassignedInLoop5.ts b/tests/cases/compiler/blockScopedBindingsReassignedInLoop5.ts new file mode 100644 index 00000000000..c6c577ea9fb --- /dev/null +++ b/tests/cases/compiler/blockScopedBindingsReassignedInLoop5.ts @@ -0,0 +1,7 @@ +for (let x = 1, y = 2; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) + break; + else + y = 5; +} diff --git a/tests/cases/compiler/blockScopedBindingsReassignedInLoop6.ts b/tests/cases/compiler/blockScopedBindingsReassignedInLoop6.ts new file mode 100644 index 00000000000..e735bb61ac8 --- /dev/null +++ b/tests/cases/compiler/blockScopedBindingsReassignedInLoop6.ts @@ -0,0 +1,28 @@ +function f1() { + for (let [x, y] = [1, 2]; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) + break; + else if (y == 2) + y = 5; + else + return; + } +} + +function f2() { + for (let [{a: x, b: {c: y}}] = [{a: 1, b: {c: 2}}]; x < y; ++x, --y) { + let a = () => x++ + y++; + if (x == 1) + break; + else if (y == 2) + y = 5; + else + return; + } +} + + + + +