Skip to content

Commit 5edf8c0

Browse files
committed
Always consider jsx names with colon to be intrinsics
1 parent 6292eaa commit 5edf8c0

16 files changed

+76
-118
lines changed

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3810,7 +3810,7 @@ namespace ts {
38103810

38113811
export function isIntrinsicJsxName(name: __String | string) {
38123812
const ch = (name as string).charCodeAt(0);
3813-
return (ch >= CharacterCodes.a && ch <= CharacterCodes.z) || stringContains((name as string), "-");
3813+
return (ch >= CharacterCodes.a && ch <= CharacterCodes.z) || stringContains((name as string), "-") || stringContains((name as string), ":");
38143814
}
38153815

38163816
const indentStrings: string[] = ["", " "];

tests/baselines/reference/jsxNamespacePrefixInName.errors.txt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ tests/cases/compiler/jsxNamespacePrefixInName.tsx(24,38): error TS1005: ':' expe
2727
tests/cases/compiler/jsxNamespacePrefixInName.tsx(24,41): error TS1109: Expression expected.
2828
tests/cases/compiler/jsxNamespacePrefixInName.tsx(24,42): error TS1109: Expression expected.
2929
tests/cases/compiler/jsxNamespacePrefixInName.tsx(25,24): error TS1003: Identifier expected.
30-
tests/cases/compiler/jsxNamespacePrefixInName.tsx(29,25): error TS2304: Cannot find name 'Upcase:element'.
31-
tests/cases/compiler/jsxNamespacePrefixInName.tsx(31,34): error TS2304: Cannot find name 'NS:something'.
3230

3331

34-
==== tests/cases/compiler/jsxNamespacePrefixInName.tsx (31 errors) ====
32+
==== tests/cases/compiler/jsxNamespacePrefixInName.tsx (29 errors) ====
3533
var justElement1 = <a:element />;
3634
var justElement2 = <a:element></a:element>;
3735
var justElement3 = <a:element attr={"value"}></a:element>;
@@ -116,13 +114,6 @@ tests/cases/compiler/jsxNamespacePrefixInName.tsx(31,34): error TS2304: Cannot f
116114
~
117115
!!! error TS1003: Identifier expected.
118116

119-
var Upcase = "mycomponent"
120-
var upcaseComponent1 = <ns:Upcase /> // Parsed as intrinsic: ok
121-
var upcaseComponent2 = <Upcase:element /> // Parsed as component: not ok
122-
~~~~~~~~~~~~~~
123-
!!! error TS2304: Cannot find name 'Upcase:element'.
124-
125-
var upcaseComponentUndeclared = <NS:something />
126-
~~~~~~~~~~~~
127-
!!! error TS2304: Cannot find name 'NS:something'.
117+
var upcaseComponent1 = <ns:Upcase />; // Parsed as intrinsic
118+
var upcaseComponent2 = <Upcase:element />; // Parsed as instrinsic
128119

tests/baselines/reference/jsxNamespacePrefixInName.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@ var endOfIdent2 = <a attr:={"value"} />;
2525
var beginOfIdent1 = <:a attr={"value"} />;
2626
var beginOfIdent1 = <a :attr={"value"} />;
2727

28-
var Upcase = "mycomponent"
29-
var upcaseComponent1 = <ns:Upcase /> // Parsed as intrinsic: ok
30-
var upcaseComponent2 = <Upcase:element /> // Parsed as component: not ok
31-
32-
var upcaseComponentUndeclared = <NS:something />
28+
var upcaseComponent1 = <ns:Upcase />; // Parsed as intrinsic
29+
var upcaseComponent2 = <Upcase:element />; // Parsed as instrinsic
3330

3431

3532
//// [jsxNamespacePrefixInName.jsx]
@@ -57,7 +54,5 @@ var endOfIdent1 = <a attr={"value"}/>;
5754
var endOfIdent2 = <a attr {..."value"}/>;
5855
var beginOfIdent1 = < , a, attr = { "value": } / > ;
5956
var beginOfIdent1 = <a attr={"value"}/>;
60-
var Upcase = "mycomponent";
61-
var upcaseComponent1 = <ns:Upcase />; // Parsed as intrinsic: ok
62-
var upcaseComponent2 = <Upcase:element />; // Parsed as component: not ok
63-
var upcaseComponentUndeclared = <NS:something />;
57+
var upcaseComponent1 = <ns:Upcase />; // Parsed as intrinsic
58+
var upcaseComponent2 = <Upcase:element />; // Parsed as instrinsic

tests/baselines/reference/jsxNamespacePrefixInName.symbols

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,9 @@ var beginOfIdent1 = <a :attr={"value"} />;
8484
>beginOfIdent1 : Symbol(beginOfIdent1, Decl(jsxNamespacePrefixInName.tsx, 23, 3), Decl(jsxNamespacePrefixInName.tsx, 24, 3))
8585
>attr : Symbol(attr, Decl(jsxNamespacePrefixInName.tsx, 24, 24))
8686

87-
var Upcase = "mycomponent"
88-
>Upcase : Symbol(Upcase, Decl(jsxNamespacePrefixInName.tsx, 26, 3))
87+
var upcaseComponent1 = <ns:Upcase />; // Parsed as intrinsic
88+
>upcaseComponent1 : Symbol(upcaseComponent1, Decl(jsxNamespacePrefixInName.tsx, 26, 3))
8989

90-
var upcaseComponent1 = <ns:Upcase /> // Parsed as intrinsic: ok
91-
>upcaseComponent1 : Symbol(upcaseComponent1, Decl(jsxNamespacePrefixInName.tsx, 27, 3))
92-
93-
var upcaseComponent2 = <Upcase:element /> // Parsed as component: not ok
94-
>upcaseComponent2 : Symbol(upcaseComponent2, Decl(jsxNamespacePrefixInName.tsx, 28, 3))
95-
96-
var upcaseComponentUndeclared = <NS:something />
97-
>upcaseComponentUndeclared : Symbol(upcaseComponentUndeclared, Decl(jsxNamespacePrefixInName.tsx, 30, 3))
90+
var upcaseComponent2 = <Upcase:element />; // Parsed as instrinsic
91+
>upcaseComponent2 : Symbol(upcaseComponent2, Decl(jsxNamespacePrefixInName.tsx, 27, 3))
9892

tests/baselines/reference/jsxNamespacePrefixInName.types

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,22 +174,13 @@ var beginOfIdent1 = <a :attr={"value"} />;
174174
>attr : string
175175
>"value" : "value"
176176

177-
var Upcase = "mycomponent"
178-
>Upcase : string
179-
>"mycomponent" : "mycomponent"
180-
181-
var upcaseComponent1 = <ns:Upcase /> // Parsed as intrinsic: ok
177+
var upcaseComponent1 = <ns:Upcase />; // Parsed as intrinsic
182178
>upcaseComponent1 : any
183179
><ns:Upcase /> : any
184180
>ns:Upcase : any
185181

186-
var upcaseComponent2 = <Upcase:element /> // Parsed as component: not ok
182+
var upcaseComponent2 = <Upcase:element />; // Parsed as instrinsic
187183
>upcaseComponent2 : any
188184
><Upcase:element /> : any
189185
>Upcase:element : any
190186

191-
var upcaseComponentUndeclared = <NS:something />
192-
>upcaseComponentUndeclared : any
193-
><NS:something /> : any
194-
>NS:something : any
195-

tests/baselines/reference/jsxNamespacePrefixInNameReact.errors.txt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ tests/cases/compiler/jsxNamespacePrefixInNameReact.tsx(26,38): error TS1005: ':'
2727
tests/cases/compiler/jsxNamespacePrefixInNameReact.tsx(26,41): error TS1109: Expression expected.
2828
tests/cases/compiler/jsxNamespacePrefixInNameReact.tsx(26,42): error TS1109: Expression expected.
2929
tests/cases/compiler/jsxNamespacePrefixInNameReact.tsx(27,24): error TS1003: Identifier expected.
30-
tests/cases/compiler/jsxNamespacePrefixInNameReact.tsx(31,25): error TS2304: Cannot find name 'Upcase:element'.
31-
tests/cases/compiler/jsxNamespacePrefixInNameReact.tsx(33,34): error TS2304: Cannot find name 'NS:something'.
3230

3331

34-
==== tests/cases/compiler/jsxNamespacePrefixInNameReact.tsx (31 errors) ====
32+
==== tests/cases/compiler/jsxNamespacePrefixInNameReact.tsx (29 errors) ====
3533
declare var React: any;
3634

3735
var justElement1 = <a:element />;
@@ -118,13 +116,6 @@ tests/cases/compiler/jsxNamespacePrefixInNameReact.tsx(33,34): error TS2304: Can
118116
~
119117
!!! error TS1003: Identifier expected.
120118

121-
var Upcase = "mycomponent"
122-
var upcaseComponent1 = <ns:Upcase /> // Parsed as intrinsic: ok
123-
var upcaseComponent2 = <Upcase:element /> // Parsed as component: not ok
124-
~~~~~~~~~~~~~~
125-
!!! error TS2304: Cannot find name 'Upcase:element'.
126-
127-
var upcaseComponentUndeclared = <NS:something />
128-
~~~~~~~~~~~~
129-
!!! error TS2304: Cannot find name 'NS:something'.
119+
var upcaseComponent1 = <ns:Upcase />; // Parsed as intrinsic
120+
var upcaseComponent2 = <Upcase:element />; // Parsed as instrinsic
130121

tests/baselines/reference/jsxNamespacePrefixInNameReact.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,8 @@ var endOfIdent2 = <a attr:={"value"} />;
2727
var beginOfIdent1 = <:a attr={"value"} />;
2828
var beginOfIdent1 = <a :attr={"value"} />;
2929

30-
var Upcase = "mycomponent"
31-
var upcaseComponent1 = <ns:Upcase /> // Parsed as intrinsic: ok
32-
var upcaseComponent2 = <Upcase:element /> // Parsed as component: not ok
33-
34-
var upcaseComponentUndeclared = <NS:something />
30+
var upcaseComponent1 = <ns:Upcase />; // Parsed as intrinsic
31+
var upcaseComponent2 = <Upcase:element />; // Parsed as instrinsic
3532

3633

3734
//// [jsxNamespacePrefixInNameReact.js]
@@ -70,7 +67,5 @@ var endOfIdent1 = React.createElement("a", { attr: "value" });
7067
var endOfIdent2 = React.createElement("a", __assign({ attr: true }, "value"));
7168
var beginOfIdent1 = < , a, attr = { "value": } / > ;
7269
var beginOfIdent1 = React.createElement("a", { attr: "value" });
73-
var Upcase = "mycomponent";
74-
var upcaseComponent1 = React.createElement("ns:Upcase", null); // Parsed as intrinsic: ok
75-
var upcaseComponent2 = React.createElement(Upcase:element, null); // Parsed as component: not ok
76-
var upcaseComponentUndeclared = React.createElement(NS:something, null);
70+
var upcaseComponent1 = React.createElement("ns:Upcase", null); // Parsed as intrinsic
71+
var upcaseComponent2 = React.createElement("Upcase:element", null); // Parsed as instrinsic

tests/baselines/reference/jsxNamespacePrefixInNameReact.symbols

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,9 @@ var beginOfIdent1 = <a :attr={"value"} />;
8787
>beginOfIdent1 : Symbol(beginOfIdent1, Decl(jsxNamespacePrefixInNameReact.tsx, 25, 3), Decl(jsxNamespacePrefixInNameReact.tsx, 26, 3))
8888
>attr : Symbol(attr, Decl(jsxNamespacePrefixInNameReact.tsx, 26, 24))
8989

90-
var Upcase = "mycomponent"
91-
>Upcase : Symbol(Upcase, Decl(jsxNamespacePrefixInNameReact.tsx, 28, 3))
90+
var upcaseComponent1 = <ns:Upcase />; // Parsed as intrinsic
91+
>upcaseComponent1 : Symbol(upcaseComponent1, Decl(jsxNamespacePrefixInNameReact.tsx, 28, 3))
9292

93-
var upcaseComponent1 = <ns:Upcase /> // Parsed as intrinsic: ok
94-
>upcaseComponent1 : Symbol(upcaseComponent1, Decl(jsxNamespacePrefixInNameReact.tsx, 29, 3))
95-
96-
var upcaseComponent2 = <Upcase:element /> // Parsed as component: not ok
97-
>upcaseComponent2 : Symbol(upcaseComponent2, Decl(jsxNamespacePrefixInNameReact.tsx, 30, 3))
98-
99-
var upcaseComponentUndeclared = <NS:something />
100-
>upcaseComponentUndeclared : Symbol(upcaseComponentUndeclared, Decl(jsxNamespacePrefixInNameReact.tsx, 32, 3))
93+
var upcaseComponent2 = <Upcase:element />; // Parsed as instrinsic
94+
>upcaseComponent2 : Symbol(upcaseComponent2, Decl(jsxNamespacePrefixInNameReact.tsx, 29, 3))
10195

tests/baselines/reference/jsxNamespacePrefixInNameReact.types

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,22 +177,13 @@ var beginOfIdent1 = <a :attr={"value"} />;
177177
>attr : string
178178
>"value" : "value"
179179

180-
var Upcase = "mycomponent"
181-
>Upcase : string
182-
>"mycomponent" : "mycomponent"
183-
184-
var upcaseComponent1 = <ns:Upcase /> // Parsed as intrinsic: ok
180+
var upcaseComponent1 = <ns:Upcase />; // Parsed as intrinsic
185181
>upcaseComponent1 : any
186182
><ns:Upcase /> : any
187183
>ns:Upcase : any
188184

189-
var upcaseComponent2 = <Upcase:element /> // Parsed as component: not ok
185+
var upcaseComponent2 = <Upcase:element />; // Parsed as instrinsic
190186
>upcaseComponent2 : any
191187
><Upcase:element /> : any
192188
>Upcase:element : any
193189

194-
var upcaseComponentUndeclared = <NS:something />
195-
>upcaseComponentUndeclared : any
196-
><NS:something /> : any
197-
>NS:something : any
198-

tests/baselines/reference/jsxNamespacePrefixIntrinsics.errors.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
tests/cases/compiler/jsxNamespacePrefixIntrinsics.tsx(13,18): error TS2339: Property 'element' does not exist on type 'JSX.IntrinsicElements'.
2-
tests/cases/compiler/jsxNamespacePrefixIntrinsics.tsx(14,30): error TS2322: Type '{ attribute: string; }' is not assignable to type '{ "ns:attribute": string; }'.
1+
tests/cases/compiler/jsxNamespacePrefixIntrinsics.tsx(15,18): error TS2339: Property 'element' does not exist on type 'JSX.IntrinsicElements'.
2+
tests/cases/compiler/jsxNamespacePrefixIntrinsics.tsx(16,30): error TS2322: Type '{ attribute: string; }' is not assignable to type '{ "ns:attribute": string; }'.
33
Property 'attribute' does not exist on type '{ "ns:attribute": string; }'.
4-
tests/cases/compiler/jsxNamespacePrefixIntrinsics.tsx(15,30): error TS2322: Type '{ "ns:invalid": string; }' is not assignable to type '{ "ns:attribute": string; }'.
4+
tests/cases/compiler/jsxNamespacePrefixIntrinsics.tsx(17,30): error TS2322: Type '{ "ns:invalid": string; }' is not assignable to type '{ "ns:attribute": string; }'.
55
Property 'ns:invalid' does not exist on type '{ "ns:attribute": string; }'.
66

77

@@ -11,12 +11,14 @@ tests/cases/compiler/jsxNamespacePrefixIntrinsics.tsx(15,30): error TS2322: Type
1111
"ns:element": {
1212
"ns:attribute": string;
1313
},
14-
"ns:NamespacedUpcaseAlsoIntrinsic": any
14+
"ns:NamespacedUpcaseAlsoIntrinsic": any,
15+
"NS:NamespacedUpcaseAlsoIntrinsic": any
1516
}
1617
}
1718

1819
const valid = <ns:element ns:attribute="yep" />;
19-
const validUpcase = <ns:NamespacedUpcaseAlsoIntrinsic />;
20+
const validUpcase1 = <ns:NamespacedUpcaseAlsoIntrinsic />;
21+
const validUpcase2 = <NS:NamespacedUpcaseAlsoIntrinsic />;
2022

2123
const invalid1 = <element />;
2224
~~~~~~~~~~~

0 commit comments

Comments
 (0)