JavaScript: Restrict InstanceFieldAsPropWrite to fields with initializers.

This commit is contained in:
Max Schaefer
2019-02-09 15:39:28 +00:00
parent 184e65d8a1
commit 10ef945b51
3 changed files with 19 additions and 2 deletions

View File

@@ -555,14 +555,15 @@ module DataFlow {
}
/**
* An instance field, seen as a property write.
* An instance field with an initializer, seen as a property write.
*/
private class InstanceFieldAsPropWrite extends PropWrite, PropNode {
override FieldDefinition prop;
InstanceFieldAsPropWrite() {
not prop.isStatic() and
not prop instanceof ParameterField
not prop instanceof ParameterField and
exists(prop.getInit())
}
override Node getBase() {

View File

@@ -1,3 +1,4 @@
| fieldInit.ts:10:3:10:8 | f = 4; | This write to property 'f' is useless, since $@ always overrides it. | fieldInit.ts:13:5:13:14 | this.f = 5 | another property write |
| real-world-examples.js:5:4:5:11 | o.p = 42 | This write to property 'p' is useless, since $@ always overrides it. | real-world-examples.js:10:2:10:9 | o.p = 42 | another property write |
| real-world-examples.js:15:9:15:18 | o.p1 += 42 | This write to property 'p1' is useless, since $@ always overrides it. | real-world-examples.js:15:2:15:18 | o.p1 = o.p1 += 42 | another property write |
| real-world-examples.js:16:11:16:20 | o.p2 *= 42 | This write to property 'p2' is useless, since $@ always overrides it. | real-world-examples.js:16:2:16:21 | o.p2 -= (o.p2 *= 42) | another property write |

View File

@@ -0,0 +1,15 @@
class C {
f; // OK
constructor() {
this.f = 5;
}
}
class D {
f = 4; // NOT OK
constructor() {
this.f = 5;
}
}