Skip to content

fix(48657): Using reserved words as intrinsic elements in TSX #48661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions tests/baselines/reference/jsxElementsAsIdentifierNames.js
Original file line number Diff line number Diff line change
@@ -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);
}
31 changes: 31 additions & 0 deletions tests/baselines/reference/jsxElementsAsIdentifierNames.symbols
Original file line number Diff line number Diff line change
@@ -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 changes: 29 additions & 0 deletions tests/baselines/reference/jsxElementsAsIdentifierNames.types
Original file line number Diff line number Diff line change
@@ -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
}

24 changes: 0 additions & 24 deletions tests/baselines/reference/jsxParsingError4(strict=true).errors.txt

This file was deleted.

12 changes: 6 additions & 6 deletions tests/baselines/reference/jsxParsingError4(strict=true).types
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions tests/cases/compiler/jsxElementsAsIdentifierNames.tsx
Original file line number Diff line number Diff line change
@@ -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>
}