@rawwee/prettier-plugin-twig-melody
Version:
Prettier Plugin for Twig/Melody (Enhanced Fork)
25 lines (22 loc) • 633 B
JavaScript
const prettier = require("prettier");
const { concat, group } = prettier.doc.builders;
const {
EXPRESSION_NEEDED,
STRING_NEEDS_QUOTES,
wrapExpressionIfNeeded
} = require("../util");
const p = (node, path, print) => {
node[EXPRESSION_NEEDED] = false;
node[STRING_NEEDS_QUOTES] = true;
const parts = [path.call(print, "object")];
parts.push(node.computed ? "[" : ".");
parts.push(path.call(print, "property"));
if (node.computed) {
parts.push("]");
}
wrapExpressionIfNeeded(path, parts, node);
return group(concat(parts));
};
module.exports = {
printMemberExpression: p
};