mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Don't parse DotDotDotToken in JSX attribute values (#55284)
This commit is contained in:
@@ -6214,7 +6214,9 @@ namespace Parser {
|
||||
let dotDotDotToken: DotDotDotToken | undefined;
|
||||
let expression: Expression | undefined;
|
||||
if (token() !== SyntaxKind.CloseBraceToken) {
|
||||
dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken);
|
||||
if (!inExpressionContext) {
|
||||
dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken);
|
||||
}
|
||||
// Only an AssignmentExpression is valid here per the JSX spec,
|
||||
// but we can unambiguously parse a comma sequence and provide
|
||||
// a better error message in grammar checking.
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
a.tsx(11,7): error TS1109: Expression expected.
|
||||
a.tsx(11,11): error TS1003: Identifier expected.
|
||||
|
||||
|
||||
==== a.tsx (2 errors) ====
|
||||
declare const React: any
|
||||
declare namespace JSX {
|
||||
interface IntrinsicElements {
|
||||
[k: string]: any
|
||||
}
|
||||
}
|
||||
|
||||
const X: any
|
||||
const a: any
|
||||
|
||||
<X a={...a} />
|
||||
~~~
|
||||
!!! error TS1109: Expression expected.
|
||||
~
|
||||
!!! error TS1003: Identifier expected.
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
//// [tests/cases/conformance/jsx/jsxParsingErrorImmediateSpreadInAttributeValue.tsx] ////
|
||||
|
||||
//// [a.tsx]
|
||||
declare const React: any
|
||||
declare namespace JSX {
|
||||
interface IntrinsicElements {
|
||||
[k: string]: any
|
||||
}
|
||||
}
|
||||
|
||||
const X: any
|
||||
const a: any
|
||||
|
||||
<X a={...a} />
|
||||
|
||||
|
||||
//// [a.js]
|
||||
var X;
|
||||
var a;
|
||||
React.createElement(X, { a: , a: true });
|
||||
@@ -0,0 +1,28 @@
|
||||
//// [tests/cases/conformance/jsx/jsxParsingErrorImmediateSpreadInAttributeValue.tsx] ////
|
||||
|
||||
=== 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 X: any
|
||||
>X : Symbol(X, Decl(a.tsx, 7, 5))
|
||||
|
||||
const a: any
|
||||
>a : Symbol(a, Decl(a.tsx, 8, 5))
|
||||
|
||||
<X a={...a} />
|
||||
>X : Symbol(X, Decl(a.tsx, 7, 5))
|
||||
>a : Symbol(a, Decl(a.tsx, 10, 2), Decl(a.tsx, 10, 9))
|
||||
>a : Symbol(a, Decl(a.tsx, 10, 2), Decl(a.tsx, 10, 9))
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
//// [tests/cases/conformance/jsx/jsxParsingErrorImmediateSpreadInAttributeValue.tsx] ////
|
||||
|
||||
=== a.tsx ===
|
||||
declare const React: any
|
||||
>React : any
|
||||
|
||||
declare namespace JSX {
|
||||
interface IntrinsicElements {
|
||||
[k: string]: any
|
||||
>k : string
|
||||
}
|
||||
}
|
||||
|
||||
const X: any
|
||||
>X : any
|
||||
|
||||
const a: any
|
||||
>a : any
|
||||
|
||||
<X a={...a} />
|
||||
><X a={...a} /> : any
|
||||
>X : any
|
||||
>a : any
|
||||
> : any
|
||||
>a : any
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// @jsx: react
|
||||
// @filename: a.tsx
|
||||
|
||||
declare const React: any
|
||||
declare namespace JSX {
|
||||
interface IntrinsicElements {
|
||||
[k: string]: any
|
||||
}
|
||||
}
|
||||
|
||||
const X: any
|
||||
const a: any
|
||||
|
||||
<X a={...a} />
|
||||
Reference in New Issue
Block a user