Skip to content

Commit

Permalink
Reduce size of span for unused declaration (revert #22388) (#24566)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy committed Jun 1, 2018
1 parent 8dc7d5a commit 5f34d06
Show file tree
Hide file tree
Showing 32 changed files with 97 additions and 102 deletions.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22692,7 +22692,7 @@ namespace ts {
function errorUnusedLocal(declaration: Declaration, name: string, addDiagnostic: AddUnusedDiagnostic) {
const node = getNameOfDeclaration(declaration) || declaration;
const message = isTypeDeclaration(declaration) ? Diagnostics._0_is_declared_but_never_used : Diagnostics._0_is_declared_but_its_value_is_never_read;
addDiagnostic(UnusedKind.Local, createDiagnosticForNodeSpan(getSourceFileOfNode(declaration), declaration, node, message, name));
addDiagnostic(UnusedKind.Local, createDiagnosticForNode(node, message, name));
}

function parameterNameStartsWithUnderscore(parameterName: DeclarationName) {
Expand Down
5 changes: 0 additions & 5 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,11 +637,6 @@ namespace ts {
return createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2, arg3);
}

export function createDiagnosticForNodeSpan(sourceFile: SourceFile, startNode: Node, endNode: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number, arg3?: string | number): DiagnosticWithLocation {
const start = skipTrivia(sourceFile.text, startNode.pos);
return createFileDiagnostic(sourceFile, start, endNode.end - start, message, arg0, arg1, arg2, arg3);
}

export function createDiagnosticForNodeFromMessageChain(node: Node, messageChain: DiagnosticMessageChain): DiagnosticWithLocation {
const sourceFile = getSourceFileOfNode(node);
const span = getErrorSpanForNode(sourceFile, node);
Expand Down
28 changes: 14 additions & 14 deletions tests/baselines/reference/noUnusedLocals_selfReference.errors.txt
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
tests/cases/compiler/noUnusedLocals_selfReference.ts(3,1): error TS6133: 'f' is declared but its value is never read.
tests/cases/compiler/noUnusedLocals_selfReference.ts(5,5): error TS6133: 'g' is declared but its value is never read.
tests/cases/compiler/noUnusedLocals_selfReference.ts(9,1): error TS6196: 'C' is declared but never used.
tests/cases/compiler/noUnusedLocals_selfReference.ts(12,1): error TS6196: 'E' is declared but never used.
tests/cases/compiler/noUnusedLocals_selfReference.ts(13,1): error TS6196: 'I' is declared but never used.
tests/cases/compiler/noUnusedLocals_selfReference.ts(14,1): error TS6196: 'T' is declared but never used.
tests/cases/compiler/noUnusedLocals_selfReference.ts(15,1): error TS6133: 'N' is declared but its value is never read.
tests/cases/compiler/noUnusedLocals_selfReference.ts(3,10): error TS6133: 'f' is declared but its value is never read.
tests/cases/compiler/noUnusedLocals_selfReference.ts(5,14): error TS6133: 'g' is declared but its value is never read.
tests/cases/compiler/noUnusedLocals_selfReference.ts(9,7): error TS6196: 'C' is declared but never used.
tests/cases/compiler/noUnusedLocals_selfReference.ts(12,6): error TS6196: 'E' is declared but never used.
tests/cases/compiler/noUnusedLocals_selfReference.ts(13,11): error TS6196: 'I' is declared but never used.
tests/cases/compiler/noUnusedLocals_selfReference.ts(14,6): error TS6196: 'T' is declared but never used.
tests/cases/compiler/noUnusedLocals_selfReference.ts(15,11): error TS6133: 'N' is declared but its value is never read.
tests/cases/compiler/noUnusedLocals_selfReference.ts(22,19): error TS6133: 'm' is declared but its value is never read.


==== tests/cases/compiler/noUnusedLocals_selfReference.ts (8 errors) ====
export {}; // Make this a module scope, so these are local variables.

function f() {
~~~~~~~~~~
~
!!! error TS6133: 'f' is declared but its value is never read.
f;
function g() {
~~~~~~~~~~
~
!!! error TS6133: 'g' is declared but its value is never read.
g;
}
}
class C {
~~~~~~~
~
!!! error TS6196: 'C' is declared but never used.
m() { C; }
}
enum E { A = 0, B = E.A }
~~~~~~
~
!!! error TS6196: 'E' is declared but never used.
interface I { x: I };
~~~~~~~~~~~
~
!!! error TS6196: 'I' is declared but never used.
type T = { x: T };
~~~~~~
~
!!! error TS6196: 'T' is declared but never used.
namespace N { N; }
~~~~~~~~~~~
~
!!! error TS6133: 'N' is declared but its value is never read.

// Avoid a false positive.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
tests/cases/compiler/noUnusedLocals_selfReference_skipsBlockLocations.ts(2,5): error TS6133: 'f' is declared but its value is never read.
tests/cases/compiler/noUnusedLocals_selfReference_skipsBlockLocations.ts(8,13): error TS6133: 'g' is declared but its value is never read.
tests/cases/compiler/noUnusedLocals_selfReference_skipsBlockLocations.ts(12,13): error TS6133: 'h' is declared but its value is never read.
tests/cases/compiler/noUnusedLocals_selfReference_skipsBlockLocations.ts(2,14): error TS6133: 'f' is declared but its value is never read.
tests/cases/compiler/noUnusedLocals_selfReference_skipsBlockLocations.ts(8,22): error TS6133: 'g' is declared but its value is never read.
tests/cases/compiler/noUnusedLocals_selfReference_skipsBlockLocations.ts(12,22): error TS6133: 'h' is declared but its value is never read.


==== tests/cases/compiler/noUnusedLocals_selfReference_skipsBlockLocations.ts (3 errors) ====
namespace n {
function f() {
~~~~~~~~~~
~
!!! error TS6133: 'f' is declared but its value is never read.
f;
}

switch (0) {
case 0:
function g() {
~~~~~~~~~~
~
!!! error TS6133: 'g' is declared but its value is never read.
g;
}
default:
function h() {
~~~~~~~~~~
~
!!! error TS6133: 'h' is declared but its value is never read.
h;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/unusedClassesinModule1.errors.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tests/cases/compiler/unusedClassesinModule1.ts(2,5): error TS6196: 'Calculator' is declared but never used.
tests/cases/compiler/unusedClassesinModule1.ts(2,11): error TS6196: 'Calculator' is declared but never used.


==== tests/cases/compiler/unusedClassesinModule1.ts (1 errors) ====
module A {
class Calculator {
~~~~~~~~~~~~~~~~
~~~~~~~~~~
!!! error TS6196: 'Calculator' is declared but never used.
public handelChar() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tests/cases/compiler/unusedClassesinNamespace1.ts(2,5): error TS6196: 'c1' is declared but never used.
tests/cases/compiler/unusedClassesinNamespace1.ts(2,11): error TS6196: 'c1' is declared but never used.


==== tests/cases/compiler/unusedClassesinNamespace1.ts (1 errors) ====
namespace Validation {
class c1 {
~~~~~~~~
~~
!!! error TS6196: 'c1' is declared but never used.

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tests/cases/compiler/unusedClassesinNamespace2.ts(2,5): error TS6196: 'c1' is declared but never used.
tests/cases/compiler/unusedClassesinNamespace2.ts(2,11): error TS6196: 'c1' is declared but never used.


==== tests/cases/compiler/unusedClassesinNamespace2.ts (1 errors) ====
namespace Validation {
class c1 {
~~~~~~~~
~~
!!! error TS6196: 'c1' is declared but never used.

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests/cases/compiler/unusedClassesinNamespace4.ts(10,5): error TS6196: 'c3' is declared but never used.
tests/cases/compiler/unusedClassesinNamespace4.ts(10,11): error TS6196: 'c3' is declared but never used.


==== tests/cases/compiler/unusedClassesinNamespace4.ts (1 errors) ====
Expand All @@ -12,7 +12,7 @@ tests/cases/compiler/unusedClassesinNamespace4.ts(10,5): error TS6196: 'c3' is d
}

class c3 extends c1 {
~~~~~~~~
~~
!!! error TS6196: 'c3' is declared but never used.

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests/cases/compiler/unusedClassesinNamespace5.ts(10,5): error TS6196: 'c3' is declared but never used.
tests/cases/compiler/unusedClassesinNamespace5.ts(10,11): error TS6196: 'c3' is declared but never used.


==== tests/cases/compiler/unusedClassesinNamespace5.ts (1 errors) ====
Expand All @@ -12,7 +12,7 @@ tests/cases/compiler/unusedClassesinNamespace5.ts(10,5): error TS6196: 'c3' is d
}

class c3 {
~~~~~~~~
~~
!!! error TS6196: 'c3' is declared but never used.
public x: c1;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/unusedDestructuring.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ tests/cases/compiler/unusedDestructuring.ts(4,9): error TS6133: 'c' is declared
tests/cases/compiler/unusedDestructuring.ts(6,7): error TS6133: 'e' is declared but its value is never read.
tests/cases/compiler/unusedDestructuring.ts(7,7): error TS6133: 'g' is declared but its value is never read.
tests/cases/compiler/unusedDestructuring.ts(8,1): error TS6199: All variables are unused.
tests/cases/compiler/unusedDestructuring.ts(10,1): error TS6133: 'f' is declared but its value is never read.
tests/cases/compiler/unusedDestructuring.ts(10,10): error TS6133: 'f' is declared but its value is never read.
tests/cases/compiler/unusedDestructuring.ts(10,12): error TS6198: All destructured elements are unused.
tests/cases/compiler/unusedDestructuring.ts(10,24): error TS6133: 'c' is declared but its value is never read.
tests/cases/compiler/unusedDestructuring.ts(10,32): error TS6133: 'e' is declared but its value is never read.
Expand All @@ -30,7 +30,7 @@ tests/cases/compiler/unusedDestructuring.ts(10,32): error TS6133: 'e' is declare
!!! error TS6199: All variables are unused.

function f({ a, b }, { c, d }, { e }) {
~~~~~~~~~~
~
!!! error TS6133: 'f' is declared but its value is never read.
~~~~~~~~
!!! error TS6198: All destructured elements are unused.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tests/cases/compiler/unusedFunctionsinNamespaces1.ts(2,5): error TS6133: 'function1' is declared but its value is never read.
tests/cases/compiler/unusedFunctionsinNamespaces1.ts(2,14): error TS6133: 'function1' is declared but its value is never read.


==== tests/cases/compiler/unusedFunctionsinNamespaces1.ts (1 errors) ====
namespace Validation {
function function1() {
~~~~~~~~~~~~~~~~~~
~~~~~~~~~
!!! error TS6133: 'function1' is declared but its value is never read.
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/compiler/unusedFunctionsinNamespaces5.ts(9,5): error TS6133: 'function3' is declared but its value is never read.
tests/cases/compiler/unusedFunctionsinNamespaces5.ts(13,5): error TS6133: 'function4' is declared but its value is never read.
tests/cases/compiler/unusedFunctionsinNamespaces5.ts(9,14): error TS6133: 'function3' is declared but its value is never read.
tests/cases/compiler/unusedFunctionsinNamespaces5.ts(13,14): error TS6133: 'function4' is declared but its value is never read.


==== tests/cases/compiler/unusedFunctionsinNamespaces5.ts (2 errors) ====
Expand All @@ -12,13 +12,13 @@ tests/cases/compiler/unusedFunctionsinNamespaces5.ts(13,5): error TS6133: 'funct
}

function function3() {
~~~~~~~~~~~~~~~~~~
~~~~~~~~~
!!! error TS6133: 'function3' is declared but its value is never read.
function1();
}

function function4() {
~~~~~~~~~~~~~~~~~~
~~~~~~~~~
!!! error TS6133: 'function4' is declared but its value is never read.

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests/cases/compiler/unusedFunctionsinNamespaces6.ts(13,5): error TS6133: 'function4' is declared but its value is never read.
tests/cases/compiler/unusedFunctionsinNamespaces6.ts(13,14): error TS6133: 'function4' is declared but its value is never read.


==== tests/cases/compiler/unusedFunctionsinNamespaces6.ts (1 errors) ====
Expand All @@ -15,7 +15,7 @@ tests/cases/compiler/unusedFunctionsinNamespaces6.ts(13,5): error TS6133: 'funct
}

function function4() {
~~~~~~~~~~~~~~~~~~
~~~~~~~~~
!!! error TS6133: 'function4' is declared but its value is never read.

}
Expand Down
20 changes: 10 additions & 10 deletions tests/baselines/reference/unusedIdentifiersConsolidated1.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ tests/cases/compiler/unusedIdentifiersConsolidated1.ts(17,13): error TS6133: 'un
tests/cases/compiler/unusedIdentifiersConsolidated1.ts(24,13): error TS6133: 'unUsedPrivateFunction' is declared but its value is never read.
tests/cases/compiler/unusedIdentifiersConsolidated1.ts(37,11): error TS6133: 'numberRegexp' is declared but its value is never read.
tests/cases/compiler/unusedIdentifiersConsolidated1.ts(44,17): error TS6133: 'unUsedPrivateFunction' is declared but its value is never read.
tests/cases/compiler/unusedIdentifiersConsolidated1.ts(57,5): error TS6196: 'usedLocallyInterface2' is declared but never used.
tests/cases/compiler/unusedIdentifiersConsolidated1.ts(64,5): error TS6196: 'dummy' is declared but never used.
tests/cases/compiler/unusedIdentifiersConsolidated1.ts(67,5): error TS6196: 'unusedInterface' is declared but never used.
tests/cases/compiler/unusedIdentifiersConsolidated1.ts(79,5): error TS6196: 'class3' is declared but never used.
tests/cases/compiler/unusedIdentifiersConsolidated1.ts(99,5): error TS6196: 'interface5' is declared but never used.
tests/cases/compiler/unusedIdentifiersConsolidated1.ts(57,15): error TS6196: 'usedLocallyInterface2' is declared but never used.
tests/cases/compiler/unusedIdentifiersConsolidated1.ts(64,11): error TS6196: 'dummy' is declared but never used.
tests/cases/compiler/unusedIdentifiersConsolidated1.ts(67,15): error TS6196: 'unusedInterface' is declared but never used.
tests/cases/compiler/unusedIdentifiersConsolidated1.ts(79,11): error TS6196: 'class3' is declared but never used.
tests/cases/compiler/unusedIdentifiersConsolidated1.ts(99,15): error TS6196: 'interface5' is declared but never used.


==== tests/cases/compiler/unusedIdentifiersConsolidated1.ts (17 errors) ====
Expand Down Expand Up @@ -99,7 +99,7 @@ tests/cases/compiler/unusedIdentifiersConsolidated1.ts(99,5): error TS6196: 'int
}

interface usedLocallyInterface2 {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
!!! error TS6196: 'usedLocallyInterface2' is declared but never used.
someFunction(s1: string): void;
}
Expand All @@ -108,12 +108,12 @@ tests/cases/compiler/unusedIdentifiersConsolidated1.ts(99,5): error TS6196: 'int
}

class dummy implements usedLocallyInterface {
~~~~~~~~~~~
~~~~~
!!! error TS6196: 'dummy' is declared but never used.
}

interface unusedInterface {
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~
!!! error TS6196: 'unusedInterface' is declared but never used.
}
}
Expand All @@ -127,7 +127,7 @@ tests/cases/compiler/unusedIdentifiersConsolidated1.ts(99,5): error TS6196: 'int
}

class class3 {
~~~~~~~~~~~~
~~~~~~
!!! error TS6196: 'class3' is declared but never used.
}

Expand All @@ -149,7 +149,7 @@ tests/cases/compiler/unusedIdentifiersConsolidated1.ts(99,5): error TS6196: 'int
export let a: interface3;

interface interface5 {
~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~
!!! error TS6196: 'interface5' is declared but never used.
}
}
4 changes: 2 additions & 2 deletions tests/baselines/reference/unusedImports10.errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests/cases/compiler/unusedImports10.ts(9,5): error TS6133: 'a' is declared but its value is never read.
tests/cases/compiler/unusedImports10.ts(9,12): error TS6133: 'a' is declared but its value is never read.


==== tests/cases/compiler/unusedImports10.ts (1 errors) ====
Expand All @@ -11,6 +11,6 @@ tests/cases/compiler/unusedImports10.ts(9,5): error TS6133: 'a' is declared but

module B {
import a = A;
~~~~~~~~
~
!!! error TS6133: 'a' is declared but its value is never read.
}
4 changes: 2 additions & 2 deletions tests/baselines/reference/unusedImports12.errors.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tests/cases/compiler/a.ts(1,1): error TS6133: 'Member' is declared but its value is never read.
tests/cases/compiler/a.ts(2,1): error TS6192: All imports in import declaration are unused.
tests/cases/compiler/a.ts(3,1): error TS6133: 'ns' is declared but its value is never read.
tests/cases/compiler/a.ts(4,1): error TS6133: 'r' is declared but its value is never read.
tests/cases/compiler/a.ts(4,8): error TS6133: 'r' is declared but its value is never read.


==== tests/cases/compiler/a.ts (4 errors) ====
Expand All @@ -15,7 +15,7 @@ tests/cases/compiler/a.ts(4,1): error TS6133: 'r' is declared but its value is n
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS6133: 'ns' is declared but its value is never read.
import r = require("./b");
~~~~~~~~
~
!!! error TS6133: 'r' is declared but its value is never read.

==== tests/cases/compiler/b.ts (0 errors) ====
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/unusedImports8.errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests/cases/compiler/file2.ts(1,41): error TS6133: 't2' is declared but its value is never read.
tests/cases/compiler/file2.ts(1,50): error TS6133: 't2' is declared but its value is never read.


==== tests/cases/compiler/file1.ts (0 errors) ====
Expand All @@ -16,7 +16,7 @@ tests/cases/compiler/file2.ts(1,41): error TS6133: 't2' is declared but its valu

==== tests/cases/compiler/file2.ts (1 errors) ====
import {Calculator as calc, test as t1, test2 as t2} from "./file1"
~~~~~~~~~~~
~~
!!! error TS6133: 't2' is declared but its value is never read.

var x = new calc();
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/unusedImports9.errors.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
tests/cases/compiler/file2.ts(1,1): error TS6133: 'c' is declared but its value is never read.
tests/cases/compiler/file2.ts(1,8): error TS6133: 'c' is declared but its value is never read.


==== tests/cases/compiler/file2.ts (1 errors) ====
import c = require('./file1')
~~~~~~~~
~
!!! error TS6133: 'c' is declared but its value is never read.
==== tests/cases/compiler/file1.ts (0 errors) ====
export class Calculator {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/b.ts(1,1): error TS6192: All imports in import declaration are unused.
/b.ts(2,1): error TS6192: All imports in import declaration are unused.
/b.ts(4,14): error TS6133: 'a2' is declared but its value is never read.
/b.ts(4,23): error TS6133: 'b2' is declared but its value is never read.
/b.ts(6,12): error TS6133: 'ns2' is declared but its value is never read.
/b.ts(4,19): error TS6133: 'a2' is declared but its value is never read.
/b.ts(4,28): error TS6133: 'b2' is declared but its value is never read.
/b.ts(6,17): error TS6133: 'ns2' is declared but its value is never read.
/b.ts(8,8): error TS6133: 'd5' is declared but its value is never read.


Expand All @@ -20,13 +20,13 @@
!!! error TS6192: All imports in import declaration are unused.

import d3, { a as a2, b as b2 } from "./a";
~~~~~~~
~~
!!! error TS6133: 'a2' is declared but its value is never read.
~~~~~~~
~~
!!! error TS6133: 'b2' is declared but its value is never read.
d3;
import d4, * as ns2 from "./a";
~~~~~~~~
~~~
!!! error TS6133: 'ns2' is declared but its value is never read.
d4;
import d5, * as ns3 from "./a";
Expand Down
Loading

0 comments on commit 5f34d06

Please sign in to comment.