@@ -15,18 +15,17 @@ import {useEffect, useState} from 'react';
1515import { renderReactCompilerMarkers } from '../../lib/reactCompilerMonacoDiagnostics' ;
1616import { useStore , useStoreDispatch } from '../StoreContext' ;
1717import { monacoOptions } from './monacoOptions' ;
18- // TODO: Make TS recognize .d.ts files, in addition to loading them with webpack.
19- // @ts -ignore
18+ // @ts -expect-error TODO: Make TS recognize .d.ts files, in addition to loading them with webpack.
2019import React$Types from '../../node_modules/@types/react/index.d.ts' ;
2120
2221loader . config ( { monaco} ) ;
2322
2423type Props = {
25- errors : CompilerErrorDetail [ ] ;
24+ errors : Array < CompilerErrorDetail > ;
2625 language : 'flow' | 'typescript' ;
2726} ;
2827
29- export default function Input ( { errors, language} : Props ) {
28+ export default function Input ( { errors, language} : Props ) : JSX . Element {
3029 const [ monaco , setMonaco ] = useState < Monaco | null > ( null ) ;
3130 const store = useStore ( ) ;
3231 const dispatchStore = useStoreDispatch ( ) ;
@@ -38,18 +37,19 @@ export default function Input({errors, language}: Props) {
3837 const model = monaco . editor . getModel ( uri ) ;
3938 invariant ( model , 'Model must exist for the selected input file.' ) ;
4039 renderReactCompilerMarkers ( { monaco, model, details : errors } ) ;
41- // N.B. that `tabSize` is a model property, not an editor property.
42- // So, the tab size has to be set per model.
40+ /**
41+ * N.B. that `tabSize` is a model property, not an editor property.
42+ * So, the tab size has to be set per model.
43+ */
4344 model . updateOptions ( { tabSize : 2 } ) ;
4445 } , [ monaco , errors ] ) ;
4546
46- const flowDiagnosticDisable = [
47- 7028 /* unused label */ , 6133 /* var declared but not read */ ,
48- ] ;
4947 useEffect ( ( ) => {
50- // Ignore "can only be used in TypeScript files." errors, since
51- // we want to support syntax highlighting for Flow (*.js) files
52- // and Flow is not a built-in language.
48+ /**
49+ * Ignore "can only be used in TypeScript files." errors, since
50+ * we want to support syntax highlighting for Flow (*.js) files
51+ * and Flow is not a built-in language.
52+ */
5353 if ( ! monaco ) return ;
5454 monaco . languages . typescript . javascriptDefaults . setDiagnosticsOptions ( {
5555 diagnosticCodesToIgnore : [
@@ -64,15 +64,17 @@ export default function Input({errors, language}: Props) {
6464 8011 ,
6565 8012 ,
6666 8013 ,
67- ...( language === 'flow' ? flowDiagnosticDisable : [ ] ) ,
67+ ...( language === 'flow'
68+ ? [ 7028 /* unused label */ , 6133 /* var declared but not read */ ]
69+ : [ ] ) ,
6870 ] ,
6971 noSemanticValidation : true ,
7072 // Monaco can't validate Flow component syntax
7173 noSyntaxValidation : language === 'flow' ,
7274 } ) ;
7375 } , [ monaco , language ] ) ;
7476
75- const handleChange = ( value : string | undefined ) => {
77+ const handleChange : ( value : string | undefined ) => void = value => {
7678 if ( ! value ) return ;
7779
7880 dispatchStore ( {
@@ -83,7 +85,10 @@ export default function Input({errors, language}: Props) {
8385 } ) ;
8486 } ;
8587
86- const handleMount = ( _ : editor . IStandaloneCodeEditor , monaco : Monaco ) => {
88+ const handleMount : (
89+ _ : editor . IStandaloneCodeEditor ,
90+ monaco : Monaco ,
91+ ) => void = ( _ , monaco ) => {
8792 setMonaco ( monaco ) ;
8893
8994 const tscOptions = {
@@ -111,10 +116,12 @@ export default function Input({errors, language}: Props) {
111116 monaco . languages . typescript . javascriptDefaults . addExtraLib ( ...reactLib ) ;
112117 monaco . languages . typescript . typescriptDefaults . addExtraLib ( ...reactLib ) ;
113118
114- // Remeasure the font in case the custom font is loaded only after
115- // Monaco Editor is mounted.
116- // N.B. that this applies also to the output editor as it seems
117- // Monaco Editor instances share the same font config.
119+ /**
120+ * Remeasure the font in case the custom font is loaded only after
121+ * Monaco Editor is mounted.
122+ * N.B. that this applies also to the output editor as it seems
123+ * Monaco Editor instances share the same font config.
124+ */
118125 document . fonts . ready . then ( ( ) => {
119126 monaco . editor . remeasureFonts ( ) ;
120127 } ) ;
@@ -125,14 +132,18 @@ export default function Input({errors, language}: Props) {
125132 < Resizable
126133 minWidth = { 650 }
127134 enable = { { right : true } }
128- // Restrict MonacoEditor's height, since the config autoLayout:true
129- // will grow the editor to fit within parent element
135+ /**
136+ * Restrict MonacoEditor's height, since the config autoLayout:true
137+ * will grow the editor to fit within parent element
138+ */
130139 className = "!h-[calc(100vh_-_3.5rem)]" >
131140 < MonacoEditor
132141 path = { 'index.js' }
133- // .js and .jsx files are specified to be TS so that Monaco can actually
134- // check their syntax using its TS language service. They are still JS files
135- // due to their extensions, so TS language features don't work.
142+ /**
143+ * .js and .jsx files are specified to be TS so that Monaco can actually
144+ * check their syntax using its TS language service. They are still JS files
145+ * due to their extensions, so TS language features don't work.
146+ */
136147 language = { 'javascript' }
137148 value = { store . source }
138149 onMount = { handleMount }
0 commit comments