This commit is contained in:
2026-11-02 12:42:04 +00:00
commit e4e28174bf
5498 changed files with 1735888 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
import { getEspree } from "./espree.js";
import { isParserObject } from "./parser-object.js";
import Module from "module";
/** Get parser for script lang */
export function getParserForLang(lang, parser) {
if (parser) {
if (typeof parser === "string" || isParserObject(parser)) {
return parser;
}
if (typeof parser === "object") {
const value = parser[lang || "js"];
if (typeof value === "string" || isParserObject(value)) {
return value;
}
}
}
return "espree";
}
/** Get parser */
export function getParser(attrs, parser) {
const parserValue = getParserForLang(attrs.lang, parser);
if (isParserObject(parserValue)) {
return parserValue;
}
if (parserValue !== "espree") {
const require = Module.createRequire(import.meta.url);
return require(parserValue);
}
return getEspree();
}