@@ -778,16 +778,16 @@ test('jsx', async () => {
778
778
String ( compileSync ( '*a*' , { jsx : true } ) ) ,
779
779
[
780
780
'/*@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
+ '}' ,
781
788
'function MDXContent(props = {}) {' ,
782
789
' 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);' ,
791
791
'}' ,
792
792
'export default MDXContent;' ,
793
793
''
@@ -799,12 +799,12 @@ test('jsx', async () => {
799
799
String ( compileSync ( '<a {...b} c d="1" e={1} />' , { jsx : true } ) ) ,
800
800
[
801
801
'/*@jsxRuntime automatic @jsxImportSource react*/' ,
802
+ 'function _createMdxContent(props) {' ,
803
+ ' return <a {...b} c d="1" e={1} />;' ,
804
+ '}' ,
802
805
'function MDXContent(props = {}) {' ,
803
806
' 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);' ,
808
808
'}' ,
809
809
'export default MDXContent;' ,
810
810
''
@@ -816,15 +816,15 @@ test('jsx', async () => {
816
816
String ( compileSync ( '<><a:b /><c.d/></>' , { jsx : true } ) ) ,
817
817
[
818
818
'/*@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
+ '}' ,
819
825
'function MDXContent(props = {}) {' ,
820
826
' 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);' ,
828
828
'}' ,
829
829
'export default MDXContent;' ,
830
830
'function _missingMdxReference(id, component) {' ,
@@ -840,12 +840,12 @@ test('jsx', async () => {
840
840
[
841
841
'/*@jsxRuntime automatic @jsxImportSource react*/' ,
842
842
'/*1*/' ,
843
+ 'function _createMdxContent(props) {' ,
844
+ ' return <><>{"a "}{}{" b"}</></>;' ,
845
+ '}' ,
843
846
'function MDXContent(props = {}) {' ,
844
847
' 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);' ,
849
849
'}' ,
850
850
'export default MDXContent;' ,
851
851
''
@@ -857,15 +857,15 @@ test('jsx', async () => {
857
857
String ( compileSync ( '{<a-b></a-b>}' , { jsx : true } ) ) ,
858
858
[
859
859
'/*@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
+ '}' ,
860
866
'function MDXContent(props = {}) {' ,
861
867
' 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);' ,
869
869
'}' ,
870
870
'export default MDXContent;' ,
871
871
''
@@ -877,22 +877,49 @@ test('jsx', async () => {
877
877
String ( compileSync ( 'Hello {props.name}' , { jsx : true } ) ) ,
878
878
[
879
879
'/*@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
+ '}' ,
880
886
'function MDXContent(props = {}) {' ,
881
887
' 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);' ,
889
889
'}' ,
890
890
'export default MDXContent;' ,
891
891
''
892
892
] . join ( '\n' ) ,
893
893
'should allow using props'
894
894
)
895
895
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
+
896
923
assert . match (
897
924
String ( compileSync ( "{<w x='y \" z' />}" , { jsx : true } ) ) ,
898
925
/ x = " y & q u o t ; z " / ,
1 commit comments
vercel[bot] commentedon Jun 17, 2022
Successfully deployed to the following URLs:
mdx – ./
mdxjs.com
mdx-mdx.vercel.app
mdx-git-main-mdx.vercel.app
v2.mdxjs.com