diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 08a70b437a9..0e0b9a53b5d 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -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. diff --git a/tests/baselines/reference/jsxParsingErrorImmediateSpreadInAttributeValue.errors.txt b/tests/baselines/reference/jsxParsingErrorImmediateSpreadInAttributeValue.errors.txt new file mode 100644 index 00000000000..8e78c781dc7 --- /dev/null +++ b/tests/baselines/reference/jsxParsingErrorImmediateSpreadInAttributeValue.errors.txt @@ -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 + + + ~~~ +!!! error TS1109: Expression expected. + ~ +!!! error TS1003: Identifier expected. + \ No newline at end of file diff --git a/tests/baselines/reference/jsxParsingErrorImmediateSpreadInAttributeValue.js b/tests/baselines/reference/jsxParsingErrorImmediateSpreadInAttributeValue.js new file mode 100644 index 00000000000..8fa436d2428 --- /dev/null +++ b/tests/baselines/reference/jsxParsingErrorImmediateSpreadInAttributeValue.js @@ -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 + + + + +//// [a.js] +var X; +var a; +React.createElement(X, { a: , a: true }); diff --git a/tests/baselines/reference/jsxParsingErrorImmediateSpreadInAttributeValue.symbols b/tests/baselines/reference/jsxParsingErrorImmediateSpreadInAttributeValue.symbols new file mode 100644 index 00000000000..106dcdfee1f --- /dev/null +++ b/tests/baselines/reference/jsxParsingErrorImmediateSpreadInAttributeValue.symbols @@ -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 : 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)) + diff --git a/tests/baselines/reference/jsxParsingErrorImmediateSpreadInAttributeValue.types b/tests/baselines/reference/jsxParsingErrorImmediateSpreadInAttributeValue.types new file mode 100644 index 00000000000..fded984f46a --- /dev/null +++ b/tests/baselines/reference/jsxParsingErrorImmediateSpreadInAttributeValue.types @@ -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 + + +> : any +>X : any +>a : any +> : any +>a : any + diff --git a/tests/cases/conformance/jsx/jsxParsingErrorImmediateSpreadInAttributeValue.tsx b/tests/cases/conformance/jsx/jsxParsingErrorImmediateSpreadInAttributeValue.tsx new file mode 100644 index 00000000000..cccc5ff03c7 --- /dev/null +++ b/tests/cases/conformance/jsx/jsxParsingErrorImmediateSpreadInAttributeValue.tsx @@ -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 + +