mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #11546 from Microsoft/unusedidentifier
Codefix for removing Unused Identifiers
This commit is contained in:
@@ -2013,13 +2013,13 @@ 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.");
|
||||
}
|
||||
|
||||
const diagnostic = !errorCode ? diagnostics[0] : ts.find(diagnostics, d => d.code == errorCode);
|
||||
|
||||
return this.languageService.getCodeFixesAtPosition(fileName, diagnostic.start, diagnostic.length, [diagnostic.code]);
|
||||
return this.languageService.getCodeFixesAtPosition(fileName, diagnostic.start, diagnostic.start + diagnostic.length, [diagnostic.code]);
|
||||
}
|
||||
|
||||
public verifyCodeFixAtPosition(expectedText: string, errorCode?: number) {
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
///<reference path='superFixes.ts' />
|
||||
///<reference path='unusedIdentifierFixes.ts' />
|
||||
@@ -0,0 +1,167 @@
|
||||
/* @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;
|
||||
|
||||
let token = getTokenAtPosition(sourceFile, start);
|
||||
|
||||
// this handles var ["computed"] = 12;
|
||||
if (token.kind === SyntaxKind.OpenBracketToken) {
|
||||
token = getTokenAtPosition(sourceFile, start + 1);
|
||||
}
|
||||
|
||||
switch (token.kind) {
|
||||
case ts.SyntaxKind.Identifier:
|
||||
switch (token.parent.kind) {
|
||||
case ts.SyntaxKind.VariableDeclaration:
|
||||
switch (token.parent.parent.parent.kind) {
|
||||
case SyntaxKind.ForStatement:
|
||||
const forStatement = <ForStatement>token.parent.parent.parent;
|
||||
const forInitializer = <VariableDeclarationList>forStatement.initializer;
|
||||
if (forInitializer.declarations.length === 1) {
|
||||
return createCodeFix("", forInitializer.pos, forInitializer.end - forInitializer.pos);
|
||||
}
|
||||
else {
|
||||
return removeSingleItem(forInitializer.declarations, token);
|
||||
}
|
||||
|
||||
case SyntaxKind.ForOfStatement:
|
||||
const forOfStatement = <ForOfStatement>token.parent.parent.parent;
|
||||
if (forOfStatement.initializer.kind === SyntaxKind.VariableDeclarationList) {
|
||||
const forOfInitializer = <VariableDeclarationList>forOfStatement.initializer;
|
||||
return createCodeFix("{}", forOfInitializer.declarations[0].pos, forOfInitializer.declarations[0].end - forOfInitializer.declarations[0].pos);
|
||||
}
|
||||
break;
|
||||
|
||||
case SyntaxKind.ForInStatement:
|
||||
// There is no valid fix in the case of:
|
||||
// for .. in
|
||||
return undefined;
|
||||
|
||||
case SyntaxKind.CatchClause:
|
||||
const catchClause = <CatchClause>token.parent.parent;
|
||||
const parameter = catchClause.variableDeclaration.getChildren()[0];
|
||||
return createCodeFix("", parameter.pos, parameter.end - parameter.pos);
|
||||
|
||||
default:
|
||||
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;
|
||||
return removeSingleItem(declarations, token);
|
||||
}
|
||||
}
|
||||
|
||||
case SyntaxKind.TypeParameter:
|
||||
const typeParameters = (<DeclarationWithTypeParameters>token.parent.parent).typeParameters;
|
||||
if (typeParameters.length === 1) {
|
||||
return createCodeFix("", token.parent.pos - 1, token.parent.end - token.parent.pos + 2);
|
||||
}
|
||||
else {
|
||||
return removeSingleItem(typeParameters, token);
|
||||
}
|
||||
|
||||
case 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 {
|
||||
return removeSingleItem(functionDeclaration.parameters, token);
|
||||
}
|
||||
|
||||
// handle case where 'import a = A;'
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
const importEquals = findImportDeclaration(token);
|
||||
return createCodeFix("", importEquals.pos, importEquals.end - importEquals.pos);
|
||||
|
||||
case SyntaxKind.ImportSpecifier:
|
||||
const namedImports = <NamedImports>token.parent.parent;
|
||||
if (namedImports.elements.length === 1) {
|
||||
// Only 1 import and it is unused. So the entire declaration should be removed.
|
||||
const importSpec = findImportDeclaration(token);
|
||||
return createCodeFix("", importSpec.pos, importSpec.end - importSpec.pos);
|
||||
}
|
||||
else {
|
||||
return removeSingleItem(namedImports.elements, token);
|
||||
}
|
||||
|
||||
// handle case where "import d, * as ns from './file'"
|
||||
// or "'import {a, b as ns} from './file'"
|
||||
case SyntaxKind.ImportClause: // this covers both 'import |d|' and 'import |d,| *'
|
||||
const importClause = <ImportClause>token.parent;
|
||||
if (!importClause.namedBindings) { // |import d from './file'| or |import * as ns from './file'|
|
||||
const importDecl = findImportDeclaration(importClause);
|
||||
return createCodeFix("", importDecl.pos, importDecl.end - importDecl.pos);
|
||||
}
|
||||
else { // import |d,| * as ns from './file'
|
||||
return createCodeFix("", importClause.name.pos, importClause.namedBindings.pos - importClause.name.pos);
|
||||
}
|
||||
|
||||
case SyntaxKind.NamespaceImport:
|
||||
const namespaceImport = <NamespaceImport>token.parent;
|
||||
if (namespaceImport.name == token && !(<ImportClause>namespaceImport.parent).name) {
|
||||
const importDecl = findImportDeclaration(namespaceImport);
|
||||
return createCodeFix("", importDecl.pos, importDecl.end - importDecl.pos);
|
||||
}
|
||||
else {
|
||||
const start = (<ImportClause>namespaceImport.parent).name.end;
|
||||
return createCodeFix("", start, (<ImportClause>namespaceImport.parent).namedBindings.end - start);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos);
|
||||
|
||||
case SyntaxKind.NamespaceImport:
|
||||
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos);
|
||||
}
|
||||
if (isDeclarationName(token)) {
|
||||
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos);
|
||||
}
|
||||
else if (isLiteralComputedPropertyDeclarationName(token)) {
|
||||
return createCodeFix("", token.parent.parent.pos, token.parent.parent.end - token.parent.parent.pos);
|
||||
}
|
||||
else {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function findImportDeclaration(token: Node): Node {
|
||||
let importDecl = token;
|
||||
while (importDecl.kind != SyntaxKind.ImportDeclaration && importDecl.parent) {
|
||||
importDecl = importDecl.parent;
|
||||
}
|
||||
|
||||
return importDecl;
|
||||
}
|
||||
|
||||
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 } }]
|
||||
}]
|
||||
}];
|
||||
}
|
||||
|
||||
function removeSingleItem<T extends Node>(elements: NodeArray<T>, token: T): CodeAction[] {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
{
|
||||
"compilerOptions": {
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
|
||||
@@ -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,25 @@
|
||||
/// <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,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// [| namespace greeter {
|
||||
//// enum enum1 {
|
||||
//// Monday
|
||||
//// }
|
||||
//// } |]
|
||||
|
||||
verify.codeFixAtPosition(`namespace greeter {
|
||||
}`);
|
||||
@@ -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() {
|
||||
////
|
||||
//// }
|
||||
////
|
||||
//// export let a = function3; |]
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition(`function function3() {
|
||||
function1();
|
||||
}
|
||||
|
||||
export let a = function3;`);
|
||||
@@ -0,0 +1,16 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// module A {
|
||||
//// export class Calculator {
|
||||
//// public handelChar() {
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
|
||||
//// module B {
|
||||
//// [|import a = A;|]
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition("");
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @Filename: file2.ts
|
||||
//// [| import f1, * as s from "./file1"; |]
|
||||
//// s.f2('hello');
|
||||
|
||||
// @Filename: file1.ts
|
||||
//// export var v1;
|
||||
//// export function f1(n: number){}
|
||||
//// export function f2(s: string){};
|
||||
//// export default f1;
|
||||
|
||||
verify.codeFixAtPosition('import * as s from "./file1";');
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @Filename: file2.ts
|
||||
//// [| import f1, * as s from "./file1"; |]
|
||||
//// f1(42);
|
||||
|
||||
// @Filename: file1.ts
|
||||
//// export function f1(n: number){}
|
||||
//// export function f2(s: string){};
|
||||
//// export default f1;
|
||||
|
||||
verify.codeFixAtPosition('import f1 from "./file1";');
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @Filename: file2.ts
|
||||
//// [|import { Calculator } from "./file1" |]
|
||||
|
||||
// @Filename: file1.ts
|
||||
//// export class Calculator {
|
||||
////
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition('');
|
||||
@@ -0,0 +1,19 @@
|
||||
/// <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"`);
|
||||
@@ -0,0 +1,24 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @Filename: file2.ts
|
||||
////[| import {Calculator, 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, test, 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('');
|
||||
@@ -0,0 +1,16 @@
|
||||
/// <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('');
|
||||
@@ -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("");
|
||||
@@ -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+1;
|
||||
////}
|
||||
|
||||
verify.codeFixAtPosition("var x;");
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////function greeter() {
|
||||
//// [| var x, y = 0,z = 1; |]
|
||||
//// x+1;
|
||||
//// z+1;
|
||||
////}
|
||||
|
||||
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,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// [|class C {
|
||||
//// private ["string"] (){}
|
||||
//// }|]
|
||||
|
||||
verify.codeFixAtPosition("class C { }");
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// [|class C {
|
||||
//// private "string" (){}
|
||||
//// }|]
|
||||
|
||||
verify.codeFixAtPosition("class C { }");
|
||||
@@ -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,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// class C1 {
|
||||
//// [|constructor(public p1: string, private p2: boolean, public p3: any, p5)|] { p5; }
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition("constructor(public p1: string, public p3: any, p5)");
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// class C1 {
|
||||
//// [|constructor(public p1: string, public p2: boolean, private p3: any, p5)|] { p5; }
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition("constructor(public p1: string, public p2: boolean, p5)");
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// class C1 {
|
||||
//// [|constructor(private readonly p2: boolean, p5)|] { p5; }
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition("constructor(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,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// [| namespace greeter {
|
||||
//// type hw = "Hello" |"world";
|
||||
//// export type nw = "No" | "Way";
|
||||
//// } |]
|
||||
|
||||
verify.codeFixAtPosition(`namespace greeter {
|
||||
export type nw = "No" | "Way";
|
||||
}`);
|
||||
@@ -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.not.codeFixAvailable();
|
||||
|
||||
@@ -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, z: number;|]
|
||||
//// z;
|
||||
//// export var y: string;
|
||||
|
||||
verify.codeFixAtPosition("var z: number;");
|
||||
@@ -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