prettier-plugin-svelte
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "prettier-plugin-svelte", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Svelte plugin for prettier", | ||
@@ -5,0 +5,0 @@ "main": "plugin.js", |
@@ -260,2 +260,3 @@ 'use strict'; | ||
let isFirst = true; | ||
const childNodes = path.getValue().children; | ||
path.each(childPath => { | ||
@@ -268,5 +269,28 @@ const child = childPath.getValue(); | ||
} | ||
if (!(isFirst && skipFirst) && child.type !== 'Text' && child.type !== 'MustacheTag') { | ||
children.push(hardline); | ||
if (!(isFirst && skipFirst)) { | ||
if (isInlineNode(child)) { | ||
if (!isEmptyNode(child)) { | ||
let lineType = softline; | ||
if (child.type === 'Text') { | ||
if (/^\s+/.test(child.data)) { | ||
// Remove leading spaces | ||
child.data = trimStart(child.data); | ||
if (!isFirst) { | ||
lineType = line; | ||
} | ||
} | ||
} | ||
children.push(lineType); | ||
} | ||
} | ||
else { | ||
children.push(hardline); | ||
} | ||
} | ||
if (child.type === 'Text') { | ||
if (isLastNode(childNodes, filter, index)) { | ||
// Remove trailing spaces | ||
child.data = trimEnd(child.data); | ||
} | ||
} | ||
children.push(childPath.call(print)); | ||
@@ -285,2 +309,22 @@ isFirst = false; | ||
} | ||
function isInlineNode(node) { | ||
return node.type === 'Text' || node.type === 'MustacheTag'; | ||
} | ||
function isEmptyNode(node) { | ||
return node.type === 'Text' && node.data.trim() === ''; | ||
} | ||
function isLastNode(nodes, filter, index) { | ||
for (let i = index + 1; i < nodes.length; i++) { | ||
if (filter(nodes[i], i)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function trimStart(text) { | ||
return text.replace(/^\s+/, ''); | ||
} | ||
function trimEnd(text) { | ||
return text.replace(/\s+$/, ''); | ||
} | ||
@@ -287,0 +331,0 @@ const { builders: { concat: concat$1, hardline: hardline$1 }, utils: { removeLines }, } = prettier.doc; |
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
47158
413