Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3661,7 +3661,7 @@
"category": "Message",
"code": 90013
},
"Change {0} to {1}.": {
"Change '{0}' to '{1}'.": {
"category": "Message",
"code": 90014
},
Expand Down
2 changes: 1 addition & 1 deletion src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2381,7 +2381,7 @@ Actual: ${stringify(fullActual)}`);
}));

return ts.flatMap(ts.deduplicate(diagnosticsForCodeFix, ts.equalOwnProperties), diagnostic => {
if (errorCode && errorCode !== diagnostic.code) {
if (errorCode !== undefined && errorCode !== diagnostic.code) {
return;
}

Expand Down
5 changes: 4 additions & 1 deletion tests/cases/fourslash/codeFixChangeExtendsToImplements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
//// interface I {}
//// [|/* */ class /* */ C /* */ extends /* */ I|]{}

verify.rangeAfterCodeFix("/* */ class /* */ C /* */ implements /* */ I");
verify.codeFix({
description: "Change 'extends' to 'implements'.",
newRangeContent: "/* */ class /* */ C /* */ implements /* */ I",
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@

//// [|abstract class A extends I1 implements I2|] { }

verify.rangeAfterCodeFix("abstract class A implements I1, I2");
verify.codeFix({
description: "Change 'extends' to 'implements'.",
// TODO: GH#18794
newRangeContent: "abstract class A implements I1 , I2",
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
////interface I<X> { x: X}
////[|class C<T extends string , U> extends I<T>|]{}

verify.rangeAfterCodeFix("class C<T extends string , U> implements I<T>");
verify.codeFix({
description: "Change 'extends' to 'implements'.",
newRangeContent: "class C<T extends string , U> implements I<T>",
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@

//// @sealed
//// [|class A extends I1 implements I2 { }|]
verify.rangeAfterCodeFix("class A implements I1, I2 { }");
verify.codeFix({
description: "Change 'extends' to 'implements'.",
// TODO: GH#18794
newRangeContent: "class A implements I1 , I2 { }",
});
5 changes: 4 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax1.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/// <reference path='fourslash.ts' />
//// var x: [|?|] = 12;

verify.rangeAfterCodeFix("any");
verify.codeFix({
description: "Change '?' to 'any'.",
newRangeContent: "any",
});
8 changes: 7 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax10.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
/// <reference path='fourslash.ts' />
//// function f(x: [|number?|]) {
//// }
verify.rangeAfterCodeFix("number | null", /*includeWhiteSpace*/ false, /*errorCode*/ 8020, 0);

verify.codeFix({
description: "Change 'number?' to 'number | null'.",
errorCode: 8020,
index: 0,
newRangeContent: "number | null",
});
8 changes: 7 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax11.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
/// <reference path='fourslash.ts' />
//// var f = function f(x: [|string?|]) {
//// }
verify.rangeAfterCodeFix("string | null | undefined", /*includeWhiteSpace*/ false, /*errorCode*/ 8020, 1);

verify.codeFix({
description: "Change 'string?' to 'string | null | undefined'.",
errorCode: 8020,
index: 1,
newRangeContent: "string | null | undefined",
});
8 changes: 7 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax12.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
////class C {
//// p: [|*|]
////}
verify.rangeAfterCodeFix("any", /*includeWhiteSpace*/ false, /*errorCode*/ 8020, 0);

verify.codeFix({
description: "Change '*' to 'any'.",
errorCode: 8020,
index: 0,
newRangeContent: "any",
});
8 changes: 7 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax13.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
////class C {
//// p: [|*|] = 12
////}
verify.rangeAfterCodeFix("any", /*includeWhiteSpace*/ false, /*errorCode*/ 8020, 0);

verify.codeFix({
description: "Change '*' to 'any'.",
errorCode: 8020,
index: 0,
newRangeContent: "any",
});
7 changes: 6 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax14.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
/// <reference path='fourslash.ts' />
//// var x = 12 as [|number?|];

verify.rangeAfterCodeFix("number | null", /*includeWhiteSpace*/ false, /*errorCode*/ 8020, 0);
verify.codeFix({
description: "Change 'number?' to 'number | null'.",
errorCode: 8020,
index: 0,
newRangeContent: "number | null",
});
7 changes: 6 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax15.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
//// var f = <[|function(number?): number|]>(x => x);

// note: without --strict, number? --> number, not number | null
verify.rangeAfterCodeFix("(arg0: number) => number", /*includeWhiteSpace*/ false, /*errorCode*/ 8020, 0);
verify.codeFix({
description: "Change 'function(number?): number' to '(arg0: number) => number'.",
errorCode: 8020,
index: 0,
newRangeContent: "(arg0: number) => number",
});
5 changes: 4 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax16.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/// <reference path='fourslash.ts' />
//// var f: { [K in keyof number]: [|*|] };

verify.rangeAfterCodeFix("any");
verify.codeFix({
description: "Change '*' to 'any'.",
newRangeContent: "any",
});
6 changes: 5 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax17.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/// <reference path='fourslash.ts' />
//// declare function index(ix: number): [|*|];
verify.rangeAfterCodeFix("any");

verify.codeFix({
description: "Change '*' to 'any'.",
newRangeContent: "any",
});
6 changes: 5 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax18.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/// <reference path='fourslash.ts' />
//// var index: { (ix: number): [|?|] };
verify.rangeAfterCodeFix("any");

verify.codeFix({
description: "Change '?' to 'any'.",
newRangeContent: "any",
});
6 changes: 5 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax19.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/// <reference path='fourslash.ts' />
//// var index: { new (ix: number): [|?|] };
verify.rangeAfterCodeFix("any");

verify.codeFix({
description: "Change '?' to 'any'.",
newRangeContent: "any",
});
5 changes: 4 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax2.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/// <reference path='fourslash.ts' />
//// var x: [|*|] = 12;

verify.rangeAfterCodeFix("any");
verify.codeFix({
description: "Change '*' to 'any'.",
newRangeContent: "any",
});
6 changes: 5 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax20.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/// <reference path='fourslash.ts' />
//// var index = { get p(): [|*|] { return 12 } };
verify.rangeAfterCodeFix("any");

verify.codeFix({
description: "Change '*' to 'any'.",
newRangeContent: "any",
});
6 changes: 5 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax21.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/// <reference path='fourslash.ts' />
//// var index = { set p(x: [|*|]) { } };
verify.rangeAfterCodeFix("any");

verify.codeFix({
description: "Change '*' to 'any'.",
newRangeContent: "any",
});
6 changes: 5 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax22.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/// <reference path='fourslash.ts' />
//// var index: { [s: string]: [|*|] };
verify.rangeAfterCodeFix("any");

verify.codeFix({
description: "Change '*' to 'any'.",
newRangeContent: "any",
});
6 changes: 5 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax23.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
//// m(): [|*|] {
//// }
////}
verify.rangeAfterCodeFix("any");

verify.codeFix({
description: "Change '*' to 'any'.",
newRangeContent: "any",
});
6 changes: 5 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax24.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
////declare class C {
//// m(): [|*|];
////}
verify.rangeAfterCodeFix("any");

verify.codeFix({
description: "Change '*' to 'any'.",
newRangeContent: "any",
});
6 changes: 5 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax25.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
////declare class C {
//// p: [|*|];
////}
verify.rangeAfterCodeFix("any");

verify.codeFix({
description: "Change '*' to 'any'.",
newRangeContent: "any",
});
6 changes: 5 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax26.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
////class C {
//// p: [|*|] = 12;
////}
verify.rangeAfterCodeFix("any");

verify.codeFix({
description: "Change '*' to 'any'.",
newRangeContent: "any",
});
8 changes: 7 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax27.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// @strict: true
/// <reference path='fourslash.ts' />
////type T = [|...number?|];
verify.rangeAfterCodeFix("number[] | null", /*includeWhiteSpace*/ false, /*errorCode*/ 8020, 0);

verify.codeFix({
description: "Change '...number?' to 'number[] | null'.",
errorCode: 8020,
index: 0,
newRangeContent: "number[] | null",
});
5 changes: 4 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax3.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/// <reference path='fourslash.ts' />
//// var x: [|......number[][]|] = 12;

verify.rangeAfterCodeFix("number[][][][]");
verify.codeFix({
description: "Change '......number[][]' to 'number[][][][]'.",
newRangeContent: "number[][][][]",
});
5 changes: 4 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax4.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/// <reference path='fourslash.ts' />
//// var x: [|Array.<number>|] = 12;

verify.rangeAfterCodeFix("number[]");
verify.codeFix({
description: "Change 'Array.<number>' to 'number[]'.",
newRangeContent: "number[]",
});
7 changes: 6 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
/// <reference path='fourslash.ts' />
//// var x: [|?number|] = 12;

verify.rangeAfterCodeFix("number | null", /*includeWhiteSpace*/ false, /*errorCode*/ 8020, 0);
verify.codeFix({
description: "Change '?number' to 'number | null'.",
errorCode: 8020,
index: 0,
newRangeContent: "number | null",
});
6 changes: 5 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
/// <reference path='fourslash.ts' />
//// var x: [|number?|] = 12;

verify.rangeAfterCodeFix("number | null | undefined", /*includeWhiteSpace*/ undefined, /*errorCode*/ undefined, 1);
verify.codeFix({
description: "Change 'number?' to 'number | null | undefined'.",
index: 1,
newRangeContent: "number | null | undefined",
});
5 changes: 4 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax7.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/// <reference path='fourslash.ts' />
//// var x: [|!number|] = 12;

verify.rangeAfterCodeFix("number");
verify.codeFix({
description: "Change '!number' to 'number'.",
newRangeContent: "number",
});
5 changes: 4 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax8.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/// <reference path='fourslash.ts' />
//// var x: [|function(this: number, number): string|] = 12;

verify.rangeAfterCodeFix("(this: number, arg1: number) => string");
verify.codeFix({
description: "Change 'function(this: number, number): string' to '(this: number, arg1: number) => string'.",
newRangeContent: "(this: number, arg1: number) => string",
});
5 changes: 4 additions & 1 deletion tests/cases/fourslash/codeFixChangeJSDocSyntax9.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/// <reference path='fourslash.ts' />
//// var x: [|function(new: number)|] = 12;

verify.rangeAfterCodeFix("new () => number");
verify.codeFix({
description: "Change 'function(new: number)' to 'new () => number'.",
newRangeContent: "new () => number",
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
/// <reference path='fourslash.ts' />

//// class A {
//// f() {}
//// }
////class A {
//// f() {}
////}
////
//// let B = class implements A {[| |]}
////let B = class implements A {[| |]}

verify.rangeAfterCodeFix(`
f(): void{
throw new Error("Method not implemented.");
}
`);
verify.codeFix({
description: "Implement interface 'A'.",
// TODO: GH#18795
newRangeContent: `f(): void {\r
throw new Error("Method not implemented.");\r
}\r
`
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
/// <reference path='fourslash.ts' />

//// function foo<T>(a: T) {
//// abstract class C<U> {
//// abstract a: T | U;
//// }
//// return C;
//// }
////function foo<T>(a: T) {
//// abstract class C<U> {
//// abstract a: T | U;
//// }
//// return C;
////}
////
//// let B = class extends foo("s")<number> {[| |]}
////let B = class extends foo("s")<number> {[| |]}

verify.rangeAfterCodeFix(`
a: string | number;
`);
verify.codeFix({
description: "Implement inherited abstract class.",
// TODO: GH#18795
newRangeContent: `a: string | number;\r
`
});
Loading