Merge branch 'master' into trylessCatchesFinallyParseNicely

Conflicts:
	src/compiler/diagnosticMessages.json
This commit is contained in:
Daniel Rosenwasser
2014-07-31 14:49:14 -07:00
103 changed files with 9339 additions and 5536 deletions

View File

@@ -136,30 +136,27 @@ module ts {
// but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way
// when the emitter comes back to it, it knows not to qualify the name if it was found in a containing scope.
var exportKind = 0;
var exportExcludes = 0;
if (symbolKind & SymbolFlags.Value) {
exportKind |= SymbolFlags.ExportValue;
exportExcludes |= SymbolFlags.Value;
}
if (symbolKind & SymbolFlags.Type) {
exportKind |= SymbolFlags.ExportType;
exportExcludes |= SymbolFlags.Type;
}
if (symbolKind & SymbolFlags.Namespace) {
exportKind |= SymbolFlags.ExportNamespace;
exportExcludes |= SymbolFlags.Namespace;
}
if (node.flags & NodeFlags.Export || (node.kind !== SyntaxKind.ImportDeclaration && isAmbientContext(container))) {
if (exportKind) {
var local = declareSymbol(container.locals, undefined, node, exportKind, exportExcludes);
var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes);
local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes);
node.localSymbol = local;
}
else {
declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes);
}
}
else {
declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes | exportKind);
declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes);
}
}

View File

@@ -4819,24 +4819,21 @@ module ts {
error(signatureDeclarationNode, Diagnostics.Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature);
}
function checkFunctionOrConstructorSymbol(symbol: Symbol) {
function getEffectiveFlagsForFunctionCheck(n: Node) {
var flags = n.flags;
// We want to determine if an overload is effectively ambient, which can happen if it
// is nested in an ambient context. However, do not treat members of interfaces differently
// based on whether the interface itself is in an ambient context. Interfaces should never
// be considered ambient for purposes of comparing overload attributes.
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
flags |= NodeFlags.Export;
}
flags |= NodeFlags.Ambient;
function getEffectiveDeclarationFlags(n: Node, flagsToCheck: NodeFlags) {
var flags = n.flags;
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
flags |= NodeFlags.Export;
}
return flags & flagsToCheck;
flags |= NodeFlags.Ambient;
}
return flags & flagsToCheck;
}
function checkFunctionOrConstructorSymbol(symbol: Symbol) {
function checkFlagAgreementBetweenOverloads(overloads: Declaration[], implementation: FunctionDeclaration, flagsToCheck: NodeFlags, someOverloadFlags: NodeFlags, allOverloadFlags: NodeFlags): void {
// Error if some overloads have a flag that is not shared by all overloads. To find the
// deviations, we XOR someOverloadFlags with allOverloadFlags
@@ -4849,10 +4846,10 @@ module ts {
// the canonical signature only if it is in the same container as the first overload
var implementationSharesContainerWithFirstOverload = implementation !== undefined && implementation.parent === overloads[0].parent;
var canonicalFlags = implementationSharesContainerWithFirstOverload
? getEffectiveFlagsForFunctionCheck(implementation)
: getEffectiveFlagsForFunctionCheck(overloads[0]);
? getEffectiveDeclarationFlags(implementation, flagsToCheck)
: getEffectiveDeclarationFlags(overloads[0], flagsToCheck);
forEach(overloads, o => {
var deviation = getEffectiveFlagsForFunctionCheck(o) ^ canonicalFlags;
var deviation = getEffectiveDeclarationFlags(o, flagsToCheck) ^ canonicalFlags;
if (deviation & NodeFlags.Export) {
error(o.name, Diagnostics.Overload_signatures_must_all_be_exported_or_not_exported);
}
@@ -4875,47 +4872,101 @@ module ts {
var hasOverloads = false;
var bodyDeclaration: FunctionDeclaration;
var lastSeenNonAmbientDeclaration: FunctionDeclaration;
var previousDeclaration: FunctionDeclaration;
var declarations = symbol.declarations;
var isConstructor = (symbol.flags & SymbolFlags.Constructor) !== 0;
function reportImplementationExpectedError(node: FunctionDeclaration): void {
var seen = false;
var subsequentNode = forEachChild(node.parent, c => {
if (seen) {
return c;
}
else {
seen = c === node;
}
});
if (subsequentNode) {
if (subsequentNode.kind === node.kind) {
var errorNode: Node = (<FunctionDeclaration>subsequentNode).name || subsequentNode;
if (node.name && (<FunctionDeclaration>subsequentNode).name && node.name.text === (<FunctionDeclaration>subsequentNode).name.text) {
// the only situation when this is possible (same kind\same name but different symbol) - mixed static and instance class members
Debug.assert(node.kind === SyntaxKind.Method);
Debug.assert((node.flags & NodeFlags.Static) !== (subsequentNode.flags & NodeFlags.Static));
var diagnostic = node.flags & NodeFlags.Static ? Diagnostics.Function_overload_must_be_static : Diagnostics.Function_overload_must_not_be_static;
error(errorNode, diagnostic);
return;
}
else if ((<FunctionDeclaration>subsequentNode).body) {
error(errorNode, Diagnostics.Function_implementation_name_must_be_0, identifierToString(node.name));
return;
}
}
}
var errorNode: Node = node.name || node;
if (isConstructor) {
error(errorNode, Diagnostics.Constructor_implementation_is_missing);
}
else {
error(errorNode, Diagnostics.Function_implementation_is_missing_or_not_immediately_following_the_declaration);
}
}
// when checking exported function declarations across modules check only duplicate implementations
// names and consistensy of modifiers are verified when we check local symbol
var isExportSymbolInsideModule = symbol.parent && symbol.parent.flags & SymbolFlags.Module;
for (var i = 0; i < declarations.length; i++) {
var node = <FunctionDeclaration>declarations[i];
var inAmbientContext = isInAmbientContext(node);
var inAmbientContextOrInterface = node.parent.kind === SyntaxKind.InterfaceDeclaration || node.parent.kind === SyntaxKind.TypeLiteral || inAmbientContext;
if (inAmbientContextOrInterface) {
// check if declarations are consecutive only if they are non-ambient
// 1. ambient declarations can be interleaved
// i.e. this is legal
// declare function foo();
// declare function bar();
// declare function foo();
// 2. mixing ambient and non-ambient declarations is a separate error that will be reported - do not want to report an extra one
previousDeclaration = undefined;
}
if (node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.Method || node.kind === SyntaxKind.Constructor) {
var currentNodeFlags = getEffectiveFlagsForFunctionCheck(node);
var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck);
someNodeFlags |= currentNodeFlags;
allNodeFlags &= currentNodeFlags;
var inAmbientContext = isInAmbientContext(node);
var inAmbientContextOrInterface = node.parent.kind === SyntaxKind.InterfaceDeclaration || node.parent.kind === SyntaxKind.TypeLiteral || inAmbientContext;
if (!inAmbientContextOrInterface) {
lastSeenNonAmbientDeclaration = node;
if (node.body && bodyDeclaration) {
if (isConstructor) {
error(node, Diagnostics.Multiple_constructor_implementations_are_not_allowed);
}
else {
error(node, Diagnostics.Duplicate_function_implementation);
}
}
else if (!isExportSymbolInsideModule && previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) {
reportImplementationExpectedError(previousDeclaration);
}
if (node.body) {
if (bodyDeclaration) {
if (isConstructor) {
error(node, Diagnostics.Multiple_constructor_implementations_are_not_allowed);
}
else {
error(node, Diagnostics.Duplicate_function_implementation);
}
}
else {
if (!bodyDeclaration) {
bodyDeclaration = node;
}
}
else {
hasOverloads = true;
}
previousDeclaration = node;
if (!inAmbientContextOrInterface) {
lastSeenNonAmbientDeclaration = node;
}
}
}
if (lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body) {
if (isConstructor) {
error(lastSeenNonAmbientDeclaration, Diagnostics.Constructor_implementation_expected);
}
else {
error(lastSeenNonAmbientDeclaration, Diagnostics.Function_implementation_expected);
}
if (!isExportSymbolInsideModule && lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body) {
reportImplementationExpectedError(lastSeenNonAmbientDeclaration);
}
if (hasOverloads) {
@@ -4951,18 +5002,101 @@ module ts {
}
}
function checkExportsOnMergedDeclarations(node: Node) {
var symbol: Symbol;
// Exports should be checked only if enclosing module contains both exported and non exported declarations.
// In case if all declarations are non-exported check is unnecesary.
// if localSymbol is defined on node then node itself is exported - check is required
var symbol = node.localSymbol;
if (!symbol) {
// local symbol is undefined => this declaration is non-exported.
// however symbol might contain other declarations that are exported
symbol = getSymbolOfNode(node);
if (!(symbol.flags & SymbolFlags.Export)) {
// this is a pure local symbol (all declarations are non-exported) - no need to check anything
return;
}
}
// run the check only for the first declaration in the list
if (getDeclarationOfKind(symbol, node.kind) !== node) {
return;
}
// we use SymbolFlags.ExportValue, SymbolFlags.ExportType and SymbolFlags.ExportNamespace
// to denote disjoint declarationSpaces (without making new enum type).
var exportedDeclarationSpaces: SymbolFlags = 0;
var nonExportedDeclarationSpaces: SymbolFlags = 0;
forEach(symbol.declarations, d => {
var declarationSpaces = getDeclarationSpaces(d);
if (getEffectiveDeclarationFlags(d, NodeFlags.Export)) {
exportedDeclarationSpaces |= declarationSpaces;
}
else {
nonExportedDeclarationSpaces |= declarationSpaces;
}
});
var commonDeclarationSpace = exportedDeclarationSpaces & nonExportedDeclarationSpaces;
if (commonDeclarationSpace) {
// declaration spaces for exported and non-exported declarations intersect
forEach(symbol.declarations, d => {
if (getDeclarationSpaces(d) & commonDeclarationSpace) {
error(d.name, Diagnostics.Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local, identifierToString(d.name));
}
});
}
function getDeclarationSpaces(d: Declaration): SymbolFlags {
switch (d.kind) {
case SyntaxKind.InterfaceDeclaration:
return SymbolFlags.ExportType;
case SyntaxKind.ModuleDeclaration:
return (<ModuleDeclaration>d).name.kind === SyntaxKind.StringLiteral || isInstantiated(d)
? SymbolFlags.ExportNamespace | SymbolFlags.ExportValue
: SymbolFlags.ExportNamespace;
case SyntaxKind.ClassDeclaration:
case SyntaxKind.EnumDeclaration:
return SymbolFlags.ExportType | SymbolFlags.ExportValue;
case SyntaxKind.ImportDeclaration:
var result: SymbolFlags = 0;
var target = resolveImport(getSymbolOfNode(d));
forEach(target.declarations, d => { result |= getDeclarationSpaces(d); } )
return result;
default:
return SymbolFlags.ExportValue;
}
}
}
function checkFunctionDeclaration(node: FunctionDeclaration) {
checkSignatureDeclaration(node);
var symbol = getSymbolOfNode(node);
var firstDeclaration = getDeclarationOfKind(symbol, node.kind);
var symbol = getSymbolOfNode(node)
// first we want to check the local symbol that contain this declaration
// - if node.localSymbol !== undefined - this is current declaration is exported and localSymbol points to the local symbol
// - if node.localSymbol === undefined - this node is non-exported so we can just pick the result of getSymbolOfNode
var localSymbol = node.localSymbol || symbol;
var firstDeclaration = getDeclarationOfKind(localSymbol, node.kind);
// Only type check the symbol once
if (node === firstDeclaration) {
checkFunctionOrConstructorSymbol(symbol);
checkFunctionOrConstructorSymbol(localSymbol);
}
if (symbol.parent) {
// run check once for the first declaration
if (getDeclarationOfKind(symbol, node.kind) === node) {
// run check on export symbol to check that modifiers agree across all exported declarations
checkFunctionOrConstructorSymbol(symbol);
}
}
checkSourceElement(node.body);
if (node.type) {
if (node.type && !isAccessor(node.kind)) {
checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type));
}
@@ -5155,8 +5289,10 @@ module ts {
function checkVariableDeclaration(node: VariableDeclaration) {
checkSourceElement(node.type);
var symbol = getSymbolOfNode(node);
checkExportsOnMergedDeclarations(node);
var symbol = getSymbolOfNode(node);
var typeOfValueDeclaration = getTypeOfVariableOrParameterOrProperty(symbol);
var type: Type;
var useTypeFromValueDeclaration = node === symbol.valueDeclaration;
@@ -5441,6 +5577,7 @@ module ts {
checkTypeNameIsReserved(node.name, Diagnostics.Class_name_cannot_be_0);
checkTypeParameters(node.typeParameters);
checkCollisionWithCapturedThisVariable(node, node.name);
checkExportsOnMergedDeclarations(node);
var symbol = getSymbolOfNode(node);
var type = <InterfaceType>getDeclaredTypeOfSymbol(symbol);
var staticType = <ObjectType>getTypeOfSymbol(symbol);
@@ -5595,6 +5732,7 @@ module ts {
function checkInterfaceDeclaration(node: InterfaceDeclaration) {
checkTypeNameIsReserved(node.name, Diagnostics.Interface_name_cannot_be_0);
checkTypeParameters(node.typeParameters);
checkExportsOnMergedDeclarations(node);
var symbol = getSymbolOfNode(node);
var firstInterfaceDecl = <InterfaceDeclaration>getDeclarationOfKind(symbol, SyntaxKind.InterfaceDeclaration);
if (symbol.declarations.length > 1) {
@@ -5640,6 +5778,7 @@ module ts {
function checkEnumDeclaration(node: EnumDeclaration) {
checkTypeNameIsReserved(node.name, Diagnostics.Enum_name_cannot_be_0);
checkCollisionWithCapturedThisVariable(node, node.name);
checkExportsOnMergedDeclarations(node);
var enumSymbol = getSymbolOfNode(node);
var enumType = getDeclaredTypeOfSymbol(enumSymbol);
var autoValue = 0;
@@ -5711,6 +5850,7 @@ module ts {
function checkModuleDeclaration(node: ModuleDeclaration) {
checkCollisionWithCapturedThisVariable(node, node.name);
checkExportsOnMergedDeclarations(node);
var symbol = getSymbolOfNode(node);
if (symbol.flags & SymbolFlags.ValueModule && symbol.declarations.length > 1 && !isInAmbientContext(node)) {
var classOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol);
@@ -5734,6 +5874,13 @@ module ts {
checkSourceElement(node.body);
}
function getFirstIdentifier(node: EntityName): Identifier {
while (node.kind === SyntaxKind.QualifiedName) {
node = (<QualifiedName>node).left;
}
return <Identifier>node;
}
function checkImportDeclaration(node: ImportDeclaration) {
checkCollisionWithCapturedThisVariable(node, node.name);
var symbol = getSymbolOfNode(node);
@@ -5744,8 +5891,15 @@ module ts {
// Import declaration for an internal module
if (target !== unknownSymbol) {
if (target.flags & SymbolFlags.Value) {
// Target is a value symbol, check that it can be evaluated as an expression
checkExpression(node.entityName);
// Target is a value symbol, check that it is not hidden by a local declaration with the same name and
// ensure it can be evaluated as an expression
var moduleName = getFirstIdentifier(node.entityName);
if (resolveEntityName(node, moduleName, SymbolFlags.Value | SymbolFlags.Namespace).flags & SymbolFlags.Namespace) {
checkExpression(node.entityName);
}
else {
error(moduleName, Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name, identifierToString(moduleName));
}
}
if (target.flags & SymbolFlags.Type) {
checkTypeNameIsReserved(node.name, Diagnostics.Import_name_cannot_be_0);
@@ -5755,7 +5909,6 @@ module ts {
else {
// Import declaration for an external module
if (node.parent.kind === SyntaxKind.SourceFile) {
// Parent is a source file, check that external modules are enabled
target = resolveImport(symbol);
}
else if (node.parent.kind === SyntaxKind.ModuleBlock && (<ModuleDeclaration>node.parent.parent).name.kind === SyntaxKind.StringLiteral) {

View File

@@ -140,6 +140,7 @@ module ts {
A_signature_with_an_implementation_cannot_use_a_string_literal_type: { code: 2163, category: DiagnosticCategory.Error, key: "A signature with an implementation cannot use a string literal type." },
Interface_0_cannot_simultaneously_extend_types_1_and_2_Colon: { code: 2189, category: DiagnosticCategory.Error, key: "Interface '{0}' cannot simultaneously extend types '{1}' and '{2}':" },
Initializer_of_parameter_0_cannot_reference_identifier_1_declared_after_it: { code: 2190, category: DiagnosticCategory.Error, key: "Initializer of parameter '{0}' cannot reference identifier '{1}' declared after it." },
Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local: { code: 2192, category: DiagnosticCategory.Error, key: "Individual declarations in merged declaration {0} must be all exported or all local." },
super_cannot_be_referenced_in_constructor_arguments: { code: 2193, category: DiagnosticCategory.Error, key: "'super' cannot be referenced in constructor arguments." },
Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class: { code: 2194, category: DiagnosticCategory.Error, key: "Return type of constructor signature must be assignable to the instance type of the class" },
Ambient_external_module_declaration_cannot_specify_relative_module_name: { code: 2196, category: DiagnosticCategory.Error, key: "Ambient external module declaration cannot specify relative module name." },
@@ -157,9 +158,12 @@ module ts {
Duplicate_number_index_signature: { code: 2233, category: DiagnosticCategory.Error, key: "Duplicate number index signature." },
All_declarations_of_an_interface_must_have_identical_type_parameters: { code: 2234, category: DiagnosticCategory.Error, key: "All declarations of an interface must have identical type parameters." },
Expression_resolves_to_variable_declaration_i_that_compiler_uses_to_initialize_rest_parameter: { code: 2235, category: DiagnosticCategory.Error, key: "Expression resolves to variable declaration '_i' that compiler uses to initialize rest parameter." },
Constructor_implementation_expected: { code: 2240, category: DiagnosticCategory.Error, key: "Constructor implementation expected." },
Function_implementation_name_must_be_0: { code: 2239, category: DiagnosticCategory.Error, key: "Function implementation name must be '{0}'." },
Constructor_implementation_is_missing: { code: 2240, category: DiagnosticCategory.Error, key: "Constructor implementation is missing." },
An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements: { code: 2245, category: DiagnosticCategory.Error, key: "An export assignment cannot be used in a module with other exported elements." },
A_parameter_property_is_only_allowed_in_a_constructor_implementation: { code: 2246, category: DiagnosticCategory.Error, key: "A parameter property is only allowed in a constructor implementation." },
Function_overload_must_be_static: { code: 2247, category: DiagnosticCategory.Error, key: "Function overload must be static." },
Function_overload_must_not_be_static: { code: 2248, category: DiagnosticCategory.Error, key: "Function overload must not be static." },
Circular_definition_of_import_alias_0: { code: 3000, category: DiagnosticCategory.Error, key: "Circular definition of import alias '{0}'." },
Cannot_find_name_0: { code: 3001, category: DiagnosticCategory.Error, key: "Cannot find name '{0}'." },
Module_0_has_no_exported_member_1: { code: 3002, category: DiagnosticCategory.Error, key: "Module '{0}' has no exported member '{1}'." },
@@ -211,6 +215,7 @@ module ts {
Could_not_write_file_0_Colon_1: { code: 5033, category: DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" },
Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: DiagnosticCategory.Error, key: "Option mapRoot cannot be specified without specifying sourcemap option." },
Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: DiagnosticCategory.Error, key: "Option sourceRoot cannot be specified without specifying sourcemap option." },
Version_0: { code: 6029, category: DiagnosticCategory.Message, key: "Version {0}" },
Variable_0_implicitly_has_an_1_type: { code: 7005, category: DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." },
Parameter_0_implicitly_has_an_1_type: { code: 7006, category: DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." },
Member_0_implicitly_has_an_1_type: { code: 7008, category: DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." },
@@ -275,7 +280,7 @@ module ts {
Types_of_parameters_0_and_1_are_incompatible_Colon: { code: -9999999, category: DiagnosticCategory.Error, key: "Types of parameters '{0}' and '{1}' are incompatible:" },
Unknown_identifier_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Unknown identifier '{0}'." },
Property_0_is_inaccessible: { code: -9999999, category: DiagnosticCategory.Error, key: "Property '{0}' is inaccessible." },
Function_implementation_expected: { code: -9999999, category: DiagnosticCategory.Error, key: "Function implementation expected." },
Function_implementation_is_missing_or_not_immediately_following_the_declaration: { code: -9999999, category: DiagnosticCategory.Error, key: "Function implementation is missing or not immediately following the declaration." },
Property_0_of_type_1_is_not_assignable_to_string_index_type_2: { code: -9999999, category: DiagnosticCategory.Error, key: "Property '{0}' of type '{1}' is not assignable to string index type '{2}'." },
Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2: { code: -9999999, category: DiagnosticCategory.Error, key: "Property '{0}' of type '{1}' is not assignable to numeric index type '{2}'." },
Numeric_index_type_0_is_not_assignable_to_string_index_type_1: { code: -9999999, category: DiagnosticCategory.Error, key: "Numeric index type '{0}' is not assignable to string index type '{1}'." },
@@ -294,6 +299,7 @@ module ts {
A_module_declaration_cannot_be_located_prior_to_a_class_or_function_with_which_it_is_merged: { code: -9999999, category: DiagnosticCategory.Error, key: "A module declaration cannot be located prior to a class or function with which it is merged" },
Cannot_compile_external_modules_unless_the_module_flag_is_provided: { code: -9999999, category: DiagnosticCategory.Error, key: "Cannot compile external modules unless the '--module' flag is provided." },
Import_declaration_conflicts_with_local_declaration_of_0: { code: -9999999, category: DiagnosticCategory.Error, key: "Import declaration conflicts with local declaration of '{0}'" },
Module_0_is_hidden_by_a_local_declaration_with_the_same_name: { code: -9999999, category: DiagnosticCategory.Error, key: "Module '{0}' is hidden by a local declaration with the same name" },
Filename_0_differs_from_already_included_filename_1_only_in_casing: { code: -9999999, category: DiagnosticCategory.Error, key: "Filename '{0}' differs from already included filename '{1}' only in casing" },
Argument_for_module_option_must_be_commonjs_or_amd: { code: -9999999, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs' or 'amd'." },
Argument_for_target_option_must_be_es3_or_es5: { code: -9999999, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3' or 'es5'." },

View File

@@ -552,6 +552,10 @@
"category": "Error",
"code": 2190
},
"Individual declarations in merged declaration {0} must be all exported or all local.": {
"category": "Error",
"code": 2192
},
"'super' cannot be referenced in constructor arguments.":{
"category": "Error",
"code": 2193
@@ -619,8 +623,12 @@
"Expression resolves to variable declaration '_i' that compiler uses to initialize rest parameter.": {
"category": "Error",
"code": 2235
},
"Constructor implementation expected.": {
},
"Function implementation name must be '{0}'.": {
"category": "Error",
"code": 2239
},
"Constructor implementation is missing.": {
"category": "Error",
"code": 2240
},
@@ -632,7 +640,14 @@
"category": "Error",
"code": 2246
},
"Function overload must be static.": {
"category": "Error",
"code": 2247
},
"Function overload must not be static.": {
"category": "Error",
"code": 2248
},
"Circular definition of import alias '{0}'.": {
"category": "Error",
"code": 3000
@@ -840,6 +855,11 @@
"code": 5039
},
"Version {0}": {
"category": "Message",
"code": 6029
},
"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",
"code": 7005
@@ -897,7 +917,6 @@
"category": "Error",
"code": 7020
},
"Variable declaration list cannot be empty.": {
"category": "Error",
"code": -9999999
@@ -1118,7 +1137,7 @@
"category": "Error",
"code": -9999999
},
"Function implementation expected.": {
"Function implementation is missing or not immediately following the declaration.": {
"category": "Error",
"code": -9999999
},
@@ -1198,6 +1217,10 @@
"category": "Error",
"code": -9999999
},
"Module '{0}' is hidden by a local declaration with the same name": {
"category": "Error",
"code": -9999999
},
"Filename '{0}' differs from already included filename '{1}' only in casing": {
"category": "Error",
"code": -9999999

View File

@@ -2106,14 +2106,20 @@ module ts {
function parseObjectLiteral(): ObjectLiteral {
var node = <ObjectLiteral>createNode(SyntaxKind.ObjectLiteral);
parseExpected(SyntaxKind.OpenBraceToken);
if (scanner.hasPrecedingLineBreak()) node.flags |= NodeFlags.MultiLine;
node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralMember, TrailingCommaBehavior.Preserve);
if (scanner.hasPrecedingLineBreak()) {
node.flags |= NodeFlags.MultiLine;
}
// ES3 itself does not accept a trailing comma in an object literal, however, we'd like to preserve it in ES5.
var trailingCommaBehavior = languageVersion === ScriptTarget.ES3 ? TrailingCommaBehavior.Allow : TrailingCommaBehavior.Preserve;
node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralMember, trailingCommaBehavior);
parseExpected(SyntaxKind.CloseBraceToken);
var seen: Map<SymbolFlags> = {};
var Property = 1;
var GetAccessor = 2;
var SetAccesor = 4;
var SetAccesor = 4;
var GetOrSetAccessor = GetAccessor | SetAccesor;
forEach(node.properties, (p: Declaration) => {
if (p.kind === SyntaxKind.OmittedExpression) {
@@ -2908,7 +2914,16 @@ module ts {
node.typeParameters = sig.typeParameters;
node.parameters = sig.parameters;
node.type = sig.type;
node.body = parseBody(/* ignoreMissingOpenBrace */ false);
// A common error is to try to declare an accessor in an ambient class.
if (inAmbientContext && canParseSemicolon()) {
parseSemicolon();
node.body = createMissingNode();
}
else {
node.body = parseBody(/* ignoreMissingOpenBrace */ false);
}
return finishNode(node);
}

View File

@@ -9,6 +9,8 @@
/// <reference path="commandLineParser.ts"/>
module ts {
export var version = "1.1.0.0";
/// Checks to see if the locale is in the appropriate format,
/// and if it is, attempt to set the appropriate language.
function validateLocaleAndSetLanguage(locale: string, errors: Diagnostic[]): boolean {
@@ -76,39 +78,47 @@ module ts {
return count;
}
function reportErrors(errors: Diagnostic[]) {
function reportDiagnostic(error: Diagnostic) {
if (error.file) {
var loc = error.file.getLineAndCharacterFromPosition(error.start);
sys.writeErr(error.file.filename + "(" + loc.line + "," + loc.character + "): " + error.messageText + sys.newLine);
}
else {
sys.writeErr(error.messageText + sys.newLine);
}
}
function reportDiagnostics(errors: Diagnostic[]) {
for (var i = 0; i < errors.length; i++) {
var error = errors[i];
if (error.file) {
var loc = error.file.getLineAndCharacterFromPosition(error.start);
sys.writeErr(error.file.filename + "(" + loc.line + "," + loc.character + "): " + error.messageText + sys.newLine);
}
else {
sys.writeErr(error.messageText + sys.newLine);
}
reportDiagnostic(errors[i]);
}
}
function padLeft(s: string, length: number) {
while (s.length < length) s = " " + s;
while (s.length < length) {
s = " " + s;
}
return s;
}
function padRight(s: string, length: number) {
while (s.length < length) s = s + " ";
while (s.length < length) {
s = s + " ";
}
return s;
}
function reportDiagnostic(name: string, value: string) {
function reportStatisticalValue(name: string, value: string) {
sys.writeErr(padRight(name + ":", 12) + padLeft(value.toString(), 10) + sys.newLine);
}
function reportDiagnosticCount(name: string, count: number) {
reportDiagnostic(name, "" + count);
function reportCountStatistic(name: string, count: number) {
reportStatisticalValue(name, "" + count);
}
function reportDiagnosticTime(name: string, time: number) {
reportDiagnostic(name, (time / 1000).toFixed(2) + "s");
function reportTimeStatistic(name: string, time: number) {
reportStatisticalValue(name, (time / 1000).toFixed(2) + "s");
}
function createCompilerHost(options: CompilerOptions): CompilerHost {
@@ -120,7 +130,9 @@ module ts {
var text = sys.readFile(filename, options.charset);
}
catch (e) {
if (onError) onError(e.message);
if (onError) {
onError(e.message);
}
text = "";
}
return text !== undefined ? createSourceFile(filename, text, languageVersion) : undefined;
@@ -168,25 +180,26 @@ module ts {
export function executeCommandLine(args: string[]): number {
var cmds = parseCommandLine(args);
if (cmds.options.locale) {
validateLocaleAndSetLanguage(cmds.options.locale, cmds.errors);
}
if (cmds.filenames.length === 0 && !(cmds.options.help || cmds.options.version)) {
cmds.errors.push(createCompilerDiagnostic(Diagnostics.No_input_files_specified));
}
if (cmds.options.version) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Version_0, version));
return 0;
}
if (cmds.filenames.length === 0 || cmds.options.help) {
// TODO (drosen): Usage.
}
// If a locale has been set but fails to load, act as if it was never specified,
// but collect the errors to report along the way.
if (cmds.options.locale) {
validateLocaleAndSetLanguage(cmds.options.locale, cmds.errors);
}
if (cmds.errors.length) {
reportErrors(cmds.errors);
reportDiagnostics(cmds.errors);
return 1;
}
@@ -209,19 +222,19 @@ module ts {
errors = concatenate(semanticErrors, emitErrors);
}
reportErrors(errors);
reportDiagnostics(errors);
if (cmds.options.diagnostics) {
reportDiagnosticCount("Files", program.getSourceFiles().length);
reportDiagnosticCount("Lines", countLines(program));
reportDiagnosticCount("Nodes", checker ? checker.getNodeCount() : 0);
reportDiagnosticCount("Identifiers", checker ? checker.getIdentifierCount() : 0);
reportDiagnosticCount("Symbols", checker ? checker.getSymbolCount() : 0);
reportDiagnosticCount("Types", checker ? checker.getTypeCount() : 0);
reportDiagnosticTime("Parse time", bindStart - parseStart);
reportDiagnosticTime("Bind time", checkStart - bindStart);
reportDiagnosticTime("Check time", emitStart - checkStart);
reportDiagnosticTime("Emit time", reportStart - emitStart);
reportDiagnosticTime("Total time", reportStart - parseStart);
reportCountStatistic("Files", program.getSourceFiles().length);
reportCountStatistic("Lines", countLines(program));
reportCountStatistic("Nodes", checker ? checker.getNodeCount() : 0);
reportCountStatistic("Identifiers", checker ? checker.getIdentifierCount() : 0);
reportCountStatistic("Symbols", checker ? checker.getSymbolCount() : 0);
reportCountStatistic("Types", checker ? checker.getTypeCount() : 0);
reportTimeStatistic("Parse time", bindStart - parseStart);
reportTimeStatistic("Bind time", checkStart - bindStart);
reportTimeStatistic("Check time", emitStart - checkStart);
reportTimeStatistic("Emit time", reportStart - emitStart);
reportTimeStatistic("Total time", reportStart - parseStart);
}
return errors.length ? 1 : 0;
}

View File

@@ -243,6 +243,7 @@ module ts {
symbol?: Symbol; // Symbol declared by node (initialized by binding)
locals?: SymbolTable; // Locals associated with node (initialized by binding)
nextContainer?: Node; // Next container in declaration order (initialized by binding)
localSymbol?: Symbol; // Local symbol declared by node (initialized by binding only for exported nodes)
}
export interface NodeArray<T> extends Array<T>, TextRange { }
@@ -699,6 +700,7 @@ module ts {
IsContainer = HasLocals | HasExports | HasMembers,
PropertyOrAccessor = Property | Accessor,
Export = ExportNamespace | ExportType | ExportValue,
}
export interface Symbol {