Skip to content

Commit ac447f1

Browse files
committed
Migrated decorator checks to call resolution
1 parent db6928e commit ac447f1

51 files changed

Lines changed: 533 additions & 306 deletions

File tree

Some content is hidden

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

src/compiler/checker.ts

Lines changed: 319 additions & 49 deletions
Large diffs are not rendered by default.

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ module ts {
174174
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" },
175175
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." },
176176
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'." },
177+
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'." },
178+
Invalid_expression_for_0_decorator: { code: 1220, category: DiagnosticCategory.Error, key: "Invalid expression for {0} decorator." },
177179
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
178180
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." },
179181
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,14 @@
683683
"category": "Error",
684684
"code": 1218
685685
},
686+
"The return type of a {0} decorator function must be either 'void' or 'any'.": {
687+
"category": "Error",
688+
"code": 1219
689+
},
690+
"Invalid expression for {0} decorator.": {
691+
"category": "Error",
692+
"code": 1220
693+
},
686694

687695
"Duplicate identifier '{0}'.": {
688696
"category": "Error",

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ module ts {
753753
template: LiteralExpression | TemplateExpression;
754754
}
755755

756-
export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression;
756+
export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression | Decorator;
757757

758758
export interface TypeAssertion extends UnaryExpression {
759759
type: TypeNode;

src/compiler/utilities.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,9 @@ module ts {
620620
if (node.kind === SyntaxKind.TaggedTemplateExpression) {
621621
return (<TaggedTemplateExpression>node).tag;
622622
}
623+
else if (node.kind === SyntaxKind.Decorator) {
624+
return (<Decorator>node).expression;
625+
}
623626

624627
// Will either be a CallExpression or NewExpression.
625628
return (<CallExpression>node).expression;

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)