MCPcopy
hub / github.com/webpack/webpack / acornParse

Function acornParse

examples/custom-javascript-parser/internals/acorn-parse.js:17–41  ·  view source on GitHub ↗
(sourceCode, options)

Source from the content-addressed store, hash-verified

15 * @returns {ParseResult} the parsed result
16 */
17const 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
43module.exports = acornParse;

Callers 1

bench.mjsFile · 0.85

Calls 2

parseMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected