prettier 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -1
- data/CONTRIBUTING.md +2 -2
- data/README.md +1 -1
- data/package.json +2 -2
- data/src/{ruby.js → plugin.js} +2 -2
- data/src/{embed.js → ruby/embed.js} +2 -2
- data/src/{nodes.js → ruby/nodes.js} +0 -0
- data/src/{nodes → ruby/nodes}/alias.js +1 -1
- data/src/{nodes → ruby/nodes}/aref.js +8 -1
- data/src/{nodes → ruby/nodes}/args.js +2 -2
- data/src/{nodes → ruby/nodes}/arrays.js +2 -3
- data/src/{nodes → ruby/nodes}/assign.js +7 -3
- data/src/{nodes → ruby/nodes}/blocks.js +3 -3
- data/src/{nodes → ruby/nodes}/calls.js +8 -4
- data/src/{nodes → ruby/nodes}/case.js +1 -1
- data/src/{nodes → ruby/nodes}/class.js +1 -1
- data/src/ruby/nodes/commands.js +126 -0
- data/src/{nodes → ruby/nodes}/conditionals.js +3 -3
- data/src/{nodes → ruby/nodes}/constants.js +2 -2
- data/src/{nodes → ruby/nodes}/flow.js +2 -2
- data/src/{nodes → ruby/nodes}/hashes.js +32 -10
- data/src/{nodes → ruby/nodes}/heredocs.js +2 -2
- data/src/{nodes → ruby/nodes}/hooks.js +2 -2
- data/src/{nodes → ruby/nodes}/ints.js +0 -0
- data/src/{nodes → ruby/nodes}/lambdas.js +2 -2
- data/src/{nodes → ruby/nodes}/loops.js +10 -7
- data/src/{nodes → ruby/nodes}/massign.js +8 -1
- data/src/{nodes → ruby/nodes}/methods.js +6 -3
- data/src/{nodes → ruby/nodes}/operators.js +2 -2
- data/src/{nodes → ruby/nodes}/params.js +9 -2
- data/src/{nodes → ruby/nodes}/patterns.js +8 -1
- data/src/{nodes → ruby/nodes}/regexp.js +2 -2
- data/src/{nodes → ruby/nodes}/rescue.js +2 -2
- data/src/{nodes → ruby/nodes}/return.js +21 -6
- data/src/{nodes → ruby/nodes}/statements.js +1 -1
- data/src/{nodes → ruby/nodes}/strings.js +1 -1
- data/src/{nodes → ruby/nodes}/super.js +2 -2
- data/src/{nodes → ruby/nodes}/undef.js +1 -1
- data/src/{parser.js → ruby/parser.js} +2 -2
- data/src/{parser.rb → ruby/parser.rb} +258 -312
- data/src/{printer.js → ruby/printer.js} +1 -1
- data/src/{toProc.js → ruby/toProc.js} +0 -0
- data/src/utils.js +10 -93
- data/src/utils/containsAssignment.js +11 -0
- data/src/utils/getTrailingComma.js +5 -0
- data/src/utils/hasAncestor.js +17 -0
- data/src/utils/literal.js +7 -0
- data/src/utils/makeCall.js +11 -0
- data/src/utils/noIndent.js +10 -0
- data/src/utils/skipAssignIndent.js +10 -0
- metadata +47 -40
- data/src/nodes/commands.js +0 -91
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0630719fd8b07b6f6fc180db0c88a5d2d2f0aad3d4cdeef4f14aeba83a87d2f1'
|
4
|
+
data.tar.gz: 925d6a78992ae155cb65ccd336ec34c3cda7538421151d91952a31461718be2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8e07ba6fd2839a1c055ec42b08c2f35a92b912a555c227bb644ea91afec560feaa27318df72dfda1023ffbe7a65c446f4ea1ba97ec6202a617d4622abcdbb4b
|
7
|
+
data.tar.gz: 7ef40ccd4d7bc5f3b521070402b1a592706d60cb19edfc3072ab45c9086e954f0f4b801a260e8ccb76efbede4b227ca07e4a6e7c1bd670b230b56b0ff01c3496
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.2.3] - 2021-01-02
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
- [@lukyth], [@kddeisz] - Ensure if a ternary breaks into an `if..else..end` within a `command_call` node that parentheses are added.
|
14
|
+
- [@AlanFoster], [@kddeisz] - Ensure you consume the optional `do` keyword on `while` and `until` loops so that it doesn't confuse the parser.
|
15
|
+
- [@AlanFoster], [@kddeisz] - Ensure key-value pairs split on line when the key has a comment attached within a hash.
|
16
|
+
- [@AlanFoster], [@kddeisz] - Fix for `for` loops that have multiple index variables.
|
17
|
+
- [@AlanFoster], [@kddeisz] - Fix parsing very large files by reducing the size of the JSON output from the parser.
|
18
|
+
- [@AlanFoster], [@kddeisz] - Ensure you don't skip parentheses if you're returning a value with the `not` unary operator.
|
19
|
+
|
9
20
|
## [1.2.2] - 2021-01-01
|
10
21
|
|
11
22
|
### Changed
|
@@ -998,7 +1009,8 @@ would previously result in `array[]`, but now prints properly.
|
|
998
1009
|
|
999
1010
|
- Initial release 🎉
|
1000
1011
|
|
1001
|
-
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.2.
|
1012
|
+
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.2.3...HEAD
|
1013
|
+
[1.2.3]: https://github.com/prettier/plugin-ruby/compare/v1.2.2...v1.2.3
|
1002
1014
|
[1.2.2]: https://github.com/prettier/plugin-ruby/compare/v1.2.1...v1.2.2
|
1003
1015
|
[1.2.1]: https://github.com/prettier/plugin-ruby/compare/v1.2.0...v1.2.1
|
1004
1016
|
[1.2.0]: https://github.com/prettier/plugin-ruby/compare/v1.1.0...v1.2.0
|
@@ -1096,6 +1108,7 @@ would previously result in `array[]`, but now prints properly.
|
|
1096
1108
|
[@kmcq]: https://github.com/kmcq
|
1097
1109
|
[@krachtstefan]: https://github.com/krachtstefan
|
1098
1110
|
[@localhostdotdev]: https://github.com/localhostdotdev
|
1111
|
+
[@lukyth]: https://github.com/lukyth
|
1099
1112
|
[@marcmaniez]: https://github.com/MarcManiez
|
1100
1113
|
[@masqita]: https://github.com/masqita
|
1101
1114
|
[@matt-wratt]: https://github.com/matt-wratt
|
data/CONTRIBUTING.md
CHANGED
@@ -22,7 +22,7 @@ In order to get printed, the code goes through a couple of transformations. The
|
|
22
22
|
|
23
23
|
### Text to AST
|
24
24
|
|
25
|
-
When the prettier process first spins up, it examines which files it's going to print and selects an appropriate plugin for each one. Once selected, it runs that plugin's `parse` function, seen [here](src/parser.js). For the case of the Ruby plugin, that entails spawning a Ruby process that runs [parser.rb](src/parser.rb) with the input code preloaded on stdin.
|
25
|
+
When the prettier process first spins up, it examines which files it's going to print and selects an appropriate plugin for each one. Once selected, it runs that plugin's `parse` function, seen [here](src/ruby/parser.js). For the case of the Ruby plugin, that entails spawning a Ruby process that runs [parser.rb](src/ruby/parser.rb) with the input code preloaded on stdin.
|
26
26
|
|
27
27
|
`parser.rb` will read the text off of stdin and then feed it to a new `Ripper` instance, which is a Ruby standard library recursive-descent parser. Briefly, the way that `Ripper` works is by tokenizing the input and then matching those tokens against a grammar to form s-expressions. To extend `Ripper`, you overwrite the methods that control how those s-expressions are formed, e.g., to modify the s-expression that is formed when `Ripper` encounters a string literal, you would override the `#on_string_literal` method. Below is an example for seeing that in action.
|
28
28
|
|
@@ -71,7 +71,7 @@ Now that the text has been transformed into an AST that we can work with, `parse
|
|
71
71
|
|
72
72
|
### AST to Doc
|
73
73
|
|
74
|
-
Once prettier has a working AST, it will take it and call the selected plugin's [`printNode` function](src/printer.js), whose purpose is to convert that AST into prettier's intermediate representation called Docs. It does this by handing the print function a `FastPath` object that keeps track of the state of the printing as it goes, and allows accessing various parts of the AST quickly.
|
74
|
+
Once prettier has a working AST, it will take it and call the selected plugin's [`printNode` function](src/ruby/printer.js), whose purpose is to convert that AST into prettier's intermediate representation called Docs. It does this by handing the print function a `FastPath` object that keeps track of the state of the printing as it goes, and allows accessing various parts of the AST quickly.
|
75
75
|
|
76
76
|
Effectively, it walks the AST in the reverse direction from the way `Ripper` built it (top-down instead of bottom-up). The first node that gets passed into the `print` function is the `program` node as that's always on top. Then it is the `program` node's responsibility to recursively call print on its child nodes as it best sees fit.
|
77
77
|
|
data/README.md
CHANGED
@@ -120,7 +120,7 @@ The `prettier` executable is now installed and ready for use:
|
|
120
120
|
|
121
121
|
## Configuration
|
122
122
|
|
123
|
-
Below are the options (from [`src/
|
123
|
+
Below are the options (from [`src/plugin.js`](src/plugin.js)) that `@prettier/plugin-ruby` currently supports:
|
124
124
|
|
125
125
|
| API Option | CLI Option | Default | Description |
|
126
126
|
| ------------------ | ---------------------- | :-----: | ------------------------------------------------------------------------------------------------------------------------------------ |
|
data/package.json
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prettier/plugin-ruby",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.3",
|
4
4
|
"description": "prettier plugin for the Ruby programming language",
|
5
|
-
"main": "src/
|
5
|
+
"main": "src/plugin.js",
|
6
6
|
"scripts": {
|
7
7
|
"check-format": "prettier --check '**/*'",
|
8
8
|
"lint": "eslint --cache .",
|
data/src/{ruby.js → plugin.js}
RENAMED
@@ -6,9 +6,9 @@ const {
|
|
6
6
|
mapDoc,
|
7
7
|
markAsRoot,
|
8
8
|
stripTrailingHardline
|
9
|
-
} = require("
|
9
|
+
} = require("../prettier");
|
10
10
|
|
11
|
-
const { literalLineNoBreak } = require("
|
11
|
+
const { literalLineNoBreak } = require("../utils");
|
12
12
|
|
13
13
|
const parsers = {
|
14
14
|
css: "css",
|
File without changes
|
@@ -1,4 +1,11 @@
|
|
1
|
-
const {
|
1
|
+
const {
|
2
|
+
concat,
|
3
|
+
group,
|
4
|
+
indent,
|
5
|
+
join,
|
6
|
+
line,
|
7
|
+
softline
|
8
|
+
} = require("../../prettier");
|
2
9
|
|
3
10
|
// `aref` nodes are when you're pulling a value out of a collection at a
|
4
11
|
// specific index. Put another way, it's any time you're calling the method
|
@@ -6,10 +6,10 @@ const {
|
|
6
6
|
join,
|
7
7
|
line,
|
8
8
|
softline
|
9
|
-
} = require("
|
9
|
+
} = require("../../prettier");
|
10
|
+
const { getTrailingComma } = require("../../utils");
|
10
11
|
|
11
12
|
const toProc = require("../toProc");
|
12
|
-
const { getTrailingComma } = require("../utils");
|
13
13
|
|
14
14
|
function printArgParen(path, opts, print) {
|
15
15
|
const argsNode = path.getValue().body[0];
|
@@ -6,9 +6,8 @@ const {
|
|
6
6
|
join,
|
7
7
|
line,
|
8
8
|
softline
|
9
|
-
} = require("
|
10
|
-
|
11
|
-
const { getTrailingComma, printEmptyCollection } = require("../utils");
|
9
|
+
} = require("../../prettier");
|
10
|
+
const { getTrailingComma, printEmptyCollection } = require("../../utils");
|
12
11
|
|
13
12
|
// Checks that every argument within this args node is a string_literal node
|
14
13
|
// that has no spaces or interpolations. This means we're dealing with an array
|
@@ -1,5 +1,5 @@
|
|
1
|
-
const { concat, group, indent, join, line } = require("
|
2
|
-
const {
|
1
|
+
const { concat, group, indent, join, line } = require("../../prettier");
|
2
|
+
const { skipAssignIndent } = require("../../utils");
|
3
3
|
|
4
4
|
function printAssign(path, opts, print) {
|
5
5
|
const [_targetNode, valueNode] = path.getValue().body;
|
@@ -35,9 +35,13 @@ function printVarField(path, opts, print) {
|
|
35
35
|
return path.getValue().body ? path.call(print, "body", 0) : "";
|
36
36
|
}
|
37
37
|
|
38
|
+
function printVarRef(path, opts, print) {
|
39
|
+
return path.call(print, "body", 0);
|
40
|
+
}
|
41
|
+
|
38
42
|
module.exports = {
|
39
43
|
assign: printAssign,
|
40
44
|
opassign: printOpAssign,
|
41
45
|
var_field: printVarField,
|
42
|
-
var_ref:
|
46
|
+
var_ref: printVarRef
|
43
47
|
};
|
@@ -7,8 +7,8 @@ const {
|
|
7
7
|
join,
|
8
8
|
removeLines,
|
9
9
|
softline
|
10
|
-
} = require("
|
11
|
-
const {
|
10
|
+
} = require("../../prettier");
|
11
|
+
const { hasAncestor } = require("../../utils");
|
12
12
|
|
13
13
|
const printBlock = (braces) => (path, opts, print) => {
|
14
14
|
const [variables, statements] = path.getValue().body;
|
@@ -81,5 +81,5 @@ module.exports = {
|
|
81
81
|
},
|
82
82
|
brace_block: printBlock(true),
|
83
83
|
do_block: printBlock(false),
|
84
|
-
excessed_comma:
|
84
|
+
excessed_comma: () => ""
|
85
85
|
};
|
@@ -5,8 +5,8 @@ const {
|
|
5
5
|
ifBreak,
|
6
6
|
indent,
|
7
7
|
softline
|
8
|
-
} = require("
|
9
|
-
const {
|
8
|
+
} = require("../../prettier");
|
9
|
+
const { makeCall, noIndent } = require("../../utils");
|
10
10
|
|
11
11
|
const toProc = require("../toProc");
|
12
12
|
|
@@ -217,10 +217,14 @@ function printMethodAddBlock(path, opts, print) {
|
|
217
217
|
return concat([callDoc, blockDoc]);
|
218
218
|
}
|
219
219
|
|
220
|
+
function printCallContainer(path, opts, print) {
|
221
|
+
return path.call(print, "body", 0);
|
222
|
+
}
|
223
|
+
|
220
224
|
module.exports = {
|
221
225
|
call: printCall,
|
222
|
-
fcall:
|
226
|
+
fcall: printCallContainer,
|
223
227
|
method_add_arg: printMethodAddArg,
|
224
228
|
method_add_block: printMethodAddBlock,
|
225
|
-
vcall:
|
229
|
+
vcall: printCallContainer
|
226
230
|
};
|
@@ -0,0 +1,126 @@
|
|
1
|
+
const {
|
2
|
+
align,
|
3
|
+
concat,
|
4
|
+
group,
|
5
|
+
ifBreak,
|
6
|
+
indent,
|
7
|
+
join,
|
8
|
+
line,
|
9
|
+
softline
|
10
|
+
} = require("../../prettier");
|
11
|
+
const { makeCall } = require("../../utils");
|
12
|
+
|
13
|
+
function docLength(doc) {
|
14
|
+
if (doc.length) {
|
15
|
+
return doc.length;
|
16
|
+
}
|
17
|
+
|
18
|
+
if (doc.parts) {
|
19
|
+
return doc.parts.reduce((sum, child) => sum + docLength(child), 0);
|
20
|
+
}
|
21
|
+
|
22
|
+
if (doc.contents) {
|
23
|
+
return docLength(doc.contents);
|
24
|
+
}
|
25
|
+
|
26
|
+
return 0;
|
27
|
+
}
|
28
|
+
|
29
|
+
function hasDef(node) {
|
30
|
+
return (
|
31
|
+
node.body[1].type === "args_add_block" &&
|
32
|
+
node.body[1].body[0].type === "args" &&
|
33
|
+
node.body[1].body[0].body[0] &&
|
34
|
+
["def", "defs"].includes(node.body[1].body[0].body[0].type)
|
35
|
+
);
|
36
|
+
}
|
37
|
+
|
38
|
+
// Very special handling case for rspec matchers. In general with rspec matchers
|
39
|
+
// you expect to see something like:
|
40
|
+
//
|
41
|
+
// expect(foo).to receive(:bar).with(
|
42
|
+
// 'one',
|
43
|
+
// 'two',
|
44
|
+
// 'three',
|
45
|
+
// 'four',
|
46
|
+
// 'five'
|
47
|
+
// )
|
48
|
+
//
|
49
|
+
// In this case the arguments are aligned to the left side as opposed to being
|
50
|
+
// aligned with the `receive` call.
|
51
|
+
function skipArgsAlign(path) {
|
52
|
+
return ["to", "not_to"].includes(path.getValue().body[2].body);
|
53
|
+
}
|
54
|
+
|
55
|
+
// If there is a ternary argument to a command and it's going to get broken
|
56
|
+
// into multiple lines, then we're going to have to use parentheses around the
|
57
|
+
// command in order to make sure operator precedence doesn't get messed up.
|
58
|
+
function hasTernaryArg(node) {
|
59
|
+
return node.body[0].body.some((child) => child.type === "ifop");
|
60
|
+
}
|
61
|
+
|
62
|
+
function printCommand(path, opts, print) {
|
63
|
+
const node = path.getValue();
|
64
|
+
|
65
|
+
const command = path.call(print, "body", 0);
|
66
|
+
const joinedArgs = join(concat([",", line]), path.call(print, "body", 1));
|
67
|
+
|
68
|
+
const hasTernary = hasTernaryArg(node.body[1]);
|
69
|
+
let breakArgs;
|
70
|
+
|
71
|
+
if (hasTernary) {
|
72
|
+
breakArgs = indent(concat([softline, joinedArgs]));
|
73
|
+
} else if (hasDef(path.getValue())) {
|
74
|
+
breakArgs = joinedArgs;
|
75
|
+
} else {
|
76
|
+
breakArgs = align(command.length + 1, joinedArgs);
|
77
|
+
}
|
78
|
+
|
79
|
+
return group(
|
80
|
+
ifBreak(
|
81
|
+
concat([
|
82
|
+
command,
|
83
|
+
hasTernary ? "(" : " ",
|
84
|
+
breakArgs,
|
85
|
+
hasTernary ? concat([softline, ")"]) : ""
|
86
|
+
]),
|
87
|
+
concat([command, " ", joinedArgs])
|
88
|
+
)
|
89
|
+
);
|
90
|
+
}
|
91
|
+
|
92
|
+
function printCommandCall(path, opts, print) {
|
93
|
+
const node = path.getValue();
|
94
|
+
const parts = [
|
95
|
+
path.call(print, "body", 0),
|
96
|
+
makeCall(path, opts, print),
|
97
|
+
path.call(print, "body", 2)
|
98
|
+
];
|
99
|
+
|
100
|
+
if (!node.body[3]) {
|
101
|
+
return concat(parts);
|
102
|
+
}
|
103
|
+
|
104
|
+
const argDocs = join(concat([",", line]), path.call(print, "body", 3));
|
105
|
+
let breakDoc;
|
106
|
+
|
107
|
+
if (hasTernaryArg(node.body[3])) {
|
108
|
+
parts.push("(");
|
109
|
+
breakDoc = parts.concat(indent(concat([softline, argDocs])), softline, ")");
|
110
|
+
} else if (skipArgsAlign(path)) {
|
111
|
+
parts.push(" ");
|
112
|
+
breakDoc = parts.concat(argDocs);
|
113
|
+
} else {
|
114
|
+
parts.push(" ");
|
115
|
+
breakDoc = parts.concat(align(docLength(concat(parts)), argDocs));
|
116
|
+
}
|
117
|
+
|
118
|
+
const joinedDoc = parts.concat(argDocs);
|
119
|
+
|
120
|
+
return group(ifBreak(concat(breakDoc), concat(joinedDoc)));
|
121
|
+
}
|
122
|
+
|
123
|
+
module.exports = {
|
124
|
+
command: printCommand,
|
125
|
+
command_call: printCommandCall
|
126
|
+
};
|
@@ -7,10 +7,10 @@ const {
|
|
7
7
|
ifBreak,
|
8
8
|
indent,
|
9
9
|
softline
|
10
|
-
} = require("
|
10
|
+
} = require("../../prettier");
|
11
11
|
|
12
|
-
const { containsAssignment, isEmptyStmts } = require("
|
13
|
-
const inlineEnsureParens = require("
|
12
|
+
const { containsAssignment, isEmptyStmts } = require("../../utils");
|
13
|
+
const inlineEnsureParens = require("../../utils/inlineEnsureParens");
|
14
14
|
|
15
15
|
const printWithAddition = (keyword, path, print, { breaking = false } = {}) =>
|
16
16
|
concat([
|
@@ -1,5 +1,5 @@
|
|
1
|
-
const { concat, group, indent, join, softline } = require("
|
2
|
-
const { makeCall } = require("
|
1
|
+
const { concat, group, indent, join, softline } = require("../../prettier");
|
2
|
+
const { makeCall } = require("../../utils");
|
3
3
|
|
4
4
|
function printConstPath(path, opts, print) {
|
5
5
|
return join("::", path.map(print, "body"));
|
@@ -1,11 +1,16 @@
|
|
1
|
-
const {
|
2
|
-
|
1
|
+
const {
|
2
|
+
concat,
|
3
|
+
group,
|
4
|
+
ifBreak,
|
5
|
+
indent,
|
6
|
+
join,
|
7
|
+
line
|
8
|
+
} = require("../../prettier");
|
3
9
|
const {
|
4
10
|
getTrailingComma,
|
5
|
-
prefix,
|
6
11
|
printEmptyCollection,
|
7
12
|
skipAssignIndent
|
8
|
-
} = require("
|
13
|
+
} = require("../../utils");
|
9
14
|
|
10
15
|
// When attempting to convert a hash rocket into a hash label, you need to take
|
11
16
|
// care because only certain patterns are allowed. Ruby source says that they
|
@@ -49,8 +54,20 @@ function printHashKeyLabel(path, print) {
|
|
49
54
|
return print(path);
|
50
55
|
case "symbol_literal":
|
51
56
|
return concat([path.call(print, "body", 0), ":"]);
|
52
|
-
case "dyna_symbol":
|
53
|
-
|
57
|
+
case "dyna_symbol": {
|
58
|
+
const { parts } = print(path);
|
59
|
+
|
60
|
+
// We're going to slice off the starting colon character so that we can
|
61
|
+
// move it to the end. If there are comments, then we're going to go
|
62
|
+
// further into the printed doc nodes.
|
63
|
+
if (parts[0] === ":") {
|
64
|
+
parts.splice(0, 1);
|
65
|
+
} else {
|
66
|
+
parts[1].parts.splice(0, 1);
|
67
|
+
}
|
68
|
+
|
69
|
+
return concat(parts.concat(":"));
|
70
|
+
}
|
54
71
|
}
|
55
72
|
}
|
56
73
|
|
@@ -66,20 +83,25 @@ function printHashKeyRocket(path, print) {
|
|
66
83
|
}
|
67
84
|
|
68
85
|
function printAssocNew(path, opts, print) {
|
86
|
+
const [keyNode, valueNode] = path.getValue().body;
|
69
87
|
const { keyPrinter } = path.getParentNode();
|
70
88
|
|
71
89
|
const parts = [path.call((keyPath) => keyPrinter(keyPath, print), "body", 0)];
|
72
90
|
const valueDoc = path.call(print, "body", 1);
|
73
91
|
|
74
|
-
if (skipAssignIndent(
|
75
|
-
parts.push(" ", valueDoc);
|
76
|
-
} else {
|
92
|
+
if (!skipAssignIndent(valueNode) || keyNode.comments) {
|
77
93
|
parts.push(indent(concat([line, valueDoc])));
|
94
|
+
} else {
|
95
|
+
parts.push(" ", valueDoc);
|
78
96
|
}
|
79
97
|
|
80
98
|
return group(concat(parts));
|
81
99
|
}
|
82
100
|
|
101
|
+
function printAssocSplat(path, opts, print) {
|
102
|
+
return concat(["**", path.call(print, "body", 0)]);
|
103
|
+
}
|
104
|
+
|
83
105
|
function printHashContents(path, opts, print) {
|
84
106
|
const node = path.getValue();
|
85
107
|
|
@@ -121,7 +143,7 @@ function printHash(path, opts, print) {
|
|
121
143
|
|
122
144
|
module.exports = {
|
123
145
|
assoc_new: printAssocNew,
|
124
|
-
assoc_splat:
|
146
|
+
assoc_splat: printAssocSplat,
|
125
147
|
assoclist_from_args: printHashContents,
|
126
148
|
bare_assoc_hash: printHashContents,
|
127
149
|
hash: printHash
|