| 15 | * @returns {ParseResult} the parsed result |
| 16 | */ |
| 17 | const acornParse = (sourceCode, options) => { |
| 18 | /** @type {(Comment & { start: number, end: number, loc: SourceLocation })[]} */ |
| 19 | const comments = []; |
| 20 | /** @type {Semicolons} */ |
| 21 | const semicolons = new Set(); |
| 22 | |
| 23 | const ast = |
| 24 | /** @type {import("estree").Program} */ |
| 25 | ( |
| 26 | acorn.parse(sourceCode, { |
| 27 | ...options, |
| 28 | onComment: options.comments ? comments : undefined, |
| 29 | onInsertedSemicolon: options.semicolons |
| 30 | ? // Set semicolons |
| 31 | /** |
| 32 | * @param {number} pos a position of semicolon |
| 33 | * @returns {Semicolons} set with semicolon positions |
| 34 | */ |
| 35 | (pos) => semicolons.add(pos) |
| 36 | : undefined |
| 37 | }) |
| 38 | ); |
| 39 | |
| 40 | return { ast, comments, semicolons }; |
| 41 | }; |
| 42 | |
| 43 | module.exports = acornParse; |