Skip to content

Commit

Permalink
Internal refactor to list nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Feb 12, 2019
1 parent 1d684ea commit 19718b7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/nodes.js
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down Expand Up @@ -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)
Expand All @@ -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]),
[
Expand Down
3 changes: 2 additions & 1 deletion src/nodes/regexp.js
Original file line number Diff line number Diff line change
@@ -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("/"));
Expand Down
6 changes: 3 additions & 3 deletions src/nodes/strings.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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),
" \\",
Expand Down Expand Up @@ -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))])),
Expand Down
3 changes: 3 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -64,6 +66,7 @@ module.exports = {
first,
literal,
makeCall,
makeList,
prefix,
printComments,
skipAssignIndent,
Expand Down

0 comments on commit 19718b7

Please sign in to comment.