mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-20 19:45:07 -06:00
fix(36416): empty import path causes server crash (#36751)
This commit is contained in:
parent
bf370659b3
commit
e435054b3b
@ -1238,9 +1238,10 @@ namespace ts.textChanges {
|
||||
}
|
||||
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
const isFirstImport = sourceFile.imports.length && node === first(sourceFile.imports).parent || node === find(sourceFile.statements, isImportDeclaration);
|
||||
deleteNode(changes, sourceFile, node,
|
||||
// For first import, leave header comment in place
|
||||
node === sourceFile.imports[0].parent ? { leadingTriviaOption: LeadingTriviaOption.Exclude } : undefined);
|
||||
isFirstImport ? { leadingTriviaOption: LeadingTriviaOption.Exclude } : undefined);
|
||||
break;
|
||||
|
||||
case SyntaxKind.BindingElement:
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: /a.ts
|
||||
////// leading trivia
|
||||
////import * as foo from ""; // trailing trivia
|
||||
|
||||
verify.codeFix({
|
||||
description: "Remove import from ''",
|
||||
newFileContent:
|
||||
`// leading trivia
|
||||
// trailing trivia`,
|
||||
});
|
||||
@ -0,0 +1,22 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: /a.ts
|
||||
////// leading trivia
|
||||
////import * as foo from "";
|
||||
////import { b } from "./b";
|
||||
////import { c } from "./c";
|
||||
|
||||
// @Filename: /b.ts
|
||||
////export const b = null;
|
||||
|
||||
// @Filename: /c.ts
|
||||
////export const c = null;
|
||||
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
description: "Remove import from ''",
|
||||
newFileContent:
|
||||
`// leading trivia
|
||||
import { b } from "./b";
|
||||
import { c } from "./c";`,
|
||||
});
|
||||
@ -0,0 +1,22 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: /a.ts
|
||||
////// leading trivia
|
||||
////import { b } from "./b";
|
||||
////import * as foo from "";
|
||||
////import { c } from "./c";
|
||||
|
||||
// @Filename: /b.ts
|
||||
////export const b = null;
|
||||
|
||||
// @Filename: /c.ts
|
||||
////export const c = null;
|
||||
|
||||
verify.codeFix({
|
||||
index: 1,
|
||||
description: "Remove import from ''",
|
||||
newFileContent:
|
||||
`// leading trivia
|
||||
import { b } from "./b";
|
||||
import { c } from "./c";`,
|
||||
});
|
||||
@ -0,0 +1,23 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: /a.ts
|
||||
////// leading trivia
|
||||
////import { b } from "./b";
|
||||
////import { c } from "./c";
|
||||
////import * as foo from "";
|
||||
|
||||
// @Filename: /b.ts
|
||||
////export const b = null;
|
||||
|
||||
// @Filename: /c.ts
|
||||
////export const c = null;
|
||||
|
||||
verify.codeFix({
|
||||
index: 2,
|
||||
description: "Remove import from ''",
|
||||
newFileContent:
|
||||
`// leading trivia
|
||||
import { b } from "./b";
|
||||
import { c } from "./c";
|
||||
`,
|
||||
});
|
||||
@ -0,0 +1,35 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: /a.ts
|
||||
////// leading trivia
|
||||
////import * as a from "";
|
||||
////import * as b from "";
|
||||
////import * as c from "";
|
||||
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
description: "Remove import from ''",
|
||||
newFileContent:
|
||||
`// leading trivia
|
||||
import * as b from "";
|
||||
import * as c from "";`,
|
||||
});
|
||||
|
||||
verify.codeFix({
|
||||
index: 1,
|
||||
description: "Remove import from ''",
|
||||
newFileContent:
|
||||
`// leading trivia
|
||||
import * as a from "";
|
||||
import * as c from "";`,
|
||||
});
|
||||
|
||||
verify.codeFix({
|
||||
index: 2,
|
||||
description: "Remove import from ''",
|
||||
newFileContent:
|
||||
`// leading trivia
|
||||
import * as a from "";
|
||||
import * as b from "";
|
||||
`
|
||||
});
|
||||
@ -0,0 +1,44 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: /main.ts
|
||||
////// leading trivia
|
||||
////import { a } from "./a";
|
||||
////import { b } from "./b";
|
||||
////import { c } from "./c";
|
||||
|
||||
// @Filename: /a.ts
|
||||
////export const a = null;
|
||||
|
||||
// @Filename: /b.ts
|
||||
////export const b = null;
|
||||
|
||||
// @Filename: /c.ts
|
||||
////export const c = null;
|
||||
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
description: "Remove import from './a'",
|
||||
newFileContent:
|
||||
`// leading trivia
|
||||
import { b } from "./b";
|
||||
import { c } from "./c";`,
|
||||
});
|
||||
|
||||
verify.codeFix({
|
||||
index: 1,
|
||||
description: "Remove import from './b'",
|
||||
newFileContent:
|
||||
`// leading trivia
|
||||
import { a } from "./a";
|
||||
import { c } from "./c";`,
|
||||
});
|
||||
|
||||
verify.codeFix({
|
||||
index: 2,
|
||||
description: "Remove import from './c'",
|
||||
newFileContent:
|
||||
`// leading trivia
|
||||
import { a } from "./a";
|
||||
import { b } from "./b";
|
||||
`,
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user