Skip to content

Commit

Permalink
🤖 Pick PR #60615 (fix missing react error with fragme...) into releas…
Browse files Browse the repository at this point in the history
…e-5.7 (#60618)

Co-authored-by: Isabel Duan <isabelduan@microsoft.com>
  • Loading branch information
typescript-bot and iisaduan authored Nov 26, 2024
1 parent d701d90 commit 5d77da6
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29882,7 +29882,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// #38720/60122, allow null as jsxFragmentFactory
let jsxFactorySym: Symbol | undefined;
if (!(isJsxOpeningFragment(node) && jsxFactoryNamespace === "null")) {
jsxFactorySym = resolveName(jsxFactoryLocation, jsxFactoryNamespace, compilerOptions.jsx === JsxEmit.Preserve ? SymbolFlags.Value & ~SymbolFlags.Enum : SymbolFlags.Value, jsxFactoryRefErr, /*isUse*/ true);
jsxFactorySym = resolveName(
jsxFactoryLocation,
jsxFactoryNamespace,
(compilerOptions.jsx === JsxEmit.Preserve || compilerOptions.jsx === JsxEmit.ReactNative) ? SymbolFlags.Value & ~SymbolFlags.Enum : SymbolFlags.Value,
jsxFactoryRefErr,
/*isUse*/ true,
);
}

if (jsxFactorySym) {
Expand All @@ -29901,7 +29907,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const file = getSourceFileOfNode(node);
const localJsxNamespace = getLocalJsxNamespace(file);
if (localJsxNamespace) {
resolveName(jsxFactoryLocation, localJsxNamespace, compilerOptions.jsx === JsxEmit.Preserve ? SymbolFlags.Value & ~SymbolFlags.Enum : SymbolFlags.Value, jsxFactoryRefErr, /*isUse*/ true);
resolveName(
jsxFactoryLocation,
localJsxNamespace,
(compilerOptions.jsx === JsxEmit.Preserve || compilerOptions.jsx === JsxEmit.ReactNative) ? SymbolFlags.Value & ~SymbolFlags.Enum : SymbolFlags.Value,
jsxFactoryRefErr,
/*isUse*/ true,
);
}
}
}
Expand Down Expand Up @@ -36655,7 +36667,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {

const jsxFactoryRefErr = diagnostics ? Diagnostics.Using_JSX_fragments_requires_fragment_factory_0_to_be_in_scope_but_it_could_not_be_found : undefined;
const jsxFactorySymbol = getJsxNamespaceContainerForImplicitImport(node) ??
resolveName(node, jsxFragmentFactoryName, compilerOptions.jsx === JsxEmit.Preserve ? SymbolFlags.Value & ~SymbolFlags.Enum : SymbolFlags.Value, /*nameNotFoundMessage*/ jsxFactoryRefErr, /*isUse*/ true);
resolveName(
node,
jsxFragmentFactoryName,
(compilerOptions.jsx === JsxEmit.Preserve || compilerOptions.jsx === JsxEmit.ReactNative) ? SymbolFlags.Value & ~SymbolFlags.Enum : SymbolFlags.Value,
/*nameNotFoundMessage*/ jsxFactoryRefErr,
/*isUse*/ true,
);

if (jsxFactorySymbol === undefined) return sourceFileLinks.jsxFragmentType = errorType;
if (jsxFactorySymbol.escapedName === ReactNames.Fragment) return sourceFileLinks.jsxFragmentType = getTypeOfSymbol(jsxFactorySymbol);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/jsxFragReactReferenceErrors.tsx] ////

//// [jsxFragReactReferenceErrors.tsx]
/// <reference path="/.lib/react18/react18.d.ts" />
/// <reference path="/.lib/react18/global.d.ts" />
export function Component(){

return <>
</>
}

//// [jsxFragReactReferenceErrors.jsx]
/// <reference path="react18/react18.d.ts" />
/// <reference path="react18/global.d.ts" />
export function Component() {
return <>
</>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [tests/cases/compiler/jsxFragReactReferenceErrors.tsx] ////

=== jsxFragReactReferenceErrors.tsx ===
/// <reference path="react18/react18.d.ts" />
/// <reference path="react18/global.d.ts" />
export function Component(){
>Component : Symbol(Component, Decl(jsxFragReactReferenceErrors.tsx, 0, 0))

return <>
</>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//// [tests/cases/compiler/jsxFragReactReferenceErrors.tsx] ////

=== jsxFragReactReferenceErrors.tsx ===
/// <reference path="react18/react18.d.ts" />
/// <reference path="react18/global.d.ts" />
export function Component(){
>Component : () => JSX.Element
> : ^^^^^^^^^^^^^^^^^

return <>
><> </> : JSX.Element
> : ^^^^^^^^^^^

</>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/jsxFragReactReferenceErrors.tsx] ////

//// [jsxFragReactReferenceErrors.tsx]
/// <reference path="/.lib/react18/react18.d.ts" />
/// <reference path="/.lib/react18/global.d.ts" />
export function Component(){

return <>
</>
}

//// [jsxFragReactReferenceErrors.js]
/// <reference path="react18/react18.d.ts" />
/// <reference path="react18/global.d.ts" />
export function Component() {
return <>
</>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [tests/cases/compiler/jsxFragReactReferenceErrors.tsx] ////

=== jsxFragReactReferenceErrors.tsx ===
/// <reference path="react18/react18.d.ts" />
/// <reference path="react18/global.d.ts" />
export function Component(){
>Component : Symbol(Component, Decl(jsxFragReactReferenceErrors.tsx, 0, 0))

return <>
</>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//// [tests/cases/compiler/jsxFragReactReferenceErrors.tsx] ////

=== jsxFragReactReferenceErrors.tsx ===
/// <reference path="react18/react18.d.ts" />
/// <reference path="react18/global.d.ts" />
export function Component(){
>Component : () => JSX.Element
> : ^^^^^^^^^^^^^^^^^

return <>
><> </> : JSX.Element
> : ^^^^^^^^^^^

</>
}
14 changes: 14 additions & 0 deletions tests/cases/compiler/jsxFragReactReferenceErrors.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @jsx: react-native, preserve
// @strict: true
// @skipLibCheck: true
// @target: ES2017
// @module: ESNext
// @esModuleInterop: true

/// <reference path="/.lib/react18/react18.d.ts" />
/// <reference path="/.lib/react18/global.d.ts" />
export function Component(){

return <>
</>
}

0 comments on commit 5d77da6

Please sign in to comment.