Preserver jsx imports even when the compiler option is not set

...based on feedback from VS Code users.

Fixes #23287
This commit is contained in:
Andrew Casey
2018-05-21 16:57:18 -07:00
parent d2f6f6a0a4
commit edd31a1505
4 changed files with 35 additions and 1 deletions

View File

@@ -513,6 +513,26 @@ D();
import { React, Other } from "react";
<div/>;
`,
},
reactLibFile);
testOrganizeImports("JsxFactoryUnusedJsx",
{
path: "/test.jsx",
content: `
import { React, Other } from "react";
`,
},
reactLibFile);
// Note: Since the file extension does not end with "x", the jsx compiler option
// will not be enabled. The import should be retained regardless.
testOrganizeImports("JsxFactoryUnusedJs",
{
path: "/test.js",
content: `
import { React, Other } from "react";
`,
},
reactLibFile);

View File

@@ -92,7 +92,7 @@ namespace ts.OrganizeImports {
function removeUnusedImports(oldImports: ReadonlyArray<ImportDeclaration>, sourceFile: SourceFile, program: Program) {
const typeChecker = program.getTypeChecker();
const jsxNamespace = typeChecker.getJsxNamespace();
const jsxContext = sourceFile.languageVariant === LanguageVariant.JSX && program.getCompilerOptions().jsx;
const jsxContext = sourceFile.languageVariant === LanguageVariant.JSX;
const usedImports: ImportDeclaration[] = [];

View File

@@ -0,0 +1,7 @@
// ==ORIGINAL==
import { React, Other } from "react";
// ==ORGANIZED==
import { React } from "react";

View File

@@ -0,0 +1,7 @@
// ==ORIGINAL==
import { React, Other } from "react";
// ==ORGANIZED==
import { React } from "react";