From 4c8e924bd6bceec80a90c0b16a581c8ecf40b022 Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Wed, 2 Oct 2024 13:50:41 -0700 Subject: [PATCH 1/3] test fix --- src/compiler/checker.ts | 10 ++-- .../inlineJsxAndJsxFragPragma.errors.txt | 15 ++---- ...gPragmaOverridesCompilerOptions.errors.txt | 49 ------------------- ...sxFragPragmaOverridesCompilerOptions.types | 24 +++------ ...actoryAndJsxFragmentFactoryNull.errors.txt | 10 ---- .../jsxFactoryAndJsxFragmentFactoryNull.types | 19 +++---- 6 files changed, 23 insertions(+), 104 deletions(-) delete mode 100644 tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.errors.txt delete mode 100644 tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fb47b8a6b2747..5319db23e6b53 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29876,7 +29876,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // allow null as jsxFragmentFactory let jsxFactorySym: Symbol | undefined; if (!(isJsxOpeningFragment(node) && jsxFactoryNamespace === "null")) { - jsxFactorySym = resolveName(jsxFactoryLocation, jsxFactoryNamespace, SymbolFlags.Value, jsxFactoryRefErr, /*isUse*/ true); + jsxFactorySym = resolveName(jsxFactoryLocation, jsxFactoryNamespace, compilerOptions.jsx === JsxEmit.Preserve ? SymbolFlags.Value & ~SymbolFlags.Enum : SymbolFlags.Value, jsxFactoryRefErr, /*isUse*/ true); } if (jsxFactorySym) { @@ -29890,12 +29890,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } - // For JsxFragment, mark jsx pragma as referenced via resolveName + // For JsxFragment, additionally mark jsx pragma as referenced via resolveName, since `getJsxNamespace` above would have resolved to only the fragment factory if they are distinct if (isJsxOpeningFragment(node)) { const file = getSourceFileOfNode(node); const localJsxNamespace = getLocalJsxNamespace(file); if (localJsxNamespace) { - resolveName(jsxFactoryLocation, localJsxNamespace, SymbolFlags.Value, jsxFactoryRefErr, /*isUse*/ true); + resolveName(jsxFactoryLocation, localJsxNamespace, compilerOptions.jsx === JsxEmit.Preserve ? SymbolFlags.Value & ~SymbolFlags.Enum : SymbolFlags.Value, jsxFactoryRefErr, /*isUse*/ true); } } } @@ -36643,9 +36643,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (sourceFileLinks.jsxFragmentType !== undefined) return sourceFileLinks.jsxFragmentType; const jsxFragmentFactoryName = getJsxNamespace(node); + if (jsxFragmentFactoryName === "null") return sourceFileLinks.jsxFragmentType = anyType; + 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, SymbolFlags.Value, /*nameNotFoundMessage*/ jsxFactoryRefErr, /*isUse*/ true); + resolveName(node, jsxFragmentFactoryName, compilerOptions.jsx === JsxEmit.Preserve ? 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); diff --git a/tests/baselines/reference/inlineJsxAndJsxFragPragma.errors.txt b/tests/baselines/reference/inlineJsxAndJsxFragPragma.errors.txt index 6dd5e9c1454eb..7867b75bdd8fc 100644 --- a/tests/baselines/reference/inlineJsxAndJsxFragPragma.errors.txt +++ b/tests/baselines/reference/inlineJsxAndJsxFragPragma.errors.txt @@ -1,9 +1,6 @@ preacty-no-fragment.tsx(5,12): error TS6133: 'Fragment' is declared but its value is never read. preacty-only-fragment-no-jsx.tsx(6,1): error TS2874: This JSX tag requires 'h' to be in scope, but it could not be found. snabbdomy-only-fragment-no-jsx.tsx(4,1): error TS2874: This JSX tag requires 'jsx' to be in scope, but it could not be found. -snabbdomy-only-fragment-no-jsx.tsx(4,1): error TS2879: Using JSX fragments requires fragment factory 'null' to be in scope, but it could not be found. -snabbdomy-only-fragment.tsx(4,1): error TS2879: Using JSX fragments requires fragment factory 'null' to be in scope, but it could not be found. -snabbdomy.tsx(4,1): error TS2879: Using JSX fragments requires fragment factory 'null' to be in scope, but it could not be found. ==== renderer.d.ts (0 errors) ==== @@ -26,13 +23,11 @@ snabbdomy.tsx(4,1): error TS2879: Using JSX fragments requires fragment factory import {h, Fragment} from "./renderer"; <>
-==== snabbdomy.tsx (1 errors) ==== +==== snabbdomy.tsx (0 errors) ==== /* @jsx jsx */ /* @jsxfrag null */ import {jsx} from "./renderer"; <> - ~~ -!!! error TS2879: Using JSX fragments requires fragment factory 'null' to be in scope, but it could not be found. ==== preacty-only-fragment.tsx (0 errors) ==== /** @@ -42,13 +37,11 @@ snabbdomy.tsx(4,1): error TS2879: Using JSX fragments requires fragment factory import {h, Fragment} from "./renderer"; <> -==== snabbdomy-only-fragment.tsx (1 errors) ==== +==== snabbdomy-only-fragment.tsx (0 errors) ==== /* @jsx jsx */ /* @jsxfrag null */ import {jsx} from "./renderer"; <> - ~~ -!!! error TS2879: Using JSX fragments requires fragment factory 'null' to be in scope, but it could not be found. ==== preacty-only-fragment-no-jsx.tsx (1 errors) ==== /** @@ -60,15 +53,13 @@ snabbdomy.tsx(4,1): error TS2879: Using JSX fragments requires fragment factory ~~ !!! error TS2874: This JSX tag requires 'h' to be in scope, but it could not be found. -==== snabbdomy-only-fragment-no-jsx.tsx (2 errors) ==== +==== snabbdomy-only-fragment-no-jsx.tsx (1 errors) ==== /* @jsx jsx */ /* @jsxfrag null */ import {} from "./renderer"; <> ~~ !!! error TS2874: This JSX tag requires 'jsx' to be in scope, but it could not be found. - ~~ -!!! error TS2879: Using JSX fragments requires fragment factory 'null' to be in scope, but it could not be found. ==== preacty-no-fragment.tsx (1 errors) ==== /** diff --git a/tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.errors.txt b/tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.errors.txt deleted file mode 100644 index 19ba24340e2da..0000000000000 --- a/tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.errors.txt +++ /dev/null @@ -1,49 +0,0 @@ -snabbdomy.tsx(6,1): error TS2879: Using JSX fragments requires fragment factory 'null' to be in scope, but it could not be found. - - -==== react.d.ts (0 errors) ==== - declare global { - namespace JSX { - interface IntrinsicElements { - [e: string]: any; - } - } - } - export function createElement(): void; - export function Fragment(): void; - -==== preact.d.ts (0 errors) ==== - export function h(): void; - export function Frag(): void; - -==== snabbdom.d.ts (0 errors) ==== - export function h(): void; - -==== reacty.tsx (0 errors) ==== - import {createElement, Fragment} from "./react"; - <> - -==== preacty.tsx (0 errors) ==== - /** - * @jsx h - * @jsxFrag Frag - */ - import {h, Frag} from "./preact"; - <>
- -==== snabbdomy.tsx (1 errors) ==== - /** - * @jsx h - * @jsxfrag null - */ - import {h} from "./snabbdom"; - <>
- ~~ -!!! error TS2879: Using JSX fragments requires fragment factory 'null' to be in scope, but it could not be found. - -==== mix-n-match.tsx (0 errors) ==== - /* @jsx h */ - /* @jsxFrag Fragment */ - import {h} from "./preact"; - import {Fragment} from "./react"; - <> \ No newline at end of file diff --git a/tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.types b/tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.types index 7920f66d89cee..8fb864cf2a86e 100644 --- a/tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.types +++ b/tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.types @@ -43,10 +43,8 @@ import {createElement, Fragment} from "./react"; > : ^^^^^^ <> -><> : any -> : ^^^ -> : any -> : ^^^ +><> : error +> : error >span : any > : ^^^ >span : any @@ -64,10 +62,8 @@ import {h, Frag} from "./preact"; > : ^^^^^^ <>
-><>
: any -> : ^^^ ->
: any -> : ^^^ +><>
: error +>
: error >div : any > : ^^^ >div : any @@ -83,10 +79,8 @@ import {h} from "./snabbdom"; > : ^^^^^^ <>
-><>
: any -> : ^^^ ->
: any -> : ^^^ +><>
: error +>
: error >div : any > : ^^^ >div : any @@ -104,10 +98,8 @@ import {Fragment} from "./react"; > : ^^^^^^ <> -><> : any -> : ^^^ -> : any -> : ^^^ +><> : error +> : error >span : any > : ^^^ >span : any diff --git a/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.errors.txt b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.errors.txt deleted file mode 100644 index df7d2e819b46c..0000000000000 --- a/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.errors.txt +++ /dev/null @@ -1,10 +0,0 @@ -jsxFactoryAndJsxFragmentFactoryNull.tsx(3,1): error TS2879: Using JSX fragments requires fragment factory 'null' to be in scope, but it could not be found. - - -==== jsxFactoryAndJsxFragmentFactoryNull.tsx (1 errors) ==== - declare var h: any; - - <>; - ~~ -!!! error TS2879: Using JSX fragments requires fragment factory 'null' to be in scope, but it could not be found. - <>1<>2.12.2; \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.types b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.types index 5c9d13f33a5ab..2517020c3b2fd 100644 --- a/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.types +++ b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.types @@ -3,31 +3,24 @@ === jsxFactoryAndJsxFragmentFactoryNull.tsx === declare var h: any; >h : any -> : ^^^ <>; -><> : any -> : ^^^ +><> : error <>1<>2.12.2; -><>1<>2.12.2 : any -> : ^^^ ->1 : any -> : ^^^ +><>1<>2.12.2 : error +>1 : error >span : any > : ^^^ >span : any > : ^^^ -><>2.12.2 : any -> : ^^^ ->2.1 : any -> : ^^^ +><>2.12.2 : error +>2.1 : error >span : any > : ^^^ >span : any > : ^^^ ->2.2 : any -> : ^^^ +>2.2 : error >span : any > : ^^^ >span : any From 6169048cdee914cdf0ca3d18ef8976383d292e65 Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Wed, 2 Oct 2024 15:30:36 -0700 Subject: [PATCH 2/3] add comments --- src/compiler/checker.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5319db23e6b53..d23d1b72d5a23 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29873,7 +29873,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const jsxFactoryNamespace = getJsxNamespace(node); const jsxFactoryLocation = isJsxOpeningLikeElement(node) ? node.tagName : node; - // allow null as jsxFragmentFactory + // #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); @@ -29890,7 +29890,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } - // For JsxFragment, additionally mark jsx pragma as referenced via resolveName, since `getJsxNamespace` above would have resolved to only the fragment factory if they are distinct + // if JsxFragment, additionally mark jsx pragma as referenced, since `getJsxNamespace` above would have resolved to only the fragment factory if they are distinct if (isJsxOpeningFragment(node)) { const file = getSourceFileOfNode(node); const localJsxNamespace = getLocalJsxNamespace(file); @@ -36643,6 +36643,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (sourceFileLinks.jsxFragmentType !== undefined) return sourceFileLinks.jsxFragmentType; const jsxFragmentFactoryName = getJsxNamespace(node); + // #38720/60122, allow null as jsxFragmentFactory if (jsxFragmentFactoryName === "null") return sourceFileLinks.jsxFragmentType = anyType; const jsxFactoryRefErr = diagnostics ? Diagnostics.Using_JSX_fragments_requires_fragment_factory_0_to_be_in_scope_but_it_could_not_be_found : undefined; From 93544c846317d8b0ff277ea33d56485c9c60ae13 Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Thu, 3 Oct 2024 15:52:28 -0700 Subject: [PATCH 3/3] fix error type showing up in baselines --- src/compiler/checker.ts | 3 ++- ...nlineJsxAndJsxFragPragmaOverridesCompilerOptions.types | 8 ++++---- .../reference/jsxFactoryAndJsxFragmentFactory.types | 6 +++--- .../reference/jsxFactoryAndJsxFragmentFactoryNull.types | 6 +++--- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d23d1b72d5a23..1f3882dff7269 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -32918,7 +32918,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } checkJsxChildren(node); - return getJsxElementTypeAt(node) || anyType; + const jsxElementType = getJsxElementTypeAt(node); + return isErrorType(jsxElementType) ? anyType : jsxElementType; } function isHyphenatedJsxName(name: string | __String) { diff --git a/tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.types b/tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.types index 8fb864cf2a86e..819a7cc2b3e3b 100644 --- a/tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.types +++ b/tests/baselines/reference/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.types @@ -43,7 +43,7 @@ import {createElement, Fragment} from "./react"; > : ^^^^^^ <> -><> : error +><> : any > : error >span : any > : ^^^ @@ -62,7 +62,7 @@ import {h, Frag} from "./preact"; > : ^^^^^^ <>
-><>
: error +><>
: any >
: error >div : any > : ^^^ @@ -79,7 +79,7 @@ import {h} from "./snabbdom"; > : ^^^^^^ <>
-><>
: error +><>
: any >
: error >div : any > : ^^^ @@ -98,7 +98,7 @@ import {Fragment} from "./react"; > : ^^^^^^ <> -><> : error +><> : any > : error >span : any > : ^^^ diff --git a/tests/baselines/reference/jsxFactoryAndJsxFragmentFactory.types b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactory.types index 9aa6630bb9171..5ac6ac7b6fc47 100644 --- a/tests/baselines/reference/jsxFactoryAndJsxFragmentFactory.types +++ b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactory.types @@ -8,16 +8,16 @@ declare var Frag: any; >Frag : any <>; -><> : error +><> : any <>1<>2.12.2; -><>1<>2.12.2 : error +><>1<>2.12.2 : any >1 : error >span : any > : ^^^ >span : any > : ^^^ -><>2.12.2 : error +><>2.12.2 : any >2.1 : error >span : any > : ^^^ diff --git a/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.types b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.types index 2517020c3b2fd..eee38e2d3fc43 100644 --- a/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.types +++ b/tests/baselines/reference/jsxFactoryAndJsxFragmentFactoryNull.types @@ -5,16 +5,16 @@ declare var h: any; >h : any <>; -><> : error +><> : any <>1<>2.12.2; -><>1<>2.12.2 : error +><>1<>2.12.2 : any >1 : error >span : any > : ^^^ >span : any > : ^^^ -><>2.12.2 : error +><>2.12.2 : any >2.1 : error >span : any > : ^^^