Skip to content

Commit edd31a1

Browse files
committed
Preserver jsx imports even when the compiler option is not set
...based on feedback from VS Code users. Fixes microsoft#23287
1 parent d2f6f6a commit edd31a1

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

src/harness/unittests/organizeImports.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,26 @@ D();
513513
import { React, Other } from "react";
514514
515515
<div/>;
516+
`,
517+
},
518+
reactLibFile);
519+
520+
testOrganizeImports("JsxFactoryUnusedJsx",
521+
{
522+
path: "/test.jsx",
523+
content: `
524+
import { React, Other } from "react";
525+
`,
526+
},
527+
reactLibFile);
528+
529+
// Note: Since the file extension does not end with "x", the jsx compiler option
530+
// will not be enabled. The import should be retained regardless.
531+
testOrganizeImports("JsxFactoryUnusedJs",
532+
{
533+
path: "/test.js",
534+
content: `
535+
import { React, Other } from "react";
516536
`,
517537
},
518538
reactLibFile);

src/services/organizeImports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ namespace ts.OrganizeImports {
9292
function removeUnusedImports(oldImports: ReadonlyArray<ImportDeclaration>, sourceFile: SourceFile, program: Program) {
9393
const typeChecker = program.getTypeChecker();
9494
const jsxNamespace = typeChecker.getJsxNamespace();
95-
const jsxContext = sourceFile.languageVariant === LanguageVariant.JSX && program.getCompilerOptions().jsx;
95+
const jsxContext = sourceFile.languageVariant === LanguageVariant.JSX;
9696

9797
const usedImports: ImportDeclaration[] = [];
9898

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// ==ORIGINAL==
2+
3+
import { React, Other } from "react";
4+
5+
// ==ORGANIZED==
6+
7+
import { React } from "react";
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// ==ORIGINAL==
2+
3+
import { React, Other } from "react";
4+
5+
// ==ORGANIZED==
6+
7+
import { React } from "react";

0 commit comments

Comments
 (0)