Skip to content
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
19 changes: 15 additions & 4 deletions tsc/internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5147,10 +5147,10 @@ func (p *Parser) parseJsxTagName() *ast.Expression {
pos := p.nodePos()
p.scanJsxIdentifier()
isThis := p.token == ast.KindThisKeyword
tagName := p.parseIdentifierNameErrorOnUnicodeEscapeSequence()
tagName := p.parseJsxIdentifierName()
if p.parseOptional(ast.KindColonToken) {
p.scanJsxIdentifier()
return p.finishNode(p.factory.NewJsxNamespacedName(tagName, p.parseIdentifierNameErrorOnUnicodeEscapeSequence()), pos)
return p.finishNode(p.factory.NewJsxNamespacedName(tagName, p.parseJsxIdentifierName()), pos)
}
if isThis {
result := p.factory.NewKeywordExpression(ast.KindThisKeyword)
Expand All @@ -5159,6 +5159,17 @@ func (p *Parser) parseJsxTagName() *ast.Expression {
return tagName
}

func (p *Parser) parseJsxIdentifierName() *ast.Node {
if p.token == ast.KindPrivateIdentifier {
// '#' is not a valid JSX identifier character. Consume the private identifier and produce a missing
// identifier, as parseRightSideOfDot does for `<a.#b />`.
p.parseErrorAtCurrentToken(diagnostics.Identifier_expected)
p.nextToken()
return p.createMissingIdentifier()
}
return p.parseIdentifierNameErrorOnUnicodeEscapeSequence()
}

func (p *Parser) parseJsxAttributes() *ast.Node {
pos := p.nodePos()
return p.finishNode(p.factory.NewJsxAttributes(p.parseList(PCJsxAttributes, (*Parser).parseJsxAttribute)), pos)
Expand All @@ -5184,10 +5195,10 @@ func (p *Parser) parseJsxSpreadAttribute() *ast.Node {
func (p *Parser) parseJsxAttributeName() *ast.Node {
pos := p.nodePos()
p.scanJsxIdentifier()
attrName := p.parseIdentifierNameErrorOnUnicodeEscapeSequence()
attrName := p.parseJsxIdentifierName()
if p.parseOptional(ast.KindColonToken) {
p.scanJsxIdentifier()
return p.finishNode(p.factory.NewJsxNamespacedName(attrName, p.parseIdentifierNameErrorOnUnicodeEscapeSequence()), pos)
return p.finishNode(p.factory.NewJsxNamespacedName(attrName, p.parseJsxIdentifierName()), pos)
}
return attrName
}
Expand Down
3 changes: 2 additions & 1 deletion tsc/internal/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,8 @@ func (s *Scanner) ScanJsxTokenEx(allowMultilineJsxText bool) ast.Kind {

// Scans a JSX identifier; these differ from normal identifiers in that they allow dashes
func (s *Scanner) ScanJsxIdentifier() ast.Kind {
if tokenIsIdentifierOrKeyword(s.token) {
// '#' is not a valid JSX identifier character, so a private identifier is left for the parser to report.
if s.token != ast.KindPrivateIdentifier && tokenIsIdentifierOrKeyword(s.token) {
Comment thread
RyanCavanaugh marked this conversation as resolved.
Resolved
// An identifier or keyword has already been parsed - check for a `-` or a single instance of `:` and then append it and
// everything after it to the token
// Do note that this means that `scanJsxIdentifier` effectively _mutates_ the visible token without advancing to a new token
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
jsxNamesStartingWithHash.tsx(8,12): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(8,17): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(9,16): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(10,16): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(11,16): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(12,14): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(13,16): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(14,12): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(15,18): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(16,16): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(16,19): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(17,12): error TS1127: Invalid character.


==== jsxNamesStartingWithHash.tsx (12 errors) ====
declare const React: any;
declare namespace JSX {
interface IntrinsicElements {
[name: string]: any;
}
}

const a = <#a></#a>;
~~
!!! error TS1003: Identifier expected.
~~
!!! error TS1003: Identifier expected.
const b = <div #b />;
~~
!!! error TS1003: Identifier expected.
const c = <div #c="" />;
~~
!!! error TS1003: Identifier expected.
const d = <div #d:e />;
~~
!!! error TS1003: Identifier expected.
const e = <a:#f />;
~~
!!! error TS1003: Identifier expected.
const f = <a.#g />;

!!! error TS1003: Identifier expected.
const g = <#h:i />;
~~
!!! error TS1003: Identifier expected.
const h = <div j:#k />;
~~
!!! error TS1003: Identifier expected.
const i = <div #l #m="" n="" />;
~~
!!! error TS1003: Identifier expected.
~~
!!! error TS1003: Identifier expected.
const j = <# />;
~
!!! error TS1127: Invalid character.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//// [tests/cases/compiler/jsxNamesStartingWithHash.tsx] ////

//// [jsxNamesStartingWithHash.tsx]
declare const React: any;
declare namespace JSX {
interface IntrinsicElements {
[name: string]: any;
}
}

const a = <#a></#a>;
const b = <div #b />;
const c = <div #c="" />;
const d = <div #d:e />;
const e = <a:#f />;
const f = <a.#g />;
const g = <#h:i />;
const h = <div j:#k />;
const i = <div #l #m="" n="" />;
const j = <# />;


//// [jsxNamesStartingWithHash.jsx]
"use strict";
const a = <></>;
const b = <div />;
const c = <div =""/>;
const d = <div :e/>;
const e = <a: />;
const f = <a. />;
const g = <:i />;
const h = <div j:/>;
const i = <div ="" n=""/>;
const j = < />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//// [tests/cases/compiler/jsxNamesStartingWithHash.tsx] ////

=== jsxNamesStartingWithHash.tsx ===
declare const React: any;
>React : Symbol(React, Decl(jsxNamesStartingWithHash.tsx, 0, 13))

declare namespace JSX {
>JSX : Symbol(JSX, Decl(jsxNamesStartingWithHash.tsx, 0, 25))

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

[name: string]: any;
>name : Symbol(name, Decl(jsxNamesStartingWithHash.tsx, 3, 9))
}
}

const a = <#a></#a>;
>a : Symbol(a, Decl(jsxNamesStartingWithHash.tsx, 7, 5))

const b = <div #b />;
>b : Symbol(b, Decl(jsxNamesStartingWithHash.tsx, 8, 5))
>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxNamesStartingWithHash.tsx, 2, 33))
> : Symbol((Missing), Decl(jsxNamesStartingWithHash.tsx, 8, 14))

const c = <div #c="" />;
>c : Symbol(c, Decl(jsxNamesStartingWithHash.tsx, 9, 5))
>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxNamesStartingWithHash.tsx, 2, 33))
> : Symbol((Missing), Decl(jsxNamesStartingWithHash.tsx, 9, 14))

const d = <div #d:e />;
>d : Symbol(d, Decl(jsxNamesStartingWithHash.tsx, 10, 5))
>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxNamesStartingWithHash.tsx, 2, 33))
>#d:e : Symbol(#d:e, Decl(jsxNamesStartingWithHash.tsx, 10, 14))

const e = <a:#f />;
>e : Symbol(e, Decl(jsxNamesStartingWithHash.tsx, 11, 5))

const f = <a.#g />;
>f : Symbol(f, Decl(jsxNamesStartingWithHash.tsx, 12, 5))
>a : Symbol(a, Decl(jsxNamesStartingWithHash.tsx, 7, 5))

const g = <#h:i />;
>g : Symbol(g, Decl(jsxNamesStartingWithHash.tsx, 13, 5))

const h = <div j:#k />;
>h : Symbol(h, Decl(jsxNamesStartingWithHash.tsx, 14, 5))
>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxNamesStartingWithHash.tsx, 2, 33))
>j:#k : Symbol(j:#k, Decl(jsxNamesStartingWithHash.tsx, 14, 14))

const i = <div #l #m="" n="" />;
>i : Symbol(i, Decl(jsxNamesStartingWithHash.tsx, 15, 5))
>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxNamesStartingWithHash.tsx, 2, 33))
> : Symbol((Missing), Decl(jsxNamesStartingWithHash.tsx, 15, 14), Decl(jsxNamesStartingWithHash.tsx, 15, 17))
> : Symbol((Missing), Decl(jsxNamesStartingWithHash.tsx, 15, 14), Decl(jsxNamesStartingWithHash.tsx, 15, 17))
>n : Symbol(n, Decl(jsxNamesStartingWithHash.tsx, 15, 23))

const j = <# />;
>j : Symbol(j, Decl(jsxNamesStartingWithHash.tsx, 16, 5))

Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//// [tests/cases/compiler/jsxNamesStartingWithHash.tsx] ////

=== jsxNamesStartingWithHash.tsx ===
declare const React: any;
>React : any

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

const a = <#a></#a>;
>a : any
><#a></#a> : any
> : any
> : any

const b = <div #b />;
>b : any
><div #b /> : any
>div : any
> : true

const c = <div #c="" />;
>c : any
><div #c="" /> : any
>div : any
> : string

const d = <div #d:e />;
>d : any
><div #d:e /> : any
>div : any
>#d:e : true
> : any
>e : any

const e = <a:#f />;
>e : any
><a:#f /> : any
>a : any
> : any

const f = <a.#g />;
>f : any
><a.#g /> : any
>a.#g : any
>a : any
> : any

const g = <#h:i />;
>g : any
><#h:i /> : any
> : any
>i : any

const h = <div j:#k />;
>h : any
><div j:#k /> : any
>div : any
>j:#k : true
>j : any
> : any

const i = <div #l #m="" n="" />;
>i : any
><div #l #m="" n="" /> : any
>div : any
> : true
> : true
>n : string

const j = <# />;
>j : any
><# /> : any
> : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
jsxNamesStartingWithHash.tsx(8,12): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(8,17): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(9,16): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(10,16): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(11,16): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(12,14): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(13,16): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(14,12): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(15,18): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(16,16): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(16,19): error TS1003: Identifier expected.
jsxNamesStartingWithHash.tsx(17,12): error TS1127: Invalid character.


==== jsxNamesStartingWithHash.tsx (12 errors) ====
declare const React: any;
declare namespace JSX {
interface IntrinsicElements {
[name: string]: any;
}
}

const a = <#a></#a>;
~~
!!! error TS1003: Identifier expected.
~~
!!! error TS1003: Identifier expected.
const b = <div #b />;
~~
!!! error TS1003: Identifier expected.
const c = <div #c="" />;
~~
!!! error TS1003: Identifier expected.
const d = <div #d:e />;
~~
!!! error TS1003: Identifier expected.
const e = <a:#f />;
~~
!!! error TS1003: Identifier expected.
const f = <a.#g />;

!!! error TS1003: Identifier expected.
const g = <#h:i />;
~~
!!! error TS1003: Identifier expected.
const h = <div j:#k />;
~~
!!! error TS1003: Identifier expected.
const i = <div #l #m="" n="" />;
~~
!!! error TS1003: Identifier expected.
~~
!!! error TS1003: Identifier expected.
const j = <# />;
~
!!! error TS1127: Invalid character.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//// [tests/cases/compiler/jsxNamesStartingWithHash.tsx] ////

//// [jsxNamesStartingWithHash.tsx]
declare const React: any;
declare namespace JSX {
interface IntrinsicElements {
[name: string]: any;
}
}

const a = <#a></#a>;
const b = <div #b />;
const c = <div #c="" />;
const d = <div #d:e />;
const e = <a:#f />;
const f = <a.#g />;
const g = <#h:i />;
const h = <div j:#k />;
const i = <div #l #m="" n="" />;
const j = <# />;


//// [jsxNamesStartingWithHash.js]
"use strict";
const a = React.createElement(, null);
const b = React.createElement("div", { "": true });
const c = React.createElement("div", { "": "" });
const d = React.createElement("div", { ":e": true });
const e = React.createElement("a:", null);
const f = React.createElement(a., null);
const g = React.createElement(":i", null);
const h = React.createElement("div", { "j:": true });
const i = React.createElement("div", { "": true, "": "", n: "" });
const j = React.createElement(, null);
Loading
Loading