Resolve aliases to jsx namespace symbol (#30160)

This commit is contained in:
Wesley Wigham
2019-02-28 13:52:57 -08:00
committed by GitHub
parent 7f5052bf7b
commit b1a73ab560
5 changed files with 109 additions and 1 deletions

View File

@@ -18897,7 +18897,7 @@ namespace ts {
const namespaceName = getJsxNamespace(location);
const resolvedNamespace = resolveName(location, namespaceName, SymbolFlags.Namespace, /*diagnosticMessage*/ undefined, namespaceName, /*isUse*/ false);
if (resolvedNamespace) {
const candidate = getSymbol(getExportsOfSymbol(resolveSymbol(resolvedNamespace)), JsxNames.JSX, SymbolFlags.Namespace);
const candidate = resolveSymbol(getSymbol(getExportsOfSymbol(resolveSymbol(resolvedNamespace)), JsxNames.JSX, SymbolFlags.Namespace));
if (candidate) {
if (links) {
links.jsxNamespace = candidate;

View File

@@ -0,0 +1,32 @@
//// [tests/cases/compiler/jsxNamespaceReexports.tsx] ////
//// [library.ts]
function createElement(element: string, props: any, ...children: any[]): any {}
namespace JSX {
export interface IntrinsicElements {
[key: string]: Record<string, any>;
}
}
export { createElement, JSX };
//// [index.tsx]
import * as MyLib from "./library";
const content = <my-element/>;
//// [library.js]
"use strict";
exports.__esModule = true;
function createElement(element, props) {
var children = [];
for (var _i = 2; _i < arguments.length; _i++) {
children[_i - 2] = arguments[_i];
}
}
exports.createElement = createElement;
//// [index.js]
"use strict";
exports.__esModule = true;
var MyLib = require("./library");
var content = MyLib.createElement("my-element", null);

View File

@@ -0,0 +1,31 @@
=== tests/cases/compiler/library.ts ===
function createElement(element: string, props: any, ...children: any[]): any {}
>createElement : Symbol(createElement, Decl(library.ts, 0, 0))
>element : Symbol(element, Decl(library.ts, 0, 23))
>props : Symbol(props, Decl(library.ts, 0, 39))
>children : Symbol(children, Decl(library.ts, 0, 51))
namespace JSX {
>JSX : Symbol(JSX, Decl(library.ts, 0, 79))
export interface IntrinsicElements {
>IntrinsicElements : Symbol(IntrinsicElements, Decl(library.ts, 2, 15))
[key: string]: Record<string, any>;
>key : Symbol(key, Decl(library.ts, 4, 5))
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
}
}
export { createElement, JSX };
>createElement : Symbol(createElement, Decl(library.ts, 8, 8))
>JSX : Symbol(JSX, Decl(library.ts, 8, 23))
=== tests/cases/compiler/index.tsx ===
import * as MyLib from "./library";
>MyLib : Symbol(MyLib, Decl(index.tsx, 0, 6))
const content = <my-element/>;
>content : Symbol(content, Decl(index.tsx, 2, 5))
>my-element : Symbol(MyLib.JSX.IntrinsicElements, Decl(library.ts, 2, 15))

View File

@@ -0,0 +1,27 @@
=== tests/cases/compiler/library.ts ===
function createElement(element: string, props: any, ...children: any[]): any {}
>createElement : (element: string, props: any, ...children: any[]) => any
>element : string
>props : any
>children : any[]
namespace JSX {
export interface IntrinsicElements {
[key: string]: Record<string, any>;
>key : string
}
}
export { createElement, JSX };
>createElement : (element: string, props: any, ...children: any[]) => any
>JSX : any
=== tests/cases/compiler/index.tsx ===
import * as MyLib from "./library";
>MyLib : typeof MyLib
const content = <my-element/>;
>content : error
><my-element/> : error
>my-element : any

View File

@@ -0,0 +1,18 @@
// @jsx: react
// @jsxFactory: MyLib.createElement
// @strict: true
// @filename: library.ts
function createElement(element: string, props: any, ...children: any[]): any {}
namespace JSX {
export interface IntrinsicElements {
[key: string]: Record<string, any>;
}
}
export { createElement, JSX };
// @filename: index.tsx
import * as MyLib from "./library";
const content = <my-element/>;