Skip to content

Commit f34db80

Browse files
Max HeiberJoseph Watts
Max Heiber
authored and
Joseph Watts
committed
Disallow decorating private-named properties
Disallow decorating private-named properties because the spec is still in flux. Signed-off-by: Max Heiber <[email protected]>
1 parent 4dd7d85 commit f34db80

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

src/compiler/utilities.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ namespace ts {
14981498
export function nodeCanBeDecorated(node: Node, parent: Node, grandparent: Node): boolean;
14991499
export function nodeCanBeDecorated(node: Node, parent?: Node, grandparent?: Node): boolean {
15001500
// private names cannot be used with decorators yet
1501-
if (isNamedDeclaration(node) && node.name.kind === SyntaxKind.PrivateName) {
1501+
if (isNamedDeclaration(node) && isPrivateName(node.name)) {
15021502
return false;
15031503
}
15041504
switch (node.kind) {
@@ -1514,8 +1514,8 @@ namespace ts {
15141514
case SyntaxKind.SetAccessor:
15151515
case SyntaxKind.MethodDeclaration:
15161516
// if this method has a body and its parent is a class declaration, this is a valid target.
1517-
return (node as FunctionLikeDeclaration).body !== undefined
1518-
&& parent!.kind === SyntaxKind.ClassDeclaration
1517+
return (<FunctionLikeDeclaration>node).body !== undefined
1518+
&& parent!.kind === SyntaxKind.ClassDeclaration;
15191519

15201520
case SyntaxKind.Parameter:
15211521
// if the parameter's parent has a body and its grandparent is a class declaration, this is a valid target;

tests/baselines/reference/privateNamesAndDecorators.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ tests/cases/conformance/classes/members/privateNames/privateNamesAndDecorators.t
66
declare function dec<T>(target: T): T;
77

88
class A {
9-
@dec
9+
@dec // Error
1010
~
1111
!!! error TS1206: Decorators are not valid here.
1212
#foo = 1;
13-
@dec
13+
@dec // Error
1414
~
1515
!!! error TS1206: Decorators are not valid here.
1616
#bar(): void { }

tests/baselines/reference/privateNamesAndDecorators.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
declare function dec<T>(target: T): T;
33

44
class A {
5-
@dec
5+
@dec // Error
66
#foo = 1;
7-
@dec
7+
@dec // Error
88
#bar(): void { }
99
}
1010

tests/baselines/reference/privateNamesAndDecorators.symbols

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ declare function dec<T>(target: T): T;
99
class A {
1010
>A : Symbol(A, Decl(privateNamesAndDecorators.ts, 0, 38))
1111

12-
@dec
12+
@dec // Error
1313
>dec : Symbol(dec, Decl(privateNamesAndDecorators.ts, 0, 0))
1414

1515
#foo = 1;
1616
>#foo : Symbol(A.#foo, Decl(privateNamesAndDecorators.ts, 2, 9))
1717

18-
@dec
18+
@dec // Error
1919
>dec : Symbol(dec, Decl(privateNamesAndDecorators.ts, 0, 0))
2020

2121
#bar(): void { }

tests/baselines/reference/privateNamesAndDecorators.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ declare function dec<T>(target: T): T;
66
class A {
77
>A : A
88

9-
@dec
9+
@dec // Error
1010
>dec : <T>(target: T) => T
1111

1212
#foo = 1;
1313
>#foo : number
1414
>1 : 1
1515

16-
@dec
16+
@dec // Error
1717
>dec : <T>(target: T) => T
1818

1919
#bar(): void { }
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
declare function dec<T>(target: T): T;
22

33
class A {
4-
@dec
4+
@dec // Error
55
#foo = 1;
6-
@dec
6+
@dec // Error
77
#bar(): void { }
88
}

0 commit comments

Comments
 (0)