Skip to content

fix(46512): JSX cannot use tag names that start with "public-" #46546

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
Nov 2, 2021
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
1 change: 1 addition & 0 deletions src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2374,6 +2374,7 @@ namespace ts {
tokenValue = tokenValue.slice(0, -1);
pos--;
}
return getIdentifierToken();
}
return token;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/baselines/reference/jsxParsingError4(strict=false).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//// [a.tsx]
declare const React: any
declare namespace JSX {
interface IntrinsicElements {
[k: string]: any
}
}

const a = (
<public-foo></public-foo>
);

const b = (
<public></public>
);


//// [a.js]
var a = (React.createElement("public-foo", null));
var b = (React.createElement("public", null));
33 changes: 33 additions & 0 deletions tests/baselines/reference/jsxParsingError4(strict=false).symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
=== tests/cases/conformance/jsx/a.tsx ===
declare const React: any
>React : Symbol(React, Decl(a.tsx, 0, 13))

declare namespace JSX {
>JSX : Symbol(JSX, Decl(a.tsx, 0, 24))

interface IntrinsicElements {
>IntrinsicElements : Symbol(IntrinsicElements, Decl(a.tsx, 1, 23))

[k: string]: any
>k : Symbol(k, Decl(a.tsx, 3, 9))
}
}

const a = (
>a : Symbol(a, Decl(a.tsx, 7, 5))

<public-foo></public-foo>
>public-foo : Symbol(JSX.IntrinsicElements, Decl(a.tsx, 1, 23))
>public-foo : Symbol(JSX.IntrinsicElements, Decl(a.tsx, 1, 23))

);

const b = (
>b : Symbol(b, Decl(a.tsx, 11, 5))

<public></public>
>public : Symbol(JSX.IntrinsicElements, Decl(a.tsx, 1, 23))
>public : Symbol(JSX.IntrinsicElements, Decl(a.tsx, 1, 23))

);

33 changes: 33 additions & 0 deletions tests/baselines/reference/jsxParsingError4(strict=false).types
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
=== tests/cases/conformance/jsx/a.tsx ===
declare const React: any
>React : any

declare namespace JSX {
interface IntrinsicElements {
[k: string]: any
>k : string
}
}

const a = (
>a : error
>( <public-foo></public-foo>) : error

<public-foo></public-foo>
><public-foo></public-foo> : error
>public-foo : any
>public-foo : any

);

const b = (
>b : error
>( <public></public>) : error

<public></public>
><public></public> : error
>public : any
>public : any

);

24 changes: 24 additions & 0 deletions tests/baselines/reference/jsxParsingError4(strict=true).errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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.
);

21 changes: 21 additions & 0 deletions tests/baselines/reference/jsxParsingError4(strict=true).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//// [a.tsx]
declare const React: any
declare namespace JSX {
interface IntrinsicElements {
[k: string]: any
}
}

const a = (
<public-foo></public-foo>
);

const b = (
<public></public>
);


//// [a.js]
"use strict";
var a = (React.createElement("public-foo", null));
var b = (React.createElement("public", null));
33 changes: 33 additions & 0 deletions tests/baselines/reference/jsxParsingError4(strict=true).symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
=== tests/cases/conformance/jsx/a.tsx ===
declare const React: any
>React : Symbol(React, Decl(a.tsx, 0, 13))

declare namespace JSX {
>JSX : Symbol(JSX, Decl(a.tsx, 0, 24))

interface IntrinsicElements {
>IntrinsicElements : Symbol(IntrinsicElements, Decl(a.tsx, 1, 23))

[k: string]: any
>k : Symbol(k, Decl(a.tsx, 3, 9))
}
}

const a = (
>a : Symbol(a, Decl(a.tsx, 7, 5))

<public-foo></public-foo>
>public-foo : Symbol(JSX.IntrinsicElements, Decl(a.tsx, 1, 23))
>public-foo : Symbol(JSX.IntrinsicElements, Decl(a.tsx, 1, 23))

);

const b = (
>b : Symbol(b, Decl(a.tsx, 11, 5))

<public></public>
>public : Symbol(JSX.IntrinsicElements, Decl(a.tsx, 1, 23))
>public : Symbol(JSX.IntrinsicElements, Decl(a.tsx, 1, 23))

);

33 changes: 33 additions & 0 deletions tests/baselines/reference/jsxParsingError4(strict=true).types
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
=== tests/cases/conformance/jsx/a.tsx ===
declare const React: any
>React : any

declare namespace JSX {
interface IntrinsicElements {
[k: string]: any
>k : string
}
}

const a = (
>a : any
>( <public-foo></public-foo>) : any

<public-foo></public-foo>
><public-foo></public-foo> : any
>public-foo : any
>public-foo : any

);

const b = (
>b : any
>( <public></public>) : any

<public></public>
><public></public> : any
>public : any
>public : any

);

18 changes: 18 additions & 0 deletions tests/cases/conformance/jsx/jsxParsingError4.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @strict: true, false
// @jsx: react
// @filename: a.tsx

declare const React: any
declare namespace JSX {
interface IntrinsicElements {
[k: string]: any
}
}

const a = (
<public-foo></public-foo>
);

const b = (
<public></public>
);