Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Hanson committed Mar 22, 2018
1 parent 4dc9423 commit bb4332b
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 24 deletions.
14 changes: 7 additions & 7 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,16 @@ namespace ts {
getSuggestionDiagnostics: file => {
return (suggestionDiagnostics.get(file.fileName) || emptyArray).concat(getUnusedDiagnostics());
function getUnusedDiagnostics(): ReadonlyArray<Diagnostic> {
if (file.isDeclarationFile) return emptyArray;

checkSourceFile(file);
const diagnostics: Diagnostic[] = [];
Debug.assert(!!(getNodeLinks(file).flags & NodeCheckFlags.TypeChecked));
if (!file.isDeclarationFile) {
checkUnusedIdentifiers(allPotentiallyUnusedIdentifiers.get(file.fileName)!, (kind, diag) => {
if (!unusedIsError(kind)) {
diagnostics.push({ ...diag, category: DiagnosticCategory.Suggestion });
}
});
}
checkUnusedIdentifiers(allPotentiallyUnusedIdentifiers.get(file.fileName)!, (kind, diag) => {
if (!unusedIsError(kind)) {
diagnostics.push({ ...diag, category: DiagnosticCategory.Suggestion });
}
});
return diagnostics;
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1623,7 +1623,7 @@ namespace ts {
messageText: text,
category: message.category,
code: message.code,
unused: message.unused,
reportsUnused: message.unused,
};
}

Expand Down Expand Up @@ -1654,7 +1654,7 @@ namespace ts {
messageText: text,
category: message.category,
code: message.code,
unused: message.unused,
reportsUnused: message.unused,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4061,7 +4061,7 @@ namespace ts {
messageText: string | DiagnosticMessageChain;
category: DiagnosticCategory;
/** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
unused?: {};
reportsUnused?: {};
code: number;
source?: string;
}
Expand Down
4 changes: 2 additions & 2 deletions src/harness/unittests/matchFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ namespace ts {
}
{
const actual = parseJsonConfigFileContent(json, host, basePath, existingOptions, configFileName, resolutionStack);
expected.errors = expected.errors.map<Diagnostic>(error => ({
expected.errors = expected.errors.map((error): Diagnostic => ({
category: error.category,
code: error.code,
file: undefined,
length: undefined,
messageText: error.messageText,
start: undefined,
unused: undefined,
reportsUnused: undefined,
}));
assertParsed(actual, expected);
}
Expand Down
4 changes: 2 additions & 2 deletions src/server/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ namespace ts.server {
const request = this.processRequest<protocol.SyntacticDiagnosticsSyncRequest | protocol.SemanticDiagnosticsSyncRequest | protocol.SuggestionDiagnosticsSyncRequest>(command, { file, includeLinePosition: true });
const response = this.processResponse<protocol.SyntacticDiagnosticsSyncResponse | protocol.SemanticDiagnosticsSyncResponse | protocol.SuggestionDiagnosticsSyncResponse>(request);

return (<protocol.DiagnosticWithLinePosition[]>response.body).map<Diagnostic>(entry => {
return (<protocol.DiagnosticWithLinePosition[]>response.body).map((entry): Diagnostic => {
const category = firstDefined(Object.keys(DiagnosticCategory), id =>
isString(id) && entry.category === id.toLowerCase() ? (<any>DiagnosticCategory)[id] : undefined);
return {
Expand All @@ -367,7 +367,7 @@ namespace ts.server {
messageText: entry.message,
category: Debug.assertDefined(category, "convertDiagnostic: category should not be undefined"),
code: entry.code,
unused: entry.unused,
reportsUnused: entry.reportsUnused,
};
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ namespace ts.server.protocol {
category: string;
code: number;
/** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
unused?: {};
reportsUnused?: {};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ declare namespace ts {
messageText: string | DiagnosticMessageChain;
category: DiagnosticCategory;
/** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
unused?: {};
reportsUnused?: {};
code: number;
source?: string;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ declare namespace ts {
messageText: string | DiagnosticMessageChain;
category: DiagnosticCategory;
/** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
unused?: {};
reportsUnused?: {};
code: number;
source?: string;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/cases/fourslash/convertFunctionToEs6ClassJsDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/////**
//// * This is a cool function!
////*/
////fn.prototype.bar = function (x, y, z) {
////fn.prototype.bar = function (y) {
//// this.x = y;
////};

Expand All @@ -38,7 +38,7 @@ verify.codeFix({
/**
* This is a cool function!
*/
bar(x, y, z) {
bar(y) {
this.x = y;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
////
////exports.z = 2;
////exports.f = function(z) {
//// exports.z; z;
//// z;
////}

// TODO: GH#22492 Should be a able access `exports.z` inside `exports.f`

verify.codeFix({
description: "Convert to ES6 module",
// TODO: GH#22492
newFileContent:
`export const x = 0;
x;
Expand All @@ -27,9 +28,8 @@ const _y = y;
export { _y as y };
_y;
const _z = 2;
export { _z as z };
export const z = 2;
export function f(z) {
_z z;
z;
}`,
});

0 comments on commit bb4332b

Please sign in to comment.