handel private properties correctelly
This commit is contained in:
parent
b40512d8a2
commit
1fa69caf13
6 changed files with 408 additions and 2 deletions
|
@ -10241,8 +10241,13 @@ namespace ts {
|
|||
return unknownType;
|
||||
}
|
||||
|
||||
if (noUnusedIdentifiers && !isInAmbientContext(node)) {
|
||||
prop.isReferenced = true;
|
||||
if (noUnusedIdentifiers && (prop.flags & SymbolFlags.ClassMember)) {
|
||||
if (prop.flags & SymbolFlags.Instantiated) {
|
||||
getSymbolLinks(prop).target.isReferenced = true;
|
||||
}
|
||||
else {
|
||||
prop.isReferenced = true;
|
||||
}
|
||||
}
|
||||
|
||||
getNodeLinks(node).resolvedSymbol = prop;
|
||||
|
|
|
@ -2107,6 +2107,8 @@ namespace ts {
|
|||
PropertyOrAccessor = Property | Accessor,
|
||||
Export = ExportNamespace | ExportType | ExportValue,
|
||||
|
||||
ClassMember = Method | Accessor | Property,
|
||||
|
||||
/* @internal */
|
||||
// The set of things we consider semantically classifiable. Used to speed up the LS during
|
||||
// classification.
|
||||
|
|
114
tests/baselines/reference/unusedPrivateMembers.js
Normal file
114
tests/baselines/reference/unusedPrivateMembers.js
Normal file
|
@ -0,0 +1,114 @@
|
|||
//// [unusedPrivateMembers.ts]
|
||||
|
||||
class Test1 {
|
||||
private initializeInternal() {
|
||||
}
|
||||
|
||||
public test() {
|
||||
var x = new Test1();
|
||||
x.initializeInternal();
|
||||
}
|
||||
}
|
||||
|
||||
class Test2 {
|
||||
private p = 0;
|
||||
public test() {
|
||||
var x = new Test2();
|
||||
x.p;
|
||||
}
|
||||
}
|
||||
|
||||
class Test3 {
|
||||
private get x () {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public test() {
|
||||
var x = new Test3();
|
||||
x.x;
|
||||
}
|
||||
}
|
||||
|
||||
class Test4 {
|
||||
private set x(v) {
|
||||
v;
|
||||
}
|
||||
|
||||
public test() {
|
||||
var x = new Test4();
|
||||
x.x;
|
||||
}
|
||||
}
|
||||
|
||||
class Test5<T> {
|
||||
private p: T;
|
||||
public test() {
|
||||
var x = new Test5<number>();
|
||||
x.p;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [unusedPrivateMembers.js]
|
||||
var Test1 = (function () {
|
||||
function Test1() {
|
||||
}
|
||||
Test1.prototype.initializeInternal = function () {
|
||||
};
|
||||
Test1.prototype.test = function () {
|
||||
var x = new Test1();
|
||||
x.initializeInternal();
|
||||
};
|
||||
return Test1;
|
||||
}());
|
||||
var Test2 = (function () {
|
||||
function Test2() {
|
||||
this.p = 0;
|
||||
}
|
||||
Test2.prototype.test = function () {
|
||||
var x = new Test2();
|
||||
x.p;
|
||||
};
|
||||
return Test2;
|
||||
}());
|
||||
var Test3 = (function () {
|
||||
function Test3() {
|
||||
}
|
||||
Object.defineProperty(Test3.prototype, "x", {
|
||||
get: function () {
|
||||
return 0;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Test3.prototype.test = function () {
|
||||
var x = new Test3();
|
||||
x.x;
|
||||
};
|
||||
return Test3;
|
||||
}());
|
||||
var Test4 = (function () {
|
||||
function Test4() {
|
||||
}
|
||||
Object.defineProperty(Test4.prototype, "x", {
|
||||
set: function (v) {
|
||||
v;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Test4.prototype.test = function () {
|
||||
var x = new Test4();
|
||||
x.x;
|
||||
};
|
||||
return Test4;
|
||||
}());
|
||||
var Test5 = (function () {
|
||||
function Test5() {
|
||||
}
|
||||
Test5.prototype.test = function () {
|
||||
var x = new Test5();
|
||||
x.p;
|
||||
};
|
||||
return Test5;
|
||||
}());
|
113
tests/baselines/reference/unusedPrivateMembers.symbols
Normal file
113
tests/baselines/reference/unusedPrivateMembers.symbols
Normal file
|
@ -0,0 +1,113 @@
|
|||
=== tests/cases/compiler/unusedPrivateMembers.ts ===
|
||||
|
||||
class Test1 {
|
||||
>Test1 : Symbol(Test1, Decl(unusedPrivateMembers.ts, 0, 0))
|
||||
|
||||
private initializeInternal() {
|
||||
>initializeInternal : Symbol(Test1.initializeInternal, Decl(unusedPrivateMembers.ts, 1, 13))
|
||||
}
|
||||
|
||||
public test() {
|
||||
>test : Symbol(Test1.test, Decl(unusedPrivateMembers.ts, 3, 5))
|
||||
|
||||
var x = new Test1();
|
||||
>x : Symbol(x, Decl(unusedPrivateMembers.ts, 6, 11))
|
||||
>Test1 : Symbol(Test1, Decl(unusedPrivateMembers.ts, 0, 0))
|
||||
|
||||
x.initializeInternal();
|
||||
>x.initializeInternal : Symbol(Test1.initializeInternal, Decl(unusedPrivateMembers.ts, 1, 13))
|
||||
>x : Symbol(x, Decl(unusedPrivateMembers.ts, 6, 11))
|
||||
>initializeInternal : Symbol(Test1.initializeInternal, Decl(unusedPrivateMembers.ts, 1, 13))
|
||||
}
|
||||
}
|
||||
|
||||
class Test2 {
|
||||
>Test2 : Symbol(Test2, Decl(unusedPrivateMembers.ts, 9, 1))
|
||||
|
||||
private p = 0;
|
||||
>p : Symbol(Test2.p, Decl(unusedPrivateMembers.ts, 11, 13))
|
||||
|
||||
public test() {
|
||||
>test : Symbol(Test2.test, Decl(unusedPrivateMembers.ts, 12, 18))
|
||||
|
||||
var x = new Test2();
|
||||
>x : Symbol(x, Decl(unusedPrivateMembers.ts, 14, 11))
|
||||
>Test2 : Symbol(Test2, Decl(unusedPrivateMembers.ts, 9, 1))
|
||||
|
||||
x.p;
|
||||
>x.p : Symbol(Test2.p, Decl(unusedPrivateMembers.ts, 11, 13))
|
||||
>x : Symbol(x, Decl(unusedPrivateMembers.ts, 14, 11))
|
||||
>p : Symbol(Test2.p, Decl(unusedPrivateMembers.ts, 11, 13))
|
||||
}
|
||||
}
|
||||
|
||||
class Test3 {
|
||||
>Test3 : Symbol(Test3, Decl(unusedPrivateMembers.ts, 17, 1))
|
||||
|
||||
private get x () {
|
||||
>x : Symbol(Test3.x, Decl(unusedPrivateMembers.ts, 19, 13))
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public test() {
|
||||
>test : Symbol(Test3.test, Decl(unusedPrivateMembers.ts, 22, 5))
|
||||
|
||||
var x = new Test3();
|
||||
>x : Symbol(x, Decl(unusedPrivateMembers.ts, 25, 11))
|
||||
>Test3 : Symbol(Test3, Decl(unusedPrivateMembers.ts, 17, 1))
|
||||
|
||||
x.x;
|
||||
>x.x : Symbol(Test3.x, Decl(unusedPrivateMembers.ts, 19, 13))
|
||||
>x : Symbol(x, Decl(unusedPrivateMembers.ts, 25, 11))
|
||||
>x : Symbol(Test3.x, Decl(unusedPrivateMembers.ts, 19, 13))
|
||||
}
|
||||
}
|
||||
|
||||
class Test4 {
|
||||
>Test4 : Symbol(Test4, Decl(unusedPrivateMembers.ts, 28, 1))
|
||||
|
||||
private set x(v) {
|
||||
>x : Symbol(Test4.x, Decl(unusedPrivateMembers.ts, 30, 13))
|
||||
>v : Symbol(v, Decl(unusedPrivateMembers.ts, 31, 18))
|
||||
|
||||
v;
|
||||
>v : Symbol(v, Decl(unusedPrivateMembers.ts, 31, 18))
|
||||
}
|
||||
|
||||
public test() {
|
||||
>test : Symbol(Test4.test, Decl(unusedPrivateMembers.ts, 33, 5))
|
||||
|
||||
var x = new Test4();
|
||||
>x : Symbol(x, Decl(unusedPrivateMembers.ts, 36, 11))
|
||||
>Test4 : Symbol(Test4, Decl(unusedPrivateMembers.ts, 28, 1))
|
||||
|
||||
x.x;
|
||||
>x.x : Symbol(Test4.x, Decl(unusedPrivateMembers.ts, 30, 13))
|
||||
>x : Symbol(x, Decl(unusedPrivateMembers.ts, 36, 11))
|
||||
>x : Symbol(Test4.x, Decl(unusedPrivateMembers.ts, 30, 13))
|
||||
}
|
||||
}
|
||||
|
||||
class Test5<T> {
|
||||
>Test5 : Symbol(Test5, Decl(unusedPrivateMembers.ts, 39, 1))
|
||||
>T : Symbol(T, Decl(unusedPrivateMembers.ts, 41, 12))
|
||||
|
||||
private p: T;
|
||||
>p : Symbol(Test5.p, Decl(unusedPrivateMembers.ts, 41, 16))
|
||||
>T : Symbol(T, Decl(unusedPrivateMembers.ts, 41, 12))
|
||||
|
||||
public test() {
|
||||
>test : Symbol(Test5.test, Decl(unusedPrivateMembers.ts, 42, 17))
|
||||
|
||||
var x = new Test5<number>();
|
||||
>x : Symbol(x, Decl(unusedPrivateMembers.ts, 44, 11))
|
||||
>Test5 : Symbol(Test5, Decl(unusedPrivateMembers.ts, 39, 1))
|
||||
|
||||
x.p;
|
||||
>x.p : Symbol(Test5.p, Decl(unusedPrivateMembers.ts, 41, 16))
|
||||
>x : Symbol(x, Decl(unusedPrivateMembers.ts, 44, 11))
|
||||
>p : Symbol(Test5.p, Decl(unusedPrivateMembers.ts, 41, 16))
|
||||
}
|
||||
}
|
||||
|
121
tests/baselines/reference/unusedPrivateMembers.types
Normal file
121
tests/baselines/reference/unusedPrivateMembers.types
Normal file
|
@ -0,0 +1,121 @@
|
|||
=== tests/cases/compiler/unusedPrivateMembers.ts ===
|
||||
|
||||
class Test1 {
|
||||
>Test1 : Test1
|
||||
|
||||
private initializeInternal() {
|
||||
>initializeInternal : () => void
|
||||
}
|
||||
|
||||
public test() {
|
||||
>test : () => void
|
||||
|
||||
var x = new Test1();
|
||||
>x : Test1
|
||||
>new Test1() : Test1
|
||||
>Test1 : typeof Test1
|
||||
|
||||
x.initializeInternal();
|
||||
>x.initializeInternal() : void
|
||||
>x.initializeInternal : () => void
|
||||
>x : Test1
|
||||
>initializeInternal : () => void
|
||||
}
|
||||
}
|
||||
|
||||
class Test2 {
|
||||
>Test2 : Test2
|
||||
|
||||
private p = 0;
|
||||
>p : number
|
||||
>0 : number
|
||||
|
||||
public test() {
|
||||
>test : () => void
|
||||
|
||||
var x = new Test2();
|
||||
>x : Test2
|
||||
>new Test2() : Test2
|
||||
>Test2 : typeof Test2
|
||||
|
||||
x.p;
|
||||
>x.p : number
|
||||
>x : Test2
|
||||
>p : number
|
||||
}
|
||||
}
|
||||
|
||||
class Test3 {
|
||||
>Test3 : Test3
|
||||
|
||||
private get x () {
|
||||
>x : number
|
||||
|
||||
return 0;
|
||||
>0 : number
|
||||
}
|
||||
|
||||
public test() {
|
||||
>test : () => void
|
||||
|
||||
var x = new Test3();
|
||||
>x : Test3
|
||||
>new Test3() : Test3
|
||||
>Test3 : typeof Test3
|
||||
|
||||
x.x;
|
||||
>x.x : number
|
||||
>x : Test3
|
||||
>x : number
|
||||
}
|
||||
}
|
||||
|
||||
class Test4 {
|
||||
>Test4 : Test4
|
||||
|
||||
private set x(v) {
|
||||
>x : any
|
||||
>v : any
|
||||
|
||||
v;
|
||||
>v : any
|
||||
}
|
||||
|
||||
public test() {
|
||||
>test : () => void
|
||||
|
||||
var x = new Test4();
|
||||
>x : Test4
|
||||
>new Test4() : Test4
|
||||
>Test4 : typeof Test4
|
||||
|
||||
x.x;
|
||||
>x.x : any
|
||||
>x : Test4
|
||||
>x : any
|
||||
}
|
||||
}
|
||||
|
||||
class Test5<T> {
|
||||
>Test5 : Test5<T>
|
||||
>T : T
|
||||
|
||||
private p: T;
|
||||
>p : T
|
||||
>T : T
|
||||
|
||||
public test() {
|
||||
>test : () => void
|
||||
|
||||
var x = new Test5<number>();
|
||||
>x : Test5<number>
|
||||
>new Test5<number>() : Test5<number>
|
||||
>Test5 : typeof Test5
|
||||
|
||||
x.p;
|
||||
>x.p : number
|
||||
>x : Test5<number>
|
||||
>p : number
|
||||
}
|
||||
}
|
||||
|
51
tests/cases/compiler/unusedPrivateMembers.ts
Normal file
51
tests/cases/compiler/unusedPrivateMembers.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
//@noUnusedLocals:true
|
||||
//@noUnusedParameters:true
|
||||
//@target:ES5
|
||||
|
||||
class Test1 {
|
||||
private initializeInternal() {
|
||||
}
|
||||
|
||||
public test() {
|
||||
var x = new Test1();
|
||||
x.initializeInternal();
|
||||
}
|
||||
}
|
||||
|
||||
class Test2 {
|
||||
private p = 0;
|
||||
public test() {
|
||||
var x = new Test2();
|
||||
x.p;
|
||||
}
|
||||
}
|
||||
|
||||
class Test3 {
|
||||
private get x () {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public test() {
|
||||
var x = new Test3();
|
||||
x.x;
|
||||
}
|
||||
}
|
||||
|
||||
class Test4 {
|
||||
private set x(v) {
|
||||
v;
|
||||
}
|
||||
|
||||
public test() {
|
||||
var x = new Test4();
|
||||
x.x;
|
||||
}
|
||||
}
|
||||
|
||||
class Test5<T> {
|
||||
private p: T;
|
||||
public test() {
|
||||
var x = new Test5<number>();
|
||||
x.p;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue