diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 51f97727ca4..b58c43b11ea 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -103,7 +103,7 @@ module ts { let globalTypedPropertyDescriptorType: ObjectType; let globalClassDecoratorType: ObjectType; let globalClassAnnotationType: ObjectType; - let globalParameterAnnotationType: ObjectType; + let globalParameterDecoratorType: ObjectType; let globalPropertyAnnotationType: ObjectType; let globalPropertyDecoratorType: ObjectType; @@ -417,22 +417,23 @@ module ts { } break; case SyntaxKind.Decorator: - if (location.parent) { + // Decorators are resolved at the class declaration as that point where they are evaluated in the emit: + // + // function y() {} + // class C { + // method(@y x, y) {} // <-- All references to decorators should occur at the class declaration + // } + // + let parent = location.parent; + if (parent && parent.kind === SyntaxKind.Parameter) { + parent = parent.parent; + } + if (parent && isClassElement(parent)) { + parent = parent.parent; + } + if (parent) { lastLocation = location; - grandparent = location.parent.parent; - if (location.parent.kind === SyntaxKind.Parameter) { - // Parameter decorators are resolved in the context of their great-grandparent - if (grandparent) { - location = grandparent.parent; - } - else { - break loop; - } - } - else { - // all other decorators are resolved in the context of their grandparent - location = grandparent; - } + location = parent; continue; } break; @@ -8121,8 +8122,8 @@ module ts { checkFunctionLikeDeclaration(node); } - function checkIncompleteDeclaration(node: Declaration) { - error(node, Diagnostics.Declaration_expected); + function checkMissingDeclaration(node: Node) { + checkDecorators(node); } function checkTypeReference(node: TypeReferenceNode) { @@ -8538,9 +8539,9 @@ module ts { switch (node.parent.kind) { case SyntaxKind.ClassDeclaration: - let classSymbol = getSymbolOfNode(node.parent); + let classSymbol = getSymbolOfNode(node.parent); let classType = getTypeOfSymbol(classSymbol); - checkDecoratorSignature(node, exprType, globalClassAnnotationType, classType, globalClassDecoratorType, Diagnostics.Decorators_may_not_change_the_type_of_a_class); + checkDecoratorSignature(node, exprType, globalClassAnnotationType, classType, globalClassDecoratorType, Diagnostics.A_decorator_may_not_change_the_type_of_a_class); break; case SyntaxKind.PropertyDeclaration: @@ -8548,11 +8549,11 @@ module ts { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: let propertyType = getTypeOfNode(node.parent); - checkDecoratorSignature(node, exprType, globalPropertyAnnotationType, propertyType, globalPropertyDecoratorType, Diagnostics.Decorators_may_not_change_the_type_of_a_member); + checkDecoratorSignature(node, exprType, globalPropertyAnnotationType, propertyType, globalPropertyDecoratorType, Diagnostics.A_decorator_may_not_change_the_type_of_a_member); break; case SyntaxKind.Parameter: - checkDecoratorSignature(node, exprType, globalParameterAnnotationType); + checkDecoratorSignature(node, exprType, globalParameterDecoratorType); break; } } @@ -8561,7 +8562,7 @@ module ts { function checkDecorators(node: Node): void { if (!node.decorators) { return; - } + } switch (node.kind) { case SyntaxKind.ClassDeclaration: @@ -10330,8 +10331,6 @@ module ts { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: return checkAccessorDeclaration(node); - case SyntaxKind.IncompleteDeclaration: - return checkIncompleteDeclaration(node); case SyntaxKind.TypeReference: return checkTypeReference(node); case SyntaxKind.TypeQuery: @@ -10410,6 +10409,8 @@ module ts { case SyntaxKind.DebuggerStatement: checkGrammarStatementInAmbientContext(node); return; + case SyntaxKind.MissingDeclaration: + return checkMissingDeclaration(node); } } @@ -11315,6 +11316,20 @@ module ts { return undefined; } + function getAnnotationTypeForDecoratorType(type: Type, typeArgument: Type): Type { + if (type === unknownType) { + return unknownType; + } + + let signature = getSingleCallSignature(type); + if (!signature) { + return unknownType; + } + + let instantiatedSignature = getSignatureInstantiation(signature, [typeArgument]); + return getOrCreateTypeFromSignature(instantiatedSignature); + } + function createResolver(): EmitResolver { return { getGeneratedNameForNode, @@ -11365,10 +11380,10 @@ module ts { globalRegExpType = getGlobalType("RegExp"); globalTypedPropertyDescriptorType = getTypeOfGlobalSymbol(getGlobalTypeSymbol("TypedPropertyDescriptor"), 1); globalClassDecoratorType = getGlobalType("ClassDecorator"); + globalClassAnnotationType = getAnnotationTypeForDecoratorType(globalClassDecoratorType, globalFunctionType); globalPropertyDecoratorType = getGlobalType("PropertyDecorator"); - globalClassAnnotationType = getGlobalType("ClassAnnotation"); - globalPropertyAnnotationType = getGlobalType("PropertyAnnotation"); - globalParameterAnnotationType = getGlobalType("ParameterAnnotation"); + globalPropertyAnnotationType = getAnnotationTypeForDecoratorType(globalPropertyDecoratorType, anyType); + globalParameterDecoratorType = getGlobalType("ParameterDecorator"); // If we're in ES6 mode, load the TemplateStringsArray. // Otherwise, default to 'unknown' for the purposes of type checking in LS scenarios. @@ -11402,6 +11417,9 @@ module ts { while (target) { switch (target.kind) { case SyntaxKind.ClassDeclaration: + if (languageVersion < ScriptTarget.ES5) { + return grammarErrorOnNode(node, Diagnostics.Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher); + } return false; case SyntaxKind.Constructor: @@ -11414,7 +11432,6 @@ module ts { target = target.parent; continue; - case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -11426,7 +11443,7 @@ module ts { } break; } - return grammarErrorOnNode(node, Diagnostics.Decorators_are_not_valid_on_this_declaration_type); + return grammarErrorOnNode(node, Diagnostics.Decorators_are_not_valid_here); } function checkGrammarModifiers(node: Node): boolean { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 005985b0d0c..839faf27b8d 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -162,11 +162,10 @@ module ts { Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1202, category: DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." }, Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead: { code: 1203, category: DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead." }, Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher: { code: 1204, category: DiagnosticCategory.Error, key: "Cannot compile external modules into amd or commonjs when targeting es6 or higher." }, - Decorators_are_only_supported_on_class_members_when_targeting_ECMAScript_5_or_higher: { code: 1205, category: DiagnosticCategory.Error, key: "Decorators are only supported on class members when targeting ECMAScript 5 or higher." }, - Decorators_are_not_valid_on_this_declaration_type: { code: 1206, category: DiagnosticCategory.Error, key: "Decorators are not valid on this declaration type." }, - Argument_to_ambient_decorator_must_be_constant_expression: { code: 1207, category: DiagnosticCategory.Error, key: "Argument to ambient decorator must be constant expression." }, - Decorators_may_not_change_the_type_of_a_member: { code: 1208, category: DiagnosticCategory.Error, key: "Decorators may not change the type of a member." }, - Decorators_may_not_change_the_type_of_a_class: { code: 1209, category: DiagnosticCategory.Error, key: "Decorators may not change the type of a class." }, + Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1205, category: DiagnosticCategory.Error, key: "Decorators are only available when targeting ECMAScript 5 and higher." }, + Decorators_are_not_valid_here: { code: 1206, category: DiagnosticCategory.Error, key: "Decorators are not valid here." }, + A_decorator_may_not_change_the_type_of_a_member: { code: 1208, category: DiagnosticCategory.Error, key: "A decorator may not change the type of a member." }, + A_decorator_may_not_change_the_type_of_a_class: { code: 1209, category: DiagnosticCategory.Error, key: "A decorator may not change the type of a class." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 3dee5320eec..c1c5152c7e4 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -639,23 +639,19 @@ "category": "Error", "code": 1204 }, - "Decorators are only supported on class members when targeting ECMAScript 5 or higher.": { + "Decorators are only available when targeting ECMAScript 5 and higher.": { "category": "Error", "code": 1205 }, - "Decorators are not valid on this declaration type.": { + "Decorators are not valid here.": { "category": "Error", "code": 1206 }, - "Argument to ambient decorator must be constant expression.": { - "category": "Error", - "code": 1207 - }, - "Decorators may not change the type of a member.": { + "A decorator may not change the type of a member.": { "category": "Error", "code": 1208 }, - "Decorators may not change the type of a class.": { + "A decorator may not change the type of a class.": { "category": "Error", "code": 1209 }, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 77347019d3e..6f35b8c0a63 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -277,6 +277,14 @@ module ts { } } + function getFirstConstructorWithBody(node: ClassDeclaration): ConstructorDeclaration { + return forEach(node.members, member => { + if (member.kind === SyntaxKind.Constructor && nodeIsPresent((member).body)) { + return member; + } + }); + } + function getAllAccessorDeclarations(declarations: NodeArray, accessor: AccessorDeclaration) { let firstAccessor: AccessorDeclaration; let lastAccessor: AccessorDeclaration; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 57519f6584e..b78f61853e8 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -119,9 +119,7 @@ module ts { case SyntaxKind.ArrayBindingPattern: return visitNodes(cbNodes, (node).elements); case SyntaxKind.ArrayLiteralExpression: - return visitNode(cbNode, (node).openBracketToken) || - visitNodes(cbNodes, (node).elements) || - visitNode(cbNode, (node).closeBracketToken); + return visitNodes(cbNodes, (node).elements); case SyntaxKind.ObjectLiteralExpression: return visitNodes(cbNodes, (node).properties); case SyntaxKind.PropertyAccessExpression: @@ -130,9 +128,7 @@ module ts { visitNode(cbNode, (node).name); case SyntaxKind.ElementAccessExpression: return visitNode(cbNode, (node).expression) || - visitNode(cbNode, (node).openBracketToken) || - visitNode(cbNode, (node).argumentExpression) || - visitNode(cbNode, (node).closeBracketToken); + visitNode(cbNode, (node).argumentExpression); case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: return visitNode(cbNode, (node).expression) || @@ -239,8 +235,7 @@ module ts { return visitNode(cbNode, (node).variableDeclaration) || visitNode(cbNode, (node).block); case SyntaxKind.Decorator: - return visitNode(cbNode, (node).atToken) || - visitNode(cbNode, (node).expression); + return visitNode(cbNode, (node).expression); case SyntaxKind.ClassDeclaration: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || @@ -315,9 +310,8 @@ module ts { return visitNodes(cbNodes, (node).types); case SyntaxKind.ExternalModuleReference: return visitNode(cbNode, (node).expression); - case SyntaxKind.IncompleteDeclaration: - return visitNodes(cbNodes, node.decorators) || - visitNodes(cbNodes, node.modifiers); + case SyntaxKind.MissingDeclaration: + return visitNodes(cbNodes, node.decorators); } } @@ -352,12 +346,6 @@ module ts { Unknown } - interface SignatureResult { - typeParameters?: NodeArray; - parameters?: NodeArray; - type?: TypeNode; - } - function parsingContextErrors(context: ParsingContext): DiagnosticMessage { switch (context) { case ParsingContext.SourceElements: return Diagnostics.Declaration_or_statement_expected; @@ -1016,6 +1004,8 @@ module ts { } function parseSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, syntaxCursor: SyntaxCursor, setParentNodes = false): SourceFile { + const disallowInAndDecoratorContext = ParserContextFlags.DisallowIn | ParserContextFlags.Decorator; + let parsingContext: ParsingContext = 0; let identifiers: Map = {}; let identifierCount = 0; @@ -1163,6 +1153,19 @@ module ts { setContextFlag(val, ParserContextFlags.Decorator); } + function doOutsideOfContext(flags: ParserContextFlags, func: () => T): T { + let currentContextFlags = contextFlags & flags; + if (currentContextFlags) { + setContextFlag(false, currentContextFlags); + let result = func(); + setContextFlag(true, currentContextFlags); + return result; + } + + // no need to do anything special as we are not in any of the requested contexts + return func(); + } + function allowInAnd(func: () => T): T { if (contextFlags & ParserContextFlags.DisallowIn) { setDisallowInContext(false); @@ -1223,18 +1226,6 @@ module ts { return result; } - function doOutsideOfDecoratorContext(func: () => T): T { - if (contextFlags & ParserContextFlags.Decorator) { - setDecoratorContext(false); - let result = func(); - setDecoratorContext(true); - return result; - } - - // no need to do anything special if we're not in the [Decorator] context. - return func(); - } - function inYieldContext() { return (contextFlags & ParserContextFlags.Yield) !== 0; } @@ -1447,12 +1438,8 @@ module ts { return node; } - function finishNode(node: T, end?: number): T { - if (!(end >= 0)) { - end = scanner.getStartPos(); - } - - node.end = end; + function finishNode(node: T): T { + node.end = scanner.getStartPos(); if (contextFlags) { node.parserContextFlags = contextFlags; @@ -1468,14 +1455,7 @@ module ts { return node; } - - function createMissingNodeAtPosition(pos: number, kind: SyntaxKind, diagnosticMessage: DiagnosticMessage, arg0?: any): Node { - parseErrorAtPosition(pos, 0, diagnosticMessage, arg0); - let result = createNode(kind, pos); - (result).text = ""; - return finishNode(result, pos); - } - + function createMissingNode(kind: SyntaxKind, reportAtCurrentPosition: boolean, diagnosticMessage: DiagnosticMessage, arg0?: any): Node { if (reportAtCurrentPosition) { parseErrorAtPosition(scanner.getStartPos(), 0, diagnosticMessage, arg0); @@ -3294,7 +3274,7 @@ module ts { let node = createNode(SyntaxKind.ConditionalExpression, leftOperand.pos); node.condition = leftOperand; node.questionToken = questionToken; - node.whenTrue = allowInAnd(parseAssignmentExpressionOrHigher); + node.whenTrue = doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher); node.colonToken = parseExpectedToken(SyntaxKind.ColonToken, /*reportAtCurrentPosition:*/ false, Diagnostics._0_expected, tokenToString(SyntaxKind.ColonToken)); node.whenFalse = parseAssignmentExpressionOrHigher(); @@ -3585,11 +3565,10 @@ module ts { continue; } - let openBracketToken = parseOptionalToken(SyntaxKind.OpenBracketToken); - if (openBracketToken) { + // when in the [Decorator] context, we do not parse ElementAccess as it could be part of a ComputedPropertyName + if (!inDecoratorContext() && parseOptional(SyntaxKind.OpenBracketToken)) { let indexedAccess = createNode(SyntaxKind.ElementAccessExpression, expression.pos); indexedAccess.expression = expression; - indexedAccess.openBracketToken = openBracketToken; // It's not uncommon for a user to write: "new Type[]". // Check for that common pattern and report a better error message. @@ -3601,7 +3580,7 @@ module ts { } } - indexedAccess.closeBracketToken = parseExpectedToken(SyntaxKind.CloseBracketToken, /*reportAtCurrentPosition*/false, Diagnostics._0_expected, "]"); + parseExpected(SyntaxKind.CloseBracketToken); expression = finishNode(indexedAccess); continue; } @@ -3623,16 +3602,6 @@ module ts { function parseCallExpressionRest(expression: LeftHandSideExpression): LeftHandSideExpression { while (true) { expression = parseMemberExpressionRest(expression); - if (inDecoratorContext() && - parsingContext === ParsingContext.ClassMembers && - (token === SyntaxKind.LessThanToken || token === SyntaxKind.OpenParenToken) && - (expression.kind === SyntaxKind.ElementAccessExpression || expression.kind === SyntaxKind.Identifier)) { - // TODO(rbuckton): switch to tryParse and reuse the parsed signature information? - let result = lookAhead(isStartOfMethodSignature); - if (result) { - return expression; - } - } if (token === SyntaxKind.LessThanToken) { // See if this is the start of a generic invocation. If so, consume it and // keep checking for postfix expressions. Otherwise, it's just a '<' that's @@ -3662,28 +3631,6 @@ module ts { } } - function isStartOfMethodSignature() { - // try to parse it as a signature, if successful and we are followed by an open brace or semicolon, this is really a method signature - var parameters: NodeArray; - var type: TypeNode; - if (token === SyntaxKind.LessThanToken && !parseTypeParameters()) { - // failed to parse type parameters here, this is not a method - return false; - } - if (token === SyntaxKind.OpenParenToken) { - if (!parseParameterList(/*yieldAndGeneratorParameterContext*/ false, /*requireCompleteParameterList*/ true)) { - // failed to parse a parameter list here, this is not a method - return false; - } - if (token === SyntaxKind.ColonToken || token === SyntaxKind.SemicolonToken || token === SyntaxKind.OpenBraceToken) { - // found a type annotation, semicolon, or open brace, this is a method signature - type = parseTypeAnnotation(); - return true; - } - } - return false; - } - function parseArgumentList() { parseExpected(SyntaxKind.OpenParenToken); let result = parseDelimitedList(ParsingContext.ArgumentExpressions, parseArgumentExpression); @@ -3801,15 +3748,15 @@ module ts { } function parseArgumentExpression(): Expression { - return allowInAnd(parseArgumentOrArrayLiteralElement); + return doOutsideOfContext(disallowInAndDecoratorContext, parseArgumentOrArrayLiteralElement); } function parseArrayLiteralExpression(): ArrayLiteralExpression { let node = createNode(SyntaxKind.ArrayLiteralExpression); - node.openBracketToken = parseExpectedToken(SyntaxKind.OpenBracketToken, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, "["); + parseExpected(SyntaxKind.OpenBracketToken); if (scanner.hasPrecedingLineBreak()) node.flags |= NodeFlags.MultiLine; node.elements = parseDelimitedList(ParsingContext.ArrayLiteralMembers, parseArgumentOrArrayLiteralElement); - node.closeBracketToken = parseExpectedToken(SyntaxKind.CloseBracketToken, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, "]"); + parseExpected(SyntaxKind.CloseBracketToken); return finishNode(node); } @@ -3928,6 +3875,8 @@ module ts { let savedYieldContext = inYieldContext(); setYieldContext(allowYield); + // We may be in a [Decorator] context when parsing a function expression or + // arrow function. The body of the function is not in [Decorator] context. let saveDecoratorContext = inDecoratorContext(); if (saveDecoratorContext) { setDecoratorContext(false); @@ -4186,7 +4135,7 @@ module ts { // as the parser will produce the same FunctionDeclaraiton or VariableStatement if it has // the same text regardless of whether it is inside a block or not. if (isModifier(token)) { - let result = lookAhead(parseVariableStatementOrFunctionDeclarationWithModifiers); + let result = lookAhead(parseVariableStatementOrFunctionDeclarationWithDecoratorsOrModifiers); if (result) { return true; } @@ -4318,7 +4267,7 @@ module ts { // Even though variable statements and function declarations cannot have decorators, // we parse them here to provide better error recovery. if (isModifier(token) || token === SyntaxKind.AtToken) { - let result = tryParse(parseVariableStatementOrFunctionDeclarationWithModifiers); + let result = tryParse(parseVariableStatementOrFunctionDeclarationWithDecoratorsOrModifiers); if (result) { return result; } @@ -4328,7 +4277,7 @@ module ts { } } - function parseVariableStatementOrFunctionDeclarationWithModifiers(): FunctionDeclaration | VariableStatement { + function parseVariableStatementOrFunctionDeclarationWithDecoratorsOrModifiers(): FunctionDeclaration | VariableStatement { let start = scanner.getStartPos(); let decorators = parseDecorators(); let modifiers = parseModifiers(); @@ -4522,10 +4471,22 @@ module ts { return finishNode(method); } + function parsePropertyDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray, name: DeclarationName, questionToken: Node): ClassElement { + let property = createNode(SyntaxKind.PropertyDeclaration, fullStart); + property.decorators = decorators; + setModifiers(property, modifiers); + property.name = name; + property.questionToken = questionToken; + property.type = parseTypeAnnotation(); + property.initializer = allowInAnd(parseNonParameterInitializer); + parseSemicolon(); + return finishNode(property); + } + function parsePropertyOrMethodDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ClassElement { let asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); let name = parsePropertyName(); - + // Note: this is not legal as per the grammar. But we allow it in the parser and // report an error in the grammar checker. let questionToken = parseOptionalToken(SyntaxKind.QuestionToken); @@ -4533,15 +4494,7 @@ module ts { return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, Diagnostics.or_expected); } else { - let property = createNode(SyntaxKind.PropertyDeclaration, fullStart); - property.decorators = decorators; - setModifiers(property, modifiers); - property.name = name; - property.questionToken = questionToken; - property.type = parseTypeAnnotation(); - property.initializer = allowInAnd(parseNonParameterInitializer); - parseSemicolon(); - return finishNode(property); + return parsePropertyDeclaration(fullStart, decorators, modifiers, name, questionToken); } } @@ -4620,7 +4573,8 @@ module ts { function parseDecorators(): NodeArray { let decorators: NodeArray; while (true) { - if (token !== SyntaxKind.AtToken) { + let decoratorStart = getNodePos(); + if (!parseOptional(SyntaxKind.AtToken)) { break; } @@ -4629,13 +4583,12 @@ module ts { decorators.pos = scanner.getStartPos(); } - let decorator = createNode(SyntaxKind.Decorator); - decorator.atToken = parseTokenNode(); + let decorator = createNode(SyntaxKind.Decorator, decoratorStart); decorator.expression = doInDecoratorContext(parseLeftHandSideExpressionOrHigher); decorators.push(finishNode(decorator)); } if (decorators) { - decorators.end = scanner.getStartPos(); + decorators.end = getNodeEnd(); } return decorators; } @@ -4665,211 +4618,6 @@ module ts { return modifiers; } - function extractCallExpressionFromDecoratorTail(decorator: Decorator): CallExpression { - // We could have greedily parsed a method signature name as a call expression, so we extract it from the decorator. - let expression = decorator.expression; - if (expression.kind === SyntaxKind.CallExpression) { - decorator.expression = (expression).expression; - decorator.end = decorator.expression.end; - return expression; - } - return undefined; - } - - function extractDeclarationNameFromDecoratorTail(decorator: Decorator): DeclarationName { - let expression = decorator.expression; - let name: DeclarationName; - switch (expression.kind) { - case SyntaxKind.Identifier: - // We could have greedily parsed a property name as an identifier, so - // we extract it from the decorator for a better editor experience: - // @ - // id() {} - // - var end = Math.min(getTokenPosOfNode(decorator.atToken, sourceFile) + 1, decorator.atToken.end); - if (lineBreakBetween(sourceFile, end, getTokenPosOfNode(expression, sourceFile))) { - decorator.expression = createMissingNodeAtPosition(end, SyntaxKind.Identifier, Diagnostics.Expression_expected); - decorator.end = decorator.atToken.end; - return expression; - } - - break; - - case SyntaxKind.ArrayLiteralExpression: - // We could have greedily parsed a computed property name as an array literal expression, so - // we extract it from the decorator for a better editor experience: - // @ - // ["computed"]() {} - // - var end = Math.min(getTokenPosOfNode(decorator.atToken, sourceFile) + 1, decorator.atToken.end); - if (lineBreakBetween(sourceFile, end, getTokenPosOfNode(expression, sourceFile))) { - let arrayExpr = expression; - decorator.expression = createMissingNodeAtPosition(end, SyntaxKind.Identifier, Diagnostics.Expression_expected); - decorator.end = decorator.atToken.end; - - var computedPropertyName = createNode(SyntaxKind.ComputedPropertyName, arrayExpr.pos); - if (arrayExpr.elements.length === 0) { - end = Math.min(getTokenPosOfNode(arrayExpr.openBracketToken, sourceFile) + 1, arrayExpr.openBracketToken.end); - computedPropertyName.expression = createMissingNodeAtPosition(end, SyntaxKind.Identifier, Diagnostics.Expression_expected); - } - else { - let i = arrayExpr.elements.length - 1; - let expr = arrayExpr.elements[i--]; - while (i >= 0) { - var element = arrayExpr.elements[i--]; - var commaExpr = createNode(SyntaxKind.BinaryExpression, element.pos); - commaExpr.operatorToken = finishNode(createNode(SyntaxKind.CommaToken, 0), 0); - commaExpr.left = element; - commaExpr.right = expr; - expr = finishNode(commaExpr, expr.end); - } - computedPropertyName.expression = expr; - } - - return finishNode(computedPropertyName, arrayExpr.end); - } - - break; - - case SyntaxKind.PropertyAccessExpression: - // We could have greedily parsed a property name as a property access, so we extract it from the decorator - // for a better editor experience. - // @expr. - // id() {} - // - let propExpr = expression; - var end = Math.min(getTokenPosOfNode(propExpr.dotToken, sourceFile) + 1, propExpr.dotToken.end); - if (lineBreakBetween(sourceFile, end, getTokenPosOfNode(propExpr.name, sourceFile))) { - name = propExpr.name; - propExpr.name = createMissingNodeAtPosition(end, SyntaxKind.Identifier, Diagnostics.Identifier_expected); - propExpr.end = propExpr.dotToken.end; - decorator.end = propExpr.dotToken.end; - return name; - } - break; - - case SyntaxKind.ElementAccessExpression: - // We could have greedily parsed a computed property name as an element access, so we extract it from the decorator. - // @expr - // ["expr"]() - // - let elementExpr = expression; - decorator.expression = elementExpr.expression; - decorator.end = elementExpr.expression.end; - - var computedPropertyName = createNode(SyntaxKind.ComputedPropertyName, getTokenPosOfNode(elementExpr.argumentExpression, sourceFile)); - computedPropertyName.expression = elementExpr.argumentExpression; - return finishNode(computedPropertyName, elementExpr.end); - } - - return createMissingNodeAtPosition(expression.end, SyntaxKind.Identifier, Diagnostics.Identifier_expected); - } - - function reparseTypeArgumentsAsTypeParameters(typeArguments: NodeArray): NodeArray { - let typeParameters = >[]; - typeParameters.pos = typeArguments.pos; - typeParameters.end = typeArguments.end; - for (let i = 0; i < typeArguments.length; i++) { - let typeArgument = typeArguments[i]; - let typeParameter = createNode(SyntaxKind.TypeParameter, typeArgument.pos); - Debug.assert(typeArgument.kind === SyntaxKind.TypeReference); - let typeReference = typeArgument; - Debug.assert(typeReference.typeName.kind === SyntaxKind.Identifier); - typeParameter.name = typeReference.typeName; - finishNode(typeParameter, typeArgument.end); - typeParameters.push(typeParameter); - } - return typeParameters; - } - - function reparseArgumentsAsParameters(argumentList: NodeArray): NodeArray { - let parameters = >[]; - parameters.pos = argumentList.pos; - parameters.end = argumentList.end; - for (let i = 0; i < argumentList.length; i++) { - let argument = argumentList[i]; - - // TODO: Object literal as object binding - // TODO: Array literal as array binding - let name: Identifier; - let initializer: Expression; - if (argument.kind === SyntaxKind.Identifier) { - name = argument; - } - else if (argument.kind === SyntaxKind.BinaryExpression) { - let binaryExpression = argument; - Debug.assert(binaryExpression.operatorToken.kind === SyntaxKind.EqualsToken); - if (binaryExpression.left.kind === SyntaxKind.Identifier) { - name = binaryExpression.left; - initializer = binaryExpression.right; - } - else { - Debug.fail("Invalid attempt to reclassify expression."); - } - } - else { - Debug.fail("Invalid attempt to reclassify expression."); - } - - let parameter = createNode(SyntaxKind.Parameter, argument.pos); - parameter.name = name; - parameter.initializer = initializer; - finishNode(parameter, argument.end); - parameters.push(parameter); - } - return parameters; - } - - function reparseCallExpressionAsSignature(node: CallExpression, signature: SignatureDeclaration): void { - if (node.typeArguments) { - signature.typeParameters = reparseTypeArgumentsAsTypeParameters(node.typeArguments); - } - signature.parameters = reparseArgumentsAsParameters(node.arguments); - signature.type = parseTypeAnnotation(); - } - - function reparseClassElement(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ClassElement { - // We may have parsed a decorator that greedily included part of the member as its expression. - let lastDecorator = decorators[decorators.length - 1]; - - // TODO(rbuckton): pull out the call expression or declaration name from the consise body of an arrow function - - // If we parsed a call expression, extract the call expression to reparse as a signature - let callExpression = extractCallExpressionFromDecoratorTail(lastDecorator); - - // Extract the declaration name from the decorator - let name = extractDeclarationNameFromDecoratorTail(lastDecorator); - let questionToken = parseOptionalToken(SyntaxKind.QuestionToken); - decorators.end = lastDecorator.end; - - if (callExpression) { - // Reparse as method - let method = createNode(SyntaxKind.MethodDeclaration, fullStart); - method.decorators = decorators; - setModifiers(method, modifiers); - method.name = name; - method.questionToken = questionToken; - reparseCallExpressionAsSignature(callExpression, method); - method.body = parseFunctionBlockOrSemicolon(/*isGenerator*/ false); - return finishNode(method); - } - else { - if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { - return parseMethodDeclaration(fullStart, decorators, modifiers, /*asteriskToken*/ undefined, name, questionToken, Diagnostics.or_expected); - } - - // Reparse as property declaration with a missing name. - let property = createNode(SyntaxKind.PropertyDeclaration, fullStart); - property.decorators = decorators; - setModifiers(property, modifiers); - property.name = name; - property.type = parseTypeAnnotation(); - property.initializer = allowInAnd(parseNonParameterInitializer); - parseSemicolon(); - return finishNode(property); - } - } - function parseClassElement(): ClassElement { let fullStart = getNodePos(); let decorators = parseDecorators(); @@ -4900,7 +4648,9 @@ module ts { } if (decorators) { - return reparseClassElement(fullStart, decorators, modifiers); + // treat this as a property declaration with a missing name. + let name = createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected); + return parsePropertyDeclaration(fullStart, decorators, modifiers, name, /*questionToken*/ undefined); } // 'isClassMemberStart' should have hinted not to attempt parsing. @@ -5397,8 +5147,9 @@ module ts { default: if (decorators) { // We reached this point because we encountered an AtToken and assumed a declaration would - // follow. For recovery and error reporting purposes, return an incomplete declaration. - let node = createNode(SyntaxKind.IncompleteDeclaration, fullStart); + // follow. For recovery and error reporting purposes, return an incomplete declaration. + let node = createMissingNode(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected); + node.pos = fullStart; node.decorators = decorators; setModifiers(node, modifiers); return finishNode(node); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f6d68cb1615..c0818af840d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -246,7 +246,7 @@ module ts { ExportDeclaration, NamedExports, ExportSpecifier, - IncompleteDeclaration, + MissingDeclaration, // Module references ExternalModuleReference, @@ -405,7 +405,6 @@ module ts { } export interface Decorator extends Node { - atToken: Node; expression: LeftHandSideExpression; } @@ -699,9 +698,7 @@ module ts { } export interface ArrayLiteralExpression extends PrimaryExpression { - openBracketToken: Node; elements: NodeArray; - closeBracketToken: Node; } export interface SpreadElementExpression extends Expression { @@ -721,9 +718,7 @@ module ts { export interface ElementAccessExpression extends MemberExpression { expression: LeftHandSideExpression; - openBracketToken: Node; argumentExpression?: Expression; - closeBracketToken: Node; } export interface CallExpression extends LeftHandSideExpression { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index a48a8fc7f2a..976a7c4f8a0 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1,4 +1,4 @@ -/// +/// module ts { export interface ReferencePathMatchResult { @@ -575,17 +575,6 @@ module ts { return (node).expression; } - function getConstructorWithBody(member: ClassElement): ConstructorDeclaration { - if (member.kind === SyntaxKind.Constructor && nodeIsPresent((member).body)) { - return member; - } - return undefined; - } - - export function getFirstConstructorWithBody(node: ClassDeclaration): ConstructorDeclaration { - return forEach(node.members, getConstructorWithBody); - } - export function nodeOrChildIsDecorated(node: Node): boolean { switch (node.kind) { case SyntaxKind.ClassDeclaration: @@ -897,6 +886,19 @@ module ts { } } + export function isClassElement(n: Node): boolean { + switch (n.kind) { + case SyntaxKind.Constructor: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + return true; + default: + return false; + } + } + // True if the given identifier, string literal, or number literal is the name of a declaration node export function isDeclarationName(name: Node): boolean { if (name.kind !== SyntaxKind.Identifier && name.kind !== SyntaxKind.StringLiteral && name.kind !== SyntaxKind.NumericLiteral) { diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index 930f5781c91..b631219c2a5 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -1167,6 +1167,4 @@ interface TypedPropertyDescriptor { interface ClassDecorator { (target: TFunction): TFunction | void; } interface PropertyDecorator { (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor | void; } -interface ClassAnnotation { (target: Function): void; } -interface PropertyAnnotation { (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void; } -interface ParameterAnnotation { (target: Function, parameterIndex: number): void; } +interface ParameterDecorator { (target: Function, parameterIndex: number): void; } diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 3aa1b0aa148..7a8aa117135 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -274,7 +274,7 @@ declare module "typescript" { ExportDeclaration = 212, NamedExports = 213, ExportSpecifier = 214, - IncompleteDeclaration = 215, + MissingDeclaration = 215, ExternalModuleReference = 216, CaseClause = 217, DefaultClause = 218, @@ -380,7 +380,6 @@ declare module "typescript" { expression: Expression; } interface Decorator extends Node { - atToken: Node; expression: LeftHandSideExpression; } interface TypeParameterDeclaration extends Declaration { @@ -585,9 +584,7 @@ declare module "typescript" { expression: Expression; } interface ArrayLiteralExpression extends PrimaryExpression { - openBracketToken: Node; elements: NodeArray; - closeBracketToken: Node; } interface SpreadElementExpression extends Expression { expression: Expression; @@ -602,9 +599,7 @@ declare module "typescript" { } interface ElementAccessExpression extends MemberExpression { expression: LeftHandSideExpression; - openBracketToken: Node; argumentExpression?: Expression; - closeBracketToken: Node; } interface CallExpression extends LeftHandSideExpression { expression: LeftHandSideExpression; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 59b08a4781c..3a1def11898 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -840,8 +840,8 @@ declare module "typescript" { ExportSpecifier = 214, >ExportSpecifier : SyntaxKind - IncompleteDeclaration = 215, ->IncompleteDeclaration : SyntaxKind + MissingDeclaration = 215, +>MissingDeclaration : SyntaxKind ExternalModuleReference = 216, >ExternalModuleReference : SyntaxKind @@ -1156,10 +1156,6 @@ declare module "typescript" { } interface Decorator extends Node { >Decorator : Decorator ->Node : Node - - atToken: Node; ->atToken : Node >Node : Node expression: LeftHandSideExpression; @@ -1764,18 +1760,10 @@ declare module "typescript" { >ArrayLiteralExpression : ArrayLiteralExpression >PrimaryExpression : PrimaryExpression - openBracketToken: Node; ->openBracketToken : Node ->Node : Node - elements: NodeArray; >elements : NodeArray >NodeArray : NodeArray >Expression : Expression - - closeBracketToken: Node; ->closeBracketToken : Node ->Node : Node } interface SpreadElementExpression extends Expression { >SpreadElementExpression : SpreadElementExpression @@ -1819,17 +1807,9 @@ declare module "typescript" { >expression : LeftHandSideExpression >LeftHandSideExpression : LeftHandSideExpression - openBracketToken: Node; ->openBracketToken : Node ->Node : Node - argumentExpression?: Expression; >argumentExpression : Expression >Expression : Expression - - closeBracketToken: Node; ->closeBracketToken : Node ->Node : Node } interface CallExpression extends LeftHandSideExpression { >CallExpression : CallExpression diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 3a757204be8..e9616e5d744 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -305,7 +305,7 @@ declare module "typescript" { ExportDeclaration = 212, NamedExports = 213, ExportSpecifier = 214, - IncompleteDeclaration = 215, + MissingDeclaration = 215, ExternalModuleReference = 216, CaseClause = 217, DefaultClause = 218, @@ -411,7 +411,6 @@ declare module "typescript" { expression: Expression; } interface Decorator extends Node { - atToken: Node; expression: LeftHandSideExpression; } interface TypeParameterDeclaration extends Declaration { @@ -616,9 +615,7 @@ declare module "typescript" { expression: Expression; } interface ArrayLiteralExpression extends PrimaryExpression { - openBracketToken: Node; elements: NodeArray; - closeBracketToken: Node; } interface SpreadElementExpression extends Expression { expression: Expression; @@ -633,9 +630,7 @@ declare module "typescript" { } interface ElementAccessExpression extends MemberExpression { expression: LeftHandSideExpression; - openBracketToken: Node; argumentExpression?: Expression; - closeBracketToken: Node; } interface CallExpression extends LeftHandSideExpression { expression: LeftHandSideExpression; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index c4e2f1ba406..bbae995432a 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -986,8 +986,8 @@ declare module "typescript" { ExportSpecifier = 214, >ExportSpecifier : SyntaxKind - IncompleteDeclaration = 215, ->IncompleteDeclaration : SyntaxKind + MissingDeclaration = 215, +>MissingDeclaration : SyntaxKind ExternalModuleReference = 216, >ExternalModuleReference : SyntaxKind @@ -1302,10 +1302,6 @@ declare module "typescript" { } interface Decorator extends Node { >Decorator : Decorator ->Node : Node - - atToken: Node; ->atToken : Node >Node : Node expression: LeftHandSideExpression; @@ -1910,18 +1906,10 @@ declare module "typescript" { >ArrayLiteralExpression : ArrayLiteralExpression >PrimaryExpression : PrimaryExpression - openBracketToken: Node; ->openBracketToken : Node ->Node : Node - elements: NodeArray; >elements : NodeArray >NodeArray : NodeArray >Expression : Expression - - closeBracketToken: Node; ->closeBracketToken : Node ->Node : Node } interface SpreadElementExpression extends Expression { >SpreadElementExpression : SpreadElementExpression @@ -1965,17 +1953,9 @@ declare module "typescript" { >expression : LeftHandSideExpression >LeftHandSideExpression : LeftHandSideExpression - openBracketToken: Node; ->openBracketToken : Node ->Node : Node - argumentExpression?: Expression; >argumentExpression : Expression >Expression : Expression - - closeBracketToken: Node; ->closeBracketToken : Node ->Node : Node } interface CallExpression extends LeftHandSideExpression { >CallExpression : CallExpression diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 54acd038e43..288bf70e864 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -306,7 +306,7 @@ declare module "typescript" { ExportDeclaration = 212, NamedExports = 213, ExportSpecifier = 214, - IncompleteDeclaration = 215, + MissingDeclaration = 215, ExternalModuleReference = 216, CaseClause = 217, DefaultClause = 218, @@ -412,7 +412,6 @@ declare module "typescript" { expression: Expression; } interface Decorator extends Node { - atToken: Node; expression: LeftHandSideExpression; } interface TypeParameterDeclaration extends Declaration { @@ -617,9 +616,7 @@ declare module "typescript" { expression: Expression; } interface ArrayLiteralExpression extends PrimaryExpression { - openBracketToken: Node; elements: NodeArray; - closeBracketToken: Node; } interface SpreadElementExpression extends Expression { expression: Expression; @@ -634,9 +631,7 @@ declare module "typescript" { } interface ElementAccessExpression extends MemberExpression { expression: LeftHandSideExpression; - openBracketToken: Node; argumentExpression?: Expression; - closeBracketToken: Node; } interface CallExpression extends LeftHandSideExpression { expression: LeftHandSideExpression; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 9d3c6e46cc6..90cc951f005 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -936,8 +936,8 @@ declare module "typescript" { ExportSpecifier = 214, >ExportSpecifier : SyntaxKind - IncompleteDeclaration = 215, ->IncompleteDeclaration : SyntaxKind + MissingDeclaration = 215, +>MissingDeclaration : SyntaxKind ExternalModuleReference = 216, >ExternalModuleReference : SyntaxKind @@ -1252,10 +1252,6 @@ declare module "typescript" { } interface Decorator extends Node { >Decorator : Decorator ->Node : Node - - atToken: Node; ->atToken : Node >Node : Node expression: LeftHandSideExpression; @@ -1860,18 +1856,10 @@ declare module "typescript" { >ArrayLiteralExpression : ArrayLiteralExpression >PrimaryExpression : PrimaryExpression - openBracketToken: Node; ->openBracketToken : Node ->Node : Node - elements: NodeArray; >elements : NodeArray >NodeArray : NodeArray >Expression : Expression - - closeBracketToken: Node; ->closeBracketToken : Node ->Node : Node } interface SpreadElementExpression extends Expression { >SpreadElementExpression : SpreadElementExpression @@ -1915,17 +1903,9 @@ declare module "typescript" { >expression : LeftHandSideExpression >LeftHandSideExpression : LeftHandSideExpression - openBracketToken: Node; ->openBracketToken : Node ->Node : Node - argumentExpression?: Expression; >argumentExpression : Expression >Expression : Expression - - closeBracketToken: Node; ->closeBracketToken : Node ->Node : Node } interface CallExpression extends LeftHandSideExpression { >CallExpression : CallExpression diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 13fd5a25457..a35850a7ce2 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -343,7 +343,7 @@ declare module "typescript" { ExportDeclaration = 212, NamedExports = 213, ExportSpecifier = 214, - IncompleteDeclaration = 215, + MissingDeclaration = 215, ExternalModuleReference = 216, CaseClause = 217, DefaultClause = 218, @@ -449,7 +449,6 @@ declare module "typescript" { expression: Expression; } interface Decorator extends Node { - atToken: Node; expression: LeftHandSideExpression; } interface TypeParameterDeclaration extends Declaration { @@ -654,9 +653,7 @@ declare module "typescript" { expression: Expression; } interface ArrayLiteralExpression extends PrimaryExpression { - openBracketToken: Node; elements: NodeArray; - closeBracketToken: Node; } interface SpreadElementExpression extends Expression { expression: Expression; @@ -671,9 +668,7 @@ declare module "typescript" { } interface ElementAccessExpression extends MemberExpression { expression: LeftHandSideExpression; - openBracketToken: Node; argumentExpression?: Expression; - closeBracketToken: Node; } interface CallExpression extends LeftHandSideExpression { expression: LeftHandSideExpression; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 514a9afe462..edaccc1daba 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -1109,8 +1109,8 @@ declare module "typescript" { ExportSpecifier = 214, >ExportSpecifier : SyntaxKind - IncompleteDeclaration = 215, ->IncompleteDeclaration : SyntaxKind + MissingDeclaration = 215, +>MissingDeclaration : SyntaxKind ExternalModuleReference = 216, >ExternalModuleReference : SyntaxKind @@ -1425,10 +1425,6 @@ declare module "typescript" { } interface Decorator extends Node { >Decorator : Decorator ->Node : Node - - atToken: Node; ->atToken : Node >Node : Node expression: LeftHandSideExpression; @@ -2033,18 +2029,10 @@ declare module "typescript" { >ArrayLiteralExpression : ArrayLiteralExpression >PrimaryExpression : PrimaryExpression - openBracketToken: Node; ->openBracketToken : Node ->Node : Node - elements: NodeArray; >elements : NodeArray >NodeArray : NodeArray >Expression : Expression - - closeBracketToken: Node; ->closeBracketToken : Node ->Node : Node } interface SpreadElementExpression extends Expression { >SpreadElementExpression : SpreadElementExpression @@ -2088,17 +2076,9 @@ declare module "typescript" { >expression : LeftHandSideExpression >LeftHandSideExpression : LeftHandSideExpression - openBracketToken: Node; ->openBracketToken : Node ->Node : Node - argumentExpression?: Expression; >argumentExpression : Expression >Expression : Expression - - closeBracketToken: Node; ->closeBracketToken : Node ->Node : Node } interface CallExpression extends LeftHandSideExpression { >CallExpression : CallExpression diff --git a/tests/baselines/reference/decoratorOnArrowFunction.errors.txt b/tests/baselines/reference/decoratorOnArrowFunction.errors.txt index 7a496a0f55d..14bde1e49bf 100644 --- a/tests/baselines/reference/decoratorOnArrowFunction.errors.txt +++ b/tests/baselines/reference/decoratorOnArrowFunction.errors.txt @@ -1,16 +1,16 @@ -tests/cases/conformance/decorators/invalid/decoratorOnArrowFunction.ts(3,9): error TS1109: Expression expected. -tests/cases/conformance/decorators/invalid/decoratorOnArrowFunction.ts(3,9): error TS1146: Declaration expected. -tests/cases/conformance/decorators/invalid/decoratorOnArrowFunction.ts(3,17): error TS1128: Declaration or statement expected. - - -==== tests/cases/conformance/decorators/invalid/decoratorOnArrowFunction.ts (3 errors) ==== - declare function dec(target: T): T; - - var F = @dec () => { - ~ -!!! error TS1109: Expression expected. - ~~~~~~~ -!!! error TS1146: Declaration expected. - ~~ -!!! error TS1128: Declaration or statement expected. +tests/cases/conformance/decorators/invalid/decoratorOnArrowFunction.ts(3,9): error TS1109: Expression expected. +tests/cases/conformance/decorators/invalid/decoratorOnArrowFunction.ts(3,16): error TS1146: Declaration expected. +tests/cases/conformance/decorators/invalid/decoratorOnArrowFunction.ts(3,17): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnArrowFunction.ts (3 errors) ==== + declare function dec(target: T): T; + + var F = @dec () => { + ~ +!!! error TS1109: Expression expected. + +!!! error TS1146: Declaration expected. + ~~ +!!! error TS1128: Declaration or statement expected. } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClass8.errors.txt b/tests/baselines/reference/decoratorOnClass8.errors.txt index b0f2872ac29..3f3cf08e217 100644 --- a/tests/baselines/reference/decoratorOnClass8.errors.txt +++ b/tests/baselines/reference/decoratorOnClass8.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/decorators/class/decoratorOnClass8.ts(3,1): error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type 'ClassAnnotation'. - - -==== tests/cases/conformance/decorators/class/decoratorOnClass8.ts (1 errors) ==== - declare function dec(): (target: Function, paramIndex: number) => void; - - @dec() - ~~~~~~ -!!! error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type 'ClassAnnotation'. - class C { +tests/cases/conformance/decorators/class/decoratorOnClass8.ts(3,1): error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type '(target: Function) => void | Function'. + + +==== tests/cases/conformance/decorators/class/decoratorOnClass8.ts (1 errors) ==== + declare function dec(): (target: Function, paramIndex: number) => void; + + @dec() + ~~~~~~ +!!! error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type '(target: Function) => void | Function'. + class C { } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt b/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt index e46e58ebbda..b75b7e0d8b6 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt +++ b/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt @@ -1,35 +1,35 @@ -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,5): error TS2304: Cannot find name 'public'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,12): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,12): error TS1146: Declaration expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,17): error TS2304: Cannot find name 'get'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,21): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,21): error TS2304: Cannot find name 'accessor'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,32): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(5,1): error TS1128: Declaration or statement expected. - - -==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts (9 errors) ==== - declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; - - class C { - public @dec get accessor() { return 1; } - ~~~~~~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'public'. - ~ -!!! error TS1005: ';' expected. - ~~~~ -!!! error TS1146: Declaration expected. - ~~~ -!!! error TS2304: Cannot find name 'get'. - ~~~~~~~~ -!!! error TS1005: ';' expected. - ~~~~~~~~ -!!! error TS2304: Cannot find name 'accessor'. - ~ -!!! error TS1005: ';' expected. - } - ~ +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,5): error TS2304: Cannot find name 'public'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,12): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,16): error TS1146: Declaration expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,17): error TS2304: Cannot find name 'get'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,21): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,21): error TS2304: Cannot find name 'accessor'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,32): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(5,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts (9 errors) ==== + declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + + class C { + public @dec get accessor() { return 1; } + ~~~~~~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~ +!!! error TS1005: ';' expected. + +!!! error TS1146: Declaration expected. + ~~~ +!!! error TS2304: Cannot find name 'get'. + ~~~~~~~~ +!!! error TS1005: ';' expected. + ~~~~~~~~ +!!! error TS2304: Cannot find name 'accessor'. + ~ +!!! error TS1005: ';' expected. + } + ~ !!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt b/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt index 277722a22d1..ec22ae0b3e1 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt +++ b/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt @@ -1,44 +1,44 @@ -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,5): error TS2304: Cannot find name 'public'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,12): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,12): error TS1146: Declaration expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,17): error TS2304: Cannot find name 'set'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,21): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,21): error TS2304: Cannot find name 'accessor'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,30): error TS2304: Cannot find name 'value'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,35): error TS1005: ',' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,37): error TS2304: Cannot find name 'number'. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,45): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(5,1): error TS1128: Declaration or statement expected. - - -==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts (12 errors) ==== - declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; - - class C { - public @dec set accessor(value: number) { } - ~~~~~~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'public'. - ~ -!!! error TS1005: ';' expected. - ~~~~ -!!! error TS1146: Declaration expected. - ~~~ -!!! error TS2304: Cannot find name 'set'. - ~~~~~~~~ -!!! error TS1005: ';' expected. - ~~~~~~~~ -!!! error TS2304: Cannot find name 'accessor'. - ~~~~~ -!!! error TS2304: Cannot find name 'value'. - ~ -!!! error TS1005: ',' expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'number'. - ~ -!!! error TS1005: ';' expected. - } - ~ +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,5): error TS2304: Cannot find name 'public'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,12): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,16): error TS1146: Declaration expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,17): error TS2304: Cannot find name 'set'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,21): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,21): error TS2304: Cannot find name 'accessor'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,30): error TS2304: Cannot find name 'value'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,35): error TS1005: ',' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,37): error TS2304: Cannot find name 'number'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,45): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(5,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts (12 errors) ==== + declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + + class C { + public @dec set accessor(value: number) { } + ~~~~~~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~ +!!! error TS1005: ';' expected. + +!!! error TS1146: Declaration expected. + ~~~ +!!! error TS2304: Cannot find name 'set'. + ~~~~~~~~ +!!! error TS1005: ';' expected. + ~~~~~~~~ +!!! error TS2304: Cannot find name 'accessor'. + ~~~~~ +!!! error TS2304: Cannot find name 'value'. + ~ +!!! error TS1005: ',' expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'number'. + ~ +!!! error TS1005: ';' expected. + } + ~ !!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassConstructor1.errors.txt b/tests/baselines/reference/decoratorOnClassConstructor1.errors.txt index 5c02776e7e0..14a164eccb4 100644 --- a/tests/baselines/reference/decoratorOnClassConstructor1.errors.txt +++ b/tests/baselines/reference/decoratorOnClassConstructor1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/class/constructor/decoratorOnClassConstructor1.ts(4,5): error TS1206: Decorators are not valid on this declaration type. +tests/cases/conformance/decorators/class/constructor/decoratorOnClassConstructor1.ts(4,5): error TS1206: Decorators are not valid here. ==== tests/cases/conformance/decorators/class/constructor/decoratorOnClassConstructor1.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/conformance/decorators/class/constructor/decoratorOnClassConstructor class C { @dec constructor() {} ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1206: Decorators are not valid on this declaration type. +!!! error TS1206: Decorators are not valid here. } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassMethod10.errors.txt b/tests/baselines/reference/decoratorOnClassMethod10.errors.txt index c9aada5d489..5b07832a407 100644 --- a/tests/baselines/reference/decoratorOnClassMethod10.errors.txt +++ b/tests/baselines/reference/decoratorOnClassMethod10.errors.txt @@ -1,17 +1,17 @@ -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod10.ts(4,5): error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type 'PropertyAnnotation'. - Types of parameters 'paramIndex' and 'propertyKey' are incompatible. - Type 'number' is not assignable to type 'string | symbol'. - Type 'number' is not assignable to type 'symbol'. - - -==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod10.ts (1 errors) ==== - declare function dec(target: Function, paramIndex: number): void; - - class C { - @dec method() {} - ~~~~ -!!! error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type 'PropertyAnnotation'. -!!! error TS2322: Types of parameters 'paramIndex' and 'propertyKey' are incompatible. -!!! error TS2322: Type 'number' is not assignable to type 'string | symbol'. -!!! error TS2322: Type 'number' is not assignable to type 'symbol'. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod10.ts(4,5): error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type '(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor'. + Types of parameters 'paramIndex' and 'propertyKey' are incompatible. + Type 'number' is not assignable to type 'string | symbol'. + Type 'number' is not assignable to type 'symbol'. + + +==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod10.ts (1 errors) ==== + declare function dec(target: Function, paramIndex: number): void; + + class C { + @dec method() {} + ~~~~ +!!! error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type '(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor'. +!!! error TS2322: Types of parameters 'paramIndex' and 'propertyKey' are incompatible. +!!! error TS2322: Type 'number' is not assignable to type 'string | symbol'. +!!! error TS2322: Type 'number' is not assignable to type 'symbol'. } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassMethod3.errors.txt b/tests/baselines/reference/decoratorOnClassMethod3.errors.txt index f125b96f9e8..b2173dedf9e 100644 --- a/tests/baselines/reference/decoratorOnClassMethod3.errors.txt +++ b/tests/baselines/reference/decoratorOnClassMethod3.errors.txt @@ -1,29 +1,29 @@ -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,5): error TS2304: Cannot find name 'public'. -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,12): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,12): error TS1146: Declaration expected. -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,17): error TS2304: Cannot find name 'method'. -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,26): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(5,1): error TS1128: Declaration or statement expected. - - -==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts (7 errors) ==== - declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; - - class C { - public @dec method() {} - ~~~~~~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'public'. - ~ -!!! error TS1005: ';' expected. - ~~~~ -!!! error TS1146: Declaration expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'method'. - ~ -!!! error TS1005: ';' expected. - } - ~ +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,5): error TS2304: Cannot find name 'public'. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,12): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,16): error TS1146: Declaration expected. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,17): error TS2304: Cannot find name 'method'. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,26): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(5,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts (7 errors) ==== + declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + + class C { + public @dec method() {} + ~~~~~~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~ +!!! error TS1005: ';' expected. + +!!! error TS1146: Declaration expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'method'. + ~ +!!! error TS1005: ';' expected. + } + ~ !!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassProperty13.errors.txt b/tests/baselines/reference/decoratorOnClassProperty13.errors.txt index 519d772cf53..27164bf3f48 100644 --- a/tests/baselines/reference/decoratorOnClassProperty13.errors.txt +++ b/tests/baselines/reference/decoratorOnClassProperty13.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty13.ts(4,5): error TS1208: Decorators may not change the type of a member. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty13.ts(4,5): error TS1208: A decorator may not change the type of a member. Type 'TypedPropertyDescriptor' is not assignable to type 'void | TypedPropertyDescriptor'. Type 'TypedPropertyDescriptor' is not assignable to type 'TypedPropertyDescriptor'. Type 'number' is not assignable to type 'string'. @@ -10,7 +10,7 @@ tests/cases/conformance/decorators/class/property/decoratorOnClassProperty13.ts( class C { @dec prop: string; ~~~~ -!!! error TS1208: Decorators may not change the type of a member. +!!! error TS1208: A decorator may not change the type of a member. !!! error TS1208: Type 'TypedPropertyDescriptor' is not assignable to type 'void | TypedPropertyDescriptor'. !!! error TS1208: Type 'TypedPropertyDescriptor' is not assignable to type 'TypedPropertyDescriptor'. !!! error TS1208: Type 'number' is not assignable to type 'string'. diff --git a/tests/baselines/reference/decoratorOnClassProperty3.errors.txt b/tests/baselines/reference/decoratorOnClassProperty3.errors.txt index 02c9c2bad61..722e1c30c60 100644 --- a/tests/baselines/reference/decoratorOnClassProperty3.errors.txt +++ b/tests/baselines/reference/decoratorOnClassProperty3.errors.txt @@ -1,26 +1,26 @@ -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,5): error TS2304: Cannot find name 'public'. -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,12): error TS1005: ';' expected. -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,12): error TS1146: Declaration expected. -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,17): error TS2304: Cannot find name 'prop'. -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(5,1): error TS1128: Declaration or statement expected. - - -==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts (6 errors) ==== - declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; - - class C { - public @dec prop; - ~~~~~~ -!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'public'. - ~ -!!! error TS1005: ';' expected. - ~~~~ -!!! error TS1146: Declaration expected. - ~~~~ -!!! error TS2304: Cannot find name 'prop'. - } - ~ +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,5): error TS2304: Cannot find name 'public'. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,12): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,16): error TS1146: Declaration expected. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,17): error TS2304: Cannot find name 'prop'. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(5,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts (6 errors) ==== + declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + + class C { + public @dec prop; + ~~~~~~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~ +!!! error TS1005: ';' expected. + +!!! error TS1146: Declaration expected. + ~~~~ +!!! error TS2304: Cannot find name 'prop'. + } + ~ !!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassProperty7.errors.txt b/tests/baselines/reference/decoratorOnClassProperty7.errors.txt index 1780959ba68..8292d49d10e 100644 --- a/tests/baselines/reference/decoratorOnClassProperty7.errors.txt +++ b/tests/baselines/reference/decoratorOnClassProperty7.errors.txt @@ -1,17 +1,17 @@ -tests/cases/conformance/decorators/class/property/decoratorOnClassProperty7.ts(4,5): error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type 'PropertyAnnotation'. - Types of parameters 'paramIndex' and 'propertyKey' are incompatible. - Type 'number' is not assignable to type 'string | symbol'. - Type 'number' is not assignable to type 'symbol'. - - -==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty7.ts (1 errors) ==== - declare function dec(target: Function, paramIndex: number): void; - - class C { - @dec prop; - ~~~~ -!!! error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type 'PropertyAnnotation'. -!!! error TS2322: Types of parameters 'paramIndex' and 'propertyKey' are incompatible. -!!! error TS2322: Type 'number' is not assignable to type 'string | symbol'. -!!! error TS2322: Type 'number' is not assignable to type 'symbol'. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty7.ts(4,5): error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type '(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor'. + Types of parameters 'paramIndex' and 'propertyKey' are incompatible. + Type 'number' is not assignable to type 'string | symbol'. + Type 'number' is not assignable to type 'symbol'. + + +==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty7.ts (1 errors) ==== + declare function dec(target: Function, paramIndex: number): void; + + class C { + @dec prop; + ~~~~ +!!! error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type '(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor'. +!!! error TS2322: Types of parameters 'paramIndex' and 'propertyKey' are incompatible. +!!! error TS2322: Type 'number' is not assignable to type 'string | symbol'. +!!! error TS2322: Type 'number' is not assignable to type 'symbol'. } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnEnum.errors.txt b/tests/baselines/reference/decoratorOnEnum.errors.txt index a5daa50a64f..21a6d39aab5 100644 --- a/tests/baselines/reference/decoratorOnEnum.errors.txt +++ b/tests/baselines/reference/decoratorOnEnum.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/invalid/decoratorOnEnum.ts(4,6): error TS1206: Decorators are not valid on this declaration type. +tests/cases/conformance/decorators/invalid/decoratorOnEnum.ts(4,6): error TS1206: Decorators are not valid here. ==== tests/cases/conformance/decorators/invalid/decoratorOnEnum.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/conformance/decorators/invalid/decoratorOnEnum.ts(4,6): error TS1206 @dec enum E { ~ -!!! error TS1206: Decorators are not valid on this declaration type. +!!! error TS1206: Decorators are not valid here. } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnEnum2.errors.txt b/tests/baselines/reference/decoratorOnEnum2.errors.txt index 69e778d0114..3a643bc861a 100644 --- a/tests/baselines/reference/decoratorOnEnum2.errors.txt +++ b/tests/baselines/reference/decoratorOnEnum2.errors.txt @@ -1,20 +1,20 @@ -tests/cases/conformance/decorators/invalid/decoratorOnEnum2.ts(4,5): error TS1132: Enum member expected. -tests/cases/conformance/decorators/invalid/decoratorOnEnum2.ts(4,5): error TS1146: Declaration expected. -tests/cases/conformance/decorators/invalid/decoratorOnEnum2.ts(4,10): error TS2304: Cannot find name 'A'. -tests/cases/conformance/decorators/invalid/decoratorOnEnum2.ts(5,1): error TS1128: Declaration or statement expected. - - -==== tests/cases/conformance/decorators/invalid/decoratorOnEnum2.ts (4 errors) ==== - declare function dec(target: T): T; - - enum E { - @dec A - ~ -!!! error TS1132: Enum member expected. - ~~~~ -!!! error TS1146: Declaration expected. - ~ -!!! error TS2304: Cannot find name 'A'. - } - ~ +tests/cases/conformance/decorators/invalid/decoratorOnEnum2.ts(4,5): error TS1132: Enum member expected. +tests/cases/conformance/decorators/invalid/decoratorOnEnum2.ts(4,9): error TS1146: Declaration expected. +tests/cases/conformance/decorators/invalid/decoratorOnEnum2.ts(4,10): error TS2304: Cannot find name 'A'. +tests/cases/conformance/decorators/invalid/decoratorOnEnum2.ts(5,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnEnum2.ts (4 errors) ==== + declare function dec(target: T): T; + + enum E { + @dec A + ~ +!!! error TS1132: Enum member expected. + +!!! error TS1146: Declaration expected. + ~ +!!! error TS2304: Cannot find name 'A'. + } + ~ !!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnFunctionDeclaration.errors.txt b/tests/baselines/reference/decoratorOnFunctionDeclaration.errors.txt index e46af2da6c6..bda00f1a85f 100644 --- a/tests/baselines/reference/decoratorOnFunctionDeclaration.errors.txt +++ b/tests/baselines/reference/decoratorOnFunctionDeclaration.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/invalid/decoratorOnFunctionDeclaration.ts(4,10): error TS1206: Decorators are not valid on this declaration type. +tests/cases/conformance/decorators/invalid/decoratorOnFunctionDeclaration.ts(4,10): error TS1206: Decorators are not valid here. ==== tests/cases/conformance/decorators/invalid/decoratorOnFunctionDeclaration.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/conformance/decorators/invalid/decoratorOnFunctionDeclaration.ts(4,1 @dec function F() { ~ -!!! error TS1206: Decorators are not valid on this declaration type. +!!! error TS1206: Decorators are not valid here. } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnImportEquals1.errors.txt b/tests/baselines/reference/decoratorOnImportEquals1.errors.txt index 4c5799dd71b..a09a0b01427 100644 --- a/tests/baselines/reference/decoratorOnImportEquals1.errors.txt +++ b/tests/baselines/reference/decoratorOnImportEquals1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/invalid/decoratorOnImportEquals1.ts(8,5): error TS1206: Decorators are not valid on this declaration type. +tests/cases/conformance/decorators/invalid/decoratorOnImportEquals1.ts(8,5): error TS1206: Decorators are not valid here. ==== tests/cases/conformance/decorators/invalid/decoratorOnImportEquals1.ts (1 errors) ==== @@ -13,5 +13,5 @@ tests/cases/conformance/decorators/invalid/decoratorOnImportEquals1.ts(8,5): err ~~~~ import X = M1.X; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS1206: Decorators are not valid on this declaration type. +!!! error TS1206: Decorators are not valid here. } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnImportEquals2.errors.txt b/tests/baselines/reference/decoratorOnImportEquals2.errors.txt index da2bcdf0775..5701afe569b 100644 --- a/tests/baselines/reference/decoratorOnImportEquals2.errors.txt +++ b/tests/baselines/reference/decoratorOnImportEquals2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/invalid/decoratorOnImportEquals2_1.ts(1,1): error TS1206: Decorators are not valid on this declaration type. +tests/cases/conformance/decorators/invalid/decoratorOnImportEquals2_1.ts(1,1): error TS1206: Decorators are not valid here. ==== tests/cases/conformance/decorators/invalid/decoratorOnImportEquals2_1.ts (1 errors) ==== @@ -6,7 +6,7 @@ tests/cases/conformance/decorators/invalid/decoratorOnImportEquals2_1.ts(1,1): e ~~~~ import lib = require('./decoratorOnImportEquals2_0'); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1206: Decorators are not valid on this declaration type. +!!! error TS1206: Decorators are not valid here. declare function dec(target: T): T; ==== tests/cases/conformance/decorators/invalid/decoratorOnImportEquals2_0.ts (0 errors) ==== diff --git a/tests/baselines/reference/decoratorOnInterface.errors.txt b/tests/baselines/reference/decoratorOnInterface.errors.txt index e6df6e15388..055b43fa877 100644 --- a/tests/baselines/reference/decoratorOnInterface.errors.txt +++ b/tests/baselines/reference/decoratorOnInterface.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/invalid/decoratorOnInterface.ts(4,11): error TS1206: Decorators are not valid on this declaration type. +tests/cases/conformance/decorators/invalid/decoratorOnInterface.ts(4,11): error TS1206: Decorators are not valid here. ==== tests/cases/conformance/decorators/invalid/decoratorOnInterface.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/conformance/decorators/invalid/decoratorOnInterface.ts(4,11): error @dec interface I { ~ -!!! error TS1206: Decorators are not valid on this declaration type. +!!! error TS1206: Decorators are not valid here. } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnInternalModule.errors.txt b/tests/baselines/reference/decoratorOnInternalModule.errors.txt index b7a2e832742..2fd92dfb250 100644 --- a/tests/baselines/reference/decoratorOnInternalModule.errors.txt +++ b/tests/baselines/reference/decoratorOnInternalModule.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/invalid/decoratorOnInternalModule.ts(4,8): error TS1206: Decorators are not valid on this declaration type. +tests/cases/conformance/decorators/invalid/decoratorOnInternalModule.ts(4,8): error TS1206: Decorators are not valid here. ==== tests/cases/conformance/decorators/invalid/decoratorOnInternalModule.ts (1 errors) ==== @@ -7,6 +7,6 @@ tests/cases/conformance/decorators/invalid/decoratorOnInternalModule.ts(4,8): er @dec module M { ~ -!!! error TS1206: Decorators are not valid on this declaration type. +!!! error TS1206: Decorators are not valid here. } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnTypeAlias.errors.txt b/tests/baselines/reference/decoratorOnTypeAlias.errors.txt index b6add9cb760..0d3109fe463 100644 --- a/tests/baselines/reference/decoratorOnTypeAlias.errors.txt +++ b/tests/baselines/reference/decoratorOnTypeAlias.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/invalid/decoratorOnTypeAlias.ts(3,1): error TS1206: Decorators are not valid on this declaration type. +tests/cases/conformance/decorators/invalid/decoratorOnTypeAlias.ts(3,1): error TS1206: Decorators are not valid here. ==== tests/cases/conformance/decorators/invalid/decoratorOnTypeAlias.ts (1 errors) ==== @@ -8,4 +8,4 @@ tests/cases/conformance/decorators/invalid/decoratorOnTypeAlias.ts(3,1): error T ~~~~ type T = number; ~~~~~~~~~~~~~~~~ -!!! error TS1206: Decorators are not valid on this declaration type. \ No newline at end of file +!!! error TS1206: Decorators are not valid here. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnVar.errors.txt b/tests/baselines/reference/decoratorOnVar.errors.txt index 243f1006e6c..bd87357edad 100644 --- a/tests/baselines/reference/decoratorOnVar.errors.txt +++ b/tests/baselines/reference/decoratorOnVar.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/decorators/invalid/decoratorOnVar.ts(3,1): error TS1206: Decorators are not valid on this declaration type. +tests/cases/conformance/decorators/invalid/decoratorOnVar.ts(3,1): error TS1206: Decorators are not valid here. ==== tests/cases/conformance/decorators/invalid/decoratorOnVar.ts (1 errors) ==== @@ -8,4 +8,4 @@ tests/cases/conformance/decorators/invalid/decoratorOnVar.ts(3,1): error TS1206: ~~~~ var x: number; ~~~~~~~~~~~~~~ -!!! error TS1206: Decorators are not valid on this declaration type. \ No newline at end of file +!!! error TS1206: Decorators are not valid here. \ No newline at end of file diff --git a/tests/baselines/reference/noDefaultLib.errors.txt b/tests/baselines/reference/noDefaultLib.errors.txt index d7e58eb31f8..6ff03b40f64 100644 --- a/tests/baselines/reference/noDefaultLib.errors.txt +++ b/tests/baselines/reference/noDefaultLib.errors.txt @@ -1,21 +1,17 @@ error TS2318: Cannot find global type 'TypedPropertyDescriptor'. error TS2318: Cannot find global type 'PropertyDecorator'. -error TS2318: Cannot find global type 'PropertyAnnotation'. -error TS2318: Cannot find global type 'ParameterAnnotation'. +error TS2318: Cannot find global type 'ParameterDecorator'. error TS2318: Cannot find global type 'IArguments'. error TS2318: Cannot find global type 'ClassDecorator'. -error TS2318: Cannot find global type 'ClassAnnotation'. error TS2318: Cannot find global type 'Boolean'. tests/cases/compiler/noDefaultLib.ts(4,11): error TS2317: Global type 'Array' must have 1 type parameter(s). !!! error TS2318: Cannot find global type 'TypedPropertyDescriptor'. !!! error TS2318: Cannot find global type 'PropertyDecorator'. -!!! error TS2318: Cannot find global type 'PropertyAnnotation'. -!!! error TS2318: Cannot find global type 'ParameterAnnotation'. +!!! error TS2318: Cannot find global type 'ParameterDecorator'. !!! error TS2318: Cannot find global type 'IArguments'. !!! error TS2318: Cannot find global type 'ClassDecorator'. -!!! error TS2318: Cannot find global type 'ClassAnnotation'. !!! error TS2318: Cannot find global type 'Boolean'. ==== tests/cases/compiler/noDefaultLib.ts (1 errors) ==== /// diff --git a/tests/baselines/reference/parser509698.errors.txt b/tests/baselines/reference/parser509698.errors.txt index e3dd323ec10..21269ca6d60 100644 --- a/tests/baselines/reference/parser509698.errors.txt +++ b/tests/baselines/reference/parser509698.errors.txt @@ -1,33 +1,29 @@ error TS2318: Cannot find global type 'Object'. error TS2318: Cannot find global type 'TypedPropertyDescriptor'. -error TS2318: Cannot find global type 'ParameterAnnotation'. error TS2318: Cannot find global type 'Array'. -error TS2318: Cannot find global type 'ClassAnnotation'. error TS2318: Cannot find global type 'String'. error TS2318: Cannot find global type 'RegExp'. error TS2318: Cannot find global type 'PropertyDecorator'. -error TS2318: Cannot find global type 'PropertyAnnotation'. -error TS2318: Cannot find global type 'ClassDecorator'. +error TS2318: Cannot find global type 'ParameterDecorator'. error TS2318: Cannot find global type 'Boolean'. error TS2318: Cannot find global type 'Number'. error TS2318: Cannot find global type 'IArguments'. error TS2318: Cannot find global type 'Function'. +error TS2318: Cannot find global type 'ClassDecorator'. !!! error TS2318: Cannot find global type 'Object'. !!! error TS2318: Cannot find global type 'TypedPropertyDescriptor'. -!!! error TS2318: Cannot find global type 'ParameterAnnotation'. !!! error TS2318: Cannot find global type 'Array'. -!!! error TS2318: Cannot find global type 'ClassAnnotation'. !!! error TS2318: Cannot find global type 'String'. !!! error TS2318: Cannot find global type 'RegExp'. !!! error TS2318: Cannot find global type 'PropertyDecorator'. -!!! error TS2318: Cannot find global type 'PropertyAnnotation'. -!!! error TS2318: Cannot find global type 'ClassDecorator'. +!!! error TS2318: Cannot find global type 'ParameterDecorator'. !!! error TS2318: Cannot find global type 'Boolean'. !!! error TS2318: Cannot find global type 'Number'. !!! error TS2318: Cannot find global type 'IArguments'. !!! error TS2318: Cannot find global type 'Function'. +!!! error TS2318: Cannot find global type 'ClassDecorator'. ==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509698.ts (0 errors) ==== ///