Skip to content

Commit

Permalink
feat: apply top-level indent to any nested && embedded language
Browse files Browse the repository at this point in the history
  • Loading branch information
Justineo committed Apr 25, 2019
1 parent 029e91d commit c282dc7
Show file tree
Hide file tree
Showing 17 changed files with 268 additions and 2,685 deletions.
13 changes: 8 additions & 5 deletions src/language-html/printer-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,14 @@ function genericPrint(path, options, print) {
? ifBreak(indent(childrenDoc), childrenDoc, {
groupId: attrGroupId
})
: node.parent.type === "root" &&
((options.htmlTopLevelIndent === "auto" &&
isScriptLikeTag(node) &&
options.parser === "vue") ||
options.htmlTopLevelIndent === "never")
: (options.htmlTopLevelIndent === "auto" &&
options.parser === "vue" &&
node.parent.type === "root" &&
isScriptLikeTag(node)) ||
(options.htmlTopLevelIndent === "never" &&
((options.parser === "vue" &&
node.parent.type === "root") ||
isScriptLikeTag(node)))
? childrenDoc
: indent(childrenDoc))(
concat([
Expand Down
23 changes: 2 additions & 21 deletions tests/html_aurelia/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,6 @@ printWidth: 80
exports[`basic.html 2`] = `
====================================options=====================================
htmlTopLevelIndent: "auto"
parsers: ["html"]
printWidth: 80
| printWidth
=====================================input======================================
<template>
<i class.bind="icon"></i>
</template>
=====================================output=====================================
<template>
<i class.bind="icon"></i>
</template>
================================================================================
`;
exports[`basic.html 3`] = `
====================================options=====================================
htmlTopLevelIndent: "always"
parsers: ["html"]
printWidth: 80
Expand All @@ -56,7 +37,7 @@ printWidth: 80
================================================================================
`;
exports[`basic.html 4`] = `
exports[`basic.html 3`] = `
====================================options=====================================
htmlTopLevelIndent: "never"
parsers: ["html"]
Expand All @@ -69,7 +50,7 @@ printWidth: 80
=====================================output=====================================
<template>
<i class.bind="icon"></i>
<i class.bind="icon"></i>
</template>
================================================================================
Expand Down
1 change: 0 additions & 1 deletion tests/html_aurelia/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
run_spec(__dirname, ["html"]);
run_spec(__dirname, ["html"], { htmlTopLevelIndent: "auto" });
run_spec(__dirname, ["html"], { htmlTopLevelIndent: "always" });
run_spec(__dirname, ["html"], { htmlTopLevelIndent: "never" });

0 comments on commit c282dc7

Please sign in to comment.