Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add useDefineForClassFields flag for Set -> Define property declaration#33509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sandersn merged 57 commits intomasterfromsandersn/add-property-define-flag
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
57 commits
Select commitHold shift + click to select a range
f76e01f
Disallow property/accessor overrides
sandersnSep 12, 2019
ac96739
Disallow uninitialised property overrides
sandersnSep 13, 2019
c26785e
Merge branch 'master' into disallow-property-accessor-override
sandersnSep 13, 2019
c4f334a
Updates from design review + fix ancient bug
sandersnSep 13, 2019
70a15bd
Need to add a couple of errors and squash one
sandersnSep 16, 2019
feb0fb6
Everything works so far
sandersnSep 16, 2019
8686242
Check for constructor initialisation
sandersnSep 16, 2019
2916c29
change error wording
sandersnSep 16, 2019
2e5f57c
Improve error wording
sandersnSep 16, 2019
f11f2be
Add codefix to add missing 'declare'
sandersnSep 17, 2019
526ceb7
Merge branch 'master' into disallow-property-accessor-override
sandersnSep 17, 2019
a8f4610
Merge branch 'master' into disallow-uninitialised-property-override
sandersnSep 17, 2019
2238b66
Always emit accessors in .d.ts files
sandersnSep 17, 2019
fcf0ff1
Allow 'declare' on any uninitialised property decl
sandersnSep 17, 2019
810f923
Undo code moves
sandersnSep 17, 2019
6408d7a
Let sleeping dogs lie
sandersnSep 17, 2019
5ee3271
Correctly set NodeFlags.Ambient
sandersnSep 17, 2019
e0ddced
Remove more unneeded code
sandersnSep 17, 2019
610a62d
Merge branch 'disallow-property-accessor-override' into add-property-…
sandersnSep 17, 2019
e7ba1ae
Merge branch 'disallow-uninitialised-property-override' into add-prop…
sandersnSep 17, 2019
6c94395
Merge branch 'always-emit-accessors-in-dts' into add-property-define-…
sandersnSep 17, 2019
6a066b9
Update baselines
sandersnSep 17, 2019
0548220
Merge branch 'disallow-uninitialised-property-override' into sandersn…
sandersnSep 17, 2019
7f69be7
Update baselines
sandersnSep 17, 2019
8f42126
Merge branch 'always-emit-accessors-in-dts' into sandersn/add-propert…
sandersnSep 17, 2019
d46a0db
Update baselines
sandersnSep 17, 2019
58e1746
Ignore this-property assignments
sandersnSep 19, 2019
9b358b1
Merge branch 'disallow-property-accessor-override' into sandersn/add-…
sandersnSep 19, 2019
832d51f
Fix base-in-interface check
sandersnSep 19, 2019
9c6aa17
Merge branch 'disallow-property-accessor-override' into sandersn/add-…
sandersnSep 19, 2019
a645ca9
Do not error when base parent is interface
sandersnSep 19, 2019
030c768
Fix base interface check
sandersnSep 19, 2019
003d041
Add missed baselines
sandersnSep 19, 2019
6ec445f
Fix check
sandersnSep 19, 2019
c283574
Fix new errors in services
sandersnSep 19, 2019
1c5f699
Fix new errors in services
sandersnSep 19, 2019
2403116
Merge branch 'disallow-property-accessor-override' into sandersn/add-…
sandersnSep 19, 2019
b45b5ba
Merge branch 'disallow-uninitialised-property-override' into sandersn…
sandersnSep 19, 2019
8d99856
Fix errors in testRunner
sandersnSep 19, 2019
f400822
Add flag and turn off errors when on
sandersnSep 19, 2019
1f68bea
Structure of new emit is correct, fake content
sandersnSep 20, 2019
6c35ac2
Basically right emit
sandersnSep 20, 2019
fbeaf01
Fix one last unitialised property declaration
sandersnSep 20, 2019
a5b1d8f
Haha no I missed another one
sandersnSep 20, 2019
32a73b3
Fix whitespace back to CRLF
sandersnSep 20, 2019
5028bfa
Minor fix and code cleanup
sandersnSep 20, 2019
8053e05
New test case
sandersnSep 20, 2019
7fdb423
Fix bug in isInitializedProperty
sandersnSep 23, 2019
18c622c
Updates from design meeting.
sandersnSep 23, 2019
8268f9a
Update baselines
sandersnSep 23, 2019
5eeb2b0
Object.defineProperty for methods too
sandersnSep 23, 2019
5ea2bc1
Update slow baselines
sandersnSep 23, 2019
088daa8
Improve error message
sandersnSep 23, 2019
e600ebe
Update src/compiler/transformers/utilities.ts
sandersnSep 23, 2019
6e3bf5c
Add test of computed properties
sandersnSep 23, 2019
ba876cf
Remove done TODO
sandersnSep 23, 2019
6a1e24c
Merge branch 'master' into sandersn/add-property-define-flag
sandersnSep 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
New test case
  • Loading branch information
@sandersn
sandersn committedSep 20, 2019
commit8053e0559a7764174ca00b81c4f4b1f2ca73b1fb
6 changes: 3 additions & 3 deletionssrc/compiler/transformers/classFields.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,7 +51,6 @@ namespace ts {
// [x] = 1 => Object.defineProperty(this, x, ...)
// -vs-
// [x] = 1 -> this[x] = 1
// TODO: Unininitialised properties need to be emitted too.
|| !options.legacyClassFields && options.target === ScriptTarget.ESNext) {
return node;
}
Expand DownExpand Up@@ -439,10 +438,11 @@ namespace ts {

function createObjectDefineProperty(target: Expression, name: PropertyName, initializer: Expression) {
const e = isComputedPropertyName(name) ? name.expression
: isIdentifier(name) ? createStringLiteral(unescapeLeadingUnderscores(name.escapedText)) : name;
: isIdentifier(name) ? createStringLiteral(unescapeLeadingUnderscores(name.escapedText))
: name;
return createCall(
createPropertyAccess(createIdentifier("Object"), createIdentifier("defineProperty")),
undefined,
/*typeArguments*/undefined,
[target, e, createObjectLiteral([createPropertyAssignment("value", initializer)])]);
}

Expand Down
13 changes: 3 additions & 10 deletionstests/baselines/reference/accessorsOverrideProperty.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,23 +17,16 @@ class D extends C {

//// [accessorsOverrideProperty.js]
class A {
constructor() {
this.p = 'yep';
}
p = 'yep';
}
class B extends A {
get p() { return 'oh no'; } // error
}
class C {
constructor() {
this.p = 101;
}
p = 101;
}
class D extends C {
constructor() {
super(...arguments);
this._secret = 11;
}
_secret = 11;
get p() { return this._secret; } // error
set p(value) { this._secret = value; } // error
}
4 changes: 1 addition & 3 deletionstests/baselines/reference/accessorsOverrideProperty2.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,9 +14,7 @@ console.log(obj.x); // 1

//// [accessorsOverrideProperty2.js]
class Base {
constructor() {
this.x = 1;
}
x = 1;
}
class Derived extends Base {
get x() { return 2; } // should be an error
Expand Down
5 changes: 1 addition & 4 deletionstests/baselines/reference/accessorsOverrideProperty3.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,10 +11,7 @@ class Lion extends Animal {

//// [accessorsOverrideProperty3.js]
class Lion extends Animal {
constructor() {
super(...arguments);
this._sound = 'grrr';
}
_sound = 'grrr';
get sound() { return this._sound; } // error here
set sound(val) { this._sound = val; }
}
5 changes: 1 addition & 4 deletionstests/baselines/reference/accessorsOverrideProperty4.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,10 +11,7 @@ class Lion extends Animal {

//// [accessorsOverrideProperty4.js]
class Lion extends Animal {
constructor() {
super(...arguments);
this._sound = 'roar';
}
_sound = 'roar';
get sound() { return this._sound; }
set sound(val) { this._sound = val; }
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,13 +31,16 @@ var __extends = (this && this.__extends) || (function () {
})();
var Base = /** @class */ (function () {
function Base() {
Object.defineProperty(this, "x", { value: void 0 });
}
return Base;
}());
var Derived = /** @class */ (function (_super) {
__extends(Derived, _super);
function Derived() {
return _super !== null && _super.apply(this, arguments) || this;
var _this = _super !== null && _super.apply(this, arguments) || this;
Object.defineProperty(_this, "x", { value: void 0 }); // error
return _this;
}
return Derived;
}(Base));
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,6 +53,8 @@ var x;
var y;
var Base = /** @class */ (function () {
function Base(a) {
Object.defineProperty(this, "a", { value: void 0 });
Object.defineProperty(this, "d", { value: void 0 });
}
Base.prototype.b = function (a) { };
Object.defineProperty(Base.prototype, "c", {
Expand All@@ -73,7 +75,10 @@ var Base = /** @class */ (function () {
var Derived = /** @class */ (function (_super) {
__extends(Derived, _super);
function Derived(a) {
return _super.call(this, x) || this;
var _this = _super.call(this, x) || this;
Object.defineProperty(_this, "a", { value: void 0 });
Object.defineProperty(_this, "d", { value: void 0 });
return _this;
}
Derived.prototype.b = function (a) { };
Object.defineProperty(Derived.prototype, "c", {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -81,6 +81,8 @@ var x;
var y;
var Base = /** @class */ (function () {
function Base(a) {
Object.defineProperty(this, "a", { value: void 0 });
Object.defineProperty(this, "d", { value: void 0 });
}
Base.prototype.b = function (a) { };
Object.defineProperty(Base.prototype, "c", {
Expand All@@ -102,7 +104,10 @@ var Base = /** @class */ (function () {
var Derived = /** @class */ (function (_super) {
__extends(Derived, _super);
function Derived(a) {
return _super.call(this, a) || this;
var _this = _super.call(this, a) || this;
Object.defineProperty(_this, "a", { value: void 0 });
Object.defineProperty(_this, "d", { value: void 0 });
return _this;
}
Derived.prototype.b = function (a) { };
Object.defineProperty(Derived.prototype, "c", {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -88,6 +88,8 @@ var x;
var y;
var Base = /** @class */ (function () {
function Base(a) {
Object.defineProperty(this, "a", { value: void 0 });
Object.defineProperty(this, "d", { value: void 0 });
}
Base.prototype.b = function (a) { };
Object.defineProperty(Base.prototype, "c", {
Expand All@@ -110,7 +112,9 @@ var Base = /** @class */ (function () {
var Derived1 = /** @class */ (function (_super) {
__extends(Derived1, _super);
function Derived1(a) {
return _super.call(this, a) || this;
var _this = _super.call(this, a) || this;
Object.defineProperty(_this, "a", { value: void 0 });
return _this;
}
return Derived1;
}(Base));
Expand DownExpand Up@@ -149,7 +153,9 @@ var Derived4 = /** @class */ (function (_super) {
var Derived5 = /** @class */ (function (_super) {
__extends(Derived5, _super);
function Derived5(a) {
return _super.call(this, a) || this;
var _this = _super.call(this, a) || this;
Object.defineProperty(_this, "d", { value: void 0 });
return _this;
}
return Derived5;
}(Base));
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,20 +32,25 @@ var x;
var y;
var Base = /** @class */ (function () {
function Base() {
Object.defineProperty(this, "a", { value: void 0 });
}
return Base;
}());
var Derived1 = /** @class */ (function (_super) {
__extends(Derived1, _super);
function Derived1() {
return _super !== null && _super.apply(this, arguments) || this;
var _this = _super !== null && _super.apply(this, arguments) || this;
Object.defineProperty(_this, "a", { value: void 0 });
return _this;
}
return Derived1;
}(Base));
var Derived2 = /** @class */ (function (_super) {
__extends(Derived2, _super);
function Derived2() {
return _super !== null && _super.apply(this, arguments) || this;
var _this = _super !== null && _super.apply(this, arguments) || this;
Object.defineProperty(_this, "a", { value: void 0 }); // Error, parent was public
return _this;
}
return Derived2;
}(Derived1));
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,6 +80,8 @@ var x;
var y;
var Base = /** @class */ (function () {
function Base(a) {
Object.defineProperty(this, "a", { value: void 0 });
Object.defineProperty(this, "d", { value: void 0 });
}
Base.prototype.b = function (a) { };
Object.defineProperty(Base.prototype, "c", {
Expand All@@ -100,7 +102,10 @@ var Base = /** @class */ (function () {
var Derived = /** @class */ (function (_super) {
__extends(Derived, _super);
function Derived(a) {
return _super.call(this, x) || this;
var _this = _super.call(this, x) || this;
Object.defineProperty(_this, "a", { value: void 0 });
Object.defineProperty(_this, "d", { value: void 0 });
return _this;
}
Derived.prototype.b = function (a) { };
Object.defineProperty(Derived.prototype, "c", {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,13 +39,16 @@ var __extends = (this && this.__extends) || (function () {
})();
var Base = /** @class */ (function () {
function Base() {
Object.defineProperty(this, "x", { value: void 0 });
}
return Base;
}());
var Derived = /** @class */ (function (_super) {
__extends(Derived, _super);
function Derived() {
return _super !== null && _super.apply(this, arguments) || this;
var _this = _super !== null && _super.apply(this, arguments) || this;
Object.defineProperty(_this, "x", { value: void 0 });
return _this;
}
return Derived;
}(Base));
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,6 +51,7 @@ function Tagged(Base) {
args[_i] = arguments[_i];
}
var _this = _super.apply(this, args) || this;
Object.defineProperty(_this, "_tag", { value: void 0 });
_this._tag = "";
return _this;
}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,10 +18,7 @@ class Base {
set x(value) { console.log(`x was set to ${value}`); }
}
class Derived extends Base {
constructor() {
super(...arguments);
this.x = 1;
}
x = 1;
}
const obj = new Derived(); // prints 'x was set to 1'
console.log(obj.x); // 2
9 changes: 2 additions & 7 deletionstests/baselines/reference/propertyOverridesAccessors3.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,9 +26,7 @@ lion.makeSound() // with [[Define]]: Expected "RAWR!" but got "rustling noise in

//// [propertyOverridesAccessors3.js]
class Animal {
constructor() {
this._sound = 'rustling noise in the bushes';
}
_sound = 'rustling noise in the bushes';
get sound() { return this._sound; }
set sound(val) {
this._sound = val;
Expand All@@ -41,10 +39,7 @@ class Animal {
const a = new Animal;
a.makeSound(); // 'rustling noise in the bushes'
class Lion extends Animal {
constructor() {
super(...arguments);
this.sound = 'RAWR!'; // error here
}
sound = 'RAWR!'; // error here
}
const lion = new Lion;
lion.makeSound(); // with [[Define]]: Expected "RAWR!" but got "rustling noise in the bushes"
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors5.ts(5,24): error TS2610: Class 'A' defines instance member accessor 'p', but extended class 'B' defines it as instance member property.


==== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors5.ts (1 errors) ====
class A {
get p() { return 'oh no' }
}
class B extends A {
constructor(public p: string) {
~
!!! error TS2610: Class 'A' defines instance member accessor 'p', but extended class 'B' defines it as instance member property.
super()
}
}

22 changes: 22 additions & 0 deletionstests/baselines/reference/propertyOverridesAccessors5.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
//// [propertyOverridesAccessors5.ts]
class A {
get p() { return 'oh no' }
}
class B extends A {
constructor(public p: string) {
super()
}
}


//// [propertyOverridesAccessors5.js]
class A {
get p() { return 'oh no'; }
}
class B extends A {
p;
constructor(p) {
super();
this.p = p;
}
}
19 changes: 19 additions & 0 deletionstests/baselines/reference/propertyOverridesAccessors5.symbols
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
=== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors5.ts ===
class A {
>A : Symbol(A, Decl(propertyOverridesAccessors5.ts, 0, 0))

get p() { return 'oh no' }
>p : Symbol(A.p, Decl(propertyOverridesAccessors5.ts, 0, 9))
}
class B extends A {
>B : Symbol(B, Decl(propertyOverridesAccessors5.ts, 2, 1))
>A : Symbol(A, Decl(propertyOverridesAccessors5.ts, 0, 0))

constructor(public p: string) {
>p : Symbol(B.p, Decl(propertyOverridesAccessors5.ts, 4, 16))

super()
>super : Symbol(A, Decl(propertyOverridesAccessors5.ts, 0, 0))
}
}

21 changes: 21 additions & 0 deletionstests/baselines/reference/propertyOverridesAccessors5.types
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
=== tests/cases/conformance/classes/propertyMemberDeclarations/propertyOverridesAccessors5.ts ===
class A {
>A : A

get p() { return 'oh no' }
>p : string
>'oh no' : "oh no"
}
class B extends A {
>B : B
>A : A

constructor(public p: string) {
>p : string

super()
>super() : void
>super : typeof A
}
}

5 changes: 1 addition & 4 deletionstests/baselines/reference/propertyOverridesMethod.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,8 +12,5 @@ class A {
m() { }
}
class B extends A {
constructor() {
super(...arguments);
this.m = () => 1;
}
m = () => 1;
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
// @target: esnext
class A {
get p() { return 'oh no' }
}
class B extends A {
constructor(public p: string) {
super()
}
}

[8]ページ先頭

©2009-2026 Movatter.jp