Skip to content

Commit 0870655

Browse files
committed
Fixed an issue with global React namespace being preferred over config & pragma implicit ones
1 parent f46544d commit 0870655

7 files changed

+17
-90
lines changed

src/compiler/checker.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -25183,11 +25183,13 @@ namespace ts {
2518325183
return links.jsxNamespace;
2518425184
}
2518525185
if (!links || links.jsxNamespace !== false) {
25186-
const namespaceName = getJsxNamespace(location);
25187-
let resolvedNamespace = resolveName(location, namespaceName, SymbolFlags.Namespace, /*diagnosticMessage*/ undefined, namespaceName, /*isUse*/ false);
25186+
let resolvedNamespace = getJsxNamespaceContainerForImplicitImport(location);
25187+
2518825188
if (!resolvedNamespace || resolvedNamespace === unknownSymbol) {
25189-
resolvedNamespace = getJsxNamespaceContainerForImplicitImport(location);
25189+
const namespaceName = getJsxNamespace(location);
25190+
resolvedNamespace = resolveName(location, namespaceName, SymbolFlags.Namespace, /*diagnosticMessage*/ undefined, namespaceName, /*isUse*/ false);
2519025191
}
25192+
2519125193
if (resolvedNamespace) {
2519225194
const candidate = resolveSymbol(getSymbol(getExportsOfSymbol(resolveSymbol(resolvedNamespace)), JsxNames.JSX, SymbolFlags.Namespace));
2519325195
if (candidate && candidate !== unknownSymbol) {

tests/baselines/reference/jsxNamespaceImplicitImportJSXNamespaceFromConfigPickedOverGlobalOne.errors.txt

-70
This file was deleted.

tests/baselines/reference/jsxNamespaceImplicitImportJSXNamespaceFromConfigPickedOverGlobalOne.symbols

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export namespace EmotionJSX {
178178
=== /index.tsx ===
179179
export const Comp = () => <div css="color: hotpink;"></div>;
180180
>Comp : Symbol(Comp, Decl(index.tsx, 0, 12))
181-
>div : Symbol(JSX.IntrinsicElements.div, Decl(index.d.ts, 14, 33))
181+
>div : Symbol(div, Decl(index.d.ts, 14, 33))
182182
>css : Symbol(css, Decl(index.tsx, 0, 30))
183-
>div : Symbol(JSX.IntrinsicElements.div, Decl(index.d.ts, 14, 33))
183+
>div : Symbol(div, Decl(index.d.ts, 14, 33))
184184

tests/baselines/reference/jsxNamespaceImplicitImportJSXNamespaceFromConfigPickedOverGlobalOne.types

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export = React;
33
>React : any
44

55
export as namespace React;
6-
>React : any
6+
>React : error
77

88
declare namespace React {}
99

@@ -103,9 +103,9 @@ export namespace EmotionJSX {
103103

104104
=== /index.tsx ===
105105
export const Comp = () => <div css="color: hotpink;"></div>;
106-
>Comp : () => JSX.Element
107-
>() => <div css="color: hotpink;"></div> : () => JSX.Element
108-
><div css="color: hotpink;"></div> : JSX.Element
106+
>Comp : () => import("/node_modules/@emotion/react/jsx-runtime/jsx-namespace").EmotionJSX.Element
107+
>() => <div css="color: hotpink;"></div> : () => import("/node_modules/@emotion/react/jsx-runtime/jsx-namespace").EmotionJSX.Element
108+
><div css="color: hotpink;"></div> : import("/node_modules/@emotion/react/jsx-runtime/jsx-namespace").EmotionJSX.Element
109109
>div : any
110110
>css : string
111111
>div : any

tests/baselines/reference/jsxNamespaceImplicitImportJSXNamespaceFromPragmaPickedOverGlobalOne.errors.txt

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/index.tsx(2,28): error TS2708: Cannot use namespace 'React' as a value.
2-
/index.tsx(2,32): error TS2322: Type '{ css: string; }' is not assignable to type '{}'.
3-
Property 'css' does not exist on type '{}'.
42

53

64
==== /node_modules/react/index.d.ts (0 errors) ====
@@ -63,12 +61,9 @@
6361
}
6462
}
6563

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

tests/baselines/reference/jsxNamespaceImplicitImportJSXNamespaceFromPragmaPickedOverGlobalOne.symbols

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export namespace EmotionJSX {
179179
/* @jsxImportSource @emotion/react */
180180
export const Comp = () => <div css="color: hotpink;"></div>;
181181
>Comp : Symbol(Comp, Decl(index.tsx, 1, 12))
182-
>div : Symbol(JSX.IntrinsicElements.div, Decl(index.d.ts, 14, 37))
182+
>div : Symbol(div, Decl(index.d.ts, 14, 37))
183183
>css : Symbol(css, Decl(index.tsx, 1, 30))
184-
>div : Symbol(JSX.IntrinsicElements.div, Decl(index.d.ts, 14, 37))
184+
>div : Symbol(div, Decl(index.d.ts, 14, 37))
185185

tests/baselines/reference/jsxNamespaceImplicitImportJSXNamespaceFromPragmaPickedOverGlobalOne.types

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ export namespace EmotionJSX {
104104
=== /index.tsx ===
105105
/* @jsxImportSource @emotion/react */
106106
export const Comp = () => <div css="color: hotpink;"></div>;
107-
>Comp : () => JSX.Element
108-
>() => <div css="color: hotpink;"></div> : () => JSX.Element
109-
><div css="color: hotpink;"></div> : JSX.Element
107+
>Comp : () => import("/node_modules/@emotion/react/jsx-runtime/jsx-namespace").EmotionJSX.Element
108+
>() => <div css="color: hotpink;"></div> : () => import("/node_modules/@emotion/react/jsx-runtime/jsx-namespace").EmotionJSX.Element
109+
><div css="color: hotpink;"></div> : import("/node_modules/@emotion/react/jsx-runtime/jsx-namespace").EmotionJSX.Element
110110
>div : any
111111
>css : string
112112
>div : any

0 commit comments

Comments
 (0)