Skip to content

Commit 998ecd9

Browse files
Andaristsandersn
andauthored
Add a test for JSX namespace lookup with jsx: preserve, jsxImportSource (#41676)
* Add a test for JSX namespace lookup with `jsx: preserve, jsxImportSource` * updated baselines Co-authored-by: Nathan Shively-Sanders <[email protected]>
1 parent dcaefe7 commit 998ecd9

10 files changed

+397
-17
lines changed

tests/baselines/reference/findAllRefsCommonJsRequire2.baseline.jsonc

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@
119119
"containerKind": "",
120120
"containerName": "",
121121
"fileName": "/a.js",
122-
"kind": "property",
123-
"name": "(property) f: () => void",
122+
"kind": "alias",
123+
"name": "(alias) function f(): void\nimport f",
124124
"textSpan": {
125125
"start": 32,
126126
"length": 1
@@ -131,7 +131,7 @@
131131
"kind": "punctuation"
132132
},
133133
{
134-
"text": "property",
134+
"text": "alias",
135135
"kind": "text"
136136
},
137137
{
@@ -143,17 +143,17 @@
143143
"kind": "space"
144144
},
145145
{
146-
"text": "f",
147-
"kind": "propertyName"
148-
},
149-
{
150-
"text": ":",
151-
"kind": "punctuation"
146+
"text": "function",
147+
"kind": "keyword"
152148
},
153149
{
154150
"text": " ",
155151
"kind": "space"
156152
},
153+
{
154+
"text": "f",
155+
"kind": "aliasName"
156+
},
157157
{
158158
"text": "(",
159159
"kind": "punctuation"
@@ -162,21 +162,33 @@
162162
"text": ")",
163163
"kind": "punctuation"
164164
},
165+
{
166+
"text": ":",
167+
"kind": "punctuation"
168+
},
165169
{
166170
"text": " ",
167171
"kind": "space"
168172
},
169173
{
170-
"text": "=>",
171-
"kind": "punctuation"
174+
"text": "void",
175+
"kind": "keyword"
176+
},
177+
{
178+
"text": "\n",
179+
"kind": "lineBreak"
180+
},
181+
{
182+
"text": "import",
183+
"kind": "keyword"
172184
},
173185
{
174186
"text": " ",
175187
"kind": "space"
176188
},
177189
{
178-
"text": "void",
179-
"kind": "keyword"
190+
"text": "f",
191+
"kind": "aliasName"
180192
}
181193
],
182194
"contextSpan": {

tests/baselines/reference/fixSignatureCaching.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,9 +1150,9 @@ define(function () {
11501150
>'[object Array]' : "[object Array]"
11511151

11521152
: Array.isArray;
1153-
>Array.isArray : <T>(arg: {} | T) => arg is T extends readonly any[] ? unknown extends T ? never : readonly any[] : any[]
1153+
>Array.isArray : (arg: any) => arg is any[]
11541154
>Array : ArrayConstructor
1155-
>isArray : <T>(arg: {} | T) => arg is T extends readonly any[] ? unknown extends T ? never : readonly any[] : any[]
1155+
>isArray : (arg: any) => arg is any[]
11561156

11571157
function equalIC(a, b) {
11581158
>equalIC : (a: any, b: any) => boolean

tests/baselines/reference/indirectJsRequireRename.baseline.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// module.exports.[|logWarning|] = message => { };
66

77
// === /bin/serverless.js ===
8-
// /*FIND ALL REFS*/require('../lib/classes/Error').[|logWarning|](`CLI triage crashed with: ${error.stack}`);
8+
// require('../lib/classes/Error').[|log/*FIND ALL REFS*/Warning|](`CLI triage crashed with: ${error.stack}`);
99

1010
[
1111
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//// [tests/cases/compiler/jsxNamespaceImplicitImportJSXNamespaceFromConfigPickedOverGlobalOne.tsx] ////
2+
3+
//// [index.d.ts]
4+
export = React;
5+
export as namespace React;
6+
7+
declare namespace React {}
8+
9+
declare global {
10+
namespace JSX {
11+
interface Element {}
12+
interface ElementClass {}
13+
interface ElementAttributesProperty {}
14+
interface ElementChildrenAttribute {}
15+
type LibraryManagedAttributes<C, P> = {}
16+
interface IntrinsicAttributes {}
17+
interface IntrinsicClassAttributes<T> {}
18+
interface IntrinsicElements {
19+
div: {}
20+
}
21+
}
22+
}
23+
//// [index.d.ts]
24+
export { EmotionJSX as JSX } from './jsx-namespace'
25+
26+
//// [jsx-namespace.d.ts]
27+
import 'react'
28+
29+
type WithConditionalCSSProp<P> = 'className' extends keyof P
30+
? (P extends { className?: string } ? P & { css?: string } : P)
31+
: P
32+
33+
type ReactJSXElement = JSX.Element
34+
type ReactJSXElementClass = JSX.ElementClass
35+
type ReactJSXElementAttributesProperty = JSX.ElementAttributesProperty
36+
type ReactJSXElementChildrenAttribute = JSX.ElementChildrenAttribute
37+
type ReactJSXLibraryManagedAttributes<C, P> = JSX.LibraryManagedAttributes<C, P>
38+
type ReactJSXIntrinsicAttributes = JSX.IntrinsicAttributes
39+
type ReactJSXIntrinsicClassAttributes<T> = JSX.IntrinsicClassAttributes<T>
40+
type ReactJSXIntrinsicElements = JSX.IntrinsicElements
41+
42+
export namespace EmotionJSX {
43+
interface Element extends ReactJSXElement {}
44+
interface ElementClass extends ReactJSXElementClass {}
45+
interface ElementAttributesProperty
46+
extends ReactJSXElementAttributesProperty {}
47+
interface ElementChildrenAttribute extends ReactJSXElementChildrenAttribute {}
48+
49+
type LibraryManagedAttributes<C, P> = WithConditionalCSSProp<P> &
50+
ReactJSXLibraryManagedAttributes<C, P>
51+
52+
interface IntrinsicAttributes extends ReactJSXIntrinsicAttributes {}
53+
interface IntrinsicClassAttributes<T>
54+
extends ReactJSXIntrinsicClassAttributes<T> {}
55+
56+
type IntrinsicElements = {
57+
[K in keyof ReactJSXIntrinsicElements]: ReactJSXIntrinsicElements[K] & {
58+
css?: string
59+
}
60+
}
61+
}
62+
63+
//// [index.tsx]
64+
export const Comp = () => <div css="color: hotpink;"></div>;
65+
66+
67+
//// [index.jsx]
68+
"use strict";
69+
exports.__esModule = true;
70+
exports.Comp = void 0;
71+
var Comp = function () { return <div css="color: hotpink;"></div>; };
72+
exports.Comp = Comp;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
=== /node_modules/react/index.d.ts ===
2+
export = React;
3+
>React : Symbol(React, Decl(index.d.ts, 1, 26))
4+
5+
export as namespace React;
6+
>React : Symbol(React, Decl(index.d.ts, 0, 15))
7+
8+
declare namespace React {}
9+
>React : Symbol(React, Decl(index.d.ts, 1, 26))
10+
11+
declare global {
12+
>global : Symbol(global, Decl(index.d.ts, 3, 26))
13+
14+
namespace JSX {
15+
>JSX : Symbol(JSX, Decl(index.d.ts, 5, 16))
16+
17+
interface Element {}
18+
>Element : Symbol(Element, Decl(index.d.ts, 6, 17))
19+
20+
interface ElementClass {}
21+
>ElementClass : Symbol(ElementClass, Decl(index.d.ts, 7, 24))
22+
23+
interface ElementAttributesProperty {}
24+
>ElementAttributesProperty : Symbol(ElementAttributesProperty, Decl(index.d.ts, 8, 29))
25+
26+
interface ElementChildrenAttribute {}
27+
>ElementChildrenAttribute : Symbol(ElementChildrenAttribute, Decl(index.d.ts, 9, 42))
28+
29+
type LibraryManagedAttributes<C, P> = {}
30+
>LibraryManagedAttributes : Symbol(LibraryManagedAttributes, Decl(index.d.ts, 10, 41))
31+
>C : Symbol(C, Decl(index.d.ts, 11, 34))
32+
>P : Symbol(P, Decl(index.d.ts, 11, 36))
33+
34+
interface IntrinsicAttributes {}
35+
>IntrinsicAttributes : Symbol(IntrinsicAttributes, Decl(index.d.ts, 11, 44))
36+
37+
interface IntrinsicClassAttributes<T> {}
38+
>IntrinsicClassAttributes : Symbol(IntrinsicClassAttributes, Decl(index.d.ts, 12, 36))
39+
>T : Symbol(T, Decl(index.d.ts, 13, 39))
40+
41+
interface IntrinsicElements {
42+
>IntrinsicElements : Symbol(IntrinsicElements, Decl(index.d.ts, 13, 44))
43+
44+
div: {}
45+
>div : Symbol(IntrinsicElements.div, Decl(index.d.ts, 14, 33))
46+
}
47+
}
48+
}
49+
=== /node_modules/@emotion/react/jsx-runtime/index.d.ts ===
50+
export { EmotionJSX as JSX } from './jsx-namespace'
51+
>EmotionJSX : Symbol(EmotionJSX, Decl(jsx-namespace.d.ts, 13, 54))
52+
>JSX : Symbol(JSX, Decl(index.d.ts, 0, 8))
53+
54+
=== /node_modules/@emotion/react/jsx-runtime/jsx-namespace.d.ts ===
55+
import 'react'
56+
57+
type WithConditionalCSSProp<P> = 'className' extends keyof P
58+
>WithConditionalCSSProp : Symbol(WithConditionalCSSProp, Decl(jsx-namespace.d.ts, 0, 14))
59+
>P : Symbol(P, Decl(jsx-namespace.d.ts, 2, 28))
60+
>P : Symbol(P, Decl(jsx-namespace.d.ts, 2, 28))
61+
62+
? (P extends { className?: string } ? P & { css?: string } : P)
63+
>P : Symbol(P, Decl(jsx-namespace.d.ts, 2, 28))
64+
>className : Symbol(className, Decl(jsx-namespace.d.ts, 3, 16))
65+
>P : Symbol(P, Decl(jsx-namespace.d.ts, 2, 28))
66+
>css : Symbol(css, Decl(jsx-namespace.d.ts, 3, 45))
67+
>P : Symbol(P, Decl(jsx-namespace.d.ts, 2, 28))
68+
69+
: P
70+
>P : Symbol(P, Decl(jsx-namespace.d.ts, 2, 28))
71+
72+
type ReactJSXElement = JSX.Element
73+
>ReactJSXElement : Symbol(ReactJSXElement, Decl(jsx-namespace.d.ts, 4, 5))
74+
>JSX : Symbol(JSX, Decl(index.d.ts, 5, 16))
75+
>Element : Symbol(JSX.Element, Decl(index.d.ts, 6, 17))
76+
77+
type ReactJSXElementClass = JSX.ElementClass
78+
>ReactJSXElementClass : Symbol(ReactJSXElementClass, Decl(jsx-namespace.d.ts, 6, 34))
79+
>JSX : Symbol(JSX, Decl(index.d.ts, 5, 16))
80+
>ElementClass : Symbol(JSX.ElementClass, Decl(index.d.ts, 7, 24))
81+
82+
type ReactJSXElementAttributesProperty = JSX.ElementAttributesProperty
83+
>ReactJSXElementAttributesProperty : Symbol(ReactJSXElementAttributesProperty, Decl(jsx-namespace.d.ts, 7, 44))
84+
>JSX : Symbol(JSX, Decl(index.d.ts, 5, 16))
85+
>ElementAttributesProperty : Symbol(JSX.ElementAttributesProperty, Decl(index.d.ts, 8, 29))
86+
87+
type ReactJSXElementChildrenAttribute = JSX.ElementChildrenAttribute
88+
>ReactJSXElementChildrenAttribute : Symbol(ReactJSXElementChildrenAttribute, Decl(jsx-namespace.d.ts, 8, 70))
89+
>JSX : Symbol(JSX, Decl(index.d.ts, 5, 16))
90+
>ElementChildrenAttribute : Symbol(JSX.ElementChildrenAttribute, Decl(index.d.ts, 9, 42))
91+
92+
type ReactJSXLibraryManagedAttributes<C, P> = JSX.LibraryManagedAttributes<C, P>
93+
>ReactJSXLibraryManagedAttributes : Symbol(ReactJSXLibraryManagedAttributes, Decl(jsx-namespace.d.ts, 9, 68))
94+
>C : Symbol(C, Decl(jsx-namespace.d.ts, 10, 38))
95+
>P : Symbol(P, Decl(jsx-namespace.d.ts, 10, 40))
96+
>JSX : Symbol(JSX, Decl(index.d.ts, 5, 16))
97+
>LibraryManagedAttributes : Symbol(JSX.LibraryManagedAttributes, Decl(index.d.ts, 10, 41))
98+
>C : Symbol(C, Decl(jsx-namespace.d.ts, 10, 38))
99+
>P : Symbol(P, Decl(jsx-namespace.d.ts, 10, 40))
100+
101+
type ReactJSXIntrinsicAttributes = JSX.IntrinsicAttributes
102+
>ReactJSXIntrinsicAttributes : Symbol(ReactJSXIntrinsicAttributes, Decl(jsx-namespace.d.ts, 10, 80))
103+
>JSX : Symbol(JSX, Decl(index.d.ts, 5, 16))
104+
>IntrinsicAttributes : Symbol(JSX.IntrinsicAttributes, Decl(index.d.ts, 11, 44))
105+
106+
type ReactJSXIntrinsicClassAttributes<T> = JSX.IntrinsicClassAttributes<T>
107+
>ReactJSXIntrinsicClassAttributes : Symbol(ReactJSXIntrinsicClassAttributes, Decl(jsx-namespace.d.ts, 11, 58))
108+
>T : Symbol(T, Decl(jsx-namespace.d.ts, 12, 38))
109+
>JSX : Symbol(JSX, Decl(index.d.ts, 5, 16))
110+
>IntrinsicClassAttributes : Symbol(JSX.IntrinsicClassAttributes, Decl(index.d.ts, 12, 36))
111+
>T : Symbol(T, Decl(jsx-namespace.d.ts, 12, 38))
112+
113+
type ReactJSXIntrinsicElements = JSX.IntrinsicElements
114+
>ReactJSXIntrinsicElements : Symbol(ReactJSXIntrinsicElements, Decl(jsx-namespace.d.ts, 12, 74))
115+
>JSX : Symbol(JSX, Decl(index.d.ts, 5, 16))
116+
>IntrinsicElements : Symbol(JSX.IntrinsicElements, Decl(index.d.ts, 13, 44))
117+
118+
export namespace EmotionJSX {
119+
>EmotionJSX : Symbol(EmotionJSX, Decl(jsx-namespace.d.ts, 13, 54))
120+
121+
interface Element extends ReactJSXElement {}
122+
>Element : Symbol(Element, Decl(jsx-namespace.d.ts, 15, 29))
123+
>ReactJSXElement : Symbol(ReactJSXElement, Decl(jsx-namespace.d.ts, 4, 5))
124+
125+
interface ElementClass extends ReactJSXElementClass {}
126+
>ElementClass : Symbol(ElementClass, Decl(jsx-namespace.d.ts, 16, 46))
127+
>ReactJSXElementClass : Symbol(ReactJSXElementClass, Decl(jsx-namespace.d.ts, 6, 34))
128+
129+
interface ElementAttributesProperty
130+
>ElementAttributesProperty : Symbol(ElementAttributesProperty, Decl(jsx-namespace.d.ts, 17, 56))
131+
132+
extends ReactJSXElementAttributesProperty {}
133+
>ReactJSXElementAttributesProperty : Symbol(ReactJSXElementAttributesProperty, Decl(jsx-namespace.d.ts, 7, 44))
134+
135+
interface ElementChildrenAttribute extends ReactJSXElementChildrenAttribute {}
136+
>ElementChildrenAttribute : Symbol(ElementChildrenAttribute, Decl(jsx-namespace.d.ts, 19, 48))
137+
>ReactJSXElementChildrenAttribute : Symbol(ReactJSXElementChildrenAttribute, Decl(jsx-namespace.d.ts, 8, 70))
138+
139+
type LibraryManagedAttributes<C, P> = WithConditionalCSSProp<P> &
140+
>LibraryManagedAttributes : Symbol(LibraryManagedAttributes, Decl(jsx-namespace.d.ts, 20, 80))
141+
>C : Symbol(C, Decl(jsx-namespace.d.ts, 22, 32))
142+
>P : Symbol(P, Decl(jsx-namespace.d.ts, 22, 34))
143+
>WithConditionalCSSProp : Symbol(WithConditionalCSSProp, Decl(jsx-namespace.d.ts, 0, 14))
144+
>P : Symbol(P, Decl(jsx-namespace.d.ts, 22, 34))
145+
146+
ReactJSXLibraryManagedAttributes<C, P>
147+
>ReactJSXLibraryManagedAttributes : Symbol(ReactJSXLibraryManagedAttributes, Decl(jsx-namespace.d.ts, 9, 68))
148+
>C : Symbol(C, Decl(jsx-namespace.d.ts, 22, 32))
149+
>P : Symbol(P, Decl(jsx-namespace.d.ts, 22, 34))
150+
151+
interface IntrinsicAttributes extends ReactJSXIntrinsicAttributes {}
152+
>IntrinsicAttributes : Symbol(IntrinsicAttributes, Decl(jsx-namespace.d.ts, 23, 42))
153+
>ReactJSXIntrinsicAttributes : Symbol(ReactJSXIntrinsicAttributes, Decl(jsx-namespace.d.ts, 10, 80))
154+
155+
interface IntrinsicClassAttributes<T>
156+
>IntrinsicClassAttributes : Symbol(IntrinsicClassAttributes, Decl(jsx-namespace.d.ts, 25, 70))
157+
>T : Symbol(T, Decl(jsx-namespace.d.ts, 26, 37))
158+
159+
extends ReactJSXIntrinsicClassAttributes<T> {}
160+
>ReactJSXIntrinsicClassAttributes : Symbol(ReactJSXIntrinsicClassAttributes, Decl(jsx-namespace.d.ts, 11, 58))
161+
>T : Symbol(T, Decl(jsx-namespace.d.ts, 26, 37))
162+
163+
type IntrinsicElements = {
164+
>IntrinsicElements : Symbol(IntrinsicElements, Decl(jsx-namespace.d.ts, 27, 50))
165+
166+
[K in keyof ReactJSXIntrinsicElements]: ReactJSXIntrinsicElements[K] & {
167+
>K : Symbol(K, Decl(jsx-namespace.d.ts, 30, 5))
168+
>ReactJSXIntrinsicElements : Symbol(ReactJSXIntrinsicElements, Decl(jsx-namespace.d.ts, 12, 74))
169+
>ReactJSXIntrinsicElements : Symbol(ReactJSXIntrinsicElements, Decl(jsx-namespace.d.ts, 12, 74))
170+
>K : Symbol(K, Decl(jsx-namespace.d.ts, 30, 5))
171+
172+
css?: string
173+
>css : Symbol(css, Decl(jsx-namespace.d.ts, 30, 76))
174+
}
175+
}
176+
}
177+
178+
=== /index.tsx ===
179+
export const Comp = () => <div css="color: hotpink;"></div>;
180+
>Comp : Symbol(Comp, Decl(index.tsx, 0, 12))
181+
>div : Symbol(div, Decl(index.d.ts, 14, 33))
182+
>css : Symbol(css, Decl(index.tsx, 0, 30))
183+
>div : Symbol(div, Decl(index.d.ts, 14, 33))
184+

0 commit comments

Comments
 (0)