( source: string, mode: 'compiler' | 'linter', configOverrides: string, )
| 190 | } |
| 191 | |
| 192 | function compile( |
| 193 | source: string, |
| 194 | mode: 'compiler' | 'linter', |
| 195 | configOverrides: string, |
| 196 | ): [CompilerOutput, 'flow' | 'typescript', PluginOptions | null] { |
| 197 | const results = new Map<string, Array<PrintedCompilerPipelineValue>>(); |
| 198 | const error = new CompilerError(); |
| 199 | const otherErrors: Array<CompilerErrorDetail | CompilerDiagnostic> = []; |
| 200 | const upsert: (result: PrintedCompilerPipelineValue) => void = result => { |
| 201 | const entry = results.get(result.name); |
| 202 | if (Array.isArray(entry)) { |
| 203 | entry.push(result); |
| 204 | } else { |
| 205 | results.set(result.name, [result]); |
| 206 | } |
| 207 | }; |
| 208 | let language: 'flow' | 'typescript'; |
| 209 | if (source.match(/\@flow/)) { |
| 210 | language = 'flow'; |
| 211 | } else { |
| 212 | language = 'typescript'; |
| 213 | } |
| 214 | let transformOutput; |
| 215 | |
| 216 | let baseOpts: PluginOptions | null = null; |
| 217 | try { |
| 218 | baseOpts = parseOptions(source, mode, configOverrides); |
| 219 | } catch (err) { |
| 220 | error.details.push( |
| 221 | new CompilerErrorDetail({ |
| 222 | category: ErrorCategory.Config, |
| 223 | reason: `Unexpected failure when transforming configs! \n${err}`, |
| 224 | loc: null, |
| 225 | suggestions: null, |
| 226 | }), |
| 227 | ); |
| 228 | } |
| 229 | if (baseOpts) { |
| 230 | try { |
| 231 | const logIR = (result: CompilerPipelineValue): void => { |
| 232 | switch (result.kind) { |
| 233 | case 'ast': { |
| 234 | break; |
| 235 | } |
| 236 | case 'hir': { |
| 237 | upsert({ |
| 238 | kind: 'hir', |
| 239 | fnName: result.value.id, |
| 240 | name: result.name, |
| 241 | value: printFunctionWithOutlined(result.value), |
| 242 | }); |
| 243 | break; |
| 244 | } |
| 245 | case 'reactive': { |
| 246 | upsert({ |
| 247 | kind: 'reactive', |
| 248 | fnName: result.value.id, |
| 249 | name: result.name, |
no test coverage detected