Skip to content

Commit 124e05f

Browse files
author
Paul van Brenk
committed
PR Feedback
1 parent 6f4fb06 commit 124e05f

8 files changed

Lines changed: 31 additions & 36 deletions

File tree

src/compiler/core.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="types.ts"/>
1+
/// <reference path="types.ts"/>
22
/// <reference path="performance.ts" />
33

44

@@ -115,15 +115,6 @@ namespace ts {
115115
return -1;
116116
}
117117

118-
export function firstOrUndefined<T>(array: T[], predicate: (x: T) => boolean): T {
119-
for (let i = 0, len = array.length; i < len; i++) {
120-
if (predicate(array[i])) {
121-
return array[i];
122-
}
123-
}
124-
return undefined;
125-
}
126-
127118
export function indexOfAnyCharCode(text: string, charCodes: number[], start?: number): number {
128119
for (let i = start || 0, len = text.length; i < len; i++) {
129120
if (contains(charCodes, text.charCodeAt(i))) {
@@ -229,6 +220,19 @@ namespace ts {
229220
return true;
230221
}
231222

223+
/**
224+
* Returns the first element that matches the predicate, or undefined if none
225+
* could be found.
226+
*/
227+
export function find<T>(array: T[], predicate: (item: T) => boolean): T {
228+
for (let i = 0, len = array.length; i < len; i++) {
229+
if (predicate(array[i])) {
230+
return array[i];
231+
}
232+
}
233+
return undefined;
234+
}
235+
232236
/**
233237
* Returns the last element of an array if non-empty, undefined otherwise.
234238
*/

src/compiler/diagnosticMessages.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3033,31 +3033,31 @@
30333033
"code": 17010
30343034
},
30353035
"Add missing 'super()' call.": {
3036-
"category": "CodeFix",
3036+
"category": "Message",
30373037
"code": 90001
30383038
},
30393039
"Make 'super()' call the first statement in the constructor.": {
3040-
"category": "CodeFix",
3040+
"category": "Message",
30413041
"code": 90002
30423042
},
30433043
"Change 'extends' to 'implements'": {
3044-
"category": "CodeFix",
3044+
"category": "Message",
30453045
"code": 90003
30463046
},
30473047
"Remove unused identifiers": {
3048-
"category": "CodeFix",
3048+
"category": "Message",
30493049
"code": 90004
30503050
},
30513051
"Implement interface on reference": {
3052-
"category": "CodeFix",
3052+
"category": "Message",
30533053
"code": 90005
30543054
},
30553055
"Implement interface on class": {
3056-
"category": "CodeFix",
3056+
"category": "Message",
30573057
"code": 90006
30583058
},
30593059
"Implement inherited abstract class": {
3060-
"category": "CodeFix",
3060+
"category": "Message",
30613061
"code": 90007
30623062
}
30633063
}

src/compiler/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2547,7 +2547,6 @@ namespace ts {
25472547
Warning,
25482548
Error,
25492549
Message,
2550-
CodeFix,
25512550
}
25522551

25532552
export enum ModuleResolutionKind {

src/harness/fourslash.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//
1+
//
22
// Copyright (c) Microsoft Corporation. All rights reserved.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1879,11 +1879,11 @@ namespace FourSlash {
18791879
this.raiseError("Errors expected.");
18801880
}
18811881

1882-
if (diagnostics.length > 1 && !errorCode) {
1882+
if (diagnostics.length > 1 && errorCode !== undefined) {
18831883
this.raiseError("When there's more than one error, you must specify the errror to fix.");
18841884
}
18851885

1886-
const diagnostic = !errorCode ? diagnostics[0] : ts.firstOrUndefined(diagnostics, d => d.code == errorCode);
1886+
const diagnostic = !errorCode ? diagnostics[0] : ts.find(diagnostics, d => d.code == errorCode);
18871887

18881888
const actual = this.languageService.getCodeFixesAtPosition(fileName, diagnostic.start, diagnostic.length, [`TS${diagnostic.code}`]);
18891889

src/services/codefixes/codeFixProvider.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
/* @internal */
1+
/* @internal */
22
namespace ts {
33
export interface CodeFix {
4-
name: string;
54
errorCodes: string[];
65
getCodeActions(context: CodeFixContext): CodeAction[];
76
}
@@ -14,7 +13,7 @@ namespace ts {
1413
newLineCharacter: string;
1514
}
1615

17-
export namespace codeFix {
16+
export namespace codefix {
1817
const codeFixes: Map<CodeFix[]> = {};
1918

2019
export function registerCodeFix(action: CodeFix) {
@@ -37,8 +36,6 @@ namespace ts {
3736
const fixes = codeFixes[context.errorCode];
3837
let allActions: CodeAction[] = [];
3938

40-
Debug.assert(fixes && fixes.length > 0, "No fixes found for error: '${errorCode}'.");
41-
4239
forEach(fixes, f => {
4340
const actions = f.getCodeActions(context);
4441
if (actions && actions.length > 0) {
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
///<reference path='..\services.ts' />
22
///<reference path='codeFixProvider.ts' />
33
///<reference path='superFixes.ts' />
4-
///<reference path='unusedIdentifierFixes.ts' />
5-
///<reference path='changeExtendsToImplementsFix.ts' />
6-
///<reference path='interfaceFixes.ts' />

src/services/codefixes/superFixes.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
/* @internal */
2-
namespace ts.codeFix {
2+
namespace ts.codefix {
33
function getOpenBraceEnd(constructor: ConstructorDeclaration, sourceFile: SourceFile) {
44
// First token is the open curly, this is where we want to put the 'super' call.
55
return constructor.body.getFirstToken(sourceFile).getEnd();
66
}
77

88
registerCodeFix({
9-
name: "AddMissingSuperCallFix",
10-
errorCodes: ["TS2377"],
9+
errorCodes: [`TS${Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call.code}`],
1110
getCodeActions: (context: CodeFixContext) => {
1211
const sourceFile = context.sourceFile;
1312
const token = getTokenAtPosition(sourceFile, context.span.start);
@@ -22,8 +21,7 @@ namespace ts.codeFix {
2221
});
2322

2423
registerCodeFix({
25-
name: "MakeSuperCallTheFirstStatementInTheConstructor",
26-
errorCodes: ["TS17009"],
24+
errorCodes: [`TS${Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class.code}`],
2725
getCodeActions: (context: CodeFixContext) => {
2826
const sourceFile = context.sourceFile;
2927

src/services/services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,7 @@ namespace ts {
19021902
}
19031903

19041904
export function getSupportedCodeFixes() {
1905-
return codeFix.CodeFixProvider.getSupportedErrorCodes();
1905+
return codefix.CodeFixProvider.getSupportedErrorCodes();
19061906
}
19071907

19081908
// Cache host information about script Should be refreshed
@@ -3041,7 +3041,7 @@ namespace ts {
30413041
documentRegistry: DocumentRegistry = createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames(), host.getCurrentDirectory())): LanguageService {
30423042

30433043
const syntaxTreeCache: SyntaxTreeCache = new SyntaxTreeCache(host);
3044-
const codeFixProvider: codeFix.CodeFixProvider = new codeFix.CodeFixProvider();
3044+
const codeFixProvider: codefix.CodeFixProvider = new codefix.CodeFixProvider();
30453045
let ruleProvider: formatting.RulesProvider;
30463046
let program: Program;
30473047
let lastProjectVersion: string;

0 commit comments

Comments
 (0)