diff --git a/package.json b/package.json index 00752302254..f6391394c6a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "http://typescriptlang.org/", - "version": "1.3.0", + "version": "1.4.0", "licenses": [ { "type": "Apache License 2.0", diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 1dfe3babfd0..dfb5482b09c 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -265,7 +265,8 @@ module ts { case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -407,7 +408,8 @@ module ts { bindDeclaration(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.FunctionScopedVariableExcludes, /*isBlockScopeContainer*/ false); } break; - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: bindDeclaration(node, SymbolFlags.Property | ((node).questionToken ? SymbolFlags.Optional : 0), SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.PropertyAssignment: @@ -422,7 +424,8 @@ module ts { case SyntaxKind.IndexSignature: bindDeclaration(node, SymbolFlags.Signature, 0, /*isBlockScopeContainer*/ false); break; - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: // If this is an ObjectLiteralExpression method, then it sits in the same space // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes // so that it will conflict with any other object literal members with the same diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9cbb9f25990..8c383368df2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -363,7 +363,8 @@ module ts { break loop; } break; - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: // TypeScript 1.0 spec (April 2014): 8.4.1 // Initializer expressions for instance member variables are evaluated in the scope // of the class constructor body but are not permitted to reference parameters or @@ -393,7 +394,8 @@ module ts { break loop; } break; - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -1612,10 +1614,12 @@ module ts { // Exported members/ambient module elements (exception import declaration) are visible if parent is visible return isDeclarationVisible(parent); - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: if (node.flags & (NodeFlags.Private | NodeFlags.Protected)) { // Private/protected properties/methods are not visible return false; @@ -2670,7 +2674,8 @@ module ts { case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: case SyntaxKind.FunctionDeclaration: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: @@ -3341,7 +3346,7 @@ module ts { // Returns true if the given expression contains (at any level of nesting) a function or arrow expression // that is subject to contextual typing. function isContextSensitive(node: Expression | MethodDeclaration | ObjectLiteralElement): boolean { - Debug.assert(node.kind !== SyntaxKind.Method || isObjectLiteralMethod(node)); + Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); switch (node.kind) { case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: @@ -3358,7 +3363,8 @@ module ts { (isContextSensitive((node).left) || isContextSensitive((node).right)); case SyntaxKind.PropertyAssignment: return isContextSensitive((node).initializer); - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: return isContextSensitiveFunctionLikeDeclaration(node); } @@ -4190,7 +4196,8 @@ module ts { function reportImplicitAnyError(declaration: Declaration, type: Type) { var typeAsString = typeToString(getWidenedType(type)); switch (declaration.kind) { - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: var diagnostic = Diagnostics.Member_0_implicitly_has_an_1_type; break; case SyntaxKind.Parameter: @@ -4199,7 +4206,8 @@ module ts { Diagnostics.Parameter_0_implicitly_has_an_1_type; break; case SyntaxKind.FunctionDeclaration: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.FunctionExpression: @@ -4647,7 +4655,8 @@ module ts { case SyntaxKind.SourceFile: case SyntaxKind.ModuleDeclaration: case SyntaxKind.FunctionDeclaration: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.Constructor: @@ -4794,7 +4803,7 @@ module ts { function captureLexicalThis(node: Node, container: Node): void { var classNode = container.parent && container.parent.kind === SyntaxKind.ClassDeclaration ? container.parent : undefined; getNodeLinks(node).flags |= NodeCheckFlags.LexicalThis; - if (container.kind === SyntaxKind.Property || container.kind === SyntaxKind.Constructor) { + if (container.kind === SyntaxKind.PropertyDeclaration || container.kind === SyntaxKind.Constructor) { getNodeLinks(classNode).flags |= NodeCheckFlags.CaptureThis; } else { @@ -4829,7 +4838,8 @@ module ts { // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks } break; - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: if (container.flags & NodeFlags.Static) { error(node, Diagnostics.this_cannot_be_referenced_in_a_static_property_initializer); // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks @@ -4857,8 +4867,10 @@ module ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - case SyntaxKind.Property: - case SyntaxKind.Method: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -4916,16 +4928,19 @@ module ts { if (container && container.parent && container.parent.kind === SyntaxKind.ClassDeclaration) { if (container.flags & NodeFlags.Static) { canUseSuperExpression = - container.kind === SyntaxKind.Method || + container.kind === SyntaxKind.MethodDeclaration || + container.kind === SyntaxKind.MethodSignature || container.kind === SyntaxKind.GetAccessor || container.kind === SyntaxKind.SetAccessor; } else { canUseSuperExpression = - container.kind === SyntaxKind.Method || + container.kind === SyntaxKind.MethodDeclaration || + container.kind === SyntaxKind.MethodSignature || container.kind === SyntaxKind.GetAccessor || container.kind === SyntaxKind.SetAccessor || - container.kind === SyntaxKind.Property || + container.kind === SyntaxKind.PropertyDeclaration || + container.kind === SyntaxKind.PropertySignature || container.kind === SyntaxKind.Constructor; } } @@ -5177,7 +5192,8 @@ module ts { switch (parent.kind) { case SyntaxKind.VariableDeclaration: case SyntaxKind.Parameter: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.BindingElement: return getContextualTypeForInitializerExpression(node); case SyntaxKind.ArrowFunction: @@ -5227,7 +5243,7 @@ module ts { // all identical ignoring their return type, the result is same signature but with return type as // union type of return types from these signatures function getContextualSignature(node: FunctionExpression | MethodDeclaration): Signature { - Debug.assert(node.kind !== SyntaxKind.Method || isObjectLiteralMethod(node)); + Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); var type = isObjectLiteralMethod(node) ? getContextualTypeForObjectLiteralMethod(node) : getContextualType(node); @@ -5349,7 +5365,7 @@ module ts { if (memberDecl.kind === SyntaxKind.PropertyAssignment) { var type = checkExpression((memberDecl).initializer, contextualMapper); } - else if (memberDecl.kind === SyntaxKind.Method) { + else if (memberDecl.kind === SyntaxKind.MethodDeclaration) { var type = checkObjectLiteralMethod(memberDecl, contextualMapper); } else { @@ -5417,7 +5433,7 @@ module ts { // If a symbol is a synthesized symbol with no value declaration, we assume it is a property. Example of this are the synthesized // '.prototype' property as well as synthesized tuple index properties. function getDeclarationKindFromSymbol(s: Symbol) { - return s.valueDeclaration ? s.valueDeclaration.kind : SyntaxKind.Property; + return s.valueDeclaration ? s.valueDeclaration.kind : SyntaxKind.PropertyDeclaration; } function getDeclarationFlagsFromSymbol(s: Symbol) { @@ -5495,7 +5511,7 @@ module ts { // - In a static member function or static member accessor // where this references the constructor function object of a derived class, // a super property access is permitted and must specify a public static member function of the base class. - if (left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.Method) { + if (left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.MethodDeclaration) { error(right, Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); } else { @@ -5516,7 +5532,7 @@ module ts { if (type !== unknownType && type !== anyType) { var prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & SymbolFlags.Class) { - if (left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.Method) { + if (left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.MethodDeclaration) { return false; } else { @@ -6379,7 +6395,7 @@ module ts { } function checkFunctionExpressionOrObjectLiteralMethod(node: FunctionExpression | MethodDeclaration, contextualMapper?: TypeMapper): Type { - Debug.assert(node.kind !== SyntaxKind.Method || isObjectLiteralMethod(node)); + Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); // The identityMapper object is used to indicate that function expressions are wildcards if (contextualMapper === identityMapper) { @@ -6412,7 +6428,7 @@ module ts { } } - if (fullTypeCheck && node.kind !== SyntaxKind.Method) { + if (fullTypeCheck && node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) { checkCollisionWithCapturedSuperVariable(node, (node).name); checkCollisionWithCapturedThisVariable(node,(node).name); } @@ -6421,7 +6437,7 @@ module ts { } function checkFunctionExpressionOrObjectLiteralMethodBody(node: FunctionExpression | MethodDeclaration) { - Debug.assert(node.kind !== SyntaxKind.Method || isObjectLiteralMethod(node)); + Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); if (node.type) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } @@ -7146,7 +7162,7 @@ module ts { } function isInstancePropertyWithInitializer(n: Node): boolean { - return n.kind === SyntaxKind.Property && + return n.kind === SyntaxKind.PropertyDeclaration && !(n.flags & NodeFlags.Static) && !!(n).initializer; } @@ -7401,7 +7417,7 @@ module ts { // TODO(jfreeman): These are methods, so handle computed name case if (node.name && (subsequentNode).name && (node.name).text === ((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.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature); 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); @@ -7442,7 +7458,7 @@ module ts { previousDeclaration = undefined; } - if (node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.Method || node.kind === SyntaxKind.Constructor) { + if (node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature || node.kind === SyntaxKind.Constructor) { var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck); someNodeFlags |= currentNodeFlags; allNodeFlags &= currentNodeFlags; @@ -7674,8 +7690,10 @@ module ts { return false; } - if (node.kind === SyntaxKind.Property || - node.kind === SyntaxKind.Method || + if (node.kind === SyntaxKind.PropertyDeclaration || + node.kind === SyntaxKind.PropertySignature || + node.kind === SyntaxKind.MethodDeclaration || + node.kind === SyntaxKind.MethodSignature || node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor) { // it is ok to have member named '_super' or '_this' - member access is always qualified @@ -7880,7 +7898,7 @@ module ts { checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, /*headMessage*/ undefined); } } - if (node.kind !== SyntaxKind.Property) { + if (node.kind !== SyntaxKind.PropertyDeclaration && node.kind !== SyntaxKind.PropertySignature) { // We know we don't have a binding pattern or computed name here checkExportsOnMergedDeclarations(node); checkCollisionWithConstDeclarations(node); @@ -8718,7 +8736,8 @@ module ts { return checkTypeParameter(node); case SyntaxKind.Parameter: return checkParameter(node); - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: return checkPropertyDeclaration(node); case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: @@ -8726,7 +8745,8 @@ module ts { case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: return checkSignatureDeclaration(node); - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: return checkMethodDeclaration(node); case SyntaxKind.Constructor: return checkConstructorDeclaration(node); @@ -8817,7 +8837,8 @@ module ts { forEach((node).parameters, checkFunctionExpressionBodies); checkFunctionExpressionOrObjectLiteralMethodBody(node); break; - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: forEach((node).parameters, checkFunctionExpressionBodies); if (isObjectLiteralMethod(node)) { checkFunctionExpressionOrObjectLiteralMethodBody(node); @@ -8833,7 +8854,8 @@ module ts { checkFunctionExpressionBodies((node).expression); break; case SyntaxKind.Parameter: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.ObjectBindingPattern: case SyntaxKind.ArrayBindingPattern: case SyntaxKind.BindingElement: @@ -9093,7 +9115,8 @@ module ts { switch (parent.kind) { case SyntaxKind.TypeParameter: return node === (parent).constraint; - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: return node === (parent).type; @@ -9101,7 +9124,8 @@ module ts { case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: case SyntaxKind.Constructor: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: return node === (parent).type; diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index c7edacaba35..9428f94bb52 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -761,6 +761,10 @@ module ts { writeLine(); } + function isPrivateMethodTypeParameter(node: TypeParameterDeclaration) { + return node.parent.kind === SyntaxKind.MethodDeclaration && (node.parent.flags & NodeFlags.Private); + } + function emitTypeParameters(typeParameters: TypeParameterDeclaration[]) { function emitTypeParameter(node: TypeParameterDeclaration) { increaseIndent(); @@ -768,12 +772,13 @@ module ts { decreaseIndent(); writeTextOfNode(currentSourceFile, node.name); // If there is constraint present and this is not a type parameter of the private method emit the constraint - if (node.constraint && (node.parent.kind !== SyntaxKind.Method || !(node.parent.flags & NodeFlags.Private))) { + if (node.constraint && !isPrivateMethodTypeParameter(node)) { write(" extends "); if (node.parent.kind === SyntaxKind.FunctionType || node.parent.kind === SyntaxKind.ConstructorType || (node.parent.parent && node.parent.parent.kind === SyntaxKind.TypeLiteral)) { - Debug.assert(node.parent.kind === SyntaxKind.Method || + Debug.assert(node.parent.kind === SyntaxKind.MethodDeclaration || + node.parent.kind === SyntaxKind.MethodSignature || node.parent.kind === SyntaxKind.FunctionType || node.parent.kind === SyntaxKind.ConstructorType || node.parent.kind === SyntaxKind.CallSignature || @@ -805,7 +810,8 @@ module ts { diagnosticMessage = Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; break; - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: if (node.parent.flags & NodeFlags.Static) { diagnosticMessage = Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } @@ -944,10 +950,10 @@ module ts { if (node.kind !== SyntaxKind.VariableDeclaration || resolver.isDeclarationVisible(node)) { writeTextOfNode(currentSourceFile, node.name); // If optional property emit ? - if (node.kind === SyntaxKind.Property && hasQuestionToken(node)) { + if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && hasQuestionToken(node)) { write("?"); } - if (node.kind === SyntaxKind.Property && node.parent.kind === SyntaxKind.TypeLiteral) { + if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) { emitTypeOfVariableDeclarationFromTypeLiteral(node); } else if (!(node.flags & NodeFlags.Private)) { @@ -965,7 +971,7 @@ module ts { Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; } // This check is to ensure we don't report error on constructor parameter property as that error would be reported during parameter emit - else if (node.kind === SyntaxKind.Property) { + else if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) { // TODO(jfreeman): Deal with computed properties in error reporting. if (node.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? @@ -1113,7 +1119,7 @@ module ts { if (node.kind === SyntaxKind.FunctionDeclaration) { emitModuleElementDeclarationFlags(node); } - else if (node.kind === SyntaxKind.Method) { + else if (node.kind === SyntaxKind.MethodDeclaration) { emitClassMemberDeclarationFlags(node); } if (node.kind === SyntaxKind.FunctionDeclaration) { @@ -1208,7 +1214,8 @@ module ts { Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; break; - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: if (node.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? @@ -1301,7 +1308,8 @@ module ts { Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; break; - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: if (node.parent.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? @@ -1348,7 +1356,8 @@ module ts { switch (node.kind) { case SyntaxKind.Constructor: case SyntaxKind.FunctionDeclaration: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: return emitFunctionDeclaration(node); case SyntaxKind.ConstructSignature: case SyntaxKind.CallSignature: @@ -1359,7 +1368,8 @@ module ts { return emitAccessorDeclaration(node); case SyntaxKind.VariableStatement: return emitVariableStatement(node); - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: return emitPropertyDeclaration(node); case SyntaxKind.InterfaceDeclaration: return emitInterfaceDeclaration(node); @@ -1736,7 +1746,8 @@ module ts { } else if (node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.FunctionExpression || - node.kind === SyntaxKind.Method || + node.kind === SyntaxKind.MethodDeclaration || + node.kind === SyntaxKind.MethodSignature || node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor || node.kind === SyntaxKind.ModuleDeclaration || @@ -2151,11 +2162,13 @@ module ts { case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.EnumMember: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.FunctionDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -3097,7 +3110,7 @@ module ts { return emitPinnedOrTripleSlashComments(node); } - if (node.kind !== SyntaxKind.Method) { + if (node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) { // Methods will emit the comments as part of emitting method declaration emitLeadingComments(node); } @@ -3106,7 +3119,7 @@ module ts { emit(node.name); } emitSignatureAndBody(node); - if (node.kind !== SyntaxKind.Method) { + if (node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) { emitTrailingComments(node); } } @@ -3256,7 +3269,7 @@ module ts { function emitMemberAssignments(node: ClassDeclaration, staticFlag: NodeFlags) { forEach(node.members, member => { - if (member.kind === SyntaxKind.Property && (member.flags & NodeFlags.Static) === staticFlag && (member).initializer) { + if (member.kind === SyntaxKind.PropertyDeclaration && (member.flags & NodeFlags.Static) === staticFlag && (member).initializer) { writeLine(); emitLeadingComments(member); emitStart(member); @@ -3280,7 +3293,7 @@ module ts { function emitMemberFunctions(node: ClassDeclaration) { forEach(node.members, member => { - if (member.kind === SyntaxKind.Method) { + if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) { if (!(member).body) { return emitPinnedOrTripleSlashComments(member); } @@ -3815,7 +3828,8 @@ module ts { return emitIdentifier(node); case SyntaxKind.Parameter: return emitParameter(node); - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: return emitMethod(node); case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index c1c2ebbef2b..d406b938d4e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -44,12 +44,6 @@ module ts { return new (getNodeConstructor(kind))(); } - interface ReferenceComments { - referencedFiles: FileReference[]; - amdDependencies: string[]; - amdModuleName: string; - } - export function getSourceFileOfNode(node: Node): SourceFile { while (node && node.kind !== SyntaxKind.SourceFile) node = node.parent; return node; @@ -263,7 +257,8 @@ module ts { return child((node).name) || child((node).constraint); case SyntaxKind.Parameter: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.VariableDeclaration: @@ -284,7 +279,8 @@ module ts { children((node).typeParameters) || children((node).parameters) || child((node).type); - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -292,6 +288,7 @@ module ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.ArrowFunction: return children(node.modifiers) || + child((node).asteriskToken) || child((node).name) || child((node).questionToken) || children((node).typeParameters) || @@ -347,6 +344,9 @@ module ts { return child((node).expression); case SyntaxKind.PrefixUnaryExpression: return child((node).operand); + case SyntaxKind.YieldExpression: + return child((node).asteriskToken) || + child((node).expression); case SyntaxKind.PostfixUnaryExpression: return child((node).operand); case SyntaxKind.BinaryExpression: @@ -499,8 +499,12 @@ module ts { export function isAnyFunction(node: Node): boolean { if (node) { switch (node.kind) { - case SyntaxKind.Method: case SyntaxKind.Constructor: + case SyntaxKind.FunctionExpression: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ArrowFunction: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.CallSignature: @@ -523,7 +527,7 @@ module ts { } export function isObjectLiteralMethod(node: Node) { - return node && node.kind === SyntaxKind.Method && node.parent.kind === SyntaxKind.ObjectLiteralExpression; + return node && node.kind === SyntaxKind.MethodDeclaration && node.parent.kind === SyntaxKind.ObjectLiteralExpression; } export function getContainingFunction(node: Node): FunctionLikeDeclaration { @@ -550,8 +554,10 @@ module ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ModuleDeclaration: - case SyntaxKind.Property: - case SyntaxKind.Method: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -569,8 +575,10 @@ module ts { return undefined; } switch (node.kind) { - case SyntaxKind.Property: - case SyntaxKind.Method: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -635,7 +643,8 @@ module ts { switch (parent.kind) { case SyntaxKind.VariableDeclaration: case SyntaxKind.Parameter: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.EnumMember: case SyntaxKind.PropertyAssignment: case SyntaxKind.BindingElement: @@ -693,11 +702,13 @@ module ts { switch (node.kind) { case SyntaxKind.Parameter: return (node).questionToken !== undefined; - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: return (node).questionToken !== undefined; case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.PropertyAssignment: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: return (node).questionToken !== undefined; } } @@ -739,11 +750,13 @@ module ts { case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.EnumMember: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.FunctionDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -1003,7 +1016,6 @@ module ts { } export function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, version: string, isOpen: boolean = false): SourceFile { - var token: SyntaxKind; var parsingContext: ParsingContext; var identifiers: Map = {}; var identifierCount = 0; @@ -1012,8 +1024,7 @@ module ts { // Flags that dictate what parsing context we're in. For example: // Whether or not we are in strict parsing mode. All that changes in strict parsing mode is - // that some tokens that would be considered identifiers may be considered keywords. When - // rewinding, we need to store and restore this as the mode may have changed. + // that some tokens that would be considered identifiers may be considered keywords. // // When adding more parser context flags, consider which is the more common case that the // flag will be in. This should be hte 'false' state for that flag. The reason for this is @@ -1088,6 +1099,44 @@ module ts { // attached to the EOF token. var parseErrorBeforeNextFinishedNode = false; + var sourceFile = createNode(SyntaxKind.SourceFile, 0); + if (fileExtensionIs(filename, ".d.ts")) { + sourceFile.flags = NodeFlags.DeclarationFile; + } + sourceFile.end = sourceText.length; + sourceFile.filename = normalizePath(filename); + sourceFile.text = sourceText; + + sourceFile.getLineAndCharacterFromPosition = getLineAndCharacterFromSourcePosition; + sourceFile.getPositionFromLineAndCharacter = getPositionFromSourceLineAndCharacter; + sourceFile.getLineStarts = getLineStarts; + sourceFile.getSyntacticDiagnostics = getSyntacticDiagnostics; + + sourceFile.referenceDiagnostics = []; + sourceFile.parseDiagnostics = []; + sourceFile.grammarDiagnostics = []; + sourceFile.semanticDiagnostics = []; + + processReferenceComments(); + + // Create and prime the scanner before parsing the source elements. + var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceText, scanError); + var token = nextToken(); + + sourceFile.statements = parseList(ParsingContext.SourceElements, /*checkForStrictMode*/ true, parseSourceElement); + Debug.assert(token === SyntaxKind.EndOfFileToken); + sourceFile.endOfFileToken = parseTokenNode(); + + sourceFile.externalModuleIndicator = getExternalModuleIndicator(); + + sourceFile.nodeCount = nodeCount; + sourceFile.identifierCount = identifierCount; + sourceFile.version = version; + sourceFile.isOpen = isOpen; + sourceFile.languageVersion = languageVersion; + sourceFile.identifiers = identifiers; + return sourceFile; + function setContextFlag(val: Boolean, flag: ParserContextFlags) { if (val) { contextFlags |= flag; @@ -1346,15 +1395,17 @@ module ts { return token === SyntaxKind.CloseBraceToken || token === SyntaxKind.EndOfFileToken || scanner.hasPrecedingLineBreak(); } - function parseSemicolon(diagnosticMessage?: DiagnosticMessage): void { + function parseSemicolon(diagnosticMessage?: DiagnosticMessage): boolean { if (canParseSemicolon()) { if (token === SyntaxKind.SemicolonToken) { // consume the semicolon if it was explicitly provided. nextToken(); } + + return true; } else { - parseExpected(SyntaxKind.SemicolonToken, diagnosticMessage); + return parseExpected(SyntaxKind.SemicolonToken, diagnosticMessage); } } @@ -2063,13 +2114,27 @@ module ts { return requireCompleteParameterList ? undefined : createMissingList(); } + function parseTypeMemberSemicolon() { + // Try to parse out an explicit or implicit (ASI) semicolon for a type member. If we + // don't have one, then an appropriate error will be reported. + if (parseSemicolon()) { + return; + } + + // If we don't have a semicolon, then the user may have written a comma instead + // accidently (pretty easy to do since commas are so prevalent as list separators). So + // just consume the comma and keep going. Note: we'll have already reported the error + // about the missing semicolon above. + parseOptional(SyntaxKind.CommaToken); + } + function parseSignatureMember(kind: SyntaxKind): SignatureDeclaration { var node = createNode(kind); if (kind === SyntaxKind.ConstructSignature) { parseExpected(SyntaxKind.NewKeyword); } fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ false, node); - parseSemicolon(); + parseTypeMemberSemicolon(); return finishNode(node); } @@ -2141,33 +2206,32 @@ module ts { setModifiers(node, modifiers); node.parameters = parseBracketedList(ParsingContext.Parameters, parseParameter, SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken); node.type = parseTypeAnnotation(); - parseSemicolon(); + parseTypeMemberSemicolon(); return finishNode(node) } - function parsePropertyOrMethod(): Declaration { + function parsePropertyOrMethodSignature(): Declaration { var fullStart = scanner.getStartPos(); var name = parsePropertyName(); var questionToken = parseOptionalToken(SyntaxKind.QuestionToken); if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { - var method = createNode(SyntaxKind.Method, fullStart); + var method = createNode(SyntaxKind.MethodSignature, fullStart); method.name = name; method.questionToken = questionToken; // Method signatues don't exist in expression contexts. So they have neither // [Yield] nor [GeneratorParameter] fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ false, method); - - parseSemicolon(); + parseTypeMemberSemicolon(); return finishNode(method); } else { - var property = createNode(SyntaxKind.Property, fullStart); + var property = createNode(SyntaxKind.PropertySignature, fullStart); property.name = name; property.questionToken = questionToken; property.type = parseTypeAnnotation(); - parseSemicolon(); + parseTypeMemberSemicolon(); return finishNode(property); } } @@ -2199,7 +2263,7 @@ module ts { return parseSignatureMember(SyntaxKind.CallSignature); case SyntaxKind.OpenBracketToken: // Indexer or computed property - return isIndexSignature() ? parseIndexSignatureDeclaration(scanner.getStartPos(), /*modifiers:*/ undefined) : parsePropertyOrMethod(); + return isIndexSignature() ? parseIndexSignatureDeclaration(scanner.getStartPos(), /*modifiers:*/ undefined) : parsePropertyOrMethodSignature(); case SyntaxKind.NewKeyword: if (lookAhead(isStartOfConstructSignature)) { return parseSignatureMember(SyntaxKind.ConstructSignature); @@ -2207,10 +2271,10 @@ module ts { // fall through. case SyntaxKind.StringLiteral: case SyntaxKind.NumericLiteral: - return parsePropertyOrMethod(); + return parsePropertyOrMethodSignature(); default: if (isIdentifierOrKeyword()) { - return parsePropertyOrMethod(); + return parsePropertyOrMethodSignature(); } } } @@ -2451,6 +2515,14 @@ module ts { // a generator, or in strict mode (or both)) and it started a yield expression. return true; default: + // Error tolerance. If we see the start of some binary operator, we consider + // that the start of an expression. That way we'll parse out a missing identifier, + // give a good message about an identifier being missing, and then consume the + // rest of the binary expression. + if (isBinaryOperator()) { + return true; + } + return isIdentifier(); } } @@ -2837,7 +2909,7 @@ module ts { // reScanGreaterToken so that we merge token sequences like > and = into >= reScanGreaterToken(); - var newPrecedence = getOperatorPrecedence(); + var newPrecedence = getBinaryOperatorPrecedence(); // Check the precedence to see if we should "take" this operator if (newPrecedence <= precedence) { @@ -2856,7 +2928,15 @@ module ts { return leftOperand; } - function getOperatorPrecedence(): number { + function isBinaryOperator() { + if (inDisallowInContext() && token === SyntaxKind.InKeyword) { + return false; + } + + return getBinaryOperatorPrecedence() > 0; + } + + function getBinaryOperatorPrecedence(): number { switch (token) { case SyntaxKind.BarBarToken: return 1; @@ -3902,7 +3982,7 @@ module ts { } function parseMethodDeclaration(fullStart: number, modifiers: ModifiersArray, asteriskToken: Node, name: DeclarationName, questionToken: Node, requireBlock: boolean): MethodDeclaration { - var method = createNode(SyntaxKind.Method, fullStart); + var method = createNode(SyntaxKind.MethodDeclaration, fullStart); setModifiers(method, modifiers); method.asteriskToken = asteriskToken; method.name = name; @@ -3923,7 +4003,7 @@ module ts { return parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, /*requireBlock:*/ false); } else { - var property = createNode(SyntaxKind.Property, fullStart); + var property = createNode(SyntaxKind.PropertyDeclaration, fullStart); setModifiers(property, modifiers); property.name = name; property.questionToken = questionToken; @@ -4367,7 +4447,7 @@ module ts { : parseStatement(); } - function processReferenceComments(): ReferenceComments { + function processReferenceComments(): void { var triviaScanner = createScanner(languageVersion, /*skipTrivia*/false, sourceText); var referencedFiles: FileReference[] = []; var amdDependencies: string[] = []; @@ -4418,11 +4498,9 @@ module ts { } } - return { - referencedFiles, - amdDependencies, - amdModuleName - }; + sourceFile.referencedFiles = referencedFiles; + sourceFile.amdDependencies = amdDependencies; + sourceFile.amdModuleName = amdModuleName; } function getExternalModuleIndicator() { @@ -4452,49 +4530,6 @@ module ts { Debug.assert(syntacticDiagnostics !== undefined); return syntacticDiagnostics; } - - - var scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceText, scanError); - var sourceFile = createNode(SyntaxKind.SourceFile); - - if (fileExtensionIs(filename, ".d.ts")) { - sourceFile.flags = NodeFlags.DeclarationFile; - } - sourceFile.end = sourceText.length; - sourceFile.filename = normalizePath(filename); - sourceFile.text = sourceText; - - sourceFile.getLineAndCharacterFromPosition = getLineAndCharacterFromSourcePosition; - sourceFile.getPositionFromLineAndCharacter = getPositionFromSourceLineAndCharacter; - sourceFile.getLineStarts = getLineStarts; - sourceFile.getSyntacticDiagnostics = getSyntacticDiagnostics; - - sourceFile.referenceDiagnostics = []; - sourceFile.parseDiagnostics = []; - sourceFile.grammarDiagnostics = []; - sourceFile.semanticDiagnostics = []; - - var referenceComments = processReferenceComments(); - sourceFile.referencedFiles = referenceComments.referencedFiles; - sourceFile.amdDependencies = referenceComments.amdDependencies; - sourceFile.amdModuleName = referenceComments.amdModuleName; - - // Prime the scanner before parsing the source elements - nextToken(); - - sourceFile.statements = parseList(ParsingContext.SourceElements, /*checkForStrictMode*/ true, parseSourceElement); - Debug.assert(token === SyntaxKind.EndOfFileToken); - sourceFile.endOfFileToken = parseTokenNode(); - - sourceFile.externalModuleIndicator = getExternalModuleIndicator(); - - sourceFile.nodeCount = nodeCount; - sourceFile.identifierCount = identifierCount; - sourceFile.version = version; - sourceFile.isOpen = isOpen; - sourceFile.languageVersion = languageVersion; - sourceFile.identifiers = identifiers; - return sourceFile; } function isLeftHandSideExpression(expr: Expression): boolean { @@ -4624,14 +4659,18 @@ module ts { case SyntaxKind.InterfaceDeclaration: return checkInterfaceDeclaration(node); case SyntaxKind.LabeledStatement: return checkLabeledStatement(node); case SyntaxKind.PropertyAssignment: return checkPropertyAssignment(node); - case SyntaxKind.Method: return checkMethod(node); + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + return checkMethod(node); case SyntaxKind.ModuleDeclaration: return checkModuleDeclaration(node); case SyntaxKind.ObjectLiteralExpression: return checkObjectLiteralExpression(node); case SyntaxKind.NumericLiteral: return checkNumericLiteral(node); case SyntaxKind.Parameter: return checkParameter(node); case SyntaxKind.PostfixUnaryExpression: return checkPostfixUnaryExpression(node); case SyntaxKind.PrefixUnaryExpression: return checkPrefixUnaryExpression(node); - case SyntaxKind.Property: return checkProperty(node); + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + return checkProperty(node); case SyntaxKind.ReturnStatement: return checkReturnStatement(node); case SyntaxKind.SetAccessor: return checkSetAccessor(node); case SyntaxKind.SourceFile: return checkSourceFile(node); @@ -5239,7 +5278,7 @@ module ts { var currentKind: number; if (prop.kind === SyntaxKind.PropertyAssignment || prop.kind === SyntaxKind.ShorthandPropertyAssignment || - prop.kind === SyntaxKind.Method) { + prop.kind === SyntaxKind.MethodDeclaration) { currentKind = Property; } else if (prop.kind === SyntaxKind.GetAccessor) { @@ -5293,8 +5332,10 @@ module ts { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.Constructor: - case SyntaxKind.Property: - case SyntaxKind.Method: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.IndexSignature: case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 333f80a663e..fbe596ee0f7 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -9,7 +9,7 @@ /// module ts { - var version = "1.3.0.0"; + var version = "1.4.0.0"; /** * Checks to see if the locale is in the appropriate format, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3bf3e2af6c2..19baf052406 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -147,8 +147,10 @@ module ts { TypeParameter, Parameter, // TypeMember - Property, - Method, + PropertySignature, + PropertyDeclaration, + MethodSignature, + MethodDeclaration, Constructor, GetAccessor, SetAccessor, diff --git a/src/harness/test262Runner.ts b/src/harness/test262Runner.ts index 756ff82ef97..a29c6ac8619 100644 --- a/src/harness/test262Runner.ts +++ b/src/harness/test262Runner.ts @@ -21,15 +21,93 @@ class Test262BaselineRunner extends RunnerBase { return Test262BaselineRunner.basePath + "/" + filename; } + private static checkInvariants(node: ts.Node, parent: ts.Node): void { + if (node) { + if (node.pos < 0) { + throw new Error("node.pos < 0"); + } + if (node.end < 0) { + throw new Error("node.end < 0"); + } + if (node.end < node.pos) { + throw new Error("node.end < node.pos"); + } + if (node.parent !== parent) { + throw new Error("node.parent !== parent"); + } + if (parent) { + // Make sure each child is contained within the parent. + if (node.pos < parent.pos) { + throw new Error("node.pos < parent.pos"); + } + if (node.end > parent.end) { + throw new Error("node.end > parent.end"); + } + } + + ts.forEachChild(node, child => { + Test262BaselineRunner.checkInvariants(child, node); + }); + + // Make sure each of the children is in order. + var currentPos = 0; + ts.forEachChild(node, + child => { + if (child.pos < currentPos) { + throw new Error("child.pos < currentPos"); + } + currentPos = child.end; + }, + (array: ts.NodeArray) => { + if (array.pos < node.pos) { + throw new Error("array.pos < node.pos"); + } + if (array.end > node.end) { + throw new Error("array.end > node.end"); + } + + if (array.pos < currentPos) { + throw new Error("array.pos < currentPos"); + } + for (var i = 0, n = array.length; i < n; i++) { + if (array[i].pos < currentPos) { + throw new Error("array[i].pos < currentPos"); + } + currentPos = array[i].end + } + + currentPos = array.end; + }); + + var childNodesAndArrays: any[] = []; + ts.forEachChild(node, child => { childNodesAndArrays.push(child) }, array => { childNodesAndArrays.push(array) }); + + for (var childName in node) { + if (childName === "parent" || childName === "nextContainer" || childName === "modifiers" || childName === "externalModuleIndicator") { + continue; + } + var child = (node)[childName]; + if (Test262BaselineRunner.isNodeOrArray(child)) { + if (childNodesAndArrays.indexOf(child) < 0) { + throw new Error("Child when forEach'ing over node. " + (ts).SyntaxKind[node.kind] + "-" + childName); + } + } + } + } + } + private static serializeSourceFile(file: ts.SourceFile): string { function getKindName(k: number): string { return (ts).SyntaxKind[k] } function getFlagName(flags: any, f: number): any { - if (f === 0) return 0; + if (f === 0) { + return 0; + } + var result = ""; - ts.forEach(Object.getOwnPropertyNames(flags),(v: any) => { + ts.forEach(Object.getOwnPropertyNames(flags), (v: any) => { if (isFinite(v)) { v = +v; if (f === +v) { @@ -49,51 +127,85 @@ class Test262BaselineRunner extends RunnerBase { function getNodeFlagName(f: number) { return getFlagName((ts).NodeFlags, f); } function getParserContextFlagName(f: number) { return getFlagName((ts).ParserContextFlags, f); } + function convertDiagnostics(diagnostics: ts.Diagnostic[]) { + return diagnostics.map(convertDiagnostic); + } + + function convertDiagnostic(diagnostic: ts.Diagnostic): any { + return { + start: diagnostic.start, + length: diagnostic.length, + messageText: diagnostic.messageText, + category: (ts).DiagnosticCategory[diagnostic.category], + code: diagnostic.code + }; + } function serializeNode(n: ts.Node): any { - var o = { kind: getKindName(n.kind) }; - ts.forEach(Object.getOwnPropertyNames(n), i => { - switch (i) { + var o: any = { kind: getKindName(n.kind) }; + + ts.forEach(Object.getOwnPropertyNames(n), propertyName => { + switch (propertyName) { case "parent": case "symbol": case "locals": case "localSymbol": case "kind": case "semanticDiagnostics": - case "parseDiagnostics": - case "grammarDiagnostics": - return undefined; + case "id": + case "nodeCount": + case "symbolCount": + case "identifierCount": + // Blacklist of items we never put in the baseline file. + break; case "flags": - (o)[i] = getNodeFlagName(n.flags); - return undefined; + // Print out flags with their enum names. + o[propertyName] = getNodeFlagName(n.flags); + break; case "parserContextFlags": - (o)[i] = getParserContextFlagName(n.parserContextFlags); - return undefined; + o[propertyName] = getParserContextFlagName(n.parserContextFlags); + break; + + case "referenceDiagnostics": + case "parseDiagnostics": + case "grammarDiagnostics": + o[propertyName] = convertDiagnostics((n)[propertyName]); + break; case "nextContainer": if (n.nextContainer) { - (o)[i] = { kind: n.nextContainer.kind, pos: n.nextContainer.pos, end: n.nextContainer.end }; - return undefined; + o[propertyName] = { kind: n.nextContainer.kind, pos: n.nextContainer.pos, end: n.nextContainer.end }; } + break; case "text": - if (n.kind === ts.SyntaxKind.SourceFile) return undefined; + // Include 'text' field for identifiers/literals, but not for source files. + if (n.kind !== ts.SyntaxKind.SourceFile) { + o[propertyName] = (n)[propertyName]; + } + break; default: - (o)[i] = ((n)[i]); + o[propertyName] = (n)[propertyName]; } + return undefined; }); + return o; } - return JSON.stringify(file,(k, v) => { - return (v && typeof v.pos === "number") ? serializeNode(v) : v; + return JSON.stringify(file, (k, v) => { + return Test262BaselineRunner.isNodeOrArray(v) ? serializeNode(v) : v; }, " "); } + private static isNodeOrArray(a: any): boolean { + return a !== undefined && typeof a.pos === "number"; + } + private runTest(filePath: string) { describe('test262 test for ' + filePath, () => { // Mocha holds onto the closure environment of the describe callback even after the test is done. @@ -150,6 +262,11 @@ class Test262BaselineRunner extends RunnerBase { }, false, Test262BaselineRunner.baselineOptions); }); + it('satisfies invariants', () => { + var sourceFile = testState.checker.getProgram().getSourceFile(Test262BaselineRunner.getTestFilePath(testState.filename)); + Test262BaselineRunner.checkInvariants(sourceFile, /*parent:*/ undefined); + }); + it('has the expected AST',() => { Harness.Baseline.runBaseline('has the expected AST', testState.filename + '.AST.txt',() => { var sourceFile = testState.checker.getProgram().getSourceFile(Test262BaselineRunner.getTestFilePath(testState.filename)); diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index 1c87984bc27..cb5324fbd3d 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -426,6 +426,8 @@ interface StringConstructor { declare var String: StringConstructor; interface Boolean { + /** Returns the primitive value of the specified object. */ + valueOf(): boolean; } interface BooleanConstructor { diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 260fa5892aa..3a2cc2ad7e7 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -86,14 +86,16 @@ module ts.BreakpointResolver { return spanInVariableDeclaration((node).declarations[0]); case SyntaxKind.VariableDeclaration: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: return spanInVariableDeclaration(node); case SyntaxKind.Parameter: return spanInParameterDeclaration(node); case SyntaxKind.FunctionDeclaration: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.Constructor: @@ -463,7 +465,8 @@ module ts.BreakpointResolver { case SyntaxKind.FunctionExpression: case SyntaxKind.FunctionDeclaration: case SyntaxKind.ArrowFunction: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.Constructor: diff --git a/src/services/formatting.ts b/src/services/formatting.ts index 9660d9af6df..b6c2df9e9c8 100644 --- a/src/services/formatting.ts +++ b/src/services/formatting.ts @@ -911,7 +911,8 @@ module ts.formatting { case SyntaxKind.Constructor: case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.ArrowFunction: if ((node).typeParameters === list) { return SyntaxKind.LessThanToken; diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 5dc44650346..bea74e529ff 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -283,7 +283,7 @@ module ts.formatting { this.NoSpaceBeforeComma = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CommaToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); this.SpaceAfterCertainKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.VarKeyword, SyntaxKind.ThrowKeyword, SyntaxKind.NewKeyword, SyntaxKind.DeleteKeyword, SyntaxKind.ReturnKeyword, SyntaxKind.TypeOfKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - this.NoSpaceBeforeOpenParenInFuncCall = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionCallOrNewContext), RuleAction.Delete)); + this.NoSpaceBeforeOpenParenInFuncCall = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), RuleAction.Delete)); this.SpaceAfterFunctionInFuncDecl = new Rule(RuleDescriptor.create3(SyntaxKind.FunctionKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Space)); this.NoSpaceBeforeOpenParenInFuncDecl = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionDeclContext), RuleAction.Delete)); this.SpaceAfterVoidOperator = new Rule(RuleDescriptor.create3(SyntaxKind.VoidKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsVoidOpContext), RuleAction.Space)); @@ -458,7 +458,8 @@ module ts.formatting { // equal in p = 0; case SyntaxKind.Parameter: case SyntaxKind.EnumMember: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: return context.currentTokenSpan.kind === SyntaxKind.EqualsToken || context.nextTokenSpan.kind === SyntaxKind.EqualsToken; // "in" keyword in for (var x in []) { } case SyntaxKind.ForInStatement: @@ -536,7 +537,8 @@ module ts.formatting { static IsFunctionDeclContext(context: FormattingContext): boolean { switch (context.contextNode.kind) { case SyntaxKind.FunctionDeclaration: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: //case SyntaxKind.MemberFunctionDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -625,6 +627,10 @@ module ts.formatting { return Rules.IsFunctionCallContext(context) || Rules.IsNewContext(context); } + static IsPreviousTokenNotComma(context: FormattingContext): boolean { + return context.currentTokenSpan.kind !== SyntaxKind.CommaToken; + } + static IsSameLineTokenContext(context: FormattingContext): boolean { return context.TokensAreOnSameLine(); } @@ -652,7 +658,8 @@ module ts.formatting { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.CallExpression: diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 9d0484af498..29b2db72fc5 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -232,7 +232,8 @@ module ts.NavigationBar { } return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.memberVariableElement); - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.memberFunctionElement); case SyntaxKind.GetAccessor: @@ -253,7 +254,8 @@ module ts.NavigationBar { case SyntaxKind.ConstructSignature: return createItem(node, "new()", ts.ScriptElementKind.constructSignatureElement); - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.memberVariableElement); case SyntaxKind.FunctionDeclaration: diff --git a/src/services/services.ts b/src/services/services.ts index 131d6494ac4..759d2bac2c5 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -766,7 +766,8 @@ module ts { forEachChild(sourceFile, function visit(node: Node): void { switch (node.kind) { case SyntaxKind.FunctionDeclaration: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: var functionDeclaration = node; if (functionDeclaration.name && functionDeclaration.name.getFullWidth() > 0) { @@ -830,7 +831,8 @@ module ts { break; } case SyntaxKind.EnumMember: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: namedDeclarations.push(node); break; } @@ -1994,10 +1996,12 @@ module ts { function isLiteralNameOfPropertyDeclarationOrIndexAccess(node: Node): boolean { if (node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NumericLiteral) { switch (node.parent.kind) { - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.PropertyAssignment: case SyntaxKind.EnumMember: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.ModuleDeclaration: @@ -2578,7 +2582,8 @@ module ts { case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: case SyntaxKind.FunctionDeclaration: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -2609,7 +2614,7 @@ module ts { containingNodeKind === SyntaxKind.InterfaceDeclaration; // interface a { | case SyntaxKind.SemicolonToken: - return containingNodeKind === SyntaxKind.Property && + return containingNodeKind === SyntaxKind.PropertySignature && previousToken.parent.parent.kind === SyntaxKind.InterfaceDeclaration; // interface a { f; | case SyntaxKind.PublicKeyword: @@ -2739,7 +2744,8 @@ module ts { } switch (node.kind) { case SyntaxKind.SourceFile: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.GetAccessor: @@ -2854,8 +2860,12 @@ module ts { case SyntaxKind.FunctionDeclaration: return ScriptElementKind.functionElement; case SyntaxKind.GetAccessor: return ScriptElementKind.memberGetAccessorElement; case SyntaxKind.SetAccessor: return ScriptElementKind.memberSetAccessorElement; - case SyntaxKind.Method: return ScriptElementKind.memberFunctionElement; - case SyntaxKind.Property: return ScriptElementKind.memberVariableElement; + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + return ScriptElementKind.memberFunctionElement; + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + return ScriptElementKind.memberVariableElement; case SyntaxKind.IndexSignature: return ScriptElementKind.indexSignatureElement; case SyntaxKind.ConstructSignature: return ScriptElementKind.constructSignatureElement; case SyntaxKind.CallSignature: return ScriptElementKind.callSignatureElement; @@ -3265,7 +3275,7 @@ module ts { forEach(signatureDeclarations, d => { if ((selectConstructors && d.kind === SyntaxKind.Constructor) || - (!selectConstructors && (d.kind === SyntaxKind.FunctionDeclaration || d.kind === SyntaxKind.Method))) { + (!selectConstructors && (d.kind === SyntaxKind.FunctionDeclaration || d.kind === SyntaxKind.MethodDeclaration || d.kind === SyntaxKind.MethodSignature))) { declarations.push(d); if ((d).body) definition = d; } @@ -4278,8 +4288,10 @@ module ts { var staticFlag = NodeFlags.Static; switch (searchSpaceNode.kind) { - case SyntaxKind.Property: - case SyntaxKind.Method: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -4323,12 +4335,14 @@ module ts { var staticFlag = NodeFlags.Static; switch (searchSpaceNode.kind) { - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: if (isObjectLiteralMethod(searchSpaceNode)) { break; } - // fall through - case SyntaxKind.Property: + // fall through + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -4381,7 +4395,8 @@ module ts { result.push(getReferenceEntryFromNode(node)); } break; - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: if (isObjectLiteralMethod(searchSpaceNode) && searchSpaceNode.symbol === container.symbol) { result.push(getReferenceEntryFromNode(node)); } @@ -4739,11 +4754,13 @@ module ts { case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: - case SyntaxKind.Property: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.EnumMember: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: diff --git a/src/services/smartIndenter.ts b/src/services/smartIndenter.ts index e93cb5616a9..cafd92a7551 100644 --- a/src/services/smartIndenter.ts +++ b/src/services/smartIndenter.ts @@ -234,7 +234,8 @@ module ts.formatting { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: var start = node.getStart(sourceFile); @@ -358,7 +359,8 @@ module ts.formatting { case SyntaxKind.IfStatement: case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.ArrowFunction: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: @@ -414,7 +416,8 @@ module ts.formatting { return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: - case SyntaxKind.Method: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: case SyntaxKind.ArrowFunction: return !(n).body || isCompletedNode((n).body, sourceFile); case SyntaxKind.ModuleDeclaration: diff --git a/tests/baselines/reference/MemberFunctionDeclaration8_es6.errors.txt b/tests/baselines/reference/MemberFunctionDeclaration8_es6.errors.txt index 1b216b72c89..a946c17ff71 100644 --- a/tests/baselines/reference/MemberFunctionDeclaration8_es6.errors.txt +++ b/tests/baselines/reference/MemberFunctionDeclaration8_es6.errors.txt @@ -1,14 +1,11 @@ tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,12): error TS1127: Invalid character. -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,14): error TS1129: Statement expected. -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,19): error TS1005: '(' expected. -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(5,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(6,3): error TS1128: Declaration or statement expected. -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(7,1): error TS1128: Declaration or statement expected. +tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,14): error TS1109: Expression expected. tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,9): error TS2304: Cannot find name 'a'. -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,16): error TS2391: Function implementation is missing or not immediately following the declaration. +tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(4,16): error TS2304: Cannot find name 'bar'. +tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts(5,12): error TS2304: Cannot find name 'bar'. -==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts (8 errors) ==== +==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration8_es6.ts (5 errors) ==== class C { foo() { // Make sure we don't think of *bar as the start of a generator method. @@ -16,19 +13,13 @@ tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration !!! error TS1127: Invalid character. ~ -!!! error TS1129: Statement expected. - ~ -!!! error TS1005: '(' expected. +!!! error TS1109: Expression expected. ~ !!! error TS2304: Cannot find name 'a'. ~~~ -!!! error TS2391: Function implementation is missing or not immediately following the declaration. +!!! error TS2304: Cannot find name 'bar'. return bar; - ~~~~~~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~~~ +!!! error TS2304: Cannot find name 'bar'. } - ~ -!!! error TS1128: Declaration or statement expected. - } - ~ -!!! error TS1128: Declaration or statement expected. \ No newline at end of file + } \ No newline at end of file diff --git a/tests/baselines/reference/assignFromBooleanInterface2.errors.txt b/tests/baselines/reference/assignFromBooleanInterface2.errors.txt index 66d55e00d86..c03eab60c74 100644 --- a/tests/baselines/reference/assignFromBooleanInterface2.errors.txt +++ b/tests/baselines/reference/assignFromBooleanInterface2.errors.txt @@ -1,8 +1,12 @@ +tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts(14,1): error TS2322: Type 'NotBoolean' is not assignable to type 'Boolean'. + Types of property 'valueOf' are incompatible. + Type '() => Object' is not assignable to type '() => boolean'. + Type 'Object' is not assignable to type 'boolean'. tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts(19,1): error TS2322: Type 'Boolean' is not assignable to type 'boolean'. tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts(20,1): error TS2322: Type 'NotBoolean' is not assignable to type 'boolean'. -==== tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts (2 errors) ==== +==== tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts (3 errors) ==== interface Boolean { doStuff(): string; } @@ -17,6 +21,11 @@ tests/cases/conformance/types/primitives/boolean/assignFromBooleanInterface2.ts( a = x; a = b; + ~ +!!! error TS2322: Type 'NotBoolean' is not assignable to type 'Boolean'. +!!! error TS2322: Types of property 'valueOf' are incompatible. +!!! error TS2322: Type '() => Object' is not assignable to type '() => boolean'. +!!! error TS2322: Type 'Object' is not assignable to type 'boolean'. b = a; b = x; diff --git a/tests/baselines/reference/booleanAssignment.errors.txt b/tests/baselines/reference/booleanAssignment.errors.txt new file mode 100644 index 00000000000..2d6c6b045ea --- /dev/null +++ b/tests/baselines/reference/booleanAssignment.errors.txt @@ -0,0 +1,38 @@ +tests/cases/compiler/booleanAssignment.ts(2,1): error TS2322: Type 'number' is not assignable to type 'Boolean'. + Types of property 'valueOf' are incompatible. + Type '() => Object' is not assignable to type '() => boolean'. + Type 'Object' is not assignable to type 'boolean'. +tests/cases/compiler/booleanAssignment.ts(3,1): error TS2322: Type 'string' is not assignable to type 'Boolean'. + Types of property 'valueOf' are incompatible. + Type '() => Object' is not assignable to type '() => boolean'. +tests/cases/compiler/booleanAssignment.ts(4,1): error TS2322: Type '{}' is not assignable to type 'Boolean'. + Types of property 'valueOf' are incompatible. + Type '() => Object' is not assignable to type '() => boolean'. + + +==== tests/cases/compiler/booleanAssignment.ts (3 errors) ==== + var b = new Boolean(); + b = 1; // Error + ~ +!!! error TS2322: Type 'number' is not assignable to type 'Boolean'. +!!! error TS2322: Types of property 'valueOf' are incompatible. +!!! error TS2322: Type '() => Object' is not assignable to type '() => boolean'. +!!! error TS2322: Type 'Object' is not assignable to type 'boolean'. + b = "a"; // Error + ~ +!!! error TS2322: Type 'string' is not assignable to type 'Boolean'. +!!! error TS2322: Types of property 'valueOf' are incompatible. +!!! error TS2322: Type '() => Object' is not assignable to type '() => boolean'. + b = {}; // Error + ~ +!!! error TS2322: Type '{}' is not assignable to type 'Boolean'. +!!! error TS2322: Types of property 'valueOf' are incompatible. +!!! error TS2322: Type '() => Object' is not assignable to type '() => boolean'. + + var o = {}; + o = b; // OK + + b = true; // OK + + var b2:boolean; + b = b2; // OK \ No newline at end of file diff --git a/tests/baselines/reference/booleanAssignment.js b/tests/baselines/reference/booleanAssignment.js new file mode 100644 index 00000000000..573367a4293 --- /dev/null +++ b/tests/baselines/reference/booleanAssignment.js @@ -0,0 +1,24 @@ +//// [booleanAssignment.ts] +var b = new Boolean(); +b = 1; // Error +b = "a"; // Error +b = {}; // Error + +var o = {}; +o = b; // OK + +b = true; // OK + +var b2:boolean; +b = b2; // OK + +//// [booleanAssignment.js] +var b = new Boolean(); +b = 1; // Error +b = "a"; // Error +b = {}; // Error +var o = {}; +o = b; // OK +b = true; // OK +var b2; +b = b2; // OK diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt index 8d544ff1bcb..ed7843ad45e 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt @@ -3,15 +3,13 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(22,35): error TS tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(24,28): error TS1005: ':' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(24,29): error TS1005: ',' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(27,18): error TS1129: Statement expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,30): error TS1005: ',' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,33): error TS1138: Parameter declaration expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,34): error TS1005: ';' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,36): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(31,18): error TS1129: Statement expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,30): error TS1005: '=' expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(31,18): error TS1109: Expression expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(34,26): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(38,17): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(40,41): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(40,45): error TS1002: Unterminated string literal. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(46,13): error TS1005: 'try' expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(49,13): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(58,5): error TS1128: Declaration or statement expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(69,13): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(72,37): error TS1127: Invalid character. @@ -43,21 +41,19 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,27): error T tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,33): error TS1005: '(' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,43): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,60): error TS1005: ';' expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,65): error TS1129: Statement expected. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,9): error TS1129: Statement expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,65): error TS1109: Expression expected. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,16): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,35): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,55): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS1128: Declaration or statement expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(11,1): error TS2304: Cannot find name 'module'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(22,39): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(27,26): error TS2304: Cannot find name 'bfs'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(28,17): error TS2391: Function implementation is missing or not immediately following the declaration. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(34,17): error TS2304: Cannot find name 'retValue'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(34,17): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(34,28): error TS2304: Cannot find name 'bfs'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(35,21): error TS2304: Cannot find name 'retValue'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(40,17): error TS2304: Cannot find name 'retValue'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(35,21): error TS2365: Operator '!=' cannot be applied to types 'boolean' and 'number'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(40,28): error TS2304: Cannot find name 'bfs'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(41,21): error TS2304: Cannot find name 'retValue'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(41,21): error TS2365: Operator '!=' cannot be applied to types 'boolean' and 'number'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(47,17): error TS2304: Cannot find name 'console'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(53,13): error TS2304: Cannot find name 'console'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(89,23): error TS2364: Invalid left-hand side of assignment expression. @@ -82,12 +78,13 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(256,33): error T tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,16): error TS2304: Cannot find name 'Overloads'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,35): error TS2304: Cannot find name 'string'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,52): error TS2304: Cannot find name 'string'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,9): error TS2304: Cannot find name 'public'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,16): error TS2304: Cannot find name 'DefaultValue'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,29): error TS2304: Cannot find name 'value'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error TS2304: Cannot find name 'string'. -==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (87 errors) ==== +==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (84 errors) ==== declare module "fs" { export class File { constructor(filename: string); @@ -136,30 +133,24 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T !!! error TS2304: Cannot find name 'bfs'. if (retValue != 0) { ~~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1138: Parameter declaration expected. - ~ -!!! error TS1005: ';' expected. - ~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~~ -!!! error TS2391: Function implementation is missing or not immediately following the declaration. +!!! error TS1005: '=' expected. return 1; ^ ~ -!!! error TS1129: Statement expected. +!!! error TS1109: Expression expected. retValue = bfs.TYPES(); + ~ +!!! error TS1005: ';' expected. ~~~~~~~~ -!!! error TS2304: Cannot find name 'retValue'. +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. ~~~ !!! error TS2304: Cannot find name 'bfs'. if (retValue != 0) { - ~~~~~~~~ -!!! error TS2304: Cannot find name 'retValue'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types 'boolean' and 'number'. return 1 && } @@ -171,25 +162,23 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T !!! error TS1005: ';' expected. !!! error TS1002: Unterminated string literal. - ~~~~~~~~ -!!! error TS2304: Cannot find name 'retValue'. ~~~ !!! error TS2304: Cannot find name 'bfs'. if (retValue != 0) { - ~~~~~~~~ -!!! error TS2304: Cannot find name 'retValue'. + ~~~~~~~~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types 'boolean' and 'number'. return 1; } } catch (e) { - ~~~~~ -!!! error TS1005: 'try' expected. console.log(e); ~~~~~~~ !!! error TS2304: Cannot find name 'console'. } finally { + ~~~~~~~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. } @@ -501,7 +490,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T ~ !!! error TS1005: ';' expected. ~ -!!! error TS1129: Statement expected. +!!! error TS1109: Expression expected. ~~~~~~~~~ !!! error TS2304: Cannot find name 'Overloads'. ~~~~~~ @@ -510,12 +499,14 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T !!! error TS2304: Cannot find name 'string'. public DefaultValue(value?: string = "Hello") { } - ~~~~~~ -!!! error TS1129: Statement expected. + ~~~~~~~~~~~~ +!!! error TS1005: ';' expected. ~ !!! error TS1109: Expression expected. ~ !!! error TS1005: ';' expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. ~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'DefaultValue'. ~~~~~ diff --git a/tests/baselines/reference/parseIncompleteBinaryExpression1.errors.txt b/tests/baselines/reference/parseIncompleteBinaryExpression1.errors.txt new file mode 100644 index 00000000000..e0155acc3f1 --- /dev/null +++ b/tests/baselines/reference/parseIncompleteBinaryExpression1.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/parser/ecmascript5/Expressions/parseIncompleteBinaryExpression1.ts(1,9): error TS1109: Expression expected. +tests/cases/conformance/parser/ecmascript5/Expressions/parseIncompleteBinaryExpression1.ts(1,12): error TS2304: Cannot find name 'b'. + + +==== tests/cases/conformance/parser/ecmascript5/Expressions/parseIncompleteBinaryExpression1.ts (2 errors) ==== + var v = || b; + ~~ +!!! error TS1109: Expression expected. + ~ +!!! error TS2304: Cannot find name 'b'. \ No newline at end of file diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.js b/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.js new file mode 100644 index 00000000000..18a1dee3e9f --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.js @@ -0,0 +1,12 @@ +//// [parserAmbiguityWithBinaryOperator1.ts] +function f1() { + var a, b, c; + if (a < b || b > (c + 1)) { } +} + +//// [parserAmbiguityWithBinaryOperator1.js] +function f1() { + var a, b, c; + if (a < b || b > (c + 1)) { + } +} diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types new file mode 100644 index 00000000000..1a087485e26 --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator1.ts === +function f1() { +>f1 : () => void + + var a, b, c; +>a : any +>b : any +>c : any + + if (a < b || b > (c + 1)) { } +>a < b || b > (c + 1) : boolean +>a < b : boolean +>a : any +>b : any +>b > (c + 1) : boolean +>b : any +>(c + 1) : any +>c + 1 : any +>c : any +} diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.js b/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.js new file mode 100644 index 00000000000..9589d57e3af --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.js @@ -0,0 +1,12 @@ +//// [parserAmbiguityWithBinaryOperator2.ts] +function f() { + var a, b, c; + if (a < b && b > (c + 1)) { } +} + +//// [parserAmbiguityWithBinaryOperator2.js] +function f() { + var a, b, c; + if (a < b && b > (c + 1)) { + } +} diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types new file mode 100644 index 00000000000..05ac7172cff --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator2.ts === +function f() { +>f : () => void + + var a, b, c; +>a : any +>b : any +>c : any + + if (a < b && b > (c + 1)) { } +>a < b && b > (c + 1) : boolean +>a < b : boolean +>a : any +>b : any +>b > (c + 1) : boolean +>b : any +>(c + 1) : any +>c + 1 : any +>c : any +} diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.js b/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.js new file mode 100644 index 00000000000..95745263c71 --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.js @@ -0,0 +1,13 @@ +//// [parserAmbiguityWithBinaryOperator3.ts] +function f() { + var a, b, c; + if (a < b && b < (c + 1)) { } +} + + +//// [parserAmbiguityWithBinaryOperator3.js] +function f() { + var a, b, c; + if (a < b && b < (c + 1)) { + } +} diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types new file mode 100644 index 00000000000..03283115bf9 --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator3.ts === +function f() { +>f : () => void + + var a, b, c; +>a : any +>b : any +>c : any + + if (a < b && b < (c + 1)) { } +>a < b && b < (c + 1) : boolean +>a < b : boolean +>a : any +>b : any +>b < (c + 1) : boolean +>b : any +>(c + 1) : any +>c + 1 : any +>c : any +} + diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt b/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt new file mode 100644 index 00000000000..2c7bef61598 --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts(3,9): error TS2347: Untyped function calls may not accept type arguments. + + +==== tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts (1 errors) ==== + function g() { + var a, b, c; + if (a(c + 1)) { } + ~~~~~~~~~~~~~~ +!!! error TS2347: Untyped function calls may not accept type arguments. + } \ No newline at end of file diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.js b/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.js new file mode 100644 index 00000000000..cdcec030ae7 --- /dev/null +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.js @@ -0,0 +1,12 @@ +//// [parserAmbiguityWithBinaryOperator4.ts] +function g() { + var a, b, c; + if (a(c + 1)) { } +} + +//// [parserAmbiguityWithBinaryOperator4.js] +function g() { + var a, b, c; + if (a(c + 1)) { + } +} diff --git a/tests/baselines/reference/parserCommaInTypeMemberList2.errors.txt b/tests/baselines/reference/parserCommaInTypeMemberList2.errors.txt index b72f20c1a3b..fb563542961 100644 --- a/tests/baselines/reference/parserCommaInTypeMemberList2.errors.txt +++ b/tests/baselines/reference/parserCommaInTypeMemberList2.errors.txt @@ -1,14 +1,11 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,70): error TS1005: ',' expected. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,71): error TS1134: Variable declaration expected. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,53): error TS1005: ';' expected. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts(1,9): error TS2304: Cannot find name '$'. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts (3 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserCommaInTypeMemberList2.ts (2 errors) ==== var s = $.extend< { workItem: any }, { workItem: any, width: string }>({ workItem: this._workItem }, {}); - ~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1134: Variable declaration expected. + ~ +!!! error TS1005: ';' expected. ~ !!! error TS2304: Cannot find name '$'. \ No newline at end of file diff --git a/tests/baselines/reference/parserErrorRecovery_Block2.errors.txt b/tests/baselines/reference/parserErrorRecovery_Block2.errors.txt index bce96874f4c..53279be443f 100644 --- a/tests/baselines/reference/parserErrorRecovery_Block2.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_Block2.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts(2,5): error TS1129: Statement expected. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts(2,5): error TS1127: Invalid character. ==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts (1 errors) ==== function f() { - | - ~ -!!! error TS1129: Statement expected. + # + +!!! error TS1127: Invalid character. return; } \ No newline at end of file diff --git a/tests/baselines/reference/parserErrorRecovery_ClassElement3.errors.txt b/tests/baselines/reference/parserErrorRecovery_ClassElement3.errors.txt index e2856855824..63c62bcd13d 100644 --- a/tests/baselines/reference/parserErrorRecovery_ClassElement3.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_ClassElement3.errors.txt @@ -1,19 +1,22 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts(2,4): error TS1128: Declaration or statement expected. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts(5,4): error TS1128: Declaration or statement expected. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts(2,4): error TS1127: Invalid character. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts(5,4): error TS1127: Invalid character. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts(7,4): error TS1127: Invalid character. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts(7,5): error TS1005: '}' expected. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts (3 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts (4 errors) ==== module M { - | - ~ -!!! error TS1128: Declaration or statement expected. + # + +!!! error TS1127: Invalid character. class C { } - | - ~ -!!! error TS1128: Declaration or statement expected. + @ + +!!! error TS1127: Invalid character. enum E { - } + # + +!!! error TS1127: Invalid character. !!! error TS1005: '}' expected. \ No newline at end of file diff --git a/tests/baselines/reference/parserErrorRecovery_ParameterList4.errors.txt b/tests/baselines/reference/parserErrorRecovery_ParameterList4.errors.txt index d44f6eadcf2..fa97550dd19 100644 --- a/tests/baselines/reference/parserErrorRecovery_ParameterList4.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_ParameterList4.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts(1,14): error TS1138: Parameter declaration expected. +tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts(1,14): error TS1127: Invalid character. ==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts (1 errors) ==== - function f(a,|) { - ~ -!!! error TS1138: Parameter declaration expected. + function f(a,#) { + +!!! error TS1127: Invalid character. } \ No newline at end of file diff --git a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt index b15a867a79e..dc494c7c3f4 100644 --- a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt +++ b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(10,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher. -lib.d.ts(513,11): error TS2300: Duplicate identifier 'TemplateStringsArray'. +lib.d.ts(515,11): error TS2300: Duplicate identifier 'TemplateStringsArray'. tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(2,7): error TS2300: Duplicate identifier 'TemplateStringsArray'. tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(8,3): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. Property 'raw' is missing in type '{ [x: number]: undefined; }'. diff --git a/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt b/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt index 248ea95e348..db383b216a5 100644 --- a/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt +++ b/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt @@ -1,4 +1,4 @@ -lib.d.ts(513,11): error TS2300: Duplicate identifier 'TemplateStringsArray'. +lib.d.ts(515,11): error TS2300: Duplicate identifier 'TemplateStringsArray'. tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(2,7): error TS2300: Duplicate identifier 'TemplateStringsArray'. tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(8,3): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'. Property 'raw' is missing in type '{ [x: number]: undefined; }'. diff --git a/tests/cases/compiler/booleanAssignment.ts b/tests/cases/compiler/booleanAssignment.ts new file mode 100644 index 00000000000..619b16bc419 --- /dev/null +++ b/tests/cases/compiler/booleanAssignment.ts @@ -0,0 +1,12 @@ +var b = new Boolean(); +b = 1; // Error +b = "a"; // Error +b = {}; // Error + +var o = {}; +o = b; // OK + +b = true; // OK + +var b2:boolean; +b = b2; // OK \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts index a28fa48ec87..2473a9d1ffb 100644 --- a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts +++ b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/Blocks/parserErrorRecovery_Block2.ts @@ -1,4 +1,4 @@ function f() { - | + # return; } \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts index c6e2649f1b2..d4ea9d60787 100644 --- a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts +++ b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ClassElements/parserErrorRecovery_ClassElement3.ts @@ -1,7 +1,7 @@ module M { - | + # class C { } - | + @ enum E { - } \ No newline at end of file + # \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts index 62b39e7f3cc..f46e4695145 100644 --- a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts +++ b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList4.ts @@ -1,2 +1,2 @@ -function f(a,|) { +function f(a,#) { } \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/Expressions/parseIncompleteBinaryExpression1.ts b/tests/cases/conformance/parser/ecmascript5/Expressions/parseIncompleteBinaryExpression1.ts new file mode 100644 index 00000000000..f5a3bb0e701 --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript5/Expressions/parseIncompleteBinaryExpression1.ts @@ -0,0 +1 @@ +var v = || b; \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator1.ts b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator1.ts new file mode 100644 index 00000000000..d008e7f7abc --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator1.ts @@ -0,0 +1,4 @@ +function f1() { + var a, b, c; + if (a < b || b > (c + 1)) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator2.ts b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator2.ts new file mode 100644 index 00000000000..ed2fb80fef0 --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator2.ts @@ -0,0 +1,4 @@ +function f() { + var a, b, c; + if (a < b && b > (c + 1)) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator3.ts b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator3.ts new file mode 100644 index 00000000000..25bc7e0c95d --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator3.ts @@ -0,0 +1,4 @@ +function f() { + var a, b, c; + if (a < b && b < (c + 1)) { } +} diff --git a/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts new file mode 100644 index 00000000000..22fc2f8e182 --- /dev/null +++ b/tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts @@ -0,0 +1,4 @@ +function g() { + var a, b, c; + if (a(c + 1)) { } +} \ No newline at end of file diff --git a/tests/cases/fourslash/formattingSpaceAfterCommaBeforeOpenParen.ts b/tests/cases/fourslash/formattingSpaceAfterCommaBeforeOpenParen.ts new file mode 100644 index 00000000000..4df76f9e9dd --- /dev/null +++ b/tests/cases/fourslash/formattingSpaceAfterCommaBeforeOpenParen.ts @@ -0,0 +1,12 @@ +/// + +////foo(a,(b))/*1*/ +////foo(a,(c).d)/*2*/ + +goTo.marker("1"); +edit.insert(";"); +verify.currentLineContentIs("foo(a, (b));"); + +goTo.marker("2"); +edit.insert(";"); +verify.currentLineContentIs("foo(a, (c).d);"); \ No newline at end of file