Skip to content

Commit b1a73ab

Browse files
authored
Resolve aliases to jsx namespace symbol (microsoft#30160)
1 parent 7f5052b commit b1a73ab

File tree

5 files changed

+109
-1
lines changed

5 files changed

+109
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18897,7 +18897,7 @@ namespace ts {
1889718897
const namespaceName = getJsxNamespace(location);
1889818898
const resolvedNamespace = resolveName(location, namespaceName, SymbolFlags.Namespace, /*diagnosticMessage*/ undefined, namespaceName, /*isUse*/ false);
1889918899
if (resolvedNamespace) {
18900-
const candidate = getSymbol(getExportsOfSymbol(resolveSymbol(resolvedNamespace)), JsxNames.JSX, SymbolFlags.Namespace);
18900+
const candidate = resolveSymbol(getSymbol(getExportsOfSymbol(resolveSymbol(resolvedNamespace)), JsxNames.JSX, SymbolFlags.Namespace));
1890118901
if (candidate) {
1890218902
if (links) {
1890318903
links.jsxNamespace = candidate;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//// [tests/cases/compiler/jsxNamespaceReexports.tsx] ////
2+
3+
//// [library.ts]
4+
function createElement(element: string, props: any, ...children: any[]): any {}
5+
6+
namespace JSX {
7+
export interface IntrinsicElements {
8+
[key: string]: Record<string, any>;
9+
}
10+
}
11+
12+
export { createElement, JSX };
13+
//// [index.tsx]
14+
import * as MyLib from "./library";
15+
16+
const content = <my-element/>;
17+
18+
//// [library.js]
19+
"use strict";
20+
exports.__esModule = true;
21+
function createElement(element, props) {
22+
var children = [];
23+
for (var _i = 2; _i < arguments.length; _i++) {
24+
children[_i - 2] = arguments[_i];
25+
}
26+
}
27+
exports.createElement = createElement;
28+
//// [index.js]
29+
"use strict";
30+
exports.__esModule = true;
31+
var MyLib = require("./library");
32+
var content = MyLib.createElement("my-element", null);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
=== tests/cases/compiler/library.ts ===
2+
function createElement(element: string, props: any, ...children: any[]): any {}
3+
>createElement : Symbol(createElement, Decl(library.ts, 0, 0))
4+
>element : Symbol(element, Decl(library.ts, 0, 23))
5+
>props : Symbol(props, Decl(library.ts, 0, 39))
6+
>children : Symbol(children, Decl(library.ts, 0, 51))
7+
8+
namespace JSX {
9+
>JSX : Symbol(JSX, Decl(library.ts, 0, 79))
10+
11+
export interface IntrinsicElements {
12+
>IntrinsicElements : Symbol(IntrinsicElements, Decl(library.ts, 2, 15))
13+
14+
[key: string]: Record<string, any>;
15+
>key : Symbol(key, Decl(library.ts, 4, 5))
16+
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
17+
}
18+
}
19+
20+
export { createElement, JSX };
21+
>createElement : Symbol(createElement, Decl(library.ts, 8, 8))
22+
>JSX : Symbol(JSX, Decl(library.ts, 8, 23))
23+
24+
=== tests/cases/compiler/index.tsx ===
25+
import * as MyLib from "./library";
26+
>MyLib : Symbol(MyLib, Decl(index.tsx, 0, 6))
27+
28+
const content = <my-element/>;
29+
>content : Symbol(content, Decl(index.tsx, 2, 5))
30+
>my-element : Symbol(MyLib.JSX.IntrinsicElements, Decl(library.ts, 2, 15))
31+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
=== tests/cases/compiler/library.ts ===
2+
function createElement(element: string, props: any, ...children: any[]): any {}
3+
>createElement : (element: string, props: any, ...children: any[]) => any
4+
>element : string
5+
>props : any
6+
>children : any[]
7+
8+
namespace JSX {
9+
export interface IntrinsicElements {
10+
[key: string]: Record<string, any>;
11+
>key : string
12+
}
13+
}
14+
15+
export { createElement, JSX };
16+
>createElement : (element: string, props: any, ...children: any[]) => any
17+
>JSX : any
18+
19+
=== tests/cases/compiler/index.tsx ===
20+
import * as MyLib from "./library";
21+
>MyLib : typeof MyLib
22+
23+
const content = <my-element/>;
24+
>content : error
25+
><my-element/> : error
26+
>my-element : any
27+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
// @jsx: react
3+
// @jsxFactory: MyLib.createElement
4+
// @strict: true
5+
// @filename: library.ts
6+
function createElement(element: string, props: any, ...children: any[]): any {}
7+
8+
namespace JSX {
9+
export interface IntrinsicElements {
10+
[key: string]: Record<string, any>;
11+
}
12+
}
13+
14+
export { createElement, JSX };
15+
// @filename: index.tsx
16+
import * as MyLib from "./library";
17+
18+
const content = <my-element/>;

0 commit comments

Comments
 (0)