Skip to content

Commit

Permalink
Lookup non-local element factory for reference marking when marking f…
Browse files Browse the repository at this point in the history
…ragment references (#60684)
  • Loading branch information
weswigham authored Dec 5, 2024
1 parent 517da72 commit 12d9687
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30042,8 +30042,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// 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);
if (localJsxNamespace) {
const entity = getJsxFactoryEntity(file);
if (entity) {
const localJsxNamespace = getFirstIdentifier(entity).escapedText;
resolveName(
jsxFactoryLocation,
localJsxNamespace,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//// [tests/cases/compiler/jsxFragmentAndFactoryUsedOnFragmentUse.tsx] ////

//// [index.tsx]
import {element, fragment} from "./jsx";

export const a = <>fragment text</>

//// [jsx.ts]
export function element() {}

export function fragment() {}

//// [jsx.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.element = element;
exports.fragment = fragment;
function element() { }
function fragment() { }
//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.a = void 0;
var jsx_1 = require("./jsx");
exports.a = (0, jsx_1.element)(jsx_1.fragment, null, "fragment text");
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//// [tests/cases/compiler/jsxFragmentAndFactoryUsedOnFragmentUse.tsx] ////

=== index.tsx ===
import {element, fragment} from "./jsx";
>element : Symbol(element, Decl(index.tsx, 0, 8))
>fragment : Symbol(fragment, Decl(index.tsx, 0, 16))

export const a = <>fragment text</>
>a : Symbol(a, Decl(index.tsx, 2, 12))

=== jsx.ts ===
export function element() {}
>element : Symbol(element, Decl(jsx.ts, 0, 0))

export function fragment() {}
>fragment : Symbol(fragment, Decl(jsx.ts, 0, 28))

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//// [tests/cases/compiler/jsxFragmentAndFactoryUsedOnFragmentUse.tsx] ////

=== index.tsx ===
import {element, fragment} from "./jsx";
>element : () => void
> : ^^^^^^^^^^
>fragment : () => void
> : ^^^^^^^^^^

export const a = <>fragment text</>
>a : any
><>fragment text</> : any

=== jsx.ts ===
export function element() {}
>element : () => void
> : ^^^^^^^^^^

export function fragment() {}
>fragment : () => void
> : ^^^^^^^^^^

13 changes: 13 additions & 0 deletions tests/cases/compiler/jsxFragmentAndFactoryUsedOnFragmentUse.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @jsx: react
// @jsxFactory: element
// @jsxFragmentFactory: fragment
// @noUnusedLocals: true
// @filename: index.tsx
import {element, fragment} from "./jsx";

export const a = <>fragment text</>

// @filename: jsx.ts
export function element() {}

export function fragment() {}

0 comments on commit 12d9687

Please sign in to comment.