Skip to content

Commit

Permalink
Fixed an issue with global React namespace being preferred over confi…
Browse files Browse the repository at this point in the history
…g & pragma implicit ones
  • Loading branch information
Andarist committed Nov 13, 2020
1 parent f46544d commit 0870655
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 90 deletions.
8 changes: 5 additions & 3 deletions src/compiler/checker.ts
Expand Up @@ -25183,11 +25183,13 @@ namespace ts {
return links.jsxNamespace;
}
if (!links || links.jsxNamespace !== false) {
const namespaceName = getJsxNamespace(location);
let resolvedNamespace = resolveName(location, namespaceName, SymbolFlags.Namespace, /*diagnosticMessage*/ undefined, namespaceName, /*isUse*/ false);
let resolvedNamespace = getJsxNamespaceContainerForImplicitImport(location);

if (!resolvedNamespace || resolvedNamespace === unknownSymbol) {
resolvedNamespace = getJsxNamespaceContainerForImplicitImport(location);
const namespaceName = getJsxNamespace(location);
resolvedNamespace = resolveName(location, namespaceName, SymbolFlags.Namespace, /*diagnosticMessage*/ undefined, namespaceName, /*isUse*/ false);
}

if (resolvedNamespace) {
const candidate = resolveSymbol(getSymbol(getExportsOfSymbol(resolveSymbol(resolvedNamespace)), JsxNames.JSX, SymbolFlags.Namespace));
if (candidate && candidate !== unknownSymbol) {
Expand Down

This file was deleted.

Expand Up @@ -178,7 +178,7 @@ export namespace EmotionJSX {
=== /index.tsx ===
export const Comp = () => <div css="color: hotpink;"></div>;
>Comp : Symbol(Comp, Decl(index.tsx, 0, 12))
>div : Symbol(JSX.IntrinsicElements.div, Decl(index.d.ts, 14, 33))
>div : Symbol(div, Decl(index.d.ts, 14, 33))
>css : Symbol(css, Decl(index.tsx, 0, 30))
>div : Symbol(JSX.IntrinsicElements.div, Decl(index.d.ts, 14, 33))
>div : Symbol(div, Decl(index.d.ts, 14, 33))

Expand Up @@ -3,7 +3,7 @@ export = React;
>React : any

export as namespace React;
>React : any
>React : error

declare namespace React {}

Expand Down Expand Up @@ -103,9 +103,9 @@ export namespace EmotionJSX {

=== /index.tsx ===
export const Comp = () => <div css="color: hotpink;"></div>;
>Comp : () => JSX.Element
>() => <div css="color: hotpink;"></div> : () => JSX.Element
><div css="color: hotpink;"></div> : JSX.Element
>Comp : () => import("/node_modules/@emotion/react/jsx-runtime/jsx-namespace").EmotionJSX.Element
>() => <div css="color: hotpink;"></div> : () => import("/node_modules/@emotion/react/jsx-runtime/jsx-namespace").EmotionJSX.Element
><div css="color: hotpink;"></div> : import("/node_modules/@emotion/react/jsx-runtime/jsx-namespace").EmotionJSX.Element
>div : any
>css : string
>div : any
Expand Down
@@ -1,6 +1,4 @@
/index.tsx(2,28): error TS2708: Cannot use namespace 'React' as a value.
/index.tsx(2,32): error TS2322: Type '{ css: string; }' is not assignable to type '{}'.
Property 'css' does not exist on type '{}'.


==== /node_modules/react/index.d.ts (0 errors) ====
Expand Down Expand Up @@ -63,12 +61,9 @@
}
}

==== /index.tsx (2 errors) ====
==== /index.tsx (1 errors) ====
/* @jsxImportSource @emotion/react */
export const Comp = () => <div css="color: hotpink;"></div>;
~~~
!!! error TS2708: Cannot use namespace 'React' as a value.
~~~
!!! error TS2322: Type '{ css: string; }' is not assignable to type '{}'.
!!! error TS2322: Property 'css' does not exist on type '{}'.

Expand Up @@ -179,7 +179,7 @@ export namespace EmotionJSX {
/* @jsxImportSource @emotion/react */
export const Comp = () => <div css="color: hotpink;"></div>;
>Comp : Symbol(Comp, Decl(index.tsx, 1, 12))
>div : Symbol(JSX.IntrinsicElements.div, Decl(index.d.ts, 14, 37))
>div : Symbol(div, Decl(index.d.ts, 14, 37))
>css : Symbol(css, Decl(index.tsx, 1, 30))
>div : Symbol(JSX.IntrinsicElements.div, Decl(index.d.ts, 14, 37))
>div : Symbol(div, Decl(index.d.ts, 14, 37))

Expand Up @@ -104,9 +104,9 @@ export namespace EmotionJSX {
=== /index.tsx ===
/* @jsxImportSource @emotion/react */
export const Comp = () => <div css="color: hotpink;"></div>;
>Comp : () => JSX.Element
>() => <div css="color: hotpink;"></div> : () => JSX.Element
><div css="color: hotpink;"></div> : JSX.Element
>Comp : () => import("/node_modules/@emotion/react/jsx-runtime/jsx-namespace").EmotionJSX.Element
>() => <div css="color: hotpink;"></div> : () => import("/node_modules/@emotion/react/jsx-runtime/jsx-namespace").EmotionJSX.Element
><div css="color: hotpink;"></div> : import("/node_modules/@emotion/react/jsx-runtime/jsx-namespace").EmotionJSX.Element
>div : any
>css : string
>div : any
Expand Down

0 comments on commit 0870655

Please sign in to comment.