({errors, language}: Props)
| 35 | }; |
| 36 | |
| 37 | export default function Input({errors, language}: Props): JSX.Element { |
| 38 | const [monaco, setMonaco] = useState<Monaco | null>(null); |
| 39 | const store = useStore(); |
| 40 | const dispatchStore = useStoreDispatch(); |
| 41 | |
| 42 | // Set tab width to 2 spaces for the selected input file. |
| 43 | useEffect(() => { |
| 44 | if (!monaco) return; |
| 45 | const uri = monaco.Uri.parse(`file:///index.js`); |
| 46 | const model = monaco.editor.getModel(uri); |
| 47 | invariant(model, 'Model must exist for the selected input file.'); |
| 48 | renderReactCompilerMarkers({ |
| 49 | monaco, |
| 50 | model, |
| 51 | details: errors, |
| 52 | source: store.source, |
| 53 | }); |
| 54 | }, [monaco, errors, store.source]); |
| 55 | |
| 56 | useEffect(() => { |
| 57 | /** |
| 58 | * Ignore "can only be used in TypeScript files." errors, since |
| 59 | * we want to support syntax highlighting for Flow (*.js) files |
| 60 | * and Flow is not a built-in language. |
| 61 | */ |
| 62 | if (!monaco) return; |
| 63 | monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({ |
| 64 | diagnosticCodesToIgnore: [ |
| 65 | 8002, |
| 66 | 8003, |
| 67 | 8004, |
| 68 | 8005, |
| 69 | 8006, |
| 70 | 8008, |
| 71 | 8009, |
| 72 | 8010, |
| 73 | 8011, |
| 74 | 8012, |
| 75 | 8013, |
| 76 | ...(language === 'flow' |
| 77 | ? [7028 /* unused label */, 6133 /* var declared but not read */] |
| 78 | : []), |
| 79 | ], |
| 80 | noSemanticValidation: true, |
| 81 | // Monaco can't validate Flow component syntax |
| 82 | noSyntaxValidation: language === 'flow', |
| 83 | }); |
| 84 | }, [monaco, language]); |
| 85 | |
| 86 | const handleChange: (value: string | undefined) => void = async value => { |
| 87 | if (!value) return; |
| 88 | |
| 89 | dispatchStore({ |
| 90 | type: 'updateSource', |
| 91 | payload: { |
| 92 | source: value, |
| 93 | }, |
| 94 | }); |
nothing calls this directly
no test coverage detected