From 761ca29d91a960cf6b3a4d3bf42694070e6dbdee Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sat, 27 May 2023 22:15:07 +0300 Subject: [PATCH] fix(54411): transform spread JSX attribute containing jsx tags --- src/compiler/transformers/jsx.ts | 2 +- tests/baselines/reference/jsxSpreadTag.js | 10 ++++++++++ .../baselines/reference/jsxSpreadTag.symbols | 11 +++++++++++ tests/baselines/reference/jsxSpreadTag.types | 19 +++++++++++++++++++ tests/cases/compiler/jsxSpreadTag.ts | 8 ++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/jsxSpreadTag.js create mode 100644 tests/baselines/reference/jsxSpreadTag.symbols create mode 100644 tests/baselines/reference/jsxSpreadTag.types create mode 100644 tests/cases/compiler/jsxSpreadTag.ts diff --git a/src/compiler/transformers/jsx.ts b/src/compiler/transformers/jsx.ts index 52fa0bc564f74..3447a2249524c 100644 --- a/src/compiler/transformers/jsx.ts +++ b/src/compiler/transformers/jsx.ts @@ -480,7 +480,7 @@ export function transformJsx(context: TransformationContext): (x: SourceFile | B continue; } finishObjectLiteralIfNeeded(); - expressions.push(attr.expression); + expressions.push(Debug.checkDefined(visitNode(attr.expression, visitor, isExpression))); continue; } properties.push(transformJsxAttributeToObjectLiteralElement(attr)); diff --git a/tests/baselines/reference/jsxSpreadTag.js b/tests/baselines/reference/jsxSpreadTag.js new file mode 100644 index 0000000000000..2fbf28534213e --- /dev/null +++ b/tests/baselines/reference/jsxSpreadTag.js @@ -0,0 +1,10 @@ +//// [a.tsx] +declare const React: any; + +const t1 =
} />; +const t2 =
} />; + + +//// [a.js] +const t1 = React.createElement("div", Object.assign({}, React.createElement("span", null))); +const t2 = React.createElement("div", Object.assign({}, React.createElement("span", { className: "foo" }))); diff --git a/tests/baselines/reference/jsxSpreadTag.symbols b/tests/baselines/reference/jsxSpreadTag.symbols new file mode 100644 index 0000000000000..93057b1ff6568 --- /dev/null +++ b/tests/baselines/reference/jsxSpreadTag.symbols @@ -0,0 +1,11 @@ +=== /a.tsx === +declare const React: any; +>React : Symbol(React, Decl(a.tsx, 0, 13)) + +const t1 =
} />; +>t1 : Symbol(t1, Decl(a.tsx, 2, 5)) + +const t2 =
} />; +>t2 : Symbol(t2, Decl(a.tsx, 3, 5)) +>className : Symbol(className, Decl(a.tsx, 3, 25)) + diff --git a/tests/baselines/reference/jsxSpreadTag.types b/tests/baselines/reference/jsxSpreadTag.types new file mode 100644 index 0000000000000..c3647817a71d9 --- /dev/null +++ b/tests/baselines/reference/jsxSpreadTag.types @@ -0,0 +1,19 @@ +=== /a.tsx === +declare const React: any; +>React : any + +const t1 =
} />; +>t1 : error +>
} /> : error +>div : any +> : error +>span : any + +const t2 =
} />; +>t2 : error +>
} /> : error +>div : any +> : error +>span : any +>className : string + diff --git a/tests/cases/compiler/jsxSpreadTag.ts b/tests/cases/compiler/jsxSpreadTag.ts new file mode 100644 index 0000000000000..d572d05783039 --- /dev/null +++ b/tests/cases/compiler/jsxSpreadTag.ts @@ -0,0 +1,8 @@ +// @jsx: react +// @target: es2015 +// @filename: /a.tsx + +declare const React: any; + +const t1 =
} />; +const t2 =
} />;