For <div a= >, after =, do not try to parse an expression (#21373)

This commit is contained in:
Andy 2018-03-05 14:38:55 -08:00 committed by GitHub
parent f41555ce89
commit 4ddf045d6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 80 additions and 58 deletions

View file

@ -4125,7 +4125,7 @@ namespace ts {
case SyntaxKind.JsxTextAllWhiteSpaces:
return parseJsxText();
case SyntaxKind.OpenBraceToken:
return parseJsxExpression(/*inExpressionContext*/ false);
return parseJsxExpression(/*inExpressionContext*/ false)!;
case SyntaxKind.LessThanToken:
return parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ false);
}
@ -4236,10 +4236,13 @@ namespace ts {
return expression;
}
function parseJsxExpression(inExpressionContext: boolean): JsxExpression {
function parseJsxExpression(inExpressionContext: boolean): JsxExpression | undefined {
const node = <JsxExpression>createNode(SyntaxKind.JsxExpression);
parseExpected(SyntaxKind.OpenBraceToken);
if (!parseExpected(SyntaxKind.OpenBraceToken)) {
return undefined;
}
if (token() !== SyntaxKind.CloseBraceToken) {
node.dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken);
node.expression = parseAssignmentExpressionOrHigher();

View file

@ -0,0 +1,9 @@
tests/cases/compiler/jsxAttributeMissingInitializer.tsx(1,21): error TS1005: '{' expected.
==== tests/cases/compiler/jsxAttributeMissingInitializer.tsx (1 errors) ====
const x = <div foo= ></div>;
~
!!! error TS1005: '{' expected.
const y = 0;

View file

@ -0,0 +1,8 @@
//// [jsxAttributeMissingInitializer.tsx]
const x = <div foo= ></div>;
const y = 0;
//// [jsxAttributeMissingInitializer.jsx]
var x = <div foo></div>;
var y = 0;

View file

@ -0,0 +1,8 @@
=== tests/cases/compiler/jsxAttributeMissingInitializer.tsx ===
const x = <div foo= ></div>;
>x : Symbol(x, Decl(jsxAttributeMissingInitializer.tsx, 0, 5))
>foo : Symbol(foo, Decl(jsxAttributeMissingInitializer.tsx, 0, 14))
const y = 0;
>y : Symbol(y, Decl(jsxAttributeMissingInitializer.tsx, 1, 5))

View file

@ -0,0 +1,12 @@
=== tests/cases/compiler/jsxAttributeMissingInitializer.tsx ===
const x = <div foo= ></div>;
>x : any
><div foo= ></div> : any
>div : any
>foo : true
>div : any
const y = 0;
>y : 0
>0 : 0

View file

@ -1,14 +1,12 @@
tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,1): error TS2695: Left side of comma operator is unused and has no side effects.
tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,17): error TS1005: '{' expected.
tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,23): error TS1005: '}' expected.
tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,29): error TS1005: '{' expected.
tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,23): error TS2304: Cannot find name 'right'.
tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,23): error TS2657: JSX expressions must have one parent element.
tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,57): error TS1109: Expression expected.
tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(39,58): error TS1109: Expression expected.
tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(41,1): error TS1003: Identifier expected.
tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(41,12): error TS2657: JSX expressions must have one parent element.
==== tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx (8 errors) ====
==== tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx (6 errors) ====
declare var React: any;
declare var 日本語;
declare var AbC_def;
@ -48,24 +46,20 @@ tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(41,12): error TS2657: JSX
<div><br />7x invalid-js-identifier</div>;
<LeftRight left=<a /> right=<b>monkeys /> gorillas</b> />;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~
!!! error TS2695: Left side of comma operator is unused and has no side effects.
~
!!! error TS1005: '{' expected.
~~~~~
!!! error TS1005: '}' expected.
~
!!! error TS1005: '{' expected.
!!! error TS2304: Cannot find name 'right'.
~~~~~
!!! error TS2657: JSX expressions must have one parent element.
~
!!! error TS1109: Expression expected.
~
!!! error TS1109: Expression expected.
<a.b></a.b>;
~
!!! error TS1003: Identifier expected.
~
!!! error TS2657: JSX expressions must have one parent element.
<a.b.c></a.b.c>;

View file

@ -71,9 +71,9 @@ baz
<a></a>;
<div>@test content</div>;
<div><br />7x invalid-js-identifier</div>;
<LeftRight left={<a />} right={<b>monkeys /> gorillas</b> / > }/>
,
<a.b></a.b>;
<LeftRight left/>, <a />;
right = <b>monkeys /> gorillas</b> / > ;
<a.b></a.b>;
<a.b.c></a.b.c>;
(<div />) < x;
<div {...props}/>;

View file

@ -71,7 +71,6 @@ baz
<LeftRight left=<a /> right=<b>monkeys /> gorillas</b> />;
>LeftRight : Symbol(LeftRight, Decl(jsxEsprimaFbTestSuite.tsx, 3, 11))
>left : Symbol(left, Decl(jsxEsprimaFbTestSuite.tsx, 38, 10))
>right : Symbol(right, Decl(jsxEsprimaFbTestSuite.tsx, 38, 21))
<a.b></a.b>;
>a : Symbol(a, Decl(jsxEsprimaFbTestSuite.tsx, 5, 11))

View file

@ -102,13 +102,14 @@ baz
>div : any
<LeftRight left=<a /> right=<b>monkeys /> gorillas</b> />;
><LeftRight left=<a /> right=<b>monkeys /> gorillas</b> />;<a.b></a.b> : any
><LeftRight left=<a /> right=<b>monkeys /> gorillas</b> />; : any
><LeftRight left=<a /> : any
><LeftRight left= : any
>LeftRight : any
>left : any
>left : true
><a /> : any
>a : any
>right : boolean
>right=<b>monkeys /> gorillas</b> /> : boolean
>right : any
><b>monkeys /> gorillas</b> /> : boolean
><b>monkeys /> gorillas</b> / : number
><b>monkeys /> gorillas</b> : any

View file

@ -58,9 +58,9 @@ tests/cases/conformance/jsx/25.tsx(1,39): error TS1109: Expression expected.
tests/cases/conformance/jsx/28.tsx(1,2): error TS17008: JSX element 'a' has no corresponding closing tag.
tests/cases/conformance/jsx/28.tsx(1,6): error TS1005: '{' expected.
tests/cases/conformance/jsx/28.tsx(2,1): error TS1005: '</' expected.
tests/cases/conformance/jsx/29.tsx(1,2): error TS17008: JSX element 'a' has no corresponding closing tag.
tests/cases/conformance/jsx/29.tsx(1,1): error TS2695: Left side of comma operator is unused and has no side effects.
tests/cases/conformance/jsx/29.tsx(1,6): error TS1005: '{' expected.
tests/cases/conformance/jsx/29.tsx(1,7): error TS1109: Expression expected.
tests/cases/conformance/jsx/29.tsx(1,7): error TS1003: Identifier expected.
tests/cases/conformance/jsx/29.tsx(2,1): error TS1005: '</' expected.
tests/cases/conformance/jsx/3.tsx(1,1): error TS1109: Expression expected.
tests/cases/conformance/jsx/3.tsx(1,2): error TS1109: Expression expected.
@ -69,10 +69,6 @@ tests/cases/conformance/jsx/3.tsx(1,6): error TS1109: Expression expected.
tests/cases/conformance/jsx/3.tsx(1,7): error TS1109: Expression expected.
tests/cases/conformance/jsx/31.tsx(1,4): error TS1003: Identifier expected.
tests/cases/conformance/jsx/4.tsx(1,6): error TS1005: '{' expected.
tests/cases/conformance/jsx/4.tsx(1,6): error TS2304: Cannot find name 'd'.
tests/cases/conformance/jsx/4.tsx(1,9): error TS1109: Expression expected.
tests/cases/conformance/jsx/4.tsx(1,10): error TS1109: Expression expected.
tests/cases/conformance/jsx/4.tsx(1,11): error TS1005: '/' expected.
tests/cases/conformance/jsx/5.tsx(1,2): error TS17008: JSX element 'a' has no corresponding closing tag.
tests/cases/conformance/jsx/5.tsx(1,5): error TS1005: '</' expected.
tests/cases/conformance/jsx/6.tsx(1,4): error TS17002: Expected corresponding JSX closing tag for 'a'.
@ -112,18 +108,10 @@ tests/cases/conformance/jsx/9.tsx(1,16): error TS1109: Expression expected.
!!! error TS1109: Expression expected.
~
!!! error TS1109: Expression expected.
==== tests/cases/conformance/jsx/4.tsx (5 errors) ====
==== tests/cases/conformance/jsx/4.tsx (1 errors) ====
<a b=d />;
~
!!! error TS1005: '{' expected.
~
!!! error TS2304: Cannot find name 'd'.
~
!!! error TS1109: Expression expected.
~
!!! error TS1109: Expression expected.
!!! error TS1005: '/' expected.
==== tests/cases/conformance/jsx/5.tsx (2 errors) ====
<a>;
~
@ -315,12 +303,12 @@ tests/cases/conformance/jsx/9.tsx(1,16): error TS1109: Expression expected.
!!! error TS1005: '</' expected.
==== tests/cases/conformance/jsx/29.tsx (4 errors) ====
<a b=<}>;
~
!!! error TS17008: JSX element 'a' has no corresponding closing tag.
~~~~~
!!! error TS2695: Left side of comma operator is unused and has no side effects.
~
!!! error TS1005: '{' expected.
~
!!! error TS1109: Expression expected.
!!! error TS1003: Identifier expected.
!!! error TS1005: '</' expected.

View file

@ -82,7 +82,7 @@ var x = <div>one</div> /* intervening comment */ <div>two</div>;;
< ;
a / > ;
//// [4.jsx]
<a b={d / > }/>;
<a b d/>;
//// [5.jsx]
<a>;</>;
//// [6.jsx]
@ -148,10 +148,10 @@ var x = <div>one</div> /* intervening comment */, /* intervening comment */ <div
//// [27.jsx]
<a> ></a>;
//// [28.jsx]
<a b=>;
<a b>;
</>;
//// [29.jsx]
<a b={ < }>;
<a b/>, <>;
</>;
//// [30.jsx]
<a>}</a>;

View file

@ -10,6 +10,7 @@ No type information for this code.=== tests/cases/conformance/jsx/3.tsx ===
No type information for this code.=== tests/cases/conformance/jsx/4.tsx ===
<a b=d />;
>b : Symbol(b, Decl(4.tsx, 0, 2))
>d : Symbol(d, Decl(4.tsx, 0, 5))
=== tests/cases/conformance/jsx/5.tsx ===
<a>;

View file

@ -25,14 +25,10 @@ declare var React: any;
=== tests/cases/conformance/jsx/4.tsx ===
<a b=d />;
><a b=d />; : any
><a b=d /> : any
>a : any
>b : boolean
>d /> : boolean
>d / : number
>d : any
> : any
> : any
>b : true
>d : true
=== tests/cases/conformance/jsx/5.tsx ===
<a>;
@ -251,17 +247,17 @@ var x = <div>one</div> /* intervening comment */ <div>two</div>;;
<a b=}>;
><a b=}>; : any
>a : any
>b : any
>b : true
> : any
=== tests/cases/conformance/jsx/29.tsx ===
<a b=<}>;
><a b=<}>; : any
><a b= : any
>a : any
>b : boolean
>< : boolean
> : any
>b : true
><}>; : any
> : any
> : any

View file

@ -0,0 +1,3 @@
// @jsx: preserve
const x = <div foo= ></div>;
const y = 0;

View file

@ -12,12 +12,12 @@ verify.completionListContains("x", "(parameter) x: number", "", "parameter", und
insertText: "{x}",
});
verify.completionListContains("p", "(property) p: number", "", "property", undefined, undefined, {
verify.completionListContains("p", "(JSX attribute) p: number", "", "JSX attribute", undefined, undefined, {
includeInsertTextCompletions: true,
insertText: "{this.p}",
});
verify.completionListContains("a b", '(property) "a b": number', "", "property", undefined, undefined, {
verify.completionListContains("a b", '(JSX attribute) "a b": number', "", "JSX attribute", undefined, undefined, {
includeInsertTextCompletions: true,
insertText: '{this["a b"]}',
});