Skip to content

Commit

Permalink
Update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Aug 25, 2020
1 parent 481ea90 commit b4c262f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
35 changes: 19 additions & 16 deletions src/language-html/utils.js
Expand Up @@ -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" ||
Expand Down Expand Up @@ -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";
Expand All @@ -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) {
Expand Down
32 changes: 20 additions & 12 deletions tests/vue/custom_block/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -1438,9 +1438,11 @@ const foo = "foo";
<custom lang="zzz">123</custom>
<custom>{
foo: "bar"
}</custom>
<custom>
{
foo: "bar";
}
</custom>
================================================================================
`;
Expand Down Expand Up @@ -1501,9 +1503,11 @@ const foo = "foo";
<custom lang="zzz">123</custom>
<custom>{
foo: "bar"
}</custom>
<custom>
{
foo: "bar";
}
</custom>
================================================================================
`;
Expand Down Expand Up @@ -1564,9 +1568,11 @@ const foo = "foo";
<custom lang="zzz">123</custom>
<custom>{
foo: "bar"
}</custom>
<custom>
{
foo: "bar";
}
</custom>
================================================================================
`;
Expand Down Expand Up @@ -1626,9 +1632,11 @@ const foo = "foo";
<custom lang="zzz">123</custom>
<custom>{
foo: "bar"
}</custom>
<custom>
{
foo: "bar";
}
</custom>
================================================================================
`;
Expand Down

0 comments on commit b4c262f

Please sign in to comment.