Merge pull request #29266 from Microsoft/jsxNamespace
Use the sourceFile to determine the jsxNamespace at the location for organizingImports
This commit is contained in:
commit
5135b83bf9
|
@ -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);
|
||||
|
|
|
@ -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[] = [];
|
||||
|
|
|
@ -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",
|
||||
|
|
15
tests/baselines/reference/organizeImports/JsxPragmaTsx.ts
Normal file
15
tests/baselines/reference/organizeImports/JsxPragmaTsx.ts
Normal 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>
|
Loading…
Reference in a new issue