Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
547 changes: 482 additions & 65 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/compiler/diagnosticInformationMap.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ namespace ts {
An_export_declaration_can_only_be_used_in_a_module: { code: 1233, category: DiagnosticCategory.Error, key: "An export declaration can only be used in a module." },
An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file: { code: 1234, category: DiagnosticCategory.Error, key: "An ambient module declaration is only allowed at the top level in a file." },
A_namespace_declaration_is_only_allowed_in_a_namespace_or_module: { code: 1235, category: DiagnosticCategory.Error, key: "A namespace declaration is only allowed in a namespace or module." },
The_return_type_of_a_property_decorator_function_must_be_either_void_or_any: { code: 1236, category: DiagnosticCategory.Error, key: "The return type of a property decorator function must be either 'void' or 'any'." },
The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any: { code: 1237, category: DiagnosticCategory.Error, key: "The return type of a parameter decorator function must be either 'void' or 'any'." },
Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression: { code: 1238, category: DiagnosticCategory.Error, key: "Unable to resolve signature of class decorator when called as an expression." },
Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression: { code: 1239, category: DiagnosticCategory.Error, key: "Unable to resolve signature of parameter decorator when called as an expression." },
Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression: { code: 1240, category: DiagnosticCategory.Error, key: "Unable to resolve signature of property decorator when called as an expression." },
Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression: { code: 1241, category: DiagnosticCategory.Error, key: "Unable to resolve signature of method decorator when called as an expression." },
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." },
Expand Down
25 changes: 25 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,31 @@
},


"The return type of a property decorator function must be either 'void' or 'any'.": {
"category": "Error",
"code": 1236
},
"The return type of a parameter decorator function must be either 'void' or 'any'.": {
"category": "Error",
"code": 1237
},
"Unable to resolve signature of class decorator when called as an expression.": {
"category": "Error",
"code": 1238
},
"Unable to resolve signature of parameter decorator when called as an expression.": {
"category": "Error",
"code": 1239
},
"Unable to resolve signature of property decorator when called as an expression.": {
"category": "Error",
"code": 1240
},
"Unable to resolve signature of method decorator when called as an expression.": {
"category": "Error",
"code": 1241
},

"Duplicate identifier '{0}'.": {
"category": "Error",
"code": 2300
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ namespace ts {
template: LiteralExpression | TemplateExpression;
}

export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression;
export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression | Decorator;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DecoratorApplication?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather just leave this as Decorator


export interface TypeAssertion extends UnaryExpression {
type: TypeNode;
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,8 @@ namespace ts {
return (<TaggedTemplateExpression>node).tag;
}

// Will either be a CallExpression or NewExpression.
return (<CallExpression>node).expression;
// Will either be a CallExpression, NewExpression, or Decorator.
return (<CallExpression | Decorator>node).expression;
}

export function nodeCanBeDecorated(node: Node): boolean {
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/decoratedClassFromExternalModule.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//// [tests/cases/conformance/decorators/class/decoratedClassFromExternalModule.ts] ////

//// [decorated.ts]
function decorate() { }
function decorate(target: any) { }

@decorate
export default class Decorated { }
Expand All @@ -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([
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts(9,14):
}

class A {
@(x => {
@((x, p) => {
var a = 3;
func(a);
~
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/decoratorChecksFunctionBodies.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function func(s: string): void {
}

class A {
@(x => {
@((x, p) => {
var a = 3;
func(a);
return x;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
// ...
};
}
Expand All @@ -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) {
// ...
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))

// ...
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

// ...
};
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tests/baselines/reference/decoratorOnClass8.errors.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
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 TS1238: Unable to resolve signature of class decorator when called as an expression.
Supplied parameters do not match any signature of call target.


==== 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: typeof C) => void | typeof C'.
!!! error TS1238: Unable to resolve signature of class decorator when called as an expression.
!!! error TS1238: Supplied parameters do not match any signature of call target.
class C {
}
14 changes: 5 additions & 9 deletions tests/baselines/reference/decoratorOnClassMethod10.errors.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
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 TS2345: 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) ====
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>) => 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 TS2345: Argument of type 'C' is not assignable to parameter of type 'Function'.
!!! error TS2345: Property 'apply' is missing in type 'C'.
}
2 changes: 1 addition & 1 deletion tests/baselines/reference/decoratorOnClassMethod13.js
Original file line number Diff line number Diff line change
@@ -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"]() { }
Expand Down
16 changes: 8 additions & 8 deletions tests/baselines/reference/decoratorOnClassMethod13.symbols
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/decoratorOnClassMethod13.types
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
13 changes: 13 additions & 0 deletions tests/baselines/reference/decoratorOnClassMethod6.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts(4,5): error TS1241: Unable to resolve signature of method decorator when called as an expression.
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 TS1241: Unable to resolve signature of method decorator when called as an expression.
!!! error TS1241: Supplied parameters do not match any signature of call target.
}
18 changes: 0 additions & 18 deletions tests/baselines/reference/decoratorOnClassMethod6.symbols

This file was deleted.

19 changes: 0 additions & 19 deletions tests/baselines/reference/decoratorOnClassMethod6.types

This file was deleted.

13 changes: 13 additions & 0 deletions tests/baselines/reference/decoratorOnClassMethod8.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tests/cases/conformance/decorators/class/method/decoratorOnClassMethod8.ts(4,5): error TS1241: Unable to resolve signature of method decorator when called as an expression.
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 TS1241: Unable to resolve signature of method decorator when called as an expression.
!!! error TS1241: Supplied parameters do not match any signature of call target.
}
15 changes: 0 additions & 15 deletions tests/baselines/reference/decoratorOnClassMethod8.symbols

This file was deleted.

15 changes: 0 additions & 15 deletions tests/baselines/reference/decoratorOnClassMethod8.types

This file was deleted.

Loading