prettier 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -1
- data/dist/haml/parser.rb +6 -0
- data/dist/parser/getInfo.js +9 -2
- 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 +34 -37
- data/dist/ruby/nodes/regexp.js +6 -6
- data/dist/ruby/nodes/rescue.js +23 -22
- 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/lib/prettier.rb +2 -1
- 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 +7 -7
- metadata +7 -3
data/dist/ruby/nodes/arrays.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.printArray = exports.printWord = void 0;
|
6
|
+
exports.printArray = exports.printWords = exports.printSymbols = exports.printQwords = exports.printQsymbols = exports.printWord = 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, softline } = prettier_1.default;
|
@@ -14,8 +14,8 @@ const { group, ifBreak, indent, join, line, softline } = prettier_1.default;
|
|
14
14
|
// ['a', 'b', 'c']
|
15
15
|
//
|
16
16
|
function isStringArray(args) {
|
17
|
-
return (args.
|
18
|
-
args.
|
17
|
+
return (args.parts.length > 1 &&
|
18
|
+
args.parts.every((arg) => {
|
19
19
|
// We want to verify that every node inside of this array is a string
|
20
20
|
// literal. We also want to make sure none of them have comments attached.
|
21
21
|
if (arg.type !== "string_literal" || arg.comments) {
|
@@ -23,19 +23,19 @@ function isStringArray(args) {
|
|
23
23
|
}
|
24
24
|
// If the string has multiple parts (meaning plain string content but also
|
25
25
|
// interpolated content) then we know it's not a simple string.
|
26
|
-
if (arg.
|
26
|
+
if (arg.parts.length !== 1) {
|
27
27
|
return false;
|
28
28
|
}
|
29
|
-
const part = arg.
|
29
|
+
const part = arg.parts[0];
|
30
30
|
// If the only part of this string is not @tstring_content then it's
|
31
31
|
// interpolated, so again we can return false.
|
32
|
-
if (part.type !== "
|
32
|
+
if (part.type !== "tstring_content") {
|
33
33
|
return false;
|
34
34
|
}
|
35
35
|
// Finally, verify that the string doesn't contain a space, an escape
|
36
36
|
// character, or brackets so that we know it can be put into a string
|
37
37
|
// literal array.
|
38
|
-
return !/[\s\\[\]]/.test(part.
|
38
|
+
return !/[\s\\[\]]/.test(part.value);
|
39
39
|
}));
|
40
40
|
}
|
41
41
|
// Checks that every argument within this args node is a symbol_literal node (as
|
@@ -45,20 +45,20 @@ function isStringArray(args) {
|
|
45
45
|
// [:a, :b, :c]
|
46
46
|
//
|
47
47
|
function isSymbolArray(args) {
|
48
|
-
return (args.
|
49
|
-
args.
|
48
|
+
return (args.parts.length > 1 &&
|
49
|
+
args.parts.every((arg) => arg.type === "symbol_literal" && !arg.comments));
|
50
50
|
}
|
51
51
|
// Prints out a word that is a part of a special array literal that accepts
|
52
52
|
// interpolation. The body is an array of either plain strings or interpolated
|
53
53
|
// expressions.
|
54
54
|
const printWord = (path, opts, print) => {
|
55
|
-
return path.map(print, "
|
55
|
+
return path.map(print, "parts");
|
56
56
|
};
|
57
57
|
exports.printWord = printWord;
|
58
58
|
// Prints out a special array literal. Accepts the parts of the array literal as
|
59
59
|
// an argument, where the first element of the parts array is a string that
|
60
60
|
// contains the special start.
|
61
|
-
function
|
61
|
+
function printArrayLiteralParts(start, parts) {
|
62
62
|
return group([
|
63
63
|
start,
|
64
64
|
"[",
|
@@ -67,47 +67,43 @@ function printArrayLiteral(start, parts) {
|
|
67
67
|
"]"
|
68
68
|
]);
|
69
69
|
}
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
70
|
+
function printArrayLiteral(start) {
|
71
|
+
return function printArrayLiteralWithStart(path, opts, print) {
|
72
|
+
return printArrayLiteralParts(start, path.map(print, "elems"));
|
73
|
+
};
|
74
|
+
}
|
75
|
+
exports.printQsymbols = printArrayLiteral("%i");
|
76
|
+
exports.printQwords = printArrayLiteral("%w");
|
77
|
+
exports.printSymbols = printArrayLiteral("%I");
|
78
|
+
exports.printWords = printArrayLiteral("%W");
|
76
79
|
// An array node is any literal array in Ruby. This includes all of the special
|
77
80
|
// array literals as well as regular arrays. If it is a special array literal
|
78
81
|
// then it will have one child that represents the special array, otherwise it
|
79
82
|
// will have one child that contains all of the elements of the array.
|
80
83
|
const printArray = (path, opts, print) => {
|
81
84
|
const array = path.getValue();
|
82
|
-
const
|
85
|
+
const contents = array.cnts;
|
83
86
|
// If there is no inner arguments node, then we're dealing with an empty
|
84
87
|
// array, so we can go ahead and return.
|
85
|
-
if (
|
88
|
+
if (contents === null) {
|
86
89
|
return (0, utils_1.printEmptyCollection)(path, opts, "[", "]");
|
87
90
|
}
|
88
|
-
// If we don't have a regular args node at this point then we have a special
|
89
|
-
// array literal. In that case we're going to print out the body (which will
|
90
|
-
// return to us an array with the first one being the start of the array) and
|
91
|
-
// send that over to the printArrayLiteral function.
|
92
|
-
if (args.type !== "args" && args.type !== "args_add_star") {
|
93
|
-
return path.call((arrayPath) => printArrayLiteral(arrayLiteralStarts[args.type], arrayPath.map(print, "body")), "body", 0);
|
94
|
-
}
|
95
91
|
if (opts.rubyArrayLiteral) {
|
96
92
|
// If we have an array that contains only simple string literals with no
|
97
93
|
// spaces or interpolation, then we're going to print a %w array.
|
98
|
-
if (isStringArray(
|
99
|
-
const printString = (stringPath) => stringPath.call(print, "
|
94
|
+
if (isStringArray(contents)) {
|
95
|
+
const printString = (stringPath) => stringPath.call(print, "parts", 0);
|
100
96
|
const nodePath = path;
|
101
|
-
const parts = nodePath.map(printString, "
|
102
|
-
return
|
97
|
+
const parts = nodePath.map(printString, "cnts", "parts");
|
98
|
+
return printArrayLiteralParts("%w", parts);
|
103
99
|
}
|
104
100
|
// If we have an array that contains only simple symbol literals with no
|
105
101
|
// interpolation, then we're going to print a %i array.
|
106
|
-
if (isSymbolArray(
|
107
|
-
const printSymbol = (symbolPath) => symbolPath.call(print, "
|
102
|
+
if (isSymbolArray(contents)) {
|
103
|
+
const printSymbol = (symbolPath) => symbolPath.call(print, "value");
|
108
104
|
const nodePath = path;
|
109
|
-
const parts = nodePath.map(printSymbol, "
|
110
|
-
return
|
105
|
+
const parts = nodePath.map(printSymbol, "cnts", "parts");
|
106
|
+
return printArrayLiteralParts("%i", parts);
|
111
107
|
}
|
112
108
|
}
|
113
109
|
// Here we have a normal array of any type of object with no special literal
|
@@ -116,7 +112,7 @@ const printArray = (path, opts, print) => {
|
|
116
112
|
"[",
|
117
113
|
indent([
|
118
114
|
softline,
|
119
|
-
join([",", line], path.call(print, "
|
115
|
+
join([",", line], path.call(print, "cnts")),
|
120
116
|
(0, utils_1.getTrailingComma)(opts) ? ifBreak(",", "") : ""
|
121
117
|
]),
|
122
118
|
softline,
|
data/dist/ruby/nodes/assign.js
CHANGED
@@ -7,35 +7,31 @@ exports.printVarRef = exports.printVarField = exports.printOpAssign = exports.pr
|
|
7
7
|
const prettier_1 = __importDefault(require("../../prettier"));
|
8
8
|
const utils_1 = require("../../utils");
|
9
9
|
const { group, indent, join, line } = prettier_1.default;
|
10
|
-
const printAssign = (
|
11
|
-
|
12
|
-
|
10
|
+
const printAssign = (...args) => {
|
11
|
+
return printOpAssignOrAssign("=", ...args);
|
12
|
+
};
|
13
|
+
exports.printAssign = printAssign;
|
14
|
+
const printOpAssign = (path, opts, print) => {
|
15
|
+
const opDoc = path.call(print, "op");
|
16
|
+
return printOpAssignOrAssign(opDoc, path, opts, print);
|
17
|
+
};
|
18
|
+
exports.printOpAssign = printOpAssign;
|
19
|
+
function printOpAssignOrAssign(opDoc, path, opts, print) {
|
20
|
+
const valueNode = path.getValue().value;
|
21
|
+
const targetDoc = path.call(print, "target");
|
22
|
+
const valueDoc = path.call(print, "value");
|
13
23
|
let rightSideDoc = valueDoc;
|
14
24
|
// If the right side of this assignment is a multiple assignment, then we need
|
15
25
|
// to join it together with commas.
|
16
|
-
if (["mrhs_add_star", "mrhs_new_from_args"].includes(valueNode.type)) {
|
26
|
+
if (["mrhs", "mrhs_add_star", "mrhs_new_from_args"].includes(valueNode.type)) {
|
17
27
|
rightSideDoc = group(join([",", line], valueDoc));
|
18
28
|
}
|
19
29
|
if ((0, utils_1.skipAssignIndent)(valueNode)) {
|
20
|
-
return group([targetDoc, "
|
30
|
+
return group([targetDoc, " ", opDoc, " ", rightSideDoc]);
|
21
31
|
}
|
22
|
-
return group([targetDoc, "
|
23
|
-
}
|
24
|
-
|
25
|
-
const printOpAssign = (path, opts, print) => {
|
26
|
-
return group([
|
27
|
-
path.call(print, "body", 0),
|
28
|
-
" ",
|
29
|
-
path.call(print, "body", 1),
|
30
|
-
indent([line, path.call(print, "body", 2)])
|
31
|
-
]);
|
32
|
-
};
|
33
|
-
exports.printOpAssign = printOpAssign;
|
34
|
-
const printVarField = (path, opts, print) => {
|
35
|
-
return path.getValue().body ? path.call(print, "body", 0) : "";
|
36
|
-
};
|
32
|
+
return group([targetDoc, " ", opDoc, indent([line, rightSideDoc])]);
|
33
|
+
}
|
34
|
+
const printVarField = (path, opts, print) => (path.getValue().value ? path.call(print, "value") : "");
|
37
35
|
exports.printVarField = printVarField;
|
38
|
-
const printVarRef = (path, opts, print) =>
|
39
|
-
return path.call(print, "body", 0);
|
40
|
-
};
|
36
|
+
const printVarRef = (path, opts, print) => path.call(print, "value");
|
41
37
|
exports.printVarRef = printVarRef;
|
data/dist/ruby/nodes/blocks.js
CHANGED
@@ -8,10 +8,10 @@ const prettier_1 = __importDefault(require("../../prettier"));
|
|
8
8
|
const utils_1 = require("../../utils");
|
9
9
|
const { breakParent, group, ifBreak, indent, join, removeLines, softline } = prettier_1.default;
|
10
10
|
const printBlockVar = (path, opts, print) => {
|
11
|
-
const parts = ["|", removeLines(path.call(print, "
|
11
|
+
const parts = ["|", removeLines(path.call(print, "params"))];
|
12
12
|
// The second part of this node is a list of optional block-local variables
|
13
|
-
if (path.getValue().
|
14
|
-
parts.push("; ", join(", ", path.map(print, "
|
13
|
+
if (path.getValue().locals.length > 0) {
|
14
|
+
parts.push("; ", join(", ", path.map(print, "locals")));
|
15
15
|
}
|
16
16
|
parts.push("| ");
|
17
17
|
return parts;
|
@@ -23,9 +23,9 @@ exports.printBlockVar = printBlockVar;
|
|
23
23
|
// braces or not. Ideally we wouldn't do this, we would instead do this
|
24
24
|
// reflection in the child printer, but this keeps the logic to just this file
|
25
25
|
// and contains it, so keeping it here for now.
|
26
|
-
function
|
26
|
+
function printBlockBegin(path, print, useBraces) {
|
27
27
|
let docs = print(path);
|
28
|
-
const doc = useBraces ? "{" : "do";
|
28
|
+
const doc = useBraces && !path.getValue().comments ? "{" : "do";
|
29
29
|
if (Array.isArray(docs)) {
|
30
30
|
docs[1] = doc;
|
31
31
|
}
|
@@ -36,13 +36,16 @@ function printBlockBeging(path, print, useBraces) {
|
|
36
36
|
}
|
37
37
|
function printBlock(braces) {
|
38
38
|
return function printBlockWithBraces(path, opts, print) {
|
39
|
-
const
|
40
|
-
const stmts =
|
39
|
+
const node = path.getValue();
|
40
|
+
const stmts = node.type === "brace_block" ? node.stmts.body : node.bodystmt.stmts.body;
|
41
41
|
let doBlockBody = "";
|
42
42
|
if (stmts.length !== 1 ||
|
43
43
|
stmts[0].type !== "void_stmt" ||
|
44
44
|
stmts[0].comments) {
|
45
|
-
doBlockBody = indent([
|
45
|
+
doBlockBody = indent([
|
46
|
+
softline,
|
47
|
+
path.call(print, node.type === "brace_block" ? "stmts" : "bodystmt")
|
48
|
+
]);
|
46
49
|
}
|
47
50
|
// If this block is nested underneath a command or command_call node, then
|
48
51
|
// we can't use `do...end` because that will get associated with the parent
|
@@ -52,8 +55,8 @@ function printBlock(braces) {
|
|
52
55
|
const useBraces = braces && (0, utils_1.hasAncestor)(path, ["command", "command_call"]);
|
53
56
|
const doBlock = [
|
54
57
|
" ",
|
55
|
-
path.call((
|
56
|
-
|
58
|
+
path.call((beginPath) => printBlockBegin(beginPath, print, useBraces), node.type === "brace_block" ? "lbrace" : "keyword"),
|
59
|
+
node.block_var ? [" ", path.call(print, "block_var")] : "",
|
57
60
|
doBlockBody,
|
58
61
|
[softline, useBraces ? "}" : "end"]
|
59
62
|
];
|
@@ -64,7 +67,7 @@ function printBlock(braces) {
|
|
64
67
|
stmts[0].comments) {
|
65
68
|
return [breakParent, doBlock];
|
66
69
|
}
|
67
|
-
const blockReceiver = path.getParentNode().
|
70
|
+
const blockReceiver = path.getParentNode().call;
|
68
71
|
// If the parent node is a command node, then there are no parentheses
|
69
72
|
// around the arguments to that command, so we need to break the block
|
70
73
|
if (["command", "command_call"].includes(blockReceiver.type)) {
|
@@ -73,10 +76,10 @@ function printBlock(braces) {
|
|
73
76
|
const hasBody = stmts.some(({ type }) => type !== "void_stmt");
|
74
77
|
const braceBlock = [
|
75
78
|
" ",
|
76
|
-
path.call((
|
77
|
-
hasBody ||
|
78
|
-
|
79
|
-
path.call(print, "
|
79
|
+
path.call((beginPath) => printBlockBegin(beginPath, print, true), node.type === "brace_block" ? "lbrace" : "keyword"),
|
80
|
+
hasBody || node.block_var ? " " : "",
|
81
|
+
node.block_var ? path.call(print, "block_var") : "",
|
82
|
+
path.call(print, node.type === "brace_block" ? "stmts" : "bodystmt"),
|
80
83
|
hasBody ? " " : "",
|
81
84
|
"}"
|
82
85
|
];
|
data/dist/ruby/nodes/calls.js
CHANGED
@@ -15,13 +15,12 @@ function hasLeadingComments(node) {
|
|
15
15
|
}
|
16
16
|
const printCall = (path, opts, print) => {
|
17
17
|
const node = path.getValue();
|
18
|
-
const
|
19
|
-
const receiverDoc = path.call(print, "body", 0);
|
18
|
+
const receiverDoc = path.call(print, "receiver");
|
20
19
|
const operatorDoc = (0, utils_1.makeCall)(path, opts, print);
|
21
20
|
// You can call lambdas with a special syntax that looks like func.(*args).
|
22
21
|
// In this case, "call" is returned for the 3rd child node. We don't alter
|
23
22
|
// call syntax so if `call` is implicit, we don't print it out.
|
24
|
-
const messageDoc =
|
23
|
+
const messageDoc = node.message === "call" ? "" : path.call(print, "message");
|
25
24
|
// Create some arrays that are going to represent each side of our call.
|
26
25
|
let leftSideDoc = [receiverDoc];
|
27
26
|
let rightSideDoc = [operatorDoc, messageDoc];
|
@@ -35,19 +34,19 @@ const printCall = (path, opts, print) => {
|
|
35
34
|
//
|
36
35
|
// In the case we need to group the receiver and the operator together or
|
37
36
|
// we'll end up with a syntax error.
|
38
|
-
const operatorIsTrailing =
|
37
|
+
const operatorIsTrailing = node.message !== "call" && hasLeadingComments(node.message);
|
39
38
|
if (operatorIsTrailing) {
|
40
39
|
leftSideDoc = [receiverDoc, operatorDoc];
|
41
40
|
rightSideDoc = [messageDoc];
|
42
41
|
}
|
43
42
|
// For certain left sides of the call nodes, we want to attach directly to
|
44
43
|
// the } or end.
|
45
|
-
if (utils_1.noIndent.includes(
|
44
|
+
if (utils_1.noIndent.includes(node.receiver.type)) {
|
46
45
|
return [leftSideDoc, rightSideDoc];
|
47
46
|
}
|
48
|
-
if (
|
49
|
-
|
50
|
-
|
47
|
+
if (node.receiver.type === "call" &&
|
48
|
+
node.receiver.message !== "call" &&
|
49
|
+
node.receiver.message.value === "where" &&
|
51
50
|
messageDoc === "not") {
|
52
51
|
// This is very specialized behavior wherein we group .where.not calls
|
53
52
|
// together because it looks better. For more information, see
|
@@ -55,7 +54,7 @@ const printCall = (path, opts, print) => {
|
|
55
54
|
}
|
56
55
|
else {
|
57
56
|
// Otherwise, we're going to put a line node into the right side doc.
|
58
|
-
rightSideDoc.unshift(
|
57
|
+
rightSideDoc.unshift(node.receiver.comments ? hardline : softline);
|
59
58
|
}
|
60
59
|
// Get a reference to the parent node so we can check if we're inside a chain
|
61
60
|
const parentNode = path.getParentNode();
|
@@ -64,7 +63,7 @@ const printCall = (path, opts, print) => {
|
|
64
63
|
if (chained.includes(parentNode.type) && !node.comments) {
|
65
64
|
parentNode.chain = (node.chain || 0) + 1;
|
66
65
|
parentNode.callChain = (node.callChain || 0) + 1;
|
67
|
-
parentNode.firstReceiverType = node.firstReceiverType ||
|
66
|
+
parentNode.firstReceiverType = node.firstReceiverType || node.receiver.type;
|
68
67
|
// Here we're going to determine what doc nodes to send up to the parent
|
69
68
|
// node to represent when we're in the multi-line form.
|
70
69
|
let breakDocLHS;
|
@@ -104,8 +103,8 @@ const printCall = (path, opts, print) => {
|
|
104
103
|
exports.printCall = printCall;
|
105
104
|
const printMethodAddArg = (path, opts, print) => {
|
106
105
|
const node = path.getValue();
|
107
|
-
const
|
108
|
-
const
|
106
|
+
const methodDoc = path.call(print, "call");
|
107
|
+
const argsDoc = path.call(print, "args");
|
109
108
|
// You can end up here if you have a method with a ? ending, presumably
|
110
109
|
// because the parser knows that it cannot be a local variable. You can also
|
111
110
|
// end up here if you are explicitly using an empty set of parentheses.
|
@@ -114,7 +113,7 @@ const printMethodAddArg = (path, opts, print) => {
|
|
114
113
|
// like a constant, then we need to match that in order to maintain valid
|
115
114
|
// Ruby. For example, you could do something like Foo(), on which we would
|
116
115
|
// need to keep the parentheses to make it look like a method call.
|
117
|
-
if (
|
116
|
+
if (node.call.type === "fcall" && node.call.value.type === "const") {
|
118
117
|
return [methodDoc, "()"];
|
119
118
|
}
|
120
119
|
// If you're using an explicit set parentheses with the special call syntax,
|
@@ -122,14 +121,14 @@ const printMethodAddArg = (path, opts, print) => {
|
|
122
121
|
// example, if you call something like Foo.new.() (implicitly calling the
|
123
122
|
// #call method on a new instance of the Foo class), then we have to print
|
124
123
|
// out those parentheses, otherwise we'll end up with Foo.new.
|
125
|
-
if (
|
124
|
+
if (node.call.type === "call" && node.call.message === "call") {
|
126
125
|
return [methodDoc, "()"];
|
127
126
|
}
|
128
127
|
return methodDoc;
|
129
128
|
}
|
130
129
|
// This case will ONLY be hit if we can successfully turn the block into a
|
131
130
|
// to_proc call. In that case, we just explicitly add the parens around it.
|
132
|
-
if (
|
131
|
+
if (node.args.type === "args" && argsDoc.length > 0) {
|
133
132
|
return [methodDoc, "(", ...argsDoc, ")"];
|
134
133
|
}
|
135
134
|
// Get a reference to the parent node so we can check if we're inside a chain
|
@@ -157,12 +156,16 @@ const printMethodAddArg = (path, opts, print) => {
|
|
157
156
|
if (sigBlock.type === "do_block") {
|
158
157
|
sigBlock = path.getParentNode(3);
|
159
158
|
}
|
160
|
-
if (sigBlock.type === "method_add_block"
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
159
|
+
if (sigBlock.type === "method_add_block") {
|
160
|
+
// Pulling this out into a separate variable so we can get back some of
|
161
|
+
// our type safety.
|
162
|
+
const sigBlockNode = sigBlock;
|
163
|
+
if (sigBlockNode.block &&
|
164
|
+
sigBlockNode.call.type === "method_add_arg" &&
|
165
|
+
sigBlockNode.call.call.type === "fcall" &&
|
166
|
+
sigBlockNode.call.call.value.value === "sig") {
|
167
|
+
threshold = 2;
|
168
|
+
}
|
166
169
|
}
|
167
170
|
}
|
168
171
|
// If we're at the top of a chain, then we're going to print out a nice
|
@@ -191,30 +194,30 @@ const printMethodAddArg = (path, opts, print) => {
|
|
191
194
|
}
|
192
195
|
// If there are already parentheses, then we can just use the doc that's
|
193
196
|
// already printed.
|
194
|
-
if (
|
195
|
-
return [methodDoc, argsDoc];
|
197
|
+
if (node.args.type == "arg_paren") {
|
198
|
+
return group([methodDoc, argsDoc]);
|
196
199
|
}
|
197
200
|
return [methodDoc, " ", join(", ", argsDoc), " "];
|
198
201
|
};
|
199
202
|
exports.printMethodAddArg = printMethodAddArg;
|
200
203
|
const printMethodAddBlock = (path, opts, print) => {
|
201
204
|
const node = path.getValue();
|
202
|
-
const
|
203
|
-
const
|
205
|
+
const callDoc = path.call(print, "call");
|
206
|
+
const blockDoc = path.call(print, "block");
|
204
207
|
// Don't bother trying to do any kind of fancy toProc transform if the option
|
205
208
|
// is disabled.
|
206
209
|
if (opts.rubyToProc) {
|
207
|
-
const proc = (0, toProc_1.default)(path,
|
208
|
-
if (proc &&
|
210
|
+
const proc = (0, toProc_1.default)(path, node.block);
|
211
|
+
if (proc && node.call.type === "call") {
|
209
212
|
return group([
|
210
|
-
path.call(print, "
|
213
|
+
path.call(print, "call"),
|
211
214
|
"(",
|
212
215
|
indent([softline, proc]),
|
213
216
|
[softline, ")"]
|
214
217
|
]);
|
215
218
|
}
|
216
219
|
if (proc) {
|
217
|
-
return path.call(print, "
|
220
|
+
return path.call(print, "call");
|
218
221
|
}
|
219
222
|
}
|
220
223
|
// Get a reference to the parent node so we can check if we're inside a chain
|
@@ -255,6 +258,6 @@ const printMethodAddBlock = (path, opts, print) => {
|
|
255
258
|
};
|
256
259
|
exports.printMethodAddBlock = printMethodAddBlock;
|
257
260
|
const printCallContainer = (path, opts, print) => {
|
258
|
-
return path.call(print, "
|
261
|
+
return path.call(print, "value");
|
259
262
|
};
|
260
263
|
exports.printCallContainer = printCallContainer;
|
data/dist/ruby/nodes/case.js
CHANGED
@@ -10,17 +10,17 @@ const printCase = (path, opts, print) => {
|
|
10
10
|
const parts = ["case"];
|
11
11
|
// You don't need to explicitly have something to test against in a case
|
12
12
|
// statement (without it it effectively becomes an if/elsif chain).
|
13
|
-
if (path.getValue().
|
14
|
-
parts.push(" ", path.call(print, "
|
13
|
+
if (path.getValue().value) {
|
14
|
+
parts.push(" ", path.call(print, "value"));
|
15
15
|
}
|
16
|
-
return [...parts, hardline, path.call(print, "
|
16
|
+
return [...parts, hardline, path.call(print, "cons"), hardline, "end"];
|
17
17
|
};
|
18
18
|
exports.printCase = printCase;
|
19
19
|
const printWhen = (path, opts, print) => {
|
20
|
-
const
|
20
|
+
const node = path.getValue();
|
21
21
|
// The `fill` builder command expects an array of docs alternating with
|
22
22
|
// line breaks. This is so it can loop through and determine where to break.
|
23
|
-
const preds = fill(path.call(print, "
|
23
|
+
const preds = fill(path.call(print, "args").reduce((accum, pred, index) => {
|
24
24
|
if (index === 0) {
|
25
25
|
return [pred];
|
26
26
|
}
|
@@ -33,7 +33,7 @@ const printWhen = (path, opts, print) => {
|
|
33
33
|
pred
|
34
34
|
];
|
35
35
|
}, []));
|
36
|
-
const stmts = path.call(print, "
|
36
|
+
const stmts = path.call(print, "stmts");
|
37
37
|
const parts = [["when ", align("when ".length, preds)]];
|
38
38
|
// It's possible in a when to just have empty void statements, in which case
|
39
39
|
// we would skip adding the body.
|
@@ -42,8 +42,8 @@ const printWhen = (path, opts, print) => {
|
|
42
42
|
}
|
43
43
|
// This is the next clause on the case statement, either another `when` or
|
44
44
|
// an `else` clause.
|
45
|
-
if (
|
46
|
-
parts.push(hardline, path.call(print, "
|
45
|
+
if (node.cons) {
|
46
|
+
parts.push(hardline, path.call(print, "cons"));
|
47
47
|
}
|
48
48
|
return group(parts);
|
49
49
|
};
|
data/dist/ruby/nodes/class.js
CHANGED
@@ -8,45 +8,45 @@ const prettier_1 = __importDefault(require("../../prettier"));
|
|
8
8
|
const utils_1 = require("../../utils");
|
9
9
|
const { group, hardline, indent } = prettier_1.default;
|
10
10
|
const printClass = (path, opts, print) => {
|
11
|
-
const
|
12
|
-
const parts = ["class ", path.call(print, "
|
13
|
-
if (superclass) {
|
14
|
-
parts.push(" < ", path.call(print, "
|
11
|
+
const node = path.getValue();
|
12
|
+
const parts = ["class ", path.call(print, "constant")];
|
13
|
+
if (node.superclass) {
|
14
|
+
parts.push(" < ", path.call(print, "superclass"));
|
15
15
|
}
|
16
16
|
const declaration = group(parts);
|
17
|
-
if ((0, utils_1.isEmptyBodyStmt)(bodystmt)) {
|
17
|
+
if ((0, utils_1.isEmptyBodyStmt)(node.bodystmt)) {
|
18
18
|
return group([declaration, hardline, "end"]);
|
19
19
|
}
|
20
20
|
return group([
|
21
21
|
declaration,
|
22
|
-
indent([hardline, path.call(print, "
|
22
|
+
indent([hardline, path.call(print, "bodystmt")]),
|
23
23
|
[hardline, "end"]
|
24
24
|
]);
|
25
25
|
};
|
26
26
|
exports.printClass = printClass;
|
27
27
|
const printModule = (path, opts, print) => {
|
28
28
|
const node = path.getValue();
|
29
|
-
const declaration = group(["module ", path.call(print, "
|
30
|
-
if ((0, utils_1.isEmptyBodyStmt)(node.
|
29
|
+
const declaration = group(["module ", path.call(print, "constant")]);
|
30
|
+
if ((0, utils_1.isEmptyBodyStmt)(node.bodystmt)) {
|
31
31
|
return group([declaration, hardline, "end"]);
|
32
32
|
}
|
33
33
|
return group([
|
34
34
|
declaration,
|
35
|
-
indent([hardline, path.call(print, "
|
35
|
+
indent([hardline, path.call(print, "bodystmt")]),
|
36
36
|
hardline,
|
37
37
|
"end"
|
38
38
|
]);
|
39
39
|
};
|
40
40
|
exports.printModule = printModule;
|
41
41
|
const printSClass = (path, opts, print) => {
|
42
|
-
const
|
43
|
-
const declaration = ["class << ", path.call(print, "
|
44
|
-
if ((0, utils_1.isEmptyBodyStmt)(bodystmt)) {
|
42
|
+
const node = path.getValue();
|
43
|
+
const declaration = ["class << ", path.call(print, "target")];
|
44
|
+
if ((0, utils_1.isEmptyBodyStmt)(node.bodystmt)) {
|
45
45
|
return group([declaration, hardline, "end"]);
|
46
46
|
}
|
47
47
|
return group([
|
48
48
|
declaration,
|
49
|
-
indent([hardline, path.call(print, "
|
49
|
+
indent([hardline, path.call(print, "bodystmt")]),
|
50
50
|
hardline,
|
51
51
|
"end"
|
52
52
|
]);
|