Skip to content

Commit

Permalink
fix(54411): transform spread JSX attribute containing jsx tags
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tarasyuk committed May 27, 2023
1 parent ca0fafd commit 761ca29
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/transformers/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
10 changes: 10 additions & 0 deletions tests/baselines/reference/jsxSpreadTag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//// [a.tsx]
declare const React: any;

const t1 = <div {...<span />} />;
const t2 = <div {...<span className="foo" />} />;


//// [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" })));
11 changes: 11 additions & 0 deletions tests/baselines/reference/jsxSpreadTag.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
=== /a.tsx ===
declare const React: any;
>React : Symbol(React, Decl(a.tsx, 0, 13))

const t1 = <div {...<span />} />;
>t1 : Symbol(t1, Decl(a.tsx, 2, 5))

const t2 = <div {...<span className="foo" />} />;
>t2 : Symbol(t2, Decl(a.tsx, 3, 5))
>className : Symbol(className, Decl(a.tsx, 3, 25))

19 changes: 19 additions & 0 deletions tests/baselines/reference/jsxSpreadTag.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
=== /a.tsx ===
declare const React: any;
>React : any

const t1 = <div {...<span />} />;
>t1 : error
><div {...<span />} /> : error
>div : any
><span /> : error
>span : any

const t2 = <div {...<span className="foo" />} />;
>t2 : error
><div {...<span className="foo" />} /> : error
>div : any
><span className="foo" /> : error
>span : any
>className : string

8 changes: 8 additions & 0 deletions tests/cases/compiler/jsxSpreadTag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @jsx: react
// @target: es2015
// @filename: /a.tsx

declare const React: any;

const t1 = <div {...<span />} />;
const t2 = <div {...<span className="foo" />} />;

0 comments on commit 761ca29

Please sign in to comment.