/
githubmirror
/
webpack
Обзор
Документация
Войти
/
githubmirror
/
webpack
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
examples/custom-javascript-parser/internals/meriyah-parse.js
48 строк
1 KB
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 meriyah = require("meriyah"); /** @typedef {import("estree").Program} Program */ /** @typedef {import("estree").Node} Node */ /** @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 meriyahParse = (sourceCode, options) => { /** @type {(Comment & { start: number, end: number, loc: SourceLocation })[]} */ const comments = []; const ast = /** @type {import("estree").Program} */ ( meriyah.parse(sourceCode, { ...options, module: options.sourceType === "module", loc: options.locations, onComment: options.comments ? (type, value, start, end, loc) => { if (type === "SingleLine" || type === "MultiLine") { comments.push({ type: type === "SingleLine" ? "Line" : "Block", value, start, end, range: [start, end], loc }); } } : undefined }) ); return { ast, comments }; }; module.exports = meriyahParse;