Skip to content

Commit bb4332b

Browse files
author
Andy Hanson
committed
Code review
1 parent 4dc9423 commit bb4332b

File tree

10 files changed

+24
-24
lines changed

10 files changed

+24
-24
lines changed

src/compiler/checker.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,16 @@ namespace ts {
314314
getSuggestionDiagnostics: file => {
315315
return (suggestionDiagnostics.get(file.fileName) || emptyArray).concat(getUnusedDiagnostics());
316316
function getUnusedDiagnostics(): ReadonlyArray<Diagnostic> {
317+
if (file.isDeclarationFile) return emptyArray;
318+
317319
checkSourceFile(file);
318320
const diagnostics: Diagnostic[] = [];
319321
Debug.assert(!!(getNodeLinks(file).flags & NodeCheckFlags.TypeChecked));
320-
if (!file.isDeclarationFile) {
321-
checkUnusedIdentifiers(allPotentiallyUnusedIdentifiers.get(file.fileName)!, (kind, diag) => {
322-
if (!unusedIsError(kind)) {
323-
diagnostics.push({ ...diag, category: DiagnosticCategory.Suggestion });
324-
}
325-
});
326-
}
322+
checkUnusedIdentifiers(allPotentiallyUnusedIdentifiers.get(file.fileName)!, (kind, diag) => {
323+
if (!unusedIsError(kind)) {
324+
diagnostics.push({ ...diag, category: DiagnosticCategory.Suggestion });
325+
}
326+
});
327327
return diagnostics;
328328
}
329329
},

src/compiler/core.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1623,7 +1623,7 @@ namespace ts {
16231623
messageText: text,
16241624
category: message.category,
16251625
code: message.code,
1626-
unused: message.unused,
1626+
reportsUnused: message.unused,
16271627
};
16281628
}
16291629

@@ -1654,7 +1654,7 @@ namespace ts {
16541654
messageText: text,
16551655
category: message.category,
16561656
code: message.code,
1657-
unused: message.unused,
1657+
reportsUnused: message.unused,
16581658
};
16591659
}
16601660

src/compiler/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4061,7 +4061,7 @@ namespace ts {
40614061
messageText: string | DiagnosticMessageChain;
40624062
category: DiagnosticCategory;
40634063
/** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
4064-
unused?: {};
4064+
reportsUnused?: {};
40654065
code: number;
40664066
source?: string;
40674067
}

src/harness/unittests/matchFiles.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ namespace ts {
123123
}
124124
{
125125
const actual = parseJsonConfigFileContent(json, host, basePath, existingOptions, configFileName, resolutionStack);
126-
expected.errors = expected.errors.map<Diagnostic>(error => ({
126+
expected.errors = expected.errors.map((error): Diagnostic => ({
127127
category: error.category,
128128
code: error.code,
129129
file: undefined,
130130
length: undefined,
131131
messageText: error.messageText,
132132
start: undefined,
133-
unused: undefined,
133+
reportsUnused: undefined,
134134
}));
135135
assertParsed(actual, expected);
136136
}

src/server/client.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ namespace ts.server {
357357
const request = this.processRequest<protocol.SyntacticDiagnosticsSyncRequest | protocol.SemanticDiagnosticsSyncRequest | protocol.SuggestionDiagnosticsSyncRequest>(command, { file, includeLinePosition: true });
358358
const response = this.processResponse<protocol.SyntacticDiagnosticsSyncResponse | protocol.SemanticDiagnosticsSyncResponse | protocol.SuggestionDiagnosticsSyncResponse>(request);
359359

360-
return (<protocol.DiagnosticWithLinePosition[]>response.body).map<Diagnostic>(entry => {
360+
return (<protocol.DiagnosticWithLinePosition[]>response.body).map((entry): Diagnostic => {
361361
const category = firstDefined(Object.keys(DiagnosticCategory), id =>
362362
isString(id) && entry.category === id.toLowerCase() ? (<any>DiagnosticCategory)[id] : undefined);
363363
return {
@@ -367,7 +367,7 @@ namespace ts.server {
367367
messageText: entry.message,
368368
category: Debug.assertDefined(category, "convertDiagnostic: category should not be undefined"),
369369
code: entry.code,
370-
unused: entry.unused,
370+
reportsUnused: entry.reportsUnused,
371371
};
372372
});
373373
}

src/server/protocol.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ namespace ts.server.protocol {
456456
category: string;
457457
code: number;
458458
/** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
459-
unused?: {};
459+
reportsUnused?: {};
460460
}
461461

462462
/**

tests/baselines/reference/api/tsserverlibrary.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2279,7 +2279,7 @@ declare namespace ts {
22792279
messageText: string | DiagnosticMessageChain;
22802280
category: DiagnosticCategory;
22812281
/** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
2282-
unused?: {};
2282+
reportsUnused?: {};
22832283
code: number;
22842284
source?: string;
22852285
}

tests/baselines/reference/api/typescript.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2279,7 +2279,7 @@ declare namespace ts {
22792279
messageText: string | DiagnosticMessageChain;
22802280
category: DiagnosticCategory;
22812281
/** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
2282-
unused?: {};
2282+
reportsUnused?: {};
22832283
code: number;
22842284
source?: string;
22852285
}

tests/cases/fourslash/convertFunctionToEs6ClassJsDoc.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/////**
1818
//// * This is a cool function!
1919
////*/
20-
////fn.prototype.bar = function (x, y, z) {
20+
////fn.prototype.bar = function (y) {
2121
//// this.x = y;
2222
////};
2323

@@ -38,7 +38,7 @@ verify.codeFix({
3838
/**
3939
* This is a cool function!
4040
*/
41-
bar(x, y, z) {
41+
bar(y) {
4242
this.x = y;
4343
}
4444
}

tests/cases/fourslash/refactorConvertToEs6Module_export_referenced.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
////
1313
////exports.z = 2;
1414
////exports.f = function(z) {
15-
//// exports.z; z;
15+
//// z;
1616
////}
1717

18+
// TODO: GH#22492 Should be a able access `exports.z` inside `exports.f`
19+
1820
verify.codeFix({
1921
description: "Convert to ES6 module",
20-
// TODO: GH#22492
2122
newFileContent:
2223
`export const x = 0;
2324
x;
@@ -27,9 +28,8 @@ const _y = y;
2728
export { _y as y };
2829
_y;
2930
30-
const _z = 2;
31-
export { _z as z };
31+
export const z = 2;
3232
export function f(z) {
33-
_z z;
33+
z;
3434
}`,
3535
});

0 commit comments

Comments
 (0)