Skip to content

Commit 4645a5b

Browse files
committed
Merge pull request #3249 from Microsoft/resolveDecoratorAsCall
Migrated decorator checks to call resolution
2 parents 72aeb3c + 071ef34 commit 4645a5b

File tree

51 files changed

+703
-316
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+703
-316
lines changed

src/compiler/checker.ts

Lines changed: 482 additions & 65 deletions
Large diffs are not rendered by default.

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ namespace ts {
191191
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." },
192192
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." },
193193
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." },
194+
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'." },
195+
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'." },
196+
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." },
197+
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." },
198+
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." },
199+
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." },
194200
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
195201
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." },
196202
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },

src/compiler/diagnosticMessages.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,31 @@
753753
},
754754

755755

756+
"The return type of a property decorator function must be either 'void' or 'any'.": {
757+
"category": "Error",
758+
"code": 1236
759+
},
760+
"The return type of a parameter decorator function must be either 'void' or 'any'.": {
761+
"category": "Error",
762+
"code": 1237
763+
},
764+
"Unable to resolve signature of class decorator when called as an expression.": {
765+
"category": "Error",
766+
"code": 1238
767+
},
768+
"Unable to resolve signature of parameter decorator when called as an expression.": {
769+
"category": "Error",
770+
"code": 1239
771+
},
772+
"Unable to resolve signature of property decorator when called as an expression.": {
773+
"category": "Error",
774+
"code": 1240
775+
},
776+
"Unable to resolve signature of method decorator when called as an expression.": {
777+
"category": "Error",
778+
"code": 1241
779+
},
780+
756781
"Duplicate identifier '{0}'.": {
757782
"category": "Error",
758783
"code": 2300

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ namespace ts {
797797
template: LiteralExpression | TemplateExpression;
798798
}
799799

800-
export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression;
800+
export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression | Decorator;
801801

802802
export interface TypeAssertion extends UnaryExpression {
803803
type: TypeNode;

src/compiler/utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,8 @@ namespace ts {
752752
return (<TaggedTemplateExpression>node).tag;
753753
}
754754

755-
// Will either be a CallExpression or NewExpression.
756-
return (<CallExpression>node).expression;
755+
// Will either be a CallExpression, NewExpression, or Decorator.
756+
return (<CallExpression | Decorator>node).expression;
757757
}
758758

759759
export function nodeCanBeDecorated(node: Node): boolean {

tests/baselines/reference/decoratedClassFromExternalModule.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//// [tests/cases/conformance/decorators/class/decoratedClassFromExternalModule.ts] ////
22

33
//// [decorated.ts]
4-
function decorate() { }
4+
function decorate(target: any) { }
55

66
@decorate
77
export default class Decorated { }
@@ -18,7 +18,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
1818
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
1919
}
2020
};
21-
function decorate() { }
21+
function decorate(target) { }
2222
let Decorated = class {
2323
};
2424
Decorated = __decorate([

tests/baselines/reference/decoratedClassFromExternalModule.symbols

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
=== tests/cases/conformance/decorators/class/decorated.ts ===
2-
function decorate() { }
2+
function decorate(target: any) { }
33
>decorate : Symbol(decorate, Decl(decorated.ts, 0, 0))
4+
>target : Symbol(target, Decl(decorated.ts, 0, 18))
45

56
@decorate
67
>decorate : Symbol(decorate, Decl(decorated.ts, 0, 0))
78

89
export default class Decorated { }
9-
>Decorated : Symbol(Decorated, Decl(decorated.ts, 0, 23))
10+
>Decorated : Symbol(Decorated, Decl(decorated.ts, 0, 34))
1011

1112
=== tests/cases/conformance/decorators/class/undecorated.ts ===
1213
import Decorated from 'decorated';

tests/baselines/reference/decoratedClassFromExternalModule.types

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
=== tests/cases/conformance/decorators/class/decorated.ts ===
2-
function decorate() { }
3-
>decorate : () => void
2+
function decorate(target: any) { }
3+
>decorate : (target: any) => void
4+
>target : any
45

56
@decorate
6-
>decorate : () => void
7+
>decorate : (target: any) => void
78

89
export default class Decorated { }
910
>Decorated : Decorated

tests/baselines/reference/decoratorChecksFunctionBodies.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts(9,14):
88
}
99

1010
class A {
11-
@(x => {
11+
@((x, p) => {
1212
var a = 3;
1313
func(a);
1414
~

tests/baselines/reference/decoratorChecksFunctionBodies.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function func(s: string): void {
55
}
66

77
class A {
8-
@(x => {
8+
@((x, p) => {
99
var a = 3;
1010
func(a);
1111
return x;
@@ -34,7 +34,7 @@ var A = (function () {
3434
};
3535
Object.defineProperty(A.prototype, "m",
3636
__decorate([
37-
(function (x) {
37+
(function (x, p) {
3838
var a = 3;
3939
func(a);
4040
return x;

0 commit comments

Comments
 (0)