Skip to content

Commit 772a571

Browse files
committed
fix(45157): omit error after property declaration without semicolon
1 parent a947bbb commit 772a571

22 files changed

+453
-8
lines changed

src/compiler/parser.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,15 +1648,15 @@ namespace ts {
16481648
}
16491649

16501650
function parseSemicolonAfterPropertyName(name: PropertyName, type: TypeNode | undefined, initializer: Expression | undefined) {
1651-
switch (token()) {
1652-
case SyntaxKind.AtToken:
1653-
parseErrorAtCurrentToken(Diagnostics.Decorators_must_precede_the_name_and_all_keywords_of_property_declarations);
1654-
return;
1651+
if (token() === SyntaxKind.AtToken && !scanner.hasPrecedingLineBreak()) {
1652+
parseErrorAtCurrentToken(Diagnostics.Decorators_must_precede_the_name_and_all_keywords_of_property_declarations);
1653+
return;
1654+
}
16551655

1656-
case SyntaxKind.OpenParenToken:
1657-
parseErrorAtCurrentToken(Diagnostics.Cannot_start_a_function_call_in_a_type_annotation);
1658-
nextToken();
1659-
return;
1656+
if (token() === SyntaxKind.OpenParenToken) {
1657+
parseErrorAtCurrentToken(Diagnostics.Cannot_start_a_function_call_in_a_type_annotation);
1658+
nextToken();
1659+
return;
16601660
}
16611661

16621662
if (type && !canParseSemicolon()) {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//// [decoratorOnClassMethod14.ts]
2+
declare var decorator: any;
3+
4+
class Foo {
5+
private prop = () => {
6+
return 0;
7+
}
8+
@decorator
9+
foo() {
10+
return 0;
11+
}
12+
}
13+
14+
15+
//// [decoratorOnClassMethod14.js]
16+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
17+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
18+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
19+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
20+
return c > 3 && r && Object.defineProperty(target, key, r), r;
21+
};
22+
var __metadata = (this && this.__metadata) || function (k, v) {
23+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
24+
};
25+
class Foo {
26+
prop = () => {
27+
return 0;
28+
};
29+
foo() {
30+
return 0;
31+
}
32+
}
33+
__decorate([
34+
decorator,
35+
__metadata("design:type", Function),
36+
__metadata("design:paramtypes", []),
37+
__metadata("design:returntype", void 0)
38+
], Foo.prototype, "foo", null);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod14.ts ===
2+
declare var decorator: any;
3+
>decorator : Symbol(decorator, Decl(decoratorOnClassMethod14.ts, 0, 11))
4+
5+
class Foo {
6+
>Foo : Symbol(Foo, Decl(decoratorOnClassMethod14.ts, 0, 27))
7+
8+
private prop = () => {
9+
>prop : Symbol(Foo.prop, Decl(decoratorOnClassMethod14.ts, 2, 11))
10+
11+
return 0;
12+
}
13+
@decorator
14+
>decorator : Symbol(decorator, Decl(decoratorOnClassMethod14.ts, 0, 11))
15+
16+
foo() {
17+
>foo : Symbol(Foo.foo, Decl(decoratorOnClassMethod14.ts, 5, 5))
18+
19+
return 0;
20+
}
21+
}
22+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod14.ts ===
2+
declare var decorator: any;
3+
>decorator : any
4+
5+
class Foo {
6+
>Foo : Foo
7+
8+
private prop = () => {
9+
>prop : () => number
10+
>() => { return 0; } : () => number
11+
12+
return 0;
13+
>0 : 0
14+
}
15+
@decorator
16+
>decorator : any
17+
18+
foo() {
19+
>foo : () => number
20+
21+
return 0;
22+
>0 : 0
23+
}
24+
}
25+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//// [decoratorOnClassMethod15.ts]
2+
declare var decorator: any;
3+
4+
class Foo {
5+
private prop = 1
6+
@decorator
7+
foo() {
8+
return 0;
9+
}
10+
}
11+
12+
13+
//// [decoratorOnClassMethod15.js]
14+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
15+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
18+
return c > 3 && r && Object.defineProperty(target, key, r), r;
19+
};
20+
var __metadata = (this && this.__metadata) || function (k, v) {
21+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
22+
};
23+
class Foo {
24+
prop = 1;
25+
foo() {
26+
return 0;
27+
}
28+
}
29+
__decorate([
30+
decorator,
31+
__metadata("design:type", Function),
32+
__metadata("design:paramtypes", []),
33+
__metadata("design:returntype", void 0)
34+
], Foo.prototype, "foo", null);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod15.ts ===
2+
declare var decorator: any;
3+
>decorator : Symbol(decorator, Decl(decoratorOnClassMethod15.ts, 0, 11))
4+
5+
class Foo {
6+
>Foo : Symbol(Foo, Decl(decoratorOnClassMethod15.ts, 0, 27))
7+
8+
private prop = 1
9+
>prop : Symbol(Foo.prop, Decl(decoratorOnClassMethod15.ts, 2, 11))
10+
11+
@decorator
12+
>decorator : Symbol(decorator, Decl(decoratorOnClassMethod15.ts, 0, 11))
13+
14+
foo() {
15+
>foo : Symbol(Foo.foo, Decl(decoratorOnClassMethod15.ts, 3, 20))
16+
17+
return 0;
18+
}
19+
}
20+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod15.ts ===
2+
declare var decorator: any;
3+
>decorator : any
4+
5+
class Foo {
6+
>Foo : Foo
7+
8+
private prop = 1
9+
>prop : number
10+
>1 : 1
11+
12+
@decorator
13+
>decorator : any
14+
15+
foo() {
16+
>foo : () => number
17+
18+
return 0;
19+
>0 : 0
20+
}
21+
}
22+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//// [decoratorOnClassMethod16.ts]
2+
declare var decorator: any;
3+
4+
class Foo {
5+
private prop
6+
@decorator
7+
foo() {
8+
return 0;
9+
}
10+
}
11+
12+
13+
//// [decoratorOnClassMethod16.js]
14+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
15+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
18+
return c > 3 && r && Object.defineProperty(target, key, r), r;
19+
};
20+
var __metadata = (this && this.__metadata) || function (k, v) {
21+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
22+
};
23+
class Foo {
24+
prop;
25+
foo() {
26+
return 0;
27+
}
28+
}
29+
__decorate([
30+
decorator,
31+
__metadata("design:type", Function),
32+
__metadata("design:paramtypes", []),
33+
__metadata("design:returntype", void 0)
34+
], Foo.prototype, "foo", null);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod16.ts ===
2+
declare var decorator: any;
3+
>decorator : Symbol(decorator, Decl(decoratorOnClassMethod16.ts, 0, 11))
4+
5+
class Foo {
6+
>Foo : Symbol(Foo, Decl(decoratorOnClassMethod16.ts, 0, 27))
7+
8+
private prop
9+
>prop : Symbol(Foo.prop, Decl(decoratorOnClassMethod16.ts, 2, 11))
10+
11+
@decorator
12+
>decorator : Symbol(decorator, Decl(decoratorOnClassMethod16.ts, 0, 11))
13+
14+
foo() {
15+
>foo : Symbol(Foo.foo, Decl(decoratorOnClassMethod16.ts, 3, 16))
16+
17+
return 0;
18+
}
19+
}
20+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod16.ts ===
2+
declare var decorator: any;
3+
>decorator : any
4+
5+
class Foo {
6+
>Foo : Foo
7+
8+
private prop
9+
>prop : any
10+
11+
@decorator
12+
>decorator : any
13+
14+
foo() {
15+
>foo : () => number
16+
17+
return 0;
18+
>0 : 0
19+
}
20+
}
21+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tests/cases/conformance/decorators/class/method/decoratorOnClassMethod17.ts(4,18): error TS1436: Decorators must precede the name and all keywords of property declarations.
2+
3+
4+
==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod17.ts (1 errors) ====
5+
declare var decorator: any;
6+
7+
class Foo {
8+
private prop @decorator
9+
~
10+
!!! error TS1436: Decorators must precede the name and all keywords of property declarations.
11+
foo() {
12+
return 0;
13+
}
14+
}
15+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//// [decoratorOnClassMethod17.ts]
2+
declare var decorator: any;
3+
4+
class Foo {
5+
private prop @decorator
6+
foo() {
7+
return 0;
8+
}
9+
}
10+
11+
12+
//// [decoratorOnClassMethod17.js]
13+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
14+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
16+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
17+
return c > 3 && r && Object.defineProperty(target, key, r), r;
18+
};
19+
var __metadata = (this && this.__metadata) || function (k, v) {
20+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
21+
};
22+
class Foo {
23+
prop;
24+
foo() {
25+
return 0;
26+
}
27+
}
28+
__decorate([
29+
decorator,
30+
__metadata("design:type", Function),
31+
__metadata("design:paramtypes", []),
32+
__metadata("design:returntype", void 0)
33+
], Foo.prototype, "foo", null);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod17.ts ===
2+
declare var decorator: any;
3+
>decorator : Symbol(decorator, Decl(decoratorOnClassMethod17.ts, 0, 11))
4+
5+
class Foo {
6+
>Foo : Symbol(Foo, Decl(decoratorOnClassMethod17.ts, 0, 27))
7+
8+
private prop @decorator
9+
>prop : Symbol(Foo.prop, Decl(decoratorOnClassMethod17.ts, 2, 11))
10+
>decorator : Symbol(decorator, Decl(decoratorOnClassMethod17.ts, 0, 11))
11+
12+
foo() {
13+
>foo : Symbol(Foo.foo, Decl(decoratorOnClassMethod17.ts, 3, 16))
14+
15+
return 0;
16+
}
17+
}
18+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod17.ts ===
2+
declare var decorator: any;
3+
>decorator : any
4+
5+
class Foo {
6+
>Foo : Foo
7+
8+
private prop @decorator
9+
>prop : any
10+
>decorator : any
11+
12+
foo() {
13+
>foo : () => number
14+
15+
return 0;
16+
>0 : 0
17+
}
18+
}
19+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//// [decoratorOnClassMethod18.ts]
2+
declare var decorator: any;
3+
4+
class Foo {
5+
p1
6+
7+
@decorator()
8+
p2;
9+
}
10+
11+
12+
//// [decoratorOnClassMethod18.js]
13+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
14+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
16+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
17+
return c > 3 && r && Object.defineProperty(target, key, r), r;
18+
};
19+
var __metadata = (this && this.__metadata) || function (k, v) {
20+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
21+
};
22+
class Foo {
23+
p1;
24+
p2;
25+
}
26+
__decorate([
27+
decorator(),
28+
__metadata("design:type", Object)
29+
], Foo.prototype, "p2", void 0);

0 commit comments

Comments
 (0)