diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 128b6f8ffe..f21ecafd25 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -206,7 +206,8 @@ module ts { if (symbolKind & SymbolFlags.Namespace) { exportKind |= SymbolFlags.ExportNamespace; } - if (node.flags & NodeFlags.Export || (node.kind !== SyntaxKind.ImportDeclaration && isAmbientContext(container))) { + + if (getNodeFlags(node) & NodeFlags.Export || (node.kind !== SyntaxKind.ImportDeclaration && isAmbientContext(container))) { if (exportKind) { var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes); local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); @@ -389,7 +390,7 @@ module ts { if (isBindingPattern((node).name)) { bindChildren(node, 0, /*isBlockScopeContainer*/ false); } - else if (node.flags & NodeFlags.BlockScoped) { + else if (getNodeFlags(node) & NodeFlags.BlockScoped) { bindBlockScopedVariableDeclaration(node); } else { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 677fb2bec4..de75ae4c24 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16,7 +16,6 @@ module ts { /// If fullTypeCheck === false, the typechecker can take shortcuts and skip checks that only produce errors. /// NOTE: checks that somehow affect decisions being made during typechecking should be executed in both cases. export function createTypeChecker(program: Program, fullTypeCheck: boolean): TypeChecker { - var Symbol = objectAllocator.getSymbolConstructor(); var Type = objectAllocator.getTypeConstructor(); var Signature = objectAllocator.getSignatureConstructor(); @@ -407,7 +406,7 @@ module ts { } if (result.flags & SymbolFlags.BlockScopedVariable) { // Block-scoped variables cannot be used before their definition - var declaration = forEach(result.declarations, d => d.flags & NodeFlags.BlockScoped ? d : undefined); + var declaration = forEach(result.declarations, d => getNodeFlags(d) & NodeFlags.BlockScoped ? d : undefined); Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined"); if (!isDefinedBefore(declaration, errorLocation)) { error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationNameToString(declaration.name)); @@ -764,7 +763,7 @@ module ts { // if the symbolFromSymbolTable is not external module (it could be if it was determined as ambient external module and would be in globals table) // and if symbolfrom symbolTable or alias resolution matches the symbol, // check the symbol can be qualified, it is only then this symbol is accessible - return !forEach(symbolFromSymbolTable.declarations, declaration => hasExternalModuleSymbol(declaration)) && + return !forEach(symbolFromSymbolTable.declarations, hasExternalModuleSymbol) && canQualifySymbol(symbolFromSymbolTable, meaning); } } @@ -868,7 +867,7 @@ module ts { // This could be a symbol that is not exported in the external module // or it could be a symbol from different external module that is not aliased and hence cannot be named - var symbolExternalModule = forEach(initialSymbol.declarations, declaration => getExternalModuleContainer(declaration)); + var symbolExternalModule = forEach(initialSymbol.declarations, getExternalModuleContainer); if (symbolExternalModule) { var enclosingExternalModule = getExternalModuleContainer(enclosingDeclaration); if (symbolExternalModule !== enclosingExternalModule) { @@ -1088,7 +1087,7 @@ module ts { } else { // If we didn't find accessible symbol chain for this symbol, break if this is external module - if (!parentSymbol && ts.forEach(symbol.declarations, declaration => hasExternalModuleSymbol(declaration))) { + if (!parentSymbol && ts.forEach(symbol.declarations, hasExternalModuleSymbol)) { return; } @@ -1557,7 +1556,7 @@ module ts { case SyntaxKind.ImportDeclaration: var parent = getDeclarationContainer(node); // If the node is not exported or it is not ambient module element (except import declaration) - if (!(node.flags & NodeFlags.Export) && + if (!(getNodeFlags(node) & NodeFlags.Export) && !(node.kind !== SyntaxKind.ImportDeclaration && parent.kind !== SyntaxKind.SourceFile && isInAmbientContext(parent))) { return isGlobalSourceFile(parent) || isUsedInExportAssignment(node); } @@ -1620,7 +1619,7 @@ module ts { function getDeclarationContainer(node: Node): Node { node = getRootDeclaration(node); - return node.kind === SyntaxKind.VariableDeclaration ? node.parent.parent : node.parent; + return node.kind === SyntaxKind.VariableDeclaration ? node.parent.parent.parent : node.parent; } function getTypeOfPrototypeProperty(prototype: Symbol): Type { @@ -1687,7 +1686,7 @@ module ts { // Return the inferred type for a variable, parameter, or property declaration function getTypeForVariableLikeDeclaration(declaration: VariableLikeDeclaration): Type { // A variable declared in a for..in statement is always of type any - if (declaration.parent.kind === SyntaxKind.ForInStatement) { + if (declaration.parent.parent.kind === SyntaxKind.ForInStatement) { return anyType; } if (isBindingPattern(declaration.parent)) { @@ -4102,7 +4101,7 @@ module ts { return anyType; } if (type.flags & TypeFlags.Union) { - return getUnionType(map((type).types, t => getWidenedType(t))); + return getUnionType(map((type).types, getWidenedType)); } if (isTypeOfObjectLiteral(type)) { return getWidenedTypeOfObjectLiteral(type); @@ -5108,7 +5107,7 @@ module ts { // Return true if the given contextual type is a tuple-like type function contextualTypeIsTupleLikeType(type: Type): boolean { - return !!(type.flags & TypeFlags.Union ? forEach((type).types, t => isTupleLikeType(t)) : isTupleLikeType(type)); + return !!(type.flags & TypeFlags.Union ? forEach((type).types, isTupleLikeType) : isTupleLikeType(type)); } // Return true if the given contextual type provides an index signature of the given kind @@ -5420,7 +5419,7 @@ module ts { } function getDeclarationFlagsFromSymbol(s: Symbol) { - return s.valueDeclaration ? s.valueDeclaration.flags : s.flags & SymbolFlags.Prototype ? NodeFlags.Public | NodeFlags.Static : 0; + return s.valueDeclaration ? getNodeFlags(s.valueDeclaration) : s.flags & SymbolFlags.Prototype ? NodeFlags.Public | NodeFlags.Static : 0; } function checkClassPropertyAccess(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, type: Type, prop: Symbol) { @@ -7306,7 +7305,7 @@ module ts { } function getEffectiveDeclarationFlags(n: Node, flagsToCheck: NodeFlags) { - var flags = n.flags; + var flags = getNodeFlags(n); if (n.parent.kind !== SyntaxKind.InterfaceDeclaration && isInAmbientContext(n)) { if (!(flags & NodeFlags.Ambient)) { // It is nested in an ambient context, which means it is automatically exported @@ -7782,7 +7781,7 @@ module ts { // const x = 0; // var x = 0; // } - if (node.initializer && (node.flags & NodeFlags.BlockScoped) === 0) { + if (node.initializer && (getNodeFlags(node) & NodeFlags.BlockScoped) === 0) { var symbol = getSymbolOfNode(node); if (symbol.flags & SymbolFlags.FunctionScopedVariable) { var localDeclarationSymbol = resolveName(node, (node.name).text, SymbolFlags.Variable, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined); @@ -7834,6 +7833,10 @@ module ts { } } + function checkVariableDeclaration(node: VariableDeclaration) { + return checkVariableLikeDeclaration(node); + } + // Check variable, parameter, or property declaration function checkVariableLikeDeclaration(node: VariableLikeDeclaration) { checkSourceElement(node.type); @@ -7892,7 +7895,7 @@ module ts { } function checkVariableStatement(node: VariableStatement) { - forEach(node.declarations, checkSourceElement); + forEach(node.declarationList.declarations, checkSourceElement); } function checkExpressionStatement(node: ExpressionStatement) { @@ -7916,8 +7919,15 @@ module ts { } function checkForStatement(node: ForStatement) { - if (node.declarations) forEach(node.declarations, checkVariableLikeDeclaration); - if (node.initializer) checkExpression(node.initializer); + if (node.initializer) { + if (node.initializer.kind === SyntaxKind.VariableDeclarationList) { + forEach((node.initializer).declarations, checkVariableDeclaration) + } + else { + checkExpression(node.initializer) + } + } + if (node.condition) checkExpression(node.condition); if (node.iterator) checkExpression(node.iterator); checkSourceElement(node.statement); @@ -7930,28 +7940,29 @@ module ts { // for (var VarDecl in Expr) Statement // VarDecl must be a variable declaration without a type annotation that declares a variable of type Any, // and Expr must be an expression of type Any, an object type, or a type parameter type. - if (node.declarations) { - if (node.declarations.length >= 1) { - var decl = node.declarations[0]; + if (node.initializer.kind === SyntaxKind.VariableDeclarationList) { + var variableDeclarationList = node.initializer; + if (variableDeclarationList.declarations.length >= 1) { + var decl = variableDeclarationList.declarations[0]; checkVariableLikeDeclaration(decl); if (decl.type) { error(decl, Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation); } } } - - // In a 'for-in' statement of the form - // for (Var in Expr) Statement - // Var must be an expression classified as a reference of type Any or the String primitive type, - // and Expr must be an expression of type Any, an object type, or a type parameter type. - if (node.variable) { - var exprType = checkExpression(node.variable); + else { + // In a 'for-in' statement of the form + // for (Var in Expr) Statement + // Var must be an expression classified as a reference of type Any or the String primitive type, + // and Expr must be an expression of type Any, an object type, or a type parameter type. + var varExpr = node.initializer; + var exprType = checkExpression(varExpr); if (exprType !== anyType && exprType !== stringType) { - error(node.variable, Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); + error(varExpr, Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); } else { // run check only former check succeeded to avoid cascading errors - checkReferenceExpression(node.variable, Diagnostics.Invalid_left_hand_side_in_for_in_statement, Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); + checkReferenceExpression(varExpr, Diagnostics.Invalid_left_hand_side_in_for_in_statement, Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); } } @@ -8879,6 +8890,7 @@ module ts { case SyntaxKind.TryStatement: case SyntaxKind.CatchClause: case SyntaxKind.VariableDeclaration: + case SyntaxKind.VariableDeclarationList: case SyntaxKind.ClassDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKind.EnumMember: diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 2d0f06e656..5e3290120b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1014,20 +1014,20 @@ module ts { } function emitVariableStatement(node: VariableStatement) { - var hasDeclarationWithEmit = forEach(node.declarations, varDeclaration => resolver.isDeclarationVisible(varDeclaration)); + var hasDeclarationWithEmit = forEach(node.declarationList.declarations, varDeclaration => resolver.isDeclarationVisible(varDeclaration)); if (hasDeclarationWithEmit) { emitJsDocComments(node); emitModuleElementDeclarationFlags(node); - if (isLet(node)) { + if (isLet(node.declarationList)) { write("let "); } - else if (isConst(node)) { + else if (isConst(node.declarationList)) { write("const "); } else { write("var "); } - emitCommaList(node.declarations, emitVariableDeclaration); + emitCommaList(node.declarationList.declarations, emitVariableDeclaration); write(";"); writeLine(); } @@ -2610,20 +2610,22 @@ module ts { var endPos = emitToken(SyntaxKind.ForKeyword, node.pos); write(" "); endPos = emitToken(SyntaxKind.OpenParenToken, endPos); - if (node.declarations) { - if (node.declarations[0] && isLet(node.declarations[0])) { + 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 (node.declarations[0] && isConst(node.declarations[0])) { + else if (declarations[0] && isConst(declarations[0])) { emitToken(SyntaxKind.ConstKeyword, endPos); } else { emitToken(SyntaxKind.VarKeyword, endPos); } write(" "); - emitCommaList(node.declarations); + emitCommaList(variableDeclarationList.declarations); } - if (node.initializer) { + else if (node.initializer) { emit(node.initializer); } write(";"); @@ -2638,9 +2640,10 @@ module ts { var endPos = emitToken(SyntaxKind.ForKeyword, node.pos); write(" "); endPos = emitToken(SyntaxKind.OpenParenToken, endPos); - if (node.declarations) { - if (node.declarations.length >= 1) { - var decl = node.declarations[0]; + if (node.initializer.kind === SyntaxKind.VariableDeclarationList) { + var variableDeclarationList = node.initializer; + if (variableDeclarationList.declarations.length >= 1) { + var decl = variableDeclarationList.declarations[0]; if (isLet(decl)) { emitToken(SyntaxKind.LetKeyword, endPos); } @@ -2652,7 +2655,7 @@ module ts { } } else { - emit(node.variable); + emit(node.initializer); } write(" in "); emit(node.expression); @@ -2769,7 +2772,7 @@ module ts { function emitModuleMemberName(node: Declaration) { emitStart(node.name); - if (node.flags & NodeFlags.Export) { + if (getNodeFlags(node) & NodeFlags.Export) { var container = getContainingModule(node); write(container ? resolver.getLocalNameOfContainer(container) : "exports"); write("."); @@ -2782,7 +2785,7 @@ module ts { var emitCount = 0; // An exported declaration is actually emitted as an assignment (to a property on the module object), so // temporary variables in an exported declaration need to have real declarations elsewhere - var isDeclaration = (root.kind === SyntaxKind.VariableDeclaration && !(root.flags & NodeFlags.Export)) || root.kind === SyntaxKind.Parameter; + var isDeclaration = (root.kind === SyntaxKind.VariableDeclaration && !(getNodeFlags(root) & NodeFlags.Export)) || root.kind === SyntaxKind.Parameter; if (root.kind === SyntaxKind.BinaryExpression) { emitAssignmentExpression(root); } @@ -2991,17 +2994,17 @@ module ts { function emitVariableStatement(node: VariableStatement) { emitLeadingComments(node); if (!(node.flags & NodeFlags.Export)) { - if (isLet(node)) { + if (isLet(node.declarationList)) { write("let "); } - else if (isConst(node)) { + else if (isConst(node.declarationList)) { write("const "); } else { write("var "); } } - emitCommaList(node.declarations); + emitCommaList(node.declarationList.declarations); write(";"); emitTrailingComments(node); } @@ -3818,6 +3821,7 @@ module ts { if (!node) { return; } + if (node.flags & NodeFlags.Ambient) { return emitPinnedOrTripleSlashComments(node); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 282353cd59..4bd8826e4c 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -158,7 +158,9 @@ module ts { child((node).endOfFileToken); case SyntaxKind.VariableStatement: return children(node.modifiers) || - children((node).declarations); + child((node).declarationList); + case SyntaxKind.VariableDeclarationList: + return children((node).declarations); case SyntaxKind.ExpressionStatement: return child((node).expression); case SyntaxKind.IfStatement: @@ -172,14 +174,12 @@ module ts { return child((node).expression) || child((node).statement); case SyntaxKind.ForStatement: - return children((node).declarations) || - child((node).initializer) || + return child((node).initializer) || child((node).condition) || child((node).iterator) || child((node).statement); case SyntaxKind.ForInStatement: - return children((node).declarations) || - child((node).variable) || + return child((node).initializer) || child((node).expression) || child((node).statement); case SyntaxKind.ContinueStatement: @@ -3769,42 +3769,27 @@ module ts { var pos = getNodePos(); parseExpected(SyntaxKind.ForKeyword); parseExpected(SyntaxKind.OpenParenToken); + + var initializer: VariableDeclarationList | Expression = undefined; if (token !== SyntaxKind.SemicolonToken) { - if (parseOptional(SyntaxKind.VarKeyword)) { - var declarations = disallowInAnd(parseVariableDeclarationList); - } - else if (parseOptional(SyntaxKind.LetKeyword)) { - var declarations = setFlag(disallowInAnd(parseVariableDeclarationList), NodeFlags.Let); - } - else if (parseOptional(SyntaxKind.ConstKeyword)) { - var declarations = setFlag(disallowInAnd(parseVariableDeclarationList), NodeFlags.Const); + if (token === SyntaxKind.VarKeyword || token === SyntaxKind.LetKeyword || token === SyntaxKind.ConstKeyword) { + initializer = parseVariableDeclarationList(/*disallowIn:*/ true); } else { - var varOrInit = disallowInAnd(parseExpression); + initializer = disallowInAnd(parseExpression); } } var forOrForInStatement: IterationStatement; if (parseOptional(SyntaxKind.InKeyword)) { var forInStatement = createNode(SyntaxKind.ForInStatement, pos); - if (declarations) { - forInStatement.declarations = declarations; - } - else { - forInStatement.variable = varOrInit; - } + forInStatement.initializer = initializer; forInStatement.expression = allowInAnd(parseExpression); parseExpected(SyntaxKind.CloseParenToken); forOrForInStatement = forInStatement; } else { var forStatement = createNode(SyntaxKind.ForStatement, pos); - if (declarations) { - forStatement.declarations = declarations; - } - if (varOrInit) { - forStatement.initializer = varOrInit; - } - + forStatement.initializer = initializer; parseExpected(SyntaxKind.SemicolonToken); if (token !== SyntaxKind.SemicolonToken && token !== SyntaxKind.CloseParenToken) { forStatement.condition = allowInAnd(parseExpression); @@ -4213,39 +4198,37 @@ module ts { return finishNode(node); } - function setFlag(nodes: NodeArray, flag: NodeFlags): NodeArray { - for (var i = 0; i < nodes.length; i++) { - var node = nodes[i]; - node.flags |= flag; - if (node.name && isBindingPattern(node.name)) { - setFlag((node.name).elements, flag); - } - } - return nodes; - } + function parseVariableDeclarationList(disallowIn: boolean): VariableDeclarationList { + var node = createNode(SyntaxKind.VariableDeclarationList); - function parseVariableDeclarationList(): NodeArray { - return parseDelimitedList(ParsingContext.VariableDeclarations, parseVariableDeclaration); + switch (token) { + case SyntaxKind.VarKeyword: + break; + case SyntaxKind.LetKeyword: + node.flags |= NodeFlags.Let; + break; + case SyntaxKind.ConstKeyword: + node.flags |= NodeFlags.Const; + break; + default: + Debug.fail(); + } + + nextToken(); + var savedDisallowIn = inDisallowInContext(); + setDisallowInContext(disallowIn); + + node.declarations = parseDelimitedList(ParsingContext.VariableDeclarations, parseVariableDeclaration); + + setDisallowInContext(savedDisallowIn); + + return finishNode(node); } function parseVariableStatement(fullStart: number, modifiers: ModifiersArray): VariableStatement { var node = createNode(SyntaxKind.VariableStatement, fullStart); setModifiers(node, modifiers); - - if (token === SyntaxKind.LetKeyword) { - node.flags |= NodeFlags.Let; - } - else if (token === SyntaxKind.ConstKeyword) { - node.flags |= NodeFlags.Const; - } - else { - Debug.assert(token === SyntaxKind.VarKeyword); - } - - nextToken(); - node.declarations = allowInAnd(parseVariableDeclarationList); - setFlag(node.declarations, node.flags); - + node.declarationList = parseVariableDeclarationList(/*disallowIn:*/ false); parseSemicolon(); return finishNode(node); } @@ -4954,8 +4937,6 @@ module ts { case SyntaxKind.ElementAccessExpression: return checkElementAccessExpression(node); case SyntaxKind.ExportAssignment: return checkExportAssignment(node); case SyntaxKind.ExternalModuleReference: return checkExternalModuleReference(node); - case SyntaxKind.ForInStatement: return checkForInStatement(node); - case SyntaxKind.ForStatement: return checkForStatement(node); case SyntaxKind.FunctionDeclaration: return checkFunctionDeclaration(node); case SyntaxKind.FunctionExpression: return checkFunctionExpression(node); case SyntaxKind.GetAccessor: return checkGetAccessor(node); @@ -4987,6 +4968,7 @@ module ts { case SyntaxKind.TypeParameter: return checkTypeParameter(node); case SyntaxKind.TypeReference: return checkTypeReference(node); case SyntaxKind.VariableDeclaration: return checkVariableDeclaration(node); + case SyntaxKind.VariableDeclarationList: return checkVariableDeclarationList(node); case SyntaxKind.VariableStatement: return checkVariableStatement(node); case SyntaxKind.WithStatement: return checkWithStatement(node); case SyntaxKind.YieldExpression: return checkYieldExpression(node); @@ -5349,15 +5331,6 @@ module ts { } } - function checkForInStatement(node: ForInStatement) { - return checkVariableDeclarations(node.declarations) || - checkForMoreThanOneDeclaration(node.declarations); - } - - function checkForStatement(node: ForStatement) { - return checkVariableDeclarations(node.declarations); - } - function checkForMoreThanOneDeclaration(declarations: NodeArray) { if (declarations && declarations.length > 1) { return grammarErrorOnFirstToken(declarations[1], Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement); @@ -6094,31 +6067,32 @@ module ts { } } - function checkVariableDeclarations(declarations: NodeArray): boolean { - if (declarations) { - if (checkForDisallowedTrailingComma(declarations)) { - return true; - } + function checkVariableDeclarationList(declarationList: VariableDeclarationList): boolean { + var declarations = declarationList.declarations; + if (checkForDisallowedTrailingComma(declarationList.declarations)) { + return true; + } - if (!declarations.length) { - return grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, Diagnostics.Variable_declaration_list_cannot_be_empty); - } + if (!declarationList.declarations.length) { + return grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, Diagnostics.Variable_declaration_list_cannot_be_empty); + } - var decl = declarations[0]; - if (languageVersion < ScriptTarget.ES6) { - if (isLet(decl)) { - return grammarErrorOnFirstToken(decl, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - else if (isConst(decl)) { - return grammarErrorOnFirstToken(decl, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } + if (declarationList.parent.kind === SyntaxKind.ForInStatement) { + checkForMoreThanOneDeclaration(declarationList.declarations); + } + + 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 checkVariableStatement(node: VariableStatement) { return checkForDisallowedModifiersInBlockOrObjectLiteral(node) || - checkVariableDeclarations(node.declarations) || checkForDisallowedLetOrConstStatement(node); } @@ -6132,10 +6106,10 @@ module ts { function checkForDisallowedLetOrConstStatement(node: VariableStatement) { if (!allowLetAndConstDeclarations(node.parent)) { - if (isLet(node)) { + if (isLet(node.declarationList)) { return grammarErrorOnNode(node, Diagnostics.let_declarations_can_only_be_declared_inside_a_block); } - else if (isConst(node)) { + else if (isConst(node.declarationList)) { return grammarErrorOnNode(node, Diagnostics.const_declarations_can_only_be_declared_inside_a_block); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1a34aaf6da..7b800548ee 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -219,6 +219,7 @@ module ts { TryStatement, DebuggerStatement, VariableDeclaration, + VariableDeclarationList, FunctionDeclaration, ClassDeclaration, InterfaceDeclaration, @@ -398,6 +399,10 @@ module ts { initializer?: Expression; // Optional initializer } + export interface VariableDeclarationList extends Node { + declarations: NodeArray; + } + // SyntaxKind.Parameter export interface ParameterDeclaration extends Declaration { dotDotDotToken?: Node; // Present on rest parameter @@ -702,7 +707,7 @@ module ts { } export interface VariableStatement extends Statement { - declarations: NodeArray; + declarationList: VariableDeclarationList; } export interface ExpressionStatement extends Statement { @@ -728,15 +733,13 @@ module ts { } export interface ForStatement extends IterationStatement { - declarations?: NodeArray; - initializer?: Expression; + initializer?: VariableDeclarationList | Expression; condition?: Expression; iterator?: Expression; } export interface ForInStatement extends IterationStatement { - declarations?: NodeArray; - variable?: Expression; + initializer: VariableDeclarationList | Expression; expression: Expression; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 6ccb0cadd2..6137d6e195 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -220,12 +220,40 @@ module ts { return node.kind === SyntaxKind.EnumDeclaration && isConst(node); } + function walkUpBindingElementsAndPatterns(node: Node): Node { + while (node && (node.kind === SyntaxKind.BindingElement || isBindingPattern(node))) { + node = node.parent; + } + + return node; + } + + export function getNodeFlags(node: Node): NodeFlags { + node = walkUpBindingElementsAndPatterns(node); + + var flags = node.flags; + if (node.kind === SyntaxKind.VariableDeclaration) { + node = node.parent; + } + + if (node && node.kind === SyntaxKind.VariableDeclarationList) { + flags |= node.flags; + node = node.parent; + } + + if (node && node.kind === SyntaxKind.VariableStatement) { + flags |= node.flags; + } + + return flags; + } + export function isConst(node: Node): boolean { - return !!(node.flags & NodeFlags.Const); + return !!(getNodeFlags(node) & NodeFlags.Const); } export function isLet(node: Node): boolean { - return !!(node.flags & NodeFlags.Let); + return !!(getNodeFlags(node) & NodeFlags.Let); } export function isPrologueDirective(node: Node): boolean { @@ -456,12 +484,14 @@ module ts { case SyntaxKind.SwitchStatement: return (parent).expression === node; case SyntaxKind.ForStatement: - return (parent).initializer === node || - (parent).condition === node || - (parent).iterator === node; + var forStatement = parent; + return (forStatement.initializer === node && forStatement.initializer.kind !== SyntaxKind.VariableDeclarationList) || + forStatement.condition === node || + forStatement.iterator === node; case SyntaxKind.ForInStatement: - return (parent).variable === node || - (parent).expression === node; + var forInStatement = parent; + return (forInStatement.initializer === node && forInStatement.initializer.kind !== SyntaxKind.VariableDeclarationList) || + forInStatement.expression === node; case SyntaxKind.TypeAssertionExpression: return node === (parent).expression; case SyntaxKind.TemplateSpan: @@ -533,7 +563,10 @@ module ts { export function isInAmbientContext(node: Node): boolean { while (node) { - if (node.flags & (NodeFlags.Ambient | NodeFlags.DeclarationFile)) return true; + if (node.flags & (NodeFlags.Ambient | NodeFlags.DeclarationFile)) { + return true; + } + node = node.parent; } return false; diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 065e9e36cd..f71c96e621 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1210,7 +1210,7 @@ module Harness { // Report global errors var globalErrors = diagnostics.filter(err => !err.filename); - globalErrors.forEach(err => outputErrorText(err)); + globalErrors.forEach(outputErrorText); // 'merge' the lines of each input file with any errors associated with it inputFiles.filter(f => f.content !== undefined).forEach(inputFile => { diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index a474ac4afb..e49d035559 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -83,7 +83,7 @@ module ts.BreakpointResolver { switch (node.kind) { case SyntaxKind.VariableStatement: // Span on first variable declaration - return spanInVariableDeclaration((node).declarations[0]); + return spanInVariableDeclaration((node).declarationList.declarations[0]); case SyntaxKind.VariableDeclaration: case SyntaxKind.PropertyDeclaration: @@ -261,16 +261,16 @@ module ts.BreakpointResolver { function spanInVariableDeclaration(variableDeclaration: VariableDeclaration): TextSpan { // If declaration of for in statement, just set the span in parent - if (variableDeclaration.parent.kind === SyntaxKind.ForInStatement) { - return spanInNode(variableDeclaration.parent); + if (variableDeclaration.parent.parent.kind === SyntaxKind.ForInStatement) { + return spanInNode(variableDeclaration.parent.parent); } - var isParentVariableStatement = variableDeclaration.parent.kind === SyntaxKind.VariableStatement; - var isDeclarationOfForStatement = variableDeclaration.parent.kind === SyntaxKind.ForStatement && contains((variableDeclaration.parent).declarations, variableDeclaration); + var isParentVariableStatement = variableDeclaration.parent.parent.kind === SyntaxKind.VariableStatement; + var isDeclarationOfForStatement = variableDeclaration.parent.parent.kind === SyntaxKind.ForStatement && contains(((variableDeclaration.parent.parent).initializer).declarations, variableDeclaration); var declarations = isParentVariableStatement - ? (variableDeclaration.parent).declarations + ? (variableDeclaration.parent.parent).declarationList.declarations : isDeclarationOfForStatement - ? (variableDeclaration.parent).declarations + ? ((variableDeclaration.parent.parent).initializer).declarations : undefined; // Breakpoint is possible in variableDeclaration only if there is initialization @@ -374,12 +374,18 @@ module ts.BreakpointResolver { } function spanInForStatement(forStatement: ForStatement): TextSpan { - if (forStatement.declarations) { - return spanInNode(forStatement.declarations[0]); - } if (forStatement.initializer) { - return spanInNode(forStatement.initializer); + if (forStatement.initializer.kind === SyntaxKind.VariableDeclarationList) { + var variableDeclarationList = forStatement.initializer; + if (variableDeclarationList.declarations.length > 0) { + return spanInNode(variableDeclarationList.declarations[0]); + } + } + else { + return spanInNode(forStatement.initializer); + } } + if (forStatement.condition) { return textSpan(forStatement.condition); } diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index e7a500e2e9..9051ee8039 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -44,7 +44,7 @@ module ts.NavigationBar { function visit(node: Node) { switch (node.kind) { case SyntaxKind.VariableStatement: - forEach((node).declarations, visit); + forEach((node).declarationList.declarations, visit); break; case SyntaxKind.ObjectBindingPattern: case SyntaxKind.ArrayBindingPattern: diff --git a/src/services/services.ts b/src/services/services.ts index 163b8d75de..ed17b59cf0 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -364,7 +364,7 @@ module ts { // Get the cleaned js doc comment text from the declaration ts.forEach(getJsDocCommentTextRange( - declaration.kind === SyntaxKind.VariableDeclaration ? declaration.parent : declaration, sourceFileOfDeclaration), jsDocCommentTextRange => { + declaration.kind === SyntaxKind.VariableDeclaration ? declaration.parent.parent : declaration, sourceFileOfDeclaration), jsDocCommentTextRange => { var cleanedJsDocComment = getCleanedJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); if (cleanedJsDocComment) { jsDocCommentParts.push.apply(jsDocCommentParts, cleanedJsDocComment); @@ -807,6 +807,7 @@ module ts { // fall through case SyntaxKind.Constructor: case SyntaxKind.VariableStatement: + case SyntaxKind.VariableDeclarationList: case SyntaxKind.ObjectBindingPattern: case SyntaxKind.ArrayBindingPattern: case SyntaxKind.ModuleBlock: @@ -2438,6 +2439,7 @@ module ts { switch (previousToken.kind) { case SyntaxKind.CommaToken: return containingNodeKind === SyntaxKind.VariableDeclaration || + containingNodeKind === SyntaxKind.VariableDeclarationList || containingNodeKind === SyntaxKind.VariableStatement || containingNodeKind === SyntaxKind.EnumDeclaration || // enum a { foo, | isFunction(containingNodeKind); @@ -2631,7 +2633,7 @@ module ts { else if (symbol.valueDeclaration && isConst(symbol.valueDeclaration)) { return ScriptElementKind.constElement; } - else if (forEach(symbol.declarations, declaration => isLet(declaration))) { + else if (forEach(symbol.declarations, isLet)) { return ScriptElementKind.letElement; } return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localVariableElement : ScriptElementKind.variableElement; @@ -2689,11 +2691,12 @@ module ts { case SyntaxKind.InterfaceDeclaration: return ScriptElementKind.interfaceElement; case SyntaxKind.TypeAliasDeclaration: return ScriptElementKind.typeElement; case SyntaxKind.EnumDeclaration: return ScriptElementKind.enumElement; - case SyntaxKind.VariableDeclaration: return isConst(node) - ? ScriptElementKind.constElement - : node.flags & NodeFlags.Let - ? ScriptElementKind.letElement - : ScriptElementKind.variableElement; + case SyntaxKind.VariableDeclaration: + return isConst(node) + ? ScriptElementKind.constElement + : isLet(node) + ? ScriptElementKind.letElement + : ScriptElementKind.variableElement; case SyntaxKind.FunctionDeclaration: return ScriptElementKind.functionElement; case SyntaxKind.GetAccessor: return ScriptElementKind.memberGetAccessorElement; case SyntaxKind.SetAccessor: return ScriptElementKind.memberSetAccessorElement; @@ -2874,7 +2877,7 @@ module ts { } if (symbolFlags & SymbolFlags.Enum) { addNewLineIfDisplayPartsExist(); - if (forEach(symbol.declarations, declaration => isConstEnumDeclaration(declaration))) { + if (forEach(symbol.declarations, isConstEnumDeclaration)) { displayParts.push(keywordPart(SyntaxKind.ConstKeyword)); displayParts.push(spacePart()); } diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 146ea141d7..1b7fa1bea6 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -271,7 +271,7 @@ module ts { } export function getNodeModifiers(node: Node): string { - var flags = node.flags; + var flags = getNodeFlags(node); var result: string[] = []; if (flags & NodeFlags.Private) result.push(ScriptElementKindModifier.privateMemberModifier); diff --git a/tests/baselines/reference/VariableDeclaration10_es6.errors.txt b/tests/baselines/reference/VariableDeclaration10_es6.errors.txt index 91c071903c..b7d4bf2f1c 100644 --- a/tests/baselines/reference/VariableDeclaration10_es6.errors.txt +++ b/tests/baselines/reference/VariableDeclaration10_es6.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es6/variableDeclarations/VariableDeclaration10_es6.ts(1,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +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/VariableDeclaration2_es6.errors.txt b/tests/baselines/reference/VariableDeclaration2_es6.errors.txt index 362b68dbb3..98c5ea9fce 100644 --- a/tests/baselines/reference/VariableDeclaration2_es6.errors.txt +++ b/tests/baselines/reference/VariableDeclaration2_es6.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es6/variableDeclarations/VariableDeclaration2_es6.ts(1,7): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. +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 errors) ==== const a - ~ + ~~~~~ !!! 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.errors.txt b/tests/baselines/reference/VariableDeclaration3_es6.errors.txt index e563c4f3ea..a3b09f70d2 100644 --- a/tests/baselines/reference/VariableDeclaration3_es6.errors.txt +++ b/tests/baselines/reference/VariableDeclaration3_es6.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es6/variableDeclarations/VariableDeclaration3_es6.ts(1,7): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. +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/VariableDeclaration4_es6.errors.txt b/tests/baselines/reference/VariableDeclaration4_es6.errors.txt index ae03582531..a411877f52 100644 --- a/tests/baselines/reference/VariableDeclaration4_es6.errors.txt +++ b/tests/baselines/reference/VariableDeclaration4_es6.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es6/variableDeclarations/VariableDeclaration4_es6.ts(1,7): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. +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 errors) ==== const a: number - ~ + ~~~~~ !!! 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.errors.txt b/tests/baselines/reference/VariableDeclaration5_es6.errors.txt index e55f5a2654..c72d423e46 100644 --- a/tests/baselines/reference/VariableDeclaration5_es6.errors.txt +++ b/tests/baselines/reference/VariableDeclaration5_es6.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es6/variableDeclarations/VariableDeclaration5_es6.ts(1,7): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. +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/VariableDeclaration7_es6.errors.txt b/tests/baselines/reference/VariableDeclaration7_es6.errors.txt index 5de31099e5..83d12d463e 100644 --- a/tests/baselines/reference/VariableDeclaration7_es6.errors.txt +++ b/tests/baselines/reference/VariableDeclaration7_es6.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es6/variableDeclarations/VariableDeclaration7_es6.ts(1,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +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/VariableDeclaration8_es6.errors.txt b/tests/baselines/reference/VariableDeclaration8_es6.errors.txt index 5409c6657c..e371c64c9a 100644 --- a/tests/baselines/reference/VariableDeclaration8_es6.errors.txt +++ b/tests/baselines/reference/VariableDeclaration8_es6.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es6/variableDeclarations/VariableDeclaration8_es6.ts(1,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +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/VariableDeclaration9_es6.errors.txt b/tests/baselines/reference/VariableDeclaration9_es6.errors.txt index 0a2a25858b..4a1890d469 100644 --- a/tests/baselines/reference/VariableDeclaration9_es6.errors.txt +++ b/tests/baselines/reference/VariableDeclaration9_es6.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es6/variableDeclarations/VariableDeclaration9_es6.ts(1,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +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/bpSpan_const.baseline b/tests/baselines/reference/bpSpan_const.baseline index bee7d93095..176fb76be8 100644 --- a/tests/baselines/reference/bpSpan_const.baseline +++ b/tests/baselines/reference/bpSpan_const.baseline @@ -76,21 +76,21 @@ -------------------------------- 7 > export const cc1 = false; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (181 to 210) SpanInfo: {"start":185,"length":24} - >export const cc1 = false - >:=> (line 7, col 4) to (line 7, col 28) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (181 to 210) SpanInfo: {"start":192,"length":17} + >const cc1 = false + >:=> (line 7, col 11) to (line 7, col 28) -------------------------------- 8 > export const cc2: number = 23; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (211 to 245) SpanInfo: {"start":215,"length":29} - >export const cc2: number = 23 - >:=> (line 8, col 4) to (line 8, col 33) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (211 to 245) SpanInfo: {"start":222,"length":22} + >const cc2: number = 23 + >:=> (line 8, col 11) to (line 8, col 33) -------------------------------- 9 > export const cc3 = 0, cc4 :string = "", cc5 = null; - ~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (246 to 270) SpanInfo: {"start":250,"length":20} - >export const cc3 = 0 - >:=> (line 9, col 4) to (line 9, col 24) + ~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (246 to 270) SpanInfo: {"start":257,"length":13} + >const cc3 = 0 + >:=> (line 9, col 11) to (line 9, col 24) 9 > export const cc3 = 0, cc4 :string = "", cc5 = null; ~~~~~~~~~~~~~~~~~~ => Pos: (271 to 288) SpanInfo: {"start":272,"length":16} diff --git a/tests/baselines/reference/bpSpan_let.baseline b/tests/baselines/reference/bpSpan_let.baseline index dff12280a9..d9a3c2f854 100644 --- a/tests/baselines/reference/bpSpan_let.baseline +++ b/tests/baselines/reference/bpSpan_let.baseline @@ -84,9 +84,9 @@ -------------------------------- 11 > export let ll2 = 0; - ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (221 to 244) SpanInfo: {"start":225,"length":18} - >export let ll2 = 0 - >:=> (line 11, col 4) to (line 11, col 22) + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (221 to 244) SpanInfo: {"start":232,"length":11} + >let ll2 = 0 + >:=> (line 11, col 11) to (line 11, col 22) -------------------------------- 12 >} ~ => Pos: (245 to 245) SpanInfo: {"start":245,"length":1} diff --git a/tests/baselines/reference/bpSpan_module.baseline b/tests/baselines/reference/bpSpan_module.baseline index 1414551265..e544fc4c43 100644 --- a/tests/baselines/reference/bpSpan_module.baseline +++ b/tests/baselines/reference/bpSpan_module.baseline @@ -50,9 +50,9 @@ -------------------------------- 7 > export var x = 30; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (67 to 93) SpanInfo: {"start":75,"length":17} - >export var x = 30 - >:=> (line 7, col 8) to (line 7, col 25) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (67 to 93) SpanInfo: {"start":82,"length":10} + >var x = 30 + >:=> (line 7, col 15) to (line 7, col 25) -------------------------------- 8 > } @@ -172,15 +172,15 @@ -------------------------------- 25 > { - ~~~~~~ => Pos: (261 to 266) SpanInfo: {"start":275,"length":17} - >export var x = 30 - >:=> (line 26, col 8) to (line 26, col 25) + ~~~~~~ => Pos: (261 to 266) SpanInfo: {"start":282,"length":10} + >var x = 30 + >:=> (line 26, col 15) to (line 26, col 25) -------------------------------- 26 > export var x = 30; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (267 to 293) SpanInfo: {"start":275,"length":17} - >export var x = 30 - >:=> (line 26, col 8) to (line 26, col 25) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (267 to 293) SpanInfo: {"start":282,"length":10} + >var x = 30 + >:=> (line 26, col 15) to (line 26, col 25) -------------------------------- 27 > } diff --git a/tests/baselines/reference/bpSpan_variables.baseline b/tests/baselines/reference/bpSpan_variables.baseline index 1904c34b83..545118daf8 100644 --- a/tests/baselines/reference/bpSpan_variables.baseline +++ b/tests/baselines/reference/bpSpan_variables.baseline @@ -58,15 +58,13 @@ -------------------------------- 9 > export var xx1; - ~~~~~~~~~~~~~~~~~~~~ => Pos: (119 to 138) SpanInfo: {"start":123,"length":14} - >export var xx1 - >:=> (line 9, col 4) to (line 9, col 18) + ~~~~~~~~~~~~~~~~~~~~ => Pos: (119 to 138) SpanInfo: undefined -------------------------------- 10 > export var xx2 = 10, xx3 = 10; - ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (139 to 162) SpanInfo: {"start":143,"length":19} - >export var xx2 = 10 - >:=> (line 10, col 4) to (line 10, col 23) + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (139 to 162) SpanInfo: {"start":150,"length":12} + >var xx2 = 10 + >:=> (line 10, col 11) to (line 10, col 23) 10 > export var xx2 = 10, xx3 = 10; ~~~~~~~~~~~ => Pos: (163 to 173) SpanInfo: {"start":164,"length":8} @@ -75,14 +73,7 @@ -------------------------------- 11 > export var xx4, xx5; - ~~~~~~~~~~~~~~~~~~~ => Pos: (174 to 192) SpanInfo: {"start":178,"length":14} - >export var xx4 - >:=> (line 11, col 4) to (line 11, col 18) -11 > export var xx4, xx5; - - ~~~~~~ => Pos: (193 to 198) SpanInfo: {"start":194,"length":3} - >xx5 - >:=> (line 11, col 20) to (line 11, col 23) + ~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (174 to 198) SpanInfo: undefined -------------------------------- 12 >} ~ => Pos: (199 to 199) SpanInfo: {"start":199,"length":1} diff --git a/tests/baselines/reference/constDeclarations-es5.errors.txt b/tests/baselines/reference/constDeclarations-es5.errors.txt index c928e6ae48..d15535349a 100644 --- a/tests/baselines/reference/constDeclarations-es5.errors.txt +++ b/tests/baselines/reference/constDeclarations-es5.errors.txt @@ -1,17 +1,17 @@ -tests/cases/compiler/constDeclarations-es5.ts(2,7): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/constDeclarations-es5.ts(3,7): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/constDeclarations-es5.ts(4,7): error TS1154: 'const' declarations are only available when targeting ECMAScript 6 and higher. +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/letDeclarations-es5-1.errors.txt b/tests/baselines/reference/letDeclarations-es5-1.errors.txt index f0430585a3..f8b5cf629d 100644 --- a/tests/baselines/reference/letDeclarations-es5-1.errors.txt +++ b/tests/baselines/reference/letDeclarations-es5-1.errors.txt @@ -1,27 +1,27 @@ -tests/cases/compiler/letDeclarations-es5-1.ts(1,9): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5-1.ts(2,9): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5-1.ts(3,9): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5-1.ts(4,9): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5-1.ts(5,9): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5-1.ts(6,9): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +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.errors.txt b/tests/baselines/reference/letDeclarations-es5.errors.txt index 34bd93dba3..27d526f03e 100644 --- a/tests/baselines/reference/letDeclarations-es5.errors.txt +++ b/tests/baselines/reference/letDeclarations-es5.errors.txt @@ -1,40 +1,40 @@ -tests/cases/compiler/letDeclarations-es5.ts(2,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(3,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(4,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(6,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(7,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(8,5): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(10,9): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. -tests/cases/compiler/letDeclarations-es5.ts(12,9): error TS1153: 'let' declarations are only available when targeting ECMAScript 6 and higher. +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/promiseChaining.js b/tests/baselines/reference/promiseChaining.js index 1d0962d30d..20961542b2 100644 --- a/tests/baselines/reference/promiseChaining.js +++ b/tests/baselines/reference/promiseChaining.js @@ -19,7 +19,7 @@ var Chain = (function () { Chain.prototype.then = function (cb) { var result = cb(this.value); // should get a fresh type parameter which each then call - var z = this.then(function (x) { return result; }).then(function (x) { return "abc"; }).then(function (x) { return x.length; }) /*number*/; // No error + var z = this.then(function (x) { return result; }).then(function (x) { return "abc"; }).then(function (x) { return x.length; }); // No error return new Chain(result); }; return Chain; diff --git a/tests/baselines/reference/promiseChaining1.js b/tests/baselines/reference/promiseChaining1.js index 9dc167f2db..ee79d3268b 100644 --- a/tests/baselines/reference/promiseChaining1.js +++ b/tests/baselines/reference/promiseChaining1.js @@ -19,7 +19,7 @@ var Chain2 = (function () { Chain2.prototype.then = function (cb) { var result = cb(this.value); // should get a fresh type parameter which each then call - var z = this.then(function (x) { return result; }).then(function (x) { return "abc"; }).then(function (x) { return x.length; }) /*number*/; // Should error on "abc" because it is not a Function + var z = this.then(function (x) { return result; }).then(function (x) { return "abc"; }).then(function (x) { return x.length; }); // Should error on "abc" because it is not a Function return new Chain2(result); }; return Chain2; diff --git a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_varDeclarations.ts b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_varDeclarations.ts index 50a112f462..346a102faa 100644 --- a/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_varDeclarations.ts +++ b/tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_varDeclarations.ts @@ -11,7 +11,7 @@ ////var a2, a/*varName4*/ - +debugger; test.markers().forEach((m) => { goTo.position(m.position, m.fileName); verify.completionListIsEmpty(); diff --git a/tests/cases/fourslash/navigateItemsLet.ts b/tests/cases/fourslash/navigateItemsLet.ts index dc39952270..8a82d04273 100644 --- a/tests/cases/fourslash/navigateItemsLet.ts +++ b/tests/cases/fourslash/navigateItemsLet.ts @@ -1,10 +1,10 @@ /// -////{| "itemName": "c", "kind": "let", "parentName": "" |}let c = 10; -////function foo() { -//// {| "itemName": "d", "kind": "let", "parentName": "foo" |}let d = 10; -////} - +////{| "itemName": "c", "kind": "let", "parentName": "" |}let c = 10; +////function foo() { +//// {| "itemName": "d", "kind": "let", "parentName": "foo" |}let d = 10; +////} +debugger; test.markers().forEach(marker => { verify.navigationItemsListContains( marker.data.itemName, diff --git a/tests/cases/fourslash/navigationItemsExactMatch2.ts b/tests/cases/fourslash/navigationItemsExactMatch2.ts index 8f934dcc3c..adf8e69761 100644 --- a/tests/cases/fourslash/navigationItemsExactMatch2.ts +++ b/tests/cases/fourslash/navigationItemsExactMatch2.ts @@ -17,7 +17,7 @@ ////function distance2(distanceParam1): void { //// var distanceLocal1; ////} - +debugger; goTo.marker("file1"); verify.navigationItemsListCount(2, "point", "exact"); verify.navigationItemsListCount(5, "distance", "prefix"); diff --git a/tests/cases/fourslash/quickInfoDisplayPartsConst.ts b/tests/cases/fourslash/quickInfoDisplayPartsConst.ts index 62295017df..8871a6cc15 100644 --- a/tests/cases/fourslash/quickInfoDisplayPartsConst.ts +++ b/tests/cases/fourslash/quickInfoDisplayPartsConst.ts @@ -22,6 +22,7 @@ /////*15*/h(10); /////*16*/h("hello"); +debugger; var marker = 0; function verifyConst(name: string, typeDisplay: ts.SymbolDisplayPart[], optionalNameDisplay?: ts.SymbolDisplayPart[], optionalKindModifiers?: string) { marker++;