prettier-plugin-marko
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -45,2 +45,3 @@ var __create = Object.create; | ||
const { builders: b } = import_prettier.doc; | ||
const identity = (val) => val; | ||
const languages = [ | ||
@@ -424,20 +425,20 @@ { | ||
case "var": { | ||
const doc2 = toDoc(`var ${node.code}=_`, { parser: opts.markoScriptParser }, { stripTrailingHardline: true }); | ||
return doc2[0].contents[1].contents[0]; | ||
return tryPrintEmbed(`var ${node.code}=_`, opts.markoScriptParser, (doc2) => doc2[0].contents[1].contents[0]); | ||
} | ||
case "params": { | ||
const doc2 = toDoc(`(${node.code})=>_`, { parser: "__js_expression" }, { stripTrailingHardline: true }); | ||
const { contents } = doc2.contents[0]; | ||
if (Array.isArray(contents) && contents[0] === "(") { | ||
return contents.slice(1, -1); | ||
} | ||
return contents; | ||
return tryPrintEmbed(`(${node.code})=>_`, "__js_expression", (doc2) => { | ||
const { contents } = doc2.contents[0]; | ||
if (Array.isArray(contents) && contents[0] === "(") { | ||
return contents.slice(1, -1); | ||
} | ||
return contents; | ||
}); | ||
} | ||
case "script": | ||
return toDoc(node.code, { parser: opts.markoScriptParser }, { stripTrailingHardline: true }); | ||
return tryPrintEmbed(node.code, opts.markoScriptParser); | ||
default: { | ||
if (!node.mode.startsWith("style.")) { | ||
throw new Error(`Invalid Marko Embed mode: ${node.mode}`); | ||
return [b.trim, (0, import_as_literal_text_content.default)(node.code)]; | ||
} | ||
return toDoc(node.code, { parser: node.mode.slice("style.".length) }, { stripTrailingHardline: true }); | ||
return tryPrintEmbed(node.code, node.mode.slice("style.".length)); | ||
} | ||
@@ -456,6 +457,13 @@ } | ||
if (import_compiler.types.isStatement(node)) { | ||
return (0, import_with_line_if_needed.default)(node, opts, toDoc((0, import_get_original_code.default)(opts, node), { parser: opts.markoScriptParser }, { stripTrailingHardline: true })); | ||
return tryPrintEmbed((0, import_get_original_code.default)(opts, node), opts.markoScriptParser); | ||
} else { | ||
return toDoc((0, import_get_original_code.default)(opts, node), { parser: "__js_expression" }, { stripTrailingHardline: true }); | ||
return tryPrintEmbed((0, import_get_original_code.default)(opts, node), "__js_expression"); | ||
} | ||
function tryPrintEmbed(code, parser, normalize = identity) { | ||
try { | ||
return normalize(toDoc(code, { parser }, { stripTrailingHardline: true })); | ||
} catch { | ||
return [b.trim, (0, import_as_literal_text_content.default)(code)]; | ||
} | ||
} | ||
} | ||
@@ -462,0 +470,0 @@ } |
{ | ||
"name": "prettier-plugin-marko", | ||
"description": "A prettier plugin for parsing and printing Marko files", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"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
72157
1764