fix(54411): Compiled code contain jsx code (#54425)

This commit is contained in:
Oleksandr T 2023-06-01 21:01:25 +03:00 committed by GitHub
parent 23d48364e4
commit b03926ea78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 1 deletions

View File

@ -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));

View File

@ -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" })));

View File

@ -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))

View File

@ -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

View File

@ -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" />} />;