Skip to content

Commit 73c93ee

Browse files
authored
fix(48657): allow JSXElement names to be IdentifierNames (microsoft#48661)
1 parent a027cfa commit 73c93ee

7 files changed

+113
-31
lines changed

Diff for: src/compiler/utilities.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -3112,7 +3112,10 @@ namespace ts {
31123112
return (parent as BindingElement | ImportSpecifier).propertyName === node;
31133113
case SyntaxKind.ExportSpecifier:
31143114
case SyntaxKind.JsxAttribute:
3115-
// Any name in an export specifier or JSX Attribute
3115+
case SyntaxKind.JsxSelfClosingElement:
3116+
case SyntaxKind.JsxOpeningElement:
3117+
case SyntaxKind.JsxClosingElement:
3118+
// Any name in an export specifier or JSX Attribute or Jsx Element
31163119
return true;
31173120
}
31183121
return false;
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [a.tsx]
2+
declare const React: any;
3+
declare module JSX {
4+
interface IntrinsicElements {
5+
["package"]: any;
6+
}
7+
}
8+
9+
function A() {
10+
return <package />
11+
}
12+
13+
function B() {
14+
return <package></package>
15+
}
16+
17+
18+
//// [a.js]
19+
"use strict";
20+
function A() {
21+
return React.createElement("package", null);
22+
}
23+
function B() {
24+
return React.createElement("package", null);
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
=== tests/cases/compiler/a.tsx ===
2+
declare const React: any;
3+
>React : Symbol(React, Decl(a.tsx, 0, 13))
4+
5+
declare module JSX {
6+
>JSX : Symbol(JSX, Decl(a.tsx, 0, 25))
7+
8+
interface IntrinsicElements {
9+
>IntrinsicElements : Symbol(IntrinsicElements, Decl(a.tsx, 1, 20))
10+
11+
["package"]: any;
12+
>["package"] : Symbol(IntrinsicElements["package"], Decl(a.tsx, 2, 33))
13+
>"package" : Symbol(IntrinsicElements["package"], Decl(a.tsx, 2, 33))
14+
}
15+
}
16+
17+
function A() {
18+
>A : Symbol(A, Decl(a.tsx, 5, 1))
19+
20+
return <package />
21+
>package : Symbol(JSX.IntrinsicElements["package"], Decl(a.tsx, 2, 33))
22+
}
23+
24+
function B() {
25+
>B : Symbol(B, Decl(a.tsx, 9, 1))
26+
27+
return <package></package>
28+
>package : Symbol(JSX.IntrinsicElements["package"], Decl(a.tsx, 2, 33))
29+
>package : Symbol(JSX.IntrinsicElements["package"], Decl(a.tsx, 2, 33))
30+
}
31+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/compiler/a.tsx ===
2+
declare const React: any;
3+
>React : any
4+
5+
declare module JSX {
6+
interface IntrinsicElements {
7+
["package"]: any;
8+
>["package"] : any
9+
>"package" : "package"
10+
}
11+
}
12+
13+
function A() {
14+
>A : () => any
15+
16+
return <package />
17+
><package /> : error
18+
>package : any
19+
}
20+
21+
function B() {
22+
>B : () => any
23+
24+
return <package></package>
25+
><package></package> : error
26+
>package : any
27+
>package : any
28+
}
29+

Diff for: tests/baselines/reference/jsxParsingError4(strict=true).errors.txt

-24
This file was deleted.

Diff for: tests/baselines/reference/jsxParsingError4(strict=true).types

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ declare namespace JSX {
1010
}
1111

1212
const a = (
13-
>a : any
14-
>( <public-foo></public-foo>) : any
13+
>a : error
14+
>( <public-foo></public-foo>) : error
1515

1616
<public-foo></public-foo>
17-
><public-foo></public-foo> : any
17+
><public-foo></public-foo> : error
1818
>public-foo : any
1919
>public-foo : any
2020

2121
);
2222

2323
const b = (
24-
>b : any
25-
>( <public></public>) : any
24+
>b : error
25+
>( <public></public>) : error
2626

2727
<public></public>
28-
><public></public> : any
28+
><public></public> : error
2929
>public : any
3030
>public : any
3131

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// @strict: true
2+
// @jsx: react
3+
// @filename: a.tsx
4+
5+
declare const React: any;
6+
declare module JSX {
7+
interface IntrinsicElements {
8+
["package"]: any;
9+
}
10+
}
11+
12+
function A() {
13+
return <package />
14+
}
15+
16+
function B() {
17+
return <package></package>
18+
}

0 commit comments

Comments
 (0)