Simplify inferParserByLanguage (#14437)
This commit is contained in:
1 parent
432976de11
commit
f8fed37dc7
4 files changed
+10
-7
No files matched your search
@@ -87,7 +87,7 @@ function ngHtmlParser(
|
||||
return false;
|
||||
}
|
||||
const language = node.attrs.find((attr) => attr.name === "lang")?.value;
|
||||
return !language || inferParserByLanguage(language, options) === "html";
|
||||
return !language || inferParserByLanguage(options, language) === "html";
|
||||
};
|
||||
if (rootNodes.some(shouldParseAsHTML)) {
|
||||
/** @type {ParserTreeResult | undefined} */
|
||||
|
||||
@@ -386,7 +386,7 @@ function inferStyleParser(node, options) {
|
||||
// But, we need to handle `"stylus"` here for printing a style block in Vue SFC as stylus code by external plugin.
|
||||
// https://github.com/prettier/prettier/pull/12707
|
||||
if (lang === "stylus") {
|
||||
return inferParserByLanguage("stylus", options);
|
||||
return inferParserByLanguage(options, "stylus");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,7 +406,7 @@ function inferScriptParser(node, options) {
|
||||
return (
|
||||
_inferScriptParser(node) ||
|
||||
(!("src" in node.attrMap) &&
|
||||
inferParserByLanguage(node.attrMap.lang, options))
|
||||
inferParserByLanguage(options, node.attrMap.lang))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ function embed(path, options) {
|
||||
const { node } = path;
|
||||
|
||||
if (node.type === "code" && node.lang !== null) {
|
||||
const parser = inferParserByLanguage(node.lang, options);
|
||||
const parser = inferParserByLanguage(options, node.lang);
|
||||
if (parser) {
|
||||
return async (textToDoc) => {
|
||||
const styleUnit = options.__inJsTemplate ? "~" : "`";
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { getSupportInfo } from "../main/support.js";
|
||||
function inferParserByLanguage(options, language) {
|
||||
if (!language) {
|
||||
return;
|
||||
}
|
||||
|
||||
const languages = options.plugins.flatMap((plugin) => plugin.languages ?? []);
|
||||
|
||||
function inferParserByLanguage(language, options) {
|
||||
const { languages } = getSupportInfo({ plugins: options.plugins });
|
||||
const matched =
|
||||
languages.find(({ name }) => name.toLowerCase() === language) ??
|
||||
languages.find(({ aliases }) => aliases?.includes(language)) ??
|
||||
|
||||
Reference in new issue
Block a user