mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Codefixes for unused variables, properties etc.
This commit is contained in:
@@ -2049,7 +2049,7 @@ namespace FourSlash {
|
||||
this.raiseError("Errors expected.");
|
||||
}
|
||||
|
||||
if (diagnostics.length > 1 && errorCode !== undefined) {
|
||||
if (diagnostics.length > 1 && errorCode === undefined) {
|
||||
this.raiseError("When there's more than one error, you must specify the errror to fix.");
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
///<reference path='superFixes.ts' />
|
||||
///<reference path='unusedIdentifierFixes.ts' />
|
||||
@@ -0,0 +1,153 @@
|
||||
/* @internal */
|
||||
namespace ts.codefix {
|
||||
registerCodeFix({
|
||||
errorCodes: [
|
||||
Diagnostics._0_is_declared_but_never_used.code,
|
||||
Diagnostics.Property_0_is_declared_but_never_used.code
|
||||
],
|
||||
getCodeActions: (context: CodeFixContext) => {
|
||||
const sourceFile = context.sourceFile;
|
||||
const start = context.span.start;
|
||||
const token = getTokenAtPosition(sourceFile, start);
|
||||
|
||||
if (token.kind === ts.SyntaxKind.Identifier) {
|
||||
if (token.parent.kind === ts.SyntaxKind.VariableDeclaration) {
|
||||
if (token.parent.parent.parent.kind === SyntaxKind.ForStatement) {
|
||||
const forStatement = <ForStatement>token.parent.parent.parent;
|
||||
const initializer = <VariableDeclarationList>forStatement.initializer;
|
||||
if (initializer.declarations.length === 1) {
|
||||
return createCodeFix("", initializer.pos, initializer.end - initializer.pos);
|
||||
}
|
||||
else {
|
||||
if (initializer.declarations[0] === token.parent) {
|
||||
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos + 1);
|
||||
}
|
||||
else {
|
||||
return createCodeFix("", token.parent.pos - 1, token.parent.end - token.parent.pos + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (token.parent.parent.parent.kind === SyntaxKind.ForInStatement) {
|
||||
const forInStatement = <ForInStatement>token.parent.parent.parent;
|
||||
const initializer = <VariableDeclarationList>forInStatement.initializer;
|
||||
return createCodeFix("{}", initializer.declarations[0].pos, initializer.declarations[0].end - initializer.declarations[0].pos);
|
||||
}
|
||||
else if (token.parent.parent.parent.kind === SyntaxKind.ForOfStatement) {
|
||||
const forOfStatement = <ForOfStatement>token.parent.parent.parent;
|
||||
const initializer = <VariableDeclarationList>forOfStatement.initializer;
|
||||
return createCodeFix("{}", initializer.declarations[0].pos, initializer.declarations[0].end - initializer.declarations[0].pos);
|
||||
}
|
||||
else if (token.parent.parent.kind === SyntaxKind.CatchClause) {
|
||||
const catchClause = <CatchClause>token.parent.parent;
|
||||
const parameter = catchClause.variableDeclaration.getChildren()[0];
|
||||
return createCodeFix("", parameter.pos, parameter.end - parameter.pos);
|
||||
}
|
||||
else {
|
||||
const variableStatement = <VariableStatement>token.parent.parent.parent;
|
||||
if (variableStatement.declarationList.declarations.length === 1) {
|
||||
return createCodeFix("", variableStatement.pos, variableStatement.end - variableStatement.pos);
|
||||
}
|
||||
else {
|
||||
const declarations = variableStatement.declarationList.declarations;
|
||||
if (declarations[0].name === token) {
|
||||
return createCodeFix("", token.parent.pos + 1, token.parent.end - token.parent.pos);
|
||||
}
|
||||
else {
|
||||
return createCodeFix("", token.parent.pos - 1, token.parent.end - token.parent.pos + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (token.parent.kind === SyntaxKind.FunctionDeclaration ||
|
||||
token.parent.kind === SyntaxKind.ClassDeclaration ||
|
||||
token.parent.kind === SyntaxKind.InterfaceDeclaration ||
|
||||
token.parent.kind === SyntaxKind.MethodDeclaration ||
|
||||
token.parent.kind === SyntaxKind.ModuleDeclaration ||
|
||||
token.parent.kind === SyntaxKind.PropertyDeclaration ||
|
||||
token.parent.kind === SyntaxKind.ArrowFunction) {
|
||||
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos);
|
||||
}
|
||||
|
||||
if (token.parent.kind === SyntaxKind.TypeParameter) {
|
||||
const typeParameters = (<ClassDeclaration>token.parent.parent).typeParameters;
|
||||
if (typeParameters.length === 1) {
|
||||
return createCodeFix("", token.parent.pos - 1, token.parent.end - token.parent.pos + 2);
|
||||
}
|
||||
else {
|
||||
if (typeParameters[0] === token.parent) {
|
||||
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos + 1);
|
||||
}
|
||||
else {
|
||||
return createCodeFix("", token.parent.pos - 1, token.parent.end - token.parent.pos + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (token.parent.kind === ts.SyntaxKind.Parameter) {
|
||||
const functionDeclaration = <FunctionDeclaration>token.parent.parent;
|
||||
if (functionDeclaration.parameters.length === 1) {
|
||||
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos);
|
||||
}
|
||||
else {
|
||||
if (functionDeclaration.parameters[0] === token.parent) {
|
||||
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos + 1);
|
||||
}
|
||||
else {
|
||||
return createCodeFix("", token.parent.pos - 1, token.parent.end - token.parent.pos + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (token.parent.kind === SyntaxKind.ImportSpecifier) {
|
||||
const namedImports = <NamedImports>token.parent.parent;
|
||||
const elements = namedImports.elements;
|
||||
if (elements.length === 1) {
|
||||
// Only 1 import and it is unused. So the entire line could be removed.
|
||||
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos);
|
||||
}
|
||||
else {
|
||||
if (elements[0] === token.parent) {
|
||||
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos + 1);
|
||||
}
|
||||
else {
|
||||
return createCodeFix("", token.parent.pos - 1, token.parent.end - token.parent.pos + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (token.parent.parent.kind === SyntaxKind.ImportClause || token.parent.parent.kind === SyntaxKind.ImportDeclaration) {
|
||||
return createCodeFix("{}", token.parent.pos, token.parent.end - token.parent.pos);
|
||||
}
|
||||
|
||||
if (token.parent.kind === SyntaxKind.ImportEqualsDeclaration) {
|
||||
return createCodeFix("{}", token.pos, token.end - token.pos);
|
||||
}
|
||||
|
||||
if (token.parent.kind === SyntaxKind.EnumDeclaration) {
|
||||
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos);
|
||||
}
|
||||
}
|
||||
|
||||
if (token.kind === SyntaxKind.PrivateKeyword && token.parent.kind === SyntaxKind.PropertyDeclaration) {
|
||||
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos);
|
||||
}
|
||||
|
||||
if (token.kind === SyntaxKind.AsteriskToken && token.parent.kind === SyntaxKind.NamespaceImport) {
|
||||
return createCodeFix("{}", token.parent.pos, token.parent.end - token.parent.pos);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
|
||||
function createCodeFix(newText: string, start: number, length: number): CodeAction[] {
|
||||
return [{
|
||||
description: getLocaleSpecificMessage(Diagnostics.Remove_unused_identifiers),
|
||||
changes: [{
|
||||
fileName: sourceFile.fileName,
|
||||
textChanges: [{ newText, span: { start, length } }]
|
||||
}]
|
||||
}];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// [| namespace greeter {
|
||||
//// class class1 {
|
||||
//// }
|
||||
//// } |]
|
||||
|
||||
verify.codeFixAtPosition(`namespace greeter {
|
||||
}`);
|
||||
@@ -0,0 +1,15 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// [| namespace greeter {
|
||||
//// export class class2 {
|
||||
//// }
|
||||
//// class class1 {
|
||||
//// }
|
||||
//// } |]
|
||||
|
||||
verify.codeFixAtPosition(`namespace greeter {
|
||||
export class class2 {
|
||||
}
|
||||
}`);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters:true
|
||||
//// [| namespace Validation {
|
||||
//// class c1 {
|
||||
////
|
||||
//// }/*1*/
|
||||
//// } |]
|
||||
|
||||
verify.codeFixAtPosition(`namespace Validation {
|
||||
}`);
|
||||
@@ -0,0 +1,19 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters:true
|
||||
|
||||
//// [| namespace Validation {
|
||||
//// class c1 {
|
||||
////
|
||||
//// }
|
||||
////
|
||||
//// export class c2 {
|
||||
////
|
||||
//// }
|
||||
//// } |]
|
||||
|
||||
verify.codeFixAtPosition(`namespace Validation {
|
||||
export class c2 {
|
||||
}
|
||||
}`);
|
||||
@@ -0,0 +1,26 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters:true
|
||||
|
||||
//// [| namespace Validation {
|
||||
//// class c1 {
|
||||
////
|
||||
//// }
|
||||
////
|
||||
//// export class c2 {
|
||||
////
|
||||
//// }
|
||||
////
|
||||
//// class c3 extends c1 {
|
||||
////
|
||||
//// }
|
||||
////} |]
|
||||
|
||||
verify.codeFixAtPosition(`namespace Validation {
|
||||
class c1 {
|
||||
}
|
||||
|
||||
export class c2 {
|
||||
}
|
||||
}`);
|
||||
@@ -0,0 +1,27 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters:true
|
||||
//// [| namespace Validation {
|
||||
//// class c1 {
|
||||
////
|
||||
//// }
|
||||
////
|
||||
//// export class c2 {
|
||||
////
|
||||
//// }
|
||||
////
|
||||
//// class c3 {
|
||||
//// public x: c1;
|
||||
//// }
|
||||
////} |]
|
||||
|
||||
verify.codeFixAtPosition(`namespace Validation {
|
||||
class c1 {
|
||||
|
||||
}
|
||||
|
||||
export class c2 {
|
||||
|
||||
}
|
||||
}`);
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// [| function f1 () {
|
||||
//// const x: string = "x";
|
||||
//// } |]
|
||||
|
||||
verify.codeFixAtPosition(`function f1 () {
|
||||
}`);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// [| function f1 () {
|
||||
//// enum Directions { Up, Down}
|
||||
//// } |]
|
||||
|
||||
verify.codeFixAtPosition(`function f1 () {
|
||||
}
|
||||
`);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// [| namespace greeter {
|
||||
//// function function1() {
|
||||
//// }/*1*/
|
||||
//// } |]
|
||||
|
||||
verify.codeFixAtPosition(`namespace greeter {
|
||||
}`);
|
||||
@@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// [| namespace greeter {
|
||||
//// export function function2() {
|
||||
//// }
|
||||
//// function function1() {
|
||||
//// }
|
||||
////} |]
|
||||
|
||||
verify.codeFixAtPosition(`namespace greeter {
|
||||
export function function2() {
|
||||
}
|
||||
}`);
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters:true
|
||||
|
||||
//// [| namespace Validation {
|
||||
//// function function1() {
|
||||
//// }
|
||||
////} |]
|
||||
|
||||
verify.codeFixAtPosition(`namespace Validation {
|
||||
}`);
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters:true
|
||||
//// [| namespace Validation {
|
||||
//// var function1 = function() {
|
||||
//// }
|
||||
////} |]
|
||||
|
||||
verify.codeFixAtPosition(`namespace Validation {
|
||||
}`);
|
||||
@@ -0,0 +1,28 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters:true
|
||||
////namespace Validation {
|
||||
//// var function1 = function() {
|
||||
//// }
|
||||
////
|
||||
//// export function function2() {
|
||||
////
|
||||
//// }
|
||||
////
|
||||
//// [| function function3() {
|
||||
//// function1();
|
||||
//// }
|
||||
////
|
||||
//// function function4() {
|
||||
////
|
||||
//// }
|
||||
////
|
||||
//// exp ort let a = function3; |]
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition(`function function3() {
|
||||
function1();
|
||||
}
|
||||
|
||||
export let a = function3;`, 6133);
|
||||
@@ -0,0 +1,16 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// module A {
|
||||
//// export class Calculator {
|
||||
//// public handelChar() {
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
|
||||
//// module B {
|
||||
//// [|import a = A;|]
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition(" import {} = A;");
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @Filename: file2.ts
|
||||
//// [| import {/*0*/Calculator/*1*/} from "./file1" |]
|
||||
|
||||
// @Filename: file1.ts
|
||||
//// export class Calculator {
|
||||
////
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition(`import {} from "./file1"`);
|
||||
@@ -0,0 +1,20 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @Filename: file2.ts
|
||||
//// [| import {Calculator} from "./file1"
|
||||
//// import {test} from "./file1" |]
|
||||
|
||||
//// var x = new Calculator();
|
||||
//// x.handleChar();
|
||||
|
||||
// @Filename: file1.ts
|
||||
//// export class Calculator {
|
||||
//// handleChar() {}
|
||||
//// }
|
||||
//// export function test() {
|
||||
////
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition(`import {Calculator} from "./file1"
|
||||
import {} from "./file1"`);
|
||||
@@ -0,0 +1,24 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @Filename: file2.ts
|
||||
////[| import {/*0*/Calculator,/*1*/ test, test2} from "./file1" |]
|
||||
|
||||
//// test();
|
||||
//// test2();
|
||||
|
||||
// @Filename: file1.ts
|
||||
//// export class Calculator {
|
||||
//// handleChar() {}
|
||||
//// }
|
||||
|
||||
//// export function test() {
|
||||
////
|
||||
//// }
|
||||
|
||||
//// export function test2() {
|
||||
////
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition(`import {test, test2} from "./file1"`);
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @Filename: file2.ts
|
||||
//// [| import {Calculator/*0*/, test/*1*/, test2} from "./file1" |]
|
||||
////
|
||||
//// var x = new Calculator();
|
||||
//// x.handleChar();
|
||||
//// test2();
|
||||
|
||||
// @Filename: file1.ts
|
||||
//// export class Calculator {
|
||||
//// handleChar() {}
|
||||
//// }
|
||||
////
|
||||
//// export function test() {
|
||||
////
|
||||
//// }
|
||||
////
|
||||
//// export function test2() {
|
||||
////
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition(`import {Calculator, test2} from "./file1"`);
|
||||
@@ -0,0 +1,24 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @Filename: file2.ts
|
||||
//// [| import {Calculator, test, test2} from "./file1" |]
|
||||
////
|
||||
//// var x = new Calculator();
|
||||
//// x.handleChar();
|
||||
//// test();
|
||||
|
||||
// @Filename: file1.ts
|
||||
//// export class Calculator {
|
||||
//// handleChar() {}
|
||||
//// }
|
||||
////
|
||||
//// export function test() {
|
||||
////
|
||||
//// }
|
||||
////
|
||||
//// export function test2() {
|
||||
////
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition(`import {Calculator, test} from "./file1"`);
|
||||
@@ -0,0 +1,20 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @Filename: file2.ts
|
||||
//// [| import d from "./file1" |]
|
||||
|
||||
// @Filename: file1.ts
|
||||
//// export class Calculator {
|
||||
//// handleChar() { }
|
||||
//// }
|
||||
|
||||
//// export function test() {
|
||||
////
|
||||
//// }
|
||||
|
||||
//// export default function test2() {
|
||||
////
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition(`import {} from "./file1"`);
|
||||
@@ -0,0 +1,20 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @Filename: file2.ts
|
||||
//// [| import * as n from "./file1" |]
|
||||
|
||||
// @Filename: file1.ts
|
||||
//// export class Calculator {
|
||||
//// handleChar() { }
|
||||
//// }
|
||||
////
|
||||
//// export function test() {
|
||||
////
|
||||
//// }
|
||||
////
|
||||
//// export default function test2() {
|
||||
////
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition(`import {} from "./file1"`);
|
||||
@@ -0,0 +1,24 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @Filename: file2.ts
|
||||
//// [|import {Calculator as calc, test as t1, test2 as t2} from "./file1"|]
|
||||
////
|
||||
//// var x = new calc();
|
||||
//// x.handleChar();
|
||||
//// t1();
|
||||
|
||||
// @Filename: file1.ts
|
||||
//// export class Calculator {
|
||||
//// handleChar() { }
|
||||
//// }
|
||||
|
||||
//// export function test() {
|
||||
////
|
||||
//// }
|
||||
|
||||
//// export function test2() {
|
||||
////
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition(`import {Calculator as calc, test as t1} from "./file1"`);
|
||||
@@ -0,0 +1,20 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @Filename: file2.ts
|
||||
//// [|import c = require('./file1')|]
|
||||
|
||||
// @Filename: file1.ts
|
||||
//// export class Calculator {
|
||||
//// handleChar() { }
|
||||
//// }
|
||||
////
|
||||
//// export function test() {
|
||||
////
|
||||
//// }
|
||||
////
|
||||
//// export function test2() {
|
||||
////
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition("import {} = require('./file1')");
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// [| namespace greeter {
|
||||
//// interface interface1 {
|
||||
//// }
|
||||
////} |]
|
||||
|
||||
verify.codeFixAtPosition(`
|
||||
namespace greeter {
|
||||
}`);
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////namespace greeter {
|
||||
//// [| export interface interface2 {
|
||||
//// }
|
||||
//// interface interface1 {
|
||||
//// } |]
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition(`export interface interface2 {
|
||||
}`);
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// [| function greeter() {
|
||||
//// var x = 0;
|
||||
////} |]
|
||||
|
||||
verify.codeFixAtPosition(`
|
||||
function greeter() {
|
||||
}`);
|
||||
@@ -0,0 +1,9 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////function greeter() {
|
||||
//// [| var x, y = 0; |]
|
||||
//// x++;
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition("var x;", 6133);
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////function greeter() {
|
||||
//// [| var x, y = 0,z = 1; |]
|
||||
//// x++;
|
||||
//// z++;
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition("var x,z = 1;", 6133);
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////function greeter() {
|
||||
//// [| var x,y = 0,z = 1; |]
|
||||
//// y++;
|
||||
//// z++;
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition("var y = 0,z = 1;");
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters: true
|
||||
////class greeter {
|
||||
//// public function1() {
|
||||
//// [| var /*0*/x,/*1*/ y = 10; |]
|
||||
//// y++;
|
||||
//// }
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition("var y = 10;");
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters: true
|
||||
////class greeter {
|
||||
//// public function1() {
|
||||
//// [| var x, y; |]
|
||||
//// y = 1;
|
||||
//// }
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition("var y;");
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters:true
|
||||
////class greeter {
|
||||
//// [| constructor() {
|
||||
//// var unused = 20;
|
||||
//// } |]
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition(`constructor() {
|
||||
}`);
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters: true
|
||||
////class greeter {
|
||||
//// [|constructor() {
|
||||
//// var unused = 20;
|
||||
//// var used = "dummy";
|
||||
//// used = used + "second part";
|
||||
//// }|]
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition(`
|
||||
constructor() {
|
||||
var used = "dummy";
|
||||
used = used + "second part";
|
||||
}
|
||||
`);
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////[| class greeter {
|
||||
//// private function1() {
|
||||
//// }
|
||||
////} |]
|
||||
|
||||
verify.codeFixAtPosition(`
|
||||
class greeter {
|
||||
}`);
|
||||
@@ -0,0 +1,15 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// [| class greeter {
|
||||
//// public function2() {
|
||||
//// }
|
||||
//// private function1() {
|
||||
//// }
|
||||
////} |]
|
||||
|
||||
verify.codeFixAtPosition(`
|
||||
class greeter {
|
||||
public function2() {
|
||||
}
|
||||
}`);
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////[|class greeter {
|
||||
//// private function1 = function() {
|
||||
//// }
|
||||
////} |]
|
||||
|
||||
verify.codeFixAtPosition(`
|
||||
class greeter {
|
||||
}`);
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////class greeter {
|
||||
//// [|public function2(){
|
||||
//// }
|
||||
//// private function1 = function() {
|
||||
//// } |]
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition(`public function2(){
|
||||
}`);
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// [|namespace A {
|
||||
//// namespace B {
|
||||
//// }
|
||||
//// }|]
|
||||
|
||||
verify.codeFixAtPosition(`
|
||||
namespace A {
|
||||
}
|
||||
`);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// class C1 {
|
||||
//// [|constructor(private p1: string, public p2: boolean, public p3: any, p5)|] { p5; }
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition("constructor(public p2: boolean, public p3: any, p5)");
|
||||
@@ -0,0 +1,7 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedParameters: true
|
||||
////function [|greeter( x)|] {
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition("greeter()");
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedParameters: true
|
||||
////function [|greeter(x,y)|] {
|
||||
//// x++;
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition("greeter(x)");
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedParameters: true
|
||||
////function [|greeter(x,y)|] {
|
||||
//// y++;
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition("greeter(y)");
|
||||
@@ -0,0 +1,9 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedParameters: true
|
||||
////[|function greeter(x,y,z) |] {
|
||||
//// x++;
|
||||
//// z++;
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition("function greeter(x,z)");
|
||||
@@ -0,0 +1,9 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters: true
|
||||
//// function f1() {
|
||||
//// [|return (x:number) => {}|]
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition("return () => {}");
|
||||
@@ -0,0 +1,7 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////[|class greeter<T> |] {
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition("class greeter");
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////[|class greeter<X, Y> |] {
|
||||
//// public a: X;
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition("class greeter<X>");
|
||||
@@ -0,0 +1,9 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////[|class greeter<X, Y, Z> |] {
|
||||
//// public a: X;
|
||||
//// public b: Z;
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition("class greeter<X, Z>");
|
||||
@@ -0,0 +1,6 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// [|function f1<T>() {}|]
|
||||
|
||||
verify.codeFixAtPosition("function f1() {}");
|
||||
@@ -0,0 +1,6 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// [|function f1<X, Y>(a: X) {a}|]
|
||||
|
||||
verify.codeFixAtPosition("function f1<X>(a: X) {a}");
|
||||
@@ -0,0 +1,6 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// [|function f1<X, Y, Z>(a: X) {a;var b:Z;b}|]
|
||||
|
||||
verify.codeFixAtPosition("function f1<X, Z>(a: X) {a;var b:Z;b}");
|
||||
@@ -0,0 +1,7 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters: true
|
||||
//// [|interface I<T> {}|]
|
||||
|
||||
verify.codeFixAtPosition("interface I {}");
|
||||
@@ -0,0 +1,9 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters: true
|
||||
//// function f1() {
|
||||
//// [|return <T>(x:number) => {x}|]
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition("return (x:number) => {x}");
|
||||
@@ -0,0 +1,9 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters: true
|
||||
//// var x : {
|
||||
//// [|new <T, U>(a: T): void;|]
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition("new <T>(a: T): void;");
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters: true
|
||||
//// class A<Dummy> { public x: Dummy }
|
||||
//// var x : {
|
||||
//// [|new <T, U, K>(a: T): A<U>;|]
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition("new <T, U>(a: T): A<U>;");
|
||||
@@ -0,0 +1,9 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// class A<T> {
|
||||
//// public x: T;
|
||||
//// }
|
||||
//// [|var y: new <T,U>(a:T)=>void;|]
|
||||
|
||||
verify.codeFixAtPosition("var y: new <T>(a:T)=>void;");
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// class C1 {
|
||||
//// [|f1<T extends number>()|] {}
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition("f1()");
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// class C1 {
|
||||
//// [|f1<T extends number, U>(a: U)|] {a;}
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition("f1<U>(a: U)");
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// class A {
|
||||
//// [|public f1<X, Y, Z>(a: X)|] { a; var b: Z; b }
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition("public f1<X, Z>(a: X)");
|
||||
@@ -0,0 +1,15 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// function f1 () {
|
||||
//// [|let x = 10;
|
||||
//// {
|
||||
//// let x = 11;
|
||||
//// }
|
||||
//// x;|]
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition(`let x = 10;
|
||||
{
|
||||
}
|
||||
x;`);
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////class greeter {
|
||||
//// [|private greeting: string;|]
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition("");
|
||||
@@ -0,0 +1,9 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////class greeter {
|
||||
//// [|public greeting1;
|
||||
//// private greeting: string;|]
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition("public greeting1;");
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////class greeter {[|
|
||||
//// private X = function() {};
|
||||
////|]}
|
||||
|
||||
verify.codeFixAtPosition("");
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// function f1 () {
|
||||
//// [|for(var i = 0; ;) |]{
|
||||
////
|
||||
//// }
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition("for(; ;)");
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// function f1 () {
|
||||
//// [|for(var i = 0, j= 0; ;i++)|] {
|
||||
////
|
||||
//// }
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition("for(var i = 0; ;i++)");
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// function f1 () {
|
||||
//// [|for(var i = 0, j= 0, k=0; ;i++, k++)|] {
|
||||
////
|
||||
//// }
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition("for(var i = 0, k=0; ;i++,k++)");
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// function f1 () {
|
||||
//// [|for(var i = 0, j= 0, k=0; ;j++, k++) |]{
|
||||
////
|
||||
//// }
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition("for(var j = 0, k=0; ;j++,k++)");
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// function f1 () {
|
||||
//// for ([|const elem in|] ["a", "b", "c"]) {
|
||||
////
|
||||
//// }
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition("const {} in ");
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// function f1 () {
|
||||
//// for ([|const elem of|] ["a", "b", "c"]) {
|
||||
////
|
||||
//// }
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition("const {} of ");
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// function f1 () {
|
||||
//// for (const elem of ["a", "b", "c"]) {
|
||||
//// elem;
|
||||
//// [|var x = 20;|]
|
||||
//// }
|
||||
////}
|
||||
////
|
||||
|
||||
verify.codeFixAtPosition("");
|
||||
@@ -0,0 +1,9 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters: true
|
||||
//// export {}
|
||||
//// [|var x: string;|]
|
||||
//// export var y: string;
|
||||
|
||||
verify.codeFixAtPosition("");
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters: true
|
||||
//// export {}
|
||||
//// [|var x: string, y: number;|]
|
||||
//// y;
|
||||
//// export var y: string;
|
||||
|
||||
verify.codeFixAtPosition("var y: number;", 6133);
|
||||
@@ -0,0 +1,9 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters: true
|
||||
//// export {}
|
||||
//// [|var x = function f1() {}|]
|
||||
//// export var y: string;
|
||||
|
||||
verify.codeFixAtPosition("");
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters: true
|
||||
//// export {}
|
||||
//// [|var x = function f1(m: number) {}|]
|
||||
//// x;
|
||||
//// export var y: string;
|
||||
|
||||
verify.codeFixAtPosition(`var x = function f1() {}`);
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////namespace greeter {
|
||||
//// [|let a = "dummy entry";|]
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition("");
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////namespace greeter {
|
||||
//// [|let a = "dummy entry", b, c = 0;|]
|
||||
//// export function function1() {
|
||||
//// a = "dummy";
|
||||
//// c++;
|
||||
//// }
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition(`let a = "dummy entry", c = 0;`);
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////namespace greeter {
|
||||
//// [|let a = "dummy entry", b, c = 0;|]
|
||||
//// export function function1() {
|
||||
//// a = "dummy";
|
||||
//// b = 0;
|
||||
//// }
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition(`let a = "dummy entry", b;`);
|
||||
Reference in New Issue
Block a user