Migrated decorator checks to call resolution

This commit is contained in:
Ron Buckton 2015-05-21 16:45:23 -07:00
parent db6928e1ce
commit ac447f1f51
51 changed files with 533 additions and 306 deletions

View File

@ -114,10 +114,7 @@ module ts {
let globalIterableType: ObjectType;
let anyArrayType: Type;
let getGlobalClassDecoratorType: () => ObjectType;
let getGlobalParameterDecoratorType: () => ObjectType;
let getGlobalPropertyDecoratorType: () => ObjectType;
let getGlobalMethodDecoratorType: () => ObjectType;
let getGlobalTypedPropertyDescriptorType: () => ObjectType;
let tupleTypes: Map<TupleType> = {};
let unionTypes: Map<UnionType> = {};
@ -3975,8 +3972,8 @@ module ts {
return checkTypeRelatedTo(source, target, subtypeRelation, errorNode, headMessage, containingMessageChain);
}
function checkTypeAssignableTo(source: Type, target: Type, errorNode: Node, headMessage?: DiagnosticMessage): boolean {
return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage);
function checkTypeAssignableTo(source: Type, target: Type, errorNode: Node, headMessage?: DiagnosticMessage, containingMessageChain?: DiagnosticMessageChain): boolean {
return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage, containingMessageChain);
}
function isSignatureAssignableTo(source: Signature, target: Signature): boolean {
@ -6539,7 +6536,7 @@ module ts {
if (node.kind === SyntaxKind.TaggedTemplateExpression) {
checkExpression((<TaggedTemplateExpression>node).template);
}
else {
else if (node.kind !== SyntaxKind.Decorator) {
forEach((<CallExpression>node).arguments, argument => {
checkExpression(argument);
});
@ -6645,6 +6642,41 @@ module ts {
callIsIncomplete = !!templateLiteral.isUnterminated;
}
}
else if (node.kind === SyntaxKind.Decorator) {
let decorator = <Decorator>node;
switch (decorator.parent.kind) {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ClassExpression:
// A class decorator will have one argument (see `ClassDecorator` in core.d.ts)
adjustedArgCount = 1;
typeArguments = undefined;
break;
case SyntaxKind.PropertyDeclaration:
// A property declaration decorator will have two arguments (see
// `PropertyDecorator` in core.d.ts)
adjustedArgCount = 2;
typeArguments = undefined;
break;
case SyntaxKind.MethodDeclaration:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
// A method or accessor declaration decorator will have two or three arguments (see
// `MethodDecorator` in core.d.ts)
adjustedArgCount = signature.parameters.length >= 3 ? 3 : 2;
typeArguments = undefined;
break;
case SyntaxKind.Parameter:
// A parameter declaration decorator will have three arguments (see
// `ParameterDecorator` in core.d.ts)
adjustedArgCount = 3;
typeArguments = undefined;
break;
}
}
else {
let callExpression = <CallExpression>node;
if (!callExpression.arguments) {
@ -6742,11 +6774,8 @@ module ts {
let arg = args[i];
if (arg.kind !== SyntaxKind.OmittedExpression) {
let paramType = getTypeAtPosition(signature, i);
let argType: Type;
if (i === 0 && args[i].parent.kind === SyntaxKind.TaggedTemplateExpression) {
argType = globalTemplateStringsArrayType;
}
else {
let argType = getSyntheticArgumentType(i, arg);
if (argType === undefined) {
// For context sensitive arguments we pass the identityMapper, which is a signal to treat all
// context sensitive function expressions as wildcards
let mapper = excludeArgument && excludeArgument[i] !== undefined ? identityMapper : inferenceMapper;
@ -6773,7 +6802,7 @@ module ts {
getInferredTypes(context);
}
function checkTypeArguments(signature: Signature, typeArguments: TypeNode[], typeArgumentResultTypes: Type[], reportErrors: boolean): boolean {
function checkTypeArguments(signature: Signature, typeArguments: TypeNode[], typeArgumentResultTypes: Type[], reportErrors: boolean, containingMessageChain?: DiagnosticMessageChain): boolean {
let typeParameters = signature.typeParameters;
let typeArgumentsAreAssignable = true;
for (let i = 0; i < typeParameters.length; i++) {
@ -6785,14 +6814,147 @@ module ts {
let constraint = getConstraintOfTypeParameter(typeParameters[i]);
if (constraint) {
typeArgumentsAreAssignable = checkTypeAssignableTo(typeArgument, constraint, reportErrors ? typeArgNode : undefined,
Diagnostics.Type_0_does_not_satisfy_the_constraint_1);
Diagnostics.Type_0_does_not_satisfy_the_constraint_1, containingMessageChain);
}
}
}
return typeArgumentsAreAssignable;
}
function getTypeOfParentOfClassElement(node: ClassElement) {
let classSymbol = getSymbolOfNode(node.parent);
if (node.flags & NodeFlags.Static) {
return getTypeOfSymbol(classSymbol);
}
else {
return getDeclaredTypeOfSymbol(classSymbol);
}
}
function createTypedPropertyDescriptorType(propertyType: Type): Type {
let globalTypedPropertyDescriptorType = getGlobalTypedPropertyDescriptorType();
return globalTypedPropertyDescriptorType !== emptyObjectType
? createTypeReference(<GenericType>globalTypedPropertyDescriptorType, [propertyType])
: emptyObjectType;
}
/**
* Gets the type for a synthetic argument when resolving the first argument for a TaggedTemplateExpression
* or any arguments to a Decorator.
*/
function getSyntheticArgumentType(argumentIndex: number, arg: Expression): Type {
if (arg.parent.kind === SyntaxKind.Decorator) {
let decorator = <Decorator>arg.parent;
let parent = decorator.parent;
if (argumentIndex === 0) {
// The first argument to a decorator is its `target`.
switch (parent.kind) {
case SyntaxKind.ClassDeclaration:
// For a class decorator, the `target` is the type of the class (e.g. the
// "static" or "constructor" side of the class)
let classSymbol = getSymbolOfNode(parent);
return getTypeOfSymbol(classSymbol);
case SyntaxKind.Parameter:
// For a parameter decorator, the `target` is the parent type of the
// parameter's containing method.
parent = parent.parent;
if (parent.kind === SyntaxKind.Constructor) {
let classSymbol = getSymbolOfNode(parent);
return getTypeOfSymbol(classSymbol);
}
// fall-through
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
// For a property or method decorator, the `target` is the
// "static"-side type of the parent of the member if the member is
// declared "static"; otherwise, it is the "instance"-side type of the
// parent of the member.
return getTypeOfParentOfClassElement(<ClassElement>parent);
}
}
else if (argumentIndex === 1) {
// The second argument to a decorator is its `propertyKey`
switch (parent.kind) {
case SyntaxKind.ClassDeclaration:
Debug.fail("Class decorators should not have a second synthetic argument.");
case SyntaxKind.Parameter:
parent = parent.parent;
if (parent.kind === SyntaxKind.Constructor) {
// For a constructor parameter decorator, the `propertyKey` will be `undefined`.
return anyType;
}
// For a non-constructor parameter decorator, the `propertyKey` will be either
// a string or a symbol, based on the name of the parameter's containing method.
// fall-through
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
// The `propertyKey` for a property or method decorator will be a
// string literal type if the member name is an identifier, number, or string;
// otherwise, if the member name is a computed property name it will
// be either string or symbol.
let element = <ClassElement>decorator.parent;
switch (element.name.kind) {
case SyntaxKind.Identifier:
case SyntaxKind.NumericLiteral:
case SyntaxKind.StringLiteral:
return getStringLiteralType(<StringLiteral>element.name);
case SyntaxKind.ComputedPropertyName:
let nameType = checkComputedPropertyName(<ComputedPropertyName>element.name);
if (allConstituentTypesHaveKind(nameType, TypeFlags.ESSymbol)) {
return nameType;
}
else {
return stringType;
}
}
}
}
else if (argumentIndex === 2) {
// The third argument to a decorator is either its `descriptor` for a method decorator
// or its `parameterIndex` for a paramter decorator
switch (parent.kind) {
case SyntaxKind.ClassDeclaration:
Debug.fail("Class decorators should not have a third synthetic argument.");
break;
function checkApplicableSignature(node: CallLikeExpression, args: Expression[], signature: Signature, relation: Map<RelationComparisonResult>, excludeArgument: boolean[], reportErrors: boolean) {
case SyntaxKind.Parameter:
// The `parameterIndex` for a parameter decorator is always a number
return numberType;
case SyntaxKind.PropertyDeclaration:
Debug.fail("Property decorators should not have a third synthetic argument.");
break;
case SyntaxKind.MethodDeclaration:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
// The `descriptor` for a method decorator will be a `TypedPropertyDescriptor<T>`
// for the type of the member.
let propertyType: Type = getTypeOfNode(parent);
return createTypedPropertyDescriptorType(propertyType);
}
}
}
else if (argumentIndex === 0 && arg.parent.kind === SyntaxKind.TaggedTemplateExpression) {
return globalTemplateStringsArrayType;
}
return undefined;
}
function checkApplicableSignature(node: CallLikeExpression, args: Expression[], signature: Signature, relation: Map<RelationComparisonResult>, excludeArgument: boolean[], reportErrors: boolean, containingMessageChain?: DiagnosticMessageChain) {
for (let i = 0; i < args.length; i++) {
let arg = args[i];
if (arg.kind !== SyntaxKind.OmittedExpression) {
@ -6800,15 +6962,16 @@ module ts {
let paramType = getTypeAtPosition(signature, i);
// A tagged template expression provides a special first argument, and string literals get string literal types
// unless we're reporting errors
let argType = i === 0 && node.kind === SyntaxKind.TaggedTemplateExpression
? globalTemplateStringsArrayType
: arg.kind === SyntaxKind.StringLiteral && !reportErrors
let argType = getSyntheticArgumentType(i, arg);
if (argType === undefined) {
argType = arg.kind === SyntaxKind.StringLiteral && !reportErrors
? getStringLiteralType(<StringLiteral>arg)
: checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined);
}
// Use argument expression as error location when reporting errors
if (!checkTypeRelatedTo(argType, paramType, relation, reportErrors ? arg : undefined,
Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1)) {
Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1, containingMessageChain)) {
return false;
}
}
@ -6822,6 +6985,8 @@ module ts {
* If 'node' is a CallExpression or a NewExpression, then its argument list is returned.
* If 'node' is a TaggedTemplateExpression, a new argument list is constructed from the substitution
* expressions, where the first element of the list is the template for error reporting purposes.
* If 'node' is a Decorator, a new argument list is constructed with the decorator
* expression as a placeholder.
*/
function getEffectiveCallArguments(node: CallLikeExpression): Expression[] {
let args: Expression[];
@ -6835,6 +7000,23 @@ module ts {
});
}
}
else if (node.kind === SyntaxKind.Decorator) {
let decorator = <Decorator>node;
switch (decorator.parent.kind) {
case SyntaxKind.ClassDeclaration:
args = [decorator.expression];
break;
case SyntaxKind.PropertyDeclaration:
args = [decorator.expression, decorator.expression];
break;
case SyntaxKind.MethodDeclaration:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.Parameter:
args = [decorator.expression, decorator.expression, decorator.expression];
break;
}
}
else {
args = (<CallExpression>node).arguments || emptyArray;
}
@ -6863,13 +7045,14 @@ module ts {
return callExpression.typeArguments;
}
}
function resolveCall(node: CallLikeExpression, signatures: Signature[], candidatesOutArray: Signature[]): Signature {
function resolveCall(node: CallLikeExpression, signatures: Signature[], candidatesOutArray: Signature[], containingMessageChain?: DiagnosticMessageChain): Signature {
let isTaggedTemplate = node.kind === SyntaxKind.TaggedTemplateExpression;
let isDecorator = node.kind === SyntaxKind.Decorator;
let typeArguments: TypeNode[];
if (!isTaggedTemplate) {
if (!isTaggedTemplate && !isDecorator) {
typeArguments = getEffectiveTypeArguments(<CallExpression>node);
// We already perform checking on the type arguments on the class declaration itself.
@ -6882,7 +7065,7 @@ module ts {
// reorderCandidates fills up the candidates array directly
reorderCandidates(signatures, candidates);
if (!candidates.length) {
error(node, Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
reportError(Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
return resolveErrorCall(node);
}
@ -6900,12 +7083,14 @@ module ts {
// For a tagged template, then the first argument be 'undefined' if necessary
// because it represents a TemplateStringsArray.
let excludeArgument: boolean[];
for (let i = isTaggedTemplate ? 1 : 0; i < args.length; i++) {
if (isContextSensitive(args[i])) {
if (!excludeArgument) {
excludeArgument = new Array(args.length);
if (!isDecorator) {
for (let i = isTaggedTemplate ? 1 : 0; i < args.length; i++) {
if (isContextSensitive(args[i])) {
if (!excludeArgument) {
excludeArgument = new Array(args.length);
}
excludeArgument[i] = true;
}
excludeArgument[i] = true;
}
}
@ -6969,11 +7154,11 @@ module ts {
// in arguments too early. If possible, we'd like to only type them once we know the correct
// overload. However, this matters for the case where the call is correct. When the call is
// an error, we don't need to exclude any arguments, although it would cause no harm to do so.
checkApplicableSignature(node, args, candidateForArgumentError, assignableRelation, /*excludeArgument*/ undefined, /*reportErrors*/ true);
checkApplicableSignature(node, args, candidateForArgumentError, assignableRelation, /*excludeArgument*/ undefined, /*reportErrors*/ true, containingMessageChain);
}
else if (candidateForTypeArgumentError) {
if (!isTaggedTemplate && (<CallExpression>node).typeArguments) {
checkTypeArguments(candidateForTypeArgumentError, (<CallExpression>node).typeArguments, [], /*reportErrors*/ true)
if (!isTaggedTemplate && !isDecorator && (<CallExpression>node).typeArguments) {
checkTypeArguments(candidateForTypeArgumentError, (<CallExpression>node).typeArguments, [], /*reportErrors*/ true, containingMessageChain)
}
else {
Debug.assert(resultOfFailedInference.failedTypeParameterIndex >= 0);
@ -6983,12 +7168,16 @@ module ts {
let diagnosticChainHead = chainDiagnosticMessages(/*details*/ undefined, // details will be provided by call to reportNoCommonSupertypeError
Diagnostics.The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly,
typeToString(failedTypeParameter));
if (containingMessageChain) {
diagnosticChainHead = concatenateDiagnosticMessageChains(containingMessageChain, diagnosticChainHead);
}
reportNoCommonSupertypeError(inferenceCandidates, (<CallExpression>node).expression || (<TaggedTemplateExpression>node).tag, diagnosticChainHead);
}
}
else {
error(node, Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
reportError(Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
}
// No signature was applicable. We have already reported the errors for the invalid signature.
@ -7005,6 +7194,15 @@ module ts {
}
return resolveErrorCall(node);
function reportError(message: DiagnosticMessage, arg0?: string, arg1?: string, arg2?: string): void {
let errorInfo = chainDiagnosticMessages(/*details*/ undefined, message, arg0, arg1, arg2);
if (containingMessageChain) {
errorInfo = concatenateDiagnosticMessageChains(containingMessageChain, errorInfo);
}
diagnostics.add(createDiagnosticForNodeFromMessageChain(node, errorInfo));
}
function chooseOverload(candidates: Signature[], relation: Map<RelationComparisonResult>) {
for (let originalCandidate of candidates) {
@ -7205,6 +7403,55 @@ module ts {
return resolveCall(node, callSignatures, candidatesOutArray);
}
function resolveDecorator(node: Decorator, candidatesOutArray: Signature[]): Signature {
let funcType = checkExpression(node.expression);
let apparentType = getApparentType(funcType);
if (apparentType === unknownType) {
return resolveErrorCall(node);
}
let callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
if (funcType === anyType || (!callSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) {
return resolveUntypedCall(node);
}
let decoratorKind: string;
switch (node.parent.kind) {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ClassExpression:
decoratorKind = "class";
break;
case SyntaxKind.Parameter:
decoratorKind = "parameter";
break;
case SyntaxKind.PropertyDeclaration:
decoratorKind = "property";
break;
case SyntaxKind.MethodDeclaration:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
decoratorKind = "method";
break;
default:
Debug.fail("Invalid decorator target.");
break;
}
let diagnosticChainHead = chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Invalid_expression_for_0_decorator, decoratorKind);
if (!callSignatures.length) {
let errorInfo = chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature);
errorInfo = concatenateDiagnosticMessageChains(diagnosticChainHead, errorInfo);
diagnostics.add(createDiagnosticForNodeFromMessageChain(node, errorInfo));
return resolveErrorCall(node);
}
return resolveCall(node, callSignatures, candidatesOutArray, diagnosticChainHead);
}
// candidatesOutArray is passed by signature help in the language service, and collectCandidates
// must fill it up with the appropriate candidate signatures
function getResolvedSignature(node: CallLikeExpression, candidatesOutArray?: Signature[]): Signature {
@ -7225,6 +7472,9 @@ module ts {
else if (node.kind === SyntaxKind.TaggedTemplateExpression) {
links.resolvedSignature = resolveTaggedTemplateExpression(<TaggedTemplateExpression>node, candidatesOutArray);
}
else if (node.kind === SyntaxKind.Decorator) {
links.resolvedSignature = resolveDecorator(<Decorator>node, candidatesOutArray);
}
else {
Debug.fail("Branch in 'getResolvedSignature' should be unreachable.");
}
@ -8844,35 +9094,58 @@ module ts {
/** Check a decorator */
function checkDecorator(node: Decorator): void {
let expression: Expression = node.expression;
let exprType = checkExpression(expression);
let signature = getResolvedSignature(node);
let returnType = getReturnTypeOfSignature(signature);
if (returnType.flags & TypeFlags.Any) {
return;
}
let expectedReturnType: Type;
let diagnosticChainHead: DiagnosticMessageChain;
let decoratorKind: string;
switch (node.parent.kind) {
case SyntaxKind.ClassDeclaration:
let classSymbol = getSymbolOfNode(node.parent);
let classConstructorType = getTypeOfSymbol(classSymbol);
let classDecoratorType = instantiateSingleCallFunctionType(getGlobalClassDecoratorType(), [classConstructorType]);
checkTypeAssignableTo(exprType, classDecoratorType, node);
expectedReturnType = getUnionType([classConstructorType, voidType]);
decoratorKind = "class";
break;
case SyntaxKind.Parameter:
expectedReturnType = voidType;
decoratorKind = "parameter";
break;
case SyntaxKind.PropertyDeclaration:
checkTypeAssignableTo(exprType, getGlobalPropertyDecoratorType(), node);
expectedReturnType = voidType;
decoratorKind = "property";
break;
case SyntaxKind.MethodDeclaration:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
let methodType = getTypeOfNode(node.parent);
let methodDecoratorType = instantiateSingleCallFunctionType(getGlobalMethodDecoratorType(), [methodType]);
checkTypeAssignableTo(exprType, methodDecoratorType, node);
break;
case SyntaxKind.Parameter:
checkTypeAssignableTo(exprType, getGlobalParameterDecoratorType(), node);
let descriptorType = createTypedPropertyDescriptorType(methodType);
expectedReturnType = getUnionType([descriptorType, voidType]);
decoratorKind = "method";
break;
}
if (expectedReturnType === voidType) {
diagnosticChainHead = chainDiagnosticMessages(
diagnosticChainHead,
Diagnostics.The_return_type_of_a_0_decorator_function_must_be_either_void_or_any,
decoratorKind);
}
diagnosticChainHead = chainDiagnosticMessages(
diagnosticChainHead,
Diagnostics.Invalid_expression_for_0_decorator,
decoratorKind);
checkTypeAssignableTo(returnType, expectedReturnType, node, /*headMessage*/ undefined, diagnosticChainHead);
}
/** Checks a type reference node as an expression. */
function checkTypeNodeAsExpression(node: TypeNode) {
// When we are emitting type metadata for decorators, we need to try to check the type
@ -12043,10 +12316,7 @@ module ts {
globalNumberType = getGlobalType("Number");
globalBooleanType = getGlobalType("Boolean");
globalRegExpType = getGlobalType("RegExp");
getGlobalClassDecoratorType = memoize(() => getGlobalType("ClassDecorator"));
getGlobalPropertyDecoratorType = memoize(() => getGlobalType("PropertyDecorator"));
getGlobalMethodDecoratorType = memoize(() => getGlobalType("MethodDecorator"));
getGlobalParameterDecoratorType = memoize(() => getGlobalType("ParameterDecorator"));
getGlobalTypedPropertyDescriptorType = memoize(() => getGlobalType("TypedPropertyDescriptor", /*arity*/ 1));
// If we're in ES6 mode, load the TemplateStringsArray.
// Otherwise, default to 'unknown' for the purposes of type checking in LS scenarios.

View File

@ -174,6 +174,8 @@ module ts {
Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" },
Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." },
Export_assignment_is_not_supported_when_module_flag_is_system: { code: 1218, category: DiagnosticCategory.Error, key: "Export assignment is not supported when '--module' flag is 'system'." },
The_return_type_of_a_0_decorator_function_must_be_either_void_or_any: { code: 1219, category: DiagnosticCategory.Error, key: "The return type of a {0} decorator function must be either 'void' or 'any'." },
Invalid_expression_for_0_decorator: { code: 1220, category: DiagnosticCategory.Error, key: "Invalid expression for {0} decorator." },
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." },

View File

@ -683,6 +683,14 @@
"category": "Error",
"code": 1218
},
"The return type of a {0} decorator function must be either 'void' or 'any'.": {
"category": "Error",
"code": 1219
},
"Invalid expression for {0} decorator.": {
"category": "Error",
"code": 1220
},
"Duplicate identifier '{0}'.": {
"category": "Error",

View File

@ -753,7 +753,7 @@ module ts {
template: LiteralExpression | TemplateExpression;
}
export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression;
export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression | Decorator;
export interface TypeAssertion extends UnaryExpression {
type: TypeNode;

View File

@ -620,6 +620,9 @@ module ts {
if (node.kind === SyntaxKind.TaggedTemplateExpression) {
return (<TaggedTemplateExpression>node).tag;
}
else if (node.kind === SyntaxKind.Decorator) {
return (<Decorator>node).expression;
}
// Will either be a CallExpression or NewExpression.
return (<CallExpression>node).expression;

View File

@ -1,7 +1,7 @@
//// [tests/cases/conformance/decorators/class/decoratedClassFromExternalModule.ts] ////
//// [decorated.ts]
function decorate() { }
function decorate(target: any) { }
@decorate
export default class Decorated { }
@ -18,7 +18,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
}
};
function decorate() { }
function decorate(target) { }
let Decorated = class {
};
Decorated = __decorate([

View File

@ -1,12 +1,13 @@
=== tests/cases/conformance/decorators/class/decorated.ts ===
function decorate() { }
function decorate(target: any) { }
>decorate : Symbol(decorate, Decl(decorated.ts, 0, 0))
>target : Symbol(target, Decl(decorated.ts, 0, 18))
@decorate
>decorate : Symbol(decorate, Decl(decorated.ts, 0, 0))
export default class Decorated { }
>Decorated : Symbol(Decorated, Decl(decorated.ts, 0, 23))
>Decorated : Symbol(Decorated, Decl(decorated.ts, 0, 34))
=== tests/cases/conformance/decorators/class/undecorated.ts ===
import Decorated from 'decorated';

View File

@ -1,9 +1,10 @@
=== tests/cases/conformance/decorators/class/decorated.ts ===
function decorate() { }
>decorate : () => void
function decorate(target: any) { }
>decorate : (target: any) => void
>target : any
@decorate
>decorate : () => void
>decorate : (target: any) => void
export default class Decorated { }
>Decorated : Decorated

View File

@ -8,7 +8,7 @@ tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts(9,14):
}
class A {
@(x => {
@((x, p) => {
var a = 3;
func(a);
~

View File

@ -5,7 +5,7 @@ function func(s: string): void {
}
class A {
@(x => {
@((x, p) => {
var a = 3;
func(a);
return x;
@ -34,7 +34,7 @@ var A = (function () {
};
Object.defineProperty(A.prototype, "m",
__decorate([
(function (x) {
(function (x, p) {
var a = 3;
func(a);
return x;

View File

@ -9,7 +9,7 @@ export var test = 'abc';
import { test } from './a';
function filter(handler: any) {
return function (target: any) {
return function (target: any, propertyKey: string) {
// ...
};
}
@ -35,7 +35,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
};
var a_1 = require('./a');
function filter(handler) {
return function (target) {
return function (target, propertyKey) {
// ...
};
}

View File

@ -12,8 +12,9 @@ function filter(handler: any) {
>filter : Symbol(filter, Decl(b.ts, 0, 27))
>handler : Symbol(handler, Decl(b.ts, 2, 16))
return function (target: any) {
return function (target: any, propertyKey: string) {
>target : Symbol(target, Decl(b.ts, 3, 21))
>propertyKey : Symbol(propertyKey, Decl(b.ts, 3, 33))
// ...
};

View File

@ -10,12 +10,13 @@ import { test } from './a';
>test : string
function filter(handler: any) {
>filter : (handler: any) => (target: any) => void
>filter : (handler: any) => (target: any, propertyKey: string) => void
>handler : any
return function (target: any) {
>function (target: any) { // ... } : (target: any) => void
return function (target: any, propertyKey: string) {
>function (target: any, propertyKey: string) { // ... } : (target: any, propertyKey: string) => void
>target : any
>propertyKey : string
// ...
};
@ -25,8 +26,8 @@ class Wat {
>Wat : Wat
@filter(() => test == 'abc')
>filter(() => test == 'abc') : (target: any) => void
>filter : (handler: any) => (target: any) => void
>filter(() => test == 'abc') : (target: any, propertyKey: string) => void
>filter : (handler: any) => (target: any, propertyKey: string) => void
>() => test == 'abc' : () => boolean
>test == 'abc' : boolean
>test : string

View File

@ -1,4 +1,5 @@
tests/cases/conformance/decorators/class/decoratorOnClass8.ts(3,1): error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type '(target: typeof C) => void | typeof C'.
tests/cases/conformance/decorators/class/decoratorOnClass8.ts(3,1): error TS1220: Invalid expression for class decorator.
Supplied parameters do not match any signature of call target.
==== tests/cases/conformance/decorators/class/decoratorOnClass8.ts (1 errors) ====
@ -6,6 +7,7 @@ tests/cases/conformance/decorators/class/decoratorOnClass8.ts(3,1): error TS2322
@dec()
~~~~~~
!!! error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type '(target: typeof C) => void | typeof C'.
!!! error TS1220: Invalid expression for class decorator.
!!! error TS1220: Supplied parameters do not match any signature of call target.
class C {
}

View File

@ -1,7 +1,6 @@
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>) => void | TypedPropertyDescriptor<() => void>'.
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(4,6): error TS1220: Invalid expression for method decorator.
Argument of type 'C' is not assignable to parameter of type 'Function'.
Property 'apply' is missing in type 'C'.
==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod10.ts (1 errors) ====
@ -9,9 +8,8 @@ tests/cases/conformance/decorators/class/method/decoratorOnClassMethod10.ts(4,5)
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>) => void | TypedPropertyDescriptor<() => void>'.
!!! 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'.
~~~
!!! error TS1220: Invalid expression for method decorator.
!!! error TS1220: Argument of type 'C' is not assignable to parameter of type 'Function'.
!!! error TS1220: Property 'apply' is missing in type 'C'.
}

View File

@ -1,5 +1,5 @@
//// [decoratorOnClassMethod13.ts]
declare function dec(): <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>;
declare function dec<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>;
class C {
@dec ["1"]() { }

View File

@ -1,17 +1,17 @@
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod13.ts ===
declare function dec(): <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>;
declare function dec<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>;
>dec : Symbol(dec, Decl(decoratorOnClassMethod13.ts, 0, 0))
>T : Symbol(T, Decl(decoratorOnClassMethod13.ts, 0, 25))
>target : Symbol(target, Decl(decoratorOnClassMethod13.ts, 0, 28))
>propertyKey : Symbol(propertyKey, Decl(decoratorOnClassMethod13.ts, 0, 40))
>descriptor : Symbol(descriptor, Decl(decoratorOnClassMethod13.ts, 0, 61))
>T : Symbol(T, Decl(decoratorOnClassMethod13.ts, 0, 21))
>target : Symbol(target, Decl(decoratorOnClassMethod13.ts, 0, 24))
>propertyKey : Symbol(propertyKey, Decl(decoratorOnClassMethod13.ts, 0, 36))
>descriptor : Symbol(descriptor, Decl(decoratorOnClassMethod13.ts, 0, 57))
>TypedPropertyDescriptor : Symbol(TypedPropertyDescriptor, Decl(lib.d.ts, 1171, 36))
>T : Symbol(T, Decl(decoratorOnClassMethod13.ts, 0, 25))
>T : Symbol(T, Decl(decoratorOnClassMethod13.ts, 0, 21))
>TypedPropertyDescriptor : Symbol(TypedPropertyDescriptor, Decl(lib.d.ts, 1171, 36))
>T : Symbol(T, Decl(decoratorOnClassMethod13.ts, 0, 25))
>T : Symbol(T, Decl(decoratorOnClassMethod13.ts, 0, 21))
class C {
>C : Symbol(C, Decl(decoratorOnClassMethod13.ts, 0, 132))
>C : Symbol(C, Decl(decoratorOnClassMethod13.ts, 0, 126))
@dec ["1"]() { }
>dec : Symbol(dec, Decl(decoratorOnClassMethod13.ts, 0, 0))

View File

@ -1,6 +1,6 @@
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod13.ts ===
declare function dec(): <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>;
>dec : () => <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
declare function dec<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>;
>dec : <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
>T : T
>target : any
>propertyKey : string
@ -14,10 +14,10 @@ class C {
>C : C
@dec ["1"]() { }
>dec : () => <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
>dec : <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
>"1" : string
@dec ["b"]() { }
>dec : () => <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
>dec : <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
>"b" : string
}

View File

@ -0,0 +1,13 @@
tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts(4,5): error TS1220: Invalid expression for method decorator.
Supplied parameters do not match any signature of call target.
==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts (1 errors) ====
declare function dec(): <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>;
class C {
@dec ["method"]() {}
~~~~
!!! error TS1220: Invalid expression for method decorator.
!!! error TS1220: Supplied parameters do not match any signature of call target.
}

View File

@ -1,18 +0,0 @@
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts ===
declare function dec(): <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>;
>dec : Symbol(dec, Decl(decoratorOnClassMethod6.ts, 0, 0))
>T : Symbol(T, Decl(decoratorOnClassMethod6.ts, 0, 25))
>target : Symbol(target, Decl(decoratorOnClassMethod6.ts, 0, 28))
>propertyKey : Symbol(propertyKey, Decl(decoratorOnClassMethod6.ts, 0, 40))
>descriptor : Symbol(descriptor, Decl(decoratorOnClassMethod6.ts, 0, 61))
>TypedPropertyDescriptor : Symbol(TypedPropertyDescriptor, Decl(lib.d.ts, 1171, 36))
>T : Symbol(T, Decl(decoratorOnClassMethod6.ts, 0, 25))
>TypedPropertyDescriptor : Symbol(TypedPropertyDescriptor, Decl(lib.d.ts, 1171, 36))
>T : Symbol(T, Decl(decoratorOnClassMethod6.ts, 0, 25))
class C {
>C : Symbol(C, Decl(decoratorOnClassMethod6.ts, 0, 132))
@dec ["method"]() {}
>dec : Symbol(dec, Decl(decoratorOnClassMethod6.ts, 0, 0))
}

View File

@ -1,19 +0,0 @@
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts ===
declare function dec(): <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>;
>dec : () => <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
>T : T
>target : any
>propertyKey : string
>descriptor : TypedPropertyDescriptor<T>
>TypedPropertyDescriptor : TypedPropertyDescriptor<T>
>T : T
>TypedPropertyDescriptor : TypedPropertyDescriptor<T>
>T : T
class C {
>C : C
@dec ["method"]() {}
>dec : () => <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>
>"method" : string
}

View File

@ -0,0 +1,13 @@
tests/cases/conformance/decorators/class/method/decoratorOnClassMethod8.ts(4,5): error TS1220: Invalid expression for method decorator.
Supplied parameters do not match any signature of call target.
==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod8.ts (1 errors) ====
declare function dec<T>(target: T): T;
class C {
@dec method() {}
~~~~
!!! error TS1220: Invalid expression for method decorator.
!!! error TS1220: Supplied parameters do not match any signature of call target.
}

View File

@ -1,15 +0,0 @@
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod8.ts ===
declare function dec<T>(target: T): T;
>dec : Symbol(dec, Decl(decoratorOnClassMethod8.ts, 0, 0))
>T : Symbol(T, Decl(decoratorOnClassMethod8.ts, 0, 21))
>target : Symbol(target, Decl(decoratorOnClassMethod8.ts, 0, 24))
>T : Symbol(T, Decl(decoratorOnClassMethod8.ts, 0, 21))
>T : Symbol(T, Decl(decoratorOnClassMethod8.ts, 0, 21))
class C {
>C : Symbol(C, Decl(decoratorOnClassMethod8.ts, 0, 38))
@dec method() {}
>dec : Symbol(dec, Decl(decoratorOnClassMethod8.ts, 0, 0))
>method : Symbol(method, Decl(decoratorOnClassMethod8.ts, 2, 9))
}

View File

@ -1,15 +0,0 @@
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod8.ts ===
declare function dec<T>(target: T): T;
>dec : <T>(target: T) => T
>T : T
>target : T
>T : T
>T : T
class C {
>C : C
@dec method() {}
>dec : <T>(target: T) => T
>method : () => void
}

View File

@ -1,5 +1,5 @@
//// [decoratorOnClassMethodParameter1.ts]
declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void;
declare function dec(target: Object, propertyKey: string | symbol, parameterIndex: number): void;
class C {
method(@dec p: number) {}

View File

@ -1,13 +1,13 @@
=== tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodParameter1.ts ===
declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void;
declare function dec(target: Object, propertyKey: string | symbol, parameterIndex: number): void;
>dec : Symbol(dec, Decl(decoratorOnClassMethodParameter1.ts, 0, 0))
>target : Symbol(target, Decl(decoratorOnClassMethodParameter1.ts, 0, 21))
>Function : Symbol(Function, Decl(lib.d.ts, 223, 38), Decl(lib.d.ts, 269, 11))
>propertyKey : Symbol(propertyKey, Decl(decoratorOnClassMethodParameter1.ts, 0, 38))
>parameterIndex : Symbol(parameterIndex, Decl(decoratorOnClassMethodParameter1.ts, 0, 68))
>Object : Symbol(Object, Decl(lib.d.ts, 92, 1), Decl(lib.d.ts, 223, 11))
>propertyKey : Symbol(propertyKey, Decl(decoratorOnClassMethodParameter1.ts, 0, 36))
>parameterIndex : Symbol(parameterIndex, Decl(decoratorOnClassMethodParameter1.ts, 0, 66))
class C {
>C : Symbol(C, Decl(decoratorOnClassMethodParameter1.ts, 0, 99))
>C : Symbol(C, Decl(decoratorOnClassMethodParameter1.ts, 0, 97))
method(@dec p: number) {}
>method : Symbol(method, Decl(decoratorOnClassMethodParameter1.ts, 2, 9))

View File

@ -1,8 +1,8 @@
=== tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodParameter1.ts ===
declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void;
>dec : (target: Function, propertyKey: string | symbol, parameterIndex: number) => void
>target : Function
>Function : Function
declare function dec(target: Object, propertyKey: string | symbol, parameterIndex: number): void;
>dec : (target: Object, propertyKey: string | symbol, parameterIndex: number) => void
>target : Object
>Object : Object
>propertyKey : string | symbol
>parameterIndex : number
@ -11,6 +11,6 @@ class C {
method(@dec p: number) {}
>method : (p: number) => void
>dec : (target: Function, propertyKey: string | symbol, parameterIndex: number) => void
>dec : (target: Object, propertyKey: string | symbol, parameterIndex: number) => void
>p : number
}

View File

@ -0,0 +1,13 @@
tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts(4,5): error TS1220: Invalid expression for property decorator.
Supplied parameters do not match any signature of call target.
==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts (1 errors) ====
declare function dec(): <T>(target: any, propertyKey: string) => void;
class C {
@dec prop;
~~~~
!!! error TS1220: Invalid expression for property decorator.
!!! error TS1220: Supplied parameters do not match any signature of call target.
}

View File

@ -1,14 +0,0 @@
=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts ===
declare function dec(): <T>(target: any, propertyKey: string) => void;
>dec : Symbol(dec, Decl(decoratorOnClassProperty11.ts, 0, 0))
>T : Symbol(T, Decl(decoratorOnClassProperty11.ts, 0, 25))
>target : Symbol(target, Decl(decoratorOnClassProperty11.ts, 0, 28))
>propertyKey : Symbol(propertyKey, Decl(decoratorOnClassProperty11.ts, 0, 40))
class C {
>C : Symbol(C, Decl(decoratorOnClassProperty11.ts, 0, 70))
@dec prop;
>dec : Symbol(dec, Decl(decoratorOnClassProperty11.ts, 0, 0))
>prop : Symbol(prop, Decl(decoratorOnClassProperty11.ts, 2, 9))
}

View File

@ -1,14 +0,0 @@
=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts ===
declare function dec(): <T>(target: any, propertyKey: string) => void;
>dec : () => <T>(target: any, propertyKey: string) => void
>T : T
>target : any
>propertyKey : string
class C {
>C : C
@dec prop;
>dec : () => <T>(target: any, propertyKey: string) => void
>prop : any
}

View File

@ -0,0 +1,13 @@
tests/cases/conformance/decorators/class/property/decoratorOnClassProperty6.ts(4,5): error TS1220: Invalid expression for property decorator.
Supplied parameters do not match any signature of call target.
==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty6.ts (1 errors) ====
declare function dec(target: Function): void;
class C {
@dec prop;
~~~~
!!! error TS1220: Invalid expression for property decorator.
!!! error TS1220: Supplied parameters do not match any signature of call target.
}

View File

@ -1,13 +0,0 @@
=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty6.ts ===
declare function dec(target: Function): void;
>dec : Symbol(dec, Decl(decoratorOnClassProperty6.ts, 0, 0))
>target : Symbol(target, Decl(decoratorOnClassProperty6.ts, 0, 21))
>Function : Symbol(Function, Decl(lib.d.ts, 223, 38), Decl(lib.d.ts, 269, 11))
class C {
>C : Symbol(C, Decl(decoratorOnClassProperty6.ts, 0, 45))
@dec prop;
>dec : Symbol(dec, Decl(decoratorOnClassProperty6.ts, 0, 0))
>prop : Symbol(prop, Decl(decoratorOnClassProperty6.ts, 2, 9))
}

View File

@ -1,13 +0,0 @@
=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty6.ts ===
declare function dec(target: Function): void;
>dec : (target: Function) => void
>target : Function
>Function : Function
class C {
>C : C
@dec prop;
>dec : (target: Function) => void
>prop : any
}

View File

@ -1,4 +1,5 @@
tests/cases/conformance/decorators/class/property/decoratorOnClassProperty7.ts(4,5): error TS2322: Type '(target: Function, propertyKey: string | symbol, paramIndex: number) => void' is not assignable to type '(target: Object, propertyKey: string | symbol) => void'.
tests/cases/conformance/decorators/class/property/decoratorOnClassProperty7.ts(4,5): error TS1220: Invalid expression for property decorator.
Supplied parameters do not match any signature of call target.
==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty7.ts (1 errors) ====
@ -7,5 +8,6 @@ tests/cases/conformance/decorators/class/property/decoratorOnClassProperty7.ts(4
class C {
@dec prop;
~~~~
!!! error TS2322: Type '(target: Function, propertyKey: string | symbol, paramIndex: number) => void' is not assignable to type '(target: Object, propertyKey: string | symbol) => void'.
!!! error TS1220: Invalid expression for property decorator.
!!! error TS1220: Supplied parameters do not match any signature of call target.
}

View File

@ -1,7 +1,17 @@
error TS2318: Cannot find global type 'ClassDecorator'.
error TS2318: Cannot find global type 'TypedPropertyDescriptor'.
!!! error TS2318: Cannot find global type 'ClassDecorator'.
!!! error TS2318: Cannot find global type 'TypedPropertyDescriptor'.
==== tests/cases/conformance/decorators/b.ts (0 errors) ====
/// <reference path="a.ts" />
declare function dec(t, k, d);
class C {
@dec
method() {}
}
==== tests/cases/conformance/decorators/a.ts (0 errors) ====
interface Object { }
@ -12,12 +22,4 @@ error TS2318: Cannot find global type 'ClassDecorator'.
interface Function { }
interface RegExp { }
interface IArguments { }
==== tests/cases/conformance/decorators/b.ts (0 errors) ====
declare var dec: any;
@dec
class C {
}

View File

@ -12,10 +12,12 @@ interface RegExp { }
interface IArguments { }
//// [b.ts]
declare var dec: any;
/// <reference path="a.ts" />
declare function dec(t, k, d);
@dec
class C {
@dec
method() {}
}
@ -30,11 +32,14 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
}
};
/// <reference path="a.ts" />
var C = (function () {
function C() {
}
C = __decorate([
dec
], C);
C.prototype.method = function () { };
Object.defineProperty(C.prototype, "method",
__decorate([
dec
], C.prototype, "method", Object.getOwnPropertyDescriptor(C.prototype, "method")));
return C;
})();

View File

@ -1,6 +1,6 @@
//// [noEmitHelpers2.ts]
function decorator() { }
declare var decorator: any;
@decorator
class A {
@ -9,7 +9,6 @@ class A {
}
//// [noEmitHelpers2.js]
function decorator() { }
var A = (function () {
function A(a, b) {
}

View File

@ -1,17 +1,17 @@
=== tests/cases/compiler/noEmitHelpers2.ts ===
function decorator() { }
>decorator : Symbol(decorator, Decl(noEmitHelpers2.ts, 0, 0))
declare var decorator: any;
>decorator : Symbol(decorator, Decl(noEmitHelpers2.ts, 1, 11))
@decorator
>decorator : Symbol(decorator, Decl(noEmitHelpers2.ts, 0, 0))
>decorator : Symbol(decorator, Decl(noEmitHelpers2.ts, 1, 11))
class A {
>A : Symbol(A, Decl(noEmitHelpers2.ts, 1, 24))
>A : Symbol(A, Decl(noEmitHelpers2.ts, 1, 27))
constructor(a: number, @decorator b: string) {
>a : Symbol(a, Decl(noEmitHelpers2.ts, 5, 16))
>decorator : Symbol(decorator, Decl(noEmitHelpers2.ts, 0, 0))
>decorator : Symbol(decorator, Decl(noEmitHelpers2.ts, 1, 11))
>b : Symbol(b, Decl(noEmitHelpers2.ts, 5, 26))
}
}

View File

@ -1,17 +1,17 @@
=== tests/cases/compiler/noEmitHelpers2.ts ===
function decorator() { }
>decorator : () => void
declare var decorator: any;
>decorator : any
@decorator
>decorator : () => void
>decorator : any
class A {
>A : A
constructor(a: number, @decorator b: string) {
>a : number
>decorator : () => void
>decorator : any
>b : string
}
}

View File

@ -3,8 +3,8 @@ declare function ClassDecorator1(target: Function): void;
declare function ClassDecorator2(x: number): (target: Function) => void;
declare function PropertyDecorator1(target: Object, key: string | symbol, descriptor?: PropertyDescriptor): void;
declare function PropertyDecorator2(x: number): (target: Object, key: string | symbol, descriptor?: PropertyDescriptor) => void;
declare function ParameterDecorator1(target: Function, key: string | symbol, paramIndex: number): void;
declare function ParameterDecorator2(x: number): (target: Function, key: string | symbol, paramIndex: number) => void;
declare function ParameterDecorator1(target: Object, key: string | symbol, paramIndex: number): void;
declare function ParameterDecorator2(x: number): (target: Object, key: string | symbol, paramIndex: number) => void;
@ClassDecorator1
@ClassDecorator2(10)

View File

@ -26,8 +26,8 @@ sourceFile:sourceMapValidationDecorators.ts
>declare function ClassDecorator2(x: number): (target: Function) => void;
>declare function PropertyDecorator1(target: Object, key: string | symbol, descriptor?: PropertyDescriptor): void;
>declare function PropertyDecorator2(x: number): (target: Object, key: string | symbol, descriptor?: PropertyDescriptor) => void;
>declare function ParameterDecorator1(target: Function, key: string | symbol, paramIndex: number): void;
>declare function ParameterDecorator2(x: number): (target: Function, key: string | symbol, paramIndex: number) => void;
>declare function ParameterDecorator1(target: Object, key: string | symbol, paramIndex: number): void;
>declare function ParameterDecorator2(x: number): (target: Object, key: string | symbol, paramIndex: number) => void;
>
>
1 >Emitted(12, 1) Source(8, 1) + SourceIndex(0)

View File

@ -27,20 +27,20 @@ declare function PropertyDecorator2(x: number): (target: Object, key: string | s
>descriptor : Symbol(descriptor, Decl(sourceMapValidationDecorators.ts, 3, 86))
>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(lib.d.ts, 79, 66))
declare function ParameterDecorator1(target: Function, key: string | symbol, paramIndex: number): void;
declare function ParameterDecorator1(target: Object, key: string | symbol, paramIndex: number): void;
>ParameterDecorator1 : Symbol(ParameterDecorator1, Decl(sourceMapValidationDecorators.ts, 3, 128))
>target : Symbol(target, Decl(sourceMapValidationDecorators.ts, 4, 37))
>Function : Symbol(Function, Decl(lib.d.ts, 223, 38), Decl(lib.d.ts, 269, 11))
>key : Symbol(key, Decl(sourceMapValidationDecorators.ts, 4, 54))
>paramIndex : Symbol(paramIndex, Decl(sourceMapValidationDecorators.ts, 4, 76))
>Object : Symbol(Object, Decl(lib.d.ts, 92, 1), Decl(lib.d.ts, 223, 11))
>key : Symbol(key, Decl(sourceMapValidationDecorators.ts, 4, 52))
>paramIndex : Symbol(paramIndex, Decl(sourceMapValidationDecorators.ts, 4, 74))
declare function ParameterDecorator2(x: number): (target: Function, key: string | symbol, paramIndex: number) => void;
>ParameterDecorator2 : Symbol(ParameterDecorator2, Decl(sourceMapValidationDecorators.ts, 4, 103))
declare function ParameterDecorator2(x: number): (target: Object, key: string | symbol, paramIndex: number) => void;
>ParameterDecorator2 : Symbol(ParameterDecorator2, Decl(sourceMapValidationDecorators.ts, 4, 101))
>x : Symbol(x, Decl(sourceMapValidationDecorators.ts, 5, 37))
>target : Symbol(target, Decl(sourceMapValidationDecorators.ts, 5, 50))
>Function : Symbol(Function, Decl(lib.d.ts, 223, 38), Decl(lib.d.ts, 269, 11))
>key : Symbol(key, Decl(sourceMapValidationDecorators.ts, 5, 67))
>paramIndex : Symbol(paramIndex, Decl(sourceMapValidationDecorators.ts, 5, 89))
>Object : Symbol(Object, Decl(lib.d.ts, 92, 1), Decl(lib.d.ts, 223, 11))
>key : Symbol(key, Decl(sourceMapValidationDecorators.ts, 5, 65))
>paramIndex : Symbol(paramIndex, Decl(sourceMapValidationDecorators.ts, 5, 87))
@ClassDecorator1
>ClassDecorator1 : Symbol(ClassDecorator1, Decl(sourceMapValidationDecorators.ts, 0, 0))
@ -49,14 +49,14 @@ declare function ParameterDecorator2(x: number): (target: Function, key: string
>ClassDecorator2 : Symbol(ClassDecorator2, Decl(sourceMapValidationDecorators.ts, 0, 57))
class Greeter {
>Greeter : Symbol(Greeter, Decl(sourceMapValidationDecorators.ts, 5, 118))
>Greeter : Symbol(Greeter, Decl(sourceMapValidationDecorators.ts, 5, 116))
constructor(
@ParameterDecorator1
>ParameterDecorator1 : Symbol(ParameterDecorator1, Decl(sourceMapValidationDecorators.ts, 3, 128))
@ParameterDecorator2(20)
>ParameterDecorator2 : Symbol(ParameterDecorator2, Decl(sourceMapValidationDecorators.ts, 4, 103))
>ParameterDecorator2 : Symbol(ParameterDecorator2, Decl(sourceMapValidationDecorators.ts, 4, 101))
public greeting: string,
>greeting : Symbol(greeting, Decl(sourceMapValidationDecorators.ts, 10, 16))
@ -65,7 +65,7 @@ class Greeter {
>ParameterDecorator1 : Symbol(ParameterDecorator1, Decl(sourceMapValidationDecorators.ts, 3, 128))
@ParameterDecorator2(30)
>ParameterDecorator2 : Symbol(ParameterDecorator2, Decl(sourceMapValidationDecorators.ts, 4, 103))
>ParameterDecorator2 : Symbol(ParameterDecorator2, Decl(sourceMapValidationDecorators.ts, 4, 101))
...b: string[]) {
>b : Symbol(b, Decl(sourceMapValidationDecorators.ts, 13, 30))
@ -82,7 +82,7 @@ class Greeter {
return "<h1>" + this.greeting + "</h1>";
>this.greeting : Symbol(greeting, Decl(sourceMapValidationDecorators.ts, 10, 16))
>this : Symbol(Greeter, Decl(sourceMapValidationDecorators.ts, 5, 118))
>this : Symbol(Greeter, Decl(sourceMapValidationDecorators.ts, 5, 116))
>greeting : Symbol(greeting, Decl(sourceMapValidationDecorators.ts, 10, 16))
}
@ -111,14 +111,14 @@ class Greeter {
>ParameterDecorator1 : Symbol(ParameterDecorator1, Decl(sourceMapValidationDecorators.ts, 3, 128))
@ParameterDecorator2(70)
>ParameterDecorator2 : Symbol(ParameterDecorator2, Decl(sourceMapValidationDecorators.ts, 4, 103))
>ParameterDecorator2 : Symbol(ParameterDecorator2, Decl(sourceMapValidationDecorators.ts, 4, 101))
x: number) {
>x : Symbol(x, Decl(sourceMapValidationDecorators.ts, 34, 15))
return this.greeting;
>this.greeting : Symbol(greeting, Decl(sourceMapValidationDecorators.ts, 10, 16))
>this : Symbol(Greeter, Decl(sourceMapValidationDecorators.ts, 5, 118))
>this : Symbol(Greeter, Decl(sourceMapValidationDecorators.ts, 5, 116))
>greeting : Symbol(greeting, Decl(sourceMapValidationDecorators.ts, 10, 16))
}
@ -133,7 +133,7 @@ class Greeter {
return this.greeting;
>this.greeting : Symbol(greeting, Decl(sourceMapValidationDecorators.ts, 10, 16))
>this : Symbol(Greeter, Decl(sourceMapValidationDecorators.ts, 5, 118))
>this : Symbol(Greeter, Decl(sourceMapValidationDecorators.ts, 5, 116))
>greeting : Symbol(greeting, Decl(sourceMapValidationDecorators.ts, 10, 16))
}
@ -144,14 +144,14 @@ class Greeter {
>ParameterDecorator1 : Symbol(ParameterDecorator1, Decl(sourceMapValidationDecorators.ts, 3, 128))
@ParameterDecorator2(90)
>ParameterDecorator2 : Symbol(ParameterDecorator2, Decl(sourceMapValidationDecorators.ts, 4, 103))
>ParameterDecorator2 : Symbol(ParameterDecorator2, Decl(sourceMapValidationDecorators.ts, 4, 101))
greetings: string) {
>greetings : Symbol(greetings, Decl(sourceMapValidationDecorators.ts, 47, 18))
this.greeting = greetings;
>this.greeting : Symbol(greeting, Decl(sourceMapValidationDecorators.ts, 10, 16))
>this : Symbol(Greeter, Decl(sourceMapValidationDecorators.ts, 5, 118))
>this : Symbol(Greeter, Decl(sourceMapValidationDecorators.ts, 5, 116))
>greeting : Symbol(greeting, Decl(sourceMapValidationDecorators.ts, 10, 16))
>greetings : Symbol(greetings, Decl(sourceMapValidationDecorators.ts, 47, 18))
}

View File

@ -27,18 +27,18 @@ declare function PropertyDecorator2(x: number): (target: Object, key: string | s
>descriptor : PropertyDescriptor
>PropertyDescriptor : PropertyDescriptor
declare function ParameterDecorator1(target: Function, key: string | symbol, paramIndex: number): void;
>ParameterDecorator1 : (target: Function, key: string | symbol, paramIndex: number) => void
>target : Function
>Function : Function
declare function ParameterDecorator1(target: Object, key: string | symbol, paramIndex: number): void;
>ParameterDecorator1 : (target: Object, key: string | symbol, paramIndex: number) => void
>target : Object
>Object : Object
>key : string | symbol
>paramIndex : number
declare function ParameterDecorator2(x: number): (target: Function, key: string | symbol, paramIndex: number) => void;
>ParameterDecorator2 : (x: number) => (target: Function, key: string | symbol, paramIndex: number) => void
declare function ParameterDecorator2(x: number): (target: Object, key: string | symbol, paramIndex: number) => void;
>ParameterDecorator2 : (x: number) => (target: Object, key: string | symbol, paramIndex: number) => void
>x : number
>target : Function
>Function : Function
>target : Object
>Object : Object
>key : string | symbol
>paramIndex : number
@ -55,22 +55,22 @@ class Greeter {
constructor(
@ParameterDecorator1
>ParameterDecorator1 : (target: Function, key: string | symbol, paramIndex: number) => void
>ParameterDecorator1 : (target: Object, key: string | symbol, paramIndex: number) => void
@ParameterDecorator2(20)
>ParameterDecorator2(20) : (target: Function, key: string | symbol, paramIndex: number) => void
>ParameterDecorator2 : (x: number) => (target: Function, key: string | symbol, paramIndex: number) => void
>ParameterDecorator2(20) : (target: Object, key: string | symbol, paramIndex: number) => void
>ParameterDecorator2 : (x: number) => (target: Object, key: string | symbol, paramIndex: number) => void
>20 : number
public greeting: string,
>greeting : string
@ParameterDecorator1
>ParameterDecorator1 : (target: Function, key: string | symbol, paramIndex: number) => void
>ParameterDecorator1 : (target: Object, key: string | symbol, paramIndex: number) => void
@ParameterDecorator2(30)
>ParameterDecorator2(30) : (target: Function, key: string | symbol, paramIndex: number) => void
>ParameterDecorator2 : (x: number) => (target: Function, key: string | symbol, paramIndex: number) => void
>ParameterDecorator2(30) : (target: Object, key: string | symbol, paramIndex: number) => void
>ParameterDecorator2 : (x: number) => (target: Object, key: string | symbol, paramIndex: number) => void
>30 : number
...b: string[]) {
@ -125,11 +125,11 @@ class Greeter {
>fn : (x: number) => string
@ParameterDecorator1
>ParameterDecorator1 : (target: Function, key: string | symbol, paramIndex: number) => void
>ParameterDecorator1 : (target: Object, key: string | symbol, paramIndex: number) => void
@ParameterDecorator2(70)
>ParameterDecorator2(70) : (target: Function, key: string | symbol, paramIndex: number) => void
>ParameterDecorator2 : (x: number) => (target: Function, key: string | symbol, paramIndex: number) => void
>ParameterDecorator2(70) : (target: Object, key: string | symbol, paramIndex: number) => void
>ParameterDecorator2 : (x: number) => (target: Object, key: string | symbol, paramIndex: number) => void
>70 : number
x: number) {
@ -162,11 +162,11 @@ class Greeter {
>greetings : string
@ParameterDecorator1
>ParameterDecorator1 : (target: Function, key: string | symbol, paramIndex: number) => void
>ParameterDecorator1 : (target: Object, key: string | symbol, paramIndex: number) => void
@ParameterDecorator2(90)
>ParameterDecorator2(90) : (target: Function, key: string | symbol, paramIndex: number) => void
>ParameterDecorator2 : (x: number) => (target: Function, key: string | symbol, paramIndex: number) => void
>ParameterDecorator2(90) : (target: Object, key: string | symbol, paramIndex: number) => void
>ParameterDecorator2 : (x: number) => (target: Object, key: string | symbol, paramIndex: number) => void
>90 : number
greetings: string) {

View File

@ -2,7 +2,7 @@
// @emitdecoratormetadata: true
// @target: es5
function decorator() { }
declare var decorator: any;
@decorator
class A {

View File

@ -4,8 +4,8 @@ declare function ClassDecorator1(target: Function): void;
declare function ClassDecorator2(x: number): (target: Function) => void;
declare function PropertyDecorator1(target: Object, key: string | symbol, descriptor?: PropertyDescriptor): void;
declare function PropertyDecorator2(x: number): (target: Object, key: string | symbol, descriptor?: PropertyDescriptor) => void;
declare function ParameterDecorator1(target: Function, key: string | symbol, paramIndex: number): void;
declare function ParameterDecorator2(x: number): (target: Function, key: string | symbol, paramIndex: number) => void;
declare function ParameterDecorator1(target: Object, key: string | symbol, paramIndex: number): void;
declare function ParameterDecorator2(x: number): (target: Object, key: string | symbol, paramIndex: number) => void;
@ClassDecorator1
@ClassDecorator2(10)

View File

@ -1,6 +1,6 @@
// @target: es6
// @Filename: decorated.ts
function decorate() { }
function decorate(target: any) { }
@decorate
export default class Decorated { }

View File

@ -5,7 +5,7 @@ function func(s: string): void {
}
class A {
@(x => {
@((x, p) => {
var a = 3;
func(a);
return x;

View File

@ -9,7 +9,7 @@ export var test = 'abc';
import { test } from './a';
function filter(handler: any) {
return function (target: any) {
return function (target: any, propertyKey: string) {
// ...
};
}

View File

@ -1,5 +1,5 @@
// @target: ES6
declare function dec(): <T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>;
declare function dec<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>;
class C {
@dec ["1"]() { }

View File

@ -1,5 +1,5 @@
// @target:es5
declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void;
declare function dec(target: Object, propertyKey: string | symbol, parameterIndex: number): void;
class C {
method(@dec p: number) {}

View File

@ -1,4 +1,4 @@
// @target: ES5
// @target: ES5
// @noLib: true
// @Filename: a.ts
@ -11,11 +11,12 @@ interface Function { }
interface RegExp { }
interface IArguments { }
// @Filename: b.ts
// @Filename: b.ts
/// <reference path="a.ts" />
declare var dec: any;
declare function dec(t, k, d);
@dec
class C {
@dec
method() {}
}