@@ -467,13 +467,23 @@ export default class Try extends Component {
467467 } ) ;
468468 }
469469
470+ compile = ( code ) => {
471+ const _consoleError = console . error ;
472+ let warning = '' ;
473+ console . error = ( ...args ) => args . forEach ( argument => warning += argument + `\n` ) ;
474+ const res = JSON . parse ( window . ocaml . compile ( code ) ) ;
475+ console . error = _consoleError ;
476+ return [ res , warning || null ] ;
477+ }
478+
470479 tryCompiling = debounce ( ( reason , ocaml ) => {
471480 try {
472- const res = JSON . parse ( window . ocaml . compile ( ocaml ) )
481+ const [ res , warning ] = this . compile ( ocaml ) ;
473482 if ( res . js_code ) {
474483 this . setState ( _ => ( {
475484 js : res . js_code ,
476485 jsIsLatest : true ,
486+ compileWarning : warning
477487 } ) )
478488 if ( this . state . autoEvaluate ) {
479489 this . evalJs ( res . js_code ) ;
@@ -483,6 +493,7 @@ export default class Try extends Component {
483493 this . errorTimerId = setTimeout (
484494 ( ) => this . setState ( _ => ( {
485495 compileError : res ,
496+ compileWarning : null ,
486497 js : '' ,
487498 } ) ) ,
488499 errorTimeout
@@ -492,6 +503,7 @@ export default class Try extends Component {
492503 this . errorTimerId = setTimeout (
493504 ( ) => this . setState ( _ => ( {
494505 compileError : err ,
506+ compileWarning : null ,
495507 js : '' ,
496508 } ) ) ,
497509 errorTimeout
@@ -500,6 +512,7 @@ export default class Try extends Component {
500512 this . setState ( _ => {
501513 return {
502514 compileError : null ,
515+ compileWarning : null ,
503516 jsIsLatest : false ,
504517 output : [ ] ,
505518 }
@@ -530,11 +543,20 @@ export default class Try extends Component {
530543 }
531544
532545 render ( ) {
533- const { reason, ocaml, js, reasonSyntaxError, compileError, ocamlSyntaxError, jsError } = this . state
546+ const {
547+ reason,
548+ ocaml,
549+ js,
550+ reasonSyntaxError,
551+ compileError,
552+ compileWarning,
553+ ocamlSyntaxError,
554+ jsError
555+ } = this . state ;
534556 const codemirrorStyles = [
535557 styles . codemirror ,
536558 isSafari && styles . codemirrorSafari ,
537- ]
559+ ] ;
538560 return (
539561 < div css = { styles . container } >
540562 < Helmet >
@@ -611,6 +633,12 @@ export default class Try extends Component {
611633 : compileError . message }
612634 </ div >
613635 </ div > }
636+ { compileWarning &&
637+ < div css = { styles . warning } >
638+ < div css = { styles . errorBody } >
639+ { compileWarning }
640+ </ div >
641+ </ div > }
614642 </ div >
615643 </ div >
616644 < div css = { styles . column } >
@@ -674,6 +702,10 @@ const styles = {
674702 backgroundColor : '#faa' ,
675703 padding : '10px 20px' ,
676704 } ,
705+ warning : {
706+ backgroundColor : '#fff8dc' ,
707+ padding : '10px 20px' ,
708+ } ,
677709
678710 container : {
679711 position : 'absolute' ,
@@ -754,7 +786,11 @@ const styles = {
754786 '&:hover, &:hover button' : {
755787 color : accent ,
756788 cursor : 'pointer'
757- }
789+ } ,
790+
791+ '@media(max-height: 770px)' : {
792+ padding : '.5em 1em' ,
793+ } ,
758794 } ,
759795
760796 shareButton : {
@@ -841,8 +877,12 @@ const styles = {
841877 width : '25vw' ,
842878 boxShadow : '1px 1px 1px rgba(0, 0, 0, .2)' ,
843879 borderTop : '1px solid #d6d4d4' ,
880+ margin : 0 ,
881+ padding : 0 ,
882+ listStyle : 'none' ,
844883
845884 '& li' : {
885+ margin : 0 ,
846886 padding : '.5em 2em' ,
847887
848888 '&:first-child' : {
0 commit comments