@@ -778,16 +778,16 @@ test('jsx', async () => {
778778 String ( compileSync ( '*a*' , { jsx : true } ) ) ,
779779 [
780780 '/*@jsxRuntime automatic @jsxImportSource react*/' ,
781+ 'function _createMdxContent(props) {' ,
782+ ' const _components = Object.assign({' ,
783+ ' p: "p",' ,
784+ ' em: "em"' ,
785+ ' }, props.components);' ,
786+ ' return <_components.p><_components.em>{"a"}</_components.em></_components.p>;' ,
787+ '}' ,
781788 'function MDXContent(props = {}) {' ,
782789 ' const {wrapper: MDXLayout} = props.components || ({});' ,
783- ' return MDXLayout ? <MDXLayout {...props}><_createMdxContent /></MDXLayout> : _createMdxContent();' ,
784- ' function _createMdxContent() {' ,
785- ' const _components = Object.assign({' ,
786- ' p: "p",' ,
787- ' em: "em"' ,
788- ' }, props.components);' ,
789- ' return <_components.p><_components.em>{"a"}</_components.em></_components.p>;' ,
790- ' }' ,
790+ ' return MDXLayout ? <MDXLayout {...props}><_createMdxContent {...props} /></MDXLayout> : _createMdxContent(props);' ,
791791 '}' ,
792792 'export default MDXContent;' ,
793793 ''
@@ -799,12 +799,12 @@ test('jsx', async () => {
799799 String ( compileSync ( '<a {...b} c d="1" e={1} />' , { jsx : true } ) ) ,
800800 [
801801 '/*@jsxRuntime automatic @jsxImportSource react*/' ,
802+ 'function _createMdxContent(props) {' ,
803+ ' return <a {...b} c d="1" e={1} />;' ,
804+ '}' ,
802805 'function MDXContent(props = {}) {' ,
803806 ' const {wrapper: MDXLayout} = props.components || ({});' ,
804- ' return MDXLayout ? <MDXLayout {...props}><_createMdxContent /></MDXLayout> : _createMdxContent();' ,
805- ' function _createMdxContent() {' ,
806- ' return <a {...b} c d="1" e={1} />;' ,
807- ' }' ,
807+ ' return MDXLayout ? <MDXLayout {...props}><_createMdxContent {...props} /></MDXLayout> : _createMdxContent(props);' ,
808808 '}' ,
809809 'export default MDXContent;' ,
810810 ''
@@ -816,15 +816,15 @@ test('jsx', async () => {
816816 String ( compileSync ( '<><a:b /><c.d/></>' , { jsx : true } ) ) ,
817817 [
818818 '/*@jsxRuntime automatic @jsxImportSource react*/' ,
819+ 'function _createMdxContent(props) {' ,
820+ ' const {c} = props.components || ({});' ,
821+ ' if (!c) _missingMdxReference("c", false);' ,
822+ ' if (!c.d) _missingMdxReference("c.d", true);' ,
823+ ' return <><><a:b /><c.d /></></>;' ,
824+ '}' ,
819825 'function MDXContent(props = {}) {' ,
820826 ' const {wrapper: MDXLayout} = props.components || ({});' ,
821- ' return MDXLayout ? <MDXLayout {...props}><_createMdxContent /></MDXLayout> : _createMdxContent();' ,
822- ' function _createMdxContent() {' ,
823- ' const {c} = props.components || ({});' ,
824- ' if (!c) _missingMdxReference("c", false);' ,
825- ' if (!c.d) _missingMdxReference("c.d", true);' ,
826- ' return <><><a:b /><c.d /></></>;' ,
827- ' }' ,
827+ ' return MDXLayout ? <MDXLayout {...props}><_createMdxContent {...props} /></MDXLayout> : _createMdxContent(props);' ,
828828 '}' ,
829829 'export default MDXContent;' ,
830830 'function _missingMdxReference(id, component) {' ,
@@ -840,12 +840,12 @@ test('jsx', async () => {
840840 [
841841 '/*@jsxRuntime automatic @jsxImportSource react*/' ,
842842 '/*1*/' ,
843+ 'function _createMdxContent(props) {' ,
844+ ' return <><>{"a "}{}{" b"}</></>;' ,
845+ '}' ,
843846 'function MDXContent(props = {}) {' ,
844847 ' const {wrapper: MDXLayout} = props.components || ({});' ,
845- ' return MDXLayout ? <MDXLayout {...props}><_createMdxContent /></MDXLayout> : _createMdxContent();' ,
846- ' function _createMdxContent() {' ,
847- ' return <><>{"a "}{}{" b"}</></>;' ,
848- ' }' ,
848+ ' return MDXLayout ? <MDXLayout {...props}><_createMdxContent {...props} /></MDXLayout> : _createMdxContent(props);' ,
849849 '}' ,
850850 'export default MDXContent;' ,
851851 ''
@@ -857,15 +857,15 @@ test('jsx', async () => {
857857 String ( compileSync ( '{<a-b></a-b>}' , { jsx : true } ) ) ,
858858 [
859859 '/*@jsxRuntime automatic @jsxImportSource react*/' ,
860+ 'function _createMdxContent(props) {' ,
861+ ' const _components = Object.assign({' ,
862+ ' "a-b": "a-b"' ,
863+ ' }, props.components);' ,
864+ ' return <>{<_components.a-b></_components.a-b>}</>;' ,
865+ '}' ,
860866 'function MDXContent(props = {}) {' ,
861867 ' const {wrapper: MDXLayout} = props.components || ({});' ,
862- ' return MDXLayout ? <MDXLayout {...props}><_createMdxContent /></MDXLayout> : _createMdxContent();' ,
863- ' function _createMdxContent() {' ,
864- ' const _components = Object.assign({' ,
865- ' "a-b": "a-b"' ,
866- ' }, props.components);' ,
867- ' return <>{<_components.a-b></_components.a-b>}</>;' ,
868- ' }' ,
868+ ' return MDXLayout ? <MDXLayout {...props}><_createMdxContent {...props} /></MDXLayout> : _createMdxContent(props);' ,
869869 '}' ,
870870 'export default MDXContent;' ,
871871 ''
@@ -877,22 +877,49 @@ test('jsx', async () => {
877877 String ( compileSync ( 'Hello {props.name}' , { jsx : true } ) ) ,
878878 [
879879 '/*@jsxRuntime automatic @jsxImportSource react*/' ,
880+ 'function _createMdxContent(props) {' ,
881+ ' const _components = Object.assign({' ,
882+ ' p: "p"' ,
883+ ' }, props.components);' ,
884+ ' return <_components.p>{"Hello "}{props.name}</_components.p>;' ,
885+ '}' ,
880886 'function MDXContent(props = {}) {' ,
881887 ' const {wrapper: MDXLayout} = props.components || ({});' ,
882- ' return MDXLayout ? <MDXLayout {...props}><_createMdxContent /></MDXLayout> : _createMdxContent();' ,
883- ' function _createMdxContent() {' ,
884- ' const _components = Object.assign({' ,
885- ' p: "p"' ,
886- ' }, props.components);' ,
887- ' return <_components.p>{"Hello "}{props.name}</_components.p>;' ,
888- ' }' ,
888+ ' return MDXLayout ? <MDXLayout {...props}><_createMdxContent {...props} /></MDXLayout> : _createMdxContent(props);' ,
889889 '}' ,
890890 'export default MDXContent;' ,
891891 ''
892892 ] . join ( '\n' ) ,
893893 'should allow using props'
894894 )
895895
896+ assert . equal (
897+ String (
898+ compileSync (
899+ 'export default function Layout({components, ...props}) { return <section {...props} /> }\n\na' ,
900+ { jsx : true }
901+ )
902+ ) ,
903+ [
904+ '/*@jsxRuntime automatic @jsxImportSource react*/' ,
905+ 'const MDXLayout = function Layout({components, ...props}) {' ,
906+ ' return <section {...props} />;' ,
907+ '};' ,
908+ 'function _createMdxContent(props) {' ,
909+ ' const _components = Object.assign({' ,
910+ ' p: "p"' ,
911+ ' }, props.components);' ,
912+ ' return <_components.p>{"a"}</_components.p>;' ,
913+ '}' ,
914+ 'function MDXContent(props = {}) {' ,
915+ ' return <MDXLayout {...props}><_createMdxContent {...props} /></MDXLayout>;' ,
916+ '}' ,
917+ 'export default MDXContent;' ,
918+ ''
919+ ] . join ( '\n' ) ,
920+ 'should not have a conditional expression for MDXLayout when there is an internal layout'
921+ )
922+
896923 assert . match (
897924 String ( compileSync ( "{<w x='y \" z' />}" , { jsx : true } ) ) ,
898925 / x = " y & q u o t ; z " / ,
0 commit comments