-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12740 from Microsoft/fix12727
Fix decorator emit for accessors
- Loading branch information
Showing
4 changed files
with
203 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
tests/baselines/reference/decoratorOnClassAccessor7.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor7.ts(26,5): error TS1207: Decorators cannot be applied to multiple get/set accessors of the same name. | ||
tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor7.ts(31,5): error TS1207: Decorators cannot be applied to multiple get/set accessors of the same name. | ||
|
||
|
||
==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor7.ts (2 errors) ==== | ||
declare function dec1<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>; | ||
declare function dec2<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>; | ||
|
||
class A { | ||
@dec1 get x() { return 0; } | ||
set x(value: number) { } | ||
} | ||
|
||
class B { | ||
get x() { return 0; } | ||
@dec2 set x(value: number) { } | ||
} | ||
|
||
class C { | ||
@dec1 set x(value: number) { } | ||
get x() { return 0; } | ||
} | ||
|
||
class D { | ||
set x(value: number) { } | ||
@dec2 get x() { return 0; } | ||
} | ||
|
||
class E { | ||
@dec1 get x() { return 0; } | ||
@dec2 set x(value: number) { } | ||
~ | ||
!!! error TS1207: Decorators cannot be applied to multiple get/set accessors of the same name. | ||
} | ||
|
||
class F { | ||
@dec1 set x(value: number) { } | ||
@dec2 get x() { return 0; } | ||
~ | ||
!!! error TS1207: Decorators cannot be applied to multiple get/set accessors of the same name. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
//// [decoratorOnClassAccessor7.ts] | ||
declare function dec1<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>; | ||
declare function dec2<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>; | ||
|
||
class A { | ||
@dec1 get x() { return 0; } | ||
set x(value: number) { } | ||
} | ||
|
||
class B { | ||
get x() { return 0; } | ||
@dec2 set x(value: number) { } | ||
} | ||
|
||
class C { | ||
@dec1 set x(value: number) { } | ||
get x() { return 0; } | ||
} | ||
|
||
class D { | ||
set x(value: number) { } | ||
@dec2 get x() { return 0; } | ||
} | ||
|
||
class E { | ||
@dec1 get x() { return 0; } | ||
@dec2 set x(value: number) { } | ||
} | ||
|
||
class F { | ||
@dec1 set x(value: number) { } | ||
@dec2 get x() { return 0; } | ||
} | ||
|
||
//// [decoratorOnClassAccessor7.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 A = (function () { | ||
function A() { | ||
} | ||
Object.defineProperty(A.prototype, "x", { | ||
get: function () { return 0; }, | ||
set: function (value) { }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return A; | ||
}()); | ||
__decorate([ | ||
dec1 | ||
], A.prototype, "x", null); | ||
var B = (function () { | ||
function B() { | ||
} | ||
Object.defineProperty(B.prototype, "x", { | ||
get: function () { return 0; }, | ||
set: function (value) { }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return B; | ||
}()); | ||
__decorate([ | ||
dec2 | ||
], B.prototype, "x", null); | ||
var C = (function () { | ||
function C() { | ||
} | ||
Object.defineProperty(C.prototype, "x", { | ||
get: function () { return 0; }, | ||
set: function (value) { }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return C; | ||
}()); | ||
__decorate([ | ||
dec1 | ||
], C.prototype, "x", null); | ||
var D = (function () { | ||
function D() { | ||
} | ||
Object.defineProperty(D.prototype, "x", { | ||
get: function () { return 0; }, | ||
set: function (value) { }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return D; | ||
}()); | ||
__decorate([ | ||
dec2 | ||
], D.prototype, "x", null); | ||
var E = (function () { | ||
function E() { | ||
} | ||
Object.defineProperty(E.prototype, "x", { | ||
get: function () { return 0; }, | ||
set: function (value) { }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return E; | ||
}()); | ||
__decorate([ | ||
dec1 | ||
], E.prototype, "x", null); | ||
var F = (function () { | ||
function F() { | ||
} | ||
Object.defineProperty(F.prototype, "x", { | ||
get: function () { return 0; }, | ||
set: function (value) { }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return F; | ||
}()); | ||
__decorate([ | ||
dec1 | ||
], F.prototype, "x", null); |
34 changes: 34 additions & 0 deletions
34
tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor7.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// @target:es5 | ||
// @experimentaldecorators: true | ||
declare function dec1<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>; | ||
declare function dec2<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>; | ||
|
||
class A { | ||
@dec1 get x() { return 0; } | ||
set x(value: number) { } | ||
} | ||
|
||
class B { | ||
get x() { return 0; } | ||
@dec2 set x(value: number) { } | ||
} | ||
|
||
class C { | ||
@dec1 set x(value: number) { } | ||
get x() { return 0; } | ||
} | ||
|
||
class D { | ||
set x(value: number) { } | ||
@dec2 get x() { return 0; } | ||
} | ||
|
||
class E { | ||
@dec1 get x() { return 0; } | ||
@dec2 set x(value: number) { } | ||
} | ||
|
||
class F { | ||
@dec1 set x(value: number) { } | ||
@dec2 get x() { return 0; } | ||
} |