printer-notifications/node_modules/svelte-eslint-parser/lib/parser/resolve-parser.js
2023-11-13 16:10:04 -05:00

35 lines
1.2 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getParser = exports.getParserForLang = void 0;
const espree_1 = require("./espree");
const parser_object_1 = require("./parser-object");
/** Get parser for script lang */
function getParserForLang(attrs, parser) {
if (parser) {
if (typeof parser === "string" || (0, parser_object_1.isParserObject)(parser)) {
return parser;
}
if (typeof parser === "object") {
const value = parser[attrs.lang || "js"];
if (typeof value === "string" || (0, parser_object_1.isParserObject)(value)) {
return value;
}
}
}
return "espree";
}
exports.getParserForLang = getParserForLang;
/** Get parser */
function getParser(attrs, parser) {
const parserValue = getParserForLang(attrs, parser);
if ((0, parser_object_1.isParserObject)(parserValue)) {
return parserValue;
}
if (parserValue !== "espree") {
// eslint-disable-next-line @typescript-eslint/no-require-imports -- ignore
return require(parserValue);
}
return (0, espree_1.getEspree)();
}
exports.getParser = getParser;