From 16d4039a1276f197326fcd424ed61d7cbdbe654a Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 27 Jan 2016 11:28:59 -0800 Subject: [PATCH] Merge pull request #6553 from Microsoft/handleNestedBlockScopedName handle block scoped binding in nested blocks --- src/compiler/checker.ts | 120 ++++---- src/compiler/emitter.ts | 86 ++++-- src/compiler/types.ts | 13 +- src/compiler/utilities.ts | 19 ++ .../reference/capturedLetConstInLoop1.js | 8 +- .../reference/capturedLetConstInLoop2.js | 6 +- .../reference/capturedLetConstInLoop3.js | 6 +- .../reference/capturedLetConstInLoop4.js | 8 +- .../reference/capturedLetConstInLoop5.js | 6 +- .../reference/capturedLetConstInLoop6.js | 8 +- .../reference/capturedLetConstInLoop7.js | 8 +- .../reference/capturedLetConstInLoop9.js | 10 +- .../reference/downlevelLetConst16.js | 2 +- .../reference/downlevelLetConst17.js | 2 +- .../reference/nestedBlockScopedBindings1.js | 97 +++++++ .../nestedBlockScopedBindings1.symbols | 68 +++++ .../nestedBlockScopedBindings1.types | 82 ++++++ .../reference/nestedBlockScopedBindings10.js | 24 ++ .../nestedBlockScopedBindings10.symbols | 19 ++ .../nestedBlockScopedBindings10.types | 27 ++ .../reference/nestedBlockScopedBindings11.js | 28 ++ .../nestedBlockScopedBindings11.symbols | 24 ++ .../nestedBlockScopedBindings11.types | 30 ++ .../reference/nestedBlockScopedBindings12.js | 28 ++ .../nestedBlockScopedBindings12.symbols | 24 ++ .../nestedBlockScopedBindings12.types | 32 +++ .../reference/nestedBlockScopedBindings13.js | 23 ++ .../nestedBlockScopedBindings13.symbols | 16 ++ .../nestedBlockScopedBindings13.types | 23 ++ .../reference/nestedBlockScopedBindings14.js | 27 ++ .../nestedBlockScopedBindings14.symbols | 22 ++ .../nestedBlockScopedBindings14.types | 29 ++ .../reference/nestedBlockScopedBindings15.js | 68 +++++ .../nestedBlockScopedBindings15.symbols | 46 ++++ .../nestedBlockScopedBindings15.types | 66 +++++ .../reference/nestedBlockScopedBindings16.js | 76 ++++++ .../nestedBlockScopedBindings16.symbols | 58 ++++ .../nestedBlockScopedBindings16.types | 78 ++++++ .../reference/nestedBlockScopedBindings2.js | 244 +++++++++++++++++ .../nestedBlockScopedBindings2.symbols | 197 +++++++++++++ .../nestedBlockScopedBindings2.types | 258 ++++++++++++++++++ .../reference/nestedBlockScopedBindings3.js | 150 ++++++++++ .../nestedBlockScopedBindings3.symbols | 130 +++++++++ .../nestedBlockScopedBindings3.types | 177 ++++++++++++ .../reference/nestedBlockScopedBindings4.js | 91 ++++++ .../nestedBlockScopedBindings4.symbols | 93 +++++++ .../nestedBlockScopedBindings4.types | 129 +++++++++ .../reference/nestedBlockScopedBindings5.js | 169 ++++++++++++ .../nestedBlockScopedBindings5.symbols | 163 +++++++++++ .../nestedBlockScopedBindings5.types | 227 +++++++++++++++ .../reference/nestedBlockScopedBindings6.js | 197 +++++++++++++ .../nestedBlockScopedBindings6.symbols | 177 ++++++++++++ .../nestedBlockScopedBindings6.types | 253 +++++++++++++++++ .../reference/nestedBlockScopedBindings7.js | 19 ++ .../nestedBlockScopedBindings7.symbols | 14 + .../nestedBlockScopedBindings7.types | 19 ++ .../reference/nestedBlockScopedBindings8.js | 23 ++ .../nestedBlockScopedBindings8.symbols | 20 ++ .../nestedBlockScopedBindings8.types | 25 ++ .../reference/nestedBlockScopedBindings9.js | 24 ++ .../nestedBlockScopedBindings9.symbols | 19 ++ .../nestedBlockScopedBindings9.types | 25 ++ .../compiler/nestedBlockScopedBindings1.ts | 49 ++++ .../compiler/nestedBlockScopedBindings10.ts | 11 + .../compiler/nestedBlockScopedBindings11.ts | 13 + .../compiler/nestedBlockScopedBindings12.ts | 13 + .../compiler/nestedBlockScopedBindings13.ts | 9 + .../compiler/nestedBlockScopedBindings14.ts | 11 + .../compiler/nestedBlockScopedBindings15.ts | 31 +++ .../compiler/nestedBlockScopedBindings16.ts | 35 +++ .../compiler/nestedBlockScopedBindings2.ts | 126 +++++++++ .../compiler/nestedBlockScopedBindings3.ts | 68 +++++ .../compiler/nestedBlockScopedBindings4.ts | 40 +++ .../compiler/nestedBlockScopedBindings5.ts | 80 ++++++ .../compiler/nestedBlockScopedBindings6.ts | 88 ++++++ .../compiler/nestedBlockScopedBindings7.ts | 7 + .../compiler/nestedBlockScopedBindings8.ts | 9 + .../compiler/nestedBlockScopedBindings9.ts | 11 + 78 files changed, 4638 insertions(+), 123 deletions(-) create mode 100644 tests/baselines/reference/nestedBlockScopedBindings1.js create mode 100644 tests/baselines/reference/nestedBlockScopedBindings1.symbols create mode 100644 tests/baselines/reference/nestedBlockScopedBindings1.types create mode 100644 tests/baselines/reference/nestedBlockScopedBindings10.js create mode 100644 tests/baselines/reference/nestedBlockScopedBindings10.symbols create mode 100644 tests/baselines/reference/nestedBlockScopedBindings10.types create mode 100644 tests/baselines/reference/nestedBlockScopedBindings11.js create mode 100644 tests/baselines/reference/nestedBlockScopedBindings11.symbols create mode 100644 tests/baselines/reference/nestedBlockScopedBindings11.types create mode 100644 tests/baselines/reference/nestedBlockScopedBindings12.js create mode 100644 tests/baselines/reference/nestedBlockScopedBindings12.symbols create mode 100644 tests/baselines/reference/nestedBlockScopedBindings12.types create mode 100644 tests/baselines/reference/nestedBlockScopedBindings13.js create mode 100644 tests/baselines/reference/nestedBlockScopedBindings13.symbols create mode 100644 tests/baselines/reference/nestedBlockScopedBindings13.types create mode 100644 tests/baselines/reference/nestedBlockScopedBindings14.js create mode 100644 tests/baselines/reference/nestedBlockScopedBindings14.symbols create mode 100644 tests/baselines/reference/nestedBlockScopedBindings14.types create mode 100644 tests/baselines/reference/nestedBlockScopedBindings15.js create mode 100644 tests/baselines/reference/nestedBlockScopedBindings15.symbols create mode 100644 tests/baselines/reference/nestedBlockScopedBindings15.types create mode 100644 tests/baselines/reference/nestedBlockScopedBindings16.js create mode 100644 tests/baselines/reference/nestedBlockScopedBindings16.symbols create mode 100644 tests/baselines/reference/nestedBlockScopedBindings16.types create mode 100644 tests/baselines/reference/nestedBlockScopedBindings2.js create mode 100644 tests/baselines/reference/nestedBlockScopedBindings2.symbols create mode 100644 tests/baselines/reference/nestedBlockScopedBindings2.types create mode 100644 tests/baselines/reference/nestedBlockScopedBindings3.js create mode 100644 tests/baselines/reference/nestedBlockScopedBindings3.symbols create mode 100644 tests/baselines/reference/nestedBlockScopedBindings3.types create mode 100644 tests/baselines/reference/nestedBlockScopedBindings4.js create mode 100644 tests/baselines/reference/nestedBlockScopedBindings4.symbols create mode 100644 tests/baselines/reference/nestedBlockScopedBindings4.types create mode 100644 tests/baselines/reference/nestedBlockScopedBindings5.js create mode 100644 tests/baselines/reference/nestedBlockScopedBindings5.symbols create mode 100644 tests/baselines/reference/nestedBlockScopedBindings5.types create mode 100644 tests/baselines/reference/nestedBlockScopedBindings6.js create mode 100644 tests/baselines/reference/nestedBlockScopedBindings6.symbols create mode 100644 tests/baselines/reference/nestedBlockScopedBindings6.types create mode 100644 tests/baselines/reference/nestedBlockScopedBindings7.js create mode 100644 tests/baselines/reference/nestedBlockScopedBindings7.symbols create mode 100644 tests/baselines/reference/nestedBlockScopedBindings7.types create mode 100644 tests/baselines/reference/nestedBlockScopedBindings8.js create mode 100644 tests/baselines/reference/nestedBlockScopedBindings8.symbols create mode 100644 tests/baselines/reference/nestedBlockScopedBindings8.types create mode 100644 tests/baselines/reference/nestedBlockScopedBindings9.js create mode 100644 tests/baselines/reference/nestedBlockScopedBindings9.symbols create mode 100644 tests/baselines/reference/nestedBlockScopedBindings9.types create mode 100644 tests/cases/compiler/nestedBlockScopedBindings1.ts create mode 100644 tests/cases/compiler/nestedBlockScopedBindings10.ts create mode 100644 tests/cases/compiler/nestedBlockScopedBindings11.ts create mode 100644 tests/cases/compiler/nestedBlockScopedBindings12.ts create mode 100644 tests/cases/compiler/nestedBlockScopedBindings13.ts create mode 100644 tests/cases/compiler/nestedBlockScopedBindings14.ts create mode 100644 tests/cases/compiler/nestedBlockScopedBindings15.ts create mode 100644 tests/cases/compiler/nestedBlockScopedBindings16.ts create mode 100644 tests/cases/compiler/nestedBlockScopedBindings2.ts create mode 100644 tests/cases/compiler/nestedBlockScopedBindings3.ts create mode 100644 tests/cases/compiler/nestedBlockScopedBindings4.ts create mode 100644 tests/cases/compiler/nestedBlockScopedBindings5.ts create mode 100644 tests/cases/compiler/nestedBlockScopedBindings6.ts create mode 100644 tests/cases/compiler/nestedBlockScopedBindings7.ts create mode 100644 tests/cases/compiler/nestedBlockScopedBindings8.ts create mode 100644 tests/cases/compiler/nestedBlockScopedBindings9.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 61c05d7688c85..47fdd36ca37b9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7156,7 +7156,7 @@ namespace ts { checkCollisionWithCapturedSuperVariable(node, node); checkCollisionWithCapturedThisVariable(node, node); - checkBlockScopedBindingCapturedInLoop(node, symbol); + checkNestedBlockScopedBinding(node, symbol); return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node); } @@ -7173,7 +7173,7 @@ namespace ts { return false; } - function checkBlockScopedBindingCapturedInLoop(node: Identifier, symbol: Symbol): void { + function checkNestedBlockScopedBinding(node: Identifier, symbol: Symbol): void { if (languageVersion >= ScriptTarget.ES6 || (symbol.flags & (SymbolFlags.BlockScopedVariable | SymbolFlags.Class)) === 0 || symbol.valueDeclaration.parent.kind === SyntaxKind.CatchClause) { @@ -7185,40 +7185,31 @@ namespace ts { // 2. walk from the declaration up to the boundary of lexical environment and check // if there is an iteration statement in between declaration and boundary (is binding/class declared inside iteration statement) - let container: Node; - if (symbol.flags & SymbolFlags.Class) { - // get parent of class declaration - container = getClassLikeDeclarationOfSymbol(symbol).parent; - } - else { - // nesting structure: - // (variable declaration or binding element) -> variable declaration list -> container - container = symbol.valueDeclaration; - while (container.kind !== SyntaxKind.VariableDeclarationList) { - container = container.parent; - } - // get the parent of variable declaration list - container = container.parent; - if (container.kind === SyntaxKind.VariableStatement) { - // if parent is variable statement - get its parent - container = container.parent; - } - } - - const inFunction = isInsideFunction(node.parent, container); - + const container = getEnclosingBlockScopeContainer(symbol.valueDeclaration); + const usedInFunction = isInsideFunction(node.parent, container); let current = container; + + let containedInIterationStatement = false; while (current && !nodeStartsNewLexicalEnvironment(current)) { if (isIterationStatement(current, /*lookInLabeledStatements*/ false)) { - if (inFunction) { - getNodeLinks(current).flags |= NodeCheckFlags.LoopWithBlockScopedBindingCapturedInFunction; - } - // mark value declaration so during emit they can have a special handling - getNodeLinks(symbol.valueDeclaration).flags |= NodeCheckFlags.BlockScopedBindingInLoop; + containedInIterationStatement = true; break; } current = current.parent; } + + if (containedInIterationStatement) { + if (usedInFunction) { + // mark iteration statement as containing block-scoped binding captured in some function + getNodeLinks(current).flags |= NodeCheckFlags.LoopWithCapturedBlockScopedBinding; + } + // set 'declared inside loop' bit on the block-scoped binding + getNodeLinks(symbol.valueDeclaration).flags |= NodeCheckFlags.BlockScopedBindingInLoop; + } + + if (usedInFunction) { + getNodeLinks(symbol.valueDeclaration).flags |= NodeCheckFlags.CapturedBlockScopedBinding; + } } function captureLexicalThis(node: Node, container: Node): void { @@ -15623,42 +15614,61 @@ namespace ts { return symbol && symbol.flags & SymbolFlags.Alias ? getDeclarationOfAliasSymbol(symbol) : undefined; } - function isStatementWithLocals(node: Node) { - switch (node.kind) { - case SyntaxKind.Block: - case SyntaxKind.CaseBlock: - case SyntaxKind.ForStatement: - case SyntaxKind.ForInStatement: - case SyntaxKind.ForOfStatement: - return true; - } - return false; - } - - function isNestedRedeclarationSymbol(symbol: Symbol): boolean { + function isSymbolOfDeclarationWithCollidingName(symbol: Symbol): boolean { if (symbol.flags & SymbolFlags.BlockScoped) { const links = getSymbolLinks(symbol); - if (links.isNestedRedeclaration === undefined) { + if (links.isDeclaratonWithCollidingName === undefined) { const container = getEnclosingBlockScopeContainer(symbol.valueDeclaration); - links.isNestedRedeclaration = isStatementWithLocals(container) && - !!resolveName(container.parent, symbol.name, SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined); + if (isStatementWithLocals(container)) { + const nodeLinks = getNodeLinks(symbol.valueDeclaration); + if (!!resolveName(container.parent, symbol.name, SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined)) { + // redeclaration - always should be renamed + links.isDeclaratonWithCollidingName = true; + } + else if (nodeLinks.flags & NodeCheckFlags.CapturedBlockScopedBinding) { + // binding is captured in the function + // should be renamed if: + // - binding is not top level - top level bindings never collide with anything + // AND + // - binding is not declared in loop, should be renamed to avoid name reuse across siblings + // let a, b + // { let x = 1; a = () => x; } + // { let x = 100; b = () => x; } + // console.log(a()); // should print '1' + // console.log(b()); // should print '100' + // OR + // - binding is declared inside loop but not in inside initializer of iteration statement or directly inside loop body + // * variables from initializer are passed to rewritted loop body as parameters so they are not captured directly + // * variables that are declared immediately in loop body will become top level variable after loop is rewritten and thus + // they will not collide with anything + const isDeclaredInLoop = nodeLinks.flags & NodeCheckFlags.BlockScopedBindingInLoop; + const inLoopInitializer = isIterationStatement(container, /*lookInLabeledStatements*/ false); + const inLoopBodyBlock = container.kind === SyntaxKind.Block && isIterationStatement(container.parent, /*lookInLabeledStatements*/ false); + + links.isDeclaratonWithCollidingName = !isBlockScopedContainerTopLevel(container) && (!isDeclaredInLoop || (!inLoopInitializer && !inLoopBodyBlock)); + } + else { + links.isDeclaratonWithCollidingName = false; + } + } } - return links.isNestedRedeclaration; + return links.isDeclaratonWithCollidingName; } return false; } // When resolved as an expression identifier, if the given node references a nested block scoped entity with - // a name that hides an existing name, return the declaration of that entity. Otherwise, return undefined. - function getReferencedNestedRedeclaration(node: Identifier): Declaration { + // a name that either hides an existing name or might hide it when compiled downlevel, + // return the declaration of that entity. Otherwise, return undefined. + function getReferencedDeclarationWithCollidingName(node: Identifier): Declaration { const symbol = getReferencedValueSymbol(node); - return symbol && isNestedRedeclarationSymbol(symbol) ? symbol.valueDeclaration : undefined; + return symbol && isSymbolOfDeclarationWithCollidingName(symbol) ? symbol.valueDeclaration : undefined; } - // Return true if the given node is a declaration of a nested block scoped entity with a name that hides an - // existing name. - function isNestedRedeclaration(node: Declaration): boolean { - return isNestedRedeclarationSymbol(getSymbolOfNode(node)); + // Return true if the given node is a declaration of a nested block scoped entity with a name that either hides an + // existing name or might hide a name when compiled downlevel + function isDeclarationWithCollidingName(node: Declaration): boolean { + return isSymbolOfDeclarationWithCollidingName(getSymbolOfNode(node)); } function isValueAliasDeclaration(node: Node): boolean { @@ -15859,8 +15869,8 @@ namespace ts { return { getReferencedExportContainer, getReferencedImportDeclaration, - getReferencedNestedRedeclaration, - isNestedRedeclaration, + getReferencedDeclarationWithCollidingName, + isDeclarationWithCollidingName, isValueAliasDeclaration, hasGlobalName, isReferencedAliasDeclaration, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d35a723a09320..e7a22ea5abee6 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1530,7 +1530,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } if (languageVersion !== ScriptTarget.ES6) { - const declaration = resolver.getReferencedNestedRedeclaration(node); + const declaration = resolver.getReferencedDeclarationWithCollidingName(node); if (declaration) { write(getGeneratedNameForNode(declaration.name)); return; @@ -1546,7 +1546,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } } - function isNameOfNestedRedeclaration(node: Identifier) { + function isNameOfNestedBlockScopedRedeclarationOrCapturedBinding(node: Identifier) { if (languageVersion < ScriptTarget.ES6) { const parent = node.parent; switch (parent.kind) { @@ -1554,7 +1554,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge case SyntaxKind.ClassDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKind.VariableDeclaration: - return (parent).name === node && resolver.isNestedRedeclaration(parent); + return (parent).name === node && resolver.isDeclarationWithCollidingName(parent); } } return false; @@ -1576,7 +1576,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge else if (isExpressionIdentifier(node)) { emitExpressionIdentifier(node); } - else if (isNameOfNestedRedeclaration(node)) { + else if (isNameOfNestedBlockScopedRedeclarationOrCapturedBinding(node)) { write(getGeneratedNameForNode(node)); } else if (nodeIsSynthesized(node)) { @@ -2891,7 +2891,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge function shouldConvertLoopBody(node: IterationStatement): boolean { return languageVersion < ScriptTarget.ES6 && - (resolver.getNodeCheckFlags(node) & NodeCheckFlags.LoopWithBlockScopedBindingCapturedInFunction) !== 0; + (resolver.getNodeCheckFlags(node) & NodeCheckFlags.LoopWithCapturedBlockScopedBinding) !== 0; } function emitLoop(node: IterationStatement, loopEmitter: (n: IterationStatement, convertedLoop: ConvertedLoop) => void): void { @@ -3045,7 +3045,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge function collectNames(name: Identifier | BindingPattern): void { if (name.kind === SyntaxKind.Identifier) { - const nameText = isNameOfNestedRedeclaration(name) ? getGeneratedNameForNode(name) : (name).text; + const nameText = isNameOfNestedBlockScopedRedeclarationOrCapturedBinding(name) ? getGeneratedNameForNode(name) : (name).text; loopParameters.push(nameText); } else { @@ -4065,22 +4065,56 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } else { let initializer = node.initializer; - if (!initializer && languageVersion < ScriptTarget.ES6) { - - // downlevel emit for non-initialized let bindings defined in loops - // for (...) { let x; } - // should be - // for (...) { var = void 0; } - // this is necessary to preserve ES6 semantic in scenarios like - // for (...) { let x; console.log(x); x = 1 } // assignment on one iteration should not affect other iterations - const isLetDefinedInLoop = - (resolver.getNodeCheckFlags(node) & NodeCheckFlags.BlockScopedBindingInLoop) && - (getCombinedFlagsForIdentifier(node.name) & NodeFlags.Let); - - // NOTE: default initialization should not be added to let bindings in for-in\for-of statements - if (isLetDefinedInLoop && - node.parent.parent.kind !== SyntaxKind.ForInStatement && - node.parent.parent.kind !== SyntaxKind.ForOfStatement) { + if (!initializer && + languageVersion < ScriptTarget.ES6 && + // for names - binding patterns that lack initializer there is no point to emit explicit initializer + // since downlevel codegen for destructuring will fail in the absence of initializer so all binding elements will say uninitialized + node.name.kind === SyntaxKind.Identifier) { + + const container = getEnclosingBlockScopeContainer(node); + const flags = resolver.getNodeCheckFlags(node); + + // nested let bindings might need to be initialized explicitly to preserve ES6 semantic + // { let x = 1; } + // { let x; } // x here should be undefined. not 1 + // NOTES: + // Top level bindings never collide with anything and thus don't require explicit initialization. + // As for nested let bindings there are two cases: + // - nested let bindings that were not renamed definitely should be initialized explicitly + // { let x = 1; } + // { let x; if (some-condition) { x = 1}; if (x) { /*1*/ } } + // Without explicit initialization code in /*1*/ can be executed even if some-condition is evaluated to false + // - renaming introduces fresh name that should not collide with any existing names, however renamed bindings sometimes also should be + // explicitly initialized. One particular case: non-captured binding declared inside loop body (but not in loop initializer) + // let x; + // for (;;) { + // let x; + // } + // in downlevel codegen inner 'x' will be renamed so it won't collide with outer 'x' however it will should be reset on every iteration + // as if it was declared anew. + // * Why non-captured binding - because if loop contains block scoped binding captured in some function then loop body will be rewritten + // to have a fresh scope on every iteration so everything will just work. + // * Why loop initializer is excluded - since we've introduced a fresh name it already will be undefined. + const isCapturedInFunction = flags & NodeCheckFlags.CapturedBlockScopedBinding; + const isDeclaredInLoop = flags & NodeCheckFlags.BlockScopedBindingInLoop; + + const emittedAsTopLevel = + isBlockScopedContainerTopLevel(container) || + (isCapturedInFunction && isDeclaredInLoop && container.kind === SyntaxKind.Block && isIterationStatement(container.parent, /*lookInLabeledStatements*/ false)); + + const emittedAsNestedLetDeclaration = + getCombinedNodeFlags(node) & NodeFlags.Let && + !emittedAsTopLevel; + + const emitExplicitInitializer = + emittedAsNestedLetDeclaration && + container.kind !== SyntaxKind.ForInStatement && + container.kind !== SyntaxKind.ForOfStatement && + ( + !resolver.isDeclarationWithCollidingName(node) || + (isDeclaredInLoop && !isCapturedInFunction && !isIterationStatement(container, /*lookInLabeledStatements*/ false)) + ); + if (emitExplicitInitializer) { initializer = createVoidZero(); } } @@ -4115,14 +4149,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } } - function getCombinedFlagsForIdentifier(node: Identifier): NodeFlags { - if (!node.parent || (node.parent.kind !== SyntaxKind.VariableDeclaration && node.parent.kind !== SyntaxKind.BindingElement)) { - return 0; - } - - return getCombinedNodeFlags(node.parent); - } - function isES6ExportedDeclaration(node: Node) { return !!(node.flags & NodeFlags.Export) && modulekind === ModuleKind.ES6 && diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3277e7e7950a4..6963797d60177 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1901,8 +1901,8 @@ namespace ts { hasGlobalName(name: string): boolean; getReferencedExportContainer(node: Identifier): SourceFile | ModuleDeclaration | EnumDeclaration; getReferencedImportDeclaration(node: Identifier): Declaration; - getReferencedNestedRedeclaration(node: Identifier): Declaration; - isNestedRedeclaration(node: Declaration): boolean; + getReferencedDeclarationWithCollidingName(node: Identifier): Declaration; + isDeclarationWithCollidingName(node: Declaration): boolean; isValueAliasDeclaration(node: Node): boolean; isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; @@ -2038,7 +2038,7 @@ namespace ts { containingType?: UnionOrIntersectionType; // Containing union or intersection type for synthetic property resolvedExports?: SymbolTable; // Resolved exports of module exportsChecked?: boolean; // True if exports of external module have been checked - isNestedRedeclaration?: boolean; // True if symbol is block scoped redeclaration + isDeclaratonWithCollidingName?: boolean; // True if symbol is block scoped redeclaration bindingElement?: BindingElement; // Binding element associated with property symbol exportsSomeValue?: boolean; // true if module exports some value (not just types) } @@ -2064,9 +2064,10 @@ namespace ts { // Values for enum members have been computed, and any errors have been reported for them. EnumValuesComputed = 0x00004000, - BlockScopedBindingInLoop = 0x00008000, - LexicalModuleMergesWithClass = 0x00010000, // Instantiated lexical module declaration is merged with a previous class declaration. - LoopWithBlockScopedBindingCapturedInFunction = 0x00020000, // Loop that contains block scoped variable captured in closure + LexicalModuleMergesWithClass = 0x00008000, // Instantiated lexical module declaration is merged with a previous class declaration. + LoopWithCapturedBlockScopedBinding = 0x00010000, // Loop that contains block scoped variable captured in closure + CapturedBlockScopedBinding = 0x00020000, // Block-scoped binding that is captured in some function + BlockScopedBindingInLoop = 0x00040000, // Block-scoped binding with declaration nested inside iteration statement } /* @internal */ diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 4bf1422e88877..4a20a54b00103 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -151,6 +151,18 @@ namespace ts { return node; } + export function isStatementWithLocals(node: Node) { + switch (node.kind) { + case SyntaxKind.Block: + case SyntaxKind.CaseBlock: + case SyntaxKind.ForStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.ForOfStatement: + return true; + } + return false; + } + export function getStartPositionOfLine(line: number, sourceFile: SourceFile): number { Debug.assert(line >= 0); return getLineStarts(sourceFile)[line]; @@ -256,6 +268,13 @@ namespace ts { ((node).name.kind === SyntaxKind.StringLiteral || isGlobalScopeAugmentation(node)); } + export function isBlockScopedContainerTopLevel(node: Node): boolean { + return node.kind === SyntaxKind.SourceFile || + node.kind === SyntaxKind.ModuleDeclaration || + isFunctionLike(node) || + isFunctionBlock(node); + } + export function isGlobalScopeAugmentation(module: ModuleDeclaration): boolean { return !!(module.flags & NodeFlags.GlobalAugmentation); } diff --git a/tests/baselines/reference/capturedLetConstInLoop1.js b/tests/baselines/reference/capturedLetConstInLoop1.js index 633b78af510f3..fe76bdd5c91a1 100644 --- a/tests/baselines/reference/capturedLetConstInLoop1.js +++ b/tests/baselines/reference/capturedLetConstInLoop1.js @@ -138,7 +138,7 @@ for (var x = 0; x < 1; ++x) { _loop_3(x); } var _loop_4 = function() { - var x = void 0; + var x; (function () { return x; }); (function () { return x; }); }; @@ -146,7 +146,7 @@ while (1 === 1) { _loop_4(); } var _loop_5 = function() { - var x = void 0; + var x; (function () { return x; }); (function () { return x; }); }; @@ -169,7 +169,7 @@ for (var x = 0, y = 1; x < 1; ++x) { _loop_7(x, y); } var _loop_8 = function() { - var x = void 0, y = void 0; + var x, y; (function () { return x + y; }); (function () { return x + y; }); }; @@ -177,7 +177,7 @@ while (1 === 1) { _loop_8(); } var _loop_9 = function() { - var x = void 0, y = void 0; + var x, y; (function () { return x + y; }); (function () { return x + y; }); }; diff --git a/tests/baselines/reference/capturedLetConstInLoop2.js b/tests/baselines/reference/capturedLetConstInLoop2.js index b9fbcf46f57a4..b41dd380a2435 100644 --- a/tests/baselines/reference/capturedLetConstInLoop2.js +++ b/tests/baselines/reference/capturedLetConstInLoop2.js @@ -225,7 +225,7 @@ function foo2(x) { } function foo3(x) { var _loop_5 = function() { - var x_4 = void 0; + var x_4; var a = arguments_5.length; (function () { return x_4 + a; }); (function () { return x_4 + a; }); @@ -260,7 +260,7 @@ function foo5(x) { } function foo6(x) { var _loop_8 = function() { - var x_7 = void 0, y = void 0; + var x_7, y; var a = arguments_8.length; (function () { return x_7 + y + a; }); (function () { return x_7 + y + a; }); @@ -272,7 +272,7 @@ function foo6(x) { } function foo7(x) { var _loop_9 = function() { - var x_8 = void 0, y = void 0; + var x_8, y; var a = arguments_9.length; (function () { return x_8 + y + a; }); (function () { return x_8 + y + a; }); diff --git a/tests/baselines/reference/capturedLetConstInLoop3.js b/tests/baselines/reference/capturedLetConstInLoop3.js index b38c12967dd2b..233dfe9206c18 100644 --- a/tests/baselines/reference/capturedLetConstInLoop3.js +++ b/tests/baselines/reference/capturedLetConstInLoop3.js @@ -270,7 +270,7 @@ function foo2(x) { } function foo3(x) { var _loop_5 = function() { - var x_5 = void 0; + var x_5; (function () { return x_5 + v; }); (function () { return x_5 + v; }); }; @@ -307,7 +307,7 @@ function foo5(x) { } function foo6(x) { var _loop_8 = function() { - var x_8 = void 0, y = void 0; + var x_8, y; v = x_8; (function () { return x_8 + y + v; }); (function () { return x_8 + y + v; }); @@ -320,7 +320,7 @@ function foo6(x) { } function foo7(x) { var _loop_9 = function() { - var x_9 = void 0, y = void 0; + var x_9, y; v = x_9; (function () { return x_9 + y + v; }); (function () { return x_9 + y + v; }); diff --git a/tests/baselines/reference/capturedLetConstInLoop4.js b/tests/baselines/reference/capturedLetConstInLoop4.js index 724c84fe04f04..160be3ccaeffc 100644 --- a/tests/baselines/reference/capturedLetConstInLoop4.js +++ b/tests/baselines/reference/capturedLetConstInLoop4.js @@ -186,7 +186,7 @@ System.register([], function(exports_1) { _loop_3(x); } var _loop_4 = function() { - var x = void 0; + var x; v2 = x; (function () { return x + v2; }); (function () { return x; }); @@ -195,7 +195,7 @@ System.register([], function(exports_1) { _loop_4(); } var _loop_5 = function() { - var x = void 0; + var x; v3 = x; (function () { return x + v3; }); (function () { return x; }); @@ -221,7 +221,7 @@ System.register([], function(exports_1) { _loop_7(x, y); } var _loop_8 = function() { - var x = void 0, y = void 0; + var x, y; v6 = x; (function () { return x + y + v6; }); (function () { return x + y; }); @@ -230,7 +230,7 @@ System.register([], function(exports_1) { _loop_8(); } var _loop_9 = function() { - var x = void 0, y = void 0; + var x, y; v7 = x; (function () { return x + y + v7; }); (function () { return x + y; }); diff --git a/tests/baselines/reference/capturedLetConstInLoop5.js b/tests/baselines/reference/capturedLetConstInLoop5.js index b73484cb430b0..7807edd122eee 100644 --- a/tests/baselines/reference/capturedLetConstInLoop5.js +++ b/tests/baselines/reference/capturedLetConstInLoop5.js @@ -349,7 +349,7 @@ function foo2(x) { } function foo3(x) { var _loop_5 = function() { - var x_5 = void 0; + var x_5; (function () { return x_5 + v; }); (function () { return x_5 + v; }); if (x_5 == 1) { @@ -398,7 +398,7 @@ function foo5(x) { } function foo6(x) { var _loop_8 = function() { - var x_8 = void 0, y = void 0; + var x_8, y; v = x_8; (function () { return x_8 + y + v; }); (function () { return x_8 + y + v; }); @@ -416,7 +416,7 @@ function foo6(x) { } function foo7(x) { var _loop_9 = function() { - var x_9 = void 0, y = void 0; + var x_9, y; v = x_9; (function () { return x_9 + y + v; }); (function () { return x_9 + y + v; }); diff --git a/tests/baselines/reference/capturedLetConstInLoop6.js b/tests/baselines/reference/capturedLetConstInLoop6.js index ca3b634ef18de..e196950e696ab 100644 --- a/tests/baselines/reference/capturedLetConstInLoop6.js +++ b/tests/baselines/reference/capturedLetConstInLoop6.js @@ -287,7 +287,7 @@ for (var x = 0; x < 1; ++x) { if (state_3 === "continue") continue; } var _loop_4 = function() { - var x = void 0; + var x; (function () { return x; }); (function () { return x; }); if (x == 1) { @@ -303,7 +303,7 @@ while (1 === 1) { if (state_4 === "continue") continue; } var _loop_5 = function() { - var x = void 0; + var x; (function () { return x; }); (function () { return x; }); if (x == 1) { @@ -350,7 +350,7 @@ for (var x = 0, y = 1; x < 1; ++x) { if (state_7 === "continue") continue; } var _loop_8 = function() { - var x = void 0, y = void 0; + var x, y; (function () { return x + y; }); (function () { return x + y; }); if (x == 1) { @@ -366,7 +366,7 @@ while (1 === 1) { if (state_8 === "continue") continue; } var _loop_9 = function() { - var x = void 0, y = void 0; + var x, y; (function () { return x + y; }); (function () { return x + y; }); if (x == 1) { diff --git a/tests/baselines/reference/capturedLetConstInLoop7.js b/tests/baselines/reference/capturedLetConstInLoop7.js index 6ec4ec1df447d..8df93bca60ff2 100644 --- a/tests/baselines/reference/capturedLetConstInLoop7.js +++ b/tests/baselines/reference/capturedLetConstInLoop7.js @@ -454,7 +454,7 @@ l1: for (var x = 0; x < 1; ++x) { } } var _loop_4 = function() { - var x = void 0; + var x; (function () { return x; }); (function () { return x; }); if (x == 1) { @@ -480,7 +480,7 @@ l2: while (1 === 1) { } } var _loop_5 = function() { - var x = void 0; + var x; (function () { return x; }); (function () { return x; }); if (x == 1) { @@ -557,7 +557,7 @@ l5: for (var x = 0, y = 1; x < 1; ++x) { } } var _loop_8 = function() { - var x = void 0, y = void 0; + var x, y; (function () { return x + y; }); (function () { return x + y; }); if (x == 1) { @@ -583,7 +583,7 @@ l6: while (1 === 1) { } } var _loop_9 = function() { - var x = void 0, y = void 0; + var x, y; (function () { return x + y; }); (function () { return x + y; }); if (x == 1) { diff --git a/tests/baselines/reference/capturedLetConstInLoop9.js b/tests/baselines/reference/capturedLetConstInLoop9.js index 9b31218a1e3d3..cbd4f7efe79c0 100644 --- a/tests/baselines/reference/capturedLetConstInLoop9.js +++ b/tests/baselines/reference/capturedLetConstInLoop9.js @@ -140,25 +140,25 @@ function foo3 () { //// [capturedLetConstInLoop9.js] var _loop_1 = function(x) { - var x_1 = void 0; + var x_1; (function () { return x_1; }); { - var x_2 = void 0; + var x_2; (function () { return x_2; }); } try { } catch (e) { - var x_3 = void 0; + var x_3; (function () { return x_3; }); } switch (x_1) { case 1: - var x_4 = void 0; + var x_4; (function () { return x_4; }); break; } var _loop_2 = function() { - var x_5 = void 0; + var x_5; (function () { return x_5; }); }; while (1 == 1) { diff --git a/tests/baselines/reference/downlevelLetConst16.js b/tests/baselines/reference/downlevelLetConst16.js index 4b9d4c438fc49..edc778209bef3 100644 --- a/tests/baselines/reference/downlevelLetConst16.js +++ b/tests/baselines/reference/downlevelLetConst16.js @@ -367,7 +367,7 @@ var M4; use(z); })(M4 || (M4 = {})); function foo3() { - for (var x_7 = void 0;;) { + for (var x_7;;) { use(x_7); } for (var y_7 = [][0];;) { diff --git a/tests/baselines/reference/downlevelLetConst17.js b/tests/baselines/reference/downlevelLetConst17.js index 56ab1e6df54c6..49212b267f0f0 100644 --- a/tests/baselines/reference/downlevelLetConst17.js +++ b/tests/baselines/reference/downlevelLetConst17.js @@ -86,7 +86,7 @@ for (;;) { var x_4 = 10; use(x_4); } -for (var x_5 = void 0;;) { +for (var x_5;;) { use(x_5); x_5 = 1; } diff --git a/tests/baselines/reference/nestedBlockScopedBindings1.js b/tests/baselines/reference/nestedBlockScopedBindings1.js new file mode 100644 index 0000000000000..ea2745c472ed4 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings1.js @@ -0,0 +1,97 @@ +//// [nestedBlockScopedBindings1.ts] +function a0() { + { + let x = 1; + } + { + let x = 1; + } +} + +function a1() { + { + let x; + } + { + let x = 1; + } +} + +function a2() { + { + let x = 1; + } + { + let x; + } +} + +function a3() { + { + let x = 1; + } + switch (1) { + case 1: + let x; + break; + } +} + + +function a4() { + { + let x; + } + switch (1) { + case 1: + let x = 1; + break; + } +} + + +//// [nestedBlockScopedBindings1.js] +function a0() { + { + var x = 1; + } + { + var x = 1; + } +} +function a1() { + { + var x = void 0; + } + { + var x = 1; + } +} +function a2() { + { + var x = 1; + } + { + var x = void 0; + } +} +function a3() { + { + var x = 1; + } + switch (1) { + case 1: + var x = void 0; + break; + } +} +function a4() { + { + var x = void 0; + } + switch (1) { + case 1: + var x = 1; + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings1.symbols b/tests/baselines/reference/nestedBlockScopedBindings1.symbols new file mode 100644 index 0000000000000..80348a1391105 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings1.symbols @@ -0,0 +1,68 @@ +=== tests/cases/compiler/nestedBlockScopedBindings1.ts === +function a0() { +>a0 : Symbol(a0, Decl(nestedBlockScopedBindings1.ts, 0, 0)) + { + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings1.ts, 2, 11)) + } + { + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings1.ts, 5, 11)) + } +} + +function a1() { +>a1 : Symbol(a1, Decl(nestedBlockScopedBindings1.ts, 7, 1)) + { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings1.ts, 11, 11)) + } + { + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings1.ts, 14, 11)) + } +} + +function a2() { +>a2 : Symbol(a2, Decl(nestedBlockScopedBindings1.ts, 16, 1)) + { + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings1.ts, 20, 11)) + } + { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings1.ts, 23, 11)) + } +} + +function a3() { +>a3 : Symbol(a3, Decl(nestedBlockScopedBindings1.ts, 25, 1)) + { + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings1.ts, 29, 11)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings1.ts, 33, 15)) + + break; + } +} + + +function a4() { +>a4 : Symbol(a4, Decl(nestedBlockScopedBindings1.ts, 36, 1)) + { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings1.ts, 41, 11)) + } + switch (1) { + case 1: + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings1.ts, 45, 15)) + + break; + } +} + diff --git a/tests/baselines/reference/nestedBlockScopedBindings1.types b/tests/baselines/reference/nestedBlockScopedBindings1.types new file mode 100644 index 0000000000000..6d5b47a348b64 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings1.types @@ -0,0 +1,82 @@ +=== tests/cases/compiler/nestedBlockScopedBindings1.ts === +function a0() { +>a0 : () => void + { + let x = 1; +>x : number +>1 : number + } + { + let x = 1; +>x : number +>1 : number + } +} + +function a1() { +>a1 : () => void + { + let x; +>x : any + } + { + let x = 1; +>x : number +>1 : number + } +} + +function a2() { +>a2 : () => void + { + let x = 1; +>x : number +>1 : number + } + { + let x; +>x : any + } +} + +function a3() { +>a3 : () => void + { + let x = 1; +>x : number +>1 : number + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } +} + + +function a4() { +>a4 : () => void + { + let x; +>x : any + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x = 1; +>x : number +>1 : number + + break; + } +} + diff --git a/tests/baselines/reference/nestedBlockScopedBindings10.js b/tests/baselines/reference/nestedBlockScopedBindings10.js new file mode 100644 index 0000000000000..4cac5bceeebc1 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings10.js @@ -0,0 +1,24 @@ +//// [nestedBlockScopedBindings10.ts] +{ + let x; + x = 1; +} + +switch (1) { + case 1: + let y; + y = 1; + break; +} + +//// [nestedBlockScopedBindings10.js] +{ + var x = void 0; + x = 1; +} +switch (1) { + case 1: + var y = void 0; + y = 1; + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings10.symbols b/tests/baselines/reference/nestedBlockScopedBindings10.symbols new file mode 100644 index 0000000000000..a569e1b1f927f --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings10.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/nestedBlockScopedBindings10.ts === +{ + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings10.ts, 1, 7)) + + x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings10.ts, 1, 7)) +} + +switch (1) { + case 1: + let y; +>y : Symbol(y, Decl(nestedBlockScopedBindings10.ts, 7, 11)) + + y = 1; +>y : Symbol(y, Decl(nestedBlockScopedBindings10.ts, 7, 11)) + + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings10.types b/tests/baselines/reference/nestedBlockScopedBindings10.types new file mode 100644 index 0000000000000..ee2701cdcf13c --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings10.types @@ -0,0 +1,27 @@ +=== tests/cases/compiler/nestedBlockScopedBindings10.ts === +{ + let x; +>x : any + + x = 1; +>x = 1 : number +>x : any +>1 : number +} + +switch (1) { +>1 : number + + case 1: +>1 : number + + let y; +>y : any + + y = 1; +>y = 1 : number +>y : any +>1 : number + + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings11.js b/tests/baselines/reference/nestedBlockScopedBindings11.js new file mode 100644 index 0000000000000..23a536bcbb1e8 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings11.js @@ -0,0 +1,28 @@ +//// [nestedBlockScopedBindings11.ts] +var x; +{ + let x; + () => x; +} + +var y; +switch (1) { + case 1: + let y; + () => y; + break; +} + +//// [nestedBlockScopedBindings11.js] +var x; +{ + var x_1; + (function () { return x_1; }); +} +var y; +switch (1) { + case 1: + var y_1; + (function () { return y_1; }); + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings11.symbols b/tests/baselines/reference/nestedBlockScopedBindings11.symbols new file mode 100644 index 0000000000000..fb3886fedeee9 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings11.symbols @@ -0,0 +1,24 @@ +=== tests/cases/compiler/nestedBlockScopedBindings11.ts === +var x; +>x : Symbol(x, Decl(nestedBlockScopedBindings11.ts, 0, 3)) +{ + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings11.ts, 2, 7)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings11.ts, 2, 7)) +} + +var y; +>y : Symbol(y, Decl(nestedBlockScopedBindings11.ts, 6, 3)) + +switch (1) { + case 1: + let y; +>y : Symbol(y, Decl(nestedBlockScopedBindings11.ts, 9, 11)) + + () => y; +>y : Symbol(y, Decl(nestedBlockScopedBindings11.ts, 9, 11)) + + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings11.types b/tests/baselines/reference/nestedBlockScopedBindings11.types new file mode 100644 index 0000000000000..ab7b4228278df --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings11.types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/nestedBlockScopedBindings11.ts === +var x; +>x : any +{ + let x; +>x : any + + () => x; +>() => x : () => any +>x : any +} + +var y; +>y : any + +switch (1) { +>1 : number + + case 1: +>1 : number + + let y; +>y : any + + () => y; +>() => y : () => any +>y : any + + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings12.js b/tests/baselines/reference/nestedBlockScopedBindings12.js new file mode 100644 index 0000000000000..0b3e323a2639c --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings12.js @@ -0,0 +1,28 @@ +//// [nestedBlockScopedBindings12.ts] +var x; +{ + let x; + x = 1; +} + +var y; +switch (1) { + case 1: + let y; + y = 1; + break; +} + +//// [nestedBlockScopedBindings12.js] +var x; +{ + var x_1; + x_1 = 1; +} +var y; +switch (1) { + case 1: + var y_1; + y_1 = 1; + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings12.symbols b/tests/baselines/reference/nestedBlockScopedBindings12.symbols new file mode 100644 index 0000000000000..bff0293e45ff6 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings12.symbols @@ -0,0 +1,24 @@ +=== tests/cases/compiler/nestedBlockScopedBindings12.ts === +var x; +>x : Symbol(x, Decl(nestedBlockScopedBindings12.ts, 0, 3)) +{ + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings12.ts, 2, 7)) + + x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings12.ts, 2, 7)) +} + +var y; +>y : Symbol(y, Decl(nestedBlockScopedBindings12.ts, 6, 3)) + +switch (1) { + case 1: + let y; +>y : Symbol(y, Decl(nestedBlockScopedBindings12.ts, 9, 11)) + + y = 1; +>y : Symbol(y, Decl(nestedBlockScopedBindings12.ts, 9, 11)) + + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings12.types b/tests/baselines/reference/nestedBlockScopedBindings12.types new file mode 100644 index 0000000000000..8c1fdda0ce0fc --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings12.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/nestedBlockScopedBindings12.ts === +var x; +>x : any +{ + let x; +>x : any + + x = 1; +>x = 1 : number +>x : any +>1 : number +} + +var y; +>y : any + +switch (1) { +>1 : number + + case 1: +>1 : number + + let y; +>y : any + + y = 1; +>y = 1 : number +>y : any +>1 : number + + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings13.js b/tests/baselines/reference/nestedBlockScopedBindings13.js new file mode 100644 index 0000000000000..86e5635df68d5 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings13.js @@ -0,0 +1,23 @@ +//// [nestedBlockScopedBindings13.ts] +for (; false;) { + let x; + () => x; +} + +for (; false;) { + let y; + y = 1; +} + +//// [nestedBlockScopedBindings13.js] +var _loop_1 = function() { + var x; + (function () { return x; }); +}; +for (; false;) { + _loop_1(); +} +for (; false;) { + var y = void 0; + y = 1; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings13.symbols b/tests/baselines/reference/nestedBlockScopedBindings13.symbols new file mode 100644 index 0000000000000..a5bc7ed7866a9 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings13.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/nestedBlockScopedBindings13.ts === +for (; false;) { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings13.ts, 1, 7)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings13.ts, 1, 7)) +} + +for (; false;) { + let y; +>y : Symbol(y, Decl(nestedBlockScopedBindings13.ts, 6, 7)) + + y = 1; +>y : Symbol(y, Decl(nestedBlockScopedBindings13.ts, 6, 7)) +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings13.types b/tests/baselines/reference/nestedBlockScopedBindings13.types new file mode 100644 index 0000000000000..2e7bc7de77ed5 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings13.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/nestedBlockScopedBindings13.ts === +for (; false;) { +>false : boolean + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any +} + +for (; false;) { +>false : boolean + + let y; +>y : any + + y = 1; +>y = 1 : number +>y : any +>1 : number +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings14.js b/tests/baselines/reference/nestedBlockScopedBindings14.js new file mode 100644 index 0000000000000..1180f587420a1 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings14.js @@ -0,0 +1,27 @@ +//// [nestedBlockScopedBindings14.ts] +var x; +for (; false;) { + let x; + () => x; +} + +var y; +for (; false;) { + let y; + y = 1; +} + +//// [nestedBlockScopedBindings14.js] +var x; +var _loop_1 = function() { + var x_1; + (function () { return x_1; }); +}; +for (; false;) { + _loop_1(); +} +var y; +for (; false;) { + var y_1 = void 0; + y_1 = 1; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings14.symbols b/tests/baselines/reference/nestedBlockScopedBindings14.symbols new file mode 100644 index 0000000000000..4a13b296e88b2 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings14.symbols @@ -0,0 +1,22 @@ +=== tests/cases/compiler/nestedBlockScopedBindings14.ts === +var x; +>x : Symbol(x, Decl(nestedBlockScopedBindings14.ts, 0, 3)) + +for (; false;) { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings14.ts, 2, 7)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings14.ts, 2, 7)) +} + +var y; +>y : Symbol(y, Decl(nestedBlockScopedBindings14.ts, 6, 3)) + +for (; false;) { + let y; +>y : Symbol(y, Decl(nestedBlockScopedBindings14.ts, 8, 7)) + + y = 1; +>y : Symbol(y, Decl(nestedBlockScopedBindings14.ts, 8, 7)) +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings14.types b/tests/baselines/reference/nestedBlockScopedBindings14.types new file mode 100644 index 0000000000000..966eaaaac7a88 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings14.types @@ -0,0 +1,29 @@ +=== tests/cases/compiler/nestedBlockScopedBindings14.ts === +var x; +>x : any + +for (; false;) { +>false : boolean + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any +} + +var y; +>y : any + +for (; false;) { +>false : boolean + + let y; +>y : any + + y = 1; +>y = 1 : number +>y : any +>1 : number +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings15.js b/tests/baselines/reference/nestedBlockScopedBindings15.js new file mode 100644 index 0000000000000..8e294de98e437 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings15.js @@ -0,0 +1,68 @@ +//// [nestedBlockScopedBindings15.ts] +for (; false;) { + { + let x; + () => x; + } +} + +for (; false;) { + { + let y; + y = 1; + } +} + +for (; false;) { + switch (1){ + case 1: + let z0; + () => z0; + break; + } +} + +for (; false;) { + switch (1){ + case 1: + let z; + z = 1; + break; + } +} + +//// [nestedBlockScopedBindings15.js] +var _loop_1 = function() { + { + var x_1; + (function () { return x_1; }); + } +}; +for (; false;) { + _loop_1(); +} +for (; false;) { + { + var y = void 0; + y = 1; + } +} +var _loop_2 = function() { + switch (1) { + case 1: + var z0_1; + (function () { return z0_1; }); + break; + } +}; +for (; false;) { + _loop_2(); +} +for (; false;) { + switch (1) { + case 1: + var z = void 0; + z = 1; + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings15.symbols b/tests/baselines/reference/nestedBlockScopedBindings15.symbols new file mode 100644 index 0000000000000..26ef28f60507b --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings15.symbols @@ -0,0 +1,46 @@ +=== tests/cases/compiler/nestedBlockScopedBindings15.ts === +for (; false;) { + { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings15.ts, 2, 11)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings15.ts, 2, 11)) + } +} + +for (; false;) { + { + let y; +>y : Symbol(y, Decl(nestedBlockScopedBindings15.ts, 9, 11)) + + y = 1; +>y : Symbol(y, Decl(nestedBlockScopedBindings15.ts, 9, 11)) + } +} + +for (; false;) { + switch (1){ + case 1: + let z0; +>z0 : Symbol(z0, Decl(nestedBlockScopedBindings15.ts, 17, 15)) + + () => z0; +>z0 : Symbol(z0, Decl(nestedBlockScopedBindings15.ts, 17, 15)) + + break; + } +} + +for (; false;) { + switch (1){ + case 1: + let z; +>z : Symbol(z, Decl(nestedBlockScopedBindings15.ts, 26, 15)) + + z = 1; +>z : Symbol(z, Decl(nestedBlockScopedBindings15.ts, 26, 15)) + + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings15.types b/tests/baselines/reference/nestedBlockScopedBindings15.types new file mode 100644 index 0000000000000..5173c0c5600b1 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings15.types @@ -0,0 +1,66 @@ +=== tests/cases/compiler/nestedBlockScopedBindings15.ts === +for (; false;) { +>false : boolean + { + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + } +} + +for (; false;) { +>false : boolean + { + let y; +>y : any + + y = 1; +>y = 1 : number +>y : any +>1 : number + } +} + +for (; false;) { +>false : boolean + + switch (1){ +>1 : number + + case 1: +>1 : number + + let z0; +>z0 : any + + () => z0; +>() => z0 : () => any +>z0 : any + + break; + } +} + +for (; false;) { +>false : boolean + + switch (1){ +>1 : number + + case 1: +>1 : number + + let z; +>z : any + + z = 1; +>z = 1 : number +>z : any +>1 : number + + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings16.js b/tests/baselines/reference/nestedBlockScopedBindings16.js new file mode 100644 index 0000000000000..91f67d0d8f20f --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings16.js @@ -0,0 +1,76 @@ +//// [nestedBlockScopedBindings16.ts] +var x; +for (; false;) { + { + let x; + () => x; + } +} + +var y; +for (; false;) { + { + let y; + y = 1; + } +} + +var z0; +for (; false;) { + switch (1){ + case 1: + let z0; + () => z0; + break; + } +} + +var z; +for (; false;) { + switch (1){ + case 1: + let z; + z = 1; + break; + } +} + +//// [nestedBlockScopedBindings16.js] +var x; +var _loop_1 = function() { + { + var x_1; + (function () { return x_1; }); + } +}; +for (; false;) { + _loop_1(); +} +var y; +for (; false;) { + { + var y_1 = void 0; + y_1 = 1; + } +} +var z0; +var _loop_2 = function() { + switch (1) { + case 1: + var z0_1; + (function () { return z0_1; }); + break; + } +}; +for (; false;) { + _loop_2(); +} +var z; +for (; false;) { + switch (1) { + case 1: + var z_1 = void 0; + z_1 = 1; + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings16.symbols b/tests/baselines/reference/nestedBlockScopedBindings16.symbols new file mode 100644 index 0000000000000..cbe8114cf14cc --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings16.symbols @@ -0,0 +1,58 @@ +=== tests/cases/compiler/nestedBlockScopedBindings16.ts === +var x; +>x : Symbol(x, Decl(nestedBlockScopedBindings16.ts, 0, 3)) + +for (; false;) { + { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings16.ts, 3, 11)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings16.ts, 3, 11)) + } +} + +var y; +>y : Symbol(y, Decl(nestedBlockScopedBindings16.ts, 8, 3)) + +for (; false;) { + { + let y; +>y : Symbol(y, Decl(nestedBlockScopedBindings16.ts, 11, 11)) + + y = 1; +>y : Symbol(y, Decl(nestedBlockScopedBindings16.ts, 11, 11)) + } +} + +var z0; +>z0 : Symbol(z0, Decl(nestedBlockScopedBindings16.ts, 16, 3)) + +for (; false;) { + switch (1){ + case 1: + let z0; +>z0 : Symbol(z0, Decl(nestedBlockScopedBindings16.ts, 20, 15)) + + () => z0; +>z0 : Symbol(z0, Decl(nestedBlockScopedBindings16.ts, 20, 15)) + + break; + } +} + +var z; +>z : Symbol(z, Decl(nestedBlockScopedBindings16.ts, 26, 3)) + +for (; false;) { + switch (1){ + case 1: + let z; +>z : Symbol(z, Decl(nestedBlockScopedBindings16.ts, 30, 15)) + + z = 1; +>z : Symbol(z, Decl(nestedBlockScopedBindings16.ts, 30, 15)) + + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings16.types b/tests/baselines/reference/nestedBlockScopedBindings16.types new file mode 100644 index 0000000000000..22698402a62df --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings16.types @@ -0,0 +1,78 @@ +=== tests/cases/compiler/nestedBlockScopedBindings16.ts === +var x; +>x : any + +for (; false;) { +>false : boolean + { + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + } +} + +var y; +>y : any + +for (; false;) { +>false : boolean + { + let y; +>y : any + + y = 1; +>y = 1 : number +>y : any +>1 : number + } +} + +var z0; +>z0 : any + +for (; false;) { +>false : boolean + + switch (1){ +>1 : number + + case 1: +>1 : number + + let z0; +>z0 : any + + () => z0; +>() => z0 : () => any +>z0 : any + + break; + } +} + +var z; +>z : any + +for (; false;) { +>false : boolean + + switch (1){ +>1 : number + + case 1: +>1 : number + + let z; +>z : any + + z = 1; +>z = 1 : number +>z : any +>1 : number + + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings2.js b/tests/baselines/reference/nestedBlockScopedBindings2.js new file mode 100644 index 0000000000000..f3a8d7f0f67da --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings2.js @@ -0,0 +1,244 @@ +//// [nestedBlockScopedBindings2.ts] +function a0() { + { + let x = 1; + () => x; + } + { + let x = 1; + } +} + +function a1() { + { + let x; + } + { + let x = 1; + () => x; + } +} + +function a2() { + { + let x = 1; + () => x; + } + { + let x; + () => x; + } +} + + +function a3() { + { + let x = 1; + () => x; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + + +function a4() { + { + let x; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + + +function a5() { + { + let x; + () => x; + } + switch (1) { + case 1: + let x; + break; + } +} + +function a6() { + switch (1) { + case 1: + let x; + break; + } + switch (1) { + case 1: + let x; + break; + } +} + +function a7() { + switch (1) { + case 1: + let x; + () => x; + break; + } + switch (1) { + case 1: + let x; + break; + } +} + +function a8() { + switch (1) { + case 1: + let x; + break; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + +function a9() { + switch (1) { + case 1: + let x; + () => x; + break; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + + +//// [nestedBlockScopedBindings2.js] +function a0() { + { + var x_1 = 1; + (function () { return x_1; }); + } + { + var x = 1; + } +} +function a1() { + { + var x = void 0; + } + { + var x_2 = 1; + (function () { return x_2; }); + } +} +function a2() { + { + var x_3 = 1; + (function () { return x_3; }); + } + { + var x_4; + (function () { return x_4; }); + } +} +function a3() { + { + var x_5 = 1; + (function () { return x_5; }); + } + switch (1) { + case 1: + var x_6; + (function () { return x_6; }); + break; + } +} +function a4() { + { + var x = void 0; + } + switch (1) { + case 1: + var x_7; + (function () { return x_7; }); + break; + } +} +function a5() { + { + var x_8; + (function () { return x_8; }); + } + switch (1) { + case 1: + var x = void 0; + break; + } +} +function a6() { + switch (1) { + case 1: + var x = void 0; + break; + } + switch (1) { + case 1: + var x = void 0; + break; + } +} +function a7() { + switch (1) { + case 1: + var x_9; + (function () { return x_9; }); + break; + } + switch (1) { + case 1: + var x = void 0; + break; + } +} +function a8() { + switch (1) { + case 1: + var x = void 0; + break; + } + switch (1) { + case 1: + var x_10; + (function () { return x_10; }); + break; + } +} +function a9() { + switch (1) { + case 1: + var x_11; + (function () { return x_11; }); + break; + } + switch (1) { + case 1: + var x_12; + (function () { return x_12; }); + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings2.symbols b/tests/baselines/reference/nestedBlockScopedBindings2.symbols new file mode 100644 index 0000000000000..e97e1539e95ee --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings2.symbols @@ -0,0 +1,197 @@ +=== tests/cases/compiler/nestedBlockScopedBindings2.ts === +function a0() { +>a0 : Symbol(a0, Decl(nestedBlockScopedBindings2.ts, 0, 0)) + { + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 2, 11)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 2, 11)) + } + { + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 6, 11)) + } +} + +function a1() { +>a1 : Symbol(a1, Decl(nestedBlockScopedBindings2.ts, 8, 1)) + { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 12, 11)) + } + { + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 15, 11)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 15, 11)) + } +} + +function a2() { +>a2 : Symbol(a2, Decl(nestedBlockScopedBindings2.ts, 18, 1)) + { + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 22, 11)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 22, 11)) + } + { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 26, 11)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 26, 11)) + } +} + + +function a3() { +>a3 : Symbol(a3, Decl(nestedBlockScopedBindings2.ts, 29, 1)) + { + let x = 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 34, 11)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 34, 11)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 39, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 39, 15)) + + break; + } +} + + +function a4() { +>a4 : Symbol(a4, Decl(nestedBlockScopedBindings2.ts, 43, 1)) + { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 48, 11)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 52, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 52, 15)) + + break; + } +} + + +function a5() { +>a5 : Symbol(a5, Decl(nestedBlockScopedBindings2.ts, 56, 1)) + { + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 61, 11)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 61, 11)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 66, 15)) + + break; + } +} + +function a6() { +>a6 : Symbol(a6, Decl(nestedBlockScopedBindings2.ts, 69, 1)) + + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 74, 15)) + + break; + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 79, 15)) + + break; + } +} + +function a7() { +>a7 : Symbol(a7, Decl(nestedBlockScopedBindings2.ts, 82, 1)) + + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 87, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 87, 15)) + + break; + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 93, 15)) + + break; + } +} + +function a8() { +>a8 : Symbol(a8, Decl(nestedBlockScopedBindings2.ts, 96, 1)) + + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 101, 15)) + + break; + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 106, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 106, 15)) + + break; + } +} + +function a9() { +>a9 : Symbol(a9, Decl(nestedBlockScopedBindings2.ts, 110, 1)) + + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 115, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 115, 15)) + + break; + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 121, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings2.ts, 121, 15)) + + break; + } +} + diff --git a/tests/baselines/reference/nestedBlockScopedBindings2.types b/tests/baselines/reference/nestedBlockScopedBindings2.types new file mode 100644 index 0000000000000..adb33b4dc7685 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings2.types @@ -0,0 +1,258 @@ +=== tests/cases/compiler/nestedBlockScopedBindings2.ts === +function a0() { +>a0 : () => void + { + let x = 1; +>x : number +>1 : number + + () => x; +>() => x : () => number +>x : number + } + { + let x = 1; +>x : number +>1 : number + } +} + +function a1() { +>a1 : () => void + { + let x; +>x : any + } + { + let x = 1; +>x : number +>1 : number + + () => x; +>() => x : () => number +>x : number + } +} + +function a2() { +>a2 : () => void + { + let x = 1; +>x : number +>1 : number + + () => x; +>() => x : () => number +>x : number + } + { + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + } +} + + +function a3() { +>a3 : () => void + { + let x = 1; +>x : number +>1 : number + + () => x; +>() => x : () => number +>x : number + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } +} + + +function a4() { +>a4 : () => void + { + let x; +>x : any + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } +} + + +function a5() { +>a5 : () => void + { + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } +} + +function a6() { +>a6 : () => void + + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } +} + +function a7() { +>a7 : () => void + + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } +} + +function a8() { +>a8 : () => void + + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } +} + +function a9() { +>a9 : () => void + + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } +} + diff --git a/tests/baselines/reference/nestedBlockScopedBindings3.js b/tests/baselines/reference/nestedBlockScopedBindings3.js new file mode 100644 index 0000000000000..97fba2da3013b --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings3.js @@ -0,0 +1,150 @@ +//// [nestedBlockScopedBindings3.ts] +function a0() { + { + for (let x = 0; x < 1; ) { + () => x; + } + } + { + for (let x;;) { + () => x; + } + } +} + +function a1() { + for (let x; x < 1;) { + () => x; + } + for (let x;;) { + () => x; + } +} + +function a2() { + for (let x; x < 1;) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + } +} + + +function a3() { + for (let x; x < 1;) { + x = x + 1; + } + switch (1) { + case 1: + let x; + break; + } +} + +function a4() { + for (let x; x < 1;) { + x = x + 1; + () => x; + } + switch (1) { + case 1: + let x; + break; + } +} + + +function a5() { + for (let x; x < 1;) { + x = x + 1; + () => x; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + +//// [nestedBlockScopedBindings3.js] +function a0() { + { + var _loop_1 = function(x) { + (function () { return x; }); + }; + for (var x = 0; x < 1;) { + _loop_1(x); + } + } + { + var _loop_2 = function(x) { + (function () { return x; }); + }; + for (var x = void 0;;) { + _loop_2(x); + } + } +} +function a1() { + var _loop_3 = function(x) { + (function () { return x; }); + }; + for (var x = void 0; x < 1;) { + _loop_3(x); + } + var _loop_4 = function(x) { + (function () { return x; }); + }; + for (var x = void 0;;) { + _loop_4(x); + } +} +function a2() { + for (var x = void 0; x < 1;) { + x = x + 1; + } + for (var x = void 0;;) { + x = x + 2; + } +} +function a3() { + for (var x = void 0; x < 1;) { + x = x + 1; + } + switch (1) { + case 1: + var x = void 0; + break; + } +} +function a4() { + var _loop_5 = function(x) { + x = x + 1; + (function () { return x; }); + }; + for (var x = void 0; x < 1;) { + _loop_5(x); + } + switch (1) { + case 1: + var x = void 0; + break; + } +} +function a5() { + var _loop_6 = function(x) { + x = x + 1; + (function () { return x; }); + }; + for (var x = void 0; x < 1;) { + _loop_6(x); + } + switch (1) { + case 1: + var x_1; + (function () { return x_1; }); + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings3.symbols b/tests/baselines/reference/nestedBlockScopedBindings3.symbols new file mode 100644 index 0000000000000..160f40a047273 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings3.symbols @@ -0,0 +1,130 @@ +=== tests/cases/compiler/nestedBlockScopedBindings3.ts === +function a0() { +>a0 : Symbol(a0, Decl(nestedBlockScopedBindings3.ts, 0, 0)) + { + for (let x = 0; x < 1; ) { +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 2, 16)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 2, 16)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 2, 16)) + } + } + { + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 7, 16)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 7, 16)) + } + } +} + +function a1() { +>a1 : Symbol(a1, Decl(nestedBlockScopedBindings3.ts, 11, 1)) + + for (let x; x < 1;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 14, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 14, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 14, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 17, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 17, 12)) + } +} + +function a2() { +>a2 : Symbol(a2, Decl(nestedBlockScopedBindings3.ts, 20, 1)) + + for (let x; x < 1;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 23, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 23, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 23, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 23, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 26, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 26, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 26, 12)) + } +} + + +function a3() { +>a3 : Symbol(a3, Decl(nestedBlockScopedBindings3.ts, 29, 1)) + + for (let x; x < 1;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 33, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 33, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 33, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 33, 12)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 38, 15)) + + break; + } +} + +function a4() { +>a4 : Symbol(a4, Decl(nestedBlockScopedBindings3.ts, 41, 1)) + + for (let x; x < 1;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 44, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 44, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 44, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 44, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 44, 12)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 50, 15)) + + break; + } +} + + +function a5() { +>a5 : Symbol(a5, Decl(nestedBlockScopedBindings3.ts, 53, 1)) + + for (let x; x < 1;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 57, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 57, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 57, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 57, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 57, 12)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 63, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings3.ts, 63, 15)) + + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings3.types b/tests/baselines/reference/nestedBlockScopedBindings3.types new file mode 100644 index 0000000000000..37b89242f3e2c --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings3.types @@ -0,0 +1,177 @@ +=== tests/cases/compiler/nestedBlockScopedBindings3.ts === +function a0() { +>a0 : () => void + { + for (let x = 0; x < 1; ) { +>x : number +>0 : number +>x < 1 : boolean +>x : number +>1 : number + + () => x; +>() => x : () => number +>x : number + } + } + { + for (let x;;) { +>x : any + + () => x; +>() => x : () => any +>x : any + } + } +} + +function a1() { +>a1 : () => void + + for (let x; x < 1;) { +>x : any +>x < 1 : boolean +>x : any +>1 : number + + () => x; +>() => x : () => any +>x : any + } + for (let x;;) { +>x : any + + () => x; +>() => x : () => any +>x : any + } +} + +function a2() { +>a2 : () => void + + for (let x; x < 1;) { +>x : any +>x < 1 : boolean +>x : any +>1 : number + + x = x + 1; +>x = x + 1 : any +>x : any +>x + 1 : any +>x : any +>1 : number + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + } +} + + +function a3() { +>a3 : () => void + + for (let x; x < 1;) { +>x : any +>x < 1 : boolean +>x : any +>1 : number + + x = x + 1; +>x = x + 1 : any +>x : any +>x + 1 : any +>x : any +>1 : number + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } +} + +function a4() { +>a4 : () => void + + for (let x; x < 1;) { +>x : any +>x < 1 : boolean +>x : any +>1 : number + + x = x + 1; +>x = x + 1 : any +>x : any +>x + 1 : any +>x : any +>1 : number + + () => x; +>() => x : () => any +>x : any + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } +} + + +function a5() { +>a5 : () => void + + for (let x; x < 1;) { +>x : any +>x < 1 : boolean +>x : any +>1 : number + + x = x + 1; +>x = x + 1 : any +>x : any +>x + 1 : any +>x : any +>1 : number + + () => x; +>() => x : () => any +>x : any + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings4.js b/tests/baselines/reference/nestedBlockScopedBindings4.js new file mode 100644 index 0000000000000..51cddcf676d10 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings4.js @@ -0,0 +1,91 @@ +//// [nestedBlockScopedBindings4.ts] +function a0() { + for (let x; x < 1;) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + } +} + +function a1() { + for (let x; x < 1;) { + x = x + 1; + () => x; + } + for (let x;;) { + x = x + 2; + } +} + +function a2() { + for (let x; x < 1;) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + () => x; + } +} + + +function a3() { + for (let x; x < 1;) { + x = x + 1; + () => x; + } + for (let x;;) { + x = x + 2; + () => x; + } +} + +//// [nestedBlockScopedBindings4.js] +function a0() { + for (var x = void 0; x < 1;) { + x = x + 1; + } + for (var x = void 0;;) { + x = x + 2; + } +} +function a1() { + var _loop_1 = function(x) { + x = x + 1; + (function () { return x; }); + }; + for (var x = void 0; x < 1;) { + _loop_1(x); + } + for (var x = void 0;;) { + x = x + 2; + } +} +function a2() { + for (var x = void 0; x < 1;) { + x = x + 1; + } + var _loop_2 = function(x) { + x = x + 2; + (function () { return x; }); + }; + for (var x = void 0;;) { + _loop_2(x); + } +} +function a3() { + var _loop_3 = function(x) { + x = x + 1; + (function () { return x; }); + }; + for (var x = void 0; x < 1;) { + _loop_3(x); + } + var _loop_4 = function(x) { + x = x + 2; + (function () { return x; }); + }; + for (var x = void 0;;) { + _loop_4(x); + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings4.symbols b/tests/baselines/reference/nestedBlockScopedBindings4.symbols new file mode 100644 index 0000000000000..dac99d8158fa9 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings4.symbols @@ -0,0 +1,93 @@ +=== tests/cases/compiler/nestedBlockScopedBindings4.ts === +function a0() { +>a0 : Symbol(a0, Decl(nestedBlockScopedBindings4.ts, 0, 0)) + + for (let x; x < 1;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 1, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 1, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 1, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 1, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 4, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 4, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 4, 12)) + } +} + +function a1() { +>a1 : Symbol(a1, Decl(nestedBlockScopedBindings4.ts, 7, 1)) + + for (let x; x < 1;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 10, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 10, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 10, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 10, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 10, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 14, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 14, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 14, 12)) + } +} + +function a2() { +>a2 : Symbol(a2, Decl(nestedBlockScopedBindings4.ts, 17, 1)) + + for (let x; x < 1;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 20, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 20, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 20, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 20, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 23, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 23, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 23, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 23, 12)) + } +} + + +function a3() { +>a3 : Symbol(a3, Decl(nestedBlockScopedBindings4.ts, 27, 1)) + + for (let x; x < 1;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 31, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 31, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 31, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 31, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 31, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 35, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 35, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 35, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings4.ts, 35, 12)) + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings4.types b/tests/baselines/reference/nestedBlockScopedBindings4.types new file mode 100644 index 0000000000000..b38d61f3f4400 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings4.types @@ -0,0 +1,129 @@ +=== tests/cases/compiler/nestedBlockScopedBindings4.ts === +function a0() { +>a0 : () => void + + for (let x; x < 1;) { +>x : any +>x < 1 : boolean +>x : any +>1 : number + + x = x + 1; +>x = x + 1 : any +>x : any +>x + 1 : any +>x : any +>1 : number + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + } +} + +function a1() { +>a1 : () => void + + for (let x; x < 1;) { +>x : any +>x < 1 : boolean +>x : any +>1 : number + + x = x + 1; +>x = x + 1 : any +>x : any +>x + 1 : any +>x : any +>1 : number + + () => x; +>() => x : () => any +>x : any + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + } +} + +function a2() { +>a2 : () => void + + for (let x; x < 1;) { +>x : any +>x < 1 : boolean +>x : any +>1 : number + + x = x + 1; +>x = x + 1 : any +>x : any +>x + 1 : any +>x : any +>1 : number + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + + () => x; +>() => x : () => any +>x : any + } +} + + +function a3() { +>a3 : () => void + + for (let x; x < 1;) { +>x : any +>x < 1 : boolean +>x : any +>1 : number + + x = x + 1; +>x = x + 1 : any +>x : any +>x + 1 : any +>x : any +>1 : number + + () => x; +>() => x : () => any +>x : any + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + + () => x; +>() => x : () => any +>x : any + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings5.js b/tests/baselines/reference/nestedBlockScopedBindings5.js new file mode 100644 index 0000000000000..c80c72c0ed66e --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings5.js @@ -0,0 +1,169 @@ +//// [nestedBlockScopedBindings5.ts] +function a0() { + for (let x in []) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + } +} + +function a1() { + for (let x in []) { + x = x + 1; + () => x; + } + for (let x;;) { + x = x + 2; + } +} + +function a2() { + for (let x in []) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + () => x; + } +} + + +function a3() { + for (let x in []) { + x = x + 1; + () => x; + } + for (let x;false;) { + x = x + 2; + () => x; + } + switch (1) { + case 1: + let x; + () => x; + break; + } + +} + +function a4() { + for (let x in []) { + x = x + 1; + } + for (let x;false;) { + x = x + 2; + } + switch (1) { + case 1: + let x; + () => x; + break; + } + +} + +function a5() { + let y; + for (let x in []) { + x = x + 1; + } + for (let x;false;) { + x = x + 2; + () => x; + } + switch (1) { + case 1: + let x; + break; + } + +} + +//// [nestedBlockScopedBindings5.js] +function a0() { + for (var x in []) { + x = x + 1; + } + for (var x = void 0;;) { + x = x + 2; + } +} +function a1() { + var _loop_1 = function(x) { + x = x + 1; + (function () { return x; }); + }; + for (var x in []) { + _loop_1(x); + } + for (var x = void 0;;) { + x = x + 2; + } +} +function a2() { + for (var x in []) { + x = x + 1; + } + var _loop_2 = function(x) { + x = x + 2; + (function () { return x; }); + }; + for (var x = void 0;;) { + _loop_2(x); + } +} +function a3() { + var _loop_3 = function(x) { + x = x + 1; + (function () { return x; }); + }; + for (var x in []) { + _loop_3(x); + } + var _loop_4 = function(x) { + x = x + 2; + (function () { return x; }); + }; + for (var x = void 0; false;) { + _loop_4(x); + } + switch (1) { + case 1: + var x_1; + (function () { return x_1; }); + break; + } +} +function a4() { + for (var x in []) { + x = x + 1; + } + for (var x = void 0; false;) { + x = x + 2; + } + switch (1) { + case 1: + var x_2; + (function () { return x_2; }); + break; + } +} +function a5() { + var y; + for (var x in []) { + x = x + 1; + } + var _loop_5 = function(x) { + x = x + 2; + (function () { return x; }); + }; + for (var x = void 0; false;) { + _loop_5(x); + } + switch (1) { + case 1: + var x = void 0; + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings5.symbols b/tests/baselines/reference/nestedBlockScopedBindings5.symbols new file mode 100644 index 0000000000000..202a1d2e83f06 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings5.symbols @@ -0,0 +1,163 @@ +=== tests/cases/compiler/nestedBlockScopedBindings5.ts === +function a0() { +>a0 : Symbol(a0, Decl(nestedBlockScopedBindings5.ts, 0, 0)) + + for (let x in []) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 1, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 1, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 1, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 4, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 4, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 4, 12)) + } +} + +function a1() { +>a1 : Symbol(a1, Decl(nestedBlockScopedBindings5.ts, 7, 1)) + + for (let x in []) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 10, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 10, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 10, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 10, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 14, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 14, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 14, 12)) + } +} + +function a2() { +>a2 : Symbol(a2, Decl(nestedBlockScopedBindings5.ts, 17, 1)) + + for (let x in []) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 20, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 20, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 20, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 23, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 23, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 23, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 23, 12)) + } +} + + +function a3() { +>a3 : Symbol(a3, Decl(nestedBlockScopedBindings5.ts, 27, 1)) + + for (let x in []) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 31, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 31, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 31, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 31, 12)) + } + for (let x;false;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 35, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 35, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 35, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 35, 12)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 41, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 41, 15)) + + break; + } + +} + +function a4() { +>a4 : Symbol(a4, Decl(nestedBlockScopedBindings5.ts, 46, 1)) + + for (let x in []) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 49, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 49, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 49, 12)) + } + for (let x;false;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 52, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 52, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 52, 12)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 57, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 57, 15)) + + break; + } + +} + +function a5() { +>a5 : Symbol(a5, Decl(nestedBlockScopedBindings5.ts, 62, 1)) + + let y; +>y : Symbol(y, Decl(nestedBlockScopedBindings5.ts, 65, 7)) + + for (let x in []) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 66, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 66, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 66, 12)) + } + for (let x;false;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 69, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 69, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 69, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 69, 12)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings5.ts, 75, 15)) + + break; + } + +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings5.types b/tests/baselines/reference/nestedBlockScopedBindings5.types new file mode 100644 index 0000000000000..10ea0e5f902fd --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings5.types @@ -0,0 +1,227 @@ +=== tests/cases/compiler/nestedBlockScopedBindings5.ts === +function a0() { +>a0 : () => void + + for (let x in []) { +>x : string +>[] : undefined[] + + x = x + 1; +>x = x + 1 : string +>x : string +>x + 1 : string +>x : string +>1 : number + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + } +} + +function a1() { +>a1 : () => void + + for (let x in []) { +>x : string +>[] : undefined[] + + x = x + 1; +>x = x + 1 : string +>x : string +>x + 1 : string +>x : string +>1 : number + + () => x; +>() => x : () => string +>x : string + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + } +} + +function a2() { +>a2 : () => void + + for (let x in []) { +>x : string +>[] : undefined[] + + x = x + 1; +>x = x + 1 : string +>x : string +>x + 1 : string +>x : string +>1 : number + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + + () => x; +>() => x : () => any +>x : any + } +} + + +function a3() { +>a3 : () => void + + for (let x in []) { +>x : string +>[] : undefined[] + + x = x + 1; +>x = x + 1 : string +>x : string +>x + 1 : string +>x : string +>1 : number + + () => x; +>() => x : () => string +>x : string + } + for (let x;false;) { +>x : any +>false : boolean + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + + () => x; +>() => x : () => any +>x : any + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } + +} + +function a4() { +>a4 : () => void + + for (let x in []) { +>x : string +>[] : undefined[] + + x = x + 1; +>x = x + 1 : string +>x : string +>x + 1 : string +>x : string +>1 : number + } + for (let x;false;) { +>x : any +>false : boolean + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } + +} + +function a5() { +>a5 : () => void + + let y; +>y : any + + for (let x in []) { +>x : string +>[] : undefined[] + + x = x + 1; +>x = x + 1 : string +>x : string +>x + 1 : string +>x : string +>1 : number + } + for (let x;false;) { +>x : any +>false : boolean + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + + () => x; +>() => x : () => any +>x : any + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } + +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings6.js b/tests/baselines/reference/nestedBlockScopedBindings6.js new file mode 100644 index 0000000000000..78207b98fcd2e --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings6.js @@ -0,0 +1,197 @@ +//// [nestedBlockScopedBindings6.ts] +function a0() { + for (let x of [1]) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + } +} + +function a1() { + for (let x of [1]) { + x = x + 1; + () => x; + } + for (let x;;) { + x = x + 2; + } +} + +function a2() { + for (let x of [1]) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + () => x; + } +} + +function a3() { + for (let x of [1]) { + x = x + 1; + () => x; + } + for (let x;;) { + x = x + 2; + () => x; + } +} + +function a4() { + for (let x of [1]) { + x = x + 1; + () => x; + } + switch (1) { + case 1: + let x; + break; + } +} + + +function a5() { + for (let x of [1]) { + x = x + 1; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + +function a6() { + for (let x of [1]) { + x = x + 1; + } + switch (1) { + case 1: + let x; + break; + } +} + +function a7() { + for (let x of [1]) { + x = x + 1; + () => x; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + +//// [nestedBlockScopedBindings6.js] +function a0() { + for (var _i = 0, _a = [1]; _i < _a.length; _i++) { + var x = _a[_i]; + x = x + 1; + } + for (var x = void 0;;) { + x = x + 2; + } +} +function a1() { + var _loop_1 = function(x) { + x = x + 1; + (function () { return x; }); + }; + for (var _i = 0, _a = [1]; _i < _a.length; _i++) { + var x = _a[_i]; + _loop_1(x); + } + for (var x = void 0;;) { + x = x + 2; + } +} +function a2() { + for (var _i = 0, _a = [1]; _i < _a.length; _i++) { + var x = _a[_i]; + x = x + 1; + } + var _loop_2 = function(x) { + x = x + 2; + (function () { return x; }); + }; + for (var x = void 0;;) { + _loop_2(x); + } +} +function a3() { + var _loop_3 = function(x) { + x = x + 1; + (function () { return x; }); + }; + for (var _i = 0, _a = [1]; _i < _a.length; _i++) { + var x = _a[_i]; + _loop_3(x); + } + var _loop_4 = function(x) { + x = x + 2; + (function () { return x; }); + }; + for (var x = void 0;;) { + _loop_4(x); + } +} +function a4() { + var _loop_5 = function(x) { + x = x + 1; + (function () { return x; }); + }; + for (var _i = 0, _a = [1]; _i < _a.length; _i++) { + var x = _a[_i]; + _loop_5(x); + } + switch (1) { + case 1: + var x = void 0; + break; + } +} +function a5() { + for (var _i = 0, _a = [1]; _i < _a.length; _i++) { + var x = _a[_i]; + x = x + 1; + } + switch (1) { + case 1: + var x_1; + (function () { return x_1; }); + break; + } +} +function a6() { + for (var _i = 0, _a = [1]; _i < _a.length; _i++) { + var x = _a[_i]; + x = x + 1; + } + switch (1) { + case 1: + var x = void 0; + break; + } +} +function a7() { + var _loop_6 = function(x) { + x = x + 1; + (function () { return x; }); + }; + for (var _i = 0, _a = [1]; _i < _a.length; _i++) { + var x = _a[_i]; + _loop_6(x); + } + switch (1) { + case 1: + var x_2; + (function () { return x_2; }); + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings6.symbols b/tests/baselines/reference/nestedBlockScopedBindings6.symbols new file mode 100644 index 0000000000000..43cfcb4381409 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings6.symbols @@ -0,0 +1,177 @@ +=== tests/cases/compiler/nestedBlockScopedBindings6.ts === +function a0() { +>a0 : Symbol(a0, Decl(nestedBlockScopedBindings6.ts, 0, 0)) + + for (let x of [1]) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 1, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 1, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 1, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 4, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 4, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 4, 12)) + } +} + +function a1() { +>a1 : Symbol(a1, Decl(nestedBlockScopedBindings6.ts, 7, 1)) + + for (let x of [1]) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 10, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 10, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 10, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 10, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 14, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 14, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 14, 12)) + } +} + +function a2() { +>a2 : Symbol(a2, Decl(nestedBlockScopedBindings6.ts, 17, 1)) + + for (let x of [1]) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 20, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 20, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 20, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 23, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 23, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 23, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 23, 12)) + } +} + +function a3() { +>a3 : Symbol(a3, Decl(nestedBlockScopedBindings6.ts, 27, 1)) + + for (let x of [1]) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 30, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 30, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 30, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 30, 12)) + } + for (let x;;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 34, 12)) + + x = x + 2; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 34, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 34, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 34, 12)) + } +} + +function a4() { +>a4 : Symbol(a4, Decl(nestedBlockScopedBindings6.ts, 38, 1)) + + for (let x of [1]) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 41, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 41, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 41, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 41, 12)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 47, 15)) + + break; + } +} + + +function a5() { +>a5 : Symbol(a5, Decl(nestedBlockScopedBindings6.ts, 50, 1)) + + for (let x of [1]) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 54, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 54, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 54, 12)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 59, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 59, 15)) + + break; + } +} + +function a6() { +>a6 : Symbol(a6, Decl(nestedBlockScopedBindings6.ts, 63, 1)) + + for (let x of [1]) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 66, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 66, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 66, 12)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 71, 15)) + + break; + } +} + +function a7() { +>a7 : Symbol(a7, Decl(nestedBlockScopedBindings6.ts, 74, 1)) + + for (let x of [1]) { +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 77, 12)) + + x = x + 1; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 77, 12)) +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 77, 12)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 77, 12)) + } + switch (1) { + case 1: + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 83, 15)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings6.ts, 83, 15)) + + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings6.types b/tests/baselines/reference/nestedBlockScopedBindings6.types new file mode 100644 index 0000000000000..5c8c1fa68fadc --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings6.types @@ -0,0 +1,253 @@ +=== tests/cases/compiler/nestedBlockScopedBindings6.ts === +function a0() { +>a0 : () => void + + for (let x of [1]) { +>x : number +>[1] : number[] +>1 : number + + x = x + 1; +>x = x + 1 : number +>x : number +>x + 1 : number +>x : number +>1 : number + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + } +} + +function a1() { +>a1 : () => void + + for (let x of [1]) { +>x : number +>[1] : number[] +>1 : number + + x = x + 1; +>x = x + 1 : number +>x : number +>x + 1 : number +>x : number +>1 : number + + () => x; +>() => x : () => number +>x : number + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + } +} + +function a2() { +>a2 : () => void + + for (let x of [1]) { +>x : number +>[1] : number[] +>1 : number + + x = x + 1; +>x = x + 1 : number +>x : number +>x + 1 : number +>x : number +>1 : number + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + + () => x; +>() => x : () => any +>x : any + } +} + +function a3() { +>a3 : () => void + + for (let x of [1]) { +>x : number +>[1] : number[] +>1 : number + + x = x + 1; +>x = x + 1 : number +>x : number +>x + 1 : number +>x : number +>1 : number + + () => x; +>() => x : () => number +>x : number + } + for (let x;;) { +>x : any + + x = x + 2; +>x = x + 2 : any +>x : any +>x + 2 : any +>x : any +>2 : number + + () => x; +>() => x : () => any +>x : any + } +} + +function a4() { +>a4 : () => void + + for (let x of [1]) { +>x : number +>[1] : number[] +>1 : number + + x = x + 1; +>x = x + 1 : number +>x : number +>x + 1 : number +>x : number +>1 : number + + () => x; +>() => x : () => number +>x : number + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } +} + + +function a5() { +>a5 : () => void + + for (let x of [1]) { +>x : number +>[1] : number[] +>1 : number + + x = x + 1; +>x = x + 1 : number +>x : number +>x + 1 : number +>x : number +>1 : number + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } +} + +function a6() { +>a6 : () => void + + for (let x of [1]) { +>x : number +>[1] : number[] +>1 : number + + x = x + 1; +>x = x + 1 : number +>x : number +>x + 1 : number +>x : number +>1 : number + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + break; + } +} + +function a7() { +>a7 : () => void + + for (let x of [1]) { +>x : number +>[1] : number[] +>1 : number + + x = x + 1; +>x = x + 1 : number +>x : number +>x + 1 : number +>x : number +>1 : number + + () => x; +>() => x : () => number +>x : number + } + switch (1) { +>1 : number + + case 1: +>1 : number + + let x; +>x : any + + () => x; +>() => x : () => any +>x : any + + break; + } +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings7.js b/tests/baselines/reference/nestedBlockScopedBindings7.js new file mode 100644 index 0000000000000..df0e6c52a6261 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings7.js @@ -0,0 +1,19 @@ +//// [nestedBlockScopedBindings7.ts] +for (let x; false;) { + () => x; +} + +for (let y; false;) { + y = 1; +} + +//// [nestedBlockScopedBindings7.js] +var _loop_1 = function(x) { + (function () { return x; }); +}; +for (var x = void 0; false;) { + _loop_1(x); +} +for (var y = void 0; false;) { + y = 1; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings7.symbols b/tests/baselines/reference/nestedBlockScopedBindings7.symbols new file mode 100644 index 0000000000000..2d65af06a960e --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings7.symbols @@ -0,0 +1,14 @@ +=== tests/cases/compiler/nestedBlockScopedBindings7.ts === +for (let x; false;) { +>x : Symbol(x, Decl(nestedBlockScopedBindings7.ts, 0, 8)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings7.ts, 0, 8)) +} + +for (let y; false;) { +>y : Symbol(y, Decl(nestedBlockScopedBindings7.ts, 4, 8)) + + y = 1; +>y : Symbol(y, Decl(nestedBlockScopedBindings7.ts, 4, 8)) +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings7.types b/tests/baselines/reference/nestedBlockScopedBindings7.types new file mode 100644 index 0000000000000..2fdb2d90e76a0 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings7.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/nestedBlockScopedBindings7.ts === +for (let x; false;) { +>x : any +>false : boolean + + () => x; +>() => x : () => any +>x : any +} + +for (let y; false;) { +>y : any +>false : boolean + + y = 1; +>y = 1 : number +>y : any +>1 : number +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings8.js b/tests/baselines/reference/nestedBlockScopedBindings8.js new file mode 100644 index 0000000000000..772dc020d6deb --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings8.js @@ -0,0 +1,23 @@ +//// [nestedBlockScopedBindings8.ts] +var x; +for (let x; false; ) { + () => x; +} + +var y; +for (let y; false; ) { + y = 1; +} + +//// [nestedBlockScopedBindings8.js] +var x; +var _loop_1 = function(x_1) { + (function () { return x_1; }); +}; +for (var x_1; false;) { + _loop_1(x_1); +} +var y; +for (var y_1; false;) { + y_1 = 1; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings8.symbols b/tests/baselines/reference/nestedBlockScopedBindings8.symbols new file mode 100644 index 0000000000000..a61df0502ec8a --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings8.symbols @@ -0,0 +1,20 @@ +=== tests/cases/compiler/nestedBlockScopedBindings8.ts === +var x; +>x : Symbol(x, Decl(nestedBlockScopedBindings8.ts, 0, 3)) + +for (let x; false; ) { +>x : Symbol(x, Decl(nestedBlockScopedBindings8.ts, 1, 8)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings8.ts, 1, 8)) +} + +var y; +>y : Symbol(y, Decl(nestedBlockScopedBindings8.ts, 5, 3)) + +for (let y; false; ) { +>y : Symbol(y, Decl(nestedBlockScopedBindings8.ts, 6, 8)) + + y = 1; +>y : Symbol(y, Decl(nestedBlockScopedBindings8.ts, 6, 8)) +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings8.types b/tests/baselines/reference/nestedBlockScopedBindings8.types new file mode 100644 index 0000000000000..9e4b98ffbf2f3 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings8.types @@ -0,0 +1,25 @@ +=== tests/cases/compiler/nestedBlockScopedBindings8.ts === +var x; +>x : any + +for (let x; false; ) { +>x : any +>false : boolean + + () => x; +>() => x : () => any +>x : any +} + +var y; +>y : any + +for (let y; false; ) { +>y : any +>false : boolean + + y = 1; +>y = 1 : number +>y : any +>1 : number +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings9.js b/tests/baselines/reference/nestedBlockScopedBindings9.js new file mode 100644 index 0000000000000..9f037924c6841 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings9.js @@ -0,0 +1,24 @@ +//// [nestedBlockScopedBindings9.ts] +{ + let x; + () => x; +} + +switch (1) { + case 1: + let y; + () => y; + break; +} + +//// [nestedBlockScopedBindings9.js] +{ + var x_1; + (function () { return x_1; }); +} +switch (1) { + case 1: + var y_1; + (function () { return y_1; }); + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings9.symbols b/tests/baselines/reference/nestedBlockScopedBindings9.symbols new file mode 100644 index 0000000000000..1564c9e893103 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings9.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/nestedBlockScopedBindings9.ts === +{ + let x; +>x : Symbol(x, Decl(nestedBlockScopedBindings9.ts, 1, 7)) + + () => x; +>x : Symbol(x, Decl(nestedBlockScopedBindings9.ts, 1, 7)) +} + +switch (1) { + case 1: + let y; +>y : Symbol(y, Decl(nestedBlockScopedBindings9.ts, 7, 11)) + + () => y; +>y : Symbol(y, Decl(nestedBlockScopedBindings9.ts, 7, 11)) + + break; +} diff --git a/tests/baselines/reference/nestedBlockScopedBindings9.types b/tests/baselines/reference/nestedBlockScopedBindings9.types new file mode 100644 index 0000000000000..b889421e7dd61 --- /dev/null +++ b/tests/baselines/reference/nestedBlockScopedBindings9.types @@ -0,0 +1,25 @@ +=== tests/cases/compiler/nestedBlockScopedBindings9.ts === +{ + let x; +>x : any + + () => x; +>() => x : () => any +>x : any +} + +switch (1) { +>1 : number + + case 1: +>1 : number + + let y; +>y : any + + () => y; +>() => y : () => any +>y : any + + break; +} diff --git a/tests/cases/compiler/nestedBlockScopedBindings1.ts b/tests/cases/compiler/nestedBlockScopedBindings1.ts new file mode 100644 index 0000000000000..9fd580044a586 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings1.ts @@ -0,0 +1,49 @@ +function a0() { + { + let x = 1; + } + { + let x = 1; + } +} + +function a1() { + { + let x; + } + { + let x = 1; + } +} + +function a2() { + { + let x = 1; + } + { + let x; + } +} + +function a3() { + { + let x = 1; + } + switch (1) { + case 1: + let x; + break; + } +} + + +function a4() { + { + let x; + } + switch (1) { + case 1: + let x = 1; + break; + } +} diff --git a/tests/cases/compiler/nestedBlockScopedBindings10.ts b/tests/cases/compiler/nestedBlockScopedBindings10.ts new file mode 100644 index 0000000000000..5b3e5ad34a659 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings10.ts @@ -0,0 +1,11 @@ +{ + let x; + x = 1; +} + +switch (1) { + case 1: + let y; + y = 1; + break; +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings11.ts b/tests/cases/compiler/nestedBlockScopedBindings11.ts new file mode 100644 index 0000000000000..5d3e527eaf0a1 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings11.ts @@ -0,0 +1,13 @@ +var x; +{ + let x; + () => x; +} + +var y; +switch (1) { + case 1: + let y; + () => y; + break; +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings12.ts b/tests/cases/compiler/nestedBlockScopedBindings12.ts new file mode 100644 index 0000000000000..05aa00c1b5b12 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings12.ts @@ -0,0 +1,13 @@ +var x; +{ + let x; + x = 1; +} + +var y; +switch (1) { + case 1: + let y; + y = 1; + break; +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings13.ts b/tests/cases/compiler/nestedBlockScopedBindings13.ts new file mode 100644 index 0000000000000..6cb1133a9f681 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings13.ts @@ -0,0 +1,9 @@ +for (; false;) { + let x; + () => x; +} + +for (; false;) { + let y; + y = 1; +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings14.ts b/tests/cases/compiler/nestedBlockScopedBindings14.ts new file mode 100644 index 0000000000000..879551a041aa3 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings14.ts @@ -0,0 +1,11 @@ +var x; +for (; false;) { + let x; + () => x; +} + +var y; +for (; false;) { + let y; + y = 1; +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings15.ts b/tests/cases/compiler/nestedBlockScopedBindings15.ts new file mode 100644 index 0000000000000..703494e0949bd --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings15.ts @@ -0,0 +1,31 @@ +for (; false;) { + { + let x; + () => x; + } +} + +for (; false;) { + { + let y; + y = 1; + } +} + +for (; false;) { + switch (1){ + case 1: + let z0; + () => z0; + break; + } +} + +for (; false;) { + switch (1){ + case 1: + let z; + z = 1; + break; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings16.ts b/tests/cases/compiler/nestedBlockScopedBindings16.ts new file mode 100644 index 0000000000000..c85a942110282 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings16.ts @@ -0,0 +1,35 @@ +var x; +for (; false;) { + { + let x; + () => x; + } +} + +var y; +for (; false;) { + { + let y; + y = 1; + } +} + +var z0; +for (; false;) { + switch (1){ + case 1: + let z0; + () => z0; + break; + } +} + +var z; +for (; false;) { + switch (1){ + case 1: + let z; + z = 1; + break; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings2.ts b/tests/cases/compiler/nestedBlockScopedBindings2.ts new file mode 100644 index 0000000000000..694f27d1a247b --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings2.ts @@ -0,0 +1,126 @@ +function a0() { + { + let x = 1; + () => x; + } + { + let x = 1; + } +} + +function a1() { + { + let x; + } + { + let x = 1; + () => x; + } +} + +function a2() { + { + let x = 1; + () => x; + } + { + let x; + () => x; + } +} + + +function a3() { + { + let x = 1; + () => x; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + + +function a4() { + { + let x; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + + +function a5() { + { + let x; + () => x; + } + switch (1) { + case 1: + let x; + break; + } +} + +function a6() { + switch (1) { + case 1: + let x; + break; + } + switch (1) { + case 1: + let x; + break; + } +} + +function a7() { + switch (1) { + case 1: + let x; + () => x; + break; + } + switch (1) { + case 1: + let x; + break; + } +} + +function a8() { + switch (1) { + case 1: + let x; + break; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + +function a9() { + switch (1) { + case 1: + let x; + () => x; + break; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} diff --git a/tests/cases/compiler/nestedBlockScopedBindings3.ts b/tests/cases/compiler/nestedBlockScopedBindings3.ts new file mode 100644 index 0000000000000..e073bebadb963 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings3.ts @@ -0,0 +1,68 @@ +function a0() { + { + for (let x = 0; x < 1; ) { + () => x; + } + } + { + for (let x;;) { + () => x; + } + } +} + +function a1() { + for (let x; x < 1;) { + () => x; + } + for (let x;;) { + () => x; + } +} + +function a2() { + for (let x; x < 1;) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + } +} + + +function a3() { + for (let x; x < 1;) { + x = x + 1; + } + switch (1) { + case 1: + let x; + break; + } +} + +function a4() { + for (let x; x < 1;) { + x = x + 1; + () => x; + } + switch (1) { + case 1: + let x; + break; + } +} + + +function a5() { + for (let x; x < 1;) { + x = x + 1; + () => x; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings4.ts b/tests/cases/compiler/nestedBlockScopedBindings4.ts new file mode 100644 index 0000000000000..33ad21e2c429d --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings4.ts @@ -0,0 +1,40 @@ +function a0() { + for (let x; x < 1;) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + } +} + +function a1() { + for (let x; x < 1;) { + x = x + 1; + () => x; + } + for (let x;;) { + x = x + 2; + } +} + +function a2() { + for (let x; x < 1;) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + () => x; + } +} + + +function a3() { + for (let x; x < 1;) { + x = x + 1; + () => x; + } + for (let x;;) { + x = x + 2; + () => x; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings5.ts b/tests/cases/compiler/nestedBlockScopedBindings5.ts new file mode 100644 index 0000000000000..65093bcc91fd4 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings5.ts @@ -0,0 +1,80 @@ +function a0() { + for (let x in []) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + } +} + +function a1() { + for (let x in []) { + x = x + 1; + () => x; + } + for (let x;;) { + x = x + 2; + } +} + +function a2() { + for (let x in []) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + () => x; + } +} + + +function a3() { + for (let x in []) { + x = x + 1; + () => x; + } + for (let x;false;) { + x = x + 2; + () => x; + } + switch (1) { + case 1: + let x; + () => x; + break; + } + +} + +function a4() { + for (let x in []) { + x = x + 1; + } + for (let x;false;) { + x = x + 2; + } + switch (1) { + case 1: + let x; + () => x; + break; + } + +} + +function a5() { + let y; + for (let x in []) { + x = x + 1; + } + for (let x;false;) { + x = x + 2; + () => x; + } + switch (1) { + case 1: + let x; + break; + } + +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings6.ts b/tests/cases/compiler/nestedBlockScopedBindings6.ts new file mode 100644 index 0000000000000..badf1db6e59ae --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings6.ts @@ -0,0 +1,88 @@ +function a0() { + for (let x of [1]) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + } +} + +function a1() { + for (let x of [1]) { + x = x + 1; + () => x; + } + for (let x;;) { + x = x + 2; + } +} + +function a2() { + for (let x of [1]) { + x = x + 1; + } + for (let x;;) { + x = x + 2; + () => x; + } +} + +function a3() { + for (let x of [1]) { + x = x + 1; + () => x; + } + for (let x;;) { + x = x + 2; + () => x; + } +} + +function a4() { + for (let x of [1]) { + x = x + 1; + () => x; + } + switch (1) { + case 1: + let x; + break; + } +} + + +function a5() { + for (let x of [1]) { + x = x + 1; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} + +function a6() { + for (let x of [1]) { + x = x + 1; + } + switch (1) { + case 1: + let x; + break; + } +} + +function a7() { + for (let x of [1]) { + x = x + 1; + () => x; + } + switch (1) { + case 1: + let x; + () => x; + break; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings7.ts b/tests/cases/compiler/nestedBlockScopedBindings7.ts new file mode 100644 index 0000000000000..67da827305b31 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings7.ts @@ -0,0 +1,7 @@ +for (let x; false;) { + () => x; +} + +for (let y; false;) { + y = 1; +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings8.ts b/tests/cases/compiler/nestedBlockScopedBindings8.ts new file mode 100644 index 0000000000000..14e33615dc208 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings8.ts @@ -0,0 +1,9 @@ +var x; +for (let x; false; ) { + () => x; +} + +var y; +for (let y; false; ) { + y = 1; +} \ No newline at end of file diff --git a/tests/cases/compiler/nestedBlockScopedBindings9.ts b/tests/cases/compiler/nestedBlockScopedBindings9.ts new file mode 100644 index 0000000000000..d7d749dcf7cd9 --- /dev/null +++ b/tests/cases/compiler/nestedBlockScopedBindings9.ts @@ -0,0 +1,11 @@ +{ + let x; + () => x; +} + +switch (1) { + case 1: + let y; + () => y; + break; +} \ No newline at end of file