mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
fix(48657): allow JSXElement names to be IdentifierNames (#48661)
This commit is contained in:
parent
a027cfa8ac
commit
73c93eec5c
@ -3112,7 +3112,10 @@ namespace ts {
|
||||
return (parent as BindingElement | ImportSpecifier).propertyName === node;
|
||||
case SyntaxKind.ExportSpecifier:
|
||||
case SyntaxKind.JsxAttribute:
|
||||
// Any name in an export specifier or JSX Attribute
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
case SyntaxKind.JsxOpeningElement:
|
||||
case SyntaxKind.JsxClosingElement:
|
||||
// Any name in an export specifier or JSX Attribute or Jsx Element
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
25
tests/baselines/reference/jsxElementsAsIdentifierNames.js
Normal file
25
tests/baselines/reference/jsxElementsAsIdentifierNames.js
Normal file
@ -0,0 +1,25 @@
|
||||
//// [a.tsx]
|
||||
declare const React: any;
|
||||
declare module JSX {
|
||||
interface IntrinsicElements {
|
||||
["package"]: any;
|
||||
}
|
||||
}
|
||||
|
||||
function A() {
|
||||
return <package />
|
||||
}
|
||||
|
||||
function B() {
|
||||
return <package></package>
|
||||
}
|
||||
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
function A() {
|
||||
return React.createElement("package", null);
|
||||
}
|
||||
function B() {
|
||||
return React.createElement("package", null);
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
=== tests/cases/compiler/a.tsx ===
|
||||
declare const React: any;
|
||||
>React : Symbol(React, Decl(a.tsx, 0, 13))
|
||||
|
||||
declare module JSX {
|
||||
>JSX : Symbol(JSX, Decl(a.tsx, 0, 25))
|
||||
|
||||
interface IntrinsicElements {
|
||||
>IntrinsicElements : Symbol(IntrinsicElements, Decl(a.tsx, 1, 20))
|
||||
|
||||
["package"]: any;
|
||||
>["package"] : Symbol(IntrinsicElements["package"], Decl(a.tsx, 2, 33))
|
||||
>"package" : Symbol(IntrinsicElements["package"], Decl(a.tsx, 2, 33))
|
||||
}
|
||||
}
|
||||
|
||||
function A() {
|
||||
>A : Symbol(A, Decl(a.tsx, 5, 1))
|
||||
|
||||
return <package />
|
||||
>package : Symbol(JSX.IntrinsicElements["package"], Decl(a.tsx, 2, 33))
|
||||
}
|
||||
|
||||
function B() {
|
||||
>B : Symbol(B, Decl(a.tsx, 9, 1))
|
||||
|
||||
return <package></package>
|
||||
>package : Symbol(JSX.IntrinsicElements["package"], Decl(a.tsx, 2, 33))
|
||||
>package : Symbol(JSX.IntrinsicElements["package"], Decl(a.tsx, 2, 33))
|
||||
}
|
||||
|
||||
29
tests/baselines/reference/jsxElementsAsIdentifierNames.types
Normal file
29
tests/baselines/reference/jsxElementsAsIdentifierNames.types
Normal file
@ -0,0 +1,29 @@
|
||||
=== tests/cases/compiler/a.tsx ===
|
||||
declare const React: any;
|
||||
>React : any
|
||||
|
||||
declare module JSX {
|
||||
interface IntrinsicElements {
|
||||
["package"]: any;
|
||||
>["package"] : any
|
||||
>"package" : "package"
|
||||
}
|
||||
}
|
||||
|
||||
function A() {
|
||||
>A : () => any
|
||||
|
||||
return <package />
|
||||
><package /> : error
|
||||
>package : any
|
||||
}
|
||||
|
||||
function B() {
|
||||
>B : () => any
|
||||
|
||||
return <package></package>
|
||||
><package></package> : error
|
||||
>package : any
|
||||
>package : any
|
||||
}
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
tests/cases/conformance/jsx/a.tsx(13,4): error TS1212: Identifier expected. 'public' is a reserved word in strict mode.
|
||||
tests/cases/conformance/jsx/a.tsx(13,13): error TS1212: Identifier expected. 'public' is a reserved word in strict mode.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsx/a.tsx (2 errors) ====
|
||||
declare const React: any
|
||||
declare namespace JSX {
|
||||
interface IntrinsicElements {
|
||||
[k: string]: any
|
||||
}
|
||||
}
|
||||
|
||||
const a = (
|
||||
<public-foo></public-foo>
|
||||
);
|
||||
|
||||
const b = (
|
||||
<public></public>
|
||||
~~~~~~
|
||||
!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode.
|
||||
~~~~~~
|
||||
!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode.
|
||||
);
|
||||
|
||||
@ -10,22 +10,22 @@ declare namespace JSX {
|
||||
}
|
||||
|
||||
const a = (
|
||||
>a : any
|
||||
>( <public-foo></public-foo>) : any
|
||||
>a : error
|
||||
>( <public-foo></public-foo>) : error
|
||||
|
||||
<public-foo></public-foo>
|
||||
><public-foo></public-foo> : any
|
||||
><public-foo></public-foo> : error
|
||||
>public-foo : any
|
||||
>public-foo : any
|
||||
|
||||
);
|
||||
|
||||
const b = (
|
||||
>b : any
|
||||
>( <public></public>) : any
|
||||
>b : error
|
||||
>( <public></public>) : error
|
||||
|
||||
<public></public>
|
||||
><public></public> : any
|
||||
><public></public> : error
|
||||
>public : any
|
||||
>public : any
|
||||
|
||||
|
||||
18
tests/cases/compiler/jsxElementsAsIdentifierNames.tsx
Normal file
18
tests/cases/compiler/jsxElementsAsIdentifierNames.tsx
Normal file
@ -0,0 +1,18 @@
|
||||
// @strict: true
|
||||
// @jsx: react
|
||||
// @filename: a.tsx
|
||||
|
||||
declare const React: any;
|
||||
declare module JSX {
|
||||
interface IntrinsicElements {
|
||||
["package"]: any;
|
||||
}
|
||||
}
|
||||
|
||||
function A() {
|
||||
return <package />
|
||||
}
|
||||
|
||||
function B() {
|
||||
return <package></package>
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user