prettier-plugin-marko
Advanced tools
Comparing version 1.4.6 to 1.4.7
@@ -268,3 +268,4 @@ "use strict"; | ||
function withParensIfNeeded(node, opts, getValDoc) { | ||
if (!enclosedNodeTypeReg.test(node.type) && outerCodeMatches( | ||
var _a, _b; | ||
if (((_a = node.leadingComments) == null ? void 0 : _a.length) || ((_b = node.trailingComments) == null ? void 0 : _b.length) || !enclosedNodeTypeReg.test(node.type) && outerCodeMatches( | ||
import_prettier3.doc.printer.printDocToString(getValDoc(), { | ||
@@ -318,5 +319,3 @@ ...opts, | ||
function getOriginalCodeForNode(opts, node) { | ||
const literal = literalToString(node); | ||
if (literal !== void 0) | ||
return literal; | ||
var _a, _b; | ||
const loc = node.loc; | ||
@@ -331,6 +330,17 @@ if (!loc) { | ||
} | ||
return opts.originalText.slice( | ||
locToPos(loc.start, opts), | ||
locToPos(loc.end, opts) | ||
); | ||
let start = loc.start; | ||
if ((_a = node.leadingComments) == null ? void 0 : _a.length) { | ||
const commentStart = node.leadingComments[0].loc.start; | ||
if (commentStart.line < start.line || commentStart.line === start.line && commentStart.column < start.column) { | ||
start = commentStart; | ||
} | ||
} | ||
let end = loc.end; | ||
if ((_b = node.trailingComments) == null ? void 0 : _b.length) { | ||
const commentEnd = node.trailingComments[node.trailingComments.length - 1].loc.end; | ||
if (commentEnd.line > end.line || commentEnd.line === end.line && commentEnd.column > end.column) { | ||
end = commentEnd; | ||
} | ||
} | ||
return opts.originalText.slice(locToPos(start, opts), locToPos(end, opts)); | ||
} | ||
@@ -340,14 +350,2 @@ function getOriginalCodeForList(opts, sep, list) { | ||
} | ||
function literalToString(node) { | ||
switch (node.type) { | ||
case "StringLiteral": | ||
return `"${node.value.replace(/(["\\])/g, "\\$1")}"`; | ||
case "NumericLiteral": | ||
return node.value.toString(); | ||
case "BooleanLiteral": | ||
return node.value ? "true" : "false"; | ||
case "NullLiteral": | ||
return "null"; | ||
} | ||
} | ||
@@ -360,4 +358,12 @@ // src/index.ts | ||
var expressionParser = (code, parsers2, options2) => { | ||
const ast = parsers2["babel-ts"](`(${code});`, options2); | ||
return { ...ast, program: ast.program.body[0].expression }; | ||
const ast = parsers2["babel-ts"](code, options2); | ||
const { tokens, comments, range } = ast; | ||
const node = ast.program.body[0].expression; | ||
return { | ||
type: "JsExpressionRoot", | ||
tokens, | ||
comments, | ||
node, | ||
range | ||
}; | ||
}; | ||
@@ -889,3 +895,3 @@ var languages = [ | ||
return tryPrintEmbed( | ||
`(${node.code})=>_`, | ||
toExpression(`(${node.code})=>_`), | ||
expressionParser, | ||
@@ -914,3 +920,3 @@ (doc6) => { | ||
return toDoc( | ||
`class ${getOriginalCodeForNode(opts, node.body)}`, | ||
toExpression(`class ${getOriginalCodeForNode(opts, node.body)}`), | ||
{ parser: expressionParser }, | ||
@@ -934,3 +940,3 @@ { stripTrailingHardline: true } | ||
return tryPrintEmbed( | ||
getOriginalCodeForNode(opts, node), | ||
toExpression(getOriginalCodeForNode(opts, node)), | ||
expressionParser | ||
@@ -980,2 +986,6 @@ ); | ||
} | ||
function toExpression(code) { | ||
return `(${code} | ||
)`; | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -982,0 +992,0 @@ 0 && (module.exports = { |
{ | ||
"name": "prettier-plugin-marko", | ||
"description": "A prettier plugin for parsing and printing Marko files", | ||
"version": "1.4.6", | ||
"version": "1.4.7", | ||
"author": "Dylan Piercey <dpiercey@ebay.com>", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/marko-js/prettier/issues", |
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
72042
1984