Skip to content

Commit 2d11280

Browse files
🤖 Pick PR #60687 (Remove reference not found errors f...) into release-5.7 (#60721)
Co-authored-by: Isabel Duan <[email protected]>
1 parent c765dce commit 2d11280

15 files changed

+434
-29
lines changed

‎src/compiler/checker.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -29878,14 +29878,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2987829878
const jsxFactoryRefErr = diagnostics && compilerOptions.jsx === JsxEmit.React ? Diagnostics.This_JSX_tag_requires_0_to_be_in_scope_but_it_could_not_be_found : undefined;
2987929879
const jsxFactoryNamespace = getJsxNamespace(node);
2988029880
const jsxFactoryLocation = isJsxOpeningLikeElement(node) ? node.tagName : node;
29881+
const shouldFactoryRefErr = compilerOptions.jsx !== JsxEmit.Preserve && compilerOptions.jsx !== JsxEmit.ReactNative;
2988129882

2988229883
// #38720/60122, allow null as jsxFragmentFactory
2988329884
let jsxFactorySym: Symbol | undefined;
2988429885
if (!(isJsxOpeningFragment(node) && jsxFactoryNamespace === "null")) {
2988529886
jsxFactorySym = resolveName(
2988629887
jsxFactoryLocation,
2988729888
jsxFactoryNamespace,
29888-
(compilerOptions.jsx === JsxEmit.Preserve || compilerOptions.jsx === JsxEmit.ReactNative) ? SymbolFlags.Value & ~SymbolFlags.Enum : SymbolFlags.Value,
29889+
shouldFactoryRefErr ? SymbolFlags.Value : SymbolFlags.Value & ~SymbolFlags.Enum,
2988929890
jsxFactoryRefErr,
2989029891
/*isUse*/ true,
2989129892
);
@@ -29910,7 +29911,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2991029911
resolveName(
2991129912
jsxFactoryLocation,
2991229913
localJsxNamespace,
29913-
(compilerOptions.jsx === JsxEmit.Preserve || compilerOptions.jsx === JsxEmit.ReactNative) ? SymbolFlags.Value & ~SymbolFlags.Enum : SymbolFlags.Value,
29914+
shouldFactoryRefErr ? SymbolFlags.Value : SymbolFlags.Value & ~SymbolFlags.Enum,
2991429915
jsxFactoryRefErr,
2991529916
/*isUse*/ true,
2991629917
);
@@ -36669,15 +36670,18 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3666936670
if (sourceFileLinks.jsxFragmentType !== undefined) return sourceFileLinks.jsxFragmentType;
3667036671

3667136672
const jsxFragmentFactoryName = getJsxNamespace(node);
36673+
3667236674
// #38720/60122, allow null as jsxFragmentFactory
36673-
if (jsxFragmentFactoryName === "null") return sourceFileLinks.jsxFragmentType = anyType;
36675+
const shouldResolveFactoryReference = (compilerOptions.jsx === JsxEmit.React || compilerOptions.jsxFragmentFactory !== undefined) && jsxFragmentFactoryName !== "null";
36676+
if (!shouldResolveFactoryReference) return sourceFileLinks.jsxFragmentType = anyType;
3667436677

36678+
const shouldModuleRefErr = compilerOptions.jsx !== JsxEmit.Preserve && compilerOptions.jsx !== JsxEmit.ReactNative;
3667536679
const jsxFactoryRefErr = diagnostics ? Diagnostics.Using_JSX_fragments_requires_fragment_factory_0_to_be_in_scope_but_it_could_not_be_found : undefined;
3667636680
const jsxFactorySymbol = getJsxNamespaceContainerForImplicitImport(node) ??
3667736681
resolveName(
3667836682
node,
3667936683
jsxFragmentFactoryName,
36680-
(compilerOptions.jsx === JsxEmit.Preserve || compilerOptions.jsx === JsxEmit.ReactNative) ? SymbolFlags.Value & ~SymbolFlags.Enum : SymbolFlags.Value,
36684+
shouldModuleRefErr ? SymbolFlags.Value : SymbolFlags.Value & ~SymbolFlags.Enum,
3668136685
/*nameNotFoundMessage*/ jsxFactoryRefErr,
3668236686
/*isUse*/ true,
3668336687
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
jsxFragmentFactoryReference.tsx(3,9): error TS2874: This JSX tag requires 'React' to be in scope, but it could not be found.
2+
jsxFragmentFactoryReference.tsx(3,9): error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found.
3+
4+
5+
==== jsxFragmentFactoryReference.tsx (2 errors) ====
6+
export class LoggedOut {
7+
content = () => (
8+
<></>
9+
~~
10+
!!! error TS2874: This JSX tag requires 'React' to be in scope, but it could not be found.
11+
~~
12+
!!! error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found.
13+
)
14+
}
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
jsxFragmentFactoryReference.tsx(3,9): error TS2792: Cannot find module 'react/jsx-runtime'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
2+
3+
4+
==== jsxFragmentFactoryReference.tsx (1 errors) ====
5+
export class LoggedOut {
6+
content = () => (
7+
<></>
8+
~~
9+
!!! error TS2792: Cannot find module 'react/jsx-runtime'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
10+
)
11+
}
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
jsxFragmentFactoryReference.tsx(3,9): error TS2792: Cannot find module 'react/jsx-dev-runtime'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
2+
3+
4+
==== jsxFragmentFactoryReference.tsx (1 errors) ====
5+
export class LoggedOut {
6+
content = () => (
7+
<></>
8+
~~
9+
!!! error TS2792: Cannot find module 'react/jsx-dev-runtime'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
10+
)
11+
}
12+

‎tests/baselines/reference/jsxJsxsCjsTransformCustomImport(jsx=react-jsx).errors.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
jsxJsxsCjsTransformCustomImport.tsx(2,11): error TS2875: This JSX tag requires the module path 'preact/jsx-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed.
2-
jsxJsxsCjsTransformCustomImport.tsx(2,11): error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found.
32

43

5-
==== jsxJsxsCjsTransformCustomImport.tsx (2 errors) ====
4+
==== jsxJsxsCjsTransformCustomImport.tsx (1 errors) ====
65
/// <reference path="/.lib/react16.d.ts" />
76
const a = <>
87
~~
98
!!! error TS2875: This JSX tag requires the module path 'preact/jsx-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed.
10-
~~
11-
!!! error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found.
129
<p></p>
1310
text
1411
<div className="foo"></div>

‎tests/baselines/reference/jsxJsxsCjsTransformCustomImport(jsx=react-jsxdev).errors.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
jsxJsxsCjsTransformCustomImport.tsx(2,11): error TS2875: This JSX tag requires the module path 'preact/jsx-dev-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed.
2-
jsxJsxsCjsTransformCustomImport.tsx(2,11): error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found.
32

43

5-
==== jsxJsxsCjsTransformCustomImport.tsx (2 errors) ====
4+
==== jsxJsxsCjsTransformCustomImport.tsx (1 errors) ====
65
/// <reference path="/.lib/react16.d.ts" />
76
const a = <>
87
~~
98
!!! error TS2875: This JSX tag requires the module path 'preact/jsx-dev-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed.
10-
~~
11-
!!! error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found.
129
<p></p>
1310
text
1411
<div className="foo"></div>

‎tests/baselines/reference/jsxJsxsCjsTransformCustomImportPragma(jsx=react-jsx).errors.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
preact.tsx(3,11): error TS2875: This JSX tag requires the module path 'preact/jsx-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed.
2-
preact.tsx(3,11): error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found.
32

43

54
==== react.tsx (0 errors) ====
@@ -13,14 +12,12 @@ preact.tsx(3,11): error TS2879: Using JSX fragments requires fragment factory 'R
1312
</>
1413

1514
export {};
16-
==== preact.tsx (2 errors) ====
15+
==== preact.tsx (1 errors) ====
1716
/// <reference path="/.lib/react16.d.ts" />
1817
/* @jsxImportSource preact */
1918
const a = <>
2019
~~
2120
!!! error TS2875: This JSX tag requires the module path 'preact/jsx-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed.
22-
~~
23-
!!! error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found.
2421
<p></p>
2522
text
2623
<div className="foo"></div>

‎tests/baselines/reference/jsxJsxsCjsTransformCustomImportPragma(jsx=react-jsxdev).errors.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
preact.tsx(3,11): error TS2875: This JSX tag requires the module path 'preact/jsx-dev-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed.
2-
preact.tsx(3,11): error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found.
32

43

54
==== react.tsx (0 errors) ====
@@ -13,14 +12,12 @@ preact.tsx(3,11): error TS2879: Using JSX fragments requires fragment factory 'R
1312
</>
1413

1514
export {};
16-
==== preact.tsx (2 errors) ====
15+
==== preact.tsx (1 errors) ====
1716
/// <reference path="/.lib/react16.d.ts" />
1817
/* @jsxImportSource preact */
1918
const a = <>
2019
~~
2120
!!! error TS2875: This JSX tag requires the module path 'preact/jsx-dev-runtime' to exist, but none could be found. Make sure you have types for the appropriate package installed.
22-
~~
23-
!!! error TS2879: Using JSX fragments requires fragment factory 'React' to be in scope, but it could not be found.
2421
<p></p>
2522
text
2623
<div className="foo"></div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//// [tests/cases/compiler/jsxRuntimePragma.ts] ////
2+
3+
//// [one.tsx]
4+
/// <reference path="/.lib/react16.d.ts" />
5+
/* @jsxRuntime classic */
6+
import * as React from "react";
7+
export const HelloWorld = () => <h1>Hello world</h1>;
8+
export const frag = <><div></div></>;
9+
export const selfClosing = <img src="./image.png" />;
10+
//// [two.tsx]
11+
/// <reference path="/.lib/react16.d.ts" />
12+
/* @jsxRuntime automatic */
13+
export const HelloWorld = () => <h1>Hello world</h1>;
14+
export const frag = <><div></div></>;
15+
export const selfClosing = <img src="./image.png" />;
16+
//// [three.tsx]
17+
/// <reference path="/.lib/react16.d.ts" />
18+
/* @jsxRuntime classic */
19+
/* @jsxRuntime automatic */
20+
export const HelloWorld = () => <h1>Hello world</h1>;
21+
export const frag = <><div></div></>;
22+
export const selfClosing = <img src="./image.png" />;
23+
//// [four.tsx]
24+
/// <reference path="/.lib/react16.d.ts" />
25+
/* @jsxRuntime automatic */
26+
/* @jsxRuntime classic */
27+
import * as React from "react";
28+
export const HelloWorld = () => <h1>Hello world</h1>;
29+
export const frag = <><div></div></>;
30+
export const selfClosing = <img src="./image.png" />;
31+
//// [index.ts]
32+
export * as one from "./one.js";
33+
export * as two from "./two.js";
34+
export * as three from "./three.js";
35+
export * as four from "./four.js";
36+
37+
//// [one.jsx]
38+
"use strict";
39+
Object.defineProperty(exports, "__esModule", { value: true });
40+
exports.selfClosing = exports.frag = exports.HelloWorld = void 0;
41+
/// <reference path="react16.d.ts" />
42+
/* @jsxRuntime classic */
43+
var React = require("react");
44+
var HelloWorld = function () { return <h1>Hello world</h1>; };
45+
exports.HelloWorld = HelloWorld;
46+
exports.frag = <><div></div></>;
47+
exports.selfClosing = <img src="./image.png"/>;
48+
//// [two.jsx]
49+
"use strict";
50+
Object.defineProperty(exports, "__esModule", { value: true });
51+
exports.selfClosing = exports.frag = exports.HelloWorld = void 0;
52+
/// <reference path="react16.d.ts" />
53+
/* @jsxRuntime automatic */
54+
var HelloWorld = function () { return <h1>Hello world</h1>; };
55+
exports.HelloWorld = HelloWorld;
56+
exports.frag = <><div></div></>;
57+
exports.selfClosing = <img src="./image.png"/>;
58+
//// [three.jsx]
59+
"use strict";
60+
Object.defineProperty(exports, "__esModule", { value: true });
61+
exports.selfClosing = exports.frag = exports.HelloWorld = void 0;
62+
/// <reference path="react16.d.ts" />
63+
/* @jsxRuntime classic */
64+
/* @jsxRuntime automatic */
65+
var HelloWorld = function () { return <h1>Hello world</h1>; };
66+
exports.HelloWorld = HelloWorld;
67+
exports.frag = <><div></div></>;
68+
exports.selfClosing = <img src="./image.png"/>;
69+
//// [four.jsx]
70+
"use strict";
71+
Object.defineProperty(exports, "__esModule", { value: true });
72+
exports.selfClosing = exports.frag = exports.HelloWorld = void 0;
73+
/// <reference path="react16.d.ts" />
74+
/* @jsxRuntime automatic */
75+
/* @jsxRuntime classic */
76+
var React = require("react");
77+
var HelloWorld = function () { return <h1>Hello world</h1>; };
78+
exports.HelloWorld = HelloWorld;
79+
exports.frag = <><div></div></>;
80+
exports.selfClosing = <img src="./image.png"/>;
81+
//// [index.js]
82+
"use strict";
83+
Object.defineProperty(exports, "__esModule", { value: true });
84+
exports.four = exports.three = exports.two = exports.one = void 0;
85+
exports.one = require("./one.js");
86+
exports.two = require("./two.js");
87+
exports.three = require("./three.js");
88+
exports.four = require("./four.js");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
//// [tests/cases/compiler/jsxRuntimePragma.ts] ////
2+
3+
=== one.tsx ===
4+
/// <reference path="react16.d.ts" />
5+
/* @jsxRuntime classic */
6+
import * as React from "react";
7+
>React : Symbol(React, Decl(one.tsx, 2, 6))
8+
9+
export const HelloWorld = () => <h1>Hello world</h1>;
10+
>HelloWorld : Symbol(HelloWorld, Decl(one.tsx, 3, 12))
11+
>h1 : Symbol(JSX.IntrinsicElements.h1, Decl(react16.d.ts, 2556, 106))
12+
>h1 : Symbol(JSX.IntrinsicElements.h1, Decl(react16.d.ts, 2556, 106))
13+
14+
export const frag = <><div></div></>;
15+
>frag : Symbol(frag, Decl(one.tsx, 4, 12))
16+
>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2546, 114))
17+
>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2546, 114))
18+
19+
export const selfClosing = <img src="./image.png" />;
20+
>selfClosing : Symbol(selfClosing, Decl(one.tsx, 5, 12))
21+
>img : Symbol(JSX.IntrinsicElements.img, Decl(react16.d.ts, 2569, 114))
22+
>src : Symbol(src, Decl(one.tsx, 5, 31))
23+
24+
=== two.tsx ===
25+
/// <reference path="react16.d.ts" />
26+
/* @jsxRuntime automatic */
27+
export const HelloWorld = () => <h1>Hello world</h1>;
28+
>HelloWorld : Symbol(HelloWorld, Decl(two.tsx, 2, 12))
29+
>h1 : Symbol(JSX.IntrinsicElements.h1, Decl(react16.d.ts, 2556, 106))
30+
>h1 : Symbol(JSX.IntrinsicElements.h1, Decl(react16.d.ts, 2556, 106))
31+
32+
export const frag = <><div></div></>;
33+
>frag : Symbol(frag, Decl(two.tsx, 3, 12))
34+
>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2546, 114))
35+
>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2546, 114))
36+
37+
export const selfClosing = <img src="./image.png" />;
38+
>selfClosing : Symbol(selfClosing, Decl(two.tsx, 4, 12))
39+
>img : Symbol(JSX.IntrinsicElements.img, Decl(react16.d.ts, 2569, 114))
40+
>src : Symbol(src, Decl(two.tsx, 4, 31))
41+
42+
=== three.tsx ===
43+
/// <reference path="react16.d.ts" />
44+
/* @jsxRuntime classic */
45+
/* @jsxRuntime automatic */
46+
export const HelloWorld = () => <h1>Hello world</h1>;
47+
>HelloWorld : Symbol(HelloWorld, Decl(three.tsx, 3, 12))
48+
>h1 : Symbol(JSX.IntrinsicElements.h1, Decl(react16.d.ts, 2556, 106))
49+
>h1 : Symbol(JSX.IntrinsicElements.h1, Decl(react16.d.ts, 2556, 106))
50+
51+
export const frag = <><div></div></>;
52+
>frag : Symbol(frag, Decl(three.tsx, 4, 12))
53+
>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2546, 114))
54+
>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2546, 114))
55+
56+
export const selfClosing = <img src="./image.png" />;
57+
>selfClosing : Symbol(selfClosing, Decl(three.tsx, 5, 12))
58+
>img : Symbol(JSX.IntrinsicElements.img, Decl(react16.d.ts, 2569, 114))
59+
>src : Symbol(src, Decl(three.tsx, 5, 31))
60+
61+
=== four.tsx ===
62+
/// <reference path="react16.d.ts" />
63+
/* @jsxRuntime automatic */
64+
/* @jsxRuntime classic */
65+
import * as React from "react";
66+
>React : Symbol(React, Decl(four.tsx, 3, 6))
67+
68+
export const HelloWorld = () => <h1>Hello world</h1>;
69+
>HelloWorld : Symbol(HelloWorld, Decl(four.tsx, 4, 12))
70+
>h1 : Symbol(JSX.IntrinsicElements.h1, Decl(react16.d.ts, 2556, 106))
71+
>h1 : Symbol(JSX.IntrinsicElements.h1, Decl(react16.d.ts, 2556, 106))
72+
73+
export const frag = <><div></div></>;
74+
>frag : Symbol(frag, Decl(four.tsx, 5, 12))
75+
>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2546, 114))
76+
>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2546, 114))
77+
78+
export const selfClosing = <img src="./image.png" />;
79+
>selfClosing : Symbol(selfClosing, Decl(four.tsx, 6, 12))
80+
>img : Symbol(JSX.IntrinsicElements.img, Decl(react16.d.ts, 2569, 114))
81+
>src : Symbol(src, Decl(four.tsx, 6, 31))
82+
83+
=== index.ts ===
84+
export * as one from "./one.js";
85+
>one : Symbol(one, Decl(index.ts, 0, 6))
86+
87+
export * as two from "./two.js";
88+
>two : Symbol(two, Decl(index.ts, 1, 6))
89+
90+
export * as three from "./three.js";
91+
>three : Symbol(three, Decl(index.ts, 2, 6))
92+
93+
export * as four from "./four.js";
94+
>four : Symbol(four, Decl(index.ts, 3, 6))
95+

0 commit comments

Comments
 (0)