From ae39c08c62ae6d12f29c407f1771e10c9219c7a2 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 22 Feb 2022 12:07:55 +0200 Subject: [PATCH] fix(7410): allow using JSXElement as JSXAttributeValue --- src/compiler/diagnosticMessages.json | 4 ++ src/compiler/factory/nodeFactory.ts | 4 +- src/compiler/parser.ts | 26 +++++++----- src/compiler/transformers/jsx.ts | 17 +++++--- src/compiler/types.ts | 13 ++++-- .../reference/api/tsserverlibrary.d.ts | 11 ++--- tests/baselines/reference/api/typescript.d.ts | 11 ++--- ...ributeInitializer(jsx=preserve).errors.txt | 15 +++++++ .../jsxAttributeInitializer(jsx=preserve).js | 18 +++++++++ ...AttributeInitializer(jsx=preserve).symbols | 19 +++++++++ ...sxAttributeInitializer(jsx=preserve).types | 40 +++++++++++++++++++ ...AttributeInitializer(jsx=react).errors.txt | 15 +++++++ .../jsxAttributeInitializer(jsx=react).js | 18 +++++++++ ...jsxAttributeInitializer(jsx=react).symbols | 19 +++++++++ .../jsxAttributeInitializer(jsx=react).types | 40 +++++++++++++++++++ .../jsxAttributeMissingInitializer.errors.txt | 4 +- .../jsxEsprimaFbTestSuite.errors.txt | 20 +--------- .../reference/jsxEsprimaFbTestSuite.js | 3 +- .../reference/jsxEsprimaFbTestSuite.symbols | 1 + .../reference/jsxEsprimaFbTestSuite.types | 10 +---- .../jsxInvalidEsprimaTestSuite.errors.txt | 17 +++----- .../reference/jsxInvalidEsprimaTestSuite.js | 4 +- .../jsxInvalidEsprimaTestSuite.types | 3 +- .../jsx/jsxAttributeInitializer.ts | 10 +++++ 24 files changed, 266 insertions(+), 76 deletions(-) create mode 100644 tests/baselines/reference/jsxAttributeInitializer(jsx=preserve).errors.txt create mode 100644 tests/baselines/reference/jsxAttributeInitializer(jsx=preserve).js create mode 100644 tests/baselines/reference/jsxAttributeInitializer(jsx=preserve).symbols create mode 100644 tests/baselines/reference/jsxAttributeInitializer(jsx=preserve).types create mode 100644 tests/baselines/reference/jsxAttributeInitializer(jsx=react).errors.txt create mode 100644 tests/baselines/reference/jsxAttributeInitializer(jsx=react).js create mode 100644 tests/baselines/reference/jsxAttributeInitializer(jsx=react).symbols create mode 100644 tests/baselines/reference/jsxAttributeInitializer(jsx=react).types create mode 100644 tests/cases/conformance/jsx/jsxAttributeInitializer.ts diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index de7903443b0c1..87656faf60686 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -435,6 +435,10 @@ "category": "Error", "code": 1144 }, + "'{' or JSX element expected.": { + "category": "Error", + "code": 1145 + }, "Declaration expected.": { "category": "Error", "code": 1146 diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index cbddf4fb32447..f36c23e881988 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -4856,7 +4856,7 @@ namespace ts { } // @api - function createJsxAttribute(name: Identifier, initializer: StringLiteral | JsxExpression | undefined) { + function createJsxAttribute(name: Identifier, initializer: JsxAttributeValue | undefined) { const node = createBaseNode(SyntaxKind.JsxAttribute); node.name = name; node.initializer = initializer; @@ -4868,7 +4868,7 @@ namespace ts { } // @api - function updateJsxAttribute(node: JsxAttribute, name: Identifier, initializer: StringLiteral | JsxExpression | undefined) { + function updateJsxAttribute(node: JsxAttribute, name: Identifier, initializer: JsxAttributeValue | undefined) { return node.name !== name || node.initializer !== initializer ? update(createJsxAttribute(name, initializer), node) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index cd7ed6285cb84..7722857e8c5cb 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -5284,15 +5284,23 @@ namespace ts { scanJsxIdentifier(); const pos = getNodePos(); - return finishNode( - factory.createJsxAttribute( - parseIdentifierName(), - token() !== SyntaxKind.EqualsToken ? undefined : - scanJsxAttributeValue() === SyntaxKind.StringLiteral ? parseLiteralNode() as StringLiteral : - parseJsxExpression(/*inExpressionContext*/ true) - ), - pos - ); + return finishNode(factory.createJsxAttribute(parseIdentifierName(), parseJsxAttributeValue()), pos); + } + + function parseJsxAttributeValue(): JsxAttributeValue | undefined { + if (token() === SyntaxKind.EqualsToken) { + if (scanJsxAttributeValue() === SyntaxKind.StringLiteral) { + return parseLiteralNode() as StringLiteral; + } + if (token() === SyntaxKind.OpenBraceToken) { + return parseJsxExpression(/*inExpressionContext*/ true); + } + if (token() === SyntaxKind.LessThanToken) { + return parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true); + } + parseErrorAtCurrentToken(Diagnostics.or_JSX_element_expected); + } + return undefined; } function parseJsxSpreadAttribute(): JsxSpreadAttribute { diff --git a/src/compiler/transformers/jsx.ts b/src/compiler/transformers/jsx.ts index d321e74817bd4..2e6fe4ea1b910 100644 --- a/src/compiler/transformers/jsx.ts +++ b/src/compiler/transformers/jsx.ts @@ -400,26 +400,33 @@ namespace ts { return factory.createPropertyAssignment(name, expression); } - function transformJsxAttributeInitializer(node: StringLiteral | JsxExpression | undefined): Expression { + function transformJsxAttributeInitializer(node: JsxAttributeValue | undefined): Expression { if (node === undefined) { return factory.createTrue(); } - else if (node.kind === SyntaxKind.StringLiteral) { + if (node.kind === SyntaxKind.StringLiteral) { // Always recreate the literal to escape any escape sequences or newlines which may be in the original jsx string and which // Need to be escaped to be handled correctly in a normal string const singleQuote = node.singleQuote !== undefined ? node.singleQuote : !isStringDoubleQuoted(node, currentSourceFile); const literal = factory.createStringLiteral(tryDecodeEntities(node.text) || node.text, singleQuote); return setTextRange(literal, node); } - else if (node.kind === SyntaxKind.JsxExpression) { + if (node.kind === SyntaxKind.JsxExpression) { if (node.expression === undefined) { return factory.createTrue(); } return visitNode(node.expression, visitor, isExpression); } - else { - return Debug.failBadSyntaxKind(node); + if (isJsxElement(node)) { + return visitJsxElement(node, /*isChild*/ false); + } + if (isJsxSelfClosingElement(node)) { + return visitJsxSelfClosingElement(node, /*isChild*/ false); + } + if (isJsxFragment(node)) { + return visitJsxFragment(node, /*isChild*/ false); } + return Debug.failBadSyntaxKind(node); } function visitJsxText(node: JsxText): StringLiteral | undefined { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 54936e787bc7a..465c9572f79c9 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2590,9 +2590,16 @@ namespace ts { readonly parent: JsxAttributes; readonly name: Identifier; /// JSX attribute initializers are optional; is sugar for - readonly initializer?: StringLiteral | JsxExpression; + readonly initializer?: JsxAttributeValue; } + export type JsxAttributeValue = + | StringLiteral + | JsxExpression + | JsxElement + | JsxSelfClosingElement + | JsxFragment; + export interface JsxSpreadAttribute extends ObjectLiteralElement { readonly kind: SyntaxKind.JsxSpreadAttribute; readonly parent: JsxAttributes; @@ -7583,8 +7590,8 @@ namespace ts { createJsxOpeningFragment(): JsxOpeningFragment; createJsxJsxClosingFragment(): JsxClosingFragment; updateJsxFragment(node: JsxFragment, openingFragment: JsxOpeningFragment, children: readonly JsxChild[], closingFragment: JsxClosingFragment): JsxFragment; - createJsxAttribute(name: Identifier, initializer: StringLiteral | JsxExpression | undefined): JsxAttribute; - updateJsxAttribute(node: JsxAttribute, name: Identifier, initializer: StringLiteral | JsxExpression | undefined): JsxAttribute; + createJsxAttribute(name: Identifier, initializer: JsxAttributeValue | undefined): JsxAttribute; + updateJsxAttribute(node: JsxAttribute, name: Identifier, initializer: JsxAttributeValue | undefined): JsxAttribute; createJsxAttributes(properties: readonly JsxAttributeLike[]): JsxAttributes; updateJsxAttributes(node: JsxAttributes, properties: readonly JsxAttributeLike[]): JsxAttributes; createJsxSpreadAttribute(expression: Expression): JsxSpreadAttribute; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 255fb6a1305c7..bf87e6bd3f209 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -1372,8 +1372,9 @@ declare namespace ts { readonly kind: SyntaxKind.JsxAttribute; readonly parent: JsxAttributes; readonly name: Identifier; - readonly initializer?: StringLiteral | JsxExpression; + readonly initializer?: JsxAttributeValue; } + export type JsxAttributeValue = StringLiteral | JsxExpression | JsxElement | JsxSelfClosingElement | JsxFragment; export interface JsxSpreadAttribute extends ObjectLiteralElement { readonly kind: SyntaxKind.JsxSpreadAttribute; readonly parent: JsxAttributes; @@ -3691,8 +3692,8 @@ declare namespace ts { createJsxOpeningFragment(): JsxOpeningFragment; createJsxJsxClosingFragment(): JsxClosingFragment; updateJsxFragment(node: JsxFragment, openingFragment: JsxOpeningFragment, children: readonly JsxChild[], closingFragment: JsxClosingFragment): JsxFragment; - createJsxAttribute(name: Identifier, initializer: StringLiteral | JsxExpression | undefined): JsxAttribute; - updateJsxAttribute(node: JsxAttribute, name: Identifier, initializer: StringLiteral | JsxExpression | undefined): JsxAttribute; + createJsxAttribute(name: Identifier, initializer: JsxAttributeValue | undefined): JsxAttribute; + updateJsxAttribute(node: JsxAttribute, name: Identifier, initializer: JsxAttributeValue | undefined): JsxAttribute; createJsxAttributes(properties: readonly JsxAttributeLike[]): JsxAttributes; updateJsxAttributes(node: JsxAttributes, properties: readonly JsxAttributeLike[]): JsxAttributes; createJsxSpreadAttribute(expression: Expression): JsxSpreadAttribute; @@ -11189,9 +11190,9 @@ declare namespace ts { /** @deprecated Use `factory.updateJsxFragment` or the factory supplied by your transformation context instead. */ const updateJsxFragment: (node: JsxFragment, openingFragment: JsxOpeningFragment, children: readonly JsxChild[], closingFragment: JsxClosingFragment) => JsxFragment; /** @deprecated Use `factory.createJsxAttribute` or the factory supplied by your transformation context instead. */ - const createJsxAttribute: (name: Identifier, initializer: StringLiteral | JsxExpression | undefined) => JsxAttribute; + const createJsxAttribute: (name: Identifier, initializer: JsxAttributeValue | undefined) => JsxAttribute; /** @deprecated Use `factory.updateJsxAttribute` or the factory supplied by your transformation context instead. */ - const updateJsxAttribute: (node: JsxAttribute, name: Identifier, initializer: StringLiteral | JsxExpression | undefined) => JsxAttribute; + const updateJsxAttribute: (node: JsxAttribute, name: Identifier, initializer: JsxAttributeValue | undefined) => JsxAttribute; /** @deprecated Use `factory.createJsxAttributes` or the factory supplied by your transformation context instead. */ const createJsxAttributes: (properties: readonly JsxAttributeLike[]) => JsxAttributes; /** @deprecated Use `factory.updateJsxAttributes` or the factory supplied by your transformation context instead. */ diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 63a6a9bc49be3..ffbab6712d342 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -1372,8 +1372,9 @@ declare namespace ts { readonly kind: SyntaxKind.JsxAttribute; readonly parent: JsxAttributes; readonly name: Identifier; - readonly initializer?: StringLiteral | JsxExpression; + readonly initializer?: JsxAttributeValue; } + export type JsxAttributeValue = StringLiteral | JsxExpression | JsxElement | JsxSelfClosingElement | JsxFragment; export interface JsxSpreadAttribute extends ObjectLiteralElement { readonly kind: SyntaxKind.JsxSpreadAttribute; readonly parent: JsxAttributes; @@ -3691,8 +3692,8 @@ declare namespace ts { createJsxOpeningFragment(): JsxOpeningFragment; createJsxJsxClosingFragment(): JsxClosingFragment; updateJsxFragment(node: JsxFragment, openingFragment: JsxOpeningFragment, children: readonly JsxChild[], closingFragment: JsxClosingFragment): JsxFragment; - createJsxAttribute(name: Identifier, initializer: StringLiteral | JsxExpression | undefined): JsxAttribute; - updateJsxAttribute(node: JsxAttribute, name: Identifier, initializer: StringLiteral | JsxExpression | undefined): JsxAttribute; + createJsxAttribute(name: Identifier, initializer: JsxAttributeValue | undefined): JsxAttribute; + updateJsxAttribute(node: JsxAttribute, name: Identifier, initializer: JsxAttributeValue | undefined): JsxAttribute; createJsxAttributes(properties: readonly JsxAttributeLike[]): JsxAttributes; updateJsxAttributes(node: JsxAttributes, properties: readonly JsxAttributeLike[]): JsxAttributes; createJsxSpreadAttribute(expression: Expression): JsxSpreadAttribute; @@ -7371,9 +7372,9 @@ declare namespace ts { /** @deprecated Use `factory.updateJsxFragment` or the factory supplied by your transformation context instead. */ const updateJsxFragment: (node: JsxFragment, openingFragment: JsxOpeningFragment, children: readonly JsxChild[], closingFragment: JsxClosingFragment) => JsxFragment; /** @deprecated Use `factory.createJsxAttribute` or the factory supplied by your transformation context instead. */ - const createJsxAttribute: (name: Identifier, initializer: StringLiteral | JsxExpression | undefined) => JsxAttribute; + const createJsxAttribute: (name: Identifier, initializer: JsxAttributeValue | undefined) => JsxAttribute; /** @deprecated Use `factory.updateJsxAttribute` or the factory supplied by your transformation context instead. */ - const updateJsxAttribute: (node: JsxAttribute, name: Identifier, initializer: StringLiteral | JsxExpression | undefined) => JsxAttribute; + const updateJsxAttribute: (node: JsxAttribute, name: Identifier, initializer: JsxAttributeValue | undefined) => JsxAttribute; /** @deprecated Use `factory.createJsxAttributes` or the factory supplied by your transformation context instead. */ const createJsxAttributes: (properties: readonly JsxAttributeLike[]) => JsxAttributes; /** @deprecated Use `factory.updateJsxAttributes` or the factory supplied by your transformation context instead. */ diff --git a/tests/baselines/reference/jsxAttributeInitializer(jsx=preserve).errors.txt b/tests/baselines/reference/jsxAttributeInitializer(jsx=preserve).errors.txt new file mode 100644 index 0000000000000..83f39a9ccb49e --- /dev/null +++ b/tests/baselines/reference/jsxAttributeInitializer(jsx=preserve).errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/jsx/a.tsx(7,16): error TS1145: '{' or JSX element expected. + + +==== tests/cases/conformance/jsx/a.tsx (1 errors) ==== + declare var React: any; + +
+
/> +
foo
/> +
foo
/> +
+ ~ +!!! error TS1145: '{' or JSX element expected. +
+ \ No newline at end of file diff --git a/tests/baselines/reference/jsxAttributeInitializer(jsx=preserve).js b/tests/baselines/reference/jsxAttributeInitializer(jsx=preserve).js new file mode 100644 index 0000000000000..3feabccd94e23 --- /dev/null +++ b/tests/baselines/reference/jsxAttributeInitializer(jsx=preserve).js @@ -0,0 +1,18 @@ +//// [a.tsx] +declare var React: any; + +
+
/> +
foo
/> +
foo
/> +
+
+ + +//// [a.jsx] +
+
/> +
foo
/> +
foo
/> +
+
; diff --git a/tests/baselines/reference/jsxAttributeInitializer(jsx=preserve).symbols b/tests/baselines/reference/jsxAttributeInitializer(jsx=preserve).symbols new file mode 100644 index 0000000000000..efabdca743a1a --- /dev/null +++ b/tests/baselines/reference/jsxAttributeInitializer(jsx=preserve).symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/jsx/a.tsx === +declare var React: any; +>React : Symbol(React, Decl(a.tsx, 0, 11)) + +
+
/> +>attr : Symbol(attr, Decl(a.tsx, 3, 8)) + +
foo
/> +>attr : Symbol(attr, Decl(a.tsx, 4, 8)) + +
foo
/> +>attr : Symbol(attr, Decl(a.tsx, 5, 8)) + +
+>attr : Symbol(attr, Decl(a.tsx, 6, 8)) + +
+ diff --git a/tests/baselines/reference/jsxAttributeInitializer(jsx=preserve).types b/tests/baselines/reference/jsxAttributeInitializer(jsx=preserve).types new file mode 100644 index 0000000000000..d401c53b96d93 --- /dev/null +++ b/tests/baselines/reference/jsxAttributeInitializer(jsx=preserve).types @@ -0,0 +1,40 @@ +=== tests/cases/conformance/jsx/a.tsx === +declare var React: any; +>React : any + +
+>
/>
foo
/>
foo
/>
: any +>div : any + +
/> +>
/> : any +>div : any +>attr : any +>
: any +>div : any + +
foo
/> +>
foo
/> : any +>div : any +>attr : any +>
foo
: any +>div : any +>div : any + +
foo
/> +>
foo
/> : any +>div : any +>attr : any +><>
foo
: any +>
foo
: any +>div : any +>div : any + +
+>
: any +>div : any +>attr : true + +
+>div : any + diff --git a/tests/baselines/reference/jsxAttributeInitializer(jsx=react).errors.txt b/tests/baselines/reference/jsxAttributeInitializer(jsx=react).errors.txt new file mode 100644 index 0000000000000..83f39a9ccb49e --- /dev/null +++ b/tests/baselines/reference/jsxAttributeInitializer(jsx=react).errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/jsx/a.tsx(7,16): error TS1145: '{' or JSX element expected. + + +==== tests/cases/conformance/jsx/a.tsx (1 errors) ==== + declare var React: any; + +
+
/> +
foo
/> +
foo
/> +
+ ~ +!!! error TS1145: '{' or JSX element expected. +
+ \ No newline at end of file diff --git a/tests/baselines/reference/jsxAttributeInitializer(jsx=react).js b/tests/baselines/reference/jsxAttributeInitializer(jsx=react).js new file mode 100644 index 0000000000000..2839c345594ba --- /dev/null +++ b/tests/baselines/reference/jsxAttributeInitializer(jsx=react).js @@ -0,0 +1,18 @@ +//// [a.tsx] +declare var React: any; + +
+
/> +
foo
/> +
foo
/> +
+
+ + +//// [a.js] +React.createElement("div", null, + React.createElement("div", { attr: React.createElement("div", null) }), + React.createElement("div", { attr: React.createElement("div", null, "foo") }), + React.createElement("div", { attr: React.createElement(React.Fragment, null, + React.createElement("div", null, "foo")) }), + React.createElement("div", { attr: true })); diff --git a/tests/baselines/reference/jsxAttributeInitializer(jsx=react).symbols b/tests/baselines/reference/jsxAttributeInitializer(jsx=react).symbols new file mode 100644 index 0000000000000..efabdca743a1a --- /dev/null +++ b/tests/baselines/reference/jsxAttributeInitializer(jsx=react).symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/jsx/a.tsx === +declare var React: any; +>React : Symbol(React, Decl(a.tsx, 0, 11)) + +
+
/> +>attr : Symbol(attr, Decl(a.tsx, 3, 8)) + +
foo
/> +>attr : Symbol(attr, Decl(a.tsx, 4, 8)) + +
foo
/> +>attr : Symbol(attr, Decl(a.tsx, 5, 8)) + +
+>attr : Symbol(attr, Decl(a.tsx, 6, 8)) + +
+ diff --git a/tests/baselines/reference/jsxAttributeInitializer(jsx=react).types b/tests/baselines/reference/jsxAttributeInitializer(jsx=react).types new file mode 100644 index 0000000000000..d401c53b96d93 --- /dev/null +++ b/tests/baselines/reference/jsxAttributeInitializer(jsx=react).types @@ -0,0 +1,40 @@ +=== tests/cases/conformance/jsx/a.tsx === +declare var React: any; +>React : any + +
+>
/>
foo
/>
foo
/>
: any +>div : any + +
/> +>
/> : any +>div : any +>attr : any +>
: any +>div : any + +
foo
/> +>
foo
/> : any +>div : any +>attr : any +>
foo
: any +>div : any +>div : any + +
foo
/> +>
foo
/> : any +>div : any +>attr : any +><>
foo
: any +>
foo
: any +>div : any +>div : any + +
+>
: any +>div : any +>attr : true + +
+>div : any + diff --git a/tests/baselines/reference/jsxAttributeMissingInitializer.errors.txt b/tests/baselines/reference/jsxAttributeMissingInitializer.errors.txt index feeaaac525dbb..4f450b08b42be 100644 --- a/tests/baselines/reference/jsxAttributeMissingInitializer.errors.txt +++ b/tests/baselines/reference/jsxAttributeMissingInitializer.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/jsxAttributeMissingInitializer.tsx(1,21): error TS1005: '{' expected. +tests/cases/compiler/jsxAttributeMissingInitializer.tsx(1,21): error TS1145: '{' or JSX element expected. ==== tests/cases/compiler/jsxAttributeMissingInitializer.tsx (1 errors) ==== const x =
; ~ -!!! error TS1005: '{' expected. +!!! error TS1145: '{' or JSX element expected. const y = 0; \ No newline at end of file diff --git a/tests/baselines/reference/jsxEsprimaFbTestSuite.errors.txt b/tests/baselines/reference/jsxEsprimaFbTestSuite.errors.txt index 22f3c94b6e1e0..0475255c224a5 100644 --- a/tests/baselines/reference/jsxEsprimaFbTestSuite.errors.txt +++ b/tests/baselines/reference/jsxEsprimaFbTestSuite.errors.txt @@ -1,13 +1,7 @@ -tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(40,1): error TS2657: JSX expressions must have one parent element. -tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(40,17): error TS1005: '{' expected. -tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(40,23): error TS1005: ';' expected. -tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(40,23): error TS2304: Cannot find name 'right'. tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(40,41): error TS1382: Unexpected token. Did you mean `{'>'}` or `>`? -tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(40,57): error TS1109: Expression expected. -tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(40,58): error TS1109: Expression expected. -==== tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx (7 errors) ==== +==== tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx (1 errors) ==== declare var React: any; declare var 日本語; declare var AbC_def; @@ -48,20 +42,8 @@ tests/cases/conformance/jsx/jsxEsprimaFbTestSuite.tsx(40,58): error TS1109: Expr

7x invalid-js-identifier
; right=monkeys /> gorillas />; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2657: JSX expressions must have one parent element. - ~ -!!! error TS1005: '{' expected. - ~~~~~ -!!! error TS1005: ';' expected. - ~~~~~ -!!! error TS2304: Cannot find name 'right'. ~ !!! error TS1382: Unexpected token. Did you mean `{'>'}` or `>`? - ~ -!!! error TS1109: Expression expected. - ~ -!!! error TS1109: Expression expected. ; diff --git a/tests/baselines/reference/jsxEsprimaFbTestSuite.js b/tests/baselines/reference/jsxEsprimaFbTestSuite.js index 7a6bec81dbf0f..e5b90a5c64ae0 100644 --- a/tests/baselines/reference/jsxEsprimaFbTestSuite.js +++ b/tests/baselines/reference/jsxEsprimaFbTestSuite.js @@ -72,8 +72,7 @@ baz {/* this is a comment */};
@test content
;

7x invalid-js-identifier
; -, ; -right = monkeys /> gorillas / > ; + right=monkeys /> gorillas/>; ; ; (
) < x; diff --git a/tests/baselines/reference/jsxEsprimaFbTestSuite.symbols b/tests/baselines/reference/jsxEsprimaFbTestSuite.symbols index 64d739a9d62dd..d336e0302aba2 100644 --- a/tests/baselines/reference/jsxEsprimaFbTestSuite.symbols +++ b/tests/baselines/reference/jsxEsprimaFbTestSuite.symbols @@ -77,6 +77,7 @@ baz right=monkeys /> gorillas />; >LeftRight : Symbol(LeftRight, Decl(jsxEsprimaFbTestSuite.tsx, 3, 11)) >left : Symbol(left, Decl(jsxEsprimaFbTestSuite.tsx, 39, 10)) +>right : Symbol(right, Decl(jsxEsprimaFbTestSuite.tsx, 39, 21)) ; >a : Symbol(a, Decl(jsxEsprimaFbTestSuite.tsx, 5, 11)) diff --git a/tests/baselines/reference/jsxEsprimaFbTestSuite.types b/tests/baselines/reference/jsxEsprimaFbTestSuite.types index 7061befb881aa..4b48d7c378d53 100644 --- a/tests/baselines/reference/jsxEsprimaFbTestSuite.types +++ b/tests/baselines/reference/jsxEsprimaFbTestSuite.types @@ -118,21 +118,15 @@ baz >div : any right=monkeys /> gorillas />; -> : any -> right=monkeys /> gorillas /> : any >LeftRight : any ->left : true +>left : any > : any >a : any ->right=monkeys /> gorillas /> : boolean >right : any ->monkeys /> gorillas /> : boolean ->monkeys /> gorillas / : number >monkeys /> gorillas : any >b : any >b : any -> : any -> : any ; > : any diff --git a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.errors.txt b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.errors.txt index 1269825548570..cbe83ef6ece5a 100644 --- a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.errors.txt +++ b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.errors.txt @@ -57,10 +57,8 @@ tests/cases/conformance/jsx/25.tsx(1,39): error TS1109: Expression expected. tests/cases/conformance/jsx/26.tsx(1,4): error TS1382: Unexpected token. Did you mean `{'>'}` or `>`? tests/cases/conformance/jsx/27.tsx(1,5): error TS1382: Unexpected token. Did you mean `{'>'}` or `>`? 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(1,6): error TS1145: '{' or JSX element expected. tests/cases/conformance/jsx/28.tsx(2,1): error TS1005: '; ~ -!!! error TS1005: '{' expected. +!!! error TS1145: '{' or JSX element expected. ==== tests/cases/conformance/jsx/5.tsx (2 errors) ==== ; ~ @@ -292,21 +290,16 @@ tests/cases/conformance/jsx/9.tsx(1,10): error TS2304: Cannot find name 'a:b'. ~ !!! error TS17008: JSX element 'a' has no corresponding closing tag. ~ -!!! error TS1005: '{' expected. +!!! error TS1145: '{' or JSX element expected. !!! error TS1005: '; - ~~~~~~~~~ - ~ -!!! error TS1005: '{' expected. ~ !!! error TS1003: Identifier expected. -!!! error TS2657: JSX expressions must have one parent element. - !!! error TS1005: '}; diff --git a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js index 0b215a47a7c2d..e0d10043838a8 100644 --- a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js +++ b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js @@ -150,8 +150,8 @@ var x =
one
/* intervening comment */, /* intervening comment */
; ; //// [29.jsx] -, <>; -; +; +/>; //// [30.jsx] }; //// [31.jsx] diff --git a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.types b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.types index cb54dc62c3af7..277d3da9da61b 100644 --- a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.types +++ b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.types @@ -250,9 +250,8 @@ var x =
one
/* intervening comment */
two
;; === tests/cases/conformance/jsx/29.tsx === ; >; : any ->a : any ->b : true +>b : any ><}>; : any > : any diff --git a/tests/cases/conformance/jsx/jsxAttributeInitializer.ts b/tests/cases/conformance/jsx/jsxAttributeInitializer.ts new file mode 100644 index 0000000000000..95e4c66820531 --- /dev/null +++ b/tests/cases/conformance/jsx/jsxAttributeInitializer.ts @@ -0,0 +1,10 @@ +// @jsx: preserve, react +// @filename: a.tsx +declare var React: any; + +
+
/> +
foo
/> +
foo
/> +
+