From a0bcd7eabfa2c7a9706e0aff3cd752fd95c6864b Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Sat, 14 Feb 2015 00:48:46 -0800 Subject: [PATCH 01/18] initial revision of downlevel compilation for let/const bindings --- src/compiler/checker.ts | 37 +++++-- src/compiler/emitter.ts | 238 +++++++++++++++++++++++++++++++++++----- src/compiler/types.ts | 1 + 3 files changed, 237 insertions(+), 39 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cccd74e3907d3..68eb3e3e9609b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -264,7 +264,7 @@ module ts { Debug.assert((symbol.flags & SymbolFlags.Instantiated) === 0, "Should never get an instantiated symbol here."); if (symbol.flags & meaning) { return symbol; - } + } if (symbol.flags & SymbolFlags.Import) { var target = resolveImport(symbol); @@ -10207,7 +10207,30 @@ module ts { } function isUnknownIdentifier(location: Node, name: string): boolean { - return !resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined); + return !resolveName(location, name, SymbolFlags.Value | SymbolFlags.Import, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined); + } + + function getBlockScopedVariableId(n: Identifier): number { + Debug.assert(n.parent !== undefined); + + // ignore name parts of property access expressions + if (n.parent.kind === SyntaxKind.PropertyAccessExpression && + (n.parent).name === n) { + return undefined; + } + + // for names in variable declarations and binding elements try to short circuit and fetch symbol from the node + var declarationSymbol: Symbol = + (n.parent.kind === SyntaxKind.VariableDeclaration && (n.parent).name === n) || + n.parent.kind === SyntaxKind.BindingElement + ? getSymbolOfNode(n.parent) + : undefined; + + var symbol = declarationSymbol || + getNodeLinks(n).resolvedSymbol || + resolveName(n, n.text, SymbolFlags.BlockScopedVariable | SymbolFlags.Import, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined); + + return symbol && symbol.flags & SymbolFlags.BlockScopedVariable ? symbol.id : undefined; } function createResolver(): EmitResolver { @@ -10226,6 +10249,7 @@ module ts { isEntityNameVisible, getConstantValue, isUnknownIdentifier, + getBlockScopedVariableId, }; } @@ -10953,15 +10977,6 @@ module ts { if (!declarationList.declarations.length) { return grammarErrorAtPos(getSourceFileOfNode(declarationList), declarations.pos, declarations.end - declarations.pos, Diagnostics.Variable_declaration_list_cannot_be_empty); } - - if (languageVersion < ScriptTarget.ES6) { - if (isLet(declarationList)) { - return grammarErrorOnFirstToken(declarationList, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - else if (isConst(declarationList)) { - return grammarErrorOnFirstToken(declarationList, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - } } function allowLetAndConstDeclarations(parent: Node): boolean { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6a2338268e899..a6681b032cedc 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -21,6 +21,12 @@ module ts { diagnosticMessage: DiagnosticMessage; typeName?: DeclarationName; } + + interface ScopeFrame { + names: Map; + previous: ScopeFrame; + } + type GetSymbolAccessibilityDiagnostic = (symbolAccesibilityResult: SymbolAccessiblityResult) => SymbolAccessibilityDiagnostic; interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter { @@ -353,7 +359,6 @@ module ts { var enclosingDeclaration: Node; var currentSourceFile: SourceFile; var reportedDeclarationError = false; - var emitJsDocComments = compilerOptions.removeComments ? function (declaration: Node) { } : writeJsDocComments; var emit = compilerOptions.stripInternal ? stripInternal : emitNode; @@ -1557,6 +1562,11 @@ module ts { var currentSourceFile: SourceFile; + var lastFrame: ScopeFrame; + var currentScopeNames: Map; + + var generatedBlockScopeNames: string[]; + var extendsEmitted = false; var tempCount = 0; var tempVariables: Identifier[]; @@ -1629,6 +1639,82 @@ module ts { writeEmittedFiles(writer.getText(), /*writeByteOrderMark*/ compilerOptions.emitBOM); return; + function enterScope(): boolean { + var names = currentScopeNames; + currentScopeNames = undefined; + if (names) { + lastFrame = { names, previous: lastFrame }; + return true; + } + return false; + } + + function exitScope(popFrame: boolean): void { + if (popFrame) { + currentScopeNames = lastFrame.names; + lastFrame = lastFrame.previous; + } + else { + currentScopeNames = undefined; + } + } + + function makeUniqueName(location: Node, baseName: string): string { + if (!isExistingName(location, baseName)) { + // use current name as is + return setGeneratedName(baseName); + } + + // First try '_name' + if (baseName.charCodeAt(0) !== CharacterCodes._) { + var baseName = "_" + baseName; + if (!isExistingName(location, baseName)) { + return setGeneratedName(baseName); + } + } + // Find the first unique '_name_n', where n is a positive number + if (baseName.charCodeAt(baseName.length - 1) !== CharacterCodes._) { + baseName += "_"; + } + var i = 1; + while (true) { + name = baseName + i; + if (!isExistingName(location, name)) { + return setGeneratedName(name); + } + i++; + } + } + + function setGeneratedName(name: string): string { + if (!currentScopeNames) { + currentScopeNames = {}; + } + + return currentScopeNames[name] = name; + } + + + function isExistingName(location: Node, name: string) { + if (!resolver.isUnknownIdentifier(location, name)) { + return true; + } + + if (currentScopeNames && hasProperty(currentScopeNames, name)) { + return true; + } + + var frame = lastFrame; + while (frame) { + if (hasProperty(frame.names, name)) { + return true; + } + frame = frame.previous; + } + + return false; + } + function initializeEmitterWithSourceMaps() { var sourceMapDir: string; // The directory in which sourcemap will be @@ -1990,7 +2076,7 @@ module ts { function createTempVariable(location: Node, forLoopVariable?: boolean): Identifier { var name = forLoopVariable ? "_i" : undefined; while (true) { - if (name && resolver.isUnknownIdentifier(location, name)) { + if (name && !isExistingName(location, name)) { break; } // _a .. _h, _j ... _z, _0, _1, ... @@ -2338,7 +2424,20 @@ module ts { writeTextOfNode(currentSourceFile, node); } + function getBlockScopedVariableId(node: Identifier): number { + // return undefined for synthesized nodes + return node.parent && resolver.getBlockScopedVariableId(node); + } + function emitIdentifier(node: Identifier) { + var symbolId = getBlockScopedVariableId(node); + if (symbolId !== undefined && generatedBlockScopeNames) { + var text = generatedBlockScopeNames[symbolId]; + if (text) { + write(text); + return; + } + } if (!node.parent) { write(node.text); } @@ -2881,6 +2980,32 @@ module ts { emitEmbeddedStatement(node.statement); } + function emitStartOfVariableDeclarationList(decl: Node, startPos?: number): void { + var tokenKind = SyntaxKind.VarKeyword; + if (decl && languageVersion >= ScriptTarget.ES6) { + if (isLet(decl)) { + tokenKind = SyntaxKind.LetKeyword; + } + else if (isConst(decl)) { + tokenKind = SyntaxKind.ConstKeyword; + } + } + + if (startPos !== undefined) { + emitToken(tokenKind, startPos); + } + else { + switch (tokenKind) { + case SyntaxKind.VarKeyword: + return write("var "); + case SyntaxKind.LetKeyword: + return write("let "); + case SyntaxKind.ConstKeyword: + return write("const "); + } + } + } + function emitForStatement(node: ForStatement) { var endPos = emitToken(SyntaxKind.ForKeyword, node.pos); write(" "); @@ -2888,17 +3013,9 @@ module ts { if (node.initializer && node.initializer.kind === SyntaxKind.VariableDeclarationList) { var variableDeclarationList = node.initializer; var declarations = variableDeclarationList.declarations; - if (declarations[0] && isLet(declarations[0])) { - emitToken(SyntaxKind.LetKeyword, endPos); - } - else if (declarations[0] && isConst(declarations[0])) { - emitToken(SyntaxKind.ConstKeyword, endPos); - } - else { - emitToken(SyntaxKind.VarKeyword, endPos); - } + emitStartOfVariableDeclarationList(declarations[0], endPos); write(" "); - emitCommaList(variableDeclarationList.declarations); + emitCommaList(declarations); } else if (node.initializer) { emit(node.initializer); @@ -2919,12 +3036,7 @@ module ts { var variableDeclarationList = node.initializer; if (variableDeclarationList.declarations.length >= 1) { var decl = variableDeclarationList.declarations[0]; - if (isLet(decl)) { - emitToken(SyntaxKind.LetKeyword, endPos); - } - else { - emitToken(SyntaxKind.VarKeyword, endPos); - } + emitStartOfVariableDeclarationList(decl, endPos); write(" "); emit(decl); } @@ -3075,6 +3187,8 @@ module ts { if (emitCount++) { write(", "); } + + renameNonTopLevelLetAndConst(name); if (name.parent && (name.parent.kind === SyntaxKind.VariableDeclaration || name.parent.kind === SyntaxKind.BindingElement)) { emitModuleMemberName(name.parent); } @@ -3184,7 +3298,7 @@ module ts { emitDestructuringAssignment(e, createElementAccess(value, createNumericLiteral(i))); } else { - if (i === elements.length - 1) { + if (i === elements.length - 1 && (e).expression.kind === SyntaxKind.Identifier) { value = ensureIdentifier(value); emitAssignment((e).expression, value); write(".slice(" + i + ")"); @@ -3286,22 +3400,75 @@ module ts { } } else { + renameNonTopLevelLetAndConst(node.name); emitModuleMemberName(node); emitOptional(" = ", node.initializer); } } - function emitVariableStatement(node: VariableStatement) { - if (!(node.flags & NodeFlags.Export)) { - if (isLet(node.declarationList)) { - write("let "); - } - else if (isConst(node.declarationList)) { - write("const "); + function getEnclosingBlockScopeContainer(node: Node): Node { + var current = node; + while (current) { + if (isAnyFunction(current)) { + return current.parent; } - else { - write("var "); + switch (current.kind) { + case SyntaxKind.CatchClause: + case SyntaxKind.ForStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.SwitchKeyword: + return current.parent; + case SyntaxKind.Block: + if (isAnyFunction(current.parent)) { + return current.parent.parent; + } + else { + return current.parent; + } + case SyntaxKind.SourceFile: + return current; } + + current = current.parent; + } + } + + function renameNonTopLevelLetAndConst(node: Node): void { + // do not rename if + // - language version is ES6+ + // - node is synthesized (does not have a parent) + // - node is definitely not name of variable declaration. + // it still can be part of parameter declaration, this check will be done next + if (languageVersion >= ScriptTarget.ES6 || + !node.parent || + (node.parent.kind !== SyntaxKind.VariableDeclaration && node.parent.kind !== SyntaxKind.BindingElement)) { + return; + } + + var combinedFlags = getCombinedNodeFlags(node.parent); + if (((combinedFlags & NodeFlags.BlockScoped) === 0) || combinedFlags & NodeFlags.Export) { + // do not rename exported or non-block scoped variables + return; + } + + // here it is known that node is a block scoped variable + var list = getAncestor(node, SyntaxKind.VariableDeclarationList); + if (list.parent.kind === SyntaxKind.VariableStatement && list.parent.parent.kind === SyntaxKind.SourceFile) { + // do not rename variables that are defined on source file level + return; + } + + var generatedName = makeUniqueName(getEnclosingBlockScopeContainer(node), (node).text); + var symbolId = resolver.getBlockScopedVariableId(node); + if (!generatedBlockScopeNames) { + generatedBlockScopeNames = []; + } + generatedBlockScopeNames[symbolId] = generatedName; + } + + function emitVariableStatement(node: VariableStatement) { + if (!(node.flags & NodeFlags.Export)) { + emitStartOfVariableDeclarationList(node.declarationList); } emitCommaList(node.declarationList.declarations); write(";"); @@ -3472,6 +3639,8 @@ module ts { tempVariables = undefined; tempParameters = undefined; + var popFrame = enterScope() + // When targeting ES6, emit arrow function natively in ES6 if (shouldEmitAsArrowFunction(node)) { emitSignatureParametersForArrow(node); @@ -3563,6 +3732,9 @@ module ts { emitEnd(node); write(";"); } + + exitScope(popFrame); + tempCount = saveTempCount; tempVariables = saveTempVariables; tempParameters = saveTempParameters; @@ -3773,6 +3945,9 @@ module ts { tempCount = 0; tempVariables = undefined; tempParameters = undefined; + + var popFrame = enterScope(); + // Emit the constructor overload pinned comments forEach(node.members, member => { if (member.kind === SyntaxKind.Constructor && !(member).body) { @@ -3833,6 +4008,9 @@ module ts { if (ctor) { emitTrailingComments(ctor); } + + exitScope(popFrame); + tempCount = saveTempCount; tempVariables = saveTempVariables; tempParameters = saveTempParameters; @@ -3962,7 +4140,11 @@ module ts { var saveTempVariables = tempVariables; tempCount = 0; tempVariables = undefined; + var popFrame = enterScope(); + emit(node.body); + + exitScope(popFrame); tempCount = saveTempCount; tempVariables = saveTempVariables; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 12c5af21e1298..b4e848f1e52ed 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1138,6 +1138,7 @@ module ts { // Returns the constant value this property access resolves to, or 'undefined' for a non-constant getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isUnknownIdentifier(location: Node, name: string): boolean; + getBlockScopedVariableId(node: Identifier): number; } export const enum SymbolFlags { From ba52d60c7a99223c47477063b26095678912d19b Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Sat, 14 Feb 2015 14:23:37 -0800 Subject: [PATCH 02/18] try only names generated in current scope with testing if name is unique --- src/compiler/emitter.ts | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a6681b032cedc..da19862e3d80b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1696,23 +1696,7 @@ module ts { function isExistingName(location: Node, name: string) { - if (!resolver.isUnknownIdentifier(location, name)) { - return true; - } - - if (currentScopeNames && hasProperty(currentScopeNames, name)) { - return true; - } - - var frame = lastFrame; - while (frame) { - if (hasProperty(frame.names, name)) { - return true; - } - frame = frame.previous; - } - - return false; + return !resolver.isUnknownIdentifier(location, name) || (currentScopeNames && hasProperty(currentScopeNames, name)); } function initializeEmitterWithSourceMaps() { From 7f5fb8bc19005a0082fd627f82c8606799709178 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Sat, 14 Feb 2015 16:11:58 -0800 Subject: [PATCH 03/18] drop locals in block-scope container nodes during binding --- src/compiler/binder.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index be9e9a525c0d5..5657ce4e8e076 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -78,7 +78,8 @@ module ts { if (!file.locals) { file.locals = {}; - container = blockScopeContainer = file; + container = file; + setBlockScopeContainer(file, /*cleanLocals*/ false); bind(file); file.symbolCount = symbolCount; } @@ -88,6 +89,13 @@ module ts { return new Symbol(flags, name); } + function setBlockScopeContainer(node: Node, cleanLocals: boolean) { + blockScopeContainer = node; + if (cleanLocals) { + blockScopeContainer.locals = undefined; + } + } + function addDeclarationToSymbol(symbol: Symbol, node: Declaration, symbolKind: SymbolFlags) { symbol.flags |= symbolKind; if (!symbol.declarations) symbol.declarations = []; @@ -244,7 +252,10 @@ module ts { } if (isBlockScopeContainer) { - blockScopeContainer = node; + // clean locals in block scope container if + // - current node does not have local variables + // - current node is not source file (source file always have locals) + setBlockScopeContainer(node, /*cleanLocals*/ (symbolKind & SymbolFlags.HasLocals) == 0 && node.kind !== SyntaxKind.SourceFile); } forEachChild(node, bind); @@ -347,7 +358,8 @@ module ts { addDeclarationToSymbol(symbol, node, SymbolFlags.FunctionScopedVariable); var saveParent = parent; var savedBlockScopeContainer = blockScopeContainer; - parent = blockScopeContainer = node; + parent = node; + setBlockScopeContainer(node, /*cleanLocals*/ true); forEachChild(node, bind); parent = saveParent; blockScopeContainer = savedBlockScopeContainer; From 5f2588f018040f5fcd2a5cb9e31d90fd72b4c597 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Sun, 15 Feb 2015 18:44:25 -0800 Subject: [PATCH 04/18] show error if block scoped variable declared in the loop is captured in closure --- src/compiler/checker.ts | 45 +++++++++++++++++++ .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++ src/compiler/types.ts | 1 + 4 files changed, 51 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4fd925947f456..211331579cdeb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4905,10 +4905,55 @@ module ts { checkCollisionWithCapturedSuperVariable(node, node); checkCollisionWithCapturedThisVariable(node, node); + checkBlockScopedBindingCapturedInLoop(node, symbol); return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node); } + function isNameScopeBoundary(n: Node): boolean { + return isAnyFunction(n) || n.kind === SyntaxKind.ModuleDeclaration || n.kind === SyntaxKind.SourceFile; + } + + function checkBlockScopedBindingCapturedInLoop(node: Identifier, symbol: Symbol): void { + if (languageVersion >= ScriptTarget.ES6 || (symbol.flags & SymbolFlags.BlockScopedVariable) === 0) { + return; + } + + // - check if binding is used in some function + // (stop the walk when reaching container of binding declaration) + // - if first check succeeded - check if variable is declared inside the loop + + // var decl -> var decl list -> parent + var container = (symbol.valueDeclaration).parent.parent; + if (container.kind === SyntaxKind.VariableStatement) { + container = container.parent; + } + + var inFunction = false; + var current = node.parent; + while (current && current !== container) { + if (isAnyFunction(current)) { + inFunction = true; + break; + } + current = current.parent; + } + + if (!inFunction) { + return; + } + + var current: Node = container; + while (current && !isNameScopeBoundary(current)) { + if (isIterationStatement(current, /*lookInLabeledStatements*/ false)) { + getNodeLinks(current).flags |= NodeCheckFlags.BlockScopedBindingCapturedInLoop; + grammarErrorOnFirstToken(current, Diagnostics.Code_in_the_loop_captures_block_scoped_variable_0_in_closure_This_is_natively_supported_in_ECMAScript_6_or_higher, declarationNameToString(node)); + break; + } + current = current.parent; + } + } + function captureLexicalThis(node: Node, container: Node): void { var classNode = container.parent && container.parent.kind === SyntaxKind.ClassDeclaration ? container.parent : undefined; getNodeLinks(node).flags |= NodeCheckFlags.LexicalThis; diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index c6061e3570ac8..a6e8f25e0a2d9 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -382,6 +382,7 @@ module ts { Property_0_does_not_exist_on_const_enum_1: { code: 4088, category: DiagnosticCategory.Error, key: "Property '{0}' does not exist on 'const' enum '{1}'." }, let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations: { code: 4089, category: DiagnosticCategory.Error, key: "'let' is not allowed to be used as a name in 'let' or 'const' declarations." }, Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1: { code: 4090, category: DiagnosticCategory.Error, key: "Cannot initialize outer scoped variable '{0}' in the same scope as block scoped declaration '{1}'." }, + Code_in_the_loop_captures_block_scoped_variable_0_in_closure_This_is_natively_supported_in_ECMAScript_6_or_higher: { code: 4091, category: DiagnosticCategory.Error, key: "Code in the loop captures block-scoped variable '{0}' in closure. This is natively supported in ECMAScript 6 or higher." }, The_current_host_does_not_support_the_0_option: { code: 5001, category: DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." }, Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: DiagnosticCategory.Error, key: "Cannot find the common subdirectory path for the input files." }, Cannot_read_file_0_Colon_1: { code: 5012, category: DiagnosticCategory.Error, key: "Cannot read file '{0}': {1}" }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index fdeec58a7057f..f3622218eef55 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1521,6 +1521,10 @@ "category": "Error", "code": 4090 }, + "Code in the loop captures block-scoped variable '{0}' in closure. This is natively supported in ECMAScript 6 or higher.": { + "category": "Error", + "code": 4091 + }, "The current host does not support the '{0}' option.": { "category": "Error", "code": 5001 diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b4e848f1e52ed..940a4a6e5a41c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1262,6 +1262,7 @@ module ts { // Values for enum members have been computed, and any errors have been reported for them. EnumValuesComputed = 0x00000080, + BlockScopedBindingCapturedInLoop = 0x00000100, } export interface NodeLinks { From 4aff9c357d31a5b3e2efce40b313d83b93eb2b1e Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 16 Feb 2015 13:39:32 -0800 Subject: [PATCH 05/18] explicitly initialize let binding in generated code to default value --- src/compiler/emitter.ts | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index da19862e3d80b..638b78812cc34 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3155,6 +3155,14 @@ module ts { emitEnd(node.name); } + function createVoidZero(): Expression { + var zero = createNode(SyntaxKind.NumericLiteral); + zero.text = "0"; + var result = createNode(SyntaxKind.VoidExpression); + result.expression = zero; + return result; + } + function emitDestructuring(root: BinaryExpression | VariableDeclaration | ParameterDeclaration, value?: Expression) { var emitCount = 0; // An exported declaration is actually emitted as an assignment (to a property on the module object), so @@ -3195,14 +3203,6 @@ module ts { return expr; } - function createVoidZero(): Expression { - var zero = createNode(SyntaxKind.NumericLiteral); - zero.text = "0"; - var result = createNode(SyntaxKind.VoidExpression); - result.expression = zero; - return result; - } - function createDefaultValueCheck(value: Expression, defaultValue: Expression): Expression { // The value expression will be evaluated twice, so for anything but a simple identifier // we need to generate a temporary variable @@ -3384,9 +3384,14 @@ module ts { } } else { - renameNonTopLevelLetAndConst(node.name); + var initializeToDefault = renameNonTopLevelLetAndConst(node.name); emitModuleMemberName(node); - emitOptional(" = ", node.initializer); + + var initializer = + node.initializer || + (initializeToDefault && createVoidZero()); + + emitOptional(" = ", initializer); } } @@ -3417,7 +3422,7 @@ module ts { } } - function renameNonTopLevelLetAndConst(node: Node): void { + function renameNonTopLevelLetAndConst(node: Node): boolean { // do not rename if // - language version is ES6+ // - node is synthesized (does not have a parent) @@ -3426,20 +3431,20 @@ module ts { if (languageVersion >= ScriptTarget.ES6 || !node.parent || (node.parent.kind !== SyntaxKind.VariableDeclaration && node.parent.kind !== SyntaxKind.BindingElement)) { - return; + return false; } var combinedFlags = getCombinedNodeFlags(node.parent); if (((combinedFlags & NodeFlags.BlockScoped) === 0) || combinedFlags & NodeFlags.Export) { // do not rename exported or non-block scoped variables - return; + return false; } // here it is known that node is a block scoped variable var list = getAncestor(node, SyntaxKind.VariableDeclarationList); if (list.parent.kind === SyntaxKind.VariableStatement && list.parent.parent.kind === SyntaxKind.SourceFile) { // do not rename variables that are defined on source file level - return; + return false; } var generatedName = makeUniqueName(getEnclosingBlockScopeContainer(node), (node).text); @@ -3448,6 +3453,8 @@ module ts { generatedBlockScopeNames = []; } generatedBlockScopeNames[symbolId] = generatedName; + + return (combinedFlags & NodeFlags.Let) !== 0; } function emitVariableStatement(node: VariableStatement) { From 40bcad994c68675b619fb6fe69c243686817a648 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 17 Feb 2015 15:14:16 -0800 Subject: [PATCH 06/18] accepted baselines --- .../baselines/reference/APISample_compile.js | 2 + .../reference/APISample_compile.types | 8 ++++ tests/baselines/reference/APISample_linter.js | 2 + .../reference/APISample_linter.types | 8 ++++ .../reference/APISample_transform.js | 2 + .../reference/APISample_transform.types | 8 ++++ .../baselines/reference/APISample_watcher.js | 2 + .../reference/APISample_watcher.types | 8 ++++ .../VariableDeclaration10_es6.errors.txt | 7 ---- .../reference/VariableDeclaration10_es6.js | 2 +- .../reference/VariableDeclaration10_es6.types | 4 ++ .../reference/VariableDeclaration11_es6.js | 2 +- .../reference/VariableDeclaration1_es6.js | 2 +- .../VariableDeclaration2_es6.errors.txt | 5 +-- .../reference/VariableDeclaration2_es6.js | 2 +- .../VariableDeclaration3_es6.errors.txt | 7 ---- .../reference/VariableDeclaration3_es6.js | 2 +- .../reference/VariableDeclaration3_es6.types | 4 ++ .../VariableDeclaration4_es6.errors.txt | 5 +-- .../reference/VariableDeclaration4_es6.js | 2 +- .../VariableDeclaration5_es6.errors.txt | 7 ---- .../reference/VariableDeclaration5_es6.js | 2 +- .../reference/VariableDeclaration5_es6.types | 4 ++ .../VariableDeclaration7_es6.errors.txt | 7 ---- .../reference/VariableDeclaration7_es6.js | 2 +- .../reference/VariableDeclaration7_es6.types | 4 ++ .../VariableDeclaration8_es6.errors.txt | 7 ---- .../reference/VariableDeclaration8_es6.js | 2 +- .../reference/VariableDeclaration8_es6.types | 4 ++ .../VariableDeclaration9_es6.errors.txt | 7 ---- .../reference/VariableDeclaration9_es6.js | 2 +- .../reference/VariableDeclaration9_es6.types | 4 ++ .../reference/constDeclarations-errors.js | 2 +- .../constDeclarations-es5.errors.txt | 17 -------- .../reference/constDeclarations-es5.js | 6 +-- .../reference/constDeclarations-es5.types | 13 ++++++ ...mitOutputWithEarlySyntacticErrors.baseline | 2 +- .../reference/letAsIdentifierInStrictMode.js | 6 +-- .../letDeclarations-es5-1.errors.txt | 27 ------------- .../reference/letDeclarations-es5-1.js | 12 +++--- .../reference/letDeclarations-es5-1.types | 24 +++++++++++ .../reference/letDeclarations-es5.errors.txt | 40 ------------------- .../reference/letDeclarations-es5.js | 16 ++++---- .../reference/letDeclarations-es5.types | 36 +++++++++++++++++ .../reference/restElementWithInitializer2.js | 2 +- .../shadowingViaLocalValue.errors.txt | 8 +--- .../reference/shadowingViaLocalValue.js | 4 +- 47 files changed, 175 insertions(+), 176 deletions(-) delete mode 100644 tests/baselines/reference/VariableDeclaration10_es6.errors.txt create mode 100644 tests/baselines/reference/VariableDeclaration10_es6.types delete mode 100644 tests/baselines/reference/VariableDeclaration3_es6.errors.txt create mode 100644 tests/baselines/reference/VariableDeclaration3_es6.types delete mode 100644 tests/baselines/reference/VariableDeclaration5_es6.errors.txt create mode 100644 tests/baselines/reference/VariableDeclaration5_es6.types delete mode 100644 tests/baselines/reference/VariableDeclaration7_es6.errors.txt create mode 100644 tests/baselines/reference/VariableDeclaration7_es6.types delete mode 100644 tests/baselines/reference/VariableDeclaration8_es6.errors.txt create mode 100644 tests/baselines/reference/VariableDeclaration8_es6.types delete mode 100644 tests/baselines/reference/VariableDeclaration9_es6.errors.txt create mode 100644 tests/baselines/reference/VariableDeclaration9_es6.types delete mode 100644 tests/baselines/reference/constDeclarations-es5.errors.txt create mode 100644 tests/baselines/reference/constDeclarations-es5.types delete mode 100644 tests/baselines/reference/letDeclarations-es5-1.errors.txt create mode 100644 tests/baselines/reference/letDeclarations-es5-1.types delete mode 100644 tests/baselines/reference/letDeclarations-es5.errors.txt create mode 100644 tests/baselines/reference/letDeclarations-es5.types diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index b91a706aa4519..1dbf40e48fac9 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -894,6 +894,7 @@ declare module "typescript" { isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isUnknownIdentifier(location: Node, name: string): boolean; + getBlockScopedVariableId(node: Identifier): number; } const enum SymbolFlags { FunctionScopedVariable = 1, @@ -996,6 +997,7 @@ declare module "typescript" { SuperStatic = 32, ContextChecked = 64, EnumValuesComputed = 128, + BlockScopedBindingCapturedInLoop = 256, } interface NodeLinks { resolvedType?: Type; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index ae53c66680708..09344976ba69d 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -2908,6 +2908,11 @@ declare module "typescript" { >location : Node >Node : Node >name : string + + getBlockScopedVariableId(node: Identifier): number; +>getBlockScopedVariableId : (node: Identifier) => number +>node : Identifier +>Identifier : Identifier } const enum SymbolFlags { >SymbolFlags : SymbolFlags @@ -3212,6 +3217,9 @@ declare module "typescript" { EnumValuesComputed = 128, >EnumValuesComputed : NodeCheckFlags + + BlockScopedBindingCapturedInLoop = 256, +>BlockScopedBindingCapturedInLoop : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 68c13edb7dbca..fd097517f275c 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -925,6 +925,7 @@ declare module "typescript" { isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isUnknownIdentifier(location: Node, name: string): boolean; + getBlockScopedVariableId(node: Identifier): number; } const enum SymbolFlags { FunctionScopedVariable = 1, @@ -1027,6 +1028,7 @@ declare module "typescript" { SuperStatic = 32, ContextChecked = 64, EnumValuesComputed = 128, + BlockScopedBindingCapturedInLoop = 256, } interface NodeLinks { resolvedType?: Type; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 0c153e7b1dc20..f68e06fdde7b1 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -3052,6 +3052,11 @@ declare module "typescript" { >location : Node >Node : Node >name : string + + getBlockScopedVariableId(node: Identifier): number; +>getBlockScopedVariableId : (node: Identifier) => number +>node : Identifier +>Identifier : Identifier } const enum SymbolFlags { >SymbolFlags : SymbolFlags @@ -3356,6 +3361,9 @@ declare module "typescript" { EnumValuesComputed = 128, >EnumValuesComputed : NodeCheckFlags + + BlockScopedBindingCapturedInLoop = 256, +>BlockScopedBindingCapturedInLoop : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 0e80f6b55b963..d523f2920edf2 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -926,6 +926,7 @@ declare module "typescript" { isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isUnknownIdentifier(location: Node, name: string): boolean; + getBlockScopedVariableId(node: Identifier): number; } const enum SymbolFlags { FunctionScopedVariable = 1, @@ -1028,6 +1029,7 @@ declare module "typescript" { SuperStatic = 32, ContextChecked = 64, EnumValuesComputed = 128, + BlockScopedBindingCapturedInLoop = 256, } interface NodeLinks { resolvedType?: Type; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 0c201b0a5fd44..a51cfb586db6f 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -3004,6 +3004,11 @@ declare module "typescript" { >location : Node >Node : Node >name : string + + getBlockScopedVariableId(node: Identifier): number; +>getBlockScopedVariableId : (node: Identifier) => number +>node : Identifier +>Identifier : Identifier } const enum SymbolFlags { >SymbolFlags : SymbolFlags @@ -3308,6 +3313,9 @@ declare module "typescript" { EnumValuesComputed = 128, >EnumValuesComputed : NodeCheckFlags + + BlockScopedBindingCapturedInLoop = 256, +>BlockScopedBindingCapturedInLoop : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 27a2ce5e41556..58b6dfbbe5d41 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -963,6 +963,7 @@ declare module "typescript" { isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isUnknownIdentifier(location: Node, name: string): boolean; + getBlockScopedVariableId(node: Identifier): number; } const enum SymbolFlags { FunctionScopedVariable = 1, @@ -1065,6 +1066,7 @@ declare module "typescript" { SuperStatic = 32, ContextChecked = 64, EnumValuesComputed = 128, + BlockScopedBindingCapturedInLoop = 256, } interface NodeLinks { resolvedType?: Type; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 4e137cae59d1a..5ec5d51f99dbd 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -3177,6 +3177,11 @@ declare module "typescript" { >location : Node >Node : Node >name : string + + getBlockScopedVariableId(node: Identifier): number; +>getBlockScopedVariableId : (node: Identifier) => number +>node : Identifier +>Identifier : Identifier } const enum SymbolFlags { >SymbolFlags : SymbolFlags @@ -3481,6 +3486,9 @@ declare module "typescript" { EnumValuesComputed = 128, >EnumValuesComputed : NodeCheckFlags + + BlockScopedBindingCapturedInLoop = 256, +>BlockScopedBindingCapturedInLoop : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks diff --git a/tests/baselines/reference/VariableDeclaration10_es6.errors.txt b/tests/baselines/reference/VariableDeclaration10_es6.errors.txt deleted file mode 100644 index b7d4bf2f1c3f9..0000000000000 --- a/tests/baselines/reference/VariableDeclaration10_es6.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/conformance/es6/variableDeclarations/VariableDeclaration10_es6.ts(1,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. - - -==== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration10_es6.ts (1 errors) ==== - let a: number = 1 - ~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/VariableDeclaration10_es6.js b/tests/baselines/reference/VariableDeclaration10_es6.js index 14f47cea04dfe..6edba42ab0df0 100644 --- a/tests/baselines/reference/VariableDeclaration10_es6.js +++ b/tests/baselines/reference/VariableDeclaration10_es6.js @@ -2,4 +2,4 @@ let a: number = 1 //// [VariableDeclaration10_es6.js] -let a = 1; +var a = 1; diff --git a/tests/baselines/reference/VariableDeclaration10_es6.types b/tests/baselines/reference/VariableDeclaration10_es6.types new file mode 100644 index 0000000000000..47238fdd5a8f7 --- /dev/null +++ b/tests/baselines/reference/VariableDeclaration10_es6.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration10_es6.ts === +let a: number = 1 +>a : number + diff --git a/tests/baselines/reference/VariableDeclaration11_es6.js b/tests/baselines/reference/VariableDeclaration11_es6.js index 83eec6d9a13ae..0000d5cb5ab78 100644 --- a/tests/baselines/reference/VariableDeclaration11_es6.js +++ b/tests/baselines/reference/VariableDeclaration11_es6.js @@ -4,4 +4,4 @@ let //// [VariableDeclaration11_es6.js] "use strict"; -let ; +var ; diff --git a/tests/baselines/reference/VariableDeclaration1_es6.js b/tests/baselines/reference/VariableDeclaration1_es6.js index 26433bd88c3dd..a867d74726c7c 100644 --- a/tests/baselines/reference/VariableDeclaration1_es6.js +++ b/tests/baselines/reference/VariableDeclaration1_es6.js @@ -2,4 +2,4 @@ const //// [VariableDeclaration1_es6.js] -const ; +var ; diff --git a/tests/baselines/reference/VariableDeclaration2_es6.errors.txt b/tests/baselines/reference/VariableDeclaration2_es6.errors.txt index 0d8214f54208b..35e0ad2821cf6 100644 --- a/tests/baselines/reference/VariableDeclaration2_es6.errors.txt +++ b/tests/baselines/reference/VariableDeclaration2_es6.errors.txt @@ -1,10 +1,7 @@ -tests/cases/conformance/es6/variableDeclarations/VariableDeclaration2_es6.ts(1,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/variableDeclarations/VariableDeclaration2_es6.ts(1,7): error TS1155: 'const' declarations must be initialized -==== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration2_es6.ts (2 errors) ==== +==== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration2_es6.ts (1 errors) ==== const a - ~~~~~ -!!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. ~ !!! error TS1155: 'const' declarations must be initialized \ No newline at end of file diff --git a/tests/baselines/reference/VariableDeclaration2_es6.js b/tests/baselines/reference/VariableDeclaration2_es6.js index a955315a2f02c..d835435a0a62a 100644 --- a/tests/baselines/reference/VariableDeclaration2_es6.js +++ b/tests/baselines/reference/VariableDeclaration2_es6.js @@ -2,4 +2,4 @@ const a //// [VariableDeclaration2_es6.js] -const a; +var a; diff --git a/tests/baselines/reference/VariableDeclaration3_es6.errors.txt b/tests/baselines/reference/VariableDeclaration3_es6.errors.txt deleted file mode 100644 index a3b09f70d2d77..0000000000000 --- a/tests/baselines/reference/VariableDeclaration3_es6.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/conformance/es6/variableDeclarations/VariableDeclaration3_es6.ts(1,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. - - -==== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration3_es6.ts (1 errors) ==== - const a = 1 - ~~~~~ -!!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/VariableDeclaration3_es6.js b/tests/baselines/reference/VariableDeclaration3_es6.js index 4be8a3daf381f..08513b8bdbce7 100644 --- a/tests/baselines/reference/VariableDeclaration3_es6.js +++ b/tests/baselines/reference/VariableDeclaration3_es6.js @@ -2,4 +2,4 @@ const a = 1 //// [VariableDeclaration3_es6.js] -const a = 1; +var a = 1; diff --git a/tests/baselines/reference/VariableDeclaration3_es6.types b/tests/baselines/reference/VariableDeclaration3_es6.types new file mode 100644 index 0000000000000..a172c8114cbb6 --- /dev/null +++ b/tests/baselines/reference/VariableDeclaration3_es6.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration3_es6.ts === +const a = 1 +>a : number + diff --git a/tests/baselines/reference/VariableDeclaration4_es6.errors.txt b/tests/baselines/reference/VariableDeclaration4_es6.errors.txt index b4bb75b5658f6..33d956ee1e51e 100644 --- a/tests/baselines/reference/VariableDeclaration4_es6.errors.txt +++ b/tests/baselines/reference/VariableDeclaration4_es6.errors.txt @@ -1,10 +1,7 @@ -tests/cases/conformance/es6/variableDeclarations/VariableDeclaration4_es6.ts(1,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. tests/cases/conformance/es6/variableDeclarations/VariableDeclaration4_es6.ts(1,7): error TS1155: 'const' declarations must be initialized -==== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration4_es6.ts (2 errors) ==== +==== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration4_es6.ts (1 errors) ==== const a: number - ~~~~~ -!!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. ~ !!! error TS1155: 'const' declarations must be initialized \ No newline at end of file diff --git a/tests/baselines/reference/VariableDeclaration4_es6.js b/tests/baselines/reference/VariableDeclaration4_es6.js index 7a9934e052bfb..f0a8331acfebc 100644 --- a/tests/baselines/reference/VariableDeclaration4_es6.js +++ b/tests/baselines/reference/VariableDeclaration4_es6.js @@ -2,4 +2,4 @@ const a: number //// [VariableDeclaration4_es6.js] -const a; +var a; diff --git a/tests/baselines/reference/VariableDeclaration5_es6.errors.txt b/tests/baselines/reference/VariableDeclaration5_es6.errors.txt deleted file mode 100644 index c72d423e46069..0000000000000 --- a/tests/baselines/reference/VariableDeclaration5_es6.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/conformance/es6/variableDeclarations/VariableDeclaration5_es6.ts(1,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. - - -==== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration5_es6.ts (1 errors) ==== - const a: number = 1 - ~~~~~ -!!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/VariableDeclaration5_es6.js b/tests/baselines/reference/VariableDeclaration5_es6.js index e6a3c175651df..98ae1af002e2d 100644 --- a/tests/baselines/reference/VariableDeclaration5_es6.js +++ b/tests/baselines/reference/VariableDeclaration5_es6.js @@ -2,4 +2,4 @@ const a: number = 1 //// [VariableDeclaration5_es6.js] -const a = 1; +var a = 1; diff --git a/tests/baselines/reference/VariableDeclaration5_es6.types b/tests/baselines/reference/VariableDeclaration5_es6.types new file mode 100644 index 0000000000000..a07894d533d85 --- /dev/null +++ b/tests/baselines/reference/VariableDeclaration5_es6.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration5_es6.ts === +const a: number = 1 +>a : number + diff --git a/tests/baselines/reference/VariableDeclaration7_es6.errors.txt b/tests/baselines/reference/VariableDeclaration7_es6.errors.txt deleted file mode 100644 index 83d12d463e6ed..0000000000000 --- a/tests/baselines/reference/VariableDeclaration7_es6.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/conformance/es6/variableDeclarations/VariableDeclaration7_es6.ts(1,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. - - -==== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration7_es6.ts (1 errors) ==== - let a - ~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/VariableDeclaration7_es6.js b/tests/baselines/reference/VariableDeclaration7_es6.js index 00ab95503a62e..4287d79a7e45a 100644 --- a/tests/baselines/reference/VariableDeclaration7_es6.js +++ b/tests/baselines/reference/VariableDeclaration7_es6.js @@ -2,4 +2,4 @@ let a //// [VariableDeclaration7_es6.js] -let a; +var a; diff --git a/tests/baselines/reference/VariableDeclaration7_es6.types b/tests/baselines/reference/VariableDeclaration7_es6.types new file mode 100644 index 0000000000000..321c1b07bbcdd --- /dev/null +++ b/tests/baselines/reference/VariableDeclaration7_es6.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration7_es6.ts === +let a +>a : any + diff --git a/tests/baselines/reference/VariableDeclaration8_es6.errors.txt b/tests/baselines/reference/VariableDeclaration8_es6.errors.txt deleted file mode 100644 index e371c64c9a6f2..0000000000000 --- a/tests/baselines/reference/VariableDeclaration8_es6.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/conformance/es6/variableDeclarations/VariableDeclaration8_es6.ts(1,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. - - -==== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration8_es6.ts (1 errors) ==== - let a = 1 - ~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/VariableDeclaration8_es6.js b/tests/baselines/reference/VariableDeclaration8_es6.js index 9178871ef65e3..4b4dd061bff03 100644 --- a/tests/baselines/reference/VariableDeclaration8_es6.js +++ b/tests/baselines/reference/VariableDeclaration8_es6.js @@ -2,4 +2,4 @@ let a = 1 //// [VariableDeclaration8_es6.js] -let a = 1; +var a = 1; diff --git a/tests/baselines/reference/VariableDeclaration8_es6.types b/tests/baselines/reference/VariableDeclaration8_es6.types new file mode 100644 index 0000000000000..530b147136dc7 --- /dev/null +++ b/tests/baselines/reference/VariableDeclaration8_es6.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration8_es6.ts === +let a = 1 +>a : number + diff --git a/tests/baselines/reference/VariableDeclaration9_es6.errors.txt b/tests/baselines/reference/VariableDeclaration9_es6.errors.txt deleted file mode 100644 index 4a1890d46947f..0000000000000 --- a/tests/baselines/reference/VariableDeclaration9_es6.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/conformance/es6/variableDeclarations/VariableDeclaration9_es6.ts(1,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. - - -==== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration9_es6.ts (1 errors) ==== - let a: number - ~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/VariableDeclaration9_es6.js b/tests/baselines/reference/VariableDeclaration9_es6.js index b22c5691eb29d..9ecfc40edff0a 100644 --- a/tests/baselines/reference/VariableDeclaration9_es6.js +++ b/tests/baselines/reference/VariableDeclaration9_es6.js @@ -2,4 +2,4 @@ let a: number //// [VariableDeclaration9_es6.js] -let a; +var a; diff --git a/tests/baselines/reference/VariableDeclaration9_es6.types b/tests/baselines/reference/VariableDeclaration9_es6.types new file mode 100644 index 0000000000000..6b29a04281b58 --- /dev/null +++ b/tests/baselines/reference/VariableDeclaration9_es6.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration9_es6.ts === +let a: number +>a : number + diff --git a/tests/baselines/reference/constDeclarations-errors.js b/tests/baselines/reference/constDeclarations-errors.js index 2947593b01d53..a9564e266a014 100644 --- a/tests/baselines/reference/constDeclarations-errors.js +++ b/tests/baselines/reference/constDeclarations-errors.js @@ -23,7 +23,7 @@ const c1; const c2; const c3, c4, c5, c6; // error, missing initialicer // error, can not be unintalized -for (var c in {}) { } +for (const c in {}) { } // error, assigning to a const for (const c8 = 0; c8 < 1; c8++) { } // error, can not be unintalized diff --git a/tests/baselines/reference/constDeclarations-es5.errors.txt b/tests/baselines/reference/constDeclarations-es5.errors.txt deleted file mode 100644 index d15535349ace0..0000000000000 --- a/tests/baselines/reference/constDeclarations-es5.errors.txt +++ /dev/null @@ -1,17 +0,0 @@ -tests/cases/compiler/constDeclarations-es5.ts(2,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/constDeclarations-es5.ts(3,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/constDeclarations-es5.ts(4,1): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. - - -==== tests/cases/compiler/constDeclarations-es5.ts (3 errors) ==== - - const z7 = false; - ~~~~~ -!!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. - const z8: number = 23; - ~~~~~ -!!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. - const z9 = 0, z10 :string = "", z11 = null; - ~~~~~ -!!! error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. - \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-es5.js b/tests/baselines/reference/constDeclarations-es5.js index 20deb9dca371d..736260ad10251 100644 --- a/tests/baselines/reference/constDeclarations-es5.js +++ b/tests/baselines/reference/constDeclarations-es5.js @@ -6,6 +6,6 @@ const z9 = 0, z10 :string = "", z11 = null; //// [constDeclarations-es5.js] -const z7 = false; -const z8 = 23; -const z9 = 0, z10 = "", z11 = null; +var z7 = false; +var z8 = 23; +var z9 = 0, z10 = "", z11 = null; diff --git a/tests/baselines/reference/constDeclarations-es5.types b/tests/baselines/reference/constDeclarations-es5.types new file mode 100644 index 0000000000000..be55dc0febcfe --- /dev/null +++ b/tests/baselines/reference/constDeclarations-es5.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/constDeclarations-es5.ts === + +const z7 = false; +>z7 : boolean + +const z8: number = 23; +>z8 : number + +const z9 = 0, z10 :string = "", z11 = null; +>z9 : number +>z10 : string +>z11 : any + diff --git a/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline b/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline index 8dc9355bca27c..9e2e9978f469d 100644 --- a/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithEarlySyntacticErrors.baseline @@ -1,5 +1,5 @@ EmitSkipped: false FileName : tests/cases/fourslash/inputFile1.js // File contains early errors. All outputs should be skipped. -const uninitialized_const_error; +var uninitialized_const_error; diff --git a/tests/baselines/reference/letAsIdentifierInStrictMode.js b/tests/baselines/reference/letAsIdentifierInStrictMode.js index e844bc1d1dcae..ccf099bcfc4ba 100644 --- a/tests/baselines/reference/letAsIdentifierInStrictMode.js +++ b/tests/baselines/reference/letAsIdentifierInStrictMode.js @@ -9,9 +9,9 @@ a; //// [letAsIdentifierInStrictMode.js] "use strict"; var ; -let ; +var ; 10; var a = 10; -let ; +var ; 30; -let a; +var a; diff --git a/tests/baselines/reference/letDeclarations-es5-1.errors.txt b/tests/baselines/reference/letDeclarations-es5-1.errors.txt deleted file mode 100644 index f8b5cf629d26d..0000000000000 --- a/tests/baselines/reference/letDeclarations-es5-1.errors.txt +++ /dev/null @@ -1,27 +0,0 @@ -tests/cases/compiler/letDeclarations-es5-1.ts(1,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5-1.ts(2,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5-1.ts(3,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5-1.ts(4,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5-1.ts(5,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5-1.ts(6,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. - - -==== tests/cases/compiler/letDeclarations-es5-1.ts (6 errors) ==== - let l1; - ~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. - let l2: number; - ~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. - let l3, l4, l5 :string, l6; - ~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. - let l7 = false; - ~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. - let l8: number = 23; - ~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. - let l9 = 0, l10 :string = "", l11 = null; - ~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-es5-1.js b/tests/baselines/reference/letDeclarations-es5-1.js index 24c2c62e58fa7..35439c5966d0c 100644 --- a/tests/baselines/reference/letDeclarations-es5-1.js +++ b/tests/baselines/reference/letDeclarations-es5-1.js @@ -7,9 +7,9 @@ let l9 = 0, l10 :string = "", l11 = null; //// [letDeclarations-es5-1.js] -let l1; -let l2; -let l3, l4, l5, l6; -let l7 = false; -let l8 = 23; -let l9 = 0, l10 = "", l11 = null; +var l1; +var l2; +var l3, l4, l5, l6; +var l7 = false; +var l8 = 23; +var l9 = 0, l10 = "", l11 = null; diff --git a/tests/baselines/reference/letDeclarations-es5-1.types b/tests/baselines/reference/letDeclarations-es5-1.types new file mode 100644 index 0000000000000..fb45d521bd358 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-es5-1.types @@ -0,0 +1,24 @@ +=== tests/cases/compiler/letDeclarations-es5-1.ts === + let l1; +>l1 : any + + let l2: number; +>l2 : number + + let l3, l4, l5 :string, l6; +>l3 : any +>l4 : any +>l5 : string +>l6 : any + + let l7 = false; +>l7 : boolean + + let l8: number = 23; +>l8 : number + + let l9 = 0, l10 :string = "", l11 = null; +>l9 : number +>l10 : string +>l11 : any + diff --git a/tests/baselines/reference/letDeclarations-es5.errors.txt b/tests/baselines/reference/letDeclarations-es5.errors.txt deleted file mode 100644 index 27d526f03eae7..0000000000000 --- a/tests/baselines/reference/letDeclarations-es5.errors.txt +++ /dev/null @@ -1,40 +0,0 @@ -tests/cases/compiler/letDeclarations-es5.ts(2,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(3,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(4,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(6,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(7,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(8,1): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(10,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(12,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. - - -==== tests/cases/compiler/letDeclarations-es5.ts (8 errors) ==== - - let l1; - ~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. - let l2: number; - ~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. - let l3, l4, l5 :string, l6; - ~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. - - let l7 = false; - ~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. - let l8: number = 23; - ~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. - let l9 = 0, l10 :string = "", l11 = null; - ~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. - - for(let l11 in {}) { } - ~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. - - for(let l12 = 0; l12 < 9; l12++) { } - ~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. - \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-es5.js b/tests/baselines/reference/letDeclarations-es5.js index 4d2f5423ee0bd..4260e8d57581d 100644 --- a/tests/baselines/reference/letDeclarations-es5.js +++ b/tests/baselines/reference/letDeclarations-es5.js @@ -14,11 +14,11 @@ for(let l12 = 0; l12 < 9; l12++) { } //// [letDeclarations-es5.js] -let l1; -let l2; -let l3, l4, l5, l6; -let l7 = false; -let l8 = 23; -let l9 = 0, l10 = "", l11 = null; -for (let l11 in {}) { } -for (let l12 = 0; l12 < 9; l12++) { } +var l1; +var l2; +var l3, l4, l5, l6; +var l7 = false; +var l8 = 23; +var l9 = 0, l10 = "", l11 = null; +for (var _l11 = void 0 in {}) { } +for (var l12 = 0; l12 < 9; l12++) { } diff --git a/tests/baselines/reference/letDeclarations-es5.types b/tests/baselines/reference/letDeclarations-es5.types new file mode 100644 index 0000000000000..0d6e992886848 --- /dev/null +++ b/tests/baselines/reference/letDeclarations-es5.types @@ -0,0 +1,36 @@ +=== tests/cases/compiler/letDeclarations-es5.ts === + +let l1; +>l1 : any + +let l2: number; +>l2 : number + +let l3, l4, l5 :string, l6; +>l3 : any +>l4 : any +>l5 : string +>l6 : any + +let l7 = false; +>l7 : boolean + +let l8: number = 23; +>l8 : number + +let l9 = 0, l10 :string = "", l11 = null; +>l9 : number +>l10 : string +>l11 : any + +for(let l11 in {}) { } +>l11 : any +>{} : {} + +for(let l12 = 0; l12 < 9; l12++) { } +>l12 : number +>l12 < 9 : boolean +>l12 : number +>l12++ : number +>l12 : number + diff --git a/tests/baselines/reference/restElementWithInitializer2.js b/tests/baselines/reference/restElementWithInitializer2.js index 8874f6a83d0a7..06f3985e3e58a 100644 --- a/tests/baselines/reference/restElementWithInitializer2.js +++ b/tests/baselines/reference/restElementWithInitializer2.js @@ -7,4 +7,4 @@ var x: number[]; //// [restElementWithInitializer2.js] var a; var x; -x = a = a.slice(0); // Error, rest element cannot have initializer +; // Error, rest element cannot have initializer diff --git a/tests/baselines/reference/shadowingViaLocalValue.errors.txt b/tests/baselines/reference/shadowingViaLocalValue.errors.txt index 2a585ba8b7d1d..3632ac77eba30 100644 --- a/tests/baselines/reference/shadowingViaLocalValue.errors.txt +++ b/tests/baselines/reference/shadowingViaLocalValue.errors.txt @@ -1,14 +1,10 @@ -tests/cases/compiler/shadowingViaLocalValue.ts(2,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. tests/cases/compiler/shadowingViaLocalValue.ts(4,13): error TS4090: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'. -tests/cases/compiler/shadowingViaLocalValue.ts(9,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. tests/cases/compiler/shadowingViaLocalValue.ts(11,18): error TS4090: Cannot initialize outer scoped variable 'x1' in the same scope as block scoped declaration 'x1'. -==== tests/cases/compiler/shadowingViaLocalValue.ts (4 errors) ==== +==== tests/cases/compiler/shadowingViaLocalValue.ts (2 errors) ==== { let x; - ~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. { var x = 1; ~ @@ -18,8 +14,6 @@ tests/cases/compiler/shadowingViaLocalValue.ts(11,18): error TS4090: Cannot init { let x1; - ~~~ -!!! error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. { for (var x1 = 0; ;); ~~ diff --git a/tests/baselines/reference/shadowingViaLocalValue.js b/tests/baselines/reference/shadowingViaLocalValue.js index f99a209f0deda..389b106fdd9e6 100644 --- a/tests/baselines/reference/shadowingViaLocalValue.js +++ b/tests/baselines/reference/shadowingViaLocalValue.js @@ -17,13 +17,13 @@ //// [shadowingViaLocalValue.js] { - let x; + var _x = void 0; { var x = 1; } } { - let x1; + var _x1 = void 0; { for (var x1 = 0;;) ; From 393b95ed0e335f63365b6fcb00f1f962781f97da Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 17 Feb 2015 16:25:38 -0800 Subject: [PATCH 07/18] accepted baselines --- tests/baselines/reference/APISample_compile.js | 2 +- tests/baselines/reference/APISample_compile.types | 4 ++-- tests/baselines/reference/APISample_linter.js | 2 +- tests/baselines/reference/APISample_linter.types | 4 ++-- tests/baselines/reference/APISample_transform.js | 2 +- tests/baselines/reference/APISample_transform.types | 4 ++-- tests/baselines/reference/APISample_watcher.js | 2 +- tests/baselines/reference/APISample_watcher.types | 4 ++-- tests/baselines/reference/letDeclarations-es5.js | 2 +- tests/baselines/reference/restElementWithInitializer2.js | 2 +- tests/baselines/reference/shadowingViaLocalValue.js | 4 ++-- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 1dbf40e48fac9..2b8be90024bf1 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -997,7 +997,7 @@ declare module "typescript" { SuperStatic = 32, ContextChecked = 64, EnumValuesComputed = 128, - BlockScopedBindingCapturedInLoop = 256, + BlockScopedBindingInLoop = 256, } interface NodeLinks { resolvedType?: Type; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 09344976ba69d..068d2549a7a19 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -3218,8 +3218,8 @@ declare module "typescript" { EnumValuesComputed = 128, >EnumValuesComputed : NodeCheckFlags - BlockScopedBindingCapturedInLoop = 256, ->BlockScopedBindingCapturedInLoop : NodeCheckFlags + BlockScopedBindingInLoop = 256, +>BlockScopedBindingInLoop : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index fd097517f275c..33cc9edfaf8d8 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -1028,7 +1028,7 @@ declare module "typescript" { SuperStatic = 32, ContextChecked = 64, EnumValuesComputed = 128, - BlockScopedBindingCapturedInLoop = 256, + BlockScopedBindingInLoop = 256, } interface NodeLinks { resolvedType?: Type; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index f68e06fdde7b1..4202e57c2a3a9 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -3362,8 +3362,8 @@ declare module "typescript" { EnumValuesComputed = 128, >EnumValuesComputed : NodeCheckFlags - BlockScopedBindingCapturedInLoop = 256, ->BlockScopedBindingCapturedInLoop : NodeCheckFlags + BlockScopedBindingInLoop = 256, +>BlockScopedBindingInLoop : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index d523f2920edf2..16a1fb7bd2055 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -1029,7 +1029,7 @@ declare module "typescript" { SuperStatic = 32, ContextChecked = 64, EnumValuesComputed = 128, - BlockScopedBindingCapturedInLoop = 256, + BlockScopedBindingInLoop = 256, } interface NodeLinks { resolvedType?: Type; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index a51cfb586db6f..d909293ae7eb9 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -3314,8 +3314,8 @@ declare module "typescript" { EnumValuesComputed = 128, >EnumValuesComputed : NodeCheckFlags - BlockScopedBindingCapturedInLoop = 256, ->BlockScopedBindingCapturedInLoop : NodeCheckFlags + BlockScopedBindingInLoop = 256, +>BlockScopedBindingInLoop : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 58b6dfbbe5d41..41d5fdcbe0f49 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -1066,7 +1066,7 @@ declare module "typescript" { SuperStatic = 32, ContextChecked = 64, EnumValuesComputed = 128, - BlockScopedBindingCapturedInLoop = 256, + BlockScopedBindingInLoop = 256, } interface NodeLinks { resolvedType?: Type; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 5ec5d51f99dbd..f8a1c2f6ebf2d 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -3487,8 +3487,8 @@ declare module "typescript" { EnumValuesComputed = 128, >EnumValuesComputed : NodeCheckFlags - BlockScopedBindingCapturedInLoop = 256, ->BlockScopedBindingCapturedInLoop : NodeCheckFlags + BlockScopedBindingInLoop = 256, +>BlockScopedBindingInLoop : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks diff --git a/tests/baselines/reference/letDeclarations-es5.js b/tests/baselines/reference/letDeclarations-es5.js index 4260e8d57581d..4ad43d52f769d 100644 --- a/tests/baselines/reference/letDeclarations-es5.js +++ b/tests/baselines/reference/letDeclarations-es5.js @@ -20,5 +20,5 @@ var l3, l4, l5, l6; var l7 = false; var l8 = 23; var l9 = 0, l10 = "", l11 = null; -for (var _l11 = void 0 in {}) { } +for (var _l11 in {}) { } for (var l12 = 0; l12 < 9; l12++) { } diff --git a/tests/baselines/reference/restElementWithInitializer2.js b/tests/baselines/reference/restElementWithInitializer2.js index 06f3985e3e58a..8874f6a83d0a7 100644 --- a/tests/baselines/reference/restElementWithInitializer2.js +++ b/tests/baselines/reference/restElementWithInitializer2.js @@ -7,4 +7,4 @@ var x: number[]; //// [restElementWithInitializer2.js] var a; var x; -; // Error, rest element cannot have initializer +x = a = a.slice(0); // Error, rest element cannot have initializer diff --git a/tests/baselines/reference/shadowingViaLocalValue.js b/tests/baselines/reference/shadowingViaLocalValue.js index 389b106fdd9e6..e788caf5720c1 100644 --- a/tests/baselines/reference/shadowingViaLocalValue.js +++ b/tests/baselines/reference/shadowingViaLocalValue.js @@ -17,13 +17,13 @@ //// [shadowingViaLocalValue.js] { - var _x = void 0; + var _x; { var x = 1; } } { - var _x1 = void 0; + var _x1; { for (var x1 = 0;;) ; From e6cfc10acc90ccaf5072f0e0fd620ba2652190f1 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 17 Feb 2015 16:26:32 -0800 Subject: [PATCH 08/18] added missing files --- src/compiler/checker.ts | 11 +++++------ src/compiler/emitter.ts | 43 +++++++++++++++++++++++++++++------------ src/compiler/types.ts | 2 +- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 211331579cdeb..748be3648ec53 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4939,15 +4939,14 @@ module ts { current = current.parent; } - if (!inFunction) { - return; - } - var current: Node = container; while (current && !isNameScopeBoundary(current)) { if (isIterationStatement(current, /*lookInLabeledStatements*/ false)) { - getNodeLinks(current).flags |= NodeCheckFlags.BlockScopedBindingCapturedInLoop; - grammarErrorOnFirstToken(current, Diagnostics.Code_in_the_loop_captures_block_scoped_variable_0_in_closure_This_is_natively_supported_in_ECMAScript_6_or_higher, declarationNameToString(node)); + if (inFunction) { + getNodeLinks(current).flags |= NodeCheckFlags.BlockScopedBindingInLoop; + grammarErrorOnFirstToken(current, Diagnostics.Code_in_the_loop_captures_block_scoped_variable_0_in_closure_This_is_natively_supported_in_ECMAScript_6_or_higher, declarationNameToString(node)); + } + getNodeLinks(symbol.valueDeclaration).flags |= NodeCheckFlags.BlockScopedBindingInLoop; break; } current = current.parent; diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 638b78812cc34..2808b561256a3 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3282,7 +3282,7 @@ module ts { emitDestructuringAssignment(e, createElementAccess(value, createNumericLiteral(i))); } else { - if (i === elements.length - 1 && (e).expression.kind === SyntaxKind.Identifier) { + if (i === elements.length - 1) { value = ensureIdentifier(value); emitAssignment((e).expression, value); write(".slice(" + i + ")"); @@ -3384,12 +3384,23 @@ module ts { } } else { - var initializeToDefault = renameNonTopLevelLetAndConst(node.name); + var isLet = renameNonTopLevelLetAndConst(node.name); emitModuleMemberName(node); - var initializer = - node.initializer || - (initializeToDefault && createVoidZero()); + var initializer = node.initializer; + if (!initializer) { + // 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 + var initializer = + languageVersion < ScriptTarget.ES6 && + (resolver.getNodeCheckFlags(node) & NodeCheckFlags.BlockScopedBindingInLoop) && + (getCombinedFlagsForIdentifier(node.name) & NodeFlags.Let) && + createVoidZero(); + } emitOptional(" = ", initializer); } @@ -3422,29 +3433,39 @@ module ts { } } - function renameNonTopLevelLetAndConst(node: Node): boolean { + 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 renameNonTopLevelLetAndConst(node: Node): void { // do not rename if // - language version is ES6+ // - node is synthesized (does not have a parent) + // - node is not identifier (can happen when tree is malformed) // - node is definitely not name of variable declaration. // it still can be part of parameter declaration, this check will be done next if (languageVersion >= ScriptTarget.ES6 || !node.parent || + node.kind !== SyntaxKind.Identifier || (node.parent.kind !== SyntaxKind.VariableDeclaration && node.parent.kind !== SyntaxKind.BindingElement)) { - return false; + return; } - var combinedFlags = getCombinedNodeFlags(node.parent); + var combinedFlags = getCombinedFlagsForIdentifier(node); if (((combinedFlags & NodeFlags.BlockScoped) === 0) || combinedFlags & NodeFlags.Export) { // do not rename exported or non-block scoped variables - return false; + return; } // here it is known that node is a block scoped variable var list = getAncestor(node, SyntaxKind.VariableDeclarationList); if (list.parent.kind === SyntaxKind.VariableStatement && list.parent.parent.kind === SyntaxKind.SourceFile) { // do not rename variables that are defined on source file level - return false; + return; } var generatedName = makeUniqueName(getEnclosingBlockScopeContainer(node), (node).text); @@ -3453,8 +3474,6 @@ module ts { generatedBlockScopeNames = []; } generatedBlockScopeNames[symbolId] = generatedName; - - return (combinedFlags & NodeFlags.Let) !== 0; } function emitVariableStatement(node: VariableStatement) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 940a4a6e5a41c..9c7c794d00279 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1262,7 +1262,7 @@ module ts { // Values for enum members have been computed, and any errors have been reported for them. EnumValuesComputed = 0x00000080, - BlockScopedBindingCapturedInLoop = 0x00000100, + BlockScopedBindingInLoop = 0x00000100, } export interface NodeLinks { From b4c82c940197d13fee16e3a0039d41e5892aa726 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 17 Feb 2015 17:04:31 -0800 Subject: [PATCH 09/18] added tests, accepted baselines --- src/compiler/emitter.ts | 16 ++++++++-------- .../reference/VariableDeclaration10_es6.js | 2 +- .../reference/VariableDeclaration11_es6.js | 2 +- .../reference/VariableDeclaration1_es6.js | 2 +- .../reference/VariableDeclaration2_es6.js | 2 +- .../reference/VariableDeclaration3_es6.js | 2 +- .../reference/VariableDeclaration4_es6.js | 2 +- .../reference/VariableDeclaration5_es6.js | 2 +- .../reference/VariableDeclaration7_es6.js | 2 +- .../reference/VariableDeclaration8_es6.js | 2 +- .../reference/VariableDeclaration9_es6.js | 2 +- .../reference/downlevelLetConst1.errors.txt | 7 +++++++ tests/baselines/reference/downlevelLetConst1.js | 5 +++++ tests/baselines/reference/downlevelLetConst10.js | 5 +++++ .../reference/downlevelLetConst10.types | 4 ++++ .../reference/downlevelLetConst11.errors.txt | 8 ++++++++ tests/baselines/reference/downlevelLetConst11.js | 7 +++++++ .../reference/downlevelLetConst2.errors.txt | 7 +++++++ tests/baselines/reference/downlevelLetConst2.js | 5 +++++ tests/baselines/reference/downlevelLetConst3.js | 5 +++++ .../baselines/reference/downlevelLetConst3.types | 4 ++++ .../reference/downlevelLetConst4.errors.txt | 7 +++++++ tests/baselines/reference/downlevelLetConst4.js | 5 +++++ tests/baselines/reference/downlevelLetConst5.js | 5 +++++ .../baselines/reference/downlevelLetConst5.types | 4 ++++ .../reference/downlevelLetConst6.errors.txt | 7 +++++++ tests/baselines/reference/downlevelLetConst6.js | 5 +++++ tests/baselines/reference/downlevelLetConst7.js | 5 +++++ .../baselines/reference/downlevelLetConst7.types | 4 ++++ tests/baselines/reference/downlevelLetConst8.js | 5 +++++ .../baselines/reference/downlevelLetConst8.types | 4 ++++ tests/baselines/reference/downlevelLetConst9.js | 5 +++++ .../baselines/reference/downlevelLetConst9.types | 4 ++++ tests/cases/compiler/downlevelLetConst1.ts | 1 + tests/cases/compiler/downlevelLetConst10.ts | 1 + tests/cases/compiler/downlevelLetConst11.ts | 2 ++ tests/cases/compiler/downlevelLetConst2.ts | 1 + tests/cases/compiler/downlevelLetConst3.ts | 1 + tests/cases/compiler/downlevelLetConst4.ts | 1 + tests/cases/compiler/downlevelLetConst5.ts | 1 + tests/cases/compiler/downlevelLetConst6.ts | 1 + tests/cases/compiler/downlevelLetConst7.ts | 1 + tests/cases/compiler/downlevelLetConst8.ts | 1 + tests/cases/compiler/downlevelLetConst9.ts | 1 + .../VariableDeclaration10_es6.ts | 1 + .../VariableDeclaration11_es6.ts | 1 + .../VariableDeclaration1_es6.ts | 1 + .../VariableDeclaration2_es6.ts | 1 + .../VariableDeclaration3_es6.ts | 1 + .../VariableDeclaration4_es6.ts | 1 + .../VariableDeclaration5_es6.ts | 1 + .../VariableDeclaration6_es6.ts | 1 + .../VariableDeclaration7_es6.ts | 1 + .../VariableDeclaration8_es6.ts | 1 + .../VariableDeclaration9_es6.ts | 1 + 55 files changed, 158 insertions(+), 18 deletions(-) create mode 100644 tests/baselines/reference/downlevelLetConst1.errors.txt create mode 100644 tests/baselines/reference/downlevelLetConst1.js create mode 100644 tests/baselines/reference/downlevelLetConst10.js create mode 100644 tests/baselines/reference/downlevelLetConst10.types create mode 100644 tests/baselines/reference/downlevelLetConst11.errors.txt create mode 100644 tests/baselines/reference/downlevelLetConst11.js create mode 100644 tests/baselines/reference/downlevelLetConst2.errors.txt create mode 100644 tests/baselines/reference/downlevelLetConst2.js create mode 100644 tests/baselines/reference/downlevelLetConst3.js create mode 100644 tests/baselines/reference/downlevelLetConst3.types create mode 100644 tests/baselines/reference/downlevelLetConst4.errors.txt create mode 100644 tests/baselines/reference/downlevelLetConst4.js create mode 100644 tests/baselines/reference/downlevelLetConst5.js create mode 100644 tests/baselines/reference/downlevelLetConst5.types create mode 100644 tests/baselines/reference/downlevelLetConst6.errors.txt create mode 100644 tests/baselines/reference/downlevelLetConst6.js create mode 100644 tests/baselines/reference/downlevelLetConst7.js create mode 100644 tests/baselines/reference/downlevelLetConst7.types create mode 100644 tests/baselines/reference/downlevelLetConst8.js create mode 100644 tests/baselines/reference/downlevelLetConst8.types create mode 100644 tests/baselines/reference/downlevelLetConst9.js create mode 100644 tests/baselines/reference/downlevelLetConst9.types create mode 100644 tests/cases/compiler/downlevelLetConst1.ts create mode 100644 tests/cases/compiler/downlevelLetConst10.ts create mode 100644 tests/cases/compiler/downlevelLetConst11.ts create mode 100644 tests/cases/compiler/downlevelLetConst2.ts create mode 100644 tests/cases/compiler/downlevelLetConst3.ts create mode 100644 tests/cases/compiler/downlevelLetConst4.ts create mode 100644 tests/cases/compiler/downlevelLetConst5.ts create mode 100644 tests/cases/compiler/downlevelLetConst6.ts create mode 100644 tests/cases/compiler/downlevelLetConst7.ts create mode 100644 tests/cases/compiler/downlevelLetConst8.ts create mode 100644 tests/cases/compiler/downlevelLetConst9.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 2808b561256a3..ad0f76621b058 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1639,7 +1639,7 @@ module ts { writeEmittedFiles(writer.getText(), /*writeByteOrderMark*/ compilerOptions.emitBOM); return; - function enterScope(): boolean { + function enterNameScope(): boolean { var names = currentScopeNames; currentScopeNames = undefined; if (names) { @@ -1649,7 +1649,7 @@ module ts { return false; } - function exitScope(popFrame: boolean): void { + function exitNameScope(popFrame: boolean): void { if (popFrame) { currentScopeNames = lastFrame.names; lastFrame = lastFrame.previous; @@ -3649,7 +3649,7 @@ module ts { tempVariables = undefined; tempParameters = undefined; - var popFrame = enterScope() + var popFrame = enterNameScope() // When targeting ES6, emit arrow function natively in ES6 if (shouldEmitAsArrowFunction(node)) { @@ -3743,7 +3743,7 @@ module ts { write(";"); } - exitScope(popFrame); + exitNameScope(popFrame); tempCount = saveTempCount; tempVariables = saveTempVariables; @@ -3956,7 +3956,7 @@ module ts { tempVariables = undefined; tempParameters = undefined; - var popFrame = enterScope(); + var popFrame = enterNameScope(); // Emit the constructor overload pinned comments forEach(node.members, member => { @@ -4019,7 +4019,7 @@ module ts { emitTrailingComments(ctor); } - exitScope(popFrame); + exitNameScope(popFrame); tempCount = saveTempCount; tempVariables = saveTempVariables; @@ -4150,11 +4150,11 @@ module ts { var saveTempVariables = tempVariables; tempCount = 0; tempVariables = undefined; - var popFrame = enterScope(); + var popFrame = enterNameScope(); emit(node.body); - exitScope(popFrame); + exitNameScope(popFrame); tempCount = saveTempCount; tempVariables = saveTempVariables; } diff --git a/tests/baselines/reference/VariableDeclaration10_es6.js b/tests/baselines/reference/VariableDeclaration10_es6.js index 6edba42ab0df0..14f47cea04dfe 100644 --- a/tests/baselines/reference/VariableDeclaration10_es6.js +++ b/tests/baselines/reference/VariableDeclaration10_es6.js @@ -2,4 +2,4 @@ let a: number = 1 //// [VariableDeclaration10_es6.js] -var a = 1; +let a = 1; diff --git a/tests/baselines/reference/VariableDeclaration11_es6.js b/tests/baselines/reference/VariableDeclaration11_es6.js index 0000d5cb5ab78..83eec6d9a13ae 100644 --- a/tests/baselines/reference/VariableDeclaration11_es6.js +++ b/tests/baselines/reference/VariableDeclaration11_es6.js @@ -4,4 +4,4 @@ let //// [VariableDeclaration11_es6.js] "use strict"; -var ; +let ; diff --git a/tests/baselines/reference/VariableDeclaration1_es6.js b/tests/baselines/reference/VariableDeclaration1_es6.js index a867d74726c7c..26433bd88c3dd 100644 --- a/tests/baselines/reference/VariableDeclaration1_es6.js +++ b/tests/baselines/reference/VariableDeclaration1_es6.js @@ -2,4 +2,4 @@ const //// [VariableDeclaration1_es6.js] -var ; +const ; diff --git a/tests/baselines/reference/VariableDeclaration2_es6.js b/tests/baselines/reference/VariableDeclaration2_es6.js index d835435a0a62a..a955315a2f02c 100644 --- a/tests/baselines/reference/VariableDeclaration2_es6.js +++ b/tests/baselines/reference/VariableDeclaration2_es6.js @@ -2,4 +2,4 @@ const a //// [VariableDeclaration2_es6.js] -var a; +const a; diff --git a/tests/baselines/reference/VariableDeclaration3_es6.js b/tests/baselines/reference/VariableDeclaration3_es6.js index 08513b8bdbce7..4be8a3daf381f 100644 --- a/tests/baselines/reference/VariableDeclaration3_es6.js +++ b/tests/baselines/reference/VariableDeclaration3_es6.js @@ -2,4 +2,4 @@ const a = 1 //// [VariableDeclaration3_es6.js] -var a = 1; +const a = 1; diff --git a/tests/baselines/reference/VariableDeclaration4_es6.js b/tests/baselines/reference/VariableDeclaration4_es6.js index f0a8331acfebc..7a9934e052bfb 100644 --- a/tests/baselines/reference/VariableDeclaration4_es6.js +++ b/tests/baselines/reference/VariableDeclaration4_es6.js @@ -2,4 +2,4 @@ const a: number //// [VariableDeclaration4_es6.js] -var a; +const a; diff --git a/tests/baselines/reference/VariableDeclaration5_es6.js b/tests/baselines/reference/VariableDeclaration5_es6.js index 98ae1af002e2d..e6a3c175651df 100644 --- a/tests/baselines/reference/VariableDeclaration5_es6.js +++ b/tests/baselines/reference/VariableDeclaration5_es6.js @@ -2,4 +2,4 @@ const a: number = 1 //// [VariableDeclaration5_es6.js] -var a = 1; +const a = 1; diff --git a/tests/baselines/reference/VariableDeclaration7_es6.js b/tests/baselines/reference/VariableDeclaration7_es6.js index 4287d79a7e45a..00ab95503a62e 100644 --- a/tests/baselines/reference/VariableDeclaration7_es6.js +++ b/tests/baselines/reference/VariableDeclaration7_es6.js @@ -2,4 +2,4 @@ let a //// [VariableDeclaration7_es6.js] -var a; +let a; diff --git a/tests/baselines/reference/VariableDeclaration8_es6.js b/tests/baselines/reference/VariableDeclaration8_es6.js index 4b4dd061bff03..9178871ef65e3 100644 --- a/tests/baselines/reference/VariableDeclaration8_es6.js +++ b/tests/baselines/reference/VariableDeclaration8_es6.js @@ -2,4 +2,4 @@ let a = 1 //// [VariableDeclaration8_es6.js] -var a = 1; +let a = 1; diff --git a/tests/baselines/reference/VariableDeclaration9_es6.js b/tests/baselines/reference/VariableDeclaration9_es6.js index 9ecfc40edff0a..b22c5691eb29d 100644 --- a/tests/baselines/reference/VariableDeclaration9_es6.js +++ b/tests/baselines/reference/VariableDeclaration9_es6.js @@ -2,4 +2,4 @@ let a: number //// [VariableDeclaration9_es6.js] -var a; +let a; diff --git a/tests/baselines/reference/downlevelLetConst1.errors.txt b/tests/baselines/reference/downlevelLetConst1.errors.txt new file mode 100644 index 0000000000000..a46d1973e04fc --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst1.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/downlevelLetConst1.ts(1,6): error TS1123: Variable declaration list cannot be empty. + + +==== tests/cases/compiler/downlevelLetConst1.ts (1 errors) ==== + const + +!!! error TS1123: Variable declaration list cannot be empty. \ No newline at end of file diff --git a/tests/baselines/reference/downlevelLetConst1.js b/tests/baselines/reference/downlevelLetConst1.js new file mode 100644 index 0000000000000..3463c1003249e --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst1.js @@ -0,0 +1,5 @@ +//// [downlevelLetConst1.ts] +const + +//// [downlevelLetConst1.js] +var ; diff --git a/tests/baselines/reference/downlevelLetConst10.js b/tests/baselines/reference/downlevelLetConst10.js new file mode 100644 index 0000000000000..8beb79b04b445 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst10.js @@ -0,0 +1,5 @@ +//// [downlevelLetConst10.ts] +let a: number = 1 + +//// [downlevelLetConst10.js] +var a = 1; diff --git a/tests/baselines/reference/downlevelLetConst10.types b/tests/baselines/reference/downlevelLetConst10.types new file mode 100644 index 0000000000000..05fe302945586 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst10.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/downlevelLetConst10.ts === +let a: number = 1 +>a : number + diff --git a/tests/baselines/reference/downlevelLetConst11.errors.txt b/tests/baselines/reference/downlevelLetConst11.errors.txt new file mode 100644 index 0000000000000..42449bd3c8a34 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst11.errors.txt @@ -0,0 +1,8 @@ +tests/cases/compiler/downlevelLetConst11.ts(2,4): error TS1123: Variable declaration list cannot be empty. + + +==== tests/cases/compiler/downlevelLetConst11.ts (1 errors) ==== + "use strict"; + let + +!!! error TS1123: Variable declaration list cannot be empty. \ No newline at end of file diff --git a/tests/baselines/reference/downlevelLetConst11.js b/tests/baselines/reference/downlevelLetConst11.js new file mode 100644 index 0000000000000..377c7e6a9ed4a --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst11.js @@ -0,0 +1,7 @@ +//// [downlevelLetConst11.ts] +"use strict"; +let + +//// [downlevelLetConst11.js] +"use strict"; +var ; diff --git a/tests/baselines/reference/downlevelLetConst2.errors.txt b/tests/baselines/reference/downlevelLetConst2.errors.txt new file mode 100644 index 0000000000000..9da0c94a12e3d --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst2.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/downlevelLetConst2.ts(1,7): error TS1155: 'const' declarations must be initialized + + +==== tests/cases/compiler/downlevelLetConst2.ts (1 errors) ==== + const a + ~ +!!! error TS1155: 'const' declarations must be initialized \ No newline at end of file diff --git a/tests/baselines/reference/downlevelLetConst2.js b/tests/baselines/reference/downlevelLetConst2.js new file mode 100644 index 0000000000000..a73688cd4afd6 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst2.js @@ -0,0 +1,5 @@ +//// [downlevelLetConst2.ts] +const a + +//// [downlevelLetConst2.js] +var a; diff --git a/tests/baselines/reference/downlevelLetConst3.js b/tests/baselines/reference/downlevelLetConst3.js new file mode 100644 index 0000000000000..f6ef605c261dc --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst3.js @@ -0,0 +1,5 @@ +//// [downlevelLetConst3.ts] +const a = 1 + +//// [downlevelLetConst3.js] +var a = 1; diff --git a/tests/baselines/reference/downlevelLetConst3.types b/tests/baselines/reference/downlevelLetConst3.types new file mode 100644 index 0000000000000..6cd3f85e074d4 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst3.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/downlevelLetConst3.ts === +const a = 1 +>a : number + diff --git a/tests/baselines/reference/downlevelLetConst4.errors.txt b/tests/baselines/reference/downlevelLetConst4.errors.txt new file mode 100644 index 0000000000000..3bf3e58ceccda --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst4.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/downlevelLetConst4.ts(1,7): error TS1155: 'const' declarations must be initialized + + +==== tests/cases/compiler/downlevelLetConst4.ts (1 errors) ==== + const a: number + ~ +!!! error TS1155: 'const' declarations must be initialized \ No newline at end of file diff --git a/tests/baselines/reference/downlevelLetConst4.js b/tests/baselines/reference/downlevelLetConst4.js new file mode 100644 index 0000000000000..725aa5cde8fbf --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst4.js @@ -0,0 +1,5 @@ +//// [downlevelLetConst4.ts] +const a: number + +//// [downlevelLetConst4.js] +var a; diff --git a/tests/baselines/reference/downlevelLetConst5.js b/tests/baselines/reference/downlevelLetConst5.js new file mode 100644 index 0000000000000..271c71b682922 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst5.js @@ -0,0 +1,5 @@ +//// [downlevelLetConst5.ts] +const a: number = 1 + +//// [downlevelLetConst5.js] +var a = 1; diff --git a/tests/baselines/reference/downlevelLetConst5.types b/tests/baselines/reference/downlevelLetConst5.types new file mode 100644 index 0000000000000..dd8cdf9fcddec --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst5.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/downlevelLetConst5.ts === +const a: number = 1 +>a : number + diff --git a/tests/baselines/reference/downlevelLetConst6.errors.txt b/tests/baselines/reference/downlevelLetConst6.errors.txt new file mode 100644 index 0000000000000..bad0674c5c412 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst6.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/downlevelLetConst6.ts(1,1): error TS2304: Cannot find name 'let'. + + +==== tests/cases/compiler/downlevelLetConst6.ts (1 errors) ==== + let + ~~~ +!!! error TS2304: Cannot find name 'let'. \ No newline at end of file diff --git a/tests/baselines/reference/downlevelLetConst6.js b/tests/baselines/reference/downlevelLetConst6.js new file mode 100644 index 0000000000000..2a1aea002d932 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst6.js @@ -0,0 +1,5 @@ +//// [downlevelLetConst6.ts] +let + +//// [downlevelLetConst6.js] +let; diff --git a/tests/baselines/reference/downlevelLetConst7.js b/tests/baselines/reference/downlevelLetConst7.js new file mode 100644 index 0000000000000..6020ddf247953 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst7.js @@ -0,0 +1,5 @@ +//// [downlevelLetConst7.ts] +let a + +//// [downlevelLetConst7.js] +var a; diff --git a/tests/baselines/reference/downlevelLetConst7.types b/tests/baselines/reference/downlevelLetConst7.types new file mode 100644 index 0000000000000..9c76479ecf50b --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst7.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/downlevelLetConst7.ts === +let a +>a : any + diff --git a/tests/baselines/reference/downlevelLetConst8.js b/tests/baselines/reference/downlevelLetConst8.js new file mode 100644 index 0000000000000..5cc548c1361a7 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst8.js @@ -0,0 +1,5 @@ +//// [downlevelLetConst8.ts] +let a = 1 + +//// [downlevelLetConst8.js] +var a = 1; diff --git a/tests/baselines/reference/downlevelLetConst8.types b/tests/baselines/reference/downlevelLetConst8.types new file mode 100644 index 0000000000000..a3b9986bbc857 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst8.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/downlevelLetConst8.ts === +let a = 1 +>a : number + diff --git a/tests/baselines/reference/downlevelLetConst9.js b/tests/baselines/reference/downlevelLetConst9.js new file mode 100644 index 0000000000000..c6bcfe27a8a26 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst9.js @@ -0,0 +1,5 @@ +//// [downlevelLetConst9.ts] +let a: number + +//// [downlevelLetConst9.js] +var a; diff --git a/tests/baselines/reference/downlevelLetConst9.types b/tests/baselines/reference/downlevelLetConst9.types new file mode 100644 index 0000000000000..cab9ac82a6058 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst9.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/downlevelLetConst9.ts === +let a: number +>a : number + diff --git a/tests/cases/compiler/downlevelLetConst1.ts b/tests/cases/compiler/downlevelLetConst1.ts new file mode 100644 index 0000000000000..8baacf4ea5443 --- /dev/null +++ b/tests/cases/compiler/downlevelLetConst1.ts @@ -0,0 +1 @@ +const \ No newline at end of file diff --git a/tests/cases/compiler/downlevelLetConst10.ts b/tests/cases/compiler/downlevelLetConst10.ts new file mode 100644 index 0000000000000..2b6e9657ef13f --- /dev/null +++ b/tests/cases/compiler/downlevelLetConst10.ts @@ -0,0 +1 @@ +let a: number = 1 \ No newline at end of file diff --git a/tests/cases/compiler/downlevelLetConst11.ts b/tests/cases/compiler/downlevelLetConst11.ts new file mode 100644 index 0000000000000..aca60708232d9 --- /dev/null +++ b/tests/cases/compiler/downlevelLetConst11.ts @@ -0,0 +1,2 @@ +"use strict"; +let \ No newline at end of file diff --git a/tests/cases/compiler/downlevelLetConst2.ts b/tests/cases/compiler/downlevelLetConst2.ts new file mode 100644 index 0000000000000..06871c9a45c00 --- /dev/null +++ b/tests/cases/compiler/downlevelLetConst2.ts @@ -0,0 +1 @@ +const a \ No newline at end of file diff --git a/tests/cases/compiler/downlevelLetConst3.ts b/tests/cases/compiler/downlevelLetConst3.ts new file mode 100644 index 0000000000000..6779cd775c017 --- /dev/null +++ b/tests/cases/compiler/downlevelLetConst3.ts @@ -0,0 +1 @@ +const a = 1 \ No newline at end of file diff --git a/tests/cases/compiler/downlevelLetConst4.ts b/tests/cases/compiler/downlevelLetConst4.ts new file mode 100644 index 0000000000000..f96229b7eaffa --- /dev/null +++ b/tests/cases/compiler/downlevelLetConst4.ts @@ -0,0 +1 @@ +const a: number \ No newline at end of file diff --git a/tests/cases/compiler/downlevelLetConst5.ts b/tests/cases/compiler/downlevelLetConst5.ts new file mode 100644 index 0000000000000..4a05e895a3cd4 --- /dev/null +++ b/tests/cases/compiler/downlevelLetConst5.ts @@ -0,0 +1 @@ +const a: number = 1 \ No newline at end of file diff --git a/tests/cases/compiler/downlevelLetConst6.ts b/tests/cases/compiler/downlevelLetConst6.ts new file mode 100644 index 0000000000000..33ae002d85961 --- /dev/null +++ b/tests/cases/compiler/downlevelLetConst6.ts @@ -0,0 +1 @@ +let \ No newline at end of file diff --git a/tests/cases/compiler/downlevelLetConst7.ts b/tests/cases/compiler/downlevelLetConst7.ts new file mode 100644 index 0000000000000..7350ac02e70c8 --- /dev/null +++ b/tests/cases/compiler/downlevelLetConst7.ts @@ -0,0 +1 @@ +let a \ No newline at end of file diff --git a/tests/cases/compiler/downlevelLetConst8.ts b/tests/cases/compiler/downlevelLetConst8.ts new file mode 100644 index 0000000000000..067c6699cfd7e --- /dev/null +++ b/tests/cases/compiler/downlevelLetConst8.ts @@ -0,0 +1 @@ +let a = 1 \ No newline at end of file diff --git a/tests/cases/compiler/downlevelLetConst9.ts b/tests/cases/compiler/downlevelLetConst9.ts new file mode 100644 index 0000000000000..aab3d49c18cc1 --- /dev/null +++ b/tests/cases/compiler/downlevelLetConst9.ts @@ -0,0 +1 @@ +let a: number \ No newline at end of file diff --git a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration10_es6.ts b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration10_es6.ts index 2b6e9657ef13f..9e02b6de034ae 100644 --- a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration10_es6.ts +++ b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration10_es6.ts @@ -1 +1,2 @@ +// @target:es6 let a: number = 1 \ No newline at end of file diff --git a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration11_es6.ts b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration11_es6.ts index aca60708232d9..0de0f085a8af3 100644 --- a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration11_es6.ts +++ b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration11_es6.ts @@ -1,2 +1,3 @@ +// @target:es6 "use strict"; let \ No newline at end of file diff --git a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration1_es6.ts b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration1_es6.ts index 8baacf4ea5443..27157193b2408 100644 --- a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration1_es6.ts +++ b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration1_es6.ts @@ -1 +1,2 @@ +// @target:es6 const \ No newline at end of file diff --git a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration2_es6.ts b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration2_es6.ts index 06871c9a45c00..17986424b1334 100644 --- a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration2_es6.ts +++ b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration2_es6.ts @@ -1 +1,2 @@ +// @target:es6 const a \ No newline at end of file diff --git a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration3_es6.ts b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration3_es6.ts index 6779cd775c017..cd1b75836e5c1 100644 --- a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration3_es6.ts +++ b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration3_es6.ts @@ -1 +1,2 @@ +// @target:es6 const a = 1 \ No newline at end of file diff --git a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration4_es6.ts b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration4_es6.ts index f96229b7eaffa..e40c7b152838d 100644 --- a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration4_es6.ts +++ b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration4_es6.ts @@ -1 +1,2 @@ +// @target:es6 const a: number \ No newline at end of file diff --git a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration5_es6.ts b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration5_es6.ts index 4a05e895a3cd4..52738ea2f07e4 100644 --- a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration5_es6.ts +++ b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration5_es6.ts @@ -1 +1,2 @@ +// @target:es6 const a: number = 1 \ No newline at end of file diff --git a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration6_es6.ts b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration6_es6.ts index 33ae002d85961..5fbd509be7615 100644 --- a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration6_es6.ts +++ b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration6_es6.ts @@ -1 +1,2 @@ +// @target:es6 let \ No newline at end of file diff --git a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration7_es6.ts b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration7_es6.ts index 7350ac02e70c8..14f4b4834131a 100644 --- a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration7_es6.ts +++ b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration7_es6.ts @@ -1 +1,2 @@ +// @target:es6 let a \ No newline at end of file diff --git a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration8_es6.ts b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration8_es6.ts index 067c6699cfd7e..2bab0e1a1a434 100644 --- a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration8_es6.ts +++ b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration8_es6.ts @@ -1 +1,2 @@ +// @target:es6 let a = 1 \ No newline at end of file diff --git a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration9_es6.ts b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration9_es6.ts index aab3d49c18cc1..db3cd38806a83 100644 --- a/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration9_es6.ts +++ b/tests/cases/conformance/es6/variableDeclarations/VariableDeclaration9_es6.ts @@ -1 +1,2 @@ +// @target:es6 let a: number \ No newline at end of file From 88911284269b7d7e3eb269b3a61f0a67197e35ed Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 24 Feb 2015 23:36:02 -0800 Subject: [PATCH 10/18] moved name generation logic to utilities --- src/compiler/checker.ts | 21 ++----------- src/compiler/emitter.ts | 66 +++++++++++++++++++++++---------------- src/compiler/utilities.ts | 23 ++++++++++++++ 3 files changed, 64 insertions(+), 46 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a9891eb0bdeed..68e8843764755 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10515,25 +10515,8 @@ module ts { } function makeUniqueName(baseName: string): string { - // First try '_name' - if (baseName.charCodeAt(0) !== CharacterCodes._) { - var baseName = "_" + baseName; - if (!isExistingName(baseName)) { - return generatedNames[baseName] = baseName; - } - } - // Find the first unique '_name_n', where n is a positive number - if (baseName.charCodeAt(baseName.length - 1) !== CharacterCodes._) { - baseName += "_"; - } - var i = 1; - while (true) { - name = baseName + i; - if (!isExistingName(name)) { - return generatedNames[name] = name; - } - i++; - } + var name = generateUniqueName(baseName, isExistingName); + return generatedNames[name] = name; } function assignGeneratedName(node: Node, name: string) { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 43422b4bb3099..9bfc14caaa0b4 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -38,6 +38,11 @@ module ts { previous: ScopeFrame; } + interface NameLookup { + setLocation(location: Node): void; + isExistingName(name: string): boolean; + } + type GetSymbolAccessibilityDiagnostic = (symbolAccesibilityResult: SymbolAccessiblityResult) => SymbolAccessibilityDiagnostic; interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter { @@ -1535,6 +1540,7 @@ module ts { var sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap ? [] : undefined; var diagnostics: Diagnostic[] = []; var newLine = host.getNewLine(); + var nameLookup: NameLookup; if (targetSourceFile === undefined) { forEach(host.getSourceFiles(), sourceFile => { @@ -1677,34 +1683,37 @@ module ts { } } - function makeUniqueName(location: Node, baseName: string): string { - if (!isExistingName(location, baseName)) { - // use current name as is - return setGeneratedName(baseName); + function createNameLookup(): NameLookup { + var location: Node; + return { + setLocation, + isExistingName: checkName } - // First try '_name' - if (baseName.charCodeAt(0) !== CharacterCodes._) { - var baseName = "_" + baseName; - if (!isExistingName(location, baseName)) { - return setGeneratedName(baseName); - } + function setLocation(l: Node): void { + location = l; } - // Find the first unique '_name_n', where n is a positive number - if (baseName.charCodeAt(baseName.length - 1) !== CharacterCodes._) { - baseName += "_"; + + function checkName(name: string): boolean { + Debug.assert(location !== undefined); + return isExistingName(location, name); } - var i = 1; - while (true) { - name = baseName + i; - if (!isExistingName(location, name)) { - return setGeneratedName(name); + } + + function makeUniqueName(location: Node, baseName: string): string { + var name: string + if (!isExistingName(location, baseName)) { + name = baseName; + } + else { + if (!nameLookup) { + nameLookup = createNameLookup(); } - i++; + nameLookup.setLocation(location); + name = generateUniqueName(baseName, nameLookup.isExistingName); + nameLookup.setLocation(undefined); } - } - function setGeneratedName(name: string): string { if (!currentScopeNames) { currentScopeNames = {}; } @@ -1712,9 +1721,12 @@ module ts { return currentScopeNames[name] = name; } + function isGeneratedName(name: string): boolean { + return currentScopeNames && hasProperty(currentScopeNames, name); + } function isExistingName(location: Node, name: string) { - return !resolver.isUnknownIdentifier(location, name) || (currentScopeNames && hasProperty(currentScopeNames, name)); + return !resolver.isUnknownIdentifier(location, name) || isGeneratedName(name); } function initializeEmitterWithSourceMaps() { @@ -2484,9 +2496,9 @@ module ts { } function emitIdentifier(node: Identifier) { - var symbolId = getBlockScopedVariableId(node); - if (symbolId !== undefined && generatedBlockScopeNames) { - var text = generatedBlockScopeNames[symbolId]; + var variableId = getBlockScopedVariableId(node); + if (variableId !== undefined && generatedBlockScopeNames) { + var text = generatedBlockScopeNames[variableId]; if (text) { write(text); return; @@ -3882,11 +3894,11 @@ module ts { } var generatedName = makeUniqueName(getEnclosingBlockScopeContainer(node), (node).text); - var symbolId = resolver.getBlockScopedVariableId(node); + var variableId = resolver.getBlockScopedVariableId(node); if (!generatedBlockScopeNames) { generatedBlockScopeNames = []; } - generatedBlockScopeNames[symbolId] = generatedName; + generatedBlockScopeNames[variableId] = generatedName; } function emitVariableStatement(node: VariableStatement) { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index c5bb46aa9624c..437894d9cfc1a 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1117,6 +1117,29 @@ module ts { return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), /*newLength: */newEndN - oldStartN); } + // @internal + export function generateUniqueName(baseName: string, isExistingName: (name: string) => boolean): string { + // First try '_name' + if (baseName.charCodeAt(0) !== CharacterCodes._) { + var baseName = "_" + baseName; + if (!isExistingName(baseName)) { + return baseName; + } + } + // Find the first unique '_name_n', where n is a positive number + if (baseName.charCodeAt(baseName.length - 1) !== CharacterCodes._) { + baseName += "_"; + } + var i = 1; + while (true) { + name = baseName + i; + if (!isExistingName(name)) { + return name; + } + i++; + } + } + // @internal export function createDiagnosticCollection(): DiagnosticCollection { var nonFileDiagnostics: Diagnostic[] = []; From 33dfe5068a2ee2f5880fd604fadb7d40a2597fd3 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 25 Feb 2015 17:44:09 -0800 Subject: [PATCH 11/18] do not emit default initializer for let\const in for-in\for-of statements --- src/compiler/checker.ts | 2 +- src/compiler/emitter.ts | 40 ++++++++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 68e8843764755..7918d393c0b3b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5119,9 +5119,9 @@ module ts { while (current && !isNameScopeBoundary(current)) { if (isIterationStatement(current, /*lookInLabeledStatements*/ false)) { if (inFunction) { - getNodeLinks(current).flags |= NodeCheckFlags.BlockScopedBindingInLoop; grammarErrorOnFirstToken(current, Diagnostics.Code_in_the_loop_captures_block_scoped_variable_0_in_closure_This_is_natively_supported_in_ECMAScript_6_or_higher, declarationNameToString(node)); } + // mark value declaration so during emit they can have a special handling getNodeLinks(symbol.valueDeclaration).flags |= NodeCheckFlags.BlockScopedBindingInLoop; break; } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9bfc14caaa0b4..1cec38872af8c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1702,6 +1702,7 @@ module ts { function makeUniqueName(location: Node, baseName: string): string { var name: string + // first try to check if base name can be used as is if (!isExistingName(location, baseName)) { name = baseName; } @@ -1721,12 +1722,9 @@ module ts { return currentScopeNames[name] = name; } - function isGeneratedName(name: string): boolean { - return currentScopeNames && hasProperty(currentScopeNames, name); - } - function isExistingName(location: Node, name: string) { - return !resolver.isUnknownIdentifier(location, name) || isGeneratedName(name); + return !resolver.isUnknownIdentifier(location, name) || + (currentScopeNames && hasProperty(currentScopeNames, name)); } function initializeEmitterWithSourceMaps() { @@ -3559,7 +3557,6 @@ module ts { result.expression = zero; return result; } - function emitExportMemberAssignments(name: Identifier) { if (exportSpecifiers && hasProperty(exportSpecifiers, name.text)) { @@ -3802,18 +3799,24 @@ module ts { emitModuleMemberName(node); var initializer = node.initializer; - if (!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 - var initializer = - languageVersion < ScriptTarget.ES6 && + var isUninitializedLet = (resolver.getNodeCheckFlags(node) & NodeCheckFlags.BlockScopedBindingInLoop) && - (getCombinedFlagsForIdentifier(node.name) & NodeFlags.Let) && - createVoidZero(); + (getCombinedFlagsForIdentifier(node.name) & NodeFlags.Let); + + // NOTE: default initialization should not be added to let bindings in for-in\for-of statements + if (isUninitializedLet && + node.parent.parent.kind !== SyntaxKind.ForInStatement && + node.parent.parent.kind !== SyntaxKind.ForOfStatement) { + initializer = createVoidZero(); + } } emitOptional(" = ", initializer); @@ -3834,20 +3837,20 @@ module ts { var current = node; while (current) { if (isAnyFunction(current)) { - return current.parent; + return current; } switch (current.kind) { case SyntaxKind.CatchClause: case SyntaxKind.ForStatement: case SyntaxKind.ForInStatement: case SyntaxKind.SwitchKeyword: - return current.parent; + return current; case SyntaxKind.Block: if (isAnyFunction(current.parent)) { - return current.parent.parent; + return current.parent; } else { - return current.parent; + return current; } case SyntaxKind.SourceFile: return current; @@ -3893,7 +3896,12 @@ module ts { return; } - var generatedName = makeUniqueName(getEnclosingBlockScopeContainer(node), (node).text); + var blockScopeContainer = getEnclosingBlockScopeContainer(node); + var parent = blockScopeContainer.kind === SyntaxKind.SourceFile + ? blockScopeContainer + : blockScopeContainer.parent; + + var generatedName = makeUniqueName(parent, (node).text); var variableId = resolver.getBlockScopedVariableId(node); if (!generatedBlockScopeNames) { generatedBlockScopeNames = []; From 32aef1a031b0386f2968a8b2636822cd417d730a Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 25 Feb 2015 18:01:40 -0800 Subject: [PATCH 12/18] do not report error on non-initialized const bindings in for-in\for-of statements --- src/compiler/checker.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7918d393c0b3b..7094f9e7ea81d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11498,7 +11498,8 @@ module ts { if (isBindingPattern(node.name) && !isBindingPattern(node.parent)) { return grammarErrorOnNode(node, Diagnostics.A_destructuring_declaration_must_have_an_initializer); } - if (isConst(node)) { + // const declarations should not be initialized in for-in for-of statements + if (isConst(node) && node.parent.parent.kind !== SyntaxKind.ForInStatement && node.parent.parent.kind !== SyntaxKind.ForOfStatement) { return grammarErrorOnNode(node, Diagnostics.const_declarations_must_be_initialized); } } From b183f8dca672d439f739d78e808d5bb5909fd624 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 26 Feb 2015 00:04:44 -0800 Subject: [PATCH 13/18] added 'nodeIsSynthesized' function, use createSynthesizedNode in emitter to build synthetic nodes --- src/compiler/checker.ts | 12 +++++++++--- src/compiler/emitter.ts | 35 ++++++++++++++--------------------- src/compiler/utilities.ts | 14 ++++++++++++++ 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7094f9e7ea81d..9dabafb0cde69 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10718,7 +10718,7 @@ module ts { } function getBlockScopedVariableId(n: Identifier): number { - Debug.assert(n.parent !== undefined); + Debug.assert(!nodeIsSynthesized(n)); // ignore name parts of property access expressions if (n.parent.kind === SyntaxKind.PropertyAccessExpression && @@ -10736,8 +10736,14 @@ module ts { var symbol = declarationSymbol || getNodeLinks(n).resolvedSymbol || resolveName(n, n.text, SymbolFlags.BlockScopedVariable | SymbolFlags.Import, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined); - - return symbol && symbol.flags & SymbolFlags.BlockScopedVariable ? symbol.id : undefined; + + if (symbol && (symbol.flags & SymbolFlags.BlockScopedVariable)) { + // side-effect of calling this method: + // assign id to symbol if it was not yet set + getSymbolLinks(symbol); + return symbol.id; + } + return undefined; } function createResolver(): EmitResolver { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 1cec38872af8c..fbe341ccd28e8 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -32,7 +32,7 @@ module ts { leadingCommentRanges?: CommentRange[]; trailingCommentRanges?: CommentRange[]; } - + interface ScopeFrame { names: Map; previous: ScopeFrame; @@ -2100,7 +2100,7 @@ module ts { name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0 : 1) + CharacterCodes.a) : tempCount - 25); tempCount++; } - var result = createNode(SyntaxKind.Identifier); + var result = createSynthesizedNode(SyntaxKind.Identifier); result.text = name; return result; } @@ -2647,14 +2647,6 @@ module ts { } } - function createSynthesizedNode(kind: SyntaxKind): Node { - var node = createNode(kind); - node.pos = -1; - node.end = -1; - - return node; - } - function emitDownlevelObjectLiteralWithComputedProperties(node: ObjectLiteralExpression, firstComputedPropertyIndex: number): void { var parenthesizedObjectLiteral = createDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex); return emit(parenthesizedObjectLiteral); @@ -3551,9 +3543,9 @@ module ts { } function createVoidZero(): Expression { - var zero = createNode(SyntaxKind.NumericLiteral); + var zero = createSynthesizedNode(SyntaxKind.NumericLiteral); zero.text = "0"; - var result = createNode(SyntaxKind.VoidExpression); + var result = createSynthesizedNode(SyntaxKind.VoidExpression); result.expression = zero; return result; } @@ -3619,11 +3611,11 @@ module ts { // we need to generate a temporary variable value = ensureIdentifier(value); // Return the expression 'value === void 0 ? defaultValue : value' - var equals = createNode(SyntaxKind.BinaryExpression); + var equals = createSynthesizedNode(SyntaxKind.BinaryExpression); equals.left = value; - equals.operatorToken = createNode(SyntaxKind.EqualsEqualsEqualsToken); + equals.operatorToken = createSynthesizedNode(SyntaxKind.EqualsEqualsEqualsToken); equals.right = createVoidZero(); - var cond = createNode(SyntaxKind.ConditionalExpression); + var cond = createSynthesizedNode(SyntaxKind.ConditionalExpression); cond.condition = equals; cond.whenTrue = defaultValue; cond.whenFalse = value; @@ -3631,7 +3623,7 @@ module ts { } function createNumericLiteral(value: number) { - var node = createNode(SyntaxKind.NumericLiteral); + var node = createSynthesizedNode(SyntaxKind.NumericLiteral); node.text = "" + value; return node; } @@ -3640,7 +3632,7 @@ module ts { if (expr.kind === SyntaxKind.Identifier || expr.kind === SyntaxKind.PropertyAccessExpression || expr.kind === SyntaxKind.ElementAccessExpression) { return expr; } - var node = createNode(SyntaxKind.ParenthesizedExpression); + var node = createSynthesizedNode(SyntaxKind.ParenthesizedExpression); node.expression = expr; return node; } @@ -3649,14 +3641,14 @@ module ts { if (propName.kind !== SyntaxKind.Identifier) { return createElementAccess(object, propName); } - var node = createNode(SyntaxKind.PropertyAccessExpression); + var node = createSynthesizedNode(SyntaxKind.PropertyAccessExpression); node.expression = parenthesizeForAccess(object); node.name = propName; return node; } function createElementAccess(object: Expression, index: Expression): Expression { - var node = createNode(SyntaxKind.ElementAccessExpression); + var node = createSynthesizedNode(SyntaxKind.ElementAccessExpression); node.expression = parenthesizeForAccess(object); node.argumentExpression = index; return node; @@ -3843,6 +3835,7 @@ module ts { case SyntaxKind.CatchClause: case SyntaxKind.ForStatement: case SyntaxKind.ForInStatement: + case SyntaxKind.ForOfStatement: case SyntaxKind.SwitchKeyword: return current; case SyntaxKind.Block: @@ -3872,12 +3865,12 @@ module ts { function renameNonTopLevelLetAndConst(node: Node): void { // do not rename if // - language version is ES6+ - // - node is synthesized (does not have a parent) + // - node is synthesized // - node is not identifier (can happen when tree is malformed) // - node is definitely not name of variable declaration. // it still can be part of parameter declaration, this check will be done next if (languageVersion >= ScriptTarget.ES6 || - !node.parent || + nodeIsSynthesized(node) || node.kind !== SyntaxKind.Identifier || (node.parent.kind !== SyntaxKind.VariableDeclaration && node.parent.kind !== SyntaxKind.BindingElement)) { return; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 437894d9cfc1a..50a8de9671d31 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1117,6 +1117,20 @@ module ts { return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), /*newLength: */newEndN - oldStartN); } + // @internal + export function nodeIsSynthesized(node: Node): boolean { + return node.pos === -1 && node.end === -1; + } + + // @internal + export function createSynthesizedNode(kind: SyntaxKind): Node { + var node = createNode(kind); + node.pos = -1; + node.end = -1; + + return node; + } + // @internal export function generateUniqueName(baseName: string, isExistingName: (name: string) => boolean): string { // First try '_name' From 4ff22a0886f3cecc17b10e0c0f1b0ad2259e4da4 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 26 Feb 2015 11:58:40 -0800 Subject: [PATCH 14/18] added SyntaxKind.ModuleDeclaration to list of block scope containers --- src/compiler/checker.ts | 6 +----- src/compiler/emitter.ts | 13 ++++++------- src/compiler/utilities.ts | 5 +++++ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9dabafb0cde69..6888a6fc25d43 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5086,10 +5086,6 @@ module ts { return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node); } - function isNameScopeBoundary(n: Node): boolean { - return isAnyFunction(n) || n.kind === SyntaxKind.ModuleDeclaration || n.kind === SyntaxKind.SourceFile; - } - function checkBlockScopedBindingCapturedInLoop(node: Identifier, symbol: Symbol): void { if (languageVersion >= ScriptTarget.ES6 || (symbol.flags & SymbolFlags.BlockScopedVariable) === 0) { return; @@ -5116,7 +5112,7 @@ module ts { } var current: Node = container; - while (current && !isNameScopeBoundary(current)) { + while (current && !nodeStartsNewLexicalEnvironment(current)) { if (isIterationStatement(current, /*lookInLabeledStatements*/ false)) { if (inFunction) { grammarErrorOnFirstToken(current, Diagnostics.Code_in_the_loop_captures_block_scoped_variable_0_in_closure_This_is_natively_supported_in_ECMAScript_6_or_higher, declarationNameToString(node)); diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index fbe341ccd28e8..1cfbbd2009697 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3832,21 +3832,20 @@ module ts { return current; } switch (current.kind) { + case SyntaxKind.SourceFile: + case SyntaxKind.SwitchKeyword: case SyntaxKind.CatchClause: + case SyntaxKind.ModuleDeclaration: case SyntaxKind.ForStatement: case SyntaxKind.ForInStatement: case SyntaxKind.ForOfStatement: - case SyntaxKind.SwitchKeyword: return current; case SyntaxKind.Block: - if (isAnyFunction(current.parent)) { - return current.parent; - } - else { + // function block is not considered block-scope container + // see comment in binder.ts: bind(...), case for SyntaxKind.Block + if (!isAnyFunction(current.parent)) { return current; } - case SyntaxKind.SourceFile: - return current; } current = current.parent; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 50a8de9671d31..bf8a9dd109741 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1117,6 +1117,11 @@ module ts { return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), /*newLength: */newEndN - oldStartN); } + // @internal + export function nodeStartsNewLexicalEnvironment(n: Node): boolean { + return isAnyFunction(n) || n.kind === SyntaxKind.ModuleDeclaration || n.kind === SyntaxKind.SourceFile; + } + // @internal export function nodeIsSynthesized(node: Node): boolean { return node.pos === -1 && node.end === -1; From 16378e3c1cb72a922b291ebc7f0244ee343779ca Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 26 Feb 2015 16:13:52 -0800 Subject: [PATCH 15/18] do not treat property names in binding elements as block scoped variables --- src/compiler/checker.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6888a6fc25d43..fd3d2141dc08d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5091,13 +5091,20 @@ module ts { return; } - // - check if binding is used in some function + // - check if binding is used in some function // (stop the walk when reaching container of binding declaration) // - if first check succeeded - check if variable is declared inside the loop - // var decl -> var decl list -> parent - var container = (symbol.valueDeclaration).parent.parent; + // nesting structure: + // (variable declaration or binding element) -> variable declaration list -> container + var container: Node = 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; } @@ -10722,6 +10729,12 @@ module ts { return undefined; } + // ignore property names in object binding patterns + if (n.parent.kind === SyntaxKind.BindingElement && + (n.parent).propertyName === n) { + return undefined; + } + // for names in variable declarations and binding elements try to short circuit and fetch symbol from the node var declarationSymbol: Symbol = (n.parent.kind === SyntaxKind.VariableDeclaration && (n.parent).name === n) || From 904d116f9ad5a4b8f88c682cbd105a76d0f86afd Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 26 Feb 2015 16:53:25 -0800 Subject: [PATCH 16/18] added tests --- .../baselines/reference/ES5SymbolProperty1.js | 3 +- .../reference/FunctionDeclaration8_es6.js | 3 +- .../reference/FunctionDeclaration9_es6.js | 3 +- .../FunctionPropertyAssignments5_es6.js | 3 +- .../reference/computedPropertyNames10_ES5.js | 3 +- .../reference/computedPropertyNames11_ES5.js | 3 +- .../reference/computedPropertyNames18_ES5.js | 3 +- .../reference/computedPropertyNames19_ES5.js | 3 +- .../reference/computedPropertyNames1_ES5.js | 3 +- .../reference/computedPropertyNames20_ES5.js | 3 +- .../reference/computedPropertyNames22_ES5.js | 3 +- .../reference/computedPropertyNames23_ES5.js | 3 +- .../reference/computedPropertyNames25_ES5.js | 3 +- .../reference/computedPropertyNames26_ES5.js | 3 +- .../reference/computedPropertyNames28_ES5.js | 3 +- .../reference/computedPropertyNames29_ES5.js | 3 +- .../reference/computedPropertyNames30_ES5.js | 3 +- .../reference/computedPropertyNames31_ES5.js | 3 +- .../reference/computedPropertyNames33_ES5.js | 3 +- .../reference/computedPropertyNames34_ES5.js | 3 +- .../reference/computedPropertyNames46_ES5.js | 3 +- .../reference/computedPropertyNames47_ES5.js | 3 +- .../reference/computedPropertyNames48_ES5.js | 9 +- .../reference/computedPropertyNames49_ES5.js | 3 +- .../reference/computedPropertyNames4_ES5.js | 3 +- .../reference/computedPropertyNames50_ES5.js | 3 +- .../reference/computedPropertyNames5_ES5.js | 3 +- .../reference/computedPropertyNames6_ES5.js | 3 +- .../reference/computedPropertyNames7_ES5.js | 3 +- .../reference/computedPropertyNames8_ES5.js | 3 +- .../reference/computedPropertyNames9_ES5.js | 3 +- ...mputedPropertyNamesContextualType10_ES5.js | 3 +- ...omputedPropertyNamesContextualType1_ES5.js | 3 +- ...omputedPropertyNamesContextualType2_ES5.js | 3 +- ...omputedPropertyNamesContextualType3_ES5.js | 3 +- ...omputedPropertyNamesContextualType4_ES5.js | 3 +- ...omputedPropertyNamesContextualType5_ES5.js | 3 +- ...omputedPropertyNamesContextualType6_ES5.js | 3 +- ...omputedPropertyNamesContextualType7_ES5.js | 3 +- ...omputedPropertyNamesContextualType8_ES5.js | 3 +- ...omputedPropertyNamesContextualType9_ES5.js | 3 +- ...mputedPropertyNamesDeclarationEmit5_ES5.js | 3 +- .../computedPropertyNamesSourceMap2_ES5.js | 3 +- ...computedPropertyNamesSourceMap2_ES5.js.map | 2 +- ...dPropertyNamesSourceMap2_ES5.sourcemap.txt | 125 +++-- .../constDeclarations-errors.errors.txt | 12 +- .../reference/constDeclarations-errors.js | 2 - .../reference/downlevelLetConst12.js | 22 + .../reference/downlevelLetConst12.types | 30 ++ .../reference/downlevelLetConst13.js | 39 ++ .../reference/downlevelLetConst13.types | 60 +++ .../reference/downlevelLetConst14.js | 107 +++++ .../reference/downlevelLetConst14.types | 178 +++++++ .../reference/downlevelLetConst15.js | 107 +++++ .../reference/downlevelLetConst15.types | 184 ++++++++ .../reference/downlevelLetConst16.errors.txt | 249 ++++++++++ .../reference/downlevelLetConst16.js | 441 ++++++++++++++++++ .../reference/downlevelLetConst17.errors.txt | 74 +++ .../reference/downlevelLetConst17.js | 124 +++++ .../reference/downlevelLetConst18.errors.txt | 60 +++ .../reference/downlevelLetConst18.js | 57 +++ .../parserES5ComputedPropertyName2.js | 3 +- .../parserES5ComputedPropertyName3.js | 3 +- .../parserES5ComputedPropertyName4.js | 3 +- tests/baselines/reference/privateIndexer2.js | 3 +- .../compiler/constDeclarations-errors.ts | 1 - tests/cases/compiler/downlevelLetConst12.ts | 12 + tests/cases/compiler/downlevelLetConst13.ts | 21 + tests/cases/compiler/downlevelLetConst14.ts | 55 +++ tests/cases/compiler/downlevelLetConst15.ts | 55 +++ tests/cases/compiler/downlevelLetConst16.ts | 229 +++++++++ tests/cases/compiler/downlevelLetConst17.ts | 69 +++ tests/cases/compiler/downlevelLetConst18.ts | 30 ++ 73 files changed, 2315 insertions(+), 177 deletions(-) create mode 100644 tests/baselines/reference/downlevelLetConst12.js create mode 100644 tests/baselines/reference/downlevelLetConst12.types create mode 100644 tests/baselines/reference/downlevelLetConst13.js create mode 100644 tests/baselines/reference/downlevelLetConst13.types create mode 100644 tests/baselines/reference/downlevelLetConst14.js create mode 100644 tests/baselines/reference/downlevelLetConst14.types create mode 100644 tests/baselines/reference/downlevelLetConst15.js create mode 100644 tests/baselines/reference/downlevelLetConst15.types create mode 100644 tests/baselines/reference/downlevelLetConst16.errors.txt create mode 100644 tests/baselines/reference/downlevelLetConst16.js create mode 100644 tests/baselines/reference/downlevelLetConst17.errors.txt create mode 100644 tests/baselines/reference/downlevelLetConst17.js create mode 100644 tests/baselines/reference/downlevelLetConst18.errors.txt create mode 100644 tests/baselines/reference/downlevelLetConst18.js create mode 100644 tests/cases/compiler/downlevelLetConst12.ts create mode 100644 tests/cases/compiler/downlevelLetConst13.ts create mode 100644 tests/cases/compiler/downlevelLetConst14.ts create mode 100644 tests/cases/compiler/downlevelLetConst15.ts create mode 100644 tests/cases/compiler/downlevelLetConst16.ts create mode 100644 tests/cases/compiler/downlevelLetConst17.ts create mode 100644 tests/cases/compiler/downlevelLetConst18.ts diff --git a/tests/baselines/reference/ES5SymbolProperty1.js b/tests/baselines/reference/ES5SymbolProperty1.js index e977df7dc6b1e..21ba59abf1948 100644 --- a/tests/baselines/reference/ES5SymbolProperty1.js +++ b/tests/baselines/reference/ES5SymbolProperty1.js @@ -13,7 +13,6 @@ obj[Symbol.foo]; //// [ES5SymbolProperty1.js] var Symbol; var obj = (_a = {}, _a[Symbol.foo] = -0, -_a); +0, _a); obj[Symbol.foo]; var _a; diff --git a/tests/baselines/reference/FunctionDeclaration8_es6.js b/tests/baselines/reference/FunctionDeclaration8_es6.js index 3f6d2499cef8b..c8cd24d837756 100644 --- a/tests/baselines/reference/FunctionDeclaration8_es6.js +++ b/tests/baselines/reference/FunctionDeclaration8_es6.js @@ -3,6 +3,5 @@ var v = { [yield]: foo } //// [FunctionDeclaration8_es6.js] var v = (_a = {}, _a[yield] = -foo, -_a); +foo, _a); var _a; diff --git a/tests/baselines/reference/FunctionDeclaration9_es6.js b/tests/baselines/reference/FunctionDeclaration9_es6.js index 04c946a96ebdd..3a894126bafb8 100644 --- a/tests/baselines/reference/FunctionDeclaration9_es6.js +++ b/tests/baselines/reference/FunctionDeclaration9_es6.js @@ -6,7 +6,6 @@ function * foo() { //// [FunctionDeclaration9_es6.js] function foo() { var v = (_a = {}, _a[] = - foo, - _a); + foo, _a); var _a; } diff --git a/tests/baselines/reference/FunctionPropertyAssignments5_es6.js b/tests/baselines/reference/FunctionPropertyAssignments5_es6.js index 0b786632bdf94..188a843f7517d 100644 --- a/tests/baselines/reference/FunctionPropertyAssignments5_es6.js +++ b/tests/baselines/reference/FunctionPropertyAssignments5_es6.js @@ -2,6 +2,5 @@ var v = { *[foo()]() { } } //// [FunctionPropertyAssignments5_es6.js] -var v = (_a = {}, _a[foo()] = function () { }, -_a); +var v = (_a = {}, _a[foo()] = function () { }, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames10_ES5.js b/tests/baselines/reference/computedPropertyNames10_ES5.js index ececb28b8cc49..e330db8707597 100644 --- a/tests/baselines/reference/computedPropertyNames10_ES5.js +++ b/tests/baselines/reference/computedPropertyNames10_ES5.js @@ -20,6 +20,5 @@ var v = { var s; var n; var a; -var v = (_a = {}, _a[s] = function () { }, _a[n] = function () { }, _a[s + s] = function () { }, _a[s + n] = function () { }, _a[+s] = function () { }, _a[""] = function () { }, _a[0] = function () { }, _a[a] = function () { }, _a[true] = function () { }, _a["hello bye"] = function () { }, _a["hello " + a + " bye"] = function () { }, -_a); +var v = (_a = {}, _a[s] = function () { }, _a[n] = function () { }, _a[s + s] = function () { }, _a[s + n] = function () { }, _a[+s] = function () { }, _a[""] = function () { }, _a[0] = function () { }, _a[a] = function () { }, _a[true] = function () { }, _a["hello bye"] = function () { }, _a["hello " + a + " bye"] = function () { }, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames11_ES5.js b/tests/baselines/reference/computedPropertyNames11_ES5.js index d8450deb76580..73ed6110cedaf 100644 --- a/tests/baselines/reference/computedPropertyNames11_ES5.js +++ b/tests/baselines/reference/computedPropertyNames11_ES5.js @@ -20,6 +20,5 @@ var v = { var s; var n; var a; -var v = (_a = {}, _a[s] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a[n] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a[s + s] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a[s + n] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a[+s] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a[""] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a[0] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a[a] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a[true] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a["hello bye"] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a["hello " + a + " bye"] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), -_a); +var v = (_a = {}, _a[s] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a[n] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a[s + s] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a[s + n] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a[+s] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a[""] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a[0] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a[a] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a[true] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a["hello bye"] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a["hello " + a + " bye"] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames18_ES5.js b/tests/baselines/reference/computedPropertyNames18_ES5.js index 0ccc0fb4e0058..0eb6cba359075 100644 --- a/tests/baselines/reference/computedPropertyNames18_ES5.js +++ b/tests/baselines/reference/computedPropertyNames18_ES5.js @@ -8,7 +8,6 @@ function foo() { //// [computedPropertyNames18_ES5.js] function foo() { var obj = (_a = {}, _a[this.bar] = - 0, - _a); + 0, _a); var _a; } diff --git a/tests/baselines/reference/computedPropertyNames19_ES5.js b/tests/baselines/reference/computedPropertyNames19_ES5.js index a18cb7b95c3dd..5ceaa2188e4f7 100644 --- a/tests/baselines/reference/computedPropertyNames19_ES5.js +++ b/tests/baselines/reference/computedPropertyNames19_ES5.js @@ -9,7 +9,6 @@ module M { var M; (function (M) { var obj = (_a = {}, _a[this.bar] = - 0, - _a); + 0, _a); var _a; })(M || (M = {})); diff --git a/tests/baselines/reference/computedPropertyNames1_ES5.js b/tests/baselines/reference/computedPropertyNames1_ES5.js index 36a7fd6052dcb..d8f339dc81129 100644 --- a/tests/baselines/reference/computedPropertyNames1_ES5.js +++ b/tests/baselines/reference/computedPropertyNames1_ES5.js @@ -5,6 +5,5 @@ var v = { } //// [computedPropertyNames1_ES5.js] -var v = (_a = {}, _a[0 + 1] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a[0 + 1] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), -_a); +var v = (_a = {}, _a[0 + 1] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a[0 + 1] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames20_ES5.js b/tests/baselines/reference/computedPropertyNames20_ES5.js index 21af64d7e4107..22aa44250a32c 100644 --- a/tests/baselines/reference/computedPropertyNames20_ES5.js +++ b/tests/baselines/reference/computedPropertyNames20_ES5.js @@ -5,6 +5,5 @@ var obj = { //// [computedPropertyNames20_ES5.js] var obj = (_a = {}, _a[this.bar] = -0, -_a); +0, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames22_ES5.js b/tests/baselines/reference/computedPropertyNames22_ES5.js index e3e685aa54bec..4dfd1286b06e3 100644 --- a/tests/baselines/reference/computedPropertyNames22_ES5.js +++ b/tests/baselines/reference/computedPropertyNames22_ES5.js @@ -13,8 +13,7 @@ var C = (function () { function C() { } C.prototype.bar = function () { - var obj = (_a = {}, _a[this.bar()] = function () { }, - _a); + var obj = (_a = {}, _a[this.bar()] = function () { }, _a); return 0; var _a; }; diff --git a/tests/baselines/reference/computedPropertyNames23_ES5.js b/tests/baselines/reference/computedPropertyNames23_ES5.js index 7b5a5a101a546..8ae21bc8d68c5 100644 --- a/tests/baselines/reference/computedPropertyNames23_ES5.js +++ b/tests/baselines/reference/computedPropertyNames23_ES5.js @@ -16,8 +16,7 @@ var C = (function () { return 0; }; C.prototype[(_a = {}, _a[this.bar()] = - 1, - _a)[0]] = function () { }; + 1, _a)[0]] = function () { }; return C; })(); var _a; diff --git a/tests/baselines/reference/computedPropertyNames25_ES5.js b/tests/baselines/reference/computedPropertyNames25_ES5.js index bd2212b72b316..97a43c7cacbf4 100644 --- a/tests/baselines/reference/computedPropertyNames25_ES5.js +++ b/tests/baselines/reference/computedPropertyNames25_ES5.js @@ -34,8 +34,7 @@ var C = (function (_super) { _super.apply(this, arguments); } C.prototype.foo = function () { - var obj = (_a = {}, _a[_super.prototype.bar.call(this)] = function () { }, - _a); + var obj = (_a = {}, _a[_super.prototype.bar.call(this)] = function () { }, _a); return 0; var _a; }; diff --git a/tests/baselines/reference/computedPropertyNames26_ES5.js b/tests/baselines/reference/computedPropertyNames26_ES5.js index 5df2f6dc1b61c..893541ef63321 100644 --- a/tests/baselines/reference/computedPropertyNames26_ES5.js +++ b/tests/baselines/reference/computedPropertyNames26_ES5.js @@ -35,8 +35,7 @@ var C = (function (_super) { // Gets emitted as super, not _super, which is consistent with // use of super in static properties initializers. C.prototype[(_a = {}, _a[super.bar.call(this)] = - 1, - _a)[0]] = function () { }; + 1, _a)[0]] = function () { }; return C; })(Base); var _a; diff --git a/tests/baselines/reference/computedPropertyNames28_ES5.js b/tests/baselines/reference/computedPropertyNames28_ES5.js index 7e548d4d6d3d8..3d9a343fcdb69 100644 --- a/tests/baselines/reference/computedPropertyNames28_ES5.js +++ b/tests/baselines/reference/computedPropertyNames28_ES5.js @@ -26,8 +26,7 @@ var C = (function (_super) { __extends(C, _super); function C() { _super.call(this); - var obj = (_a = {}, _a[(_super.call(this), "prop")] = function () { }, - _a); + var obj = (_a = {}, _a[(_super.call(this), "prop")] = function () { }, _a); var _a; } return C; diff --git a/tests/baselines/reference/computedPropertyNames29_ES5.js b/tests/baselines/reference/computedPropertyNames29_ES5.js index 27c7cd979882d..ea9a9b1b635ae 100644 --- a/tests/baselines/reference/computedPropertyNames29_ES5.js +++ b/tests/baselines/reference/computedPropertyNames29_ES5.js @@ -17,8 +17,7 @@ var C = (function () { C.prototype.bar = function () { var _this = this; (function () { - var obj = (_a = {}, _a[_this.bar()] = function () { }, - _a); + var obj = (_a = {}, _a[_this.bar()] = function () { }, _a); var _a; }); return 0; diff --git a/tests/baselines/reference/computedPropertyNames30_ES5.js b/tests/baselines/reference/computedPropertyNames30_ES5.js index 505b149f62d64..06a63dd75652d 100644 --- a/tests/baselines/reference/computedPropertyNames30_ES5.js +++ b/tests/baselines/reference/computedPropertyNames30_ES5.js @@ -32,8 +32,7 @@ var C = (function (_super) { function C() { _super.call(this); (function () { - var obj = (_a = {}, _a[(_super.call(this), "prop")] = function () { }, - _a); + var obj = (_a = {}, _a[(_super.call(this), "prop")] = function () { }, _a); var _a; }); } diff --git a/tests/baselines/reference/computedPropertyNames31_ES5.js b/tests/baselines/reference/computedPropertyNames31_ES5.js index 0c8cbac455f26..a6db55259d5c6 100644 --- a/tests/baselines/reference/computedPropertyNames31_ES5.js +++ b/tests/baselines/reference/computedPropertyNames31_ES5.js @@ -38,8 +38,7 @@ var C = (function (_super) { C.prototype.foo = function () { var _this = this; (function () { - var obj = (_a = {}, _a[_super.prototype.bar.call(_this)] = function () { }, - _a); + var obj = (_a = {}, _a[_super.prototype.bar.call(_this)] = function () { }, _a); var _a; }); return 0; diff --git a/tests/baselines/reference/computedPropertyNames33_ES5.js b/tests/baselines/reference/computedPropertyNames33_ES5.js index 84df68fcc106a..d689d27fe5a06 100644 --- a/tests/baselines/reference/computedPropertyNames33_ES5.js +++ b/tests/baselines/reference/computedPropertyNames33_ES5.js @@ -15,8 +15,7 @@ var C = (function () { function C() { } C.prototype.bar = function () { - var obj = (_a = {}, _a[foo()] = function () { }, - _a); + var obj = (_a = {}, _a[foo()] = function () { }, _a); return 0; var _a; }; diff --git a/tests/baselines/reference/computedPropertyNames34_ES5.js b/tests/baselines/reference/computedPropertyNames34_ES5.js index 9e1de33be7c7f..3c97971120d8e 100644 --- a/tests/baselines/reference/computedPropertyNames34_ES5.js +++ b/tests/baselines/reference/computedPropertyNames34_ES5.js @@ -15,8 +15,7 @@ var C = (function () { function C() { } C.bar = function () { - var obj = (_a = {}, _a[foo()] = function () { }, - _a); + var obj = (_a = {}, _a[foo()] = function () { }, _a); return 0; var _a; }; diff --git a/tests/baselines/reference/computedPropertyNames46_ES5.js b/tests/baselines/reference/computedPropertyNames46_ES5.js index 3e4329b8a2046..6e999b3958679 100644 --- a/tests/baselines/reference/computedPropertyNames46_ES5.js +++ b/tests/baselines/reference/computedPropertyNames46_ES5.js @@ -5,6 +5,5 @@ var o = { //// [computedPropertyNames46_ES5.js] var o = (_a = {}, _a["" || 0] = -0, -_a); +0, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames47_ES5.js b/tests/baselines/reference/computedPropertyNames47_ES5.js index 7874a25976f8f..977f18770be03 100644 --- a/tests/baselines/reference/computedPropertyNames47_ES5.js +++ b/tests/baselines/reference/computedPropertyNames47_ES5.js @@ -15,6 +15,5 @@ var E2; E2[E2["x"] = 0] = "x"; })(E2 || (E2 = {})); var o = (_a = {}, _a[0 /* x */ || 0 /* x */] = -0, -_a); +0, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames48_ES5.js b/tests/baselines/reference/computedPropertyNames48_ES5.js index f3f9941aeae7c..00d7db670ebb9 100644 --- a/tests/baselines/reference/computedPropertyNames48_ES5.js +++ b/tests/baselines/reference/computedPropertyNames48_ES5.js @@ -24,12 +24,9 @@ var E; })(E || (E = {})); var a; extractIndexer((_a = {}, _a[a] = -"", -_a)); // Should return string +"", _a)); // Should return string extractIndexer((_b = {}, _b[0 /* x */] = -"", -_b)); // Should return string +"", _b)); // Should return string extractIndexer((_c = {}, _c["" || 0] = -"", -_c)); // Should return any (widened form of undefined) +"", _c)); // Should return any (widened form of undefined) var _a, _b, _c; diff --git a/tests/baselines/reference/computedPropertyNames49_ES5.js b/tests/baselines/reference/computedPropertyNames49_ES5.js index a64d9431a9ab7..ba941a49e125a 100644 --- a/tests/baselines/reference/computedPropertyNames49_ES5.js +++ b/tests/baselines/reference/computedPropertyNames49_ES5.js @@ -41,6 +41,5 @@ var x = (_a = { return 10; } }, enumerable: true, configurable: true }), _a.p2 = -20, -_a); +20, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames4_ES5.js b/tests/baselines/reference/computedPropertyNames4_ES5.js index 255b14eb97053..59f5e80873e4b 100644 --- a/tests/baselines/reference/computedPropertyNames4_ES5.js +++ b/tests/baselines/reference/computedPropertyNames4_ES5.js @@ -31,6 +31,5 @@ s, _a[""] = 1, _a[true] = 0, _a["hello bye"] = 0, _a["hello " + a + " bye"] = -0, -_a); +0, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames50_ES5.js b/tests/baselines/reference/computedPropertyNames50_ES5.js index a0703eeac0581..6e7f63dd56ef8 100644 --- a/tests/baselines/reference/computedPropertyNames50_ES5.js +++ b/tests/baselines/reference/computedPropertyNames50_ES5.js @@ -46,6 +46,5 @@ var x = (_a = { }, enumerable: true, configurable: true }), _a[1 + 1] = Object.defineProperty({ get: function () { return 10; }, enumerable: true, configurable: true }), _a.p2 = -20, -_a); +20, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames5_ES5.js b/tests/baselines/reference/computedPropertyNames5_ES5.js index 722c0f3a74d77..25c6e79a9ea1b 100644 --- a/tests/baselines/reference/computedPropertyNames5_ES5.js +++ b/tests/baselines/reference/computedPropertyNames5_ES5.js @@ -17,6 +17,5 @@ var v = (_a = {}, _a[b] = 0, _a[{}] = 0, _a[undefined] = undefined, _a[null] = -null, -_a); +null, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames6_ES5.js b/tests/baselines/reference/computedPropertyNames6_ES5.js index 4e3ed1b2e9f46..4e4cc0ad09e08 100644 --- a/tests/baselines/reference/computedPropertyNames6_ES5.js +++ b/tests/baselines/reference/computedPropertyNames6_ES5.js @@ -15,6 +15,5 @@ var p3; var v = (_a = {}, _a[p1] = 0, _a[p2] = 1, _a[p3] = -2, -_a); +2, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames7_ES5.js b/tests/baselines/reference/computedPropertyNames7_ES5.js index 3e1bcc1151cc3..f5939227d9d05 100644 --- a/tests/baselines/reference/computedPropertyNames7_ES5.js +++ b/tests/baselines/reference/computedPropertyNames7_ES5.js @@ -12,6 +12,5 @@ var E; E[E["member"] = 0] = "member"; })(E || (E = {})); var v = (_a = {}, _a[0 /* member */] = -0, -_a); +0, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames8_ES5.js b/tests/baselines/reference/computedPropertyNames8_ES5.js index 4db9ed2ec133c..23c2d6c1832bc 100644 --- a/tests/baselines/reference/computedPropertyNames8_ES5.js +++ b/tests/baselines/reference/computedPropertyNames8_ES5.js @@ -14,7 +14,6 @@ function f() { var u; var v = (_a = {}, _a[t] = 0, _a[u] = - 1, - _a); + 1, _a); var _a; } diff --git a/tests/baselines/reference/computedPropertyNames9_ES5.js b/tests/baselines/reference/computedPropertyNames9_ES5.js index a7c4a74d5ec8f..137a3e8d10374 100644 --- a/tests/baselines/reference/computedPropertyNames9_ES5.js +++ b/tests/baselines/reference/computedPropertyNames9_ES5.js @@ -15,6 +15,5 @@ function f(x) { } var v = (_a = {}, _a[f("")] = 0, _a[f(0)] = 0, _a[f(true)] = -0, -_a); +0, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType10_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType10_ES5.js index 5ea0512467478..00f1cec3cc4e9 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType10_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType10_ES5.js @@ -11,6 +11,5 @@ var o: I = { //// [computedPropertyNamesContextualType10_ES5.js] var o = (_a = {}, _a[+"foo"] = "", _a[+"bar"] = -0, -_a); +0, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType1_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType1_ES5.js index a799449541141..2efeaa2149cc7 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType1_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType1_ES5.js @@ -11,6 +11,5 @@ var o: I = { //// [computedPropertyNamesContextualType1_ES5.js] var o = (_a = {}, _a["" + 0] = function (y) { return y.length; }, _a["" + 1] = -function (y) { return y.length; }, -_a); +function (y) { return y.length; }, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.js index 0c6b80bbabb6c..dad5e0ea0cf2d 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.js @@ -11,6 +11,5 @@ var o: I = { //// [computedPropertyNamesContextualType2_ES5.js] var o = (_a = {}, _a[+"foo"] = function (y) { return y.length; }, _a[+"bar"] = -function (y) { return y.length; }, -_a); +function (y) { return y.length; }, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType3_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType3_ES5.js index 4336808c558f9..b453460eea558 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType3_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType3_ES5.js @@ -10,6 +10,5 @@ var o: I = { //// [computedPropertyNamesContextualType3_ES5.js] var o = (_a = {}, _a[+"foo"] = function (y) { return y.length; }, _a[+"bar"] = -function (y) { return y.length; }, -_a); +function (y) { return y.length; }, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType4_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType4_ES5.js index b813da3049684..6e9a0b49daa5c 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType4_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType4_ES5.js @@ -12,6 +12,5 @@ var o: I = { //// [computedPropertyNamesContextualType4_ES5.js] var o = (_a = {}, _a["" + "foo"] = "", _a["" + "bar"] = -0, -_a); +0, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType5_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType5_ES5.js index f75389de3e9d9..01830f4f46b8d 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType5_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType5_ES5.js @@ -12,6 +12,5 @@ var o: I = { //// [computedPropertyNamesContextualType5_ES5.js] var o = (_a = {}, _a[+"foo"] = "", _a[+"bar"] = -0, -_a); +0, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.js index bc724320d148c..820439c1522c6 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.js @@ -22,6 +22,5 @@ foo((_a = { function () { }, _a["hi" + "bye"] = true, _a[0 + 1] = 0, _a[+"hi"] = -[0], -_a)); +[0], _a)); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js index 8d2386a1d1460..f1087c12431c9 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js @@ -22,6 +22,5 @@ foo((_a = { function () { }, _a["hi" + "bye"] = true, _a[0 + 1] = 0, _a[+"hi"] = -[0], -_a)); +[0], _a)); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.js index 626f3d1a8e251..e47dc67e40e12 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.js @@ -12,6 +12,5 @@ var o: I = { //// [computedPropertyNamesContextualType8_ES5.js] var o = (_a = {}, _a["" + "foo"] = "", _a["" + "bar"] = -0, -_a); +0, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.js index c28db4ded9785..dd21df8dd6734 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.js @@ -12,6 +12,5 @@ var o: I = { //// [computedPropertyNamesContextualType9_ES5.js] var o = (_a = {}, _a[+"foo"] = "", _a[+"bar"] = -0, -_a); +0, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES5.js b/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES5.js index a0666f166d4a6..f93d26b23d6f6 100644 --- a/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES5.js @@ -8,8 +8,7 @@ var v = { //// [computedPropertyNamesDeclarationEmit5_ES5.js] var v = (_a = {}, _a["" + ""] = -0, _a["" + ""] = function () { }, _a["" + ""] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a["" + ""] = Object.defineProperty({ set: function (x) { }, enumerable: true, configurable: true }), -_a); +0, _a["" + ""] = function () { }, _a["" + ""] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a["" + ""] = Object.defineProperty({ set: function (x) { }, enumerable: true, configurable: true }), _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js b/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js index c5af22ef39891..d01778ff90d31 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js @@ -8,7 +8,6 @@ var v = { //// [computedPropertyNamesSourceMap2_ES5.js] var v = (_a = {}, _a["hello"] = function () { debugger; -}, -_a); +}, _a); var _a; //# sourceMappingURL=computedPropertyNamesSourceMap2_ES5.js.map \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js.map b/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js.map index 82a729df95734..e794b6265a3e6 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js.map +++ b/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js.map @@ -1,2 +1,2 @@ //// [computedPropertyNamesSourceMap2_ES5.js.map] -{"version":3,"file":"computedPropertyNamesSourceMap2_ES5.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap2_ES5.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,AADA,CACA,EAAA,GADA,EAAA,EACA,EAAA,CACK,OAAO,CAFA,GAAA;IAGA,QAAQ,CAAC;AACb,CAAC,AAJA;AACA,EAAA,AADA,CAKA,CAAA;IAJD,EAAA"} \ No newline at end of file +{"version":3,"file":"computedPropertyNamesSourceMap2_ES5.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap2_ES5.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,AADA,CAAA,EAAA,GAAA,EAAA,EAAA,EAAA,CAEA,OAAO,CAFA,GAAA;IAGA,QAAQ,CAAC;AACb,CAAC,AAJA,EAAA,EAAA,CAKA,CAAA;IALA,EAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.sourcemap.txt b/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.sourcemap.txt index 33a3a2b4c2c7b..2ca7a36792409 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.sourcemap.txt +++ b/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.sourcemap.txt @@ -32,47 +32,46 @@ sourceFile:computedPropertyNamesSourceMap2_ES5.ts 5 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 9) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 9) Source(0, NaN) + SourceIndex(0) nameIndex (-1) 5 > 6 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column -6 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 9) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 10) Source(1, 1) + SourceIndex(0) nameIndex (-1) +6 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 9) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 10) Source(0, NaN) + SourceIndex(0) nameIndex (-1) 6 > -7 > !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: -7 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 10) Source(1, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 12) Source(1, 1) + SourceIndex(0) nameIndex (-1) +7 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Invalid sourceLine found +7 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 10) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 12) Source(0, NaN) + SourceIndex(0) nameIndex (-1) 7 > -8 > !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: -8 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 12) Source(1, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 15) Source(0, NaN) + SourceIndex(0) nameIndex (-1) +8 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column +8 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 10) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 15) Source(0, NaN) + SourceIndex(0) nameIndex (-1) 8 > 9 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Invalid sourceLine found -9 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 15) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 17) Source(0, NaN) + SourceIndex(0) nameIndex (-1) +9 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 12) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 17) Source(0, NaN) + SourceIndex(0) nameIndex (-1) 9 > 10> !!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column -10> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 15) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 19) Source(1, 1) + SourceIndex(0) nameIndex (-1) +10> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 12) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 19) Source(0, NaN) + SourceIndex(0) nameIndex (-1) 10> 11> !!^^ !!^^ There was decoding error in the sourcemap at this location: Invalid sourceLine found -11> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 17) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 21) Source(1, 1) + SourceIndex(0) nameIndex (-1) +11> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 15) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 21) Source(0, NaN) + SourceIndex(0) nameIndex (-1) 11> 12> !!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column -12> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 17) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 22) Source(2, 6) + SourceIndex(0) nameIndex (-1) -12> var v = { - > [ -13> !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: -13> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 19) Source(1, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 29) Source(2, 13) + SourceIndex(0) nameIndex (-1) +12> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 15) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 22) Source(2, 6) + SourceIndex(0) nameIndex (-1) +12> +13> !!^^ !!^^ There was decoding error in the sourcemap at this location: Invalid sourceLine found +13> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 17) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 29) Source(2, 13) + SourceIndex(0) nameIndex (-1) 13> "hello" -14> !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: -14> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 21) Source(1, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 30) Source(0, NaN) + SourceIndex(0) nameIndex (-1) +14> !!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column +14> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 17) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 30) Source(0, NaN) + SourceIndex(0) nameIndex (-1) 14> -15> !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: -15> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 22) Source(2, 14) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 33) Source(0, NaN) + SourceIndex(0) nameIndex (-1) +15> !!^^ !!^^ There was decoding error in the sourcemap at this location: Invalid sourceLine found +15> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 19) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 33) Source(0, NaN) + SourceIndex(0) nameIndex (-1) 15> 1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) 2 >Emitted(1, 5) Source(1, 5) + SourceIndex(0) 3 >Emitted(1, 6) Source(1, 6) + SourceIndex(0) 4 >Emitted(1, 9) Source(1, 9) + SourceIndex(0) 5 >Emitted(1, 9) Source(0, NaN) + SourceIndex(0) -6 >Emitted(1, 10) Source(1, 1) + SourceIndex(0) -7 >Emitted(1, 12) Source(1, 1) + SourceIndex(0) +6 >Emitted(1, 10) Source(0, NaN) + SourceIndex(0) +7 >Emitted(1, 12) Source(0, NaN) + SourceIndex(0) 8 >Emitted(1, 15) Source(0, NaN) + SourceIndex(0) 9 >Emitted(1, 17) Source(0, NaN) + SourceIndex(0) -10>Emitted(1, 19) Source(1, 1) + SourceIndex(0) -11>Emitted(1, 21) Source(1, 1) + SourceIndex(0) +10>Emitted(1, 19) Source(0, NaN) + SourceIndex(0) +11>Emitted(1, 21) Source(0, NaN) + SourceIndex(0) 12>Emitted(1, 22) Source(2, 6) + SourceIndex(0) 13>Emitted(1, 29) Source(2, 13) + SourceIndex(0) 14>Emitted(1, 30) Source(0, NaN) + SourceIndex(0) @@ -82,79 +81,71 @@ sourceFile:computedPropertyNamesSourceMap2_ES5.ts 1 >^^^^ 2 > ^^^^^^^^ 3 > ^ -1 >!!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: -1 >!!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 29) Source(2, 21) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(2, 5) Source(3, 9) + SourceIndex(0) nameIndex (-1) +1 >!!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column +1 >!!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 19) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(2, 5) Source(3, 9) + SourceIndex(0) nameIndex (-1) 1 > 2 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Invalid sourceLine found -2 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 30) Source(0, 21) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(2, 13) Source(3, 17) + SourceIndex(0) nameIndex (-1) +2 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 21) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(2, 13) Source(3, 17) + SourceIndex(0) nameIndex (-1) 2 > debugger 3 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column -3 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 30) Source(0, 21) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(2, 14) Source(3, 18) + SourceIndex(0) nameIndex (-1) +3 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 21) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(2, 14) Source(3, 18) + SourceIndex(0) nameIndex (-1) 3 > ; 1 >Emitted(2, 5) Source(3, 9) + SourceIndex(0) 2 >Emitted(2, 13) Source(3, 17) + SourceIndex(0) 3 >Emitted(2, 14) Source(3, 18) + SourceIndex(0) --- ->>>}, +>>>}, _a); 1 > 2 >^ 3 > -4 > ^^^^-> -1 >!!^^ !!^^ There was decoding error in the sourcemap at this location: Invalid sourceLine found -1 >!!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 33) Source(0, 21) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 1) Source(4, 5) + SourceIndex(0) nameIndex (-1) +4 > ^^ +5 > ^^ +6 > ^ +7 > ^ +8 > ^-> +1 >!!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: +1 >!!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 22) Source(2, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 1) Source(4, 5) + SourceIndex(0) nameIndex (-1) 1 > > -2 >!!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column -2 >!!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 33) Source(0, 21) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 2) Source(4, 6) + SourceIndex(0) nameIndex (-1) +2 >!!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: +2 >!!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 29) Source(2, 16) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 2) Source(4, 6) + SourceIndex(0) nameIndex (-1) 2 >} -3 > !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: -3 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(2, 5) Source(3, 21) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 2) Source(0, NaN) + SourceIndex(0) nameIndex (-1) +3 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Invalid sourceLine found +3 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 30) Source(0, 16) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 2) Source(0, NaN) + SourceIndex(0) nameIndex (-1) 3 > +4 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column +4 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 30) Source(0, 16) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 4) Source(0, NaN) + SourceIndex(0) nameIndex (-1) +4 > +5 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Invalid sourceLine found +5 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 33) Source(0, 16) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 6) Source(0, NaN) + SourceIndex(0) nameIndex (-1) +5 > +6 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column +6 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 33) Source(0, 16) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 7) Source(5, 2) + SourceIndex(0) nameIndex (-1) +6 > +7 > !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: +7 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(2, 5) Source(3, 16) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 8) Source(5, 2) + SourceIndex(0) nameIndex (-1) +7 > 1 >Emitted(3, 1) Source(4, 5) + SourceIndex(0) 2 >Emitted(3, 2) Source(4, 6) + SourceIndex(0) 3 >Emitted(3, 2) Source(0, NaN) + SourceIndex(0) ---- ->>>_a); -1-> -2 >^^ -3 > -4 > ^ -5 > ^ -6 > ^^^^-> -1->!!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: -1->!!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(2, 13) Source(3, 29) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(4, 1) Source(1, 1) + SourceIndex(0) nameIndex (-1) -1-> -2 >!!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: -2 >!!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(2, 14) Source(3, 30) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(4, 3) Source(1, 1) + SourceIndex(0) nameIndex (-1) -2 > -3 > !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: -3 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 1) Source(4, 17) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(4, 3) Source(0, NaN) + SourceIndex(0) nameIndex (-1) -3 > -4 > !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: -4 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 2) Source(4, 18) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(4, 4) Source(5, 2) + SourceIndex(0) nameIndex (-1) -4 > -5 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Invalid sourceLine found -5 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 2) Source(0, 18) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(4, 5) Source(5, 2) + SourceIndex(0) nameIndex (-1) -5 > -1->Emitted(4, 1) Source(1, 1) + SourceIndex(0) -2 >Emitted(4, 3) Source(1, 1) + SourceIndex(0) -3 >Emitted(4, 3) Source(0, NaN) + SourceIndex(0) -4 >Emitted(4, 4) Source(5, 2) + SourceIndex(0) -5 >Emitted(4, 5) Source(5, 2) + SourceIndex(0) +4 >Emitted(3, 4) Source(0, NaN) + SourceIndex(0) +5 >Emitted(3, 6) Source(0, NaN) + SourceIndex(0) +6 >Emitted(3, 7) Source(5, 2) + SourceIndex(0) +7 >Emitted(3, 8) Source(5, 2) + SourceIndex(0) --- >>>var _a; 1->^^^^ 2 > ^^ 3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1->!!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column -1->!!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 2) Source(0, 18) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(5, 5) Source(1, 1) + SourceIndex(0) nameIndex (-1) +1->!!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: +1->!!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(2, 13) Source(3, 24) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(4, 5) Source(0, NaN) + SourceIndex(0) nameIndex (-1) 1-> 2 > !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: -2 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(4, 1) Source(1, 18) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(5, 7) Source(1, 1) + SourceIndex(0) nameIndex (-1) +2 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(2, 14) Source(3, 25) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(4, 7) Source(0, NaN) + SourceIndex(0) nameIndex (-1) 2 > -1->Emitted(5, 5) Source(1, 1) + SourceIndex(0) -2 >Emitted(5, 7) Source(1, 1) + SourceIndex(0) +1->Emitted(4, 5) Source(0, NaN) + SourceIndex(0) +2 >Emitted(4, 7) Source(0, NaN) + SourceIndex(0) --- !!!! **** There are more source map entries in the sourceMap's mapping than what was encoded -!!!! **** Remaining decoded string: ,EAAA,AADA,CAKA,CAAA;IAJD,EAAA +!!!! **** Remaining decoded string: ;AACb,CAAC,AAJA,EAAA,EAAA,CAKA,CAAA;IALA,EAAA >>>//# sourceMappingURL=computedPropertyNamesSourceMap2_ES5.js.map \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-errors.errors.txt b/tests/baselines/reference/constDeclarations-errors.errors.txt index c0ae6635c5e78..10501beb1a540 100644 --- a/tests/baselines/reference/constDeclarations-errors.errors.txt +++ b/tests/baselines/reference/constDeclarations-errors.errors.txt @@ -4,13 +4,12 @@ tests/cases/compiler/constDeclarations-errors.ts(5,7): error TS1155: 'const' dec tests/cases/compiler/constDeclarations-errors.ts(5,11): error TS1155: 'const' declarations must be initialized tests/cases/compiler/constDeclarations-errors.ts(5,15): error TS1155: 'const' declarations must be initialized tests/cases/compiler/constDeclarations-errors.ts(5,27): error TS1155: 'const' declarations must be initialized -tests/cases/compiler/constDeclarations-errors.ts(8,11): error TS1155: 'const' declarations must be initialized -tests/cases/compiler/constDeclarations-errors.ts(11,27): error TS2449: The operand of an increment or decrement operator cannot be a constant. -tests/cases/compiler/constDeclarations-errors.ts(14,11): error TS1155: 'const' declarations must be initialized -tests/cases/compiler/constDeclarations-errors.ts(17,20): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(10,27): error TS2449: The operand of an increment or decrement operator cannot be a constant. +tests/cases/compiler/constDeclarations-errors.ts(13,11): error TS1155: 'const' declarations must be initialized +tests/cases/compiler/constDeclarations-errors.ts(16,20): error TS1155: 'const' declarations must be initialized -==== tests/cases/compiler/constDeclarations-errors.ts (10 errors) ==== +==== tests/cases/compiler/constDeclarations-errors.ts (9 errors) ==== // error, missing intialicer const c1; @@ -29,10 +28,7 @@ tests/cases/compiler/constDeclarations-errors.ts(17,20): error TS1155: 'const' d ~~ !!! error TS1155: 'const' declarations must be initialized - // error, can not be unintalized for(const c in {}) { } - ~ -!!! error TS1155: 'const' declarations must be initialized // error, assigning to a const for(const c8 = 0; c8 < 1; c8++) { } diff --git a/tests/baselines/reference/constDeclarations-errors.js b/tests/baselines/reference/constDeclarations-errors.js index a9564e266a014..e7143f2564ae7 100644 --- a/tests/baselines/reference/constDeclarations-errors.js +++ b/tests/baselines/reference/constDeclarations-errors.js @@ -5,7 +5,6 @@ const c1; const c2: number; const c3, c4, c5 :string, c6; // error, missing initialicer -// error, can not be unintalized for(const c in {}) { } // error, assigning to a const @@ -22,7 +21,6 @@ for(const c10 = 0, c11; c10 < 1;) { } const c1; const c2; const c3, c4, c5, c6; // error, missing initialicer -// error, can not be unintalized for (const c in {}) { } // error, assigning to a const for (const c8 = 0; c8 < 1; c8++) { } diff --git a/tests/baselines/reference/downlevelLetConst12.js b/tests/baselines/reference/downlevelLetConst12.js new file mode 100644 index 0000000000000..6437d17accb3e --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst12.js @@ -0,0 +1,22 @@ +//// [downlevelLetConst12.ts] + +'use strict' +// top level let\const should not be renamed +let foo; +const bar = 1; + +let [baz] = []; +let {a: baz2} = { a: 1 }; + +const [baz3] = [] +const {a: baz4} = { a: 1 }; + +//// [downlevelLetConst12.js] +'use strict'; +// top level let\const should not be renamed +var foo; +var bar = 1; +var baz = ([])[0]; +var baz2 = ({ a: 1 }).a; +var baz3 = ([])[0]; +var baz4 = ({ a: 1 }).a; diff --git a/tests/baselines/reference/downlevelLetConst12.types b/tests/baselines/reference/downlevelLetConst12.types new file mode 100644 index 0000000000000..90a814e0753c8 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst12.types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/downlevelLetConst12.ts === + +'use strict' +// top level let\const should not be renamed +let foo; +>foo : any + +const bar = 1; +>bar : number + +let [baz] = []; +>baz : any +>[] : undefined[] + +let {a: baz2} = { a: 1 }; +>a : unknown +>baz2 : number +>{ a: 1 } : { a: number; } +>a : number + +const [baz3] = [] +>baz3 : any +>[] : undefined[] + +const {a: baz4} = { a: 1 }; +>a : unknown +>baz4 : number +>{ a: 1 } : { a: number; } +>a : number + diff --git a/tests/baselines/reference/downlevelLetConst13.js b/tests/baselines/reference/downlevelLetConst13.js new file mode 100644 index 0000000000000..8324d697e95fd --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst13.js @@ -0,0 +1,39 @@ +//// [downlevelLetConst13.ts] + +'use strict' +// exported let\const bindings should not be renamed + +export let foo = 10; +export const bar = "123" +export let [bar1] = [1]; +export const [bar2] = [2]; +export let {a: bar3} = { a: 1 }; +export const {a: bar4} = { a: 1 }; + +export module M { + export let baz = 100; + export const baz2 = true; + export let [bar5] = [1]; + export const [bar6] = [2]; + export let {a: bar7} = { a: 1 }; + export const {a: bar8} = { a: 1 }; +} + +//// [downlevelLetConst13.js] +'use strict'; +// exported let\const bindings should not be renamed +exports.foo = 10; +exports.bar = "123"; +exports.bar1 = ([1])[0]; +exports.bar2 = ([2])[0]; +exports.bar3 = ({ a: 1 }).a; +exports.bar4 = ({ a: 1 }).a; +var M; +(function (M) { + M.baz = 100; + M.baz2 = true; + M.bar5 = ([1])[0]; + M.bar6 = ([2])[0]; + M.bar7 = ({ a: 1 }).a; + M.bar8 = ({ a: 1 }).a; +})(M = exports.M || (exports.M = {})); diff --git a/tests/baselines/reference/downlevelLetConst13.types b/tests/baselines/reference/downlevelLetConst13.types new file mode 100644 index 0000000000000..e72e3936f4398 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst13.types @@ -0,0 +1,60 @@ +=== tests/cases/compiler/downlevelLetConst13.ts === + +'use strict' +// exported let\const bindings should not be renamed + +export let foo = 10; +>foo : number + +export const bar = "123" +>bar : string + +export let [bar1] = [1]; +>bar1 : number +>[1] : [number] + +export const [bar2] = [2]; +>bar2 : number +>[2] : [number] + +export let {a: bar3} = { a: 1 }; +>a : unknown +>bar3 : number +>{ a: 1 } : { a: number; } +>a : number + +export const {a: bar4} = { a: 1 }; +>a : unknown +>bar4 : number +>{ a: 1 } : { a: number; } +>a : number + +export module M { +>M : typeof M + + export let baz = 100; +>baz : number + + export const baz2 = true; +>baz2 : boolean + + export let [bar5] = [1]; +>bar5 : number +>[1] : [number] + + export const [bar6] = [2]; +>bar6 : number +>[2] : [number] + + export let {a: bar7} = { a: 1 }; +>a : unknown +>bar7 : number +>{ a: 1 } : { a: number; } +>a : number + + export const {a: bar8} = { a: 1 }; +>a : unknown +>bar8 : number +>{ a: 1 } : { a: number; } +>a : number +} diff --git a/tests/baselines/reference/downlevelLetConst14.js b/tests/baselines/reference/downlevelLetConst14.js new file mode 100644 index 0000000000000..212262dc43ae4 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst14.js @@ -0,0 +1,107 @@ +//// [downlevelLetConst14.ts] +'use strict' +declare function use(a: any); + +var x = 10; +var z0, z1, z2, z3; +{ + let x = 20; + use(x); + + let [z0] = [1]; + use(z0); + let [z1] = [1] + use(z1); + let {a: z2} = { a: 1 }; + use(z2); + let {a: z3} = { a: 1 }; + use(z3); +} +use(x); +use(z0); +use(z1); +use(z2); +use(z3); +var z6; +var y = true; +{ + let y = ""; + let [z6] = [true] + { + let y = 1; + let {a: z6} = {a: 1} + use(y); + use(z6); + } + use(y); + use(z6); +} +use(y); +use(z6); + +var z = false; +var z5 = 1; +{ + let z = ""; + let [z5] = [5]; + { + let _z = 1; + let {a: _z5} = { a: 1 }; + // try to step on generated name + use(_z); + } + use(z); +} +use(y); + +//// [downlevelLetConst14.js] +'use strict'; +var x = 10; +var z0, z1, z2, z3; +{ + var _x = 20; + use(_x); + var _z0 = ([1])[0]; + use(_z0); + var _z1 = ([1])[0]; + use(_z1); + var _z2 = ({ a: 1 }).a; + use(_z2); + var _z3 = ({ a: 1 }).a; + use(_z3); +} +use(x); +use(z0); +use(z1); +use(z2); +use(z3); +var z6; +var y = true; +{ + var _y = ""; + var _z6 = ([true])[0]; + { + var _y_1 = 1; + var _z6_1 = ({ a: 1 }).a; + use(_y_1); + use(_z6_1); + } + use(_y); + use(_z6); +} +use(y); +use(z6); +var z = false; +var z5 = 1; +{ + var _z = ""; + var _z5 = ([5])[0]; + { + var _z_1 = 1; + var _z5_1 = ({ a: 1 }).a; + // try to step on generated name + use(_z_1); + } + use(_z); +} +use(y); diff --git a/tests/baselines/reference/downlevelLetConst14.types b/tests/baselines/reference/downlevelLetConst14.types new file mode 100644 index 0000000000000..05b66948830ad --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst14.types @@ -0,0 +1,178 @@ +=== tests/cases/compiler/downlevelLetConst14.ts === +'use strict' +declare function use(a: any); +>use : (a: any) => any +>a : any + +var x = 10; +>x : number + +var z0, z1, z2, z3; +>z0 : any +>z1 : any +>z2 : any +>z3 : any +{ + let x = 20; +>x : number + + use(x); +>use(x) : any +>use : (a: any) => any +>x : number + + let [z0] = [1]; +>z0 : number +>[1] : [number] + + use(z0); +>use(z0) : any +>use : (a: any) => any +>z0 : number + + let [z1] = [1] +>z1 : number +>[1] : [number] + + use(z1); +>use(z1) : any +>use : (a: any) => any +>z1 : number + + let {a: z2} = { a: 1 }; +>a : unknown +>z2 : number +>{ a: 1 } : { a: number; } +>a : number + + use(z2); +>use(z2) : any +>use : (a: any) => any +>z2 : number + + let {a: z3} = { a: 1 }; +>a : unknown +>z3 : number +>{ a: 1 } : { a: number; } +>a : number + + use(z3); +>use(z3) : any +>use : (a: any) => any +>z3 : number +} +use(x); +>use(x) : any +>use : (a: any) => any +>x : number + +use(z0); +>use(z0) : any +>use : (a: any) => any +>z0 : any + +use(z1); +>use(z1) : any +>use : (a: any) => any +>z1 : any + +use(z2); +>use(z2) : any +>use : (a: any) => any +>z2 : any + +use(z3); +>use(z3) : any +>use : (a: any) => any +>z3 : any + +var z6; +>z6 : any + +var y = true; +>y : boolean +{ + let y = ""; +>y : string + + let [z6] = [true] +>z6 : boolean +>[true] : [boolean] + { + let y = 1; +>y : number + + let {a: z6} = {a: 1} +>a : unknown +>z6 : number +>{a: 1} : { a: number; } +>a : number + + use(y); +>use(y) : any +>use : (a: any) => any +>y : number + + use(z6); +>use(z6) : any +>use : (a: any) => any +>z6 : number + } + use(y); +>use(y) : any +>use : (a: any) => any +>y : string + + use(z6); +>use(z6) : any +>use : (a: any) => any +>z6 : boolean +} +use(y); +>use(y) : any +>use : (a: any) => any +>y : boolean + +use(z6); +>use(z6) : any +>use : (a: any) => any +>z6 : any + +var z = false; +>z : boolean + +var z5 = 1; +>z5 : number +{ + let z = ""; +>z : string + + let [z5] = [5]; +>z5 : number +>[5] : [number] + { + let _z = 1; +>_z : number + + let {a: _z5} = { a: 1 }; +>a : unknown +>_z5 : number +>{ a: 1 } : { a: number; } +>a : number + + // try to step on generated name + use(_z); +>use(_z) : any +>use : (a: any) => any +>_z : number + } + use(z); +>use(z) : any +>use : (a: any) => any +>z : string +} +use(y); +>use(y) : any +>use : (a: any) => any +>y : boolean + diff --git a/tests/baselines/reference/downlevelLetConst15.js b/tests/baselines/reference/downlevelLetConst15.js new file mode 100644 index 0000000000000..c9b677191975e --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst15.js @@ -0,0 +1,107 @@ +//// [downlevelLetConst15.ts] +'use strict' +declare function use(a: any); + +var x = 10; +var z0, z1, z2, z3; +{ + const x = 20; + use(x); + + const [z0] = [1]; + use(z0); + const [{a: z1}] = [{a: 1}] + use(z1); + const {a: z2} = { a: 1 }; + use(z2); + const {a: {b: z3}} = { a: {b: 1} }; + use(z3); +} +use(x); +use(z0); +use(z1); +use(z2); +use(z3); +var z6; +var y = true; +{ + const y = ""; + const [z6] = [true] + { + const y = 1; + const {a: z6} = { a: 1 } + use(y); + use(z6); + } + use(y); + use(z6); +} +use(y); +use(z6); + +var z = false; +var z5 = 1; +{ + const z = ""; + const [z5] = [5]; + { + const _z = 1; + const {a: _z5} = { a: 1 }; + // try to step on generated name + use(_z); + } + use(z); +} +use(y); + +//// [downlevelLetConst15.js] +'use strict'; +var x = 10; +var z0, z1, z2, z3; +{ + var _x = 20; + use(_x); + var _z0 = ([1])[0]; + use(_z0); + var _z1 = ([{ a: 1 }])[0].a; + use(_z1); + var _z2 = ({ a: 1 }).a; + use(_z2); + var _z3 = ({ a: { b: 1 } }).a.b; + use(_z3); +} +use(x); +use(z0); +use(z1); +use(z2); +use(z3); +var z6; +var y = true; +{ + var _y = ""; + var _z6 = ([true])[0]; + { + var _y_1 = 1; + var _z6_1 = ({ a: 1 }).a; + use(_y_1); + use(_z6_1); + } + use(_y); + use(_z6); +} +use(y); +use(z6); +var z = false; +var z5 = 1; +{ + var _z = ""; + var _z5 = ([5])[0]; + { + var _z_1 = 1; + var _z5_1 = ({ a: 1 }).a; + // try to step on generated name + use(_z_1); + } + use(_z); +} +use(y); diff --git a/tests/baselines/reference/downlevelLetConst15.types b/tests/baselines/reference/downlevelLetConst15.types new file mode 100644 index 0000000000000..008d132ab70bb --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst15.types @@ -0,0 +1,184 @@ +=== tests/cases/compiler/downlevelLetConst15.ts === +'use strict' +declare function use(a: any); +>use : (a: any) => any +>a : any + +var x = 10; +>x : number + +var z0, z1, z2, z3; +>z0 : any +>z1 : any +>z2 : any +>z3 : any +{ + const x = 20; +>x : number + + use(x); +>use(x) : any +>use : (a: any) => any +>x : number + + const [z0] = [1]; +>z0 : number +>[1] : [number] + + use(z0); +>use(z0) : any +>use : (a: any) => any +>z0 : number + + const [{a: z1}] = [{a: 1}] +>a : unknown +>z1 : number +>[{a: 1}] : [{ a: number; }] +>{a: 1} : { a: number; } +>a : number + + use(z1); +>use(z1) : any +>use : (a: any) => any +>z1 : number + + const {a: z2} = { a: 1 }; +>a : unknown +>z2 : number +>{ a: 1 } : { a: number; } +>a : number + + use(z2); +>use(z2) : any +>use : (a: any) => any +>z2 : number + + const {a: {b: z3}} = { a: {b: 1} }; +>a : unknown +>b : unknown +>z3 : number +>{ a: {b: 1} } : { a: { b: number; }; } +>a : { b: number; } +>{b: 1} : { b: number; } +>b : number + + use(z3); +>use(z3) : any +>use : (a: any) => any +>z3 : number +} +use(x); +>use(x) : any +>use : (a: any) => any +>x : number + +use(z0); +>use(z0) : any +>use : (a: any) => any +>z0 : any + +use(z1); +>use(z1) : any +>use : (a: any) => any +>z1 : any + +use(z2); +>use(z2) : any +>use : (a: any) => any +>z2 : any + +use(z3); +>use(z3) : any +>use : (a: any) => any +>z3 : any + +var z6; +>z6 : any + +var y = true; +>y : boolean +{ + const y = ""; +>y : string + + const [z6] = [true] +>z6 : boolean +>[true] : [boolean] + { + const y = 1; +>y : number + + const {a: z6} = { a: 1 } +>a : unknown +>z6 : number +>{ a: 1 } : { a: number; } +>a : number + + use(y); +>use(y) : any +>use : (a: any) => any +>y : number + + use(z6); +>use(z6) : any +>use : (a: any) => any +>z6 : number + } + use(y); +>use(y) : any +>use : (a: any) => any +>y : string + + use(z6); +>use(z6) : any +>use : (a: any) => any +>z6 : boolean +} +use(y); +>use(y) : any +>use : (a: any) => any +>y : boolean + +use(z6); +>use(z6) : any +>use : (a: any) => any +>z6 : any + +var z = false; +>z : boolean + +var z5 = 1; +>z5 : number +{ + const z = ""; +>z : string + + const [z5] = [5]; +>z5 : number +>[5] : [number] + { + const _z = 1; +>_z : number + + const {a: _z5} = { a: 1 }; +>a : unknown +>_z5 : number +>{ a: 1 } : { a: number; } +>a : number + + // try to step on generated name + use(_z); +>use(_z) : any +>use : (a: any) => any +>_z : number + } + use(z); +>use(z) : any +>use : (a: any) => any +>z : string +} +use(y); +>use(y) : any +>use : (a: any) => any +>y : boolean + diff --git a/tests/baselines/reference/downlevelLetConst16.errors.txt b/tests/baselines/reference/downlevelLetConst16.errors.txt new file mode 100644 index 0000000000000..dafdd5b7b074d --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst16.errors.txt @@ -0,0 +1,249 @@ +tests/cases/compiler/downlevelLetConst16.ts(189,5): error TS9003: 'for...of' statements are not currently supported. +tests/cases/compiler/downlevelLetConst16.ts(196,5): error TS9003: 'for...of' statements are not currently supported. +tests/cases/compiler/downlevelLetConst16.ts(203,5): error TS9003: 'for...of' statements are not currently supported. +tests/cases/compiler/downlevelLetConst16.ts(210,5): error TS9003: 'for...of' statements are not currently supported. +tests/cases/compiler/downlevelLetConst16.ts(217,5): error TS9003: 'for...of' statements are not currently supported. +tests/cases/compiler/downlevelLetConst16.ts(224,5): error TS9003: 'for...of' statements are not currently supported. + + +==== tests/cases/compiler/downlevelLetConst16.ts (6 errors) ==== + 'use strict' + + declare function use(a: any); + + var x = 10; + var y; + var z; + use(x); + use(y); + use(z); + function foo1() { + let x = 1; + use(x); + let [y] = [1]; + use(y); + let {a: z} = {a: 1}; + use(z); + } + + function foo2() { + { + let x = 1; + use(x); + let [y] = [1]; + use(y); + let {a: z} = { a: 1 }; + use(z); + } + use(x); + } + + class A { + m1() { + let x = 1; + use(x); + let [y] = [1]; + use(y); + let {a: z} = { a: 1 }; + use(z); + } + m2() { + { + let x = 1; + use(x); + let [y] = [1]; + use(y); + let {a: z} = { a: 1 }; + use(z); + } + use(x); + } + + } + + class B { + m1() { + const x = 1; + use(x); + const [y] = [1]; + use(y); + const {a: z} = { a: 1 }; + use(z); + + } + m2() { + { + const x = 1; + use(x); + const [y] = [1]; + use(y); + const {a: z} = { a: 1 }; + use(z); + + } + use(x); + } + } + + function bar1() { + const x = 1; + use(x); + const [y] = [1]; + use(y); + const {a: z} = { a: 1 }; + use(z); + } + + function bar2() { + { + const x = 1; + use(x); + const [y] = [1]; + use(y); + const {a: z} = { a: 1 }; + use(z); + + } + use(x); + } + + module M1 { + let x = 1; + use(x); + let [y] = [1]; + use(y); + let {a: z} = { a: 1 }; + use(z); + } + + module M2 { + { + let x = 1; + use(x); + let [y] = [1]; + use(y); + let {a: z} = { a: 1 }; + use(z); + } + use(x); + } + + module M3 { + const x = 1; + use(x); + const [y] = [1]; + use(y); + const {a: z} = { a: 1 }; + use(z); + + } + + module M4 { + { + const x = 1; + use(x); + const [y] = [1]; + use(y); + const {a: z} = { a: 1 }; + use(z); + + } + use(x); + use(y); + use(z); + } + + function foo3() { + for (let x; ;) { + use(x); + } + for (let [y] = []; ;) { + use(y); + } + for (let {a: z} = {a: 1}; ;) { + use(z); + } + use(x); + } + + function foo4() { + for (const x = 1; ;) { + use(x); + } + for (const [y] = []; ;) { + use(y); + } + for (const {a: z} = { a: 1 }; ;) { + use(z); + } + use(x); + } + + function foo5() { + for (let x in []) { + use(x); + } + use(x); + } + + function foo6() { + for (const x in []) { + use(x); + } + use(x); + } + + // TODO: once for-of is supported downlevel + function foo7() { + for (let x of []) { + ~~~ +!!! error TS9003: 'for...of' statements are not currently supported. + use(x); + } + use(x); + } + + function foo8() { + for (let [x] of []) { + ~~~ +!!! error TS9003: 'for...of' statements are not currently supported. + use(x); + } + use(x); + } + + function foo9() { + for (let {a: x} of []) { + ~~~ +!!! error TS9003: 'for...of' statements are not currently supported. + use(x); + } + use(x); + } + + function foo10() { + for (const x of []) { + ~~~ +!!! error TS9003: 'for...of' statements are not currently supported. + use(x); + } + use(x); + } + + function foo11() { + for (const [x] of []) { + ~~~ +!!! error TS9003: 'for...of' statements are not currently supported. + use(x); + } + use(x); + } + + function foo12() { + for (const {a: x} of []) { + ~~~ +!!! error TS9003: 'for...of' statements are not currently supported. + use(x); + } + use(x); + } \ No newline at end of file diff --git a/tests/baselines/reference/downlevelLetConst16.js b/tests/baselines/reference/downlevelLetConst16.js new file mode 100644 index 0000000000000..36da8ac36fe6c --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst16.js @@ -0,0 +1,441 @@ +//// [downlevelLetConst16.ts] +'use strict' + +declare function use(a: any); + +var x = 10; +var y; +var z; +use(x); +use(y); +use(z); +function foo1() { + let x = 1; + use(x); + let [y] = [1]; + use(y); + let {a: z} = {a: 1}; + use(z); +} + +function foo2() { + { + let x = 1; + use(x); + let [y] = [1]; + use(y); + let {a: z} = { a: 1 }; + use(z); + } + use(x); +} + +class A { + m1() { + let x = 1; + use(x); + let [y] = [1]; + use(y); + let {a: z} = { a: 1 }; + use(z); + } + m2() { + { + let x = 1; + use(x); + let [y] = [1]; + use(y); + let {a: z} = { a: 1 }; + use(z); + } + use(x); + } + +} + +class B { + m1() { + const x = 1; + use(x); + const [y] = [1]; + use(y); + const {a: z} = { a: 1 }; + use(z); + + } + m2() { + { + const x = 1; + use(x); + const [y] = [1]; + use(y); + const {a: z} = { a: 1 }; + use(z); + + } + use(x); + } +} + +function bar1() { + const x = 1; + use(x); + const [y] = [1]; + use(y); + const {a: z} = { a: 1 }; + use(z); +} + +function bar2() { + { + const x = 1; + use(x); + const [y] = [1]; + use(y); + const {a: z} = { a: 1 }; + use(z); + + } + use(x); +} + +module M1 { + let x = 1; + use(x); + let [y] = [1]; + use(y); + let {a: z} = { a: 1 }; + use(z); +} + +module M2 { + { + let x = 1; + use(x); + let [y] = [1]; + use(y); + let {a: z} = { a: 1 }; + use(z); + } + use(x); +} + +module M3 { + const x = 1; + use(x); + const [y] = [1]; + use(y); + const {a: z} = { a: 1 }; + use(z); + +} + +module M4 { + { + const x = 1; + use(x); + const [y] = [1]; + use(y); + const {a: z} = { a: 1 }; + use(z); + + } + use(x); + use(y); + use(z); +} + +function foo3() { + for (let x; ;) { + use(x); + } + for (let [y] = []; ;) { + use(y); + } + for (let {a: z} = {a: 1}; ;) { + use(z); + } + use(x); +} + +function foo4() { + for (const x = 1; ;) { + use(x); + } + for (const [y] = []; ;) { + use(y); + } + for (const {a: z} = { a: 1 }; ;) { + use(z); + } + use(x); +} + +function foo5() { + for (let x in []) { + use(x); + } + use(x); +} + +function foo6() { + for (const x in []) { + use(x); + } + use(x); +} + +// TODO: once for-of is supported downlevel +function foo7() { + for (let x of []) { + use(x); + } + use(x); +} + +function foo8() { + for (let [x] of []) { + use(x); + } + use(x); +} + +function foo9() { + for (let {a: x} of []) { + use(x); + } + use(x); +} + +function foo10() { + for (const x of []) { + use(x); + } + use(x); +} + +function foo11() { + for (const [x] of []) { + use(x); + } + use(x); +} + +function foo12() { + for (const {a: x} of []) { + use(x); + } + use(x); +} + +//// [downlevelLetConst16.js] +'use strict'; +var x = 10; +var y; +var z; +use(x); +use(y); +use(z); +function foo1() { + var _x = 1; + use(_x); + var _y = ([1])[0]; + use(_y); + var _z = ({ a: 1 }).a; + use(_z); +} +function foo2() { + { + var _x = 1; + use(_x); + var _y = ([1])[0]; + use(_y); + var _z = ({ a: 1 }).a; + use(_z); + } + use(x); +} +var A = (function () { + function A() { + } + A.prototype.m1 = function () { + var _x = 1; + use(_x); + var _y = ([1])[0]; + use(_y); + var _z = ({ a: 1 }).a; + use(_z); + }; + A.prototype.m2 = function () { + { + var _x = 1; + use(_x); + var _y = ([1])[0]; + use(_y); + var _z = ({ a: 1 }).a; + use(_z); + } + use(x); + }; + return A; +})(); +var B = (function () { + function B() { + } + B.prototype.m1 = function () { + var _x = 1; + use(_x); + var _y = ([1])[0]; + use(_y); + var _z = ({ a: 1 }).a; + use(_z); + }; + B.prototype.m2 = function () { + { + var _x = 1; + use(_x); + var _y = ([1])[0]; + use(_y); + var _z = ({ a: 1 }).a; + use(_z); + } + use(x); + }; + return B; +})(); +function bar1() { + var _x = 1; + use(_x); + var _y = ([1])[0]; + use(_y); + var _z = ({ a: 1 }).a; + use(_z); +} +function bar2() { + { + var _x = 1; + use(_x); + var _y = ([1])[0]; + use(_y); + var _z = ({ a: 1 }).a; + use(_z); + } + use(x); +} +var M1; +(function (M1) { + var _x = 1; + use(_x); + var _y = ([1])[0]; + use(_y); + var _z = ({ a: 1 }).a; + use(_z); +})(M1 || (M1 = {})); +var M2; +(function (M2) { + { + var _x = 1; + use(_x); + var _y = ([1])[0]; + use(_y); + var _z = ({ a: 1 }).a; + use(_z); + } + use(x); +})(M2 || (M2 = {})); +var M3; +(function (M3) { + var _x = 1; + use(_x); + var _y = ([1])[0]; + use(_y); + var _z = ({ a: 1 }).a; + use(_z); +})(M3 || (M3 = {})); +var M4; +(function (M4) { + { + var _x = 1; + use(_x); + var _y = ([1])[0]; + use(_y); + var _z = ({ a: 1 }).a; + use(_z); + } + use(x); + use(y); + use(z); +})(M4 || (M4 = {})); +function foo3() { + for (var _x = void 0;;) { + use(_x); + } + for (var _y = ([])[0];;) { + use(_y); + } + for (var _z = ({ a: 1 }).a;;) { + use(_z); + } + use(x); +} +function foo4() { + for (var _x = 1;;) { + use(_x); + } + for (var _y = ([])[0];;) { + use(_y); + } + for (var _z = ({ a: 1 }).a;;) { + use(_z); + } + use(x); +} +function foo5() { + for (var _x in []) { + use(_x); + } + use(x); +} +function foo6() { + for (var _x in []) { + use(_x); + } + use(x); +} +// TODO: once for-of is supported downlevel +function foo7() { + for (var _x of []) { + use(_x); + } + use(x); +} +function foo8() { + for (var _x = (void 0)[0] of []) { + use(_x); + } + use(x); +} +function foo9() { + for (var _x = (void 0).a of []) { + use(_x); + } + use(x); +} +function foo10() { + for (var _x of []) { + use(_x); + } + use(x); +} +function foo11() { + for (var _x = (void 0)[0] of []) { + use(_x); + } + use(x); +} +function foo12() { + for (var _x = (void 0).a of []) { + use(_x); + } + use(x); +} diff --git a/tests/baselines/reference/downlevelLetConst17.errors.txt b/tests/baselines/reference/downlevelLetConst17.errors.txt new file mode 100644 index 0000000000000..a185ca4abe1e1 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst17.errors.txt @@ -0,0 +1,74 @@ +tests/cases/compiler/downlevelLetConst17.ts(66,1): error TS9003: 'for...of' statements are not currently supported. + + +==== tests/cases/compiler/downlevelLetConst17.ts (1 errors) ==== + 'use strict' + + declare function use(a: any); + + var x; + for (let x = 10; ;) { + use(x); + } + use(x); + + for (const x = 10; ;) { + use(x); + } + + for (; ;) { + let x = 10; + use(x); + x = 1; + } + + for (; ;) { + const x = 10; + use(x); + } + + for (let x; ;) { + use(x); + x = 1; + } + + for (; ;) { + let x; + use(x); + x = 1; + } + + while (true) { + let x; + use(x); + } + + while (true) { + const x = true; + use(x); + } + + do { + let x; + use(x); + } while (true); + + do { + let x; + use(x); + } while (true); + + for (let x in []) { + use(x); + } + + for (const x in []) { + use(x); + } + + // TODO: update once for-of statements are supported downlevel + for (const x of []) { + ~~~ +!!! error TS9003: 'for...of' statements are not currently supported. + use(x); + } \ No newline at end of file diff --git a/tests/baselines/reference/downlevelLetConst17.js b/tests/baselines/reference/downlevelLetConst17.js new file mode 100644 index 0000000000000..1fe9c1a01edf4 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst17.js @@ -0,0 +1,124 @@ +//// [downlevelLetConst17.ts] +'use strict' + +declare function use(a: any); + +var x; +for (let x = 10; ;) { + use(x); +} +use(x); + +for (const x = 10; ;) { + use(x); +} + +for (; ;) { + let x = 10; + use(x); + x = 1; +} + +for (; ;) { + const x = 10; + use(x); +} + +for (let x; ;) { + use(x); + x = 1; +} + +for (; ;) { + let x; + use(x); + x = 1; +} + +while (true) { + let x; + use(x); +} + +while (true) { + const x = true; + use(x); +} + +do { + let x; + use(x); +} while (true); + +do { + let x; + use(x); +} while (true); + +for (let x in []) { + use(x); +} + +for (const x in []) { + use(x); +} + +// TODO: update once for-of statements are supported downlevel +for (const x of []) { + use(x); +} + +//// [downlevelLetConst17.js] +'use strict'; +var x; +for (var _x = 10;;) { + use(_x); +} +use(x); +for (var _x_1 = 10;;) { + use(_x_1); +} +for (;;) { + var _x_2 = 10; + use(_x_2); + _x_2 = 1; +} +for (;;) { + var _x_3 = 10; + use(_x_3); +} +for (var _x_4 = void 0;;) { + use(_x_4); + _x_4 = 1; +} +for (;;) { + var _x_5 = void 0; + use(_x_5); + _x_5 = 1; +} +while (true) { + var _x_6 = void 0; + use(_x_6); +} +while (true) { + var _x_7 = true; + use(_x_7); +} +do { + var _x_8 = void 0; + use(_x_8); +} while (true); +do { + var _x_9 = void 0; + use(_x_9); +} while (true); +for (var _x_10 in []) { + use(_x_10); +} +for (var _x_11 in []) { + use(_x_11); +} +// TODO: update once for-of statements are supported downlevel +for (var _x_12 of []) { + use(_x_12); +} diff --git a/tests/baselines/reference/downlevelLetConst18.errors.txt b/tests/baselines/reference/downlevelLetConst18.errors.txt new file mode 100644 index 0000000000000..93a2578defa77 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst18.errors.txt @@ -0,0 +1,60 @@ +tests/cases/compiler/downlevelLetConst18.ts(3,1): error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. +tests/cases/compiler/downlevelLetConst18.ts(4,14): error TS2393: Duplicate function implementation. +tests/cases/compiler/downlevelLetConst18.ts(7,1): error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. +tests/cases/compiler/downlevelLetConst18.ts(8,14): error TS2393: Duplicate function implementation. +tests/cases/compiler/downlevelLetConst18.ts(11,1): error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. +tests/cases/compiler/downlevelLetConst18.ts(15,1): error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. +tests/cases/compiler/downlevelLetConst18.ts(19,1): error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. +tests/cases/compiler/downlevelLetConst18.ts(23,1): error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. +tests/cases/compiler/downlevelLetConst18.ts(27,1): error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. + + +==== tests/cases/compiler/downlevelLetConst18.ts (9 errors) ==== + 'use strict' + + for (let x; ;) { + ~~~ +!!! error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. + function foo() { x }; + ~~~ +!!! error TS2393: Duplicate function implementation. + } + + for (let x; ;) { + ~~~ +!!! error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. + function foo() { x }; + ~~~ +!!! error TS2393: Duplicate function implementation. + } + + for (let x; ;) { + ~~~ +!!! error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. + (() => { x })(); + } + + for (const x = 1; ;) { + ~~~ +!!! error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. + (() => { x })(); + } + + for (let x; ;) { + ~~~ +!!! error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. + ({ foo() { x }}) + } + + for (let x; ;) { + ~~~ +!!! error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. + ({ get foo() { return x } }) + } + + for (let x; ;) { + ~~~ +!!! error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. + ({ set foo(v) { x } }) + } + \ No newline at end of file diff --git a/tests/baselines/reference/downlevelLetConst18.js b/tests/baselines/reference/downlevelLetConst18.js new file mode 100644 index 0000000000000..e9993a90bce61 --- /dev/null +++ b/tests/baselines/reference/downlevelLetConst18.js @@ -0,0 +1,57 @@ +//// [downlevelLetConst18.ts] +'use strict' + +for (let x; ;) { + function foo() { x }; +} + +for (let x; ;) { + function foo() { x }; +} + +for (let x; ;) { + (() => { x })(); +} + +for (const x = 1; ;) { + (() => { x })(); +} + +for (let x; ;) { + ({ foo() { x }}) +} + +for (let x; ;) { + ({ get foo() { return x } }) +} + +for (let x; ;) { + ({ set foo(v) { x } }) +} + + +//// [downlevelLetConst18.js] +'use strict'; +for (var x = void 0;;) { + function foo() { x; } + ; +} +for (var _x = void 0;;) { + function foo() { _x; } + ; +} +for (var _x_1 = void 0;;) { + (function () { _x_1; })(); +} +for (var _x_2 = 1;;) { + (function () { _x_2; })(); +} +for (var _x_3 = void 0;;) { + ({ foo: function () { _x_3; } }); +} +for (var _x_4 = void 0;;) { + ({ get foo() { return _x_4; } }); +} +for (var _x_5 = void 0;;) { + ({ set foo(v) { _x_5; } }); +} diff --git a/tests/baselines/reference/parserES5ComputedPropertyName2.js b/tests/baselines/reference/parserES5ComputedPropertyName2.js index 2b39e305e07dd..b7fce15bc9289 100644 --- a/tests/baselines/reference/parserES5ComputedPropertyName2.js +++ b/tests/baselines/reference/parserES5ComputedPropertyName2.js @@ -3,6 +3,5 @@ var v = { [e]: 1 }; //// [parserES5ComputedPropertyName2.js] var v = (_a = {}, _a[e] = -1, -_a); +1, _a); var _a; diff --git a/tests/baselines/reference/parserES5ComputedPropertyName3.js b/tests/baselines/reference/parserES5ComputedPropertyName3.js index 3247b0251f13f..1fdb5ced65dcd 100644 --- a/tests/baselines/reference/parserES5ComputedPropertyName3.js +++ b/tests/baselines/reference/parserES5ComputedPropertyName3.js @@ -2,6 +2,5 @@ var v = { [e]() { } }; //// [parserES5ComputedPropertyName3.js] -var v = (_a = {}, _a[e] = function () { }, -_a); +var v = (_a = {}, _a[e] = function () { }, _a); var _a; diff --git a/tests/baselines/reference/parserES5ComputedPropertyName4.js b/tests/baselines/reference/parserES5ComputedPropertyName4.js index 436f967e8decd..3271fa41207ee 100644 --- a/tests/baselines/reference/parserES5ComputedPropertyName4.js +++ b/tests/baselines/reference/parserES5ComputedPropertyName4.js @@ -2,6 +2,5 @@ var v = { get [e]() { } }; //// [parserES5ComputedPropertyName4.js] -var v = (_a = {}, _a[e] = Object.defineProperty({ get: function () { }, enumerable: true, configurable: true }), -_a); +var v = (_a = {}, _a[e] = Object.defineProperty({ get: function () { }, enumerable: true, configurable: true }), _a); var _a; diff --git a/tests/baselines/reference/privateIndexer2.js b/tests/baselines/reference/privateIndexer2.js index 5a36a9eae18bb..0c9112ba28015 100644 --- a/tests/baselines/reference/privateIndexer2.js +++ b/tests/baselines/reference/privateIndexer2.js @@ -13,7 +13,6 @@ var y: { // private indexers not allowed var x = (_a = {}, _a[x] = string, _a.string = -, -_a); +, _a); var y; var _a; diff --git a/tests/cases/compiler/constDeclarations-errors.ts b/tests/cases/compiler/constDeclarations-errors.ts index 09dc0e9679068..1c3ef8848b0b9 100644 --- a/tests/cases/compiler/constDeclarations-errors.ts +++ b/tests/cases/compiler/constDeclarations-errors.ts @@ -5,7 +5,6 @@ const c1; const c2: number; const c3, c4, c5 :string, c6; // error, missing initialicer -// error, can not be unintalized for(const c in {}) { } // error, assigning to a const diff --git a/tests/cases/compiler/downlevelLetConst12.ts b/tests/cases/compiler/downlevelLetConst12.ts new file mode 100644 index 0000000000000..5acefcdf7bf49 --- /dev/null +++ b/tests/cases/compiler/downlevelLetConst12.ts @@ -0,0 +1,12 @@ +// @target:es5 + +'use strict' +// top level let\const should not be renamed +let foo; +const bar = 1; + +let [baz] = []; +let {a: baz2} = { a: 1 }; + +const [baz3] = [] +const {a: baz4} = { a: 1 }; \ No newline at end of file diff --git a/tests/cases/compiler/downlevelLetConst13.ts b/tests/cases/compiler/downlevelLetConst13.ts new file mode 100644 index 0000000000000..af803e079bc3f --- /dev/null +++ b/tests/cases/compiler/downlevelLetConst13.ts @@ -0,0 +1,21 @@ +// @target:es5 +// @module: commonjs + +'use strict' +// exported let\const bindings should not be renamed + +export let foo = 10; +export const bar = "123" +export let [bar1] = [1]; +export const [bar2] = [2]; +export let {a: bar3} = { a: 1 }; +export const {a: bar4} = { a: 1 }; + +export module M { + export let baz = 100; + export const baz2 = true; + export let [bar5] = [1]; + export const [bar6] = [2]; + export let {a: bar7} = { a: 1 }; + export const {a: bar8} = { a: 1 }; +} \ No newline at end of file diff --git a/tests/cases/compiler/downlevelLetConst14.ts b/tests/cases/compiler/downlevelLetConst14.ts new file mode 100644 index 0000000000000..0a77883809618 --- /dev/null +++ b/tests/cases/compiler/downlevelLetConst14.ts @@ -0,0 +1,55 @@ +// @target:es5 +'use strict' +declare function use(a: any); + +var x = 10; +var z0, z1, z2, z3; +{ + let x = 20; + use(x); + + let [z0] = [1]; + use(z0); + let [z1] = [1] + use(z1); + let {a: z2} = { a: 1 }; + use(z2); + let {a: z3} = { a: 1 }; + use(z3); +} +use(x); +use(z0); +use(z1); +use(z2); +use(z3); +var z6; +var y = true; +{ + let y = ""; + let [z6] = [true] + { + let y = 1; + let {a: z6} = {a: 1} + use(y); + use(z6); + } + use(y); + use(z6); +} +use(y); +use(z6); + +var z = false; +var z5 = 1; +{ + let z = ""; + let [z5] = [5]; + { + let _z = 1; + let {a: _z5} = { a: 1 }; + // try to step on generated name + use(_z); + } + use(z); +} +use(y); \ No newline at end of file diff --git a/tests/cases/compiler/downlevelLetConst15.ts b/tests/cases/compiler/downlevelLetConst15.ts new file mode 100644 index 0000000000000..abe06e1709bd9 --- /dev/null +++ b/tests/cases/compiler/downlevelLetConst15.ts @@ -0,0 +1,55 @@ +// @target:es5 +'use strict' +declare function use(a: any); + +var x = 10; +var z0, z1, z2, z3; +{ + const x = 20; + use(x); + + const [z0] = [1]; + use(z0); + const [{a: z1}] = [{a: 1}] + use(z1); + const {a: z2} = { a: 1 }; + use(z2); + const {a: {b: z3}} = { a: {b: 1} }; + use(z3); +} +use(x); +use(z0); +use(z1); +use(z2); +use(z3); +var z6; +var y = true; +{ + const y = ""; + const [z6] = [true] + { + const y = 1; + const {a: z6} = { a: 1 } + use(y); + use(z6); + } + use(y); + use(z6); +} +use(y); +use(z6); + +var z = false; +var z5 = 1; +{ + const z = ""; + const [z5] = [5]; + { + const _z = 1; + const {a: _z5} = { a: 1 }; + // try to step on generated name + use(_z); + } + use(z); +} +use(y); \ No newline at end of file diff --git a/tests/cases/compiler/downlevelLetConst16.ts b/tests/cases/compiler/downlevelLetConst16.ts new file mode 100644 index 0000000000000..2d592d253c9ff --- /dev/null +++ b/tests/cases/compiler/downlevelLetConst16.ts @@ -0,0 +1,229 @@ +// @target:es5 +'use strict' + +declare function use(a: any); + +var x = 10; +var y; +var z; +use(x); +use(y); +use(z); +function foo1() { + let x = 1; + use(x); + let [y] = [1]; + use(y); + let {a: z} = {a: 1}; + use(z); +} + +function foo2() { + { + let x = 1; + use(x); + let [y] = [1]; + use(y); + let {a: z} = { a: 1 }; + use(z); + } + use(x); +} + +class A { + m1() { + let x = 1; + use(x); + let [y] = [1]; + use(y); + let {a: z} = { a: 1 }; + use(z); + } + m2() { + { + let x = 1; + use(x); + let [y] = [1]; + use(y); + let {a: z} = { a: 1 }; + use(z); + } + use(x); + } + +} + +class B { + m1() { + const x = 1; + use(x); + const [y] = [1]; + use(y); + const {a: z} = { a: 1 }; + use(z); + + } + m2() { + { + const x = 1; + use(x); + const [y] = [1]; + use(y); + const {a: z} = { a: 1 }; + use(z); + + } + use(x); + } +} + +function bar1() { + const x = 1; + use(x); + const [y] = [1]; + use(y); + const {a: z} = { a: 1 }; + use(z); +} + +function bar2() { + { + const x = 1; + use(x); + const [y] = [1]; + use(y); + const {a: z} = { a: 1 }; + use(z); + + } + use(x); +} + +module M1 { + let x = 1; + use(x); + let [y] = [1]; + use(y); + let {a: z} = { a: 1 }; + use(z); +} + +module M2 { + { + let x = 1; + use(x); + let [y] = [1]; + use(y); + let {a: z} = { a: 1 }; + use(z); + } + use(x); +} + +module M3 { + const x = 1; + use(x); + const [y] = [1]; + use(y); + const {a: z} = { a: 1 }; + use(z); + +} + +module M4 { + { + const x = 1; + use(x); + const [y] = [1]; + use(y); + const {a: z} = { a: 1 }; + use(z); + + } + use(x); + use(y); + use(z); +} + +function foo3() { + for (let x; ;) { + use(x); + } + for (let [y] = []; ;) { + use(y); + } + for (let {a: z} = {a: 1}; ;) { + use(z); + } + use(x); +} + +function foo4() { + for (const x = 1; ;) { + use(x); + } + for (const [y] = []; ;) { + use(y); + } + for (const {a: z} = { a: 1 }; ;) { + use(z); + } + use(x); +} + +function foo5() { + for (let x in []) { + use(x); + } + use(x); +} + +function foo6() { + for (const x in []) { + use(x); + } + use(x); +} + +// TODO: once for-of is supported downlevel +function foo7() { + for (let x of []) { + use(x); + } + use(x); +} + +function foo8() { + for (let [x] of []) { + use(x); + } + use(x); +} + +function foo9() { + for (let {a: x} of []) { + use(x); + } + use(x); +} + +function foo10() { + for (const x of []) { + use(x); + } + use(x); +} + +function foo11() { + for (const [x] of []) { + use(x); + } + use(x); +} + +function foo12() { + for (const {a: x} of []) { + use(x); + } + use(x); +} \ No newline at end of file diff --git a/tests/cases/compiler/downlevelLetConst17.ts b/tests/cases/compiler/downlevelLetConst17.ts new file mode 100644 index 0000000000000..5cbb7b605fee5 --- /dev/null +++ b/tests/cases/compiler/downlevelLetConst17.ts @@ -0,0 +1,69 @@ +// @target:es5 +'use strict' + +declare function use(a: any); + +var x; +for (let x = 10; ;) { + use(x); +} +use(x); + +for (const x = 10; ;) { + use(x); +} + +for (; ;) { + let x = 10; + use(x); + x = 1; +} + +for (; ;) { + const x = 10; + use(x); +} + +for (let x; ;) { + use(x); + x = 1; +} + +for (; ;) { + let x; + use(x); + x = 1; +} + +while (true) { + let x; + use(x); +} + +while (true) { + const x = true; + use(x); +} + +do { + let x; + use(x); +} while (true); + +do { + let x; + use(x); +} while (true); + +for (let x in []) { + use(x); +} + +for (const x in []) { + use(x); +} + +// TODO: update once for-of statements are supported downlevel +for (const x of []) { + use(x); +} \ No newline at end of file diff --git a/tests/cases/compiler/downlevelLetConst18.ts b/tests/cases/compiler/downlevelLetConst18.ts new file mode 100644 index 0000000000000..59f2ee7a46ee3 --- /dev/null +++ b/tests/cases/compiler/downlevelLetConst18.ts @@ -0,0 +1,30 @@ +// @target:es5 +'use strict' + +for (let x; ;) { + function foo() { x }; +} + +for (let x; ;) { + function foo() { x }; +} + +for (let x; ;) { + (() => { x })(); +} + +for (const x = 1; ;) { + (() => { x })(); +} + +for (let x; ;) { + ({ foo() { x }}) +} + +for (let x; ;) { + ({ get foo() { return x } }) +} + +for (let x; ;) { + ({ set foo(v) { x } }) +} From 4bf0bb640579000bcb5c4a531c5654ee1774bb59 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 26 Feb 2015 17:19:47 -0800 Subject: [PATCH 17/18] added comments --- src/compiler/checker.ts | 4 ++-- src/compiler/emitter.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fd3d2141dc08d..46d7dc5d3827f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -280,7 +280,7 @@ module ts { Debug.assert((symbol.flags & SymbolFlags.Instantiated) === 0, "Should never get an instantiated symbol here."); if (symbol.flags & meaning) { return symbol; - } + } if (symbol.flags & SymbolFlags.Import) { var target = resolveImport(symbol); @@ -10716,7 +10716,7 @@ module ts { } function isUnknownIdentifier(location: Node, name: string): boolean { - return !resolveName(location, name, SymbolFlags.Value | SymbolFlags.Import, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined) && + return !resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined) && !hasProperty(getGeneratedNamesForSourceFile(getSourceFile(location)), name); } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 1cfbbd2009697..a887df0dcc558 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -33,11 +33,17 @@ module ts { trailingCommentRanges?: CommentRange[]; } + // represents one LexicalEnvironment frame to store unique generated names interface ScopeFrame { names: Map; previous: ScopeFrame; } + // isExisingName function has signature string -> boolean, however check if name is unique should be performed + // in the context of some location. Instead of creating function expression and closing over location + // every time isExisingName is called we use one single instance of NameLookup that is effectively a + // handrolled closure where value of location can be swapped. This allows to avoid allocations of closures on + // every call and use one shared instance instead interface NameLookup { setLocation(location: Node): void; isExistingName(name: string): boolean; @@ -1663,6 +1669,8 @@ module ts { writeEmittedFiles(writer.getText(), /*writeByteOrderMark*/ compilerOptions.emitBOM); return; + // enters the new lexical environment + // return value should be passed to matching call to exitNameScope. function enterNameScope(): boolean { var names = currentScopeNames; currentScopeNames = undefined; @@ -1683,6 +1691,8 @@ module ts { } } + // creates instance of NameLookup to be used in 'isExisingName' checks. + // see comment for NameLookup for more information function createNameLookup(): NameLookup { var location: Node; return { From 3b3a94c7d7bea54baec55507d67dc458004da59d Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 27 Feb 2015 17:24:24 -0800 Subject: [PATCH 18/18] addressed PR feedback --- src/compiler/binder.ts | 12 +++--- src/compiler/checker.ts | 33 ++++++++------ .../diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- src/compiler/emitter.ts | 43 ++----------------- src/compiler/utilities.ts | 7 +-- .../reference/downlevelLetConst18.errors.txt | 28 ++++++------ 7 files changed, 49 insertions(+), 78 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 7245ee4e82c15..f5b23ffb59b84 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -244,10 +244,13 @@ module ts { } if (isBlockScopeContainer) { - // clean locals in block scope container if - // - current node does not have local variables - // - current node is not source file (source file always have locals) - setBlockScopeContainer(node, /*cleanLocals*/ (symbolKind & SymbolFlags.HasLocals) == 0 && node.kind !== SyntaxKind.SourceFile); + // in incremental scenarios we might reuse nodes that already have locals being allocated + // during the bind step these locals should be dropped to prevent using stale data. + // locals should always be dropped unless they were previously initialized by the binder + // these cases are: + // - node has locals (symbolKind & HasLocals) !== 0 + // - node is a source file + setBlockScopeContainer(node, /*cleanLocals*/ (symbolKind & SymbolFlags.HasLocals) === 0 && node.kind !== SyntaxKind.SourceFile); } forEachChild(node, bind); @@ -354,7 +357,6 @@ module ts { function bindCatchVariableDeclaration(node: CatchClause) { bindChildren(node, /*symbolKind:*/ 0, /*isBlockScopeContainer:*/ true); - } function bindBlockScopedVariableDeclaration(node: Declaration) { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7f6482bb272ac..2776c6595a856 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5080,6 +5080,18 @@ module ts { return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node); } + function isInsideFunction(node: Node, threshold: Node): boolean { + var current = node; + while (current && current !== threshold) { + if (isAnyFunction(current)) { + return true; + } + current = current.parent; + } + + return false; + } + function checkBlockScopedBindingCapturedInLoop(node: Identifier, symbol: Symbol): void { if (languageVersion >= ScriptTarget.ES6 || (symbol.flags & SymbolFlags.BlockScopedVariable) === 0 || @@ -5104,21 +5116,13 @@ module ts { container = container.parent; } - var inFunction = false; - var current = node.parent; - while (current && current !== container) { - if (isAnyFunction(current)) { - inFunction = true; - break; - } - current = current.parent; - } + var inFunction = isInsideFunction(node.parent, container); - var current: Node = container; + var current = container; while (current && !nodeStartsNewLexicalEnvironment(current)) { if (isIterationStatement(current, /*lookInLabeledStatements*/ false)) { if (inFunction) { - grammarErrorOnFirstToken(current, Diagnostics.Code_in_the_loop_captures_block_scoped_variable_0_in_closure_This_is_natively_supported_in_ECMAScript_6_or_higher, declarationNameToString(node)); + grammarErrorOnFirstToken(current, Diagnostics.Loop_contains_block_scoped_variable_0_referenced_by_a_function_in_the_loop_This_is_only_supported_in_ECMAScript_6_or_higher, declarationNameToString(node)); } // mark value declaration so during emit they can have a special handling getNodeLinks(symbol.valueDeclaration).flags |= NodeCheckFlags.BlockScopedBindingInLoop; @@ -10744,7 +10748,12 @@ module ts { getNodeLinks(n).resolvedSymbol || resolveName(n, n.text, SymbolFlags.BlockScopedVariable | SymbolFlags.Import, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined); - if (symbol && (symbol.flags & SymbolFlags.BlockScopedVariable)) { + var isLetOrConst = + symbol && + (symbol.flags & SymbolFlags.BlockScopedVariable) && + symbol.valueDeclaration.parent.kind !== SyntaxKind.CatchClause; + + if (isLetOrConst) { // side-effect of calling this method: // assign id to symbol if it was not yet set getSymbolLinks(symbol); diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 36439a1fccde1..0e8d1bdd25fa2 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -397,7 +397,7 @@ module ts { Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." }, Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using private name '{1}'." }, Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using private name '{1}'." }, - Code_in_the_loop_captures_block_scoped_variable_0_in_closure_This_is_natively_supported_in_ECMAScript_6_or_higher: { code: 4091, category: DiagnosticCategory.Error, key: "Code in the loop captures block-scoped variable '{0}' in closure. This is natively supported in ECMAScript 6 or higher." }, + Loop_contains_block_scoped_variable_0_referenced_by_a_function_in_the_loop_This_is_only_supported_in_ECMAScript_6_or_higher: { code: 4091, category: DiagnosticCategory.Error, key: "Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher." }, The_current_host_does_not_support_the_0_option: { code: 5001, category: DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." }, Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: DiagnosticCategory.Error, key: "Cannot find the common subdirectory path for the input files." }, Cannot_read_file_0_Colon_1: { code: 5012, category: DiagnosticCategory.Error, key: "Cannot read file '{0}': {1}" }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 22083ab6d56f0..cca74aac7ce68 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1581,7 +1581,7 @@ "category": "Error", "code": 4081 }, - "Code in the loop captures block-scoped variable '{0}' in closure. This is natively supported in ECMAScript 6 or higher.": { + "Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher.": { "category": "Error", "code": 4091 }, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 53040fe776b87..c4f7c79939f5c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -34,16 +34,6 @@ module ts { previous: ScopeFrame; } - // isExisingName function has signature string -> boolean, however check if name is unique should be performed - // in the context of some location. Instead of creating function expression and closing over location - // every time isExisingName is called we use one single instance of NameLookup that is effectively a - // handrolled closure where value of location can be swapped. This allows to avoid allocations of closures on - // every call and use one shared instance instead - interface NameLookup { - setLocation(location: Node): void; - isExistingName(name: string): boolean; - } - type GetSymbolAccessibilityDiagnostic = (symbolAccesibilityResult: SymbolAccessiblityResult) => SymbolAccessibilityDiagnostic; interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter { @@ -1541,7 +1531,6 @@ module ts { var sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap ? [] : undefined; var diagnostics: Diagnostic[] = []; var newLine = host.getNewLine(); - var nameLookup: NameLookup; if (targetSourceFile === undefined) { forEach(host.getSourceFiles(), sourceFile => { @@ -1686,38 +1675,14 @@ module ts { } } - // creates instance of NameLookup to be used in 'isExisingName' checks. - // see comment for NameLookup for more information - function createNameLookup(): NameLookup { - var location: Node; - return { - setLocation, - isExistingName: checkName - } - - function setLocation(l: Node): void { - location = l; - } - - function checkName(name: string): boolean { - Debug.assert(location !== undefined); - return isExistingName(location, name); - } - } - - function makeUniqueName(location: Node, baseName: string): string { + function generateUniqueNameForLocation(location: Node, baseName: string): string { var name: string // first try to check if base name can be used as is if (!isExistingName(location, baseName)) { name = baseName; } else { - if (!nameLookup) { - nameLookup = createNameLookup(); - } - nameLookup.setLocation(location); - name = generateUniqueName(baseName, nameLookup.isExistingName); - nameLookup.setLocation(undefined); + name = generateUniqueName(baseName, n => isExistingName(location, n)); } if (!currentScopeNames) { @@ -2560,7 +2525,7 @@ module ts { function getBlockScopedVariableId(node: Identifier): number { // return undefined for synthesized nodes - return node.parent && resolver.getBlockScopedVariableId(node); + return !nodeIsSynthesized(node) && resolver.getBlockScopedVariableId(node); } function emitIdentifier(node: Identifier) { @@ -3924,7 +3889,7 @@ module ts { ? blockScopeContainer : blockScopeContainer.parent; - var generatedName = makeUniqueName(parent, (node).text); + var generatedName = generateUniqueNameForLocation(parent, (node).text); var variableId = resolver.getBlockScopedVariableId(node); if (!generatedBlockScopeNames) { generatedBlockScopeNames = []; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 12ca74e953b87..af574572055cf 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1139,17 +1139,14 @@ module ts { return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), /*newLength: */newEndN - oldStartN); } - // @internal export function nodeStartsNewLexicalEnvironment(n: Node): boolean { return isAnyFunction(n) || n.kind === SyntaxKind.ModuleDeclaration || n.kind === SyntaxKind.SourceFile; } - // @internal export function nodeIsSynthesized(node: Node): boolean { return node.pos === -1 && node.end === -1; } - // @internal export function createSynthesizedNode(kind: SyntaxKind, startsOnNewLine?: boolean): Node { var node = createNode(kind); node.pos = -1; @@ -1158,7 +1155,6 @@ module ts { return node; } - // @internal export function generateUniqueName(baseName: string, isExistingName: (name: string) => boolean): string { // First try '_name' if (baseName.charCodeAt(0) !== CharacterCodes._) { @@ -1173,7 +1169,7 @@ module ts { } var i = 1; while (true) { - name = baseName + i; + var name = baseName + i; if (!isExistingName(name)) { return name; } @@ -1181,7 +1177,6 @@ module ts { } } - // @internal export function createDiagnosticCollection(): DiagnosticCollection { var nonFileDiagnostics: Diagnostic[] = []; var fileDiagnostics: Map = {}; diff --git a/tests/baselines/reference/downlevelLetConst18.errors.txt b/tests/baselines/reference/downlevelLetConst18.errors.txt index 93a2578defa77..8f30b0f802a60 100644 --- a/tests/baselines/reference/downlevelLetConst18.errors.txt +++ b/tests/baselines/reference/downlevelLetConst18.errors.txt @@ -1,12 +1,12 @@ -tests/cases/compiler/downlevelLetConst18.ts(3,1): error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. +tests/cases/compiler/downlevelLetConst18.ts(3,1): error TS4091: Loop contains block-scoped variable 'x' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher. tests/cases/compiler/downlevelLetConst18.ts(4,14): error TS2393: Duplicate function implementation. -tests/cases/compiler/downlevelLetConst18.ts(7,1): error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. +tests/cases/compiler/downlevelLetConst18.ts(7,1): error TS4091: Loop contains block-scoped variable 'x' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher. tests/cases/compiler/downlevelLetConst18.ts(8,14): error TS2393: Duplicate function implementation. -tests/cases/compiler/downlevelLetConst18.ts(11,1): error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. -tests/cases/compiler/downlevelLetConst18.ts(15,1): error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. -tests/cases/compiler/downlevelLetConst18.ts(19,1): error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. -tests/cases/compiler/downlevelLetConst18.ts(23,1): error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. -tests/cases/compiler/downlevelLetConst18.ts(27,1): error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. +tests/cases/compiler/downlevelLetConst18.ts(11,1): error TS4091: Loop contains block-scoped variable 'x' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher. +tests/cases/compiler/downlevelLetConst18.ts(15,1): error TS4091: Loop contains block-scoped variable 'x' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher. +tests/cases/compiler/downlevelLetConst18.ts(19,1): error TS4091: Loop contains block-scoped variable 'x' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher. +tests/cases/compiler/downlevelLetConst18.ts(23,1): error TS4091: Loop contains block-scoped variable 'x' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher. +tests/cases/compiler/downlevelLetConst18.ts(27,1): error TS4091: Loop contains block-scoped variable 'x' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher. ==== tests/cases/compiler/downlevelLetConst18.ts (9 errors) ==== @@ -14,7 +14,7 @@ tests/cases/compiler/downlevelLetConst18.ts(27,1): error TS4091: Code in the loo for (let x; ;) { ~~~ -!!! error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. +!!! error TS4091: Loop contains block-scoped variable 'x' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher. function foo() { x }; ~~~ !!! error TS2393: Duplicate function implementation. @@ -22,7 +22,7 @@ tests/cases/compiler/downlevelLetConst18.ts(27,1): error TS4091: Code in the loo for (let x; ;) { ~~~ -!!! error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. +!!! error TS4091: Loop contains block-scoped variable 'x' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher. function foo() { x }; ~~~ !!! error TS2393: Duplicate function implementation. @@ -30,31 +30,31 @@ tests/cases/compiler/downlevelLetConst18.ts(27,1): error TS4091: Code in the loo for (let x; ;) { ~~~ -!!! error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. +!!! error TS4091: Loop contains block-scoped variable 'x' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher. (() => { x })(); } for (const x = 1; ;) { ~~~ -!!! error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. +!!! error TS4091: Loop contains block-scoped variable 'x' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher. (() => { x })(); } for (let x; ;) { ~~~ -!!! error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. +!!! error TS4091: Loop contains block-scoped variable 'x' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher. ({ foo() { x }}) } for (let x; ;) { ~~~ -!!! error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. +!!! error TS4091: Loop contains block-scoped variable 'x' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher. ({ get foo() { return x } }) } for (let x; ;) { ~~~ -!!! error TS4091: Code in the loop captures block-scoped variable 'x' in closure. This is natively supported in ECMAScript 6 or higher. +!!! error TS4091: Loop contains block-scoped variable 'x' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher. ({ set foo(v) { x } }) } \ No newline at end of file