prettier-plugin-astro
Advanced tools
Comparing version 0.8.0 to 0.8.1
@@ -6,2 +6,3 @@ 'use strict'; | ||
var _doc = require('prettier/doc'); | ||
var node_buffer = require('node:buffer'); | ||
var sassFormatter = require('sass-formatter'); | ||
@@ -596,7 +597,41 @@ | ||
if (node.type === 'frontmatter') { | ||
const frontmatterContent = wrapParserTryCatch(textToDoc, node.value, { | ||
const textContent = node.value.replace(/\breturn\b/g, '___astro_return;throw'); | ||
const frontmatterContent = wrapParserTryCatch(textToDoc, textContent, { | ||
...opts, | ||
parser: 'typescript', | ||
}); | ||
return [group(['---', hardline, frontmatterContent, '---', hardline]), hardline]; | ||
const frontmatterDoc = mapDoc(frontmatterContent, (doc) => { | ||
if (typeof doc === 'string') { | ||
return doc.replace(/___astro_return;throw/g, 'return'); | ||
} | ||
if (Array.isArray(doc)) { | ||
const parts = []; | ||
for (const p of doc) { | ||
if (Array.isArray(p)) { | ||
parts.push(...p); | ||
} | ||
else { | ||
parts.push(p); | ||
} | ||
} | ||
for (let i = parts.length - 1; i > 0; i--) { | ||
if (parts[i] === 'throw') { | ||
for (let j = i - 1; j >= 0; j--) { | ||
if (parts[j] === '___astro_return') { | ||
parts[i] = 'return'; | ||
parts.splice(j, i - j); | ||
i = j; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
return parts; | ||
} | ||
if ('parts' in doc) { | ||
return doc.parts; | ||
} | ||
return doc; | ||
}); | ||
return [group(['---', hardline, frontmatterDoc, '---', hardline]), hardline]; | ||
} | ||
@@ -647,3 +682,3 @@ if (node.type === 'element' && node.name === 'script') { | ||
function expressionParser(text, parsers, options) { | ||
const ast = parsers['babel-ts'](text, options); | ||
const ast = parsers['babel-ts'](text, parsers, options); | ||
return { | ||
@@ -751,3 +786,5 @@ ...ast, | ||
if (node) { | ||
return options.originalText.slice(options.locStart(node), options.locEnd(node)); | ||
return node_buffer.Buffer.from(options.originalText) | ||
.subarray(options.locStart(node), options.locEnd(node)) | ||
.toString(); | ||
} | ||
@@ -754,0 +791,0 @@ return null; |
{ | ||
"name": "prettier-plugin-astro", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"type": "commonjs", | ||
@@ -5,0 +5,0 @@ "description": "A Prettier Plugin for formatting Astro files", |
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
106098
837