mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-28 09:22:42 -05:00
Simplifying handling import cases
This commit is contained in:
@@ -92,18 +92,20 @@ namespace ts.codefix {
|
||||
}
|
||||
|
||||
// handle case where 'import a = A;'
|
||||
// remove entire line
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
const importDecl = token.parent;
|
||||
return createCodeFix("", importDecl.pos, importDecl.end - importDecl.pos);
|
||||
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos);
|
||||
|
||||
// handle case where 'import d from './file'
|
||||
case SyntaxKind.ImportClause:
|
||||
return createCodeFix("", token.parent.parent.pos, token.parent.parent.end - token.parent.parent.pos);
|
||||
|
||||
// handle case where 'import * as a from './file'
|
||||
case SyntaxKind.NamespaceImport:
|
||||
return createCodeFix("", token.parent.parent.parent.pos, token.parent.parent.parent.end - token.parent.parent.parent.pos);
|
||||
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos);
|
||||
}
|
||||
|
||||
if (token.parent.parent.kind === SyntaxKind.ImportClause || token.parent.parent.kind === SyntaxKind.ImportDeclaration) {
|
||||
return createCodeFix("{}", token.parent.pos, token.parent.end - token.parent.pos);
|
||||
}
|
||||
break;
|
||||
|
||||
case SyntaxKind.PrivateKeyword:
|
||||
@@ -112,7 +114,7 @@ namespace ts.codefix {
|
||||
|
||||
case SyntaxKind.AsteriskToken:
|
||||
case SyntaxKind.NamespaceImport:
|
||||
return createCodeFix("{}", token.parent.pos, token.parent.end - token.parent.pos);
|
||||
return createCodeFix("", token.parent.pos, token.parent.end - token.parent.pos);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
|
||||
14
tests/cases/fourslash/unusedImports11FS.ts
Normal file
14
tests/cases/fourslash/unusedImports11FS.ts
Normal file
@@ -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";');
|
||||
13
tests/cases/fourslash/unusedImports12FS.ts
Normal file
13
tests/cases/fourslash/unusedImports12FS.ts
Normal file
@@ -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 "./file1";');
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @Filename: file2.ts
|
||||
//// [| import {/*0*/Calculator/*1*/} from "./file1" |]
|
||||
//// [| import { Calculator } from "./file1" |]
|
||||
|
||||
// @Filename: file1.ts
|
||||
//// export class Calculator {
|
||||
////
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition(`import {} from "./file1"`);
|
||||
verify.codeFixAtPosition('');
|
||||
|
||||
@@ -16,5 +16,4 @@
|
||||
////
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition(`import {Calculator} from "./file1"
|
||||
import {} from "./file1"`);
|
||||
verify.codeFixAtPosition(`import {Calculator} from "./file1"`);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @Filename: file2.ts
|
||||
////[| import {/*0*/Calculator,/*1*/ test, test2} from "./file1" |]
|
||||
////[| import {Calculator, test, test2} from "./file1" |]
|
||||
|
||||
//// test();
|
||||
//// test2();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @Filename: file2.ts
|
||||
//// [| import {Calculator/*0*/, test/*1*/, test2} from "./file1" |]
|
||||
//// [| import {Calculator, test, test2} from "./file1" |]
|
||||
////
|
||||
//// var x = new Calculator();
|
||||
//// x.handleChar();
|
||||
|
||||
@@ -17,4 +17,4 @@
|
||||
////
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition(`import {} from "./file1"`);
|
||||
verify.codeFixAtPosition('');
|
||||
@@ -8,13 +8,9 @@
|
||||
//// export class Calculator {
|
||||
//// handleChar() { }
|
||||
//// }
|
||||
////
|
||||
//// export function test() {
|
||||
////
|
||||
//// }
|
||||
////
|
||||
//// export default function test2() {
|
||||
////
|
||||
//// }
|
||||
|
||||
verify.codeFixAtPosition(`import {} from "./file1"`);
|
||||
verify.codeFixAtPosition('');
|
||||
Reference in New Issue
Block a user