From e961916217d42187c4cfa404ce2a7bd236305e9e Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 19 Feb 2021 03:06:08 +0200 Subject: [PATCH] fix(42368): omit converting jsx spread attributes to Object.assign for ES2018 and up (#42554) --- src/compiler/transformers/jsx.ts | 52 ++++++--- .../tsxEmitSpreadAttribute(target=es2015).js | 47 ++++++++ ...EmitSpreadAttribute(target=es2015).symbols | 76 +++++++++++++ ...sxEmitSpreadAttribute(target=es2015).types | 105 ++++++++++++++++++ .../tsxEmitSpreadAttribute(target=es2018).js | 47 ++++++++ ...EmitSpreadAttribute(target=es2018).symbols | 76 +++++++++++++ ...sxEmitSpreadAttribute(target=es2018).types | 105 ++++++++++++++++++ .../tsxEmitSpreadAttribute(target=esnext).js | 47 ++++++++ ...EmitSpreadAttribute(target=esnext).symbols | 76 +++++++++++++ ...sxEmitSpreadAttribute(target=esnext).types | 105 ++++++++++++++++++ .../conformance/jsx/tsxEmitSpreadAttribute.ts | 29 +++++ 11 files changed, 747 insertions(+), 18 deletions(-) create mode 100644 tests/baselines/reference/tsxEmitSpreadAttribute(target=es2015).js create mode 100644 tests/baselines/reference/tsxEmitSpreadAttribute(target=es2015).symbols create mode 100644 tests/baselines/reference/tsxEmitSpreadAttribute(target=es2015).types create mode 100644 tests/baselines/reference/tsxEmitSpreadAttribute(target=es2018).js create mode 100644 tests/baselines/reference/tsxEmitSpreadAttribute(target=es2018).symbols create mode 100644 tests/baselines/reference/tsxEmitSpreadAttribute(target=es2018).types create mode 100644 tests/baselines/reference/tsxEmitSpreadAttribute(target=esnext).js create mode 100644 tests/baselines/reference/tsxEmitSpreadAttribute(target=esnext).symbols create mode 100644 tests/baselines/reference/tsxEmitSpreadAttribute(target=esnext).types create mode 100644 tests/cases/conformance/jsx/tsxEmitSpreadAttribute.ts diff --git a/src/compiler/transformers/jsx.ts b/src/compiler/transformers/jsx.ts index 9814f29b2a..1759d72bfd 100644 --- a/src/compiler/transformers/jsx.ts +++ b/src/compiler/transformers/jsx.ts @@ -292,26 +292,38 @@ namespace ts { // When there are no attributes, React wants "null" } else { - // Map spans of JsxAttribute nodes into object literals and spans - // of JsxSpreadAttribute nodes into expressions. - const segments = flatten( - spanMap(attrs, isJsxSpreadAttribute, (attrs, isSpread) => isSpread - ? map(attrs, transformJsxSpreadAttributeToExpression) - : factory.createObjectLiteralExpression(map(attrs, transformJsxAttributeToObjectLiteralElement)) - ) - ); - - if (isJsxSpreadAttribute(attrs[0])) { - // We must always emit at least one object literal before a spread - // argument.factory.createObjectLiteral - segments.unshift(factory.createObjectLiteralExpression()); + const target = compilerOptions.target; + if (target && target >= ScriptTarget.ES2018) { + objectProperties = factory.createObjectLiteralExpression( + flatten( + spanMap(attrs, isJsxSpreadAttribute, (attrs, isSpread) => + isSpread ? map(attrs, transformJsxSpreadAttributeToSpreadAssignment) : map(attrs, transformJsxAttributeToObjectLiteralElement) + ) + ) + ); } + else { + // Map spans of JsxAttribute nodes into object literals and spans + // of JsxSpreadAttribute nodes into expressions. + const segments = flatten( + spanMap(attrs, isJsxSpreadAttribute, (attrs, isSpread) => isSpread + ? map(attrs, transformJsxSpreadAttributeToExpression) + : factory.createObjectLiteralExpression(map(attrs, transformJsxAttributeToObjectLiteralElement)) + ) + ); - // Either emit one big object literal (no spread attribs), or - // a call to the __assign helper. - objectProperties = singleOrUndefined(segments); - if (!objectProperties) { - objectProperties = emitHelpers().createAssignHelper(segments); + if (isJsxSpreadAttribute(attrs[0])) { + // We must always emit at least one object literal before a spread + // argument.factory.createObjectLiteral + segments.unshift(factory.createObjectLiteralExpression()); + } + + // Either emit one big object literal (no spread attribs), or + // a call to the __assign helper. + objectProperties = singleOrUndefined(segments); + if (!objectProperties) { + objectProperties = emitHelpers().createAssignHelper(segments); + } } } @@ -376,6 +388,10 @@ namespace ts { return element; } + function transformJsxSpreadAttributeToSpreadAssignment(node: JsxSpreadAttribute) { + return factory.createSpreadAssignment(visitNode(node.expression, visitor, isExpression)); + } + function transformJsxSpreadAttributeToExpression(node: JsxSpreadAttribute) { return visitNode(node.expression, visitor, isExpression); } diff --git a/tests/baselines/reference/tsxEmitSpreadAttribute(target=es2015).js b/tests/baselines/reference/tsxEmitSpreadAttribute(target=es2015).js new file mode 100644 index 0000000000..fbf2d3ac97 --- /dev/null +++ b/tests/baselines/reference/tsxEmitSpreadAttribute(target=es2015).js @@ -0,0 +1,47 @@ +//// [test.tsx] +declare const React: any; + +export function T1(a: any) { + return
T1
; +} + +export function T2(a: any, b: any) { + return
T2
; +} + +export function T3(a: any, b: any) { + return
T3
; +} + +export function T4(a: any, b: any) { + return
T4
; +} + +export function T5(a: any, b: any, c: any, d: any) { + return
T5
; +} + +export function T6(a: any, b: any, c: any, d: any) { + return
T6
; +} + + +//// [test.js] +export function T1(a) { + return React.createElement("div", Object.assign({ className: "T1" }, a), "T1"); +} +export function T2(a, b) { + return React.createElement("div", Object.assign({ className: "T2" }, a, b), "T2"); +} +export function T3(a, b) { + return React.createElement("div", Object.assign({}, a, { className: "T3" }, b), "T3"); +} +export function T4(a, b) { + return React.createElement("div", Object.assign({ className: "T4" }, Object.assign(Object.assign({}, a), b)), "T4"); +} +export function T5(a, b, c, d) { + return React.createElement("div", Object.assign({ className: "T5" }, Object.assign(Object.assign(Object.assign({}, a), b), { c, d })), "T5"); +} +export function T6(a, b, c, d) { + return React.createElement("div", Object.assign({ className: "T6" }, Object.assign(Object.assign(Object.assign({}, a), b), Object.assign(Object.assign({}, c), d))), "T6"); +} diff --git a/tests/baselines/reference/tsxEmitSpreadAttribute(target=es2015).symbols b/tests/baselines/reference/tsxEmitSpreadAttribute(target=es2015).symbols new file mode 100644 index 0000000000..2ef93d2f43 --- /dev/null +++ b/tests/baselines/reference/tsxEmitSpreadAttribute(target=es2015).symbols @@ -0,0 +1,76 @@ +=== tests/cases/conformance/jsx/test.tsx === +declare const React: any; +>React : Symbol(React, Decl(test.tsx, 0, 13)) + +export function T1(a: any) { +>T1 : Symbol(T1, Decl(test.tsx, 0, 25)) +>a : Symbol(a, Decl(test.tsx, 2, 19)) + + return
T1
; +>className : Symbol(className, Decl(test.tsx, 3, 15)) +>a : Symbol(a, Decl(test.tsx, 2, 19)) +} + +export function T2(a: any, b: any) { +>T2 : Symbol(T2, Decl(test.tsx, 4, 1)) +>a : Symbol(a, Decl(test.tsx, 6, 19)) +>b : Symbol(b, Decl(test.tsx, 6, 26)) + + return
T2
; +>className : Symbol(className, Decl(test.tsx, 7, 15)) +>a : Symbol(a, Decl(test.tsx, 6, 19)) +>b : Symbol(b, Decl(test.tsx, 6, 26)) +} + +export function T3(a: any, b: any) { +>T3 : Symbol(T3, Decl(test.tsx, 8, 1)) +>a : Symbol(a, Decl(test.tsx, 10, 19)) +>b : Symbol(b, Decl(test.tsx, 10, 26)) + + return
T3
; +>a : Symbol(a, Decl(test.tsx, 10, 19)) +>className : Symbol(className, Decl(test.tsx, 11, 24)) +>b : Symbol(b, Decl(test.tsx, 10, 26)) +} + +export function T4(a: any, b: any) { +>T4 : Symbol(T4, Decl(test.tsx, 12, 1)) +>a : Symbol(a, Decl(test.tsx, 14, 19)) +>b : Symbol(b, Decl(test.tsx, 14, 26)) + + return
T4
; +>className : Symbol(className, Decl(test.tsx, 15, 15)) +>a : Symbol(a, Decl(test.tsx, 14, 19)) +>b : Symbol(b, Decl(test.tsx, 14, 26)) +} + +export function T5(a: any, b: any, c: any, d: any) { +>T5 : Symbol(T5, Decl(test.tsx, 16, 1)) +>a : Symbol(a, Decl(test.tsx, 18, 19)) +>b : Symbol(b, Decl(test.tsx, 18, 26)) +>c : Symbol(c, Decl(test.tsx, 18, 34)) +>d : Symbol(d, Decl(test.tsx, 18, 42)) + + return
T5
; +>className : Symbol(className, Decl(test.tsx, 19, 15)) +>a : Symbol(a, Decl(test.tsx, 18, 19)) +>b : Symbol(b, Decl(test.tsx, 18, 26)) +>c : Symbol(c, Decl(test.tsx, 19, 56)) +>d : Symbol(d, Decl(test.tsx, 19, 59)) +} + +export function T6(a: any, b: any, c: any, d: any) { +>T6 : Symbol(T6, Decl(test.tsx, 20, 1)) +>a : Symbol(a, Decl(test.tsx, 22, 19)) +>b : Symbol(b, Decl(test.tsx, 22, 26)) +>c : Symbol(c, Decl(test.tsx, 22, 34)) +>d : Symbol(d, Decl(test.tsx, 22, 42)) + + return
T6
; +>className : Symbol(className, Decl(test.tsx, 23, 15)) +>a : Symbol(a, Decl(test.tsx, 22, 19)) +>b : Symbol(b, Decl(test.tsx, 22, 26)) +>c : Symbol(c, Decl(test.tsx, 22, 34)) +>d : Symbol(d, Decl(test.tsx, 22, 42)) +} + diff --git a/tests/baselines/reference/tsxEmitSpreadAttribute(target=es2015).types b/tests/baselines/reference/tsxEmitSpreadAttribute(target=es2015).types new file mode 100644 index 0000000000..101c3fb75a --- /dev/null +++ b/tests/baselines/reference/tsxEmitSpreadAttribute(target=es2015).types @@ -0,0 +1,105 @@ +=== tests/cases/conformance/jsx/test.tsx === +declare const React: any; +>React : any + +export function T1(a: any) { +>T1 : (a: any) => any +>a : any + + return
T1
; +>
T1
: error +>div : any +>className : string +>"T1" : "T1" +>a : any +>div : any +} + +export function T2(a: any, b: any) { +>T2 : (a: any, b: any) => any +>a : any +>b : any + + return
T2
; +>
T2
: error +>div : any +>className : string +>"T2" : "T2" +>a : any +>b : any +>div : any +} + +export function T3(a: any, b: any) { +>T3 : (a: any, b: any) => any +>a : any +>b : any + + return
T3
; +>
T3
: error +>div : any +>a : any +>className : string +>"T3" : "T3" +>b : any +>div : any +} + +export function T4(a: any, b: any) { +>T4 : (a: any, b: any) => any +>a : any +>b : any + + return
T4
; +>
T4
: error +>div : any +>className : string +>"T4" : "T4" +>{ ...a, ...b } : any +>a : any +>b : any +>div : any +} + +export function T5(a: any, b: any, c: any, d: any) { +>T5 : (a: any, b: any, c: any, d: any) => any +>a : any +>b : any +>c : any +>d : any + + return
T5
; +>
T5
: error +>div : any +>className : string +>"T5" : "T5" +>{ ...a, ...b, ...{ c, d } } : any +>a : any +>b : any +>{ c, d } : { c: any; d: any; } +>c : any +>d : any +>div : any +} + +export function T6(a: any, b: any, c: any, d: any) { +>T6 : (a: any, b: any, c: any, d: any) => any +>a : any +>b : any +>c : any +>d : any + + return
T6
; +>
T6
: error +>div : any +>className : string +>"T6" : "T6" +>{ ...a, ...b, ...{ ...c, ...d } } : any +>a : any +>b : any +>{ ...c, ...d } : any +>c : any +>d : any +>div : any +} + diff --git a/tests/baselines/reference/tsxEmitSpreadAttribute(target=es2018).js b/tests/baselines/reference/tsxEmitSpreadAttribute(target=es2018).js new file mode 100644 index 0000000000..dcb223449b --- /dev/null +++ b/tests/baselines/reference/tsxEmitSpreadAttribute(target=es2018).js @@ -0,0 +1,47 @@ +//// [test.tsx] +declare const React: any; + +export function T1(a: any) { + return
T1
; +} + +export function T2(a: any, b: any) { + return
T2
; +} + +export function T3(a: any, b: any) { + return
T3
; +} + +export function T4(a: any, b: any) { + return
T4
; +} + +export function T5(a: any, b: any, c: any, d: any) { + return
T5
; +} + +export function T6(a: any, b: any, c: any, d: any) { + return
T6
; +} + + +//// [test.js] +export function T1(a) { + return React.createElement("div", { className: "T1", ...a }, "T1"); +} +export function T2(a, b) { + return React.createElement("div", { className: "T2", ...a, ...b }, "T2"); +} +export function T3(a, b) { + return React.createElement("div", { ...a, className: "T3", ...b }, "T3"); +} +export function T4(a, b) { + return React.createElement("div", { className: "T4", ...{ ...a, ...b } }, "T4"); +} +export function T5(a, b, c, d) { + return React.createElement("div", { className: "T5", ...{ ...a, ...b, ...{ c, d } } }, "T5"); +} +export function T6(a, b, c, d) { + return React.createElement("div", { className: "T6", ...{ ...a, ...b, ...{ ...c, ...d } } }, "T6"); +} diff --git a/tests/baselines/reference/tsxEmitSpreadAttribute(target=es2018).symbols b/tests/baselines/reference/tsxEmitSpreadAttribute(target=es2018).symbols new file mode 100644 index 0000000000..2ef93d2f43 --- /dev/null +++ b/tests/baselines/reference/tsxEmitSpreadAttribute(target=es2018).symbols @@ -0,0 +1,76 @@ +=== tests/cases/conformance/jsx/test.tsx === +declare const React: any; +>React : Symbol(React, Decl(test.tsx, 0, 13)) + +export function T1(a: any) { +>T1 : Symbol(T1, Decl(test.tsx, 0, 25)) +>a : Symbol(a, Decl(test.tsx, 2, 19)) + + return
T1
; +>className : Symbol(className, Decl(test.tsx, 3, 15)) +>a : Symbol(a, Decl(test.tsx, 2, 19)) +} + +export function T2(a: any, b: any) { +>T2 : Symbol(T2, Decl(test.tsx, 4, 1)) +>a : Symbol(a, Decl(test.tsx, 6, 19)) +>b : Symbol(b, Decl(test.tsx, 6, 26)) + + return
T2
; +>className : Symbol(className, Decl(test.tsx, 7, 15)) +>a : Symbol(a, Decl(test.tsx, 6, 19)) +>b : Symbol(b, Decl(test.tsx, 6, 26)) +} + +export function T3(a: any, b: any) { +>T3 : Symbol(T3, Decl(test.tsx, 8, 1)) +>a : Symbol(a, Decl(test.tsx, 10, 19)) +>b : Symbol(b, Decl(test.tsx, 10, 26)) + + return
T3
; +>a : Symbol(a, Decl(test.tsx, 10, 19)) +>className : Symbol(className, Decl(test.tsx, 11, 24)) +>b : Symbol(b, Decl(test.tsx, 10, 26)) +} + +export function T4(a: any, b: any) { +>T4 : Symbol(T4, Decl(test.tsx, 12, 1)) +>a : Symbol(a, Decl(test.tsx, 14, 19)) +>b : Symbol(b, Decl(test.tsx, 14, 26)) + + return
T4
; +>className : Symbol(className, Decl(test.tsx, 15, 15)) +>a : Symbol(a, Decl(test.tsx, 14, 19)) +>b : Symbol(b, Decl(test.tsx, 14, 26)) +} + +export function T5(a: any, b: any, c: any, d: any) { +>T5 : Symbol(T5, Decl(test.tsx, 16, 1)) +>a : Symbol(a, Decl(test.tsx, 18, 19)) +>b : Symbol(b, Decl(test.tsx, 18, 26)) +>c : Symbol(c, Decl(test.tsx, 18, 34)) +>d : Symbol(d, Decl(test.tsx, 18, 42)) + + return
T5
; +>className : Symbol(className, Decl(test.tsx, 19, 15)) +>a : Symbol(a, Decl(test.tsx, 18, 19)) +>b : Symbol(b, Decl(test.tsx, 18, 26)) +>c : Symbol(c, Decl(test.tsx, 19, 56)) +>d : Symbol(d, Decl(test.tsx, 19, 59)) +} + +export function T6(a: any, b: any, c: any, d: any) { +>T6 : Symbol(T6, Decl(test.tsx, 20, 1)) +>a : Symbol(a, Decl(test.tsx, 22, 19)) +>b : Symbol(b, Decl(test.tsx, 22, 26)) +>c : Symbol(c, Decl(test.tsx, 22, 34)) +>d : Symbol(d, Decl(test.tsx, 22, 42)) + + return
T6
; +>className : Symbol(className, Decl(test.tsx, 23, 15)) +>a : Symbol(a, Decl(test.tsx, 22, 19)) +>b : Symbol(b, Decl(test.tsx, 22, 26)) +>c : Symbol(c, Decl(test.tsx, 22, 34)) +>d : Symbol(d, Decl(test.tsx, 22, 42)) +} + diff --git a/tests/baselines/reference/tsxEmitSpreadAttribute(target=es2018).types b/tests/baselines/reference/tsxEmitSpreadAttribute(target=es2018).types new file mode 100644 index 0000000000..101c3fb75a --- /dev/null +++ b/tests/baselines/reference/tsxEmitSpreadAttribute(target=es2018).types @@ -0,0 +1,105 @@ +=== tests/cases/conformance/jsx/test.tsx === +declare const React: any; +>React : any + +export function T1(a: any) { +>T1 : (a: any) => any +>a : any + + return
T1
; +>
T1
: error +>div : any +>className : string +>"T1" : "T1" +>a : any +>div : any +} + +export function T2(a: any, b: any) { +>T2 : (a: any, b: any) => any +>a : any +>b : any + + return
T2
; +>
T2
: error +>div : any +>className : string +>"T2" : "T2" +>a : any +>b : any +>div : any +} + +export function T3(a: any, b: any) { +>T3 : (a: any, b: any) => any +>a : any +>b : any + + return
T3
; +>
T3
: error +>div : any +>a : any +>className : string +>"T3" : "T3" +>b : any +>div : any +} + +export function T4(a: any, b: any) { +>T4 : (a: any, b: any) => any +>a : any +>b : any + + return
T4
; +>
T4
: error +>div : any +>className : string +>"T4" : "T4" +>{ ...a, ...b } : any +>a : any +>b : any +>div : any +} + +export function T5(a: any, b: any, c: any, d: any) { +>T5 : (a: any, b: any, c: any, d: any) => any +>a : any +>b : any +>c : any +>d : any + + return
T5
; +>
T5
: error +>div : any +>className : string +>"T5" : "T5" +>{ ...a, ...b, ...{ c, d } } : any +>a : any +>b : any +>{ c, d } : { c: any; d: any; } +>c : any +>d : any +>div : any +} + +export function T6(a: any, b: any, c: any, d: any) { +>T6 : (a: any, b: any, c: any, d: any) => any +>a : any +>b : any +>c : any +>d : any + + return
T6
; +>
T6
: error +>div : any +>className : string +>"T6" : "T6" +>{ ...a, ...b, ...{ ...c, ...d } } : any +>a : any +>b : any +>{ ...c, ...d } : any +>c : any +>d : any +>div : any +} + diff --git a/tests/baselines/reference/tsxEmitSpreadAttribute(target=esnext).js b/tests/baselines/reference/tsxEmitSpreadAttribute(target=esnext).js new file mode 100644 index 0000000000..dcb223449b --- /dev/null +++ b/tests/baselines/reference/tsxEmitSpreadAttribute(target=esnext).js @@ -0,0 +1,47 @@ +//// [test.tsx] +declare const React: any; + +export function T1(a: any) { + return
T1
; +} + +export function T2(a: any, b: any) { + return
T2
; +} + +export function T3(a: any, b: any) { + return
T3
; +} + +export function T4(a: any, b: any) { + return
T4
; +} + +export function T5(a: any, b: any, c: any, d: any) { + return
T5
; +} + +export function T6(a: any, b: any, c: any, d: any) { + return
T6
; +} + + +//// [test.js] +export function T1(a) { + return React.createElement("div", { className: "T1", ...a }, "T1"); +} +export function T2(a, b) { + return React.createElement("div", { className: "T2", ...a, ...b }, "T2"); +} +export function T3(a, b) { + return React.createElement("div", { ...a, className: "T3", ...b }, "T3"); +} +export function T4(a, b) { + return React.createElement("div", { className: "T4", ...{ ...a, ...b } }, "T4"); +} +export function T5(a, b, c, d) { + return React.createElement("div", { className: "T5", ...{ ...a, ...b, ...{ c, d } } }, "T5"); +} +export function T6(a, b, c, d) { + return React.createElement("div", { className: "T6", ...{ ...a, ...b, ...{ ...c, ...d } } }, "T6"); +} diff --git a/tests/baselines/reference/tsxEmitSpreadAttribute(target=esnext).symbols b/tests/baselines/reference/tsxEmitSpreadAttribute(target=esnext).symbols new file mode 100644 index 0000000000..2ef93d2f43 --- /dev/null +++ b/tests/baselines/reference/tsxEmitSpreadAttribute(target=esnext).symbols @@ -0,0 +1,76 @@ +=== tests/cases/conformance/jsx/test.tsx === +declare const React: any; +>React : Symbol(React, Decl(test.tsx, 0, 13)) + +export function T1(a: any) { +>T1 : Symbol(T1, Decl(test.tsx, 0, 25)) +>a : Symbol(a, Decl(test.tsx, 2, 19)) + + return
T1
; +>className : Symbol(className, Decl(test.tsx, 3, 15)) +>a : Symbol(a, Decl(test.tsx, 2, 19)) +} + +export function T2(a: any, b: any) { +>T2 : Symbol(T2, Decl(test.tsx, 4, 1)) +>a : Symbol(a, Decl(test.tsx, 6, 19)) +>b : Symbol(b, Decl(test.tsx, 6, 26)) + + return
T2
; +>className : Symbol(className, Decl(test.tsx, 7, 15)) +>a : Symbol(a, Decl(test.tsx, 6, 19)) +>b : Symbol(b, Decl(test.tsx, 6, 26)) +} + +export function T3(a: any, b: any) { +>T3 : Symbol(T3, Decl(test.tsx, 8, 1)) +>a : Symbol(a, Decl(test.tsx, 10, 19)) +>b : Symbol(b, Decl(test.tsx, 10, 26)) + + return
T3
; +>a : Symbol(a, Decl(test.tsx, 10, 19)) +>className : Symbol(className, Decl(test.tsx, 11, 24)) +>b : Symbol(b, Decl(test.tsx, 10, 26)) +} + +export function T4(a: any, b: any) { +>T4 : Symbol(T4, Decl(test.tsx, 12, 1)) +>a : Symbol(a, Decl(test.tsx, 14, 19)) +>b : Symbol(b, Decl(test.tsx, 14, 26)) + + return
T4
; +>className : Symbol(className, Decl(test.tsx, 15, 15)) +>a : Symbol(a, Decl(test.tsx, 14, 19)) +>b : Symbol(b, Decl(test.tsx, 14, 26)) +} + +export function T5(a: any, b: any, c: any, d: any) { +>T5 : Symbol(T5, Decl(test.tsx, 16, 1)) +>a : Symbol(a, Decl(test.tsx, 18, 19)) +>b : Symbol(b, Decl(test.tsx, 18, 26)) +>c : Symbol(c, Decl(test.tsx, 18, 34)) +>d : Symbol(d, Decl(test.tsx, 18, 42)) + + return
T5
; +>className : Symbol(className, Decl(test.tsx, 19, 15)) +>a : Symbol(a, Decl(test.tsx, 18, 19)) +>b : Symbol(b, Decl(test.tsx, 18, 26)) +>c : Symbol(c, Decl(test.tsx, 19, 56)) +>d : Symbol(d, Decl(test.tsx, 19, 59)) +} + +export function T6(a: any, b: any, c: any, d: any) { +>T6 : Symbol(T6, Decl(test.tsx, 20, 1)) +>a : Symbol(a, Decl(test.tsx, 22, 19)) +>b : Symbol(b, Decl(test.tsx, 22, 26)) +>c : Symbol(c, Decl(test.tsx, 22, 34)) +>d : Symbol(d, Decl(test.tsx, 22, 42)) + + return
T6
; +>className : Symbol(className, Decl(test.tsx, 23, 15)) +>a : Symbol(a, Decl(test.tsx, 22, 19)) +>b : Symbol(b, Decl(test.tsx, 22, 26)) +>c : Symbol(c, Decl(test.tsx, 22, 34)) +>d : Symbol(d, Decl(test.tsx, 22, 42)) +} + diff --git a/tests/baselines/reference/tsxEmitSpreadAttribute(target=esnext).types b/tests/baselines/reference/tsxEmitSpreadAttribute(target=esnext).types new file mode 100644 index 0000000000..101c3fb75a --- /dev/null +++ b/tests/baselines/reference/tsxEmitSpreadAttribute(target=esnext).types @@ -0,0 +1,105 @@ +=== tests/cases/conformance/jsx/test.tsx === +declare const React: any; +>React : any + +export function T1(a: any) { +>T1 : (a: any) => any +>a : any + + return
T1
; +>
T1
: error +>div : any +>className : string +>"T1" : "T1" +>a : any +>div : any +} + +export function T2(a: any, b: any) { +>T2 : (a: any, b: any) => any +>a : any +>b : any + + return
T2
; +>
T2
: error +>div : any +>className : string +>"T2" : "T2" +>a : any +>b : any +>div : any +} + +export function T3(a: any, b: any) { +>T3 : (a: any, b: any) => any +>a : any +>b : any + + return
T3
; +>
T3
: error +>div : any +>a : any +>className : string +>"T3" : "T3" +>b : any +>div : any +} + +export function T4(a: any, b: any) { +>T4 : (a: any, b: any) => any +>a : any +>b : any + + return
T4
; +>
T4
: error +>div : any +>className : string +>"T4" : "T4" +>{ ...a, ...b } : any +>a : any +>b : any +>div : any +} + +export function T5(a: any, b: any, c: any, d: any) { +>T5 : (a: any, b: any, c: any, d: any) => any +>a : any +>b : any +>c : any +>d : any + + return
T5
; +>
T5
: error +>div : any +>className : string +>"T5" : "T5" +>{ ...a, ...b, ...{ c, d } } : any +>a : any +>b : any +>{ c, d } : { c: any; d: any; } +>c : any +>d : any +>div : any +} + +export function T6(a: any, b: any, c: any, d: any) { +>T6 : (a: any, b: any, c: any, d: any) => any +>a : any +>b : any +>c : any +>d : any + + return
T6
; +>
T6
: error +>div : any +>className : string +>"T6" : "T6" +>{ ...a, ...b, ...{ ...c, ...d } } : any +>a : any +>b : any +>{ ...c, ...d } : any +>c : any +>d : any +>div : any +} + diff --git a/tests/cases/conformance/jsx/tsxEmitSpreadAttribute.ts b/tests/cases/conformance/jsx/tsxEmitSpreadAttribute.ts new file mode 100644 index 0000000000..4ddebfcb12 --- /dev/null +++ b/tests/cases/conformance/jsx/tsxEmitSpreadAttribute.ts @@ -0,0 +1,29 @@ +// @jsx: react +// @target: es2015,es2018,esnext +// @filename: test.tsx + +declare const React: any; + +export function T1(a: any) { + return
T1
; +} + +export function T2(a: any, b: any) { + return
T2
; +} + +export function T3(a: any, b: any) { + return
T3
; +} + +export function T4(a: any, b: any) { + return
T4
; +} + +export function T5(a: any, b: any, c: any, d: any) { + return
T5
; +} + +export function T6(a: any, b: any, c: any, d: any) { + return
T6
; +}