(options, opts = {})
| 20 | |
| 21 | // Copy options and fill in default values. |
| 22 | async function normalizeFormatOptions(options, opts = {}) { |
| 23 | const rawOptions = { ...options }; |
| 24 | |
| 25 | if (!rawOptions.parser) { |
| 26 | if (!rawOptions.filepath) { |
| 27 | throw new UndefinedParserError( |
| 28 | "No parser and no file path given, couldn't infer a parser.", |
| 29 | ); |
| 30 | } |
| 31 | |
| 32 | rawOptions.parser = inferParser(rawOptions, { |
| 33 | physicalFile: rawOptions.filepath, |
| 34 | }); |
| 35 | |
| 36 | if (!rawOptions.parser) { |
| 37 | throw new UndefinedParserError( |
| 38 | `No parser could be inferred for file "${rawOptions.filepath}".`, |
| 39 | ); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | const supportOptions = getSupportInfo({ |
| 44 | plugins: options.plugins, |
| 45 | showDeprecated: true, |
| 46 | }).options; |
| 47 | |
| 48 | const defaults = { |
| 49 | ...formatOptionsHiddenDefaults, |
| 50 | ...Object.fromEntries( |
| 51 | supportOptions |
| 52 | .filter((optionInfo) => optionInfo.default !== undefined) |
| 53 | .map((option) => [option.name, option.default]), |
| 54 | ), |
| 55 | }; |
| 56 | |
| 57 | const parserPlugin = getParserPluginByParserName( |
| 58 | rawOptions.plugins, |
| 59 | rawOptions.parser, |
| 60 | ); |
| 61 | |
| 62 | const parser = await initParser(parserPlugin, rawOptions.parser); |
| 63 | rawOptions.astFormat = parser.astFormat; |
| 64 | rawOptions.locEnd = parser.locEnd; |
| 65 | rawOptions.locStart = parser.locStart; |
| 66 | |
| 67 | const printerPlugin = parserPlugin.printers?.[parser.astFormat] |
| 68 | ? parserPlugin |
| 69 | : getPrinterPluginByAstFormat(rawOptions.plugins, parser.astFormat); |
| 70 | const printer = await initPrinter(printerPlugin, parser.astFormat); |
| 71 | |
| 72 | rawOptions.printer = printer; |
| 73 | rawOptions.getVisitorKeys = printer.getVisitorKeys; |
| 74 | |
| 75 | const pluginDefaults = printerPlugin.defaultOptions |
| 76 | ? Object.fromEntries( |
| 77 | Object.entries(printerPlugin.defaultOptions).filter( |
| 78 | ([, value]) => value !== undefined, |
| 79 | ), |
no test coverage detected
searching dependent graphs…