Skip to content

Commit b03926e

Browse files
authored
fix(54411): Compiled code contain jsx code (#54425)
1 parent 23d4836 commit b03926e

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

src/compiler/transformers/jsx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ export function transformJsx(context: TransformationContext): (x: SourceFile | B
480480
continue;
481481
}
482482
finishObjectLiteralIfNeeded();
483-
expressions.push(attr.expression);
483+
expressions.push(Debug.checkDefined(visitNode(attr.expression, visitor, isExpression)));
484484
continue;
485485
}
486486
properties.push(transformJsxAttributeToObjectLiteralElement(attr));
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//// [a.tsx]
2+
declare const React: any;
3+
4+
const t1 = <div {...<span />} />;
5+
const t2 = <div {...<span className="foo" />} />;
6+
7+
8+
//// [a.js]
9+
const t1 = React.createElement("div", Object.assign({}, React.createElement("span", null)));
10+
const t2 = React.createElement("div", Object.assign({}, React.createElement("span", { className: "foo" })));
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=== /a.tsx ===
2+
declare const React: any;
3+
>React : Symbol(React, Decl(a.tsx, 0, 13))
4+
5+
const t1 = <div {...<span />} />;
6+
>t1 : Symbol(t1, Decl(a.tsx, 2, 5))
7+
8+
const t2 = <div {...<span className="foo" />} />;
9+
>t2 : Symbol(t2, Decl(a.tsx, 3, 5))
10+
>className : Symbol(className, Decl(a.tsx, 3, 25))
11+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== /a.tsx ===
2+
declare const React: any;
3+
>React : any
4+
5+
const t1 = <div {...<span />} />;
6+
>t1 : error
7+
><div {...<span />} /> : error
8+
>div : any
9+
><span /> : error
10+
>span : any
11+
12+
const t2 = <div {...<span className="foo" />} />;
13+
>t2 : error
14+
><div {...<span className="foo" />} /> : error
15+
>div : any
16+
><span className="foo" /> : error
17+
>span : any
18+
>className : string
19+

tests/cases/compiler/jsxSpreadTag.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @jsx: react
2+
// @target: es2015
3+
// @filename: /a.tsx
4+
5+
declare const React: any;
6+
7+
const t1 = <div {...<span />} />;
8+
const t2 = <div {...<span className="foo" />} />;

0 commit comments

Comments
 (0)