diff --git a/src/language-html/utils.js b/src/language-html/utils.js index e4ad67118e50..8863c1e64f63 100644 --- a/src/language-html/utils.js +++ b/src/language-html/utils.js @@ -365,8 +365,18 @@ function hasNonTextChild(node) { } function _inferScriptParser(node) { - const { type, lang } = node.attrMap; + if (node.name !== "script") { + return; + } + + const { type, lang, src } = node.attrMap; + + if (src) { + return; + } + if ( + (!lang && !type) || type === "module" || type === "text/javascript" || type === "text/babel" || @@ -398,6 +408,10 @@ function _inferScriptParser(node) { } function inferStyleParser(node) { + if (node.name !== "style") { + return; + } + const { lang } = node.attrMap; if (!lang || lang === "postcss" || lang === "css") { return "css"; @@ -413,24 +427,13 @@ function inferStyleParser(node) { } function inferScriptParser(node, options) { - if (node.name === "script" && !node.attrMap.src) { - if (!node.attrMap.lang && !node.attrMap.type) { - return "babel"; - } - return _inferScriptParser(node); - } + let parser = _inferScriptParser(node) || inferStyleParser(node); - if (node.name === "style") { - return inferStyleParser(node); + if (!parser && options && isVueNonHtmlBlock(node, options)) { + parser = getParserName(node.attrMap.lang, options); } - if (options && isVueNonHtmlBlock(node, options)) { - return ( - _inferScriptParser(node) || - inferStyleParser(node) || - getParserName(node.attrMap.lang, options) - ); - } + return parser; } function isBlockLikeCssDisplay(cssDisplay) { diff --git a/tests/vue/custom_block/__snapshots__/jsfmt.spec.js.snap b/tests/vue/custom_block/__snapshots__/jsfmt.spec.js.snap index 80e2b4bb4d50..e0c79c45a9bc 100644 --- a/tests/vue/custom_block/__snapshots__/jsfmt.spec.js.snap +++ b/tests/vue/custom_block/__snapshots__/jsfmt.spec.js.snap @@ -1438,9 +1438,11 @@ const foo = "foo"; 123 -{ - foo: "bar" -} + + { + foo: "bar"; +} + ================================================================================ `; @@ -1501,9 +1503,11 @@ const foo = "foo"; 123 -{ - foo: "bar" -} + + { + foo: "bar"; +} + ================================================================================ `; @@ -1564,9 +1568,11 @@ const foo = "foo"; 123 -{ - foo: "bar" -} + + { + foo: "bar"; +} + ================================================================================ `; @@ -1626,9 +1632,11 @@ const foo = "foo"; 123 -{ - foo: "bar" -} + + { + foo: "bar"; +} + ================================================================================ `;