mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'master' into overloadResolution
Conflicts: src/compiler/diagnosticInformationMap.generated.ts src/compiler/diagnosticMessages.json
This commit is contained in:
+81
-36
@@ -31,13 +31,14 @@ module ts {
|
||||
|
||||
var parent: Node;
|
||||
var container: Declaration;
|
||||
var blockScopeContainer: Node;
|
||||
var lastContainer: Declaration;
|
||||
var symbolCount = 0;
|
||||
var Symbol = objectAllocator.getSymbolConstructor();
|
||||
|
||||
if (!file.locals) {
|
||||
file.locals = {};
|
||||
container = file;
|
||||
container = blockScopeContainer = file;
|
||||
bind(file);
|
||||
file.symbolCount = symbolCount;
|
||||
}
|
||||
@@ -86,10 +87,11 @@ module ts {
|
||||
}
|
||||
// Report errors every position with duplicate declaration
|
||||
// Report errors on previous encountered declarations
|
||||
var message = symbol.flags & SymbolFlags.BlockScopedVariable ? Diagnostics.Cannot_redeclare_block_scoped_variable_0 : Diagnostics.Duplicate_identifier_0;
|
||||
forEach(symbol.declarations, (declaration) => {
|
||||
file.semanticErrors.push(createDiagnosticForNode(declaration.name, Diagnostics.Duplicate_identifier_0, getDisplayName(declaration)));
|
||||
file.semanticErrors.push(createDiagnosticForNode(declaration.name, message, getDisplayName(declaration)));
|
||||
});
|
||||
file.semanticErrors.push(createDiagnosticForNode(node.name, Diagnostics.Duplicate_identifier_0, getDisplayName(node)));
|
||||
file.semanticErrors.push(createDiagnosticForNode(node.name, message, getDisplayName(node)));
|
||||
|
||||
symbol = createSymbol(0, name);
|
||||
}
|
||||
@@ -167,12 +169,13 @@ module ts {
|
||||
|
||||
// All container nodes are kept on a linked list in declaration order. This list is used by the getLocalNameOfContainer function
|
||||
// in the type checker to validate that the local name used for a container is unique.
|
||||
function bindChildren(node: Declaration, symbolKind: SymbolFlags) {
|
||||
function bindChildren(node: Declaration, symbolKind: SymbolFlags, isBlockScopeContainer: boolean) {
|
||||
if (symbolKind & SymbolFlags.HasLocals) {
|
||||
node.locals = {};
|
||||
}
|
||||
var saveParent = parent;
|
||||
var saveContainer = container;
|
||||
var savedBlockScopeContainer = blockScopeContainer;
|
||||
parent = node;
|
||||
if (symbolKind & SymbolFlags.IsContainer) {
|
||||
container = node;
|
||||
@@ -184,12 +187,16 @@ module ts {
|
||||
lastContainer = container;
|
||||
}
|
||||
}
|
||||
if (isBlockScopeContainer) {
|
||||
blockScopeContainer = node;
|
||||
}
|
||||
forEachChild(node, bind);
|
||||
container = saveContainer;
|
||||
parent = saveParent;
|
||||
blockScopeContainer = savedBlockScopeContainer;
|
||||
}
|
||||
|
||||
function bindDeclaration(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags) {
|
||||
function bindDeclaration(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags, isBlockScopeContainer: boolean) {
|
||||
switch (container.kind) {
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
declareModuleMember(node, symbolKind, symbolExcludes);
|
||||
@@ -225,121 +232,159 @@ module ts {
|
||||
declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes);
|
||||
break;
|
||||
}
|
||||
bindChildren(node, symbolKind);
|
||||
bindChildren(node, symbolKind, isBlockScopeContainer);
|
||||
}
|
||||
|
||||
function bindConstructorDeclaration(node: ConstructorDeclaration) {
|
||||
bindDeclaration(node, SymbolFlags.Constructor, 0);
|
||||
bindDeclaration(node, SymbolFlags.Constructor, 0, /*isBlockScopeContainer*/ true);
|
||||
forEach(node.parameters, p => {
|
||||
if (p.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected)) {
|
||||
bindDeclaration(p, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
|
||||
bindDeclaration(p, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function bindModuleDeclaration(node: ModuleDeclaration) {
|
||||
if (node.name.kind === SyntaxKind.StringLiteral) {
|
||||
bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes);
|
||||
bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes, /*isBlockScopeContainer*/ true);
|
||||
}
|
||||
else if (isInstantiated(node)) {
|
||||
bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes);
|
||||
bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes, /*isBlockScopeContainer*/ true);
|
||||
}
|
||||
else {
|
||||
bindDeclaration(node, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes);
|
||||
bindDeclaration(node, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes, /*isBlockScopeContainer*/ true);
|
||||
}
|
||||
}
|
||||
|
||||
function bindAnonymousDeclaration(node: Node, symbolKind: SymbolFlags, name: string) {
|
||||
function bindAnonymousDeclaration(node: Node, symbolKind: SymbolFlags, name: string, isBlockScopeContainer: boolean) {
|
||||
var symbol = createSymbol(symbolKind, name);
|
||||
addDeclarationToSymbol(symbol, node, symbolKind);
|
||||
bindChildren(node, symbolKind);
|
||||
bindChildren(node, symbolKind, isBlockScopeContainer);
|
||||
}
|
||||
|
||||
function bindCatchVariableDeclaration(node: CatchBlock) {
|
||||
var symbol = createSymbol(SymbolFlags.Variable, node.variable.text || "__missing");
|
||||
addDeclarationToSymbol(symbol, node, SymbolFlags.Variable);
|
||||
var symbol = createSymbol(SymbolFlags.FunctionScopedVariable, node.variable.text || "__missing");
|
||||
addDeclarationToSymbol(symbol, node, SymbolFlags.FunctionScopedVariable);
|
||||
var saveParent = parent;
|
||||
parent = node;
|
||||
var savedBlockScopeContainer = blockScopeContainer;
|
||||
parent = blockScopeContainer = node;
|
||||
forEachChild(node, bind);
|
||||
parent = saveParent;
|
||||
blockScopeContainer = savedBlockScopeContainer;
|
||||
}
|
||||
|
||||
function bindBlockScopedVariableDeclaration(node: Declaration) {
|
||||
switch (blockScopeContainer.kind) {
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
declareModuleMember(node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes);
|
||||
break;
|
||||
case SyntaxKind.SourceFile:
|
||||
if (isExternalModule(<SourceFile>container)) {
|
||||
declareModuleMember(node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
if (!blockScopeContainer.locals) {
|
||||
blockScopeContainer.locals = {};
|
||||
}
|
||||
declareSymbol(blockScopeContainer.locals, undefined, node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes);
|
||||
}
|
||||
|
||||
bindChildren(node, SymbolFlags.BlockScopedVariable, /*isBlockScopeContainer*/ false);
|
||||
}
|
||||
|
||||
function bind(node: Node) {
|
||||
node.parent = parent;
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.TypeParameter:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.Parameter:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Variable, SymbolFlags.ParameterExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Variable, SymbolFlags.VariableExcludes);
|
||||
if (node.flags & NodeFlags.BlockScoped) {
|
||||
bindBlockScopedVariableDeclaration(<Declaration>node);
|
||||
}
|
||||
else {
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.FunctionScopedVariable, SymbolFlags.FunctionScopedVariableExcludes, /*isBlockScopeContainer*/ false);
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.Property:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.EnumMember:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.CallSignature:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.CallSignature, 0);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.CallSignature, 0, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.Method:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Method, SymbolFlags.MethodExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Method, SymbolFlags.MethodExcludes, /*isBlockScopeContainer*/ true);
|
||||
break;
|
||||
case SyntaxKind.ConstructSignature:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.ConstructSignature, 0);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.ConstructSignature, 0, /*isBlockScopeContainer*/ true);
|
||||
break;
|
||||
case SyntaxKind.IndexSignature:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.IndexSignature, 0);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.IndexSignature, 0, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Function, SymbolFlags.FunctionExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Function, SymbolFlags.FunctionExcludes, /*isBlockScopeContainer*/ true);
|
||||
break;
|
||||
case SyntaxKind.Constructor:
|
||||
bindConstructorDeclaration(<ConstructorDeclaration>node);
|
||||
break;
|
||||
case SyntaxKind.GetAccessor:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes, /*isBlockScopeContainer*/ true);
|
||||
break;
|
||||
case SyntaxKind.SetAccessor:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes, /*isBlockScopeContainer*/ true);
|
||||
break;
|
||||
case SyntaxKind.TypeLiteral:
|
||||
bindAnonymousDeclaration(node, SymbolFlags.TypeLiteral, "__type");
|
||||
bindAnonymousDeclaration(node, SymbolFlags.TypeLiteral, "__type", /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.ObjectLiteral:
|
||||
bindAnonymousDeclaration(node, SymbolFlags.ObjectLiteral, "__object");
|
||||
bindAnonymousDeclaration(node, SymbolFlags.ObjectLiteral, "__object", /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
bindAnonymousDeclaration(node, SymbolFlags.Function, "__function");
|
||||
bindAnonymousDeclaration(node, SymbolFlags.Function, "__function", /*isBlockScopeContainer*/ true);
|
||||
break;
|
||||
case SyntaxKind.CatchBlock:
|
||||
bindCatchVariableDeclaration(<CatchBlock>node);
|
||||
break;
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Class, SymbolFlags.ClassExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Class, SymbolFlags.ClassExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Enum, SymbolFlags.EnumExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Enum, SymbolFlags.EnumExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
bindModuleDeclaration(<ModuleDeclaration>node);
|
||||
break;
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Import, SymbolFlags.ImportExcludes);
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Import, SymbolFlags.ImportExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.SourceFile:
|
||||
if (isExternalModule(<SourceFile>node)) {
|
||||
bindAnonymousDeclaration(node, SymbolFlags.ValueModule, '"' + removeFileExtension((<SourceFile>node).filename) + '"');
|
||||
bindAnonymousDeclaration(node, SymbolFlags.ValueModule, '"' + removeFileExtension((<SourceFile>node).filename) + '"', /*isBlockScopeContainer*/ true);
|
||||
break;
|
||||
}
|
||||
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.CatchBlock:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
case SyntaxKind.ForStatement:
|
||||
case SyntaxKind.ForInStatement:
|
||||
case SyntaxKind.SwitchStatement:
|
||||
bindChildren(node, 0 , true);
|
||||
break;
|
||||
|
||||
default:
|
||||
var saveParent = parent;
|
||||
parent = node;
|
||||
|
||||
+114
-87
@@ -108,7 +108,8 @@ module ts {
|
||||
isImplementationOfOverload: isImplementationOfOverload,
|
||||
getAliasedSymbol: resolveImport,
|
||||
isUndefinedSymbol: symbol => symbol === undefinedSymbol,
|
||||
isArgumentsSymbol: symbol => symbol === argumentsSymbol
|
||||
isArgumentsSymbol: symbol => symbol === argumentsSymbol,
|
||||
hasEarlyErrors: hasEarlyErrors
|
||||
};
|
||||
|
||||
var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined");
|
||||
@@ -177,7 +178,8 @@ module ts {
|
||||
|
||||
function getExcludedSymbolFlags(flags: SymbolFlags): SymbolFlags {
|
||||
var result: SymbolFlags = 0;
|
||||
if (flags & SymbolFlags.Variable) result |= SymbolFlags.VariableExcludes;
|
||||
if (flags & SymbolFlags.BlockScopedVariable) result |= SymbolFlags.BlockScopedVariableExcludes;
|
||||
if (flags & SymbolFlags.FunctionScopedVariable) result |= SymbolFlags.FunctionScopedVariableExcludes;
|
||||
if (flags & SymbolFlags.Property) result |= SymbolFlags.PropertyExcludes;
|
||||
if (flags & SymbolFlags.EnumMember) result |= SymbolFlags.EnumMemberExcludes;
|
||||
if (flags & SymbolFlags.Function) result |= SymbolFlags.FunctionExcludes;
|
||||
@@ -227,8 +229,13 @@ module ts {
|
||||
recordMergedSymbol(target, source);
|
||||
}
|
||||
else {
|
||||
var message = target.flags & SymbolFlags.BlockScopedVariable || source.flags & SymbolFlags.BlockScopedVariable
|
||||
? Diagnostics.Cannot_redeclare_block_scoped_variable_0 : Diagnostics.Duplicate_identifier_0;
|
||||
forEach(source.declarations, node => {
|
||||
error(node.name ? node.name : node, Diagnostics.Duplicate_identifier_0, symbolToString(source));
|
||||
error(node.name ? node.name : node, message, symbolToString(source));
|
||||
});
|
||||
forEach(target.declarations, node => {
|
||||
error(node.name ? node.name : node, message, symbolToString(source));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -319,6 +326,25 @@ module ts {
|
||||
if (!s && nameNotFoundMessage) {
|
||||
error(errorLocation, nameNotFoundMessage, nameArg);
|
||||
}
|
||||
|
||||
if (s && s.flags & SymbolFlags.BlockScopedVariable) {
|
||||
// Block-scoped variables can not be used before their definition
|
||||
var declaration = forEach(s.declarations, d => d.flags & NodeFlags.BlockScoped ? d : undefined);
|
||||
Debug.assert(declaration, "Block-scoped variable declaration is undefined");
|
||||
var declarationSourceFile = getSourceFileOfNode(declaration);
|
||||
var referenceSourceFile = getSourceFileOfNode(errorLocation);
|
||||
if (declarationSourceFile === referenceSourceFile) {
|
||||
if (declaration.pos > errorLocation.pos) {
|
||||
error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, identifierToString(declaration.name));
|
||||
}
|
||||
}
|
||||
else if (compilerOptions.out) {
|
||||
var sourceFiles = program.getSourceFiles();
|
||||
if (sourceFiles.indexOf(referenceSourceFile) < sourceFiles.indexOf(declarationSourceFile)) {
|
||||
error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, identifierToString(declaration.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -4205,8 +4231,8 @@ module ts {
|
||||
// Get the narrowed type of a given symbol at a given location
|
||||
function getNarrowedTypeOfSymbol(symbol: Symbol, node: Node) {
|
||||
var type = getTypeOfSymbol(symbol);
|
||||
// Only narrow when symbol is variable of a non-primitive type
|
||||
if (symbol.flags & SymbolFlags.Variable && isTypeAnyOrObjectOrTypeParameter(type)) {
|
||||
// Only narrow when symbol is variable of a structured type
|
||||
if (symbol.flags & SymbolFlags.Variable && type.flags & TypeFlags.Structured) {
|
||||
while (true) {
|
||||
var child = node;
|
||||
node = node.parent;
|
||||
@@ -5735,7 +5761,7 @@ module ts {
|
||||
return true;
|
||||
}
|
||||
|
||||
function checkReferenceExpression(n: Node, message: DiagnosticMessage): boolean {
|
||||
function checkReferenceExpression(n: Node, invalidReferenceMessage: DiagnosticMessage, constantVarianleMessage: DiagnosticMessage): boolean {
|
||||
function findSymbol(n: Node): Symbol {
|
||||
var symbol = getNodeLinks(n).resolvedSymbol;
|
||||
// Because we got the symbol from the resolvedSymbol property, it might be of kind
|
||||
@@ -5774,8 +5800,34 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function isConstVariableReference(n: Node): boolean {
|
||||
switch (n.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
case SyntaxKind.PropertyAccess:
|
||||
var symbol = findSymbol(n);
|
||||
return symbol && (symbol.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & NodeFlags.Const) !== 0;
|
||||
case SyntaxKind.IndexedAccess:
|
||||
var index = (<IndexedAccess>n).index;
|
||||
var symbol = findSymbol((<IndexedAccess>n).object);
|
||||
if (symbol && index.kind === SyntaxKind.StringLiteral) {
|
||||
var name = (<LiteralExpression>index).text;
|
||||
var prop = getPropertyOfType(getTypeOfSymbol(symbol), name);
|
||||
return prop && (prop.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(prop) & NodeFlags.Const) !== 0;
|
||||
}
|
||||
return false;
|
||||
case SyntaxKind.ParenExpression:
|
||||
return isConstVariableReference((<ParenExpression>n).expression);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isReferenceOrErrorExpression(n)) {
|
||||
error(n, message);
|
||||
error(n, invalidReferenceMessage);
|
||||
return false;
|
||||
}
|
||||
if (isConstVariableReference(n)) {
|
||||
error(n, constantVarianleMessage);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -5800,7 +5852,9 @@ module ts {
|
||||
var ok = checkArithmeticOperandType(node.operand, operandType, Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type);
|
||||
if (ok) {
|
||||
// run check only if former checks succeeded to avoid reporting cascading errors
|
||||
checkReferenceExpression(node.operand, Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer);
|
||||
checkReferenceExpression(node.operand,
|
||||
Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer,
|
||||
Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant);
|
||||
}
|
||||
return numberType;
|
||||
}
|
||||
@@ -5812,13 +5866,19 @@ module ts {
|
||||
var ok = checkArithmeticOperandType(node.operand, operandType, Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type);
|
||||
if (ok) {
|
||||
// run check only if former checks succeeded to avoid reporting cascading errors
|
||||
checkReferenceExpression(node.operand, Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer);
|
||||
checkReferenceExpression(node.operand,
|
||||
Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer,
|
||||
Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant);
|
||||
}
|
||||
return numberType;
|
||||
}
|
||||
|
||||
function isTypeAnyOrObjectOrTypeParameter(type: Type): boolean {
|
||||
return (type.flags & (TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) !== 0;
|
||||
// Return true if type is any, an object type, a type parameter, or a union type composed of only those kinds of types
|
||||
function isStructuredType(type: Type): boolean {
|
||||
if (type.flags & TypeFlags.Union) {
|
||||
return !forEach((<UnionType>type).types, t => !isStructuredType(t));
|
||||
}
|
||||
return (type.flags & TypeFlags.Structured) !== 0;
|
||||
}
|
||||
|
||||
function checkInstanceOfExpression(node: BinaryExpression, leftType: Type, rightType: Type): Type {
|
||||
@@ -5827,7 +5887,7 @@ module ts {
|
||||
// and the right operand to be of type Any or a subtype of the 'Function' interface type.
|
||||
// The result is always of the Boolean primitive type.
|
||||
// NOTE: do not raise error if leftType is unknown as related error was already reported
|
||||
if (leftType !== unknownType && !isTypeAnyOrObjectOrTypeParameter(leftType)) {
|
||||
if (leftType !== unknownType && !isStructuredType(leftType)) {
|
||||
error(node.left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
|
||||
}
|
||||
// NOTE: do not raise error if right is unknown as related error was already reported
|
||||
@@ -5845,7 +5905,7 @@ module ts {
|
||||
if (leftType !== anyType && leftType !== stringType && leftType !== numberType) {
|
||||
error(node.left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_types_any_string_or_number);
|
||||
}
|
||||
if (!isTypeAnyOrObjectOrTypeParameter(rightType)) {
|
||||
if (!isStructuredType(rightType)) {
|
||||
error(node.right, Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
|
||||
}
|
||||
return booleanType;
|
||||
@@ -5989,7 +6049,7 @@ module ts {
|
||||
// requires VarExpr to be classified as a reference
|
||||
// A compound assignment furthermore requires VarExpr to be classified as a reference (section 4.1)
|
||||
// and the type of the non - compound operation to be assignable to the type of VarExpr.
|
||||
var ok = checkReferenceExpression(node.left, Diagnostics.Invalid_left_hand_side_of_assignment_expression);
|
||||
var ok = checkReferenceExpression(node.left, Diagnostics.Invalid_left_hand_side_of_assignment_expression, Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant);
|
||||
// Use default messages
|
||||
if (ok) {
|
||||
// to avoid cascading errors check assignability only if 'isReference' check succeeded and no errors were reported
|
||||
@@ -6963,6 +7023,38 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function checkCollisionWithConstDeclarations(node: VariableDeclaration) {
|
||||
// Variable declarations are hoisted to the top of their function scope. They can shadow
|
||||
// block scoped declarations, which bind tighter. this will not be flagged as duplicate definition
|
||||
// by the binder as the declaration scope is different.
|
||||
// A non-initialized declaration is a no-op as the block declaration will resolve before the var
|
||||
// declaration. the problem is if the declaration has an initializer. this will act as a write to the
|
||||
// block declared value. this is fine for let, but not const.
|
||||
//
|
||||
// Only consider declarations with initializers, uninitialized var declarations will not
|
||||
// step on a const variable.
|
||||
// Do not consider let and const declarations, as duplicate block-scoped declarations
|
||||
// are handled by the binder.
|
||||
// We are only looking for var declarations that step on const declarations from a
|
||||
// different scope. e.g.:
|
||||
// var x = 0;
|
||||
// {
|
||||
// const x = 0;
|
||||
// var x = 0;
|
||||
// }
|
||||
if (node.initializer && (node.flags & 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);
|
||||
if (localDeclarationSymbol && localDeclarationSymbol !== symbol && localDeclarationSymbol.flags & SymbolFlags.BlockScopedVariable) {
|
||||
if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & NodeFlags.Const) {
|
||||
error(node, Diagnostics.Cannot_redeclare_block_scoped_variable_0, symbolToString(localDeclarationSymbol));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkVariableDeclaration(node: VariableDeclaration) {
|
||||
checkSourceElement(node.type);
|
||||
checkExportsOnMergedDeclarations(node);
|
||||
@@ -6986,6 +7078,7 @@ module ts {
|
||||
// Use default messages
|
||||
checkTypeAssignableTo(checkAndMarkExpression(node.initializer), type, node, /*chainedMessage*/ undefined, /*terminalMessage*/ undefined);
|
||||
}
|
||||
checkCollisionWithConstDeclarations(node);
|
||||
}
|
||||
|
||||
checkCollisionWithCapturedSuperVariable(node, node.name);
|
||||
@@ -7059,14 +7152,14 @@ module ts {
|
||||
}
|
||||
else {
|
||||
// run check only former check succeeded to avoid cascading errors
|
||||
checkReferenceExpression(node.variable, Diagnostics.Invalid_left_hand_side_in_for_in_statement);
|
||||
checkReferenceExpression(node.variable, Diagnostics.Invalid_left_hand_side_in_for_in_statement, Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant);
|
||||
}
|
||||
}
|
||||
|
||||
var exprType = checkExpression(node.expression);
|
||||
// unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved
|
||||
// in this case error about missing name is already reported - do not report extra one
|
||||
if (!isTypeAnyOrObjectOrTypeParameter(exprType) && exprType !== unknownType) {
|
||||
if (!isStructuredType(exprType) && exprType !== unknownType) {
|
||||
error(node.expression, Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter);
|
||||
}
|
||||
|
||||
@@ -7990,77 +8083,6 @@ module ts {
|
||||
return node.parent && node.parent.kind === SyntaxKind.TypeReference;
|
||||
}
|
||||
|
||||
function isExpression(node: Node): boolean {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ThisKeyword:
|
||||
case SyntaxKind.SuperKeyword:
|
||||
case SyntaxKind.NullKeyword:
|
||||
case SyntaxKind.TrueKeyword:
|
||||
case SyntaxKind.FalseKeyword:
|
||||
case SyntaxKind.RegularExpressionLiteral:
|
||||
case SyntaxKind.ArrayLiteral:
|
||||
case SyntaxKind.ObjectLiteral:
|
||||
case SyntaxKind.PropertyAccess:
|
||||
case SyntaxKind.IndexedAccess:
|
||||
case SyntaxKind.CallExpression:
|
||||
case SyntaxKind.NewExpression:
|
||||
case SyntaxKind.TypeAssertion:
|
||||
case SyntaxKind.ParenExpression:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.PrefixOperator:
|
||||
case SyntaxKind.PostfixOperator:
|
||||
case SyntaxKind.BinaryExpression:
|
||||
case SyntaxKind.ConditionalExpression:
|
||||
case SyntaxKind.OmittedExpression:
|
||||
return true;
|
||||
case SyntaxKind.QualifiedName:
|
||||
while (node.parent.kind === SyntaxKind.QualifiedName) node = node.parent;
|
||||
return node.parent.kind === SyntaxKind.TypeQuery;
|
||||
case SyntaxKind.Identifier:
|
||||
if (node.parent.kind === SyntaxKind.TypeQuery) {
|
||||
return true;
|
||||
}
|
||||
// Fall through
|
||||
case SyntaxKind.NumericLiteral:
|
||||
case SyntaxKind.StringLiteral:
|
||||
var parent = node.parent;
|
||||
switch (parent.kind) {
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.Property:
|
||||
case SyntaxKind.EnumMember:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
return (<VariableDeclaration>parent).initializer === node;
|
||||
case SyntaxKind.ExpressionStatement:
|
||||
case SyntaxKind.IfStatement:
|
||||
case SyntaxKind.DoStatement:
|
||||
case SyntaxKind.WhileStatement:
|
||||
case SyntaxKind.ReturnStatement:
|
||||
case SyntaxKind.WithStatement:
|
||||
case SyntaxKind.SwitchStatement:
|
||||
case SyntaxKind.CaseClause:
|
||||
case SyntaxKind.ThrowStatement:
|
||||
case SyntaxKind.SwitchStatement:
|
||||
return (<ExpressionStatement>parent).expression === node;
|
||||
case SyntaxKind.ForStatement:
|
||||
return (<ForStatement>parent).initializer === node ||
|
||||
(<ForStatement>parent).condition === node ||
|
||||
(<ForStatement>parent).iterator === node;
|
||||
case SyntaxKind.ForInStatement:
|
||||
return (<ForInStatement>parent).variable === node ||
|
||||
(<ForInStatement>parent).expression === node;
|
||||
case SyntaxKind.TypeAssertion:
|
||||
return node === (<TypeAssertion>parent).operand;
|
||||
default:
|
||||
if (isExpression(parent)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isTypeNode(node: Node): boolean {
|
||||
if (SyntaxKind.FirstTypeNode <= node.kind && node.kind <= SyntaxKind.LastTypeNode) {
|
||||
return true;
|
||||
@@ -8432,6 +8454,10 @@ module ts {
|
||||
return getDiagnostics().length > 0 || getGlobalDiagnostics().length > 0;
|
||||
}
|
||||
|
||||
function hasEarlyErrors(sourceFile?: SourceFile): boolean {
|
||||
return forEach(getDiagnostics(sourceFile), d => d.isEarly);
|
||||
}
|
||||
|
||||
function isReferencedImportDeclaration(node: ImportDeclaration): boolean {
|
||||
var symbol = getSymbolOfNode(node);
|
||||
if (getSymbolLinks(symbol).referenced) {
|
||||
@@ -8515,6 +8541,7 @@ module ts {
|
||||
getEnumMemberValue: getEnumMemberValue,
|
||||
isTopLevelValueImportedViaEntityName: isTopLevelValueImportedViaEntityName,
|
||||
hasSemanticErrors: hasSemanticErrors,
|
||||
hasEarlyErrors: hasEarlyErrors,
|
||||
isDeclarationVisible: isDeclarationVisible,
|
||||
isImplementationOfOverload: isImplementationOfOverload,
|
||||
writeTypeAtLocation: writeTypeAtLocation,
|
||||
|
||||
@@ -102,10 +102,10 @@ module ts {
|
||||
{
|
||||
name: "target",
|
||||
shortName: "t",
|
||||
type: { "es3": ScriptTarget.ES3, "es5": ScriptTarget.ES5 },
|
||||
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_or_ES5,
|
||||
type: { "es3": ScriptTarget.ES3, "es5": ScriptTarget.ES5 , "es6": ScriptTarget.ES6 },
|
||||
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental,
|
||||
paramType: Diagnostics.VERSION,
|
||||
error: Diagnostics.Argument_for_target_option_must_be_es3_or_es5
|
||||
error: Diagnostics.Argument_for_target_option_must_be_es3_es5_or_es6
|
||||
},
|
||||
{
|
||||
name: "version",
|
||||
|
||||
@@ -232,7 +232,8 @@ module ts {
|
||||
|
||||
messageText: text,
|
||||
category: message.category,
|
||||
code: message.code
|
||||
code: message.code,
|
||||
isEarly: message.isEarly
|
||||
};
|
||||
}
|
||||
|
||||
@@ -251,7 +252,8 @@ module ts {
|
||||
|
||||
messageText: text,
|
||||
category: message.category,
|
||||
code: message.code
|
||||
code: message.code,
|
||||
isEarly: message.isEarly
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,12 @@ module ts {
|
||||
Cannot_compile_external_modules_unless_the_module_flag_is_provided: { code: 1148, category: DiagnosticCategory.Error, key: "Cannot compile external modules unless the '--module' flag is provided." },
|
||||
Filename_0_differs_from_already_included_filename_1_only_in_casing: { code: 1149, category: DiagnosticCategory.Error, key: "Filename '{0}' differs from already included filename '{1}' only in casing" },
|
||||
new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead." },
|
||||
An_enum_member_cannot_have_a_numeric_name: { code: 1151, category: DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." },
|
||||
var_let_or_const_expected: { code: 1152, category: DiagnosticCategory.Error, key: "'var', 'let' or 'const' expected." },
|
||||
let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1153, category: DiagnosticCategory.Error, key: "'let' declarations are only available when targeting ECMAScript 6 and higher." },
|
||||
const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1154, category: DiagnosticCategory.Error, key: "'const' declarations are only available when targeting ECMAScript 6 and higher." },
|
||||
const_declarations_must_be_initialized: { code: 1155, category: DiagnosticCategory.Error, key: "'const' declarations must be initialized" },
|
||||
const_declarations_can_only_be_declared_inside_a_block: { code: 1156, category: DiagnosticCategory.Error, key: "'const' declarations can only be declared inside a block." },
|
||||
let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "'let' declarations can only be declared inside a block." },
|
||||
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
|
||||
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
|
||||
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
|
||||
@@ -261,9 +266,14 @@ module ts {
|
||||
Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses: { code: 2445, category: DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible within class '{1}' and its subclasses." },
|
||||
Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1: { code: 2446, category: DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible through an instance of class '{1}'." },
|
||||
The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead: { code: 2447, category: DiagnosticCategory.Error, key: "The '{0}' operator is not allowed for boolean types. Consider using '{1}' instead." },
|
||||
The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly_Colon: { code: 2448, category: DiagnosticCategory.Error, key: "The type argument for type parameter '{0}' cannot be inferred from the usage. Consider specifying the type arguments explicitly:" },
|
||||
Type_argument_candidate_1_is_not_a_valid_type_argument_because_it_is_not_a_supertype_of_candidate_0_Colon: { code: 2449, category: DiagnosticCategory.Error, key: "Type argument candidate '{1}' is not a valid type argument because it is not a supertype of candidate '{0}':" },
|
||||
Type_argument_candidate_1_is_not_a_valid_type_argument_because_it_is_not_a_supertype_of_candidate_0: { code: 2450, category: DiagnosticCategory.Error, key: "Type argument candidate '{1}' is not a valid type argument because it is not a supertype of candidate '{0}'." },
|
||||
Block_scoped_variable_0_used_before_its_declaration: { code: 2448, category: DiagnosticCategory.Error, key: "Block-scoped variable '{0}' used before its declaration.", isEarly: true },
|
||||
The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant: { code: 2449, category: DiagnosticCategory.Error, key: "The operand of an increment or decrement operator cannot be a constant.", isEarly: true },
|
||||
Left_hand_side_of_assignment_expression_cannot_be_a_constant: { code: 2450, category: DiagnosticCategory.Error, key: "Left-hand side of assignment expression cannot be a constant.", isEarly: true },
|
||||
Cannot_redeclare_block_scoped_variable_0: { code: 2451, category: DiagnosticCategory.Error, key: "Cannot redeclare block-scoped variable '{0}'.", isEarly: true },
|
||||
An_enum_member_cannot_have_a_numeric_name: { code: 2452, category: DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." },
|
||||
The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly_Colon: { code: 2453, category: DiagnosticCategory.Error, key: "The type argument for type parameter '{0}' cannot be inferred from the usage. Consider specifying the type arguments explicitly:" },
|
||||
Type_argument_candidate_1_is_not_a_valid_type_argument_because_it_is_not_a_supertype_of_candidate_0_Colon: { code: 2454, category: DiagnosticCategory.Error, key: "Type argument candidate '{1}' is not a valid type argument because it is not a supertype of candidate '{0}':" },
|
||||
Type_argument_candidate_1_is_not_a_valid_type_argument_because_it_is_not_a_supertype_of_candidate_0: { code: 2455, category: DiagnosticCategory.Error, key: "Type argument candidate '{1}' is not a valid type argument because it is not a supertype of candidate '{0}'." },
|
||||
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
|
||||
Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." },
|
||||
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
|
||||
@@ -358,7 +368,7 @@ module ts {
|
||||
Watch_input_files: { code: 6005, category: DiagnosticCategory.Message, key: "Watch input files." },
|
||||
Redirect_output_structure_to_the_directory: { code: 6006, category: DiagnosticCategory.Message, key: "Redirect output structure to the directory." },
|
||||
Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." },
|
||||
Specify_ECMAScript_target_version_Colon_ES3_default_or_ES5: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), or 'ES5'" },
|
||||
Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" },
|
||||
Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs' or 'amd'" },
|
||||
Print_this_message: { code: 6017, category: DiagnosticCategory.Message, key: "Print this message." },
|
||||
Print_the_compiler_s_version: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version." },
|
||||
@@ -380,7 +390,7 @@ module ts {
|
||||
Compiler_option_0_expects_an_argument: { code: 6044, category: DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." },
|
||||
Unterminated_quoted_string_in_response_file_0: { code: 6045, category: DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." },
|
||||
Argument_for_module_option_must_be_commonjs_or_amd: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs' or 'amd'." },
|
||||
Argument_for_target_option_must_be_es3_or_es5: { code: 6047, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3' or 'es5'." },
|
||||
Argument_for_target_option_must_be_es3_es5_or_es6: { code: 6047, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3', 'es5', or 'es6'." },
|
||||
Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: { code: 6048, category: DiagnosticCategory.Error, key: "Locale must be of the form <language> or <language>-<territory>. For example '{0}' or '{1}'." },
|
||||
Unsupported_locale_0: { code: 6049, category: DiagnosticCategory.Error, key: "Unsupported locale '{0}'." },
|
||||
Unable_to_open_file_0: { code: 6050, category: DiagnosticCategory.Error, key: "Unable to open file '{0}'." },
|
||||
|
||||
@@ -447,9 +447,29 @@
|
||||
"category": "Error",
|
||||
"code": 1150
|
||||
},
|
||||
"An enum member cannot have a numeric name.": {
|
||||
"'var', 'let' or 'const' expected.": {
|
||||
"category": "Error",
|
||||
"code": 1151
|
||||
"code": 1152
|
||||
},
|
||||
"'let' declarations are only available when targeting ECMAScript 6 and higher.": {
|
||||
"category": "Error",
|
||||
"code": 1153
|
||||
},
|
||||
"'const' declarations are only available when targeting ECMAScript 6 and higher.": {
|
||||
"category": "Error",
|
||||
"code": 1154
|
||||
},
|
||||
"'const' declarations must be initialized": {
|
||||
"category": "Error",
|
||||
"code": 1155
|
||||
},
|
||||
"'const' declarations can only be declared inside a block.": {
|
||||
"category": "Error",
|
||||
"code": 1156
|
||||
},
|
||||
"'let' declarations can only be declared inside a block.": {
|
||||
"category": "Error",
|
||||
"code": 1157
|
||||
},
|
||||
|
||||
"Duplicate identifier '{0}'.": {
|
||||
@@ -1036,18 +1056,41 @@
|
||||
"category": "Error",
|
||||
"code": 2447
|
||||
},
|
||||
"Block-scoped variable '{0}' used before its declaration.": {
|
||||
"category": "Error",
|
||||
"code": 2448,
|
||||
"isEarly": true
|
||||
},
|
||||
"The operand of an increment or decrement operator cannot be a constant.": {
|
||||
"category": "Error",
|
||||
"code": 2449,
|
||||
"isEarly": true
|
||||
},
|
||||
"Left-hand side of assignment expression cannot be a constant.": {
|
||||
"category": "Error",
|
||||
"code": 2450,
|
||||
"isEarly": true
|
||||
},
|
||||
"Cannot redeclare block-scoped variable '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 2451,
|
||||
"isEarly": true
|
||||
},
|
||||
"An enum member cannot have a numeric name.": {
|
||||
"category": "Error",
|
||||
"code": 2452
|
||||
},
|
||||
"The type argument for type parameter '{0}' cannot be inferred from the usage. Consider specifying the type arguments explicitly:": {
|
||||
"category": "Error",
|
||||
"code": 2448
|
||||
"code": 2453
|
||||
},
|
||||
|
||||
"Type argument candidate '{1}' is not a valid type argument because it is not a supertype of candidate '{0}':": {
|
||||
"category": "Error",
|
||||
"code": 2449
|
||||
"code": 2454
|
||||
},
|
||||
"Type argument candidate '{1}' is not a valid type argument because it is not a supertype of candidate '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 2450
|
||||
"code": 2455
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
@@ -1429,7 +1472,7 @@
|
||||
"category": "Message",
|
||||
"code": 6009
|
||||
},
|
||||
"Specify ECMAScript target version: 'ES3' (default), or 'ES5'": {
|
||||
"Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)": {
|
||||
"category": "Message",
|
||||
"code": 6015
|
||||
},
|
||||
@@ -1517,7 +1560,7 @@
|
||||
"category": "Error",
|
||||
"code": 6046
|
||||
},
|
||||
"Argument for '--target' option must be 'es3' or 'es5'.": {
|
||||
"Argument for '--target' option must be 'es3', 'es5', or 'es6'.": {
|
||||
"category": "Error",
|
||||
"code": 6047
|
||||
},
|
||||
|
||||
+44
-8
@@ -1143,7 +1143,15 @@ module ts {
|
||||
write(" ");
|
||||
endPos = emitToken(SyntaxKind.OpenParenToken, endPos);
|
||||
if (node.declarations) {
|
||||
emitToken(SyntaxKind.VarKeyword, endPos);
|
||||
if (node.declarations[0] && node.declarations[0].flags & NodeFlags.Let) {
|
||||
emitToken(SyntaxKind.LetKeyword, endPos);
|
||||
}
|
||||
else if (node.declarations[0] && node.declarations[0].flags & NodeFlags.Const) {
|
||||
emitToken(SyntaxKind.ConstKeyword, endPos);
|
||||
}
|
||||
else {
|
||||
emitToken(SyntaxKind.VarKeyword, endPos);
|
||||
}
|
||||
write(" ");
|
||||
emitCommaList(node.declarations, /*includeTrailingComma*/ false);
|
||||
}
|
||||
@@ -1163,7 +1171,12 @@ module ts {
|
||||
write(" ");
|
||||
endPos = emitToken(SyntaxKind.OpenParenToken, endPos);
|
||||
if (node.declaration) {
|
||||
emitToken(SyntaxKind.VarKeyword, endPos);
|
||||
if (node.declaration.flags & NodeFlags.Let) {
|
||||
emitToken(SyntaxKind.LetKeyword, endPos);
|
||||
}
|
||||
else {
|
||||
emitToken(SyntaxKind.VarKeyword, endPos);
|
||||
}
|
||||
write(" ");
|
||||
emit(node.declaration);
|
||||
}
|
||||
@@ -1292,7 +1305,17 @@ module ts {
|
||||
|
||||
function emitVariableStatement(node: VariableStatement) {
|
||||
emitLeadingComments(node);
|
||||
if (!(node.flags & NodeFlags.Export)) write("var ");
|
||||
if (!(node.flags & NodeFlags.Export)) {
|
||||
if (node.flags & NodeFlags.Let) {
|
||||
write("let ");
|
||||
}
|
||||
else if (node.flags & NodeFlags.Const) {
|
||||
write("const ");
|
||||
}
|
||||
else {
|
||||
write("var ");
|
||||
}
|
||||
}
|
||||
emitCommaList(node.declarations, /*includeTrailingComma*/ false);
|
||||
write(";");
|
||||
emitTrailingComments(node);
|
||||
@@ -2829,7 +2852,15 @@ module ts {
|
||||
if (hasDeclarationWithEmit) {
|
||||
emitJsDocComments(node);
|
||||
emitDeclarationFlags(node);
|
||||
write("var ");
|
||||
if (node.flags & NodeFlags.Let) {
|
||||
write("let ");
|
||||
}
|
||||
else if (node.flags & NodeFlags.Const) {
|
||||
write("const ");
|
||||
}
|
||||
else {
|
||||
write("var ");
|
||||
}
|
||||
emitCommaList(node.declarations, emitVariableDeclaration);
|
||||
write(";");
|
||||
writeLine();
|
||||
@@ -3240,11 +3271,14 @@ module ts {
|
||||
}
|
||||
|
||||
var hasSemanticErrors = resolver.hasSemanticErrors();
|
||||
var hasEarlyErrors = resolver.hasEarlyErrors(targetSourceFile);
|
||||
|
||||
function emitFile(jsFilePath: string, sourceFile?: SourceFile) {
|
||||
emitJavaScript(jsFilePath, sourceFile);
|
||||
if (!hasSemanticErrors && compilerOptions.declaration) {
|
||||
emitDeclarations(jsFilePath, sourceFile);
|
||||
if (!hasEarlyErrors) {
|
||||
emitJavaScript(jsFilePath, sourceFile);
|
||||
if (!hasSemanticErrors && compilerOptions.declaration) {
|
||||
emitDeclarations(jsFilePath, sourceFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3284,7 +3318,9 @@ module ts {
|
||||
|
||||
// Check and update returnCode for syntactic and semantic
|
||||
var returnCode: EmitReturnStatus;
|
||||
if (hasEmitterError) {
|
||||
if (hasEarlyErrors) {
|
||||
returnCode = EmitReturnStatus.AllOutputGenerationSkipped;
|
||||
} else if (hasEmitterError) {
|
||||
returnCode = EmitReturnStatus.EmitErrorsEncountered;
|
||||
} else if (hasSemanticErrors && compilerOptions.declaration) {
|
||||
returnCode = EmitReturnStatus.DeclarationGenerationSkipped;
|
||||
|
||||
+150
-26
@@ -67,6 +67,77 @@ module ts {
|
||||
return identifier.kind === SyntaxKind.Missing ? "(Missing)" : getTextOfNode(identifier);
|
||||
}
|
||||
|
||||
export function isExpression(node: Node): boolean {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ThisKeyword:
|
||||
case SyntaxKind.SuperKeyword:
|
||||
case SyntaxKind.NullKeyword:
|
||||
case SyntaxKind.TrueKeyword:
|
||||
case SyntaxKind.FalseKeyword:
|
||||
case SyntaxKind.RegularExpressionLiteral:
|
||||
case SyntaxKind.ArrayLiteral:
|
||||
case SyntaxKind.ObjectLiteral:
|
||||
case SyntaxKind.PropertyAccess:
|
||||
case SyntaxKind.IndexedAccess:
|
||||
case SyntaxKind.CallExpression:
|
||||
case SyntaxKind.NewExpression:
|
||||
case SyntaxKind.TypeAssertion:
|
||||
case SyntaxKind.ParenExpression:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.PrefixOperator:
|
||||
case SyntaxKind.PostfixOperator:
|
||||
case SyntaxKind.BinaryExpression:
|
||||
case SyntaxKind.ConditionalExpression:
|
||||
case SyntaxKind.OmittedExpression:
|
||||
return true;
|
||||
case SyntaxKind.QualifiedName:
|
||||
while (node.parent.kind === SyntaxKind.QualifiedName) node = node.parent;
|
||||
return node.parent.kind === SyntaxKind.TypeQuery;
|
||||
case SyntaxKind.Identifier:
|
||||
if (node.parent.kind === SyntaxKind.TypeQuery) {
|
||||
return true;
|
||||
}
|
||||
// Fall through
|
||||
case SyntaxKind.NumericLiteral:
|
||||
case SyntaxKind.StringLiteral:
|
||||
var parent = node.parent;
|
||||
switch (parent.kind) {
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.Property:
|
||||
case SyntaxKind.EnumMember:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
return (<VariableDeclaration>parent).initializer === node;
|
||||
case SyntaxKind.ExpressionStatement:
|
||||
case SyntaxKind.IfStatement:
|
||||
case SyntaxKind.DoStatement:
|
||||
case SyntaxKind.WhileStatement:
|
||||
case SyntaxKind.ReturnStatement:
|
||||
case SyntaxKind.WithStatement:
|
||||
case SyntaxKind.SwitchStatement:
|
||||
case SyntaxKind.CaseClause:
|
||||
case SyntaxKind.ThrowStatement:
|
||||
case SyntaxKind.SwitchStatement:
|
||||
return (<ExpressionStatement>parent).expression === node;
|
||||
case SyntaxKind.ForStatement:
|
||||
return (<ForStatement>parent).initializer === node ||
|
||||
(<ForStatement>parent).condition === node ||
|
||||
(<ForStatement>parent).iterator === node;
|
||||
case SyntaxKind.ForInStatement:
|
||||
return (<ForInStatement>parent).variable === node ||
|
||||
(<ForInStatement>parent).expression === node;
|
||||
case SyntaxKind.TypeAssertion:
|
||||
return node === (<TypeAssertion>parent).operand;
|
||||
default:
|
||||
if (isExpression(parent)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): Diagnostic {
|
||||
node = getErrorSpanForNode(node);
|
||||
var file = getSourceFileOfNode(node);
|
||||
@@ -2625,11 +2696,14 @@ module ts {
|
||||
}
|
||||
|
||||
// STATEMENTS
|
||||
function parseStatementAllowingLetDeclaration() {
|
||||
return parseStatement(/*allowLetAndConstDeclarations*/ true);
|
||||
}
|
||||
|
||||
function parseBlock(ignoreMissingOpenBrace: boolean, checkForStrictMode: boolean): Block {
|
||||
var node = <Block>createNode(SyntaxKind.Block);
|
||||
if (parseExpected(SyntaxKind.OpenBraceToken) || ignoreMissingOpenBrace) {
|
||||
node.statements = parseList(ParsingContext.BlockStatements,checkForStrictMode, parseStatement);
|
||||
node.statements = parseList(ParsingContext.BlockStatements, checkForStrictMode, parseStatementAllowingLetDeclaration);
|
||||
parseExpected(SyntaxKind.CloseBraceToken);
|
||||
}
|
||||
else {
|
||||
@@ -2675,8 +2749,8 @@ module ts {
|
||||
parseExpected(SyntaxKind.OpenParenToken);
|
||||
node.expression = parseExpression();
|
||||
parseExpected(SyntaxKind.CloseParenToken);
|
||||
node.thenStatement = parseStatement();
|
||||
node.elseStatement = parseOptional(SyntaxKind.ElseKeyword) ? parseStatement() : undefined;
|
||||
node.thenStatement = parseStatement(/*allowLetAndConstDeclarations*/ false);
|
||||
node.elseStatement = parseOptional(SyntaxKind.ElseKeyword) ? parseStatement(/*allowLetAndConstDeclarations*/ false) : undefined;
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
@@ -2686,7 +2760,7 @@ module ts {
|
||||
|
||||
var saveInIterationStatement = inIterationStatement;
|
||||
inIterationStatement = ControlBlockContext.Nested;
|
||||
node.statement = parseStatement();
|
||||
node.statement = parseStatement(/*allowLetAndConstDeclarations*/ false);
|
||||
inIterationStatement = saveInIterationStatement;
|
||||
|
||||
parseExpected(SyntaxKind.WhileKeyword);
|
||||
@@ -2711,7 +2785,7 @@ module ts {
|
||||
|
||||
var saveInIterationStatement = inIterationStatement;
|
||||
inIterationStatement = ControlBlockContext.Nested;
|
||||
node.statement = parseStatement();
|
||||
node.statement = parseStatement(/*allowLetAndConstDeclarations*/ false);
|
||||
inIterationStatement = saveInIterationStatement;
|
||||
|
||||
return finishNode(node);
|
||||
@@ -2723,11 +2797,29 @@ module ts {
|
||||
parseExpected(SyntaxKind.OpenParenToken);
|
||||
if (token !== SyntaxKind.SemicolonToken) {
|
||||
if (parseOptional(SyntaxKind.VarKeyword)) {
|
||||
var declarations = parseVariableDeclarationList(0, true);
|
||||
var declarations = parseVariableDeclarationList(0, /*noIn*/ true);
|
||||
if (!declarations.length) {
|
||||
error(Diagnostics.Variable_declaration_list_cannot_be_empty);
|
||||
}
|
||||
}
|
||||
else if (parseOptional(SyntaxKind.LetKeyword)) {
|
||||
var declarations = parseVariableDeclarationList(NodeFlags.Let, /*noIn*/ true);
|
||||
if (!declarations.length) {
|
||||
error(Diagnostics.Variable_declaration_list_cannot_be_empty);
|
||||
}
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
|
||||
}
|
||||
}
|
||||
else if (parseOptional(SyntaxKind.ConstKeyword)) {
|
||||
var declarations = parseVariableDeclarationList(NodeFlags.Const, /*noIn*/ true);
|
||||
if (!declarations.length) {
|
||||
error(Diagnostics.Variable_declaration_list_cannot_be_empty);
|
||||
}
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
|
||||
}
|
||||
}
|
||||
else {
|
||||
var varOrInit = parseExpression(true);
|
||||
}
|
||||
@@ -2766,7 +2858,7 @@ module ts {
|
||||
|
||||
var saveInIterationStatement = inIterationStatement;
|
||||
inIterationStatement = ControlBlockContext.Nested;
|
||||
forOrForInStatement.statement = parseStatement();
|
||||
forOrForInStatement.statement = parseStatement(/*allowLetAndConstDeclarations*/ false);
|
||||
inIterationStatement = saveInIterationStatement;
|
||||
|
||||
return finishNode(forOrForInStatement);
|
||||
@@ -2877,7 +2969,7 @@ module ts {
|
||||
parseExpected(SyntaxKind.OpenParenToken);
|
||||
node.expression = parseExpression();
|
||||
parseExpected(SyntaxKind.CloseParenToken);
|
||||
node.statement = parseStatement();
|
||||
node.statement = parseStatement(/*allowLetAndConstDeclarations*/ false);
|
||||
node = finishNode(node);
|
||||
if (isInStrictMode) {
|
||||
// Strict mode code may not include a WithStatement. The occurrence of a WithStatement in such
|
||||
@@ -2892,7 +2984,7 @@ module ts {
|
||||
parseExpected(SyntaxKind.CaseKeyword);
|
||||
node.expression = parseExpression();
|
||||
parseExpected(SyntaxKind.ColonToken);
|
||||
node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatement);
|
||||
node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatementAllowingLetDeclaration);
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
@@ -2900,7 +2992,7 @@ module ts {
|
||||
var node = <CaseOrDefaultClause>createNode(SyntaxKind.DefaultClause);
|
||||
parseExpected(SyntaxKind.DefaultKeyword);
|
||||
parseExpected(SyntaxKind.ColonToken);
|
||||
node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatement);
|
||||
node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatementAllowingLetDeclaration);
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
@@ -3007,9 +3099,9 @@ module ts {
|
||||
return token === SyntaxKind.WhileKeyword || token === SyntaxKind.DoKeyword || token === SyntaxKind.ForKeyword;
|
||||
}
|
||||
|
||||
function parseStatementWithLabelSet(): Statement {
|
||||
function parseStatementWithLabelSet(allowLetAndConstDeclarations: boolean): Statement {
|
||||
labelledStatementInfo.pushCurrentLabelSet(isIterationStatementStart());
|
||||
var statement = parseStatement();
|
||||
var statement = parseStatement(allowLetAndConstDeclarations);
|
||||
labelledStatementInfo.pop();
|
||||
return statement;
|
||||
}
|
||||
@@ -3018,7 +3110,7 @@ module ts {
|
||||
return isIdentifier() && lookAhead(() => nextToken() === SyntaxKind.ColonToken);
|
||||
}
|
||||
|
||||
function parseLabelledStatement(): LabeledStatement {
|
||||
function parseLabeledStatement(allowLetAndConstDeclarations: boolean): LabeledStatement {
|
||||
var node = <LabeledStatement>createNode(SyntaxKind.LabeledStatement);
|
||||
node.label = parseIdentifier();
|
||||
parseExpected(SyntaxKind.ColonToken);
|
||||
@@ -3030,7 +3122,7 @@ module ts {
|
||||
|
||||
// We only want to call parseStatementWithLabelSet when the label set is complete
|
||||
// Therefore, keep parsing labels until we know we're done.
|
||||
node.statement = isLabel() ? parseLabelledStatement() : parseStatementWithLabelSet();
|
||||
node.statement = isLabel() ? parseLabeledStatement(allowLetAndConstDeclarations) : parseStatementWithLabelSet(allowLetAndConstDeclarations);
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
@@ -3053,6 +3145,8 @@ module ts {
|
||||
return !inErrorRecovery;
|
||||
case SyntaxKind.OpenBraceToken:
|
||||
case SyntaxKind.VarKeyword:
|
||||
case SyntaxKind.LetKeyword:
|
||||
case SyntaxKind.ConstKeyword:
|
||||
case SyntaxKind.FunctionKeyword:
|
||||
case SyntaxKind.IfKeyword:
|
||||
case SyntaxKind.DoKeyword:
|
||||
@@ -3094,12 +3188,14 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function parseStatement(): Statement {
|
||||
function parseStatement(allowLetAndConstDeclarations: boolean): Statement {
|
||||
switch (token) {
|
||||
case SyntaxKind.OpenBraceToken:
|
||||
return parseBlock(/* ignoreMissingOpenBrace */ false, /*checkForStrictMode*/ false);
|
||||
case SyntaxKind.VarKeyword:
|
||||
return parseVariableStatement();
|
||||
case SyntaxKind.LetKeyword:
|
||||
case SyntaxKind.ConstKeyword:
|
||||
return parseVariableStatement(allowLetAndConstDeclarations);
|
||||
case SyntaxKind.FunctionKeyword:
|
||||
return parseFunctionDeclaration();
|
||||
case SyntaxKind.SemicolonToken:
|
||||
@@ -3133,16 +3229,12 @@ module ts {
|
||||
return parseDebuggerStatement();
|
||||
default:
|
||||
if (isLabel()) {
|
||||
return parseLabelledStatement();
|
||||
return parseLabeledStatement(allowLetAndConstDeclarations);
|
||||
}
|
||||
return parseExpressionStatement();
|
||||
}
|
||||
}
|
||||
|
||||
function parseStatementOrFunction(): Statement {
|
||||
return token === SyntaxKind.FunctionKeyword ? parseFunctionDeclaration() : parseStatement();
|
||||
}
|
||||
|
||||
function parseAndCheckFunctionBody(isConstructor: boolean): Block {
|
||||
var initialPosition = scanner.getTokenPos();
|
||||
var errorCountBeforeBody = file.syntacticErrors.length;
|
||||
@@ -3178,6 +3270,9 @@ module ts {
|
||||
if (inAmbientContext && node.initializer && errorCountBeforeVariableDeclaration === file.syntacticErrors.length) {
|
||||
grammarErrorAtPos(initializerStart, initializerFirstTokenLength, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
|
||||
}
|
||||
if (!inAmbientContext && !node.initializer && flags & NodeFlags.Const) {
|
||||
grammarErrorOnNode(node, Diagnostics.const_declarations_must_be_initialized);
|
||||
}
|
||||
if (isInStrictMode && isEvalOrArgumentsIdentifier(node.name)) {
|
||||
// It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code
|
||||
// and its Identifier is eval or arguments
|
||||
@@ -3191,17 +3286,42 @@ module ts {
|
||||
() => parseVariableDeclaration(flags, noIn), /*allowTrailingComma*/ false);
|
||||
}
|
||||
|
||||
function parseVariableStatement(pos?: number, flags?: NodeFlags): VariableStatement {
|
||||
function parseVariableStatement(allowLetAndConstDeclarations: boolean, pos?: number, flags?: NodeFlags): VariableStatement {
|
||||
var node = <VariableStatement>createNode(SyntaxKind.VariableStatement, pos);
|
||||
if (flags) node.flags = flags;
|
||||
var errorCountBeforeVarStatement = file.syntacticErrors.length;
|
||||
parseExpected(SyntaxKind.VarKeyword);
|
||||
node.declarations = parseVariableDeclarationList(flags, /*noIn*/false);
|
||||
if (token === SyntaxKind.LetKeyword) {
|
||||
node.flags |= NodeFlags.Let;
|
||||
}
|
||||
else if (token === SyntaxKind.ConstKeyword) {
|
||||
node.flags |= NodeFlags.Const;
|
||||
}
|
||||
else if (token !== SyntaxKind.VarKeyword) {
|
||||
error(Diagnostics.var_let_or_const_expected);
|
||||
}
|
||||
nextToken();
|
||||
node.declarations = parseVariableDeclarationList(node.flags, /*noIn*/false);
|
||||
parseSemicolon();
|
||||
finishNode(node);
|
||||
if (!node.declarations.length && file.syntacticErrors.length === errorCountBeforeVarStatement) {
|
||||
grammarErrorOnNode(node, Diagnostics.Variable_declaration_list_cannot_be_empty);
|
||||
}
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
if (node.flags & NodeFlags.Let) {
|
||||
grammarErrorOnNode(node, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
|
||||
}
|
||||
else if (node.flags & NodeFlags.Const) {
|
||||
grammarErrorOnNode(node, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
|
||||
}
|
||||
}
|
||||
else if (!allowLetAndConstDeclarations) {
|
||||
if (node.flags & NodeFlags.Let) {
|
||||
grammarErrorOnNode(node, Diagnostics.let_declarations_can_only_be_declared_inside_a_block);
|
||||
}
|
||||
else if (node.flags & NodeFlags.Const) {
|
||||
grammarErrorOnNode(node, Diagnostics.const_declarations_can_only_be_declared_inside_a_block);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -3780,6 +3900,8 @@ module ts {
|
||||
function isDeclaration(): boolean {
|
||||
switch (token) {
|
||||
case SyntaxKind.VarKeyword:
|
||||
case SyntaxKind.LetKeyword:
|
||||
case SyntaxKind.ConstKeyword:
|
||||
case SyntaxKind.FunctionKeyword:
|
||||
return true;
|
||||
case SyntaxKind.ClassKeyword:
|
||||
@@ -3830,7 +3952,9 @@ module ts {
|
||||
var result: Declaration;
|
||||
switch (token) {
|
||||
case SyntaxKind.VarKeyword:
|
||||
result = parseVariableStatement(pos, flags);
|
||||
case SyntaxKind.LetKeyword:
|
||||
case SyntaxKind.ConstKeyword:
|
||||
result = parseVariableStatement(/*allowLetAndConstDeclarations*/ true, pos, flags);
|
||||
break;
|
||||
case SyntaxKind.FunctionKeyword:
|
||||
result = parseFunctionDeclaration(pos, flags);
|
||||
@@ -3878,7 +4002,7 @@ module ts {
|
||||
var statementStart = scanner.getTokenPos();
|
||||
var statementFirstTokenLength = scanner.getTextPos() - statementStart;
|
||||
var errorCountBeforeStatement = file.syntacticErrors.length;
|
||||
var statement = parseStatement();
|
||||
var statement = parseStatement(/*allowLetAndConstDeclarations*/ true);
|
||||
|
||||
if (inAmbientContext && file.syntacticErrors.length === errorCountBeforeStatement) {
|
||||
grammarErrorAtPos(statementStart, statementFirstTokenLength, Diagnostics.Statements_are_not_allowed_in_ambient_contexts);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/// <reference path="diagnosticInformationMap.generated.ts"/>
|
||||
|
||||
interface System {
|
||||
args: string[];
|
||||
|
||||
+12
-7
@@ -361,13 +361,18 @@ module ts {
|
||||
else {
|
||||
var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true);
|
||||
var checkStart = new Date().getTime();
|
||||
var semanticErrors = checker.getDiagnostics();
|
||||
var emitStart = new Date().getTime();
|
||||
var emitOutput = checker.emitFiles();
|
||||
var emitErrors = emitOutput.errors;
|
||||
exitStatus = emitOutput.emitResultStatus;
|
||||
var reportStart = new Date().getTime();
|
||||
errors = concatenate(semanticErrors, emitErrors);
|
||||
errors = checker.getDiagnostics();
|
||||
if (!checker.hasEarlyErrors()) {
|
||||
var emitStart = new Date().getTime();
|
||||
var emitOutput = checker.emitFiles();
|
||||
var emitErrors = emitOutput.errors;
|
||||
exitStatus = emitOutput.emitResultStatus;
|
||||
var reportStart = new Date().getTime();
|
||||
errors = concatenate(errors, emitErrors);
|
||||
}
|
||||
else {
|
||||
exitStatus = EmitReturnStatus.AllOutputGenerationSkipped;
|
||||
}
|
||||
}
|
||||
|
||||
reportDiagnostics(errors);
|
||||
|
||||
+53
-32
@@ -247,9 +247,12 @@ module ts {
|
||||
MultiLine = 0x00000100, // Multi-line array or object literal
|
||||
Synthetic = 0x00000200, // Synthetic node (for full fidelity)
|
||||
DeclarationFile = 0x00000400, // Node is a .d.ts file
|
||||
Let = 0x00000800, // Variable declaration
|
||||
Const = 0x00001000, // Variable declaration
|
||||
|
||||
Modifier = Export | Ambient | Public | Private | Protected | Static,
|
||||
AccessibilityModifier = Public | Private | Protected
|
||||
AccessibilityModifier = Public | Private | Protected,
|
||||
BlockScoped = Let | Const
|
||||
}
|
||||
|
||||
export interface Node extends TextRange {
|
||||
@@ -663,6 +666,7 @@ module ts {
|
||||
isImplementationOfOverload(node: FunctionDeclaration): boolean;
|
||||
isUndefinedSymbol(symbol: Symbol): boolean;
|
||||
isArgumentsSymbol(symbol: Symbol): boolean;
|
||||
hasEarlyErrors(sourceFile?: SourceFile): boolean;
|
||||
|
||||
// Returns the constant value of this enum member, or 'undefined' if the enum member has a
|
||||
// computed value.
|
||||
@@ -758,51 +762,62 @@ module ts {
|
||||
// Returns the constant value this property access resolves to, or 'undefined' if it does
|
||||
// resolve to a constant.
|
||||
getConstantValue(node: PropertyAccess): number;
|
||||
hasEarlyErrors(sourceFile?: SourceFile): boolean;
|
||||
}
|
||||
|
||||
export enum SymbolFlags {
|
||||
Variable = 0x00000001, // Variable or parameter
|
||||
Property = 0x00000002, // Property or enum member
|
||||
EnumMember = 0x00000004, // Enum member
|
||||
Function = 0x00000008, // Function
|
||||
Class = 0x00000010, // Class
|
||||
Interface = 0x00000020, // Interface
|
||||
Enum = 0x00000040, // Enum
|
||||
ValueModule = 0x00000080, // Instantiated module
|
||||
NamespaceModule = 0x00000100, // Uninstantiated module
|
||||
TypeLiteral = 0x00000200, // Type Literal
|
||||
ObjectLiteral = 0x00000400, // Object Literal
|
||||
Method = 0x00000800, // Method
|
||||
Constructor = 0x00001000, // Constructor
|
||||
GetAccessor = 0x00002000, // Get accessor
|
||||
SetAccessor = 0x00004000, // Set accessor
|
||||
CallSignature = 0x00008000, // Call signature
|
||||
ConstructSignature = 0x00010000, // Construct signature
|
||||
IndexSignature = 0x00020000, // Index signature
|
||||
TypeParameter = 0x00040000, // Type parameter
|
||||
FunctionScopedVariable = 0x00000001, // Variable (var) or parameter
|
||||
Property = 0x00000002, // Property or enum member
|
||||
EnumMember = 0x00000004, // Enum member
|
||||
Function = 0x00000008, // Function
|
||||
Class = 0x00000010, // Class
|
||||
Interface = 0x00000020, // Interface
|
||||
Enum = 0x00000040, // Enum
|
||||
ValueModule = 0x00000080, // Instantiated module
|
||||
NamespaceModule = 0x00000100, // Uninstantiated module
|
||||
TypeLiteral = 0x00000200, // Type Literal
|
||||
ObjectLiteral = 0x00000400, // Object Literal
|
||||
Method = 0x00000800, // Method
|
||||
Constructor = 0x00001000, // Constructor
|
||||
GetAccessor = 0x00002000, // Get accessor
|
||||
SetAccessor = 0x00004000, // Set accessor
|
||||
CallSignature = 0x00008000, // Call signature
|
||||
ConstructSignature = 0x00010000, // Construct signature
|
||||
IndexSignature = 0x00020000, // Index signature
|
||||
TypeParameter = 0x00040000, // Type parameter
|
||||
|
||||
// Export markers (see comment in declareModuleMember in binder)
|
||||
ExportValue = 0x00080000, // Exported value marker
|
||||
ExportType = 0x00100000, // Exported type marker
|
||||
ExportNamespace = 0x00200000, // Exported namespace marker
|
||||
ExportValue = 0x00080000, // Exported value marker
|
||||
ExportType = 0x00100000, // Exported type marker
|
||||
ExportNamespace = 0x00200000, // Exported namespace marker
|
||||
|
||||
Import = 0x00400000, // Import
|
||||
Instantiated = 0x00800000, // Instantiated symbol
|
||||
Merged = 0x01000000, // Merged symbol (created during program binding)
|
||||
Transient = 0x02000000, // Transient symbol (created during type check)
|
||||
Prototype = 0x04000000, // Prototype property (no source representation)
|
||||
UnionProperty = 0x08000000, // Property in union type
|
||||
Import = 0x00400000, // Import
|
||||
Instantiated = 0x00800000, // Instantiated symbol
|
||||
Merged = 0x01000000, // Merged symbol (created during program binding)
|
||||
Transient = 0x02000000, // Transient symbol (created during type check)
|
||||
Prototype = 0x04000000, // Prototype property (no source representation)
|
||||
UnionProperty = 0x08000000, // Property in union type
|
||||
|
||||
BlockScopedVariable = 0x10000000, // A block-scoped variable (let ot const)
|
||||
|
||||
Variable = FunctionScopedVariable | BlockScopedVariable,
|
||||
Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor,
|
||||
|
||||
Type = Class | Interface | Enum | TypeLiteral | ObjectLiteral | TypeParameter,
|
||||
Namespace = ValueModule | NamespaceModule,
|
||||
Module = ValueModule | NamespaceModule,
|
||||
Accessor = GetAccessor | SetAccessor,
|
||||
Signature = CallSignature | ConstructSignature | IndexSignature,
|
||||
|
||||
|
||||
// Variables can be redeclared, but can not redeclare a block-scoped declaration with the
|
||||
// same name, or any other value that is not a variable, e.g. ValueModule or Class
|
||||
FunctionScopedVariableExcludes = Value & ~FunctionScopedVariable,
|
||||
|
||||
// Block-scoped declarations are not allowed to be re-declared
|
||||
// they can not merge with anything in the value space
|
||||
BlockScopedVariableExcludes = Value,
|
||||
|
||||
ParameterExcludes = Value,
|
||||
VariableExcludes = Value & ~Variable,
|
||||
PropertyExcludes = Value,
|
||||
EnumMemberExcludes = Value,
|
||||
FunctionExcludes = Value & ~(Function | ValueModule),
|
||||
@@ -816,8 +831,9 @@ module ts {
|
||||
SetAccessorExcludes = Value & ~GetAccessor,
|
||||
TypeParameterExcludes = Type & ~TypeParameter,
|
||||
|
||||
|
||||
// Imports collide with all other imports with the same name.
|
||||
ImportExcludes = Import,
|
||||
ImportExcludes = Import,
|
||||
|
||||
ModuleMember = Variable | Function | Class | Interface | Enum | Module | Import,
|
||||
|
||||
@@ -909,6 +925,7 @@ module ts {
|
||||
StringLike = String | StringLiteral,
|
||||
NumberLike = Number | Enum,
|
||||
ObjectType = Class | Interface | Reference | Tuple | Anonymous,
|
||||
Structured = Any | ObjectType | Union | TypeParameter
|
||||
}
|
||||
|
||||
// Properties common to all types
|
||||
@@ -1025,6 +1042,7 @@ module ts {
|
||||
key: string;
|
||||
category: DiagnosticCategory;
|
||||
code: number;
|
||||
isEarly?: boolean;
|
||||
}
|
||||
|
||||
// A linked list of formatted diagnostic messages to be used as part of a multiline message.
|
||||
@@ -1045,6 +1063,7 @@ module ts {
|
||||
messageText: string;
|
||||
category: DiagnosticCategory;
|
||||
code: number;
|
||||
isEarly?: boolean;
|
||||
}
|
||||
|
||||
export enum DiagnosticCategory {
|
||||
@@ -1097,6 +1116,8 @@ module ts {
|
||||
export enum ScriptTarget {
|
||||
ES3,
|
||||
ES5,
|
||||
ES6,
|
||||
Latest = ES6,
|
||||
}
|
||||
|
||||
export interface ParsedCommandLine {
|
||||
|
||||
Reference in New Issue
Block a user