mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
fix(45157): omit error after property declaration without semicolon (#45165)
This commit is contained in:
@@ -1648,15 +1648,15 @@ namespace ts {
|
||||
}
|
||||
|
||||
function parseSemicolonAfterPropertyName(name: PropertyName, type: TypeNode | undefined, initializer: Expression | undefined) {
|
||||
switch (token()) {
|
||||
case SyntaxKind.AtToken:
|
||||
parseErrorAtCurrentToken(Diagnostics.Decorators_must_precede_the_name_and_all_keywords_of_property_declarations);
|
||||
return;
|
||||
if (token() === SyntaxKind.AtToken && !scanner.hasPrecedingLineBreak()) {
|
||||
parseErrorAtCurrentToken(Diagnostics.Decorators_must_precede_the_name_and_all_keywords_of_property_declarations);
|
||||
return;
|
||||
}
|
||||
|
||||
case SyntaxKind.OpenParenToken:
|
||||
parseErrorAtCurrentToken(Diagnostics.Cannot_start_a_function_call_in_a_type_annotation);
|
||||
nextToken();
|
||||
return;
|
||||
if (token() === SyntaxKind.OpenParenToken) {
|
||||
parseErrorAtCurrentToken(Diagnostics.Cannot_start_a_function_call_in_a_type_annotation);
|
||||
nextToken();
|
||||
return;
|
||||
}
|
||||
|
||||
if (type && !canParseSemicolon()) {
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
//// [decoratorOnClassMethod14.ts]
|
||||
declare var decorator: any;
|
||||
|
||||
class Foo {
|
||||
private prop = () => {
|
||||
return 0;
|
||||
}
|
||||
@decorator
|
||||
foo() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [decoratorOnClassMethod14.js]
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
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;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
class Foo {
|
||||
prop = () => {
|
||||
return 0;
|
||||
};
|
||||
foo() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
__decorate([
|
||||
decorator,
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", void 0)
|
||||
], Foo.prototype, "foo", null);
|
||||
@@ -0,0 +1,22 @@
|
||||
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod14.ts ===
|
||||
declare var decorator: any;
|
||||
>decorator : Symbol(decorator, Decl(decoratorOnClassMethod14.ts, 0, 11))
|
||||
|
||||
class Foo {
|
||||
>Foo : Symbol(Foo, Decl(decoratorOnClassMethod14.ts, 0, 27))
|
||||
|
||||
private prop = () => {
|
||||
>prop : Symbol(Foo.prop, Decl(decoratorOnClassMethod14.ts, 2, 11))
|
||||
|
||||
return 0;
|
||||
}
|
||||
@decorator
|
||||
>decorator : Symbol(decorator, Decl(decoratorOnClassMethod14.ts, 0, 11))
|
||||
|
||||
foo() {
|
||||
>foo : Symbol(Foo.foo, Decl(decoratorOnClassMethod14.ts, 5, 5))
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod14.ts ===
|
||||
declare var decorator: any;
|
||||
>decorator : any
|
||||
|
||||
class Foo {
|
||||
>Foo : Foo
|
||||
|
||||
private prop = () => {
|
||||
>prop : () => number
|
||||
>() => { return 0; } : () => number
|
||||
|
||||
return 0;
|
||||
>0 : 0
|
||||
}
|
||||
@decorator
|
||||
>decorator : any
|
||||
|
||||
foo() {
|
||||
>foo : () => number
|
||||
|
||||
return 0;
|
||||
>0 : 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
//// [decoratorOnClassMethod15.ts]
|
||||
declare var decorator: any;
|
||||
|
||||
class Foo {
|
||||
private prop = 1
|
||||
@decorator
|
||||
foo() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [decoratorOnClassMethod15.js]
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
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;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
class Foo {
|
||||
prop = 1;
|
||||
foo() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
__decorate([
|
||||
decorator,
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", void 0)
|
||||
], Foo.prototype, "foo", null);
|
||||
@@ -0,0 +1,20 @@
|
||||
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod15.ts ===
|
||||
declare var decorator: any;
|
||||
>decorator : Symbol(decorator, Decl(decoratorOnClassMethod15.ts, 0, 11))
|
||||
|
||||
class Foo {
|
||||
>Foo : Symbol(Foo, Decl(decoratorOnClassMethod15.ts, 0, 27))
|
||||
|
||||
private prop = 1
|
||||
>prop : Symbol(Foo.prop, Decl(decoratorOnClassMethod15.ts, 2, 11))
|
||||
|
||||
@decorator
|
||||
>decorator : Symbol(decorator, Decl(decoratorOnClassMethod15.ts, 0, 11))
|
||||
|
||||
foo() {
|
||||
>foo : Symbol(Foo.foo, Decl(decoratorOnClassMethod15.ts, 3, 20))
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod15.ts ===
|
||||
declare var decorator: any;
|
||||
>decorator : any
|
||||
|
||||
class Foo {
|
||||
>Foo : Foo
|
||||
|
||||
private prop = 1
|
||||
>prop : number
|
||||
>1 : 1
|
||||
|
||||
@decorator
|
||||
>decorator : any
|
||||
|
||||
foo() {
|
||||
>foo : () => number
|
||||
|
||||
return 0;
|
||||
>0 : 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
//// [decoratorOnClassMethod16.ts]
|
||||
declare var decorator: any;
|
||||
|
||||
class Foo {
|
||||
private prop
|
||||
@decorator
|
||||
foo() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [decoratorOnClassMethod16.js]
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
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;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
class Foo {
|
||||
prop;
|
||||
foo() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
__decorate([
|
||||
decorator,
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", void 0)
|
||||
], Foo.prototype, "foo", null);
|
||||
@@ -0,0 +1,20 @@
|
||||
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod16.ts ===
|
||||
declare var decorator: any;
|
||||
>decorator : Symbol(decorator, Decl(decoratorOnClassMethod16.ts, 0, 11))
|
||||
|
||||
class Foo {
|
||||
>Foo : Symbol(Foo, Decl(decoratorOnClassMethod16.ts, 0, 27))
|
||||
|
||||
private prop
|
||||
>prop : Symbol(Foo.prop, Decl(decoratorOnClassMethod16.ts, 2, 11))
|
||||
|
||||
@decorator
|
||||
>decorator : Symbol(decorator, Decl(decoratorOnClassMethod16.ts, 0, 11))
|
||||
|
||||
foo() {
|
||||
>foo : Symbol(Foo.foo, Decl(decoratorOnClassMethod16.ts, 3, 16))
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod16.ts ===
|
||||
declare var decorator: any;
|
||||
>decorator : any
|
||||
|
||||
class Foo {
|
||||
>Foo : Foo
|
||||
|
||||
private prop
|
||||
>prop : any
|
||||
|
||||
@decorator
|
||||
>decorator : any
|
||||
|
||||
foo() {
|
||||
>foo : () => number
|
||||
|
||||
return 0;
|
||||
>0 : 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
tests/cases/conformance/decorators/class/method/decoratorOnClassMethod17.ts(4,18): error TS1436: Decorators must precede the name and all keywords of property declarations.
|
||||
|
||||
|
||||
==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod17.ts (1 errors) ====
|
||||
declare var decorator: any;
|
||||
|
||||
class Foo {
|
||||
private prop @decorator
|
||||
~
|
||||
!!! error TS1436: Decorators must precede the name and all keywords of property declarations.
|
||||
foo() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
//// [decoratorOnClassMethod17.ts]
|
||||
declare var decorator: any;
|
||||
|
||||
class Foo {
|
||||
private prop @decorator
|
||||
foo() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [decoratorOnClassMethod17.js]
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
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;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
class Foo {
|
||||
prop;
|
||||
foo() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
__decorate([
|
||||
decorator,
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", void 0)
|
||||
], Foo.prototype, "foo", null);
|
||||
@@ -0,0 +1,18 @@
|
||||
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod17.ts ===
|
||||
declare var decorator: any;
|
||||
>decorator : Symbol(decorator, Decl(decoratorOnClassMethod17.ts, 0, 11))
|
||||
|
||||
class Foo {
|
||||
>Foo : Symbol(Foo, Decl(decoratorOnClassMethod17.ts, 0, 27))
|
||||
|
||||
private prop @decorator
|
||||
>prop : Symbol(Foo.prop, Decl(decoratorOnClassMethod17.ts, 2, 11))
|
||||
>decorator : Symbol(decorator, Decl(decoratorOnClassMethod17.ts, 0, 11))
|
||||
|
||||
foo() {
|
||||
>foo : Symbol(Foo.foo, Decl(decoratorOnClassMethod17.ts, 3, 16))
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod17.ts ===
|
||||
declare var decorator: any;
|
||||
>decorator : any
|
||||
|
||||
class Foo {
|
||||
>Foo : Foo
|
||||
|
||||
private prop @decorator
|
||||
>prop : any
|
||||
>decorator : any
|
||||
|
||||
foo() {
|
||||
>foo : () => number
|
||||
|
||||
return 0;
|
||||
>0 : 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
//// [decoratorOnClassMethod18.ts]
|
||||
declare var decorator: any;
|
||||
|
||||
class Foo {
|
||||
p1
|
||||
|
||||
@decorator()
|
||||
p2;
|
||||
}
|
||||
|
||||
|
||||
//// [decoratorOnClassMethod18.js]
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
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;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
class Foo {
|
||||
p1;
|
||||
p2;
|
||||
}
|
||||
__decorate([
|
||||
decorator(),
|
||||
__metadata("design:type", Object)
|
||||
], Foo.prototype, "p2", void 0);
|
||||
@@ -0,0 +1,17 @@
|
||||
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod18.ts ===
|
||||
declare var decorator: any;
|
||||
>decorator : Symbol(decorator, Decl(decoratorOnClassMethod18.ts, 0, 11))
|
||||
|
||||
class Foo {
|
||||
>Foo : Symbol(Foo, Decl(decoratorOnClassMethod18.ts, 0, 27))
|
||||
|
||||
p1
|
||||
>p1 : Symbol(Foo.p1, Decl(decoratorOnClassMethod18.ts, 2, 11))
|
||||
|
||||
@decorator()
|
||||
>decorator : Symbol(decorator, Decl(decoratorOnClassMethod18.ts, 0, 11))
|
||||
|
||||
p2;
|
||||
>p2 : Symbol(Foo.p2, Decl(decoratorOnClassMethod18.ts, 3, 6))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod18.ts ===
|
||||
declare var decorator: any;
|
||||
>decorator : any
|
||||
|
||||
class Foo {
|
||||
>Foo : Foo
|
||||
|
||||
p1
|
||||
>p1 : any
|
||||
|
||||
@decorator()
|
||||
>decorator() : any
|
||||
>decorator : any
|
||||
|
||||
p2;
|
||||
>p2 : any
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// @target: esnext
|
||||
// @experimentaldecorators: true
|
||||
// @emitdecoratormetadata: true
|
||||
declare var decorator: any;
|
||||
|
||||
class Foo {
|
||||
private prop = () => {
|
||||
return 0;
|
||||
}
|
||||
@decorator
|
||||
foo() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// @target: esnext
|
||||
// @experimentaldecorators: true
|
||||
// @emitdecoratormetadata: true
|
||||
declare var decorator: any;
|
||||
|
||||
class Foo {
|
||||
private prop = 1
|
||||
@decorator
|
||||
foo() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// @target: esnext
|
||||
// @experimentaldecorators: true
|
||||
// @emitdecoratormetadata: true
|
||||
declare var decorator: any;
|
||||
|
||||
class Foo {
|
||||
private prop
|
||||
@decorator
|
||||
foo() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// @target: esnext
|
||||
// @experimentaldecorators: true
|
||||
// @emitdecoratormetadata: true
|
||||
declare var decorator: any;
|
||||
|
||||
class Foo {
|
||||
private prop @decorator
|
||||
foo() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// @target: esnext
|
||||
// @experimentaldecorators: true
|
||||
// @emitdecoratormetadata: true
|
||||
declare var decorator: any;
|
||||
|
||||
class Foo {
|
||||
p1
|
||||
|
||||
@decorator()
|
||||
p2;
|
||||
}
|
||||
Reference in New Issue
Block a user