Merge branch 'funcDeclsInBlocks' into sourceFileUpdate

Conflicts:
	src/compiler/parser.ts
	src/compiler/utilities.ts
This commit is contained in:
Cyrus Najmabadi 2014-12-16 03:12:31 -08:00
commit 8917e96663
32 changed files with 289 additions and 261 deletions

View file

@ -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((<Declaration>node).name)) {
bindChildren(node, 0, /*isBlockScopeContainer*/ false);
}
else if (node.flags & NodeFlags.BlockScoped) {
else if (getNodeFlags(node) & NodeFlags.BlockScoped) {
bindBlockScopedVariableDeclaration(<Declaration>node);
}
else {

View file

@ -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((<UnionType>type).types, t => getWidenedType(t)));
return getUnionType(map((<UnionType>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((<UnionType>type).types, t => isTupleLikeType(t)) : isTupleLikeType(type));
return !!(type.flags & TypeFlags.Union ? forEach((<UnionType>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, (<Identifier>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(<VariableLikeDeclaration[]>node.declarations, checkVariableLikeDeclaration);
if (node.initializer) checkExpression(node.initializer);
if (node.initializer) {
if (node.initializer.kind === SyntaxKind.VariableDeclarationList) {
forEach((<VariableDeclarationList>node.initializer).declarations, checkVariableDeclaration)
}
else {
checkExpression(<Expression>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 = <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 = <Expression>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:

View file

@ -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 = <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 = <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(<BinaryExpression>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);
}

View file

@ -158,7 +158,9 @@ module ts {
child((<SourceFile>node).endOfFileToken);
case SyntaxKind.VariableStatement:
return children(node.modifiers) ||
children((<VariableStatement>node).declarations);
child((<VariableStatement>node).declarationList);
case SyntaxKind.VariableDeclarationList:
return children((<VariableDeclarationList>node).declarations);
case SyntaxKind.ExpressionStatement:
return child((<ExpressionStatement>node).expression);
case SyntaxKind.IfStatement:
@ -172,14 +174,12 @@ module ts {
return child((<WhileStatement>node).expression) ||
child((<WhileStatement>node).statement);
case SyntaxKind.ForStatement:
return children((<ForStatement>node).declarations) ||
child((<ForStatement>node).initializer) ||
return child((<ForStatement>node).initializer) ||
child((<ForStatement>node).condition) ||
child((<ForStatement>node).iterator) ||
child((<ForStatement>node).statement);
case SyntaxKind.ForInStatement:
return children((<ForInStatement>node).declarations) ||
child((<ForInStatement>node).variable) ||
return child((<ForInStatement>node).initializer) ||
child((<ForInStatement>node).expression) ||
child((<ForInStatement>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 = <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 = <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<VariableDeclaration>, flag: NodeFlags): NodeArray<VariableDeclaration> {
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
node.flags |= flag;
if (node.name && isBindingPattern(node.name)) {
setFlag((<BindingPattern>node.name).elements, flag);
}
}
return nodes;
}
function parseVariableDeclarationList(disallowIn: boolean): VariableDeclarationList {
var node = <VariableDeclarationList>createNode(SyntaxKind.VariableDeclarationList);
function parseVariableDeclarationList(): NodeArray<VariableDeclaration> {
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 = <VariableStatement>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(<ElementAccessExpression>node);
case SyntaxKind.ExportAssignment: return checkExportAssignment(<ExportAssignment>node);
case SyntaxKind.ExternalModuleReference: return checkExternalModuleReference(<ExternalModuleReference>node);
case SyntaxKind.ForInStatement: return checkForInStatement(<ForInStatement>node);
case SyntaxKind.ForStatement: return checkForStatement(<ForStatement>node);
case SyntaxKind.FunctionDeclaration: return checkFunctionDeclaration(<FunctionLikeDeclaration>node);
case SyntaxKind.FunctionExpression: return checkFunctionExpression(<FunctionExpression>node);
case SyntaxKind.GetAccessor: return checkGetAccessor(<MethodDeclaration>node);
@ -4987,6 +4968,7 @@ module ts {
case SyntaxKind.TypeParameter: return checkTypeParameter(<TypeParameterDeclaration>node);
case SyntaxKind.TypeReference: return checkTypeReference(<TypeReferenceNode>node);
case SyntaxKind.VariableDeclaration: return checkVariableDeclaration(<VariableDeclaration>node);
case SyntaxKind.VariableDeclarationList: return checkVariableDeclarationList(<VariableDeclarationList>node);
case SyntaxKind.VariableStatement: return checkVariableStatement(<VariableStatement>node);
case SyntaxKind.WithStatement: return checkWithStatement(<WithStatement>node);
case SyntaxKind.YieldExpression: return checkYieldExpression(<YieldExpression>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<VariableDeclaration>) {
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<VariableDeclaration>): 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);
}
}

View file

@ -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<VariableDeclaration>;
}
// 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<VariableDeclaration>;
declarationList: VariableDeclarationList;
}
export interface ExpressionStatement extends Statement {
@ -728,15 +733,13 @@ module ts {
}
export interface ForStatement extends IterationStatement {
declarations?: NodeArray<VariableDeclaration>;
initializer?: Expression;
initializer?: VariableDeclarationList | Expression;
condition?: Expression;
iterator?: Expression;
}
export interface ForInStatement extends IterationStatement {
declarations?: NodeArray<VariableDeclaration>;
variable?: Expression;
initializer: VariableDeclarationList | Expression;
expression: Expression;
}

View file

@ -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 (<ExpressionStatement>parent).expression === node;
case SyntaxKind.ForStatement:
return (<ForStatement>parent).initializer === node ||
(<ForStatement>parent).condition === node ||
(<ForStatement>parent).iterator === node;
var forStatement = <ForStatement>parent;
return (forStatement.initializer === node && forStatement.initializer.kind !== SyntaxKind.VariableDeclarationList) ||
forStatement.condition === node ||
forStatement.iterator === node;
case SyntaxKind.ForInStatement:
return (<ForInStatement>parent).variable === node ||
(<ForInStatement>parent).expression === node;
var forInStatement = <ForInStatement>parent;
return (forInStatement.initializer === node && forInStatement.initializer.kind !== SyntaxKind.VariableDeclarationList) ||
forInStatement.expression === node;
case SyntaxKind.TypeAssertionExpression:
return node === (<TypeAssertion>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;

View file

@ -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 => {

View file

@ -83,7 +83,7 @@ module ts.BreakpointResolver {
switch (node.kind) {
case SyntaxKind.VariableStatement:
// Span on first variable declaration
return spanInVariableDeclaration((<VariableStatement>node).declarations[0]);
return spanInVariableDeclaration((<VariableStatement>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((<ForStatement>variableDeclaration.parent).declarations, variableDeclaration);
var isParentVariableStatement = variableDeclaration.parent.parent.kind === SyntaxKind.VariableStatement;
var isDeclarationOfForStatement = variableDeclaration.parent.parent.kind === SyntaxKind.ForStatement && contains((<VariableDeclarationList>(<ForStatement>variableDeclaration.parent.parent).initializer).declarations, variableDeclaration);
var declarations = isParentVariableStatement
? (<VariableStatement>variableDeclaration.parent).declarations
? (<VariableStatement>variableDeclaration.parent.parent).declarationList.declarations
: isDeclarationOfForStatement
? (<ForStatement>variableDeclaration.parent).declarations
? (<VariableDeclarationList>(<ForStatement>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 = <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);
}

View file

@ -44,7 +44,7 @@ module ts.NavigationBar {
function visit(node: Node) {
switch (node.kind) {
case SyntaxKind.VariableStatement:
forEach((<VariableStatement>node).declarations, visit);
forEach((<VariableStatement>node).declarationList.declarations, visit);
break;
case SyntaxKind.ObjectBindingPattern:
case SyntaxKind.ArrayBindingPattern:

View file

@ -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());
}

View file

@ -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);

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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}

View file

@ -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}

View file

@ -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 > }

View file

@ -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}

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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;

View file

@ -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;

View file

@ -11,7 +11,7 @@
////var a2, a/*varName4*/
debugger;
test.markers().forEach((m) => {
goTo.position(m.position, m.fileName);
verify.completionListIsEmpty();

View file

@ -1,10 +1,10 @@
/// <reference path="fourslash.ts" />
////{| "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,

View file

@ -17,7 +17,7 @@
////function distance2(distanceParam1): void {
//// var distanceLocal1;
////}
debugger;
goTo.marker("file1");
verify.navigationItemsListCount(2, "point", "exact");
verify.navigationItemsListCount(5, "distance", "prefix");

View file

@ -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++;