Merge pull request #29266 from Microsoft/jsxNamespace

Use the sourceFile to determine the jsxNamespace at the location for organizingImports
This commit is contained in:
Sheetal Nandi 2019-01-04 14:43:48 -08:00 committed by GitHub
commit 5135b83bf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 2 deletions

View file

@ -375,7 +375,7 @@ namespace ts.codefix {
const symbolName = isJsxOpeningLikeElement(symbolToken.parent)
&& symbolToken.parent.tagName === symbolToken
&& (isIntrinsicJsxName(symbolToken.text) || checker.resolveName(symbolToken.text, symbolToken, SymbolFlags.All, /*excludeGlobals*/ false))
? checker.getJsxNamespace()
? checker.getJsxNamespace(sourceFile)
: symbolToken.text;
// "default" is a keyword and not a legal identifier for the import, so we don't expect it here
Debug.assert(symbolName !== InternalSymbolName.Default);

View file

@ -83,7 +83,7 @@ namespace ts.OrganizeImports {
function removeUnusedImports(oldImports: ReadonlyArray<ImportDeclaration>, sourceFile: SourceFile, program: Program) {
const typeChecker = program.getTypeChecker();
const jsxNamespace = typeChecker.getJsxNamespace();
const jsxNamespace = typeChecker.getJsxNamespace(sourceFile);
const jsxElementsPresent = !!(sourceFile.transformFlags & TransformFlags.ContainsJsx);
const usedImports: ImportDeclaration[] = [];

View file

@ -596,6 +596,34 @@ import { React, Other } from "react";
},
reactLibFile);
testOrganizeImports("JsxPragmaTsx",
{
path: "/test.tsx",
content: `/** @jsx jsx */
import { Global, jsx } from '@emotion/core';
import * as React from 'react';
export const App: React.FunctionComponent = _ => <Global><h1>Hello!</h1></Global>
`,
},
{
path: "/@emotion/core/index.d.ts",
content: `import { createElement } from 'react'
export const jsx: typeof createElement;
export function Global(props: any): ReactElement<any>;`
},
{
path: reactLibFile.path,
content: `${reactLibFile.content}
export namespace React {
interface FunctionComponent {
}
}
`
}
);
describe("Exports", () => {
testOrganizeExports("MoveToTop",

View file

@ -0,0 +1,15 @@
// ==ORIGINAL==
/** @jsx jsx */
import { Global, jsx } from '@emotion/core';
import * as React from 'react';
export const App: React.FunctionComponent = _ => <Global><h1>Hello!</h1></Global>
// ==ORGANIZED==
/** @jsx jsx */
import { Global, jsx } from '@emotion/core';
import * as React from 'react';
export const App: React.FunctionComponent = _ => <Global><h1>Hello!</h1></Global>