Simplifying handling import cases

This commit is contained in:
Paul van Brenk
2016-10-24 17:32:58 -07:00
parent 409787495e
commit d4b99d66e0
9 changed files with 44 additions and 20 deletions

View File

@@ -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;

View 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";');

View 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";');

View File

@@ -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('');

View File

@@ -16,5 +16,4 @@
////
//// }
verify.codeFixAtPosition(`import {Calculator} from "./file1"
import {} from "./file1"`);
verify.codeFixAtPosition(`import {Calculator} from "./file1"`);

View File

@@ -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();

View File

@@ -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();

View File

@@ -17,4 +17,4 @@
////
//// }
verify.codeFixAtPosition(`import {} from "./file1"`);
verify.codeFixAtPosition('');

View File

@@ -8,13 +8,9 @@
//// export class Calculator {
//// handleChar() { }
//// }
////
//// export function test() {
////
//// }
////
//// export default function test2() {
////
//// }
verify.codeFixAtPosition(`import {} from "./file1"`);
verify.codeFixAtPosition('');