diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1e8a87bc4d4..7bc8a28a795 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -695,7 +695,7 @@ module ts { var members = node.members; for (var i = 0; i < members.length; i++) { var member = members[i]; - if (member.kind === SyntaxKind.Constructor && (member).body) { + if (member.kind === SyntaxKind.Constructor && !isMissingNode((member).body)) { return member; } } @@ -2654,7 +2654,7 @@ module ts { returnType = getAnnotatedAccessorType(setter); } - if (!returnType && !(declaration).body) { + if (!returnType && isMissingNode((declaration).body)) { returnType = anyType; } } @@ -6372,7 +6372,7 @@ module ts { } // If all we have is a function signature, or an arrow function with an expression body, then there is nothing to check. - if (!func.body || func.body.kind !== SyntaxKind.Block) { + if (isMissingNode(func.body) || func.body.kind !== SyntaxKind.Block) { return; } @@ -7030,7 +7030,7 @@ module ts { var func = getContainingFunction(node); if (node.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected)) { func = getContainingFunction(node); - if (!(func.kind === SyntaxKind.Constructor && func.body)) { + if (!(func.kind === SyntaxKind.Constructor && !isMissingNode(func.body))) { error(node, Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } } @@ -7127,7 +7127,7 @@ module ts { } // exit early in the case of signature - super checks are not relevant to them - if (!node.body) { + if (isMissingNode(node.body)) { return; } @@ -7201,7 +7201,7 @@ module ts { function checkAccessorDeclaration(node: AccessorDeclaration) { if (fullTypeCheck) { if (node.kind === SyntaxKind.GetAccessor) { - if (!isInAmbientContext(node) && node.body && !(bodyContainsAReturnStatement(node.body) || bodyContainsSingleThrowStatement(node.body))) { + if (!isInAmbientContext(node) && !isMissingNode(node.body) && !(bodyContainsAReturnStatement(node.body) || bodyContainsSingleThrowStatement(node.body))) { error(node.name, Diagnostics.A_get_accessor_must_return_a_value_or_consist_of_a_single_throw_statement); } } @@ -7290,7 +7290,7 @@ module ts { // TypeScript 1.0 spec (April 2014): 3.7.2.2 // Specialized signatures are not permitted in conjunction with a function body - if ((signatureDeclarationNode).body) { + if (!isMissingNode((signatureDeclarationNode).body)) { error(signatureDeclarationNode, Diagnostics.A_signature_with_an_implementation_cannot_use_a_string_literal_type); return; } @@ -7423,7 +7423,7 @@ module ts { error(errorNode, diagnostic); return; } - else if ((subsequentNode).body) { + else if (!isMissingNode((subsequentNode).body)) { error(errorNode, Diagnostics.Function_implementation_name_must_be_0, declarationNameToString(node.name)); return; } @@ -7465,7 +7465,7 @@ module ts { someHaveQuestionToken = someHaveQuestionToken || hasQuestionToken(node); allHaveQuestionToken = allHaveQuestionToken && hasQuestionToken(node); - if (node.body && bodyDeclaration) { + if (!isMissingNode(node.body) && bodyDeclaration) { if (isConstructor) { multipleConstructorImplementation = true; } @@ -7477,7 +7477,7 @@ module ts { reportImplementationExpectedError(previousDeclaration); } - if (node.body) { + if (!isMissingNode(node.body)) { if (!bodyDeclaration) { bodyDeclaration = node; } @@ -7660,7 +7660,7 @@ module ts { // Report an implicit any error if there is no body, no explicit return type, and node is not a private method // in an ambient context - if (compilerOptions.noImplicitAny && !node.body && !node.type && !isPrivateWithinAmbient(node)) { + if (compilerOptions.noImplicitAny && isMissingNode(node.body) && !node.type && !isPrivateWithinAmbient(node)) { reportImplicitAnyError(node, anyType); } } @@ -7674,7 +7674,7 @@ module ts { function checkCollisionWithArgumentsInGeneratedCode(node: SignatureDeclaration) { // no rest parameters \ declaration context \ overload - no codegen impact - if (!hasRestParameters(node) || isInAmbientContext(node) || !(node).body) { + if (!hasRestParameters(node) || isInAmbientContext(node) || isMissingNode((node).body)) { return; } @@ -7706,7 +7706,7 @@ module ts { } var root = getRootDeclaration(node); - if (root.kind === SyntaxKind.Parameter && !(root.parent).body) { + if (root.kind === SyntaxKind.Parameter && isMissingNode((root.parent).body)) { // just an overload - no codegen impact return false; } @@ -7866,7 +7866,7 @@ module ts { forEach((node.name).elements, checkSourceElement); } // For a parameter declaration with an initializer, error and exit if the containing function doesn't have a body - if (node.initializer && getRootDeclaration(node).kind === SyntaxKind.Parameter && !getContainingFunction(node).body) { + if (node.initializer && getRootDeclaration(node).kind === SyntaxKind.Parameter && isMissingNode(getContainingFunction(node).body)) { error(node, Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation); return; } @@ -8612,7 +8612,7 @@ module ts { var declarations = symbol.declarations; for (var i = 0; i < declarations.length; i++) { var declaration = declarations[i]; - if ((declaration.kind === SyntaxKind.ClassDeclaration || (declaration.kind === SyntaxKind.FunctionDeclaration && (declaration).body)) && !isInAmbientContext(declaration)) { + if ((declaration.kind === SyntaxKind.ClassDeclaration || (declaration.kind === SyntaxKind.FunctionDeclaration && !isMissingNode((declaration).body))) && !isInAmbientContext(declaration)) { return declaration; } } @@ -9499,7 +9499,7 @@ module ts { } function isImplementationOfOverload(node: FunctionLikeDeclaration) { - if (node.body) { + if (!isMissingNode(node.body)) { var symbol = getSymbolOfNode(node); var signaturesOfSymbol = getSignaturesOfSymbol(symbol); // If this function body corresponds to function with multiple signature, it is implementation of overload diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9428f94bb52..24890799706 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -268,7 +268,7 @@ module ts { function getFirstConstructorWithBody(node: ClassDeclaration): ConstructorDeclaration { return forEach(node.members, member => { - if (member.kind === SyntaxKind.Constructor && (member).body) { + if (member.kind === SyntaxKind.Constructor && !isMissingNode((member).body)) { return member; } }); @@ -3106,7 +3106,7 @@ module ts { } function emitFunctionDeclaration(node: FunctionLikeDeclaration) { - if (!node.body) { + if (isMissingNode(node.body)) { return emitPinnedOrTripleSlashComments(node); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index bd408ad24ef..5729e29c0e5 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -61,6 +61,10 @@ module ts { } export function isMissingNode(node: Node) { + if (node === undefined) { + return true; + } + return node.pos === node.end && node.kind !== SyntaxKind.EndOfFileToken; } @@ -1377,7 +1381,7 @@ module ts { return inStrictModeContext() ? token > SyntaxKind.LastFutureReservedWord : token > SyntaxKind.LastReservedWord; } - function parseExpected(kind: SyntaxKind, diagnosticMessage?: DiagnosticMessage, arg0?: any): boolean { + function parseExpected(kind: SyntaxKind, diagnosticMessage?: DiagnosticMessage): boolean { if (token === kind) { nextToken(); return true; @@ -1385,7 +1389,7 @@ module ts { // Report specific message if provided with one. Otherwise, report generic fallback message. if (diagnosticMessage) { - parseErrorAtCurrentToken(diagnosticMessage, arg0); + parseErrorAtCurrentToken(diagnosticMessage); } else { parseErrorAtCurrentToken(Diagnostics._0_expected, tokenToString(kind)); @@ -1420,7 +1424,7 @@ module ts { return token === SyntaxKind.CloseBraceToken || token === SyntaxKind.EndOfFileToken || scanner.hasPrecedingLineBreak(); } - function parseSemicolon(diagnosticMessage?: DiagnosticMessage): boolean { + function parseSemicolon(): boolean { if (canParseSemicolon()) { if (token === SyntaxKind.SemicolonToken) { // consume the semicolon if it was explicitly provided. @@ -1430,7 +1434,7 @@ module ts { return true; } else { - return parseExpected(SyntaxKind.SemicolonToken, diagnosticMessage); + return parseExpected(SyntaxKind.SemicolonToken); } } @@ -3438,21 +3442,22 @@ module ts { var fullStart = scanner.getStartPos(); var initialToken = token; + var modifiers = parseModifiers(); if (parseContextualModifier(SyntaxKind.GetKeyword) || parseContextualModifier(SyntaxKind.SetKeyword)) { var kind = initialToken === SyntaxKind.GetKeyword ? SyntaxKind.GetAccessor : SyntaxKind.SetAccessor; - return parseAccessorDeclaration(kind, fullStart, /*modifiers*/undefined); + return parseAccessorDeclaration(kind, fullStart, modifiers); } var asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); var tokenIsIdentifier = isIdentifier(); var nameToken = token; var propertyName = parsePropertyName(); - if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { - return parseMethodDeclaration(fullStart, /*modifiers:*/ undefined, asteriskToken, propertyName, /*questionToken:*/ undefined, /*requireBlock:*/ true); - } // Disallowing of optional property assignments happens in the grammar checker. var questionToken = parseOptionalToken(SyntaxKind.QuestionToken); + if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { + return parseMethodDeclaration(fullStart, modifiers, asteriskToken, propertyName, questionToken); + } // Parse to check if it is short-hand property assignment or normal property assignment if ((token === SyntaxKind.CommaToken || token === SyntaxKind.CloseBraceToken) && tokenIsIdentifier) { @@ -3514,9 +3519,9 @@ module ts { } // STATEMENTS - function parseBlock(kind: SyntaxKind, ignoreMissingOpenBrace: boolean, checkForStrictMode: boolean): Block { + function parseBlock(kind: SyntaxKind, ignoreMissingOpenBrace: boolean, checkForStrictMode: boolean, diagnosticMessage?: DiagnosticMessage): Block { var node = createNode(kind); - if (parseExpected(SyntaxKind.OpenBraceToken) || ignoreMissingOpenBrace) { + if (parseExpected(SyntaxKind.OpenBraceToken, diagnosticMessage) || ignoreMissingOpenBrace) { node.statements = parseList(ParsingContext.BlockStatements, checkForStrictMode, parseStatement); parseExpected(SyntaxKind.CloseBraceToken); } @@ -3526,11 +3531,11 @@ module ts { return finishNode(node); } - function parseFunctionBlock(allowYield: boolean, ignoreMissingOpenBrace: boolean): Block { + function parseFunctionBlock(allowYield: boolean, ignoreMissingOpenBrace: boolean, diagnosticMessage?: DiagnosticMessage): Block { var savedYieldContext = inYieldContext(); setYieldContext(allowYield); - var block = parseBlock(SyntaxKind.Block, ignoreMissingOpenBrace, /*checkForStrictMode*/ true); + var block = parseBlock(SyntaxKind.Block, ignoreMissingOpenBrace, /*checkForStrictMode*/ true, diagnosticMessage); setYieldContext(savedYieldContext); @@ -3949,13 +3954,13 @@ module ts { return undefined; } - function parseFunctionBlockOrSemicolon(isGenerator: boolean): Block { - if (token === SyntaxKind.OpenBraceToken) { - return parseFunctionBlock(isGenerator, /*ignoreMissingOpenBrace:*/ false); + function parseFunctionBlockOrSemicolon(isGenerator: boolean, diagnosticMessage?: DiagnosticMessage): Block { + if (token !== SyntaxKind.OpenBraceToken && canParseSemicolon()) { + parseSemicolon(); + return; } - parseSemicolon(Diagnostics.or_expected); - return undefined; + return parseFunctionBlock(isGenerator, /*ignoreMissingOpenBrace:*/ false, diagnosticMessage); } // DECLARATIONS @@ -4070,7 +4075,7 @@ module ts { node.asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); node.name = parseIdentifier(); fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ !!node.asteriskToken, /*requireCompleteParameterList:*/ false, node); - node.body = parseFunctionBlockOrSemicolon(!!node.asteriskToken); + node.body = parseFunctionBlockOrSemicolon(!!node.asteriskToken, Diagnostics.or_expected); return finishNode(node); } @@ -4079,18 +4084,18 @@ module ts { setModifiers(node, modifiers); parseExpected(SyntaxKind.ConstructorKeyword); fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ false, node); - node.body = parseFunctionBlockOrSemicolon(/*isGenerator:*/ false); + node.body = parseFunctionBlockOrSemicolon(/*isGenerator:*/ false, Diagnostics.or_expected); return finishNode(node); } - function parseMethodDeclaration(fullStart: number, modifiers: ModifiersArray, asteriskToken: Node, name: DeclarationName, questionToken: Node, requireBlock: boolean): MethodDeclaration { + function parseMethodDeclaration(fullStart: number, modifiers: ModifiersArray, asteriskToken: Node, name: DeclarationName, questionToken: Node, diagnosticMessage?: DiagnosticMessage): MethodDeclaration { var method = createNode(SyntaxKind.MethodDeclaration, fullStart); setModifiers(method, modifiers); method.asteriskToken = asteriskToken; method.name = name; method.questionToken = questionToken; fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ !!asteriskToken, /*requireCompleteParameterList:*/ false, method); - method.body = requireBlock ? parseFunctionBlock(!!asteriskToken, /*ignoreMissingOpenBrace:*/ false) : parseFunctionBlockOrSemicolon(!!asteriskToken); + method.body = parseFunctionBlockOrSemicolon(!!asteriskToken, diagnosticMessage); return finishNode(method); } @@ -4102,7 +4107,7 @@ module ts { // report an error in the grammar checker. var questionToken = parseOptionalToken(SyntaxKind.QuestionToken); if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { - return parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, /*requireBlock:*/ false); + return parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, Diagnostics.or_expected); } else { var property = createNode(SyntaxKind.PropertyDeclaration, fullStart); @@ -4681,6 +4686,7 @@ module ts { // We're automatically in an ambient context if this is a .d.ts file. var inAmbientContext = fileExtensionIs(file.filename, ".d.ts"); var inFunctionBlock = false; + var inObjectLiteralExpression = false; var inBlock = false; var parent: Node; visitNode(file); @@ -4700,7 +4706,10 @@ module ts { if (node.kind === SyntaxKind.Block || node.kind === SyntaxKind.TryBlock || node.kind === SyntaxKind.FinallyBlock) { inBlock = true; } - + var savedInObjectLiteralExpression = inObjectLiteralExpression; + if (node.kind === SyntaxKind.ObjectLiteralExpression) { + inObjectLiteralExpression = true; + } var savedInAmbientContext = inAmbientContext if (node.flags & NodeFlags.Ambient) { inAmbientContext = true; @@ -4711,6 +4720,7 @@ module ts { inAmbientContext = savedInAmbientContext; inFunctionBlock = savedInFunctionBlock; inBlock = savedInBlock; + inObjectLiteralExpression = savedInObjectLiteralExpression; } parent = savedParent; @@ -5172,7 +5182,7 @@ module ts { } function checkFunctionDeclaration(node: FunctionLikeDeclaration) { - return checkForDisallowedModifiersInBlock(node) || + return checkForDisallowedModifiersInBlockOrObjectLiteral(node) || checkAnySignatureDeclaration(node) || checkFunctionName(node.name) || checkForBodyInAmbientContext(node.body, /*isConstructor:*/ false) || @@ -5200,7 +5210,8 @@ module ts { } function checkGetAccessor(node: MethodDeclaration) { - return checkAnySignatureDeclaration(node) || + return checkForDisallowedModifiersInBlockOrObjectLiteral(node) || + checkAnySignatureDeclaration(node) || checkAccessor(node); } @@ -5298,12 +5309,22 @@ module ts { } function checkMethod(node: MethodDeclaration) { - if (checkAnySignatureDeclaration(node) || + if (checkForDisallowedModifiersInBlockOrObjectLiteral(node) || + checkAnySignatureDeclaration(node) || checkForBodyInAmbientContext(node.body, /*isConstructor:*/ false) || checkForGenerator(node)) { return true; } + if (node.parent.kind === SyntaxKind.ObjectLiteralExpression) { + if (checkForInvalidQuestionMark(node, node.questionToken, Diagnostics.A_class_member_cannot_be_declared_optional)) { + return true; + } + else if (node.body === undefined) { + return grammarErrorAtPos(node.end - 1, ";".length, Diagnostics._0_expected, "{"); + } + } + if (node.parent.kind === SyntaxKind.ClassDeclaration) { if (checkForInvalidQuestionMark(node, node.questionToken, Diagnostics.A_class_member_cannot_be_declared_optional)) { return true; @@ -5316,7 +5337,7 @@ module ts { if (inAmbientContext) { return checkForDisallowedComputedProperty(node.name, Diagnostics.Computed_property_names_are_not_allowed_in_an_ambient_context); } - else if (!node.body) { + else if (isMissingNode(node.body)) { return checkForDisallowedComputedProperty(node.name, Diagnostics.Computed_property_names_are_not_allowed_in_method_overloads); } } @@ -5711,7 +5732,8 @@ module ts { } function checkSetAccessor(node: MethodDeclaration) { - return checkAnySignatureDeclaration(node) || + return checkForDisallowedModifiersInBlockOrObjectLiteral(node) || + checkAnySignatureDeclaration(node) || checkAccessor(node); } @@ -5908,14 +5930,16 @@ module ts { } function checkVariableStatement(node: VariableStatement) { - return checkForDisallowedModifiersInBlock(node) || + return checkForDisallowedModifiersInBlockOrObjectLiteral(node) || checkVariableDeclarations(node.declarations) || checkForDisallowedLetOrConstStatement(node); } - function checkForDisallowedModifiersInBlock(node: Node) { - if (inBlock && node.modifiers) { - return grammarErrorOnFirstToken(node, Diagnostics.Modifiers_cannot_appear_here); + function checkForDisallowedModifiersInBlockOrObjectLiteral(node: Node) { + if (node.modifiers) { + if (inBlock || inObjectLiteralExpression) { + return grammarErrorOnFirstToken(node, Diagnostics.Modifiers_cannot_appear_here); + } } } diff --git a/tests/baselines/reference/FunctionDeclaration5_es6.errors.txt b/tests/baselines/reference/FunctionDeclaration5_es6.errors.txt index 9a8be921795..490f3bd9f22 100644 --- a/tests/baselines/reference/FunctionDeclaration5_es6.errors.txt +++ b/tests/baselines/reference/FunctionDeclaration5_es6.errors.txt @@ -1,17 +1,14 @@ tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration5_es6.ts(1,14): error TS1138: Parameter declaration expected. tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration5_es6.ts(1,19): error TS1005: ';' expected. -tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration5_es6.ts(1,10): error TS2391: Function implementation is missing or not immediately following the declaration. tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration5_es6.ts(1,14): error TS2304: Cannot find name 'yield'. -==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration5_es6.ts (4 errors) ==== +==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration5_es6.ts (3 errors) ==== function*foo(yield) { ~~~~~ !!! error TS1138: Parameter declaration expected. ~ !!! error TS1005: ';' expected. - ~~~ -!!! error TS2391: Function implementation is missing or not immediately following the declaration. ~~~~~ !!! error TS2304: Cannot find name 'yield'. } \ No newline at end of file diff --git a/tests/baselines/reference/callSignaturesWithParameterInitializers2.errors.txt b/tests/baselines/reference/callSignaturesWithParameterInitializers2.errors.txt index 1801bd42e4d..c307f8ad5cf 100644 --- a/tests/baselines/reference/callSignaturesWithParameterInitializers2.errors.txt +++ b/tests/baselines/reference/callSignaturesWithParameterInitializers2.errors.txt @@ -2,10 +2,11 @@ tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignaturesWit tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignaturesWithParameterInitializers2.ts(4,14): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignaturesWithParameterInitializers2.ts(11,9): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignaturesWithParameterInitializers2.ts(20,5): error TS2300: Duplicate identifier 'foo'. +tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignaturesWithParameterInitializers2.ts(20,9): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignaturesWithParameterInitializers2.ts(21,5): error TS2300: Duplicate identifier 'foo'. -==== tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignaturesWithParameterInitializers2.ts (5 errors) ==== +==== tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignaturesWithParameterInitializers2.ts (6 errors) ==== // Optional parameters allow initializers only in implementation signatures // All the below declarations are errors @@ -34,6 +35,8 @@ tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignaturesWit !!! error TS1005: '{' expected. ~~~ !!! error TS2300: Duplicate identifier 'foo'. + ~~~~~ +!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. foo(x = 1) { }, // error ~~~ !!! error TS2300: Duplicate identifier 'foo'. diff --git a/tests/baselines/reference/dottedModuleName.errors.txt b/tests/baselines/reference/dottedModuleName.errors.txt index 9d9de6ee230..afb8b944355 100644 --- a/tests/baselines/reference/dottedModuleName.errors.txt +++ b/tests/baselines/reference/dottedModuleName.errors.txt @@ -1,16 +1,13 @@ tests/cases/compiler/dottedModuleName.ts(3,29): error TS1144: '{' or ';' expected. -tests/cases/compiler/dottedModuleName.ts(3,18): error TS2391: Function implementation is missing or not immediately following the declaration. tests/cases/compiler/dottedModuleName.ts(3,33): error TS2304: Cannot find name 'x'. -==== tests/cases/compiler/dottedModuleName.ts (3 errors) ==== +==== tests/cases/compiler/dottedModuleName.ts (2 errors) ==== module M { export module N { export function f(x:number)=>2*x; ~~ !!! error TS1144: '{' or ';' expected. - ~ -!!! error TS2391: Function implementation is missing or not immediately following the declaration. ~ !!! error TS2304: Cannot find name 'x'. export module X.Y.Z { diff --git a/tests/baselines/reference/modifiersOnInterfaceIndexSignature1.errors.txt b/tests/baselines/reference/modifiersOnInterfaceIndexSignature1.errors.txt new file mode 100644 index 00000000000..b325710a9f0 --- /dev/null +++ b/tests/baselines/reference/modifiersOnInterfaceIndexSignature1.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/modifiersOnInterfaceIndexSignature1.ts(2,3): error TS1145: Modifiers not permitted on index signature members. + + +==== tests/cases/compiler/modifiersOnInterfaceIndexSignature1.ts (1 errors) ==== + interface I { + public [a: string]: number; + ~~~~~~ +!!! error TS1145: Modifiers not permitted on index signature members. + } \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralMemberWithModifiers1.errors.txt b/tests/baselines/reference/objectLiteralMemberWithModifiers1.errors.txt new file mode 100644 index 00000000000..9e739194f54 --- /dev/null +++ b/tests/baselines/reference/objectLiteralMemberWithModifiers1.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/objectLiteralMemberWithModifiers1.ts(1,11): error TS1184: Modifiers cannot appear here. + + +==== tests/cases/compiler/objectLiteralMemberWithModifiers1.ts (1 errors) ==== + var v = { public foo() { } } + ~~~~~~ +!!! error TS1184: Modifiers cannot appear here. \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralMemberWithModifiers2.errors.txt b/tests/baselines/reference/objectLiteralMemberWithModifiers2.errors.txt new file mode 100644 index 00000000000..9b34ea61733 --- /dev/null +++ b/tests/baselines/reference/objectLiteralMemberWithModifiers2.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/objectLiteralMemberWithModifiers2.ts(1,11): error TS1184: Modifiers cannot appear here. + + +==== tests/cases/compiler/objectLiteralMemberWithModifiers2.ts (1 errors) ==== + var v = { public get foo() { } } + ~~~~~~ +!!! error TS1184: Modifiers cannot appear here. \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralMemberWithQuestionMark1.errors.txt b/tests/baselines/reference/objectLiteralMemberWithQuestionMark1.errors.txt new file mode 100644 index 00000000000..b10ba701143 --- /dev/null +++ b/tests/baselines/reference/objectLiteralMemberWithQuestionMark1.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/objectLiteralMemberWithQuestionMark1.ts(1,14): error TS1112: A class member cannot be declared optional. + + +==== tests/cases/compiler/objectLiteralMemberWithQuestionMark1.ts (1 errors) ==== + var v = { foo?() { } } + ~ +!!! error TS1112: A class member cannot be declared optional. \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralMemberWithoutBlock1.errors.txt b/tests/baselines/reference/objectLiteralMemberWithoutBlock1.errors.txt new file mode 100644 index 00000000000..fa5fb104c82 --- /dev/null +++ b/tests/baselines/reference/objectLiteralMemberWithoutBlock1.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/objectLiteralMemberWithoutBlock1.ts(1,16): error TS1005: '{' expected. + + +==== tests/cases/compiler/objectLiteralMemberWithoutBlock1.ts (1 errors) ==== + var v = { foo(); } + ~ +!!! error TS1005: '{' expected. \ No newline at end of file diff --git a/tests/baselines/reference/objectTypesWithOptionalProperties2.errors.txt b/tests/baselines/reference/objectTypesWithOptionalProperties2.errors.txt index 533834baea7..761fba18b15 100644 --- a/tests/baselines/reference/objectTypesWithOptionalProperties2.errors.txt +++ b/tests/baselines/reference/objectTypesWithOptionalProperties2.errors.txt @@ -11,11 +11,9 @@ tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWith tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties2.ts(25,8): error TS1005: '{' expected. tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties2.ts(25,9): error TS1136: Property assignment expected. tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties2.ts(26,1): error TS1005: ':' expected. -tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties2.ts(12,5): error TS2391: Function implementation is missing or not immediately following the declaration. -tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties2.ts(20,5): error TS2391: Function implementation is missing or not immediately following the declaration. -==== tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties2.ts (15 errors) ==== +==== tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties2.ts (13 errors) ==== // Illegal attempts to define optional methods var a: { @@ -40,8 +38,6 @@ tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWith !!! error TS1144: '{' or ';' 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. } interface I2 { @@ -58,8 +54,6 @@ tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWith !!! error TS1144: '{' or ';' 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. } diff --git a/tests/baselines/reference/parserAccessors10.errors.txt b/tests/baselines/reference/parserAccessors10.errors.txt index dcd819c4880..3c4981ddc45 100644 --- a/tests/baselines/reference/parserAccessors10.errors.txt +++ b/tests/baselines/reference/parserAccessors10.errors.txt @@ -1,15 +1,9 @@ -tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors10.ts(2,10): error TS1005: ':' expected. -tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors10.ts(2,14): error TS1005: ',' expected. -tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors10.ts(2,10): error TS2304: Cannot find name 'get'. +tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors10.ts(2,3): error TS1184: Modifiers cannot appear here. -==== tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors10.ts (3 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors10.ts (1 errors) ==== var v = { public get foo() { } - ~~~ -!!! error TS1005: ':' expected. - ~~~ -!!! error TS1005: ',' expected. - ~~~ -!!! error TS2304: Cannot find name 'get'. + ~~~~~~ +!!! error TS1184: Modifiers cannot appear here. }; \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName5.errors.txt b/tests/baselines/reference/parserComputedPropertyName5.errors.txt index 149550c93ff..756a133111b 100644 --- a/tests/baselines/reference/parserComputedPropertyName5.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName5.errors.txt @@ -1,19 +1,7 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName5.ts(1,18): error TS1005: ':' expected. -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName5.ts(1,28): error TS1005: ',' expected. -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName5.ts(1,32): error TS1128: Declaration or statement expected. -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName5.ts(1,18): error TS2304: Cannot find name 'get'. -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName5.ts(1,23): error TS2304: Cannot find name 'e'. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName5.ts(1,11): error TS1184: Modifiers cannot appear here. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName5.ts (5 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName5.ts (1 errors) ==== var v = { public get [e]() { } }; - ~~~ -!!! error TS1005: ':' expected. - ~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1128: Declaration or statement expected. - ~~~ -!!! error TS2304: Cannot find name 'get'. - ~ -!!! error TS2304: Cannot find name 'e'. \ No newline at end of file + ~~~~~~ +!!! error TS1184: Modifiers cannot appear here. \ No newline at end of file diff --git a/tests/baselines/reference/parserErrantEqualsGreaterThanAfterFunction1.errors.txt b/tests/baselines/reference/parserErrantEqualsGreaterThanAfterFunction1.errors.txt index 7c32d4433e4..4f4c37c78be 100644 --- a/tests/baselines/reference/parserErrantEqualsGreaterThanAfterFunction1.errors.txt +++ b/tests/baselines/reference/parserErrantEqualsGreaterThanAfterFunction1.errors.txt @@ -1,10 +1,7 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreaterThanAfterFunction1.ts(1,14): error TS1144: '{' or ';' expected. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreaterThanAfterFunction1.ts(1,10): error TS2391: Function implementation is missing or not immediately following the declaration. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreaterThanAfterFunction1.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreaterThanAfterFunction1.ts (1 errors) ==== function f() => 4; ~~ -!!! error TS1144: '{' or ';' expected. - ~ -!!! error TS2391: Function implementation is missing or not immediately following the declaration. \ No newline at end of file +!!! error TS1144: '{' or ';' expected. \ No newline at end of file diff --git a/tests/baselines/reference/parserErrantEqualsGreaterThanAfterFunction2.errors.txt b/tests/baselines/reference/parserErrantEqualsGreaterThanAfterFunction2.errors.txt index 8df3b0bbff6..74f538a0e07 100644 --- a/tests/baselines/reference/parserErrantEqualsGreaterThanAfterFunction2.errors.txt +++ b/tests/baselines/reference/parserErrantEqualsGreaterThanAfterFunction2.errors.txt @@ -1,15 +1,12 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreaterThanAfterFunction2.ts(1,18): error TS1144: '{' or ';' expected. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreaterThanAfterFunction2.ts(1,10): error TS2391: Function implementation is missing or not immediately following the declaration. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreaterThanAfterFunction2.ts(1,15): error TS2304: Cannot find name 'A'. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreaterThanAfterFunction2.ts(1,21): error TS2304: Cannot find name 'p'. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreaterThanAfterFunction2.ts (4 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserErrantEqualsGreaterThanAfterFunction2.ts (3 errors) ==== function f(p: A) => p; ~~ !!! error TS1144: '{' or ';' expected. - ~ -!!! error TS2391: Function implementation is missing or not immediately following the declaration. ~ !!! error TS2304: Cannot find name 'A'. ~ diff --git a/tests/baselines/reference/parserErrorRecovery_ParameterList6.errors.txt b/tests/baselines/reference/parserErrorRecovery_ParameterList6.errors.txt index f6920f4f6a6..61ad2fb175f 100644 --- a/tests/baselines/reference/parserErrorRecovery_ParameterList6.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_ParameterList6.errors.txt @@ -1,18 +1,15 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList6.ts(2,23): error TS1110: Type expected. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList6.ts(2,28): error TS1003: Identifier expected. tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList6.ts(3,1): error TS1128: Declaration or statement expected. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList6.ts(2,12): error TS2391: Function implementation is missing or not immediately following the declaration. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList6.ts (4 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList6.ts (3 errors) ==== class Foo { public banana (x: break) { } ~~~~~ !!! error TS1110: Type expected. ~ !!! error TS1003: Identifier expected. - ~~~~~~ -!!! error TS2391: Function implementation is missing or not immediately following the declaration. } ~ !!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/parserSkippedTokens16.errors.txt b/tests/baselines/reference/parserSkippedTokens16.errors.txt index 0d1effe23c3..5d505b90112 100644 --- a/tests/baselines/reference/parserSkippedTokens16.errors.txt +++ b/tests/baselines/reference/parserSkippedTokens16.errors.txt @@ -6,10 +6,9 @@ tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens16.t tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens16.ts(8,14): error TS1109: Expression expected. tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens16.ts(1,1): error TS2304: Cannot find name 'foo'. tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens16.ts(1,8): error TS2304: Cannot find name 'Bar'. -tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens16.ts(2,10): error TS2391: Function implementation is missing or not immediately following the declaration. -==== tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens16.ts (9 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens16.ts (8 errors) ==== foo(): Bar { } ~ !!! error TS1005: ';' expected. @@ -22,8 +21,6 @@ tests/cases/conformance/parser/ecmascript5/SkippedTokens/parserSkippedTokens16.t function Foo () # { } !!! error TS1127: Invalid character. - ~~~ -!!! error TS2391: Function implementation is missing or not immediately following the declaration. 4+:5 ~ !!! error TS1109: Expression expected. diff --git a/tests/baselines/reference/privateIndexer2.errors.txt b/tests/baselines/reference/privateIndexer2.errors.txt index cff05a92965..8d3c1ec1e6d 100644 --- a/tests/baselines/reference/privateIndexer2.errors.txt +++ b/tests/baselines/reference/privateIndexer2.errors.txt @@ -1,54 +1,27 @@ -tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(4,13): error TS1005: ':' expected. -tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(4,15): error TS1005: ',' expected. -tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(4,24): error TS1005: ',' expected. +tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(4,15): error TS1005: ']' expected. +tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(4,23): error TS1005: ',' expected. +tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(4,24): error TS1136: Property assignment expected. tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(4,32): error TS1005: ':' expected. tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(5,1): error TS1128: Declaration or statement expected. -tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(8,5): error TS1131: Property or signature expected. -tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(8,14): error TS1005: ']' expected. -tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(8,22): error TS1005: ';' expected. -tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(8,23): error TS1128: Declaration or statement expected. -tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(9,1): error TS1128: Declaration or statement expected. -tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(4,17): error TS2304: Cannot find name 'string'. -tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(8,5): error TS2304: Cannot find name 'private'. -tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(8,16): error TS2304: Cannot find name 'string'. -tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts(8,25): error TS2304: Cannot find name 'string'. -==== tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts (14 errors) ==== +==== tests/cases/conformance/classes/indexMemberDeclarations/privateIndexer2.ts (5 errors) ==== // private indexers not allowed var x = { private [x: string]: string; - ~ -!!! error TS1005: ':' expected. ~ +!!! error TS1005: ']' expected. + ~ !!! error TS1005: ',' expected. ~ -!!! error TS1005: ',' expected. +!!! error TS1136: Property assignment expected. ~ !!! error TS1005: ':' expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'string'. } ~ !!! error TS1128: Declaration or statement expected. var y: { private[x: string]: string; - ~~~~~~~ -!!! error TS1131: Property or signature expected. - ~ -!!! error TS1005: ']' expected. - ~ -!!! error TS1005: ';' expected. - ~ -!!! error TS1128: Declaration or statement expected. - ~~~~~~~ -!!! error TS2304: Cannot find name 'private'. - ~~~~~~ -!!! error TS2304: Cannot find name 'string'. - ~~~~~~ -!!! error TS2304: Cannot find name 'string'. - } - ~ -!!! error TS1128: Declaration or statement expected. \ No newline at end of file + } \ No newline at end of file diff --git a/tests/cases/compiler/modifiersOnInterfaceIndexSignature1.ts b/tests/cases/compiler/modifiersOnInterfaceIndexSignature1.ts new file mode 100644 index 00000000000..ba5eebbefc9 --- /dev/null +++ b/tests/cases/compiler/modifiersOnInterfaceIndexSignature1.ts @@ -0,0 +1,3 @@ +interface I { + public [a: string]: number; +} \ No newline at end of file diff --git a/tests/cases/compiler/objectLiteralMemberWithModifiers1.ts b/tests/cases/compiler/objectLiteralMemberWithModifiers1.ts new file mode 100644 index 00000000000..6bdc9476fb8 --- /dev/null +++ b/tests/cases/compiler/objectLiteralMemberWithModifiers1.ts @@ -0,0 +1 @@ +var v = { public foo() { } } \ No newline at end of file diff --git a/tests/cases/compiler/objectLiteralMemberWithModifiers2.ts b/tests/cases/compiler/objectLiteralMemberWithModifiers2.ts new file mode 100644 index 00000000000..0bfa0a20521 --- /dev/null +++ b/tests/cases/compiler/objectLiteralMemberWithModifiers2.ts @@ -0,0 +1 @@ +var v = { public get foo() { } } \ No newline at end of file diff --git a/tests/cases/compiler/objectLiteralMemberWithQuestionMark1.ts b/tests/cases/compiler/objectLiteralMemberWithQuestionMark1.ts new file mode 100644 index 00000000000..0529c717d16 --- /dev/null +++ b/tests/cases/compiler/objectLiteralMemberWithQuestionMark1.ts @@ -0,0 +1 @@ +var v = { foo?() { } } \ No newline at end of file diff --git a/tests/cases/compiler/objectLiteralMemberWithoutBlock1.ts b/tests/cases/compiler/objectLiteralMemberWithoutBlock1.ts new file mode 100644 index 00000000000..7f930a5dfde --- /dev/null +++ b/tests/cases/compiler/objectLiteralMemberWithoutBlock1.ts @@ -0,0 +1 @@ +var v = { foo(); } \ No newline at end of file