Skip to content

Commit

Permalink
Mark property referenced in the destructuring as referenced
Browse files Browse the repository at this point in the history
Fixes #11324
  • Loading branch information
sheetalkamat committed Nov 2, 2016
1 parent 116c878 commit 13e8f7f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 29 deletions.
28 changes: 17 additions & 11 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11504,6 +11504,21 @@ namespace ts {
diagnostics.add(createDiagnosticForNodeFromMessageChain(propNode, errorInfo));
}

function markPropertyAsReferenced(prop: Symbol) {
if (prop &&
noUnusedIdentifiers &&
(prop.flags & SymbolFlags.ClassMember) &&
prop.valueDeclaration && (getModifierFlags(prop.valueDeclaration) & ModifierFlags.Private)) {
if (prop.flags & SymbolFlags.Instantiated) {
getSymbolLinks(prop).target.isReferenced = true;

}
else {
prop.isReferenced = true;
}
}
}

function checkPropertyAccessExpressionOrQualifiedName(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, right: Identifier) {
const type = checkNonNullExpression(left);
if (isTypeAny(type) || type === silentNeverType) {
Expand All @@ -11523,17 +11538,7 @@ namespace ts {
return unknownType;
}

if (noUnusedIdentifiers &&
(prop.flags & SymbolFlags.ClassMember) &&
prop.valueDeclaration && (getModifierFlags(prop.valueDeclaration) & ModifierFlags.Private)) {
if (prop.flags & SymbolFlags.Instantiated) {
getSymbolLinks(prop).target.isReferenced = true;

}
else {
prop.isReferenced = true;
}
}
markPropertyAsReferenced(prop);

getNodeLinks(node).resolvedSymbol = prop;

Expand Down Expand Up @@ -16323,6 +16328,7 @@ namespace ts {
const parentType = getTypeForBindingElementParent(parent);
const name = node.propertyName || <Identifier>node.name;
const property = getPropertyOfType(parentType, getTextOfPropertyName(name));
markPropertyAsReferenced(property);
if (parent.initializer && property && getParentOfSymbol(property)) {
checkClassPropertyAccess(parent, parent.initializer, parentType, property);
}
Expand Down
18 changes: 0 additions & 18 deletions tests/baselines/reference/unusedLocalProperty.errors.txt

This file was deleted.

29 changes: 29 additions & 0 deletions tests/baselines/reference/unusedLocalProperty.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
=== tests/cases/compiler/unusedLocalProperty.ts ===
declare var console: { log(msg: any): void; }
>console : Symbol(console, Decl(unusedLocalProperty.ts, 0, 11))
>log : Symbol(log, Decl(unusedLocalProperty.ts, 0, 22))
>msg : Symbol(msg, Decl(unusedLocalProperty.ts, 0, 27))

class Animal {
>Animal : Symbol(Animal, Decl(unusedLocalProperty.ts, 0, 45))

constructor(private species: string) {
>species : Symbol(Animal.species, Decl(unusedLocalProperty.ts, 2, 16))
}

printSpecies() {
>printSpecies : Symbol(Animal.printSpecies, Decl(unusedLocalProperty.ts, 3, 5))

let { species } = this;
>species : Symbol(species, Decl(unusedLocalProperty.ts, 6, 13))
>this : Symbol(Animal, Decl(unusedLocalProperty.ts, 0, 45))

console.log(species);
>console.log : Symbol(log, Decl(unusedLocalProperty.ts, 0, 22))
>console : Symbol(console, Decl(unusedLocalProperty.ts, 0, 11))
>log : Symbol(log, Decl(unusedLocalProperty.ts, 0, 22))
>species : Symbol(species, Decl(unusedLocalProperty.ts, 6, 13))
}
}


30 changes: 30 additions & 0 deletions tests/baselines/reference/unusedLocalProperty.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
=== tests/cases/compiler/unusedLocalProperty.ts ===
declare var console: { log(msg: any): void; }
>console : { log(msg: any): void; }
>log : (msg: any) => void
>msg : any

class Animal {
>Animal : Animal

constructor(private species: string) {
>species : string
}

printSpecies() {
>printSpecies : () => void

let { species } = this;
>species : string
>this : this

console.log(species);
>console.log(species) : void
>console.log : (msg: any) => void
>console : { log(msg: any): void; }
>log : (msg: any) => void
>species : string
}
}


0 comments on commit 13e8f7f

Please sign in to comment.