Skip to content

Commit 12d9687

Browse files
authored
Lookup non-local element factory for reference marking when marking fragment references (#60684)
1 parent 517da72 commit 12d9687

File tree

5 files changed

+80
-2
lines changed

5 files changed

+80
-2
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30042,8 +30042,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3004230042
// if JsxFragment, additionally mark jsx pragma as referenced, since `getJsxNamespace` above would have resolved to only the fragment factory if they are distinct
3004330043
if (isJsxOpeningFragment(node)) {
3004430044
const file = getSourceFileOfNode(node);
30045-
const localJsxNamespace = getLocalJsxNamespace(file);
30046-
if (localJsxNamespace) {
30045+
const entity = getJsxFactoryEntity(file);
30046+
if (entity) {
30047+
const localJsxNamespace = getFirstIdentifier(entity).escapedText;
3004730048
resolveName(
3004830049
jsxFactoryLocation,
3004930050
localJsxNamespace,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [tests/cases/compiler/jsxFragmentAndFactoryUsedOnFragmentUse.tsx] ////
2+
3+
//// [index.tsx]
4+
import {element, fragment} from "./jsx";
5+
6+
export const a = <>fragment text</>
7+
8+
//// [jsx.ts]
9+
export function element() {}
10+
11+
export function fragment() {}
12+
13+
//// [jsx.js]
14+
"use strict";
15+
Object.defineProperty(exports, "__esModule", { value: true });
16+
exports.element = element;
17+
exports.fragment = fragment;
18+
function element() { }
19+
function fragment() { }
20+
//// [index.js]
21+
"use strict";
22+
Object.defineProperty(exports, "__esModule", { value: true });
23+
exports.a = void 0;
24+
var jsx_1 = require("./jsx");
25+
exports.a = (0, jsx_1.element)(jsx_1.fragment, null, "fragment text");
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [tests/cases/compiler/jsxFragmentAndFactoryUsedOnFragmentUse.tsx] ////
2+
3+
=== index.tsx ===
4+
import {element, fragment} from "./jsx";
5+
>element : Symbol(element, Decl(index.tsx, 0, 8))
6+
>fragment : Symbol(fragment, Decl(index.tsx, 0, 16))
7+
8+
export const a = <>fragment text</>
9+
>a : Symbol(a, Decl(index.tsx, 2, 12))
10+
11+
=== jsx.ts ===
12+
export function element() {}
13+
>element : Symbol(element, Decl(jsx.ts, 0, 0))
14+
15+
export function fragment() {}
16+
>fragment : Symbol(fragment, Decl(jsx.ts, 0, 28))
17+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//// [tests/cases/compiler/jsxFragmentAndFactoryUsedOnFragmentUse.tsx] ////
2+
3+
=== index.tsx ===
4+
import {element, fragment} from "./jsx";
5+
>element : () => void
6+
> : ^^^^^^^^^^
7+
>fragment : () => void
8+
> : ^^^^^^^^^^
9+
10+
export const a = <>fragment text</>
11+
>a : any
12+
><>fragment text</> : any
13+
14+
=== jsx.ts ===
15+
export function element() {}
16+
>element : () => void
17+
> : ^^^^^^^^^^
18+
19+
export function fragment() {}
20+
>fragment : () => void
21+
> : ^^^^^^^^^^
22+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @jsx: react
2+
// @jsxFactory: element
3+
// @jsxFragmentFactory: fragment
4+
// @noUnusedLocals: true
5+
// @filename: index.tsx
6+
import {element, fragment} from "./jsx";
7+
8+
export const a = <>fragment text</>
9+
10+
// @filename: jsx.ts
11+
export function element() {}
12+
13+
export function fragment() {}

0 commit comments

Comments
 (0)