/
githubmirror
/
webpack
Обзор
Документация
Войти
/
githubmirror
/
webpack
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
examples/custom-javascript-parser/internals/acorn-parse.js
32 строки
925 B
Alexander Akait
refactor: derive ASI positions from source instead of acorn callback (#21453)
19 июл 2026, 23:58
Не верифицирован
19 июл 2026, 23:58
e4a217e
Код
Авторство
О чём код?
"use strict"; const acorn = require("acorn"); /** @typedef {import("estree").Program} Program */ /** @typedef {import("estree").Comment} Comment */ /** @typedef {import("estree").SourceLocation} SourceLocation */ /** @typedef {import("../../../lib/javascript/JavascriptParser").ParseOptions} ParseOptions */ /** @typedef {import("../../../lib/javascript/JavascriptParser").ParseResult} ParseResult */ /** * @param {string} sourceCode the source code * @param {ParseOptions} options options * @returns {ParseResult} the parsed result */ const acornParse = (sourceCode, options) => { /** @type {(Comment & { start: number, end: number, loc: SourceLocation })[]} */ const comments = []; const ast = /** @type {import("estree").Program} */ ( acorn.parse(sourceCode, { ...options, onComment: options.comments ? comments : undefined }) ); return { ast, comments }; }; module.exports = acornParse;