prettier 2.0.0.pre.rc3 → 2.1.0
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 +46 -4
- data/dist/haml/parser.rb +6 -0
- data/dist/parser/getInfo.js +9 -2
- data/dist/parser/parseSync.js +53 -16
- data/dist/parser/server.rb +6 -2
- data/dist/rbs/parser.rb +59 -2
- data/dist/rbs/printer.js +14 -6
- data/dist/ruby/embed.js +10 -5
- data/dist/ruby/location.js +19 -0
- data/dist/ruby/nodes/alias.js +6 -5
- data/dist/ruby/nodes/aref.js +4 -6
- data/dist/ruby/nodes/args.js +29 -56
- data/dist/ruby/nodes/arrays.js +31 -35
- data/dist/ruby/nodes/assign.js +19 -23
- data/dist/ruby/nodes/blocks.js +18 -15
- data/dist/ruby/nodes/calls.js +33 -30
- data/dist/ruby/nodes/case.js +8 -8
- data/dist/ruby/nodes/class.js +13 -13
- data/dist/ruby/nodes/commands.js +36 -22
- data/dist/ruby/nodes/conditionals.js +56 -52
- data/dist/ruby/nodes/constants.js +10 -13
- data/dist/ruby/nodes/flow.js +39 -46
- data/dist/ruby/nodes/hashes.js +26 -30
- data/dist/ruby/nodes/heredocs.js +9 -9
- data/dist/ruby/nodes/hooks.js +2 -2
- data/dist/ruby/nodes/ints.js +5 -5
- data/dist/ruby/nodes/lambdas.js +7 -6
- data/dist/ruby/nodes/loops.js +26 -24
- data/dist/ruby/nodes/massign.js +22 -35
- data/dist/ruby/nodes/methods.js +20 -40
- data/dist/ruby/nodes/operators.js +26 -28
- data/dist/ruby/nodes/params.js +31 -25
- data/dist/ruby/nodes/patterns.js +52 -42
- data/dist/ruby/nodes/regexp.js +6 -6
- data/dist/ruby/nodes/rescue.js +28 -24
- data/dist/ruby/nodes/return.js +61 -36
- data/dist/ruby/nodes/statements.js +24 -25
- data/dist/ruby/nodes/strings.js +36 -34
- data/dist/ruby/nodes/super.js +6 -10
- data/dist/ruby/nodes/undef.js +19 -14
- data/dist/ruby/nodes.js +47 -21
- data/dist/ruby/parser.js +3 -2
- data/dist/ruby/parser.rb +8470 -2972
- data/dist/ruby/printer.js +9 -71
- data/dist/ruby/toProc.js +33 -35
- data/dist/types.js +5 -1
- data/dist/utils/containsAssignment.js +5 -2
- data/dist/utils/getChildNodes.js +305 -0
- data/dist/utils/inlineEnsureParens.js +1 -1
- data/dist/utils/isEmptyBodyStmt.js +1 -1
- data/dist/utils/isEmptyParams.js +12 -0
- data/dist/utils/isEmptyStmts.js +1 -1
- data/dist/utils/makeCall.js +5 -4
- data/dist/utils/printEmptyCollection.js +3 -1
- data/dist/utils/skipAssignIndent.js +6 -2
- data/dist/utils.js +5 -3
- data/exe/rbprettier +1 -2
- data/lib/prettier.rb +37 -5
- data/node_modules/prettier/bin-prettier.js +48 -18924
- data/node_modules/prettier/cli.js +12335 -0
- data/node_modules/prettier/doc.js +1306 -4755
- data/node_modules/prettier/index.js +37468 -57614
- data/node_modules/prettier/package.json +3 -2
- data/node_modules/prettier/parser-angular.js +2 -66
- data/node_modules/prettier/parser-babel.js +27 -22
- data/node_modules/prettier/parser-espree.js +26 -22
- data/node_modules/prettier/parser-flow.js +26 -22
- data/node_modules/prettier/parser-glimmer.js +27 -1
- data/node_modules/prettier/parser-graphql.js +15 -1
- data/node_modules/prettier/parser-html.js +21 -117
- data/node_modules/prettier/parser-markdown.js +61 -19
- data/node_modules/prettier/parser-meriyah.js +19 -22
- data/node_modules/prettier/parser-postcss.js +76 -22
- data/node_modules/prettier/parser-typescript.js +280 -22
- data/node_modules/prettier/parser-yaml.js +150 -15
- data/node_modules/prettier/third-party.js +8660 -11030
- data/package.json +8 -8
- data/rubocop.yml +9 -3
- metadata +9 -5
data/dist/ruby/nodes/hashes.js
CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.printHash = exports.printHashContents = exports.printAssocSplat = exports.
|
6
|
+
exports.printHash = exports.printHashContents = exports.printAssocSplat = exports.printAssoc = void 0;
|
7
7
|
const prettier_1 = __importDefault(require("../../prettier"));
|
8
8
|
const utils_1 = require("../../utils");
|
9
9
|
const { group, ifBreak, indent, join, line } = prettier_1.default;
|
@@ -18,19 +18,19 @@ const { group, ifBreak, indent, join, line } = prettier_1.default;
|
|
18
18
|
// This function represents that check, as it determines if it can convert the
|
19
19
|
// symbol node into a hash label.
|
20
20
|
function isValidHashLabel(symbolLiteral) {
|
21
|
-
const label = symbolLiteral.
|
21
|
+
const label = symbolLiteral.value.value;
|
22
22
|
return label.match(/^[_A-Za-z]/) && !label.endsWith("=");
|
23
23
|
}
|
24
24
|
function canUseHashLabels(contentsNode) {
|
25
|
-
return contentsNode.
|
25
|
+
return contentsNode.assocs.every((assocNode) => {
|
26
26
|
if (assocNode.type === "assoc_splat") {
|
27
27
|
return true;
|
28
28
|
}
|
29
|
-
switch (assocNode.
|
30
|
-
case "
|
29
|
+
switch (assocNode.key.type) {
|
30
|
+
case "label":
|
31
31
|
return true;
|
32
32
|
case "symbol_literal":
|
33
|
-
return isValidHashLabel(assocNode.
|
33
|
+
return isValidHashLabel(assocNode.key);
|
34
34
|
case "dyna_symbol":
|
35
35
|
return true;
|
36
36
|
default:
|
@@ -41,12 +41,10 @@ function canUseHashLabels(contentsNode) {
|
|
41
41
|
const printHashKeyLabel = (path, print) => {
|
42
42
|
const node = path.getValue();
|
43
43
|
switch (node.type) {
|
44
|
-
case "
|
44
|
+
case "label":
|
45
45
|
return print(path);
|
46
|
-
case "symbol_literal":
|
47
|
-
|
48
|
-
return [nodePath.call(print, "body", 0), ":"];
|
49
|
-
}
|
46
|
+
case "symbol_literal":
|
47
|
+
return [path.call(print, "value"), ":"];
|
50
48
|
case "dyna_symbol":
|
51
49
|
return [print(path), ":"];
|
52
50
|
default:
|
@@ -58,7 +56,7 @@ const printHashKeyLabel = (path, print) => {
|
|
58
56
|
const printHashKeyRocket = (path, print) => {
|
59
57
|
const node = path.getValue();
|
60
58
|
let doc = print(path);
|
61
|
-
if (node.type === "
|
59
|
+
if (node.type === "label") {
|
62
60
|
const sDoc = doc; // since we know this is a label
|
63
61
|
doc = [":", sDoc.slice(0, sDoc.length - 1)];
|
64
62
|
}
|
@@ -67,18 +65,18 @@ const printHashKeyRocket = (path, print) => {
|
|
67
65
|
}
|
68
66
|
return [doc, " =>"];
|
69
67
|
};
|
70
|
-
const
|
71
|
-
const
|
68
|
+
const printAssoc = (path, opts, print) => {
|
69
|
+
const node = path.getValue();
|
72
70
|
const { keyPrinter } = path.getParentNode();
|
73
|
-
const parts = [path.call((keyPath) => keyPrinter(keyPath, print), "
|
74
|
-
const valueDoc = path.call(print, "
|
71
|
+
const parts = [path.call((keyPath) => keyPrinter(keyPath, print), "key")];
|
72
|
+
const valueDoc = path.call(print, "value");
|
75
73
|
// If we're printing a child hash then we want it to break along with its
|
76
74
|
// parent hash, so we don't group the parts.
|
77
|
-
if (
|
75
|
+
if (node.value.type === "hash") {
|
78
76
|
parts.push(" ", valueDoc);
|
79
77
|
return parts;
|
80
78
|
}
|
81
|
-
if (!(0, utils_1.skipAssignIndent)(
|
79
|
+
if (!(0, utils_1.skipAssignIndent)(node.value) || node.key.comments) {
|
82
80
|
parts.push(indent([line, valueDoc]));
|
83
81
|
}
|
84
82
|
else {
|
@@ -86,10 +84,8 @@ const printAssocNew = (path, opts, print) => {
|
|
86
84
|
}
|
87
85
|
return group(parts);
|
88
86
|
};
|
89
|
-
exports.
|
90
|
-
const printAssocSplat = (path, opts, print) =>
|
91
|
-
return ["**", path.call(print, "body", 0)];
|
92
|
-
};
|
87
|
+
exports.printAssoc = printAssoc;
|
88
|
+
const printAssocSplat = (path, opts, print) => ["**", path.call(print, "value")];
|
93
89
|
exports.printAssocSplat = printAssocSplat;
|
94
90
|
const printHashContents = (path, opts, print) => {
|
95
91
|
const node = path.getValue();
|
@@ -99,22 +95,22 @@ const printHashContents = (path, opts, print) => {
|
|
99
95
|
opts.rubyHashLabel && canUseHashLabels(path.getValue())
|
100
96
|
? printHashKeyLabel
|
101
97
|
: printHashKeyRocket;
|
102
|
-
return join([",", line], path.map(print, "
|
98
|
+
return join([",", line], path.map(print, "assocs"));
|
103
99
|
};
|
104
100
|
exports.printHashContents = printHashContents;
|
105
101
|
const printHash = (path, opts, print) => {
|
106
|
-
const
|
102
|
+
const node = path.getValue();
|
107
103
|
// Hashes normally have a single assoclist_from_args child node. If it's
|
108
104
|
// missing, then it means we're dealing with an empty hash, so we can just
|
109
105
|
// exit here and print.
|
110
|
-
if (
|
106
|
+
if (node.cnts === null) {
|
111
107
|
return (0, utils_1.printEmptyCollection)(path, opts, "{", "}");
|
112
108
|
}
|
113
|
-
const
|
109
|
+
const doc = [
|
114
110
|
"{",
|
115
111
|
indent([
|
116
112
|
line,
|
117
|
-
path.call(print, "
|
113
|
+
path.call(print, "cnts"),
|
118
114
|
(0, utils_1.getTrailingComma)(opts) ? ifBreak(",", "") : ""
|
119
115
|
]),
|
120
116
|
line,
|
@@ -122,9 +118,9 @@ const printHash = (path, opts, print) => {
|
|
122
118
|
];
|
123
119
|
// If we're inside another hash, then we don't want to group our contents
|
124
120
|
// because we want this hash to break along with its parent hash.
|
125
|
-
if (path.getParentNode().type === "
|
126
|
-
return
|
121
|
+
if (path.getParentNode().type === "assoc") {
|
122
|
+
return doc;
|
127
123
|
}
|
128
|
-
return group(
|
124
|
+
return group(doc);
|
129
125
|
};
|
130
126
|
exports.printHash = printHash;
|
data/dist/ruby/nodes/heredocs.js
CHANGED
@@ -8,15 +8,15 @@ const prettier_1 = __importDefault(require("../../prettier"));
|
|
8
8
|
const utils_1 = require("../../utils");
|
9
9
|
const { group, lineSuffix, join } = prettier_1.default;
|
10
10
|
const printHeredoc = (path, opts, print) => {
|
11
|
-
const
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
const node = path.getValue();
|
12
|
+
// Print out each part of the heredoc to its own doc node.
|
13
|
+
const parts = path.map((partPath) => {
|
14
|
+
const part = partPath.getValue();
|
15
|
+
if (part.type !== "tstring_content") {
|
16
|
+
return print(partPath);
|
16
17
|
}
|
17
|
-
|
18
|
-
|
19
|
-
});
|
18
|
+
return join(utils_1.literallineWithoutBreakParent, part.value.split(/\r?\n/));
|
19
|
+
}, "parts");
|
20
20
|
// We use a literalline break because matching indentation is required
|
21
21
|
// for the heredoc contents and ending. If the line suffix contains a
|
22
22
|
// break-parent, all ancestral groups are broken, and heredocs automatically
|
@@ -24,7 +24,7 @@ const printHeredoc = (path, opts, print) => {
|
|
24
24
|
// possible, so we use a literalline without the break-parent.
|
25
25
|
return group([
|
26
26
|
path.call(print, "beging"),
|
27
|
-
lineSuffix(group([utils_1.literallineWithoutBreakParent, ...parts, ending]))
|
27
|
+
lineSuffix(group([utils_1.literallineWithoutBreakParent, ...parts, node.ending]))
|
28
28
|
]);
|
29
29
|
};
|
30
30
|
exports.printHeredoc = printHeredoc;
|
data/dist/ruby/nodes/hooks.js
CHANGED
data/dist/ruby/nodes/ints.js
CHANGED
@@ -6,22 +6,22 @@ exports.printInt = void 0;
|
|
6
6
|
//
|
7
7
|
// Binary (2) - 0b0110
|
8
8
|
// Octal (8) - 0o34 or 034
|
9
|
-
// Decimal (10) -
|
9
|
+
// Decimal (10) - 159 or 0d159
|
10
10
|
// Hexidecimal (16) - 0xac5
|
11
11
|
//
|
12
12
|
// If it's a decimal number, it can be optional separated by any number of
|
13
13
|
// arbitrarily places underscores. This can be useful for dollars and cents
|
14
14
|
// (34_99), dates (2020_11_30), and normal 3 digit separation (1_222_333).
|
15
15
|
const printInt = (path) => {
|
16
|
-
const {
|
16
|
+
const { value } = path.getValue();
|
17
17
|
// If the number is a base 10 number, is sufficiently large, and is not
|
18
18
|
// already formatted with underscores, then add them in in between the
|
19
19
|
// numbers every three characters starting from the right.
|
20
|
-
if (!
|
20
|
+
if (!value.startsWith("0") && value.length >= 5 && !value.includes("_")) {
|
21
21
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
22
|
-
const segments = ` ${
|
22
|
+
const segments = ` ${value}`.slice((value.length + 2) % 3).match(/.{3}/g);
|
23
23
|
return segments.join("_").trim();
|
24
24
|
}
|
25
|
-
return
|
25
|
+
return value;
|
26
26
|
};
|
27
27
|
exports.printInt = printInt;
|
data/dist/ruby/nodes/lambdas.js
CHANGED
@@ -12,19 +12,19 @@ const { group, ifBreak, indent, line } = prettier_1.default;
|
|
12
12
|
// though it's possible to omit the parens if you only have one argument, we're
|
13
13
|
// going to keep them in no matter what for consistency.
|
14
14
|
function printLambdaParams(path, print) {
|
15
|
-
let node = path.getValue().
|
15
|
+
let node = path.getValue().params;
|
16
16
|
// In this case we had something like -> (foo) { bar } which would mean that
|
17
17
|
// we're looking at a paren node, so we'll descend one level deeper to get at
|
18
18
|
// the actual params node.
|
19
19
|
if (node.type !== "params") {
|
20
|
-
node = node.
|
20
|
+
node = node.cnts;
|
21
21
|
}
|
22
22
|
// If we don't have any params at all, then we're just going to bail out and
|
23
23
|
// print nothing. This is to avoid printing an empty set of parentheses.
|
24
|
-
if (
|
24
|
+
if ((0, utils_1.isEmptyParams)(node)) {
|
25
25
|
return "";
|
26
26
|
}
|
27
|
-
return path.call(print, "
|
27
|
+
return path.call(print, "params");
|
28
28
|
}
|
29
29
|
// Lambda nodes represent stabby lambda literals, which can come in a couple of
|
30
30
|
// flavors. They can use either braces or do...end for their block, and their
|
@@ -56,14 +56,15 @@ function printLambdaParams(path, print) {
|
|
56
56
|
const printLambda = (path, opts, print) => {
|
57
57
|
const params = printLambdaParams(path, print);
|
58
58
|
const inCommand = (0, utils_1.hasAncestor)(path, ["command", "command_call"]);
|
59
|
+
const stmtsDoc = path.call(print, "stmts");
|
59
60
|
return group(ifBreak([
|
60
61
|
"->",
|
61
62
|
params,
|
62
63
|
" ",
|
63
64
|
inCommand ? "{" : "do",
|
64
|
-
indent([line,
|
65
|
+
indent([line, stmtsDoc]),
|
65
66
|
line,
|
66
67
|
inCommand ? "}" : "end"
|
67
|
-
], ["->", params, " { ",
|
68
|
+
], ["->", params, " { ", stmtsDoc, " }"]));
|
68
69
|
};
|
69
70
|
exports.printLambda = printLambda;
|
data/dist/ruby/nodes/loops.js
CHANGED
@@ -3,26 +3,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.
|
6
|
+
exports.printUntil = exports.printWhile = exports.printFor = void 0;
|
7
7
|
const prettier_1 = __importDefault(require("../../prettier"));
|
8
8
|
const utils_1 = require("../../utils");
|
9
9
|
const { align, breakParent, group, hardline, ifBreak, indent, join, softline } = prettier_1.default;
|
10
|
-
function
|
10
|
+
function isModifier(node) {
|
11
|
+
return node.type === "while_mod" || node.type === "until_mod";
|
12
|
+
}
|
13
|
+
function printLoop(keyword) {
|
11
14
|
return function printLoopWithOptions(path, { rubyModifier }, print) {
|
12
|
-
const
|
15
|
+
const node = path.getValue();
|
16
|
+
const predicateDoc = path.call(print, "pred");
|
13
17
|
// If the only statement inside this while loop is a void statement, then we
|
14
18
|
// can shorten to just displaying the predicate and then a semicolon.
|
15
|
-
if ((0, utils_1.isEmptyStmts)(stmts)) {
|
16
|
-
return group([
|
17
|
-
group([keyword, " ", path.call(print, "body", 0)]),
|
18
|
-
hardline,
|
19
|
-
"end"
|
20
|
-
]);
|
19
|
+
if (!isModifier(node) && (0, utils_1.isEmptyStmts)(node.stmts)) {
|
20
|
+
return group([group([keyword, " ", predicateDoc]), hardline, "end"]);
|
21
21
|
}
|
22
|
+
const statementDoc = path.call(print, isModifier(node) ? "stmt" : "stmts");
|
22
23
|
const inlineLoop = (0, utils_1.inlineEnsureParens)(path, [
|
23
|
-
|
24
|
+
statementDoc,
|
24
25
|
` ${keyword} `,
|
25
|
-
|
26
|
+
predicateDoc
|
26
27
|
]);
|
27
28
|
// If we're in the modifier form and we're modifying a `begin`, then this is
|
28
29
|
// a special case where we need to explicitly use the modifier form because
|
@@ -34,12 +35,12 @@ function printLoop(keyword, modifier) {
|
|
34
35
|
//
|
35
36
|
// The above is effectively a `do...while` loop (which we don't have in
|
36
37
|
// ruby).
|
37
|
-
if (
|
38
|
+
if (isModifier(node) && node.stmt.type === "begin") {
|
38
39
|
return inlineLoop;
|
39
40
|
}
|
40
41
|
const blockLoop = [
|
41
|
-
[`${keyword} `, align(keyword.length + 1,
|
42
|
-
indent([softline,
|
42
|
+
[`${keyword} `, align(keyword.length + 1, predicateDoc)],
|
43
|
+
indent([softline, statementDoc]),
|
43
44
|
softline,
|
44
45
|
"end"
|
45
46
|
];
|
@@ -47,27 +48,28 @@ function printLoop(keyword, modifier) {
|
|
47
48
|
// contains an assignment (in which case we can't know for certain that that
|
48
49
|
// assignment doesn't impact the statements inside the loop) then we can't
|
49
50
|
// use the modifier form and we must use the block form.
|
50
|
-
if (!rubyModifier || (0, utils_1.containsAssignment)(
|
51
|
+
if (!rubyModifier || (0, utils_1.containsAssignment)(node.pred)) {
|
51
52
|
return [breakParent, blockLoop];
|
52
53
|
}
|
53
54
|
return group(ifBreak(blockLoop, inlineLoop));
|
54
55
|
};
|
55
56
|
}
|
56
57
|
const printFor = (path, opts, print) => {
|
57
|
-
const
|
58
|
-
|
58
|
+
const node = path.getValue();
|
59
|
+
let indexDoc = path.call(print, "index");
|
60
|
+
if (node.index.type === "mlhs") {
|
61
|
+
indexDoc = join(", ", indexDoc);
|
62
|
+
}
|
59
63
|
return group([
|
60
64
|
"for ",
|
61
|
-
|
65
|
+
indexDoc,
|
62
66
|
" in ",
|
63
|
-
|
64
|
-
indent([hardline,
|
67
|
+
path.call(print, "collection"),
|
68
|
+
indent([hardline, path.call(print, "stmts")]),
|
65
69
|
hardline,
|
66
70
|
"end"
|
67
71
|
]);
|
68
72
|
};
|
69
73
|
exports.printFor = printFor;
|
70
|
-
exports.printWhile = printLoop("while"
|
71
|
-
exports.
|
72
|
-
exports.printUntil = printLoop("until", false);
|
73
|
-
exports.printUntilModifer = printLoop("until", true);
|
74
|
+
exports.printWhile = printLoop("while");
|
75
|
+
exports.printUntil = printLoop("until");
|
data/dist/ruby/nodes/massign.js
CHANGED
@@ -3,71 +3,58 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.printMRHSNewFromArgs = exports.printMRHSAddStar = exports.printMRHS = exports.printMLHSParen = exports.
|
6
|
+
exports.printMRHSNewFromArgs = exports.printMRHSAddStar = exports.printMRHS = exports.printMLHSParen = exports.printMLHS = exports.printMAssign = void 0;
|
7
7
|
const prettier_1 = __importDefault(require("../../prettier"));
|
8
8
|
const { group, indent, join, line, softline } = prettier_1.default;
|
9
9
|
const printMAssign = (path, opts, print) => {
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
const node = path.getValue();
|
11
|
+
let valueDoc = path.call(print, "value");
|
12
|
+
if (["mrhs", "mrhs_add_star", "mrhs_new_from_args"].includes(node.value.type)) {
|
13
|
+
valueDoc = group(join([",", line], valueDoc));
|
13
14
|
}
|
14
|
-
const
|
15
|
-
|
16
|
-
|
15
|
+
const targetDoc = [
|
16
|
+
join([",", line], path.call(print, "target"))
|
17
|
+
];
|
18
|
+
if (node.target.type === "mlhs" && node.target.comma) {
|
19
|
+
targetDoc.push(",");
|
17
20
|
}
|
18
|
-
return group([group(
|
21
|
+
return group([group(targetDoc), " =", indent([line, valueDoc])]);
|
19
22
|
};
|
20
23
|
exports.printMAssign = printMAssign;
|
21
24
|
const printMLHS = (path, opts, print) => {
|
22
|
-
return path.map(print, "
|
25
|
+
return path.map(print, "parts");
|
23
26
|
};
|
24
27
|
exports.printMLHS = printMLHS;
|
25
|
-
const printMLHSAddPost = (path, opts, print) => {
|
26
|
-
return [
|
27
|
-
...path.call(print, "body", 0),
|
28
|
-
...path.call(print, "body", 1)
|
29
|
-
];
|
30
|
-
};
|
31
|
-
exports.printMLHSAddPost = printMLHSAddPost;
|
32
|
-
const printMLHSAddStar = (path, opts, print) => {
|
33
|
-
const parts = ["*"];
|
34
|
-
if (path.getValue().body[1]) {
|
35
|
-
parts.push(path.call(print, "body", 1));
|
36
|
-
}
|
37
|
-
return [...path.call(print, "body", 0), parts];
|
38
|
-
};
|
39
|
-
exports.printMLHSAddStar = printMLHSAddStar;
|
40
28
|
const printMLHSParen = (path, opts, print) => {
|
41
29
|
if (["massign", "mlhs_paren"].includes(path.getParentNode().type)) {
|
42
30
|
// If we're nested in brackets as part of the left hand side of an
|
43
31
|
// assignment, i.e., (a, b, c) = 1, 2, 3
|
44
32
|
// ignore the current node and just go straight to the content
|
45
|
-
return path.call(print, "
|
33
|
+
return path.call(print, "cnts");
|
46
34
|
}
|
35
|
+
const node = path.getValue();
|
47
36
|
const parts = [
|
48
37
|
softline,
|
49
|
-
join([",", line], path.call(print, "
|
38
|
+
join([",", line], path.call(print, "cnts"))
|
50
39
|
];
|
51
|
-
if (
|
40
|
+
if (node.cnts.comma) {
|
52
41
|
parts.push(",");
|
53
42
|
}
|
54
43
|
return group(["(", indent(parts), [softline, ")"]]);
|
55
44
|
};
|
56
45
|
exports.printMLHSParen = printMLHSParen;
|
57
46
|
const printMRHS = (path, opts, print) => {
|
58
|
-
return path.map(print, "
|
47
|
+
return path.map(print, "parts");
|
59
48
|
};
|
60
49
|
exports.printMRHS = printMRHS;
|
61
50
|
const printMRHSAddStar = (path, opts, print) => {
|
62
|
-
|
63
|
-
|
51
|
+
return [
|
52
|
+
...path.call(print, "mrhs"),
|
53
|
+
["*", path.call(print, "star")]
|
54
|
+
];
|
64
55
|
};
|
65
56
|
exports.printMRHSAddStar = printMRHSAddStar;
|
66
57
|
const printMRHSNewFromArgs = (path, opts, print) => {
|
67
|
-
|
68
|
-
if (path.getValue().body[1]) {
|
69
|
-
parts.push(path.call(print, "body", 1));
|
70
|
-
}
|
71
|
-
return parts;
|
58
|
+
return path.call(print, "args");
|
72
59
|
};
|
73
60
|
exports.printMRHSNewFromArgs = printMRHSNewFromArgs;
|
data/dist/ruby/nodes/methods.js
CHANGED
@@ -3,68 +3,48 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.printAccessControl = exports.
|
6
|
+
exports.printAccessControl = exports.printDefEndless = exports.printDef = void 0;
|
7
7
|
const prettier_1 = __importDefault(require("../../prettier"));
|
8
8
|
const utils_1 = require("../../utils");
|
9
9
|
const { group, hardline, indent, line } = prettier_1.default;
|
10
10
|
const printDef = (path, opts, print) => {
|
11
11
|
const node = path.getValue();
|
12
12
|
const declaration = ["def "];
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
let bodystmtDoc;
|
18
|
-
if (node.type === "def") {
|
19
|
-
paramsNode = node.body[1];
|
20
|
-
bodystmtNode = node.body[2];
|
21
|
-
nameDoc = path.call(print, "body", 0);
|
22
|
-
paramsDoc = path.call(print, "body", 1);
|
23
|
-
bodystmtDoc = path.call(print, "body", 2);
|
13
|
+
// In this case, we're printing a method that's defined as a singleton, so
|
14
|
+
// we need to include the target and the operator before the name.
|
15
|
+
if (node.type === "defs") {
|
16
|
+
declaration.push(path.call(print, "target"), path.call(print, "op"));
|
24
17
|
}
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
paramsNode = node.body[3];
|
30
|
-
bodystmtNode = node.body[4];
|
31
|
-
nameDoc = path.call(print, "body", 2);
|
32
|
-
paramsDoc = path.call(print, "body", 3);
|
33
|
-
bodystmtDoc = path.call(print, "body", 4);
|
34
|
-
}
|
35
|
-
// In case there are no parens but there are arguments
|
36
|
-
const parens = paramsNode.type === "params" && paramsNode.body.some((type) => type);
|
37
|
-
declaration.push(nameDoc, parens ? "(" : "", paramsDoc, parens ? ")" : "");
|
38
|
-
if ((0, utils_1.isEmptyBodyStmt)(bodystmtNode)) {
|
18
|
+
// In case there are no parens but there are parameters
|
19
|
+
const useParens = node.params.type === "params" && !(0, utils_1.isEmptyParams)(node.params);
|
20
|
+
declaration.push(path.call(print, "name"), useParens ? "(" : "", path.call(print, "params"), useParens ? ")" : "");
|
21
|
+
if ((0, utils_1.isEmptyBodyStmt)(node.bodystmt)) {
|
39
22
|
return group([...declaration, "; end"]);
|
40
23
|
}
|
41
24
|
return group([
|
42
25
|
group(declaration),
|
43
|
-
indent([hardline,
|
26
|
+
indent([hardline, path.call(print, "bodystmt")]),
|
44
27
|
hardline,
|
45
28
|
"end"
|
46
29
|
]);
|
47
30
|
};
|
48
31
|
exports.printDef = printDef;
|
49
|
-
const
|
50
|
-
const
|
32
|
+
const printDefEndless = (path, opts, print) => {
|
33
|
+
const node = path.getValue();
|
51
34
|
let paramsDoc = "";
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
}
|
35
|
+
// If we have any kind of parameters, we're going to print the whole
|
36
|
+
// parentheses. If we don't, then we're just going to skip them entirely.
|
37
|
+
if (node.paren && !(0, utils_1.isEmptyParams)(node.paren.cnts)) {
|
38
|
+
paramsDoc = path.call(print, "paren");
|
57
39
|
}
|
58
40
|
return group([
|
59
41
|
"def ",
|
60
|
-
path.call(print, "
|
42
|
+
path.call(print, "name"),
|
61
43
|
paramsDoc,
|
62
44
|
" =",
|
63
|
-
indent(group([line, path.call(print, "
|
45
|
+
indent(group([line, path.call(print, "stmt")]))
|
64
46
|
]);
|
65
47
|
};
|
66
|
-
exports.
|
67
|
-
const printAccessControl = (path, opts, print) =>
|
68
|
-
return path.call(print, "body", 0);
|
69
|
-
};
|
48
|
+
exports.printDefEndless = printDefEndless;
|
49
|
+
const printAccessControl = (path, opts, print) => path.call(print, "value");
|
70
50
|
exports.printAccessControl = printAccessControl;
|
@@ -3,29 +3,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.printUnary = exports.printDot3 = exports.printDot2 = exports.printBinary = void 0;
|
6
|
+
exports.printNot = exports.printUnary = exports.printDot3 = exports.printDot2 = exports.printBinary = void 0;
|
7
7
|
const prettier_1 = __importDefault(require("../../prettier"));
|
8
8
|
const utils_1 = require("../../utils");
|
9
9
|
const { group, indent, line, softline } = prettier_1.default;
|
10
10
|
const printBinary = (path, opts, print) => {
|
11
|
-
const
|
12
|
-
const space =
|
13
|
-
if (utils_1.noIndent.includes(
|
11
|
+
const node = path.getValue();
|
12
|
+
const space = node.op === "**" ? "" : " ";
|
13
|
+
if (utils_1.noIndent.includes(node.right.type)) {
|
14
14
|
return group([
|
15
|
-
group(path.call(print, "
|
15
|
+
group(path.call(print, "left")),
|
16
16
|
space,
|
17
|
-
|
17
|
+
node.op,
|
18
18
|
space,
|
19
|
-
group(path.call(print, "
|
19
|
+
group(path.call(print, "right"))
|
20
20
|
]);
|
21
21
|
}
|
22
22
|
return group([
|
23
|
-
group(path.call(print, "
|
23
|
+
group(path.call(print, "left")),
|
24
24
|
space,
|
25
25
|
group(indent([
|
26
|
-
|
26
|
+
node.op,
|
27
27
|
space === "" ? softline : line,
|
28
|
-
path.call(print, "
|
28
|
+
path.call(print, "right")
|
29
29
|
]))
|
30
30
|
]);
|
31
31
|
};
|
@@ -33,38 +33,36 @@ exports.printBinary = printBinary;
|
|
33
33
|
// dot2 nodes are used with ranges (or flip-flops). They can optionally drop
|
34
34
|
// their left side for beginless ranges or their right side for endless ranges.
|
35
35
|
const printDot2 = (path, opts, print) => {
|
36
|
-
const
|
36
|
+
const node = path.getValue();
|
37
37
|
return [
|
38
|
-
|
38
|
+
node.left ? path.call(print, "left") : "",
|
39
39
|
"..",
|
40
|
-
|
40
|
+
node.right ? path.call(print, "right") : ""
|
41
41
|
];
|
42
42
|
};
|
43
43
|
exports.printDot2 = printDot2;
|
44
44
|
// dot3 nodes are used with ranges (or flip-flops). They can optionally drop
|
45
45
|
// their left side for beginless ranges or their right side for endless ranges.
|
46
46
|
const printDot3 = (path, opts, print) => {
|
47
|
-
const
|
47
|
+
const node = path.getValue();
|
48
48
|
return [
|
49
|
-
|
49
|
+
node.left ? path.call(print, "left") : "",
|
50
50
|
"...",
|
51
|
-
|
51
|
+
node.right ? path.call(print, "right") : ""
|
52
52
|
];
|
53
53
|
};
|
54
54
|
exports.printDot3 = printDot3;
|
55
55
|
const printUnary = (path, opts, print) => {
|
56
56
|
const node = path.getValue();
|
57
|
-
|
58
|
-
if (node.oper === "not") {
|
59
|
-
// Here we defer to the original source, as it's kind of difficult to
|
60
|
-
// determine if we can actually remove the parentheses being used.
|
61
|
-
if (node.paren) {
|
62
|
-
return ["not", "(", contentsDoc, ")"];
|
63
|
-
}
|
64
|
-
else {
|
65
|
-
return ["not", " ", contentsDoc];
|
66
|
-
}
|
67
|
-
}
|
68
|
-
return [node.oper, contentsDoc];
|
57
|
+
return [node.op, path.call(print, "value")];
|
69
58
|
};
|
70
59
|
exports.printUnary = printUnary;
|
60
|
+
const printNot = (path, opts, print) => {
|
61
|
+
const node = path.getValue();
|
62
|
+
const valueDoc = path.call(print, "value");
|
63
|
+
if (node.paren) {
|
64
|
+
return ["not", "(", valueDoc, ")"];
|
65
|
+
}
|
66
|
+
return ["not", " ", valueDoc];
|
67
|
+
};
|
68
|
+
exports.printNot = printNot;
|