prettier-plugin-svelte
Advanced tools
Comparing version 1.4.0 to 1.4.1
# prettier-plugin-svelte changelog | ||
## 1.4.1 | ||
* Format next node correctly when previous node has a comment as last child ([#152](https://github.com/sveltejs/prettier-plugin-svelte/issues/152)) | ||
* Only `prettier-ignore` comments should ignore formatting of next line ([#151](https://github.com/sveltejs/prettier-plugin-svelte/issues/151)) | ||
* Do not encode entities in attribute values ([#29](https://github.com/sveltejs/prettier-plugin-svelte/issues/29)) | ||
* Fix raw printing of unsupported languages ([#156](https://github.com/sveltejs/prettier-plugin-svelte/issues/156)) | ||
## 1.4.0 | ||
@@ -4,0 +11,0 @@ |
{ | ||
"name": "prettier-plugin-svelte", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "Svelte plugin for prettier", | ||
@@ -5,0 +5,0 @@ "main": "plugin.js", |
@@ -246,3 +246,3 @@ 'use strict'; | ||
case 'Text': | ||
const text = node.raw || node.data; | ||
const text = getUnencodedText(node); | ||
const isAllWhitespace = text.trim() === ''; | ||
@@ -278,28 +278,12 @@ return !isAllWhitespace || text === ''; | ||
/** | ||
* Returns the next sibling node. | ||
* Did there use to be any embedded object (that has been snipped out of the AST to be moved) | ||
* at the specified position? | ||
*/ | ||
function getNextNode(path) { | ||
const node = path.getNode(); | ||
let parent = path.getParentNode(); | ||
if (isASTNode(parent)) { | ||
parent = parent.html; | ||
} | ||
return getChildren(parent).find((child) => child.start === node.end); | ||
} | ||
/** | ||
* Returns the position that used to be the end of the node before the embed elements were cut out. | ||
*/ | ||
function getNodeEnd(node, path) { | ||
function doesEmbedStartAt(position, path) { | ||
const root = path.stack[0]; | ||
if (root.html === node) { | ||
return Math.max(...[root.css, root.html, root.instance, root.js, root.module] | ||
.filter((n) => !!n) | ||
.map((n) => n.end)); | ||
} | ||
else { | ||
return node.end; | ||
} | ||
const embeds = [root.css, root.html, root.instance, root.js, root.module]; | ||
return embeds.find((n) => n && n.start === position) != null; | ||
} | ||
function isEmptyNode(node) { | ||
return node.type === 'Text' && (node.raw || node.data).trim() === ''; | ||
return node.type === 'Text' && getUnencodedText(node).trim() === ''; | ||
} | ||
@@ -309,10 +293,9 @@ function isIgnoreDirective(node) { | ||
} | ||
function printRaw(node) { | ||
const children = node.children; | ||
if (children) { | ||
return children.map(printRaw).join(''); | ||
function printRaw(node, originalText) { | ||
if (node.children.length === 0) { | ||
return ''; | ||
} | ||
else { | ||
return node.raw || ''; | ||
} | ||
const firstChild = node.children[0]; | ||
const lastChild = node.children[node.children.length - 1]; | ||
return originalText.substring(firstChild.start, lastChild.end); | ||
} | ||
@@ -338,3 +321,3 @@ function isTextNode(node) { | ||
function getLangAttribute(node) { | ||
const value = getAttributeTextValue('lang', node); | ||
const value = getAttributeTextValue('lang', node) || getAttributeTextValue('type', node); | ||
if (value != null) { | ||
@@ -375,2 +358,6 @@ return value.replace(/^text\//, ''); | ||
} | ||
function getUnencodedText(node) { | ||
// `raw` will contain HTML entities in unencoded form | ||
return node.raw || node.data; | ||
} | ||
@@ -538,3 +525,3 @@ function isLine(doc) { | ||
*/ | ||
keepIfLonely: /\n\r?\s*\n\r?/.test(node.raw || node.data) }); | ||
keepIfLonely: /\n\r?\s*\n\r?/.test(getUnencodedText(node)) }); | ||
} | ||
@@ -547,6 +534,6 @@ /** | ||
*/ | ||
return fill(splitTextToDocs(node.raw || node.data)); | ||
return fill(splitTextToDocs(getUnencodedText(node))); | ||
} | ||
else { | ||
return node.data; | ||
return getUnencodedText(node); | ||
} | ||
@@ -572,3 +559,3 @@ case 'Element': | ||
else if (!isSupportedLanguage) { | ||
body = printRaw(node); | ||
body = printRaw(node, options$$1.originalText); | ||
} | ||
@@ -804,6 +791,6 @@ else if (isInlineElement(node) || isPreTagContent(path)) { | ||
*/ | ||
if (node.end < getNodeEnd(path.getParentNode(), path) && !getNextNode(path)) { | ||
if (doesEmbedStartAt(node.end, path)) { | ||
return ''; | ||
} | ||
else { | ||
else if (isIgnoreDirective(node)) { | ||
ignoreNext = true; | ||
@@ -810,0 +797,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
138760
1198