Permalink
Browse files

Internal refactor to list nodes

  • Loading branch information...
kddeisz committed Feb 12, 2019
1 parent 1d684ea commit 19718b7ce11ab854305eaa744cbf1b2b10ec8ec3
Showing with 13 additions and 7 deletions.
  1. +2 −0 CHANGELOG.md
  2. +3 −3 src/nodes.js
  3. +2 −1 src/nodes/regexp.js
  4. +3 −3 src/nodes/strings.js
  5. +3 −0 src/utils.js
@@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- [INTERNAL] Provide the `makeList` utility for the nodes that are lists from within ripper.

## [0.4.0] - 2019-02-12
### Added
@@ -1,5 +1,5 @@
const { align, breakParent, concat, dedent, dedentToRoot, group, hardline, ifBreak, indent, join, line, lineSuffix, literalline, markAsRoot, softline, trim } = require("prettier").doc.builders;
const { concatBody, empty, first, literal, makeCall, prefix, printComments, skipAssignIndent, surround } = require("./utils");
const { concatBody, empty, first, literal, makeCall, makeList, prefix, printComments, skipAssignIndent, surround } = require("./utils");

module.exports = {
...require("./nodes/alias"),
@@ -380,7 +380,7 @@ module.exports = {
},
method_add_block: (path, opts, print) => concat(path.map(print, "body")),
methref: (path, opts, print) => join(".:", path.map(print, "body")),
mlhs: (path, opts, print) => path.map(print, "body"),
mlhs: makeList,
mlhs_add_post: (path, opts, print) => [
...path.call(print, "body", 0),
...path.call(print, "body", 1)
@@ -394,7 +394,7 @@ module.exports = {
indent(concat([softline, join(concat([",", line]), path.call(print, "body", 0))])),
concat([softline, ")"])
])),
mrhs: (path, opts, print) => path.map(print, "body"),
mrhs: makeList,
mrhs_add_star: (path, opts, print) => group(join(
concat([",", line]),
[
@@ -1,7 +1,8 @@
const { concat, group, indent, softline } = require("prettier").doc.builders;
const { makeList } = require("../utils");

module.exports = {
regexp: (path, opts, print) => path.map(print, "body"),
regexp: makeList,
regexp_literal: (path, opts, print) => {
const [contents, ending] = path.map(print, "body");
const useBraces = contents.some(content => typeof content === "string" && content.includes("/"));
@@ -1,5 +1,5 @@
const { concat, group, hardline, indent, join, line, softline } = require("prettier").doc.builders;
const { concatBody, empty, surround } = require("../utils");
const { concatBody, empty, makeList, surround } = require("../utils");

// Matches _any_ escape and unescaped quotes (both single and double).
const quotePattern = /\\([\s\S])|(['"])/g;
@@ -46,7 +46,7 @@ module.exports = {
ending
]);
},
string: (path, opts, print) => path.map(print, "body"),
string: makeList,
string_concat: (path, opts, print) => group(concat([
path.call(print, "body", 0),
" \\",
@@ -92,7 +92,7 @@ module.exports = {
},
word_add: concatBody,
word_new: empty,
xstring: (path, opts, print) => path.map(print, "body"),
xstring: makeList,
xstring_literal: (path, opts, print) => group(concat([
"`",
indent(concat([softline, join(softline, path.call(print, "body", 0))])),
@@ -18,6 +18,8 @@ const makeCall = (path, opts, print) => {
return operation === "::" ? "." : path.call(print, "body", 1);
};

const makeList = (path, opts, print) => path.map(print, "body");

const prefix = value => (path, opts, print) => concat([
value,
path.call(print, "body", 0)
@@ -64,6 +66,7 @@ module.exports = {
first,
literal,
makeCall,
makeList,
prefix,
printComments,
skipAssignIndent,

0 comments on commit 19718b7

Please sign in to comment.