prettier-plugin-svelte
Advanced tools
Comparing version 2.0.2 to 2.0.3
# prettier-plugin-svelte changelog | ||
## 2.0.3 | ||
* When `svelteBracketNewLine` is set to `false`, don't print the closing `>` in a separate line if possible ([#183](https://github.com/sveltejs/prettier-plugin-svelte/issues/183)) | ||
## 2.0.2 | ||
@@ -4,0 +8,0 @@ |
{ | ||
"name": "prettier-plugin-svelte", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Svelte plugin for prettier", | ||
@@ -5,0 +5,0 @@ "main": "plugin.js", |
@@ -612,2 +612,29 @@ 'use strict'; | ||
} | ||
/** | ||
* Returns true if the softline between `</tagName` and `>` can be omitted. | ||
*/ | ||
function canOmitSoftlineBeforeClosingTag(node, path, options) { | ||
return (!options.svelteBracketNewLine && | ||
(!hugsStartOfNextNode(node, options) || isLastChildWithinParentBlockElement(path))); | ||
} | ||
/** | ||
* Return true if given node does not hug the next node, meaning there's whitespace | ||
* or the end of the doc afterwards. | ||
*/ | ||
function hugsStartOfNextNode(node, options) { | ||
if (node.end === options.originalText.length) { | ||
// end of document | ||
return false; | ||
} | ||
return !options.originalText.substring(node.end).match(/^\s/); | ||
} | ||
function isLastChildWithinParentBlockElement(path) { | ||
const parent = path.getParentNode(); | ||
if (!parent || !isBlockElement(parent)) { | ||
return false; | ||
} | ||
const children = getChildren(parent); | ||
const lastChild = children[children.length - 1]; | ||
return lastChild === path.getNode(); | ||
} | ||
@@ -781,3 +808,6 @@ const { concat, join, line, group, indent, dedent, softline, hardline, fill, breakParent, literalline, } = prettier.doc.builders; | ||
group(indent(concat([softline, groupConcat(['>', body(), `</${node.name}`])]))), | ||
isEmpty && options.svelteBracketNewLine ? '' : softline, | ||
(isEmpty && options.svelteBracketNewLine) || | ||
canOmitSoftlineBeforeClosingTag(node, path, options) | ||
? '' | ||
: softline, | ||
'>', | ||
@@ -828,3 +858,3 @@ ]); | ||
group(indent(concat([noHugSeparatorStart, groupConcat([body(), `</${node.name}`])]))), | ||
softline, | ||
canOmitSoftlineBeforeClosingTag(node, path, options) ? '' : '', | ||
'>', | ||
@@ -831,0 +861,0 @@ ]); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
197539
1640