(originalText, options)
| 2 | import { resolveParser } from "./parser-and-printer.js"; |
| 3 | |
| 4 | async function parse(originalText, options) { |
| 5 | const parser = await resolveParser(options); |
| 6 | const text = parser.preprocess |
| 7 | ? await parser.preprocess(originalText, options) |
| 8 | : originalText; |
| 9 | options.originalText = text; |
| 10 | |
| 11 | let ast; |
| 12 | try { |
| 13 | ast = await parser.parse( |
| 14 | text, |
| 15 | options, |
| 16 | // TODO: remove the third argument in v4 |
| 17 | // The duplicated argument is passed as intended, see #10156 |
| 18 | options, |
| 19 | ); |
| 20 | } catch (error) { |
| 21 | handleParseError(error, originalText); |
| 22 | } |
| 23 | |
| 24 | return { text, ast }; |
| 25 | } |
| 26 | |
| 27 | function handleParseError(error, text) { |
| 28 | const { loc } = error; |
nothing calls this directly
no test coverage detected
searching dependent graphs…