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/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;
|
data/dist/ruby/nodes/params.js
CHANGED
@@ -3,51 +3,51 @@ 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.printRestParam = exports.printKeywordRestParam = exports.printArgsForward = exports.printParams = void 0;
|
6
|
+
exports.printExcessedComma = exports.printRestParam = exports.printKeywordRestParam = exports.printArgsForward = exports.printParams = void 0;
|
7
7
|
const prettier_1 = __importDefault(require("../../prettier"));
|
8
|
-
const utils_1 = require("../../utils");
|
9
8
|
const { group, hardline, join, indent, line, lineSuffix, softline } = prettier_1.default;
|
10
9
|
function printRestParamSymbol(symbol) {
|
11
10
|
return function printRestParamWithSymbol(path, opts, print) {
|
12
|
-
|
13
|
-
|
14
|
-
: symbol;
|
11
|
+
const node = path.getValue();
|
12
|
+
return node.name ? [symbol, path.call(print, "name")] : symbol;
|
15
13
|
};
|
16
14
|
}
|
17
15
|
const printParams = (path, opts, print) => {
|
18
|
-
const
|
16
|
+
const node = path.getValue();
|
19
17
|
let parts = [];
|
20
|
-
if (reqs) {
|
18
|
+
if (node.reqs) {
|
21
19
|
path.each((reqPath) => {
|
22
20
|
// For some very strange reason, if you have a comment attached to a
|
23
21
|
// rest_param, it shows up here in the list of required params.
|
24
22
|
if (reqPath.getValue().type !== "rest_param") {
|
25
23
|
parts.push(print(reqPath));
|
26
24
|
}
|
27
|
-
}, "
|
25
|
+
}, "reqs");
|
28
26
|
}
|
29
|
-
if (
|
30
|
-
parts = parts.concat(path.map((optlPath) => join(" = ", optlPath.map(print)), "
|
27
|
+
if (node.opts) {
|
28
|
+
parts = parts.concat(path.map((optlPath) => join(" = ", optlPath.map(print)), "opts"));
|
31
29
|
}
|
32
|
-
if (rest && rest.type !== "excessed_comma") {
|
33
|
-
parts.push(path.call(print, "
|
30
|
+
if (node.rest && node.rest.type !== "excessed_comma") {
|
31
|
+
parts.push(path.call(print, "rest"));
|
34
32
|
}
|
35
|
-
if (
|
36
|
-
parts = parts.concat(path.map(print, "
|
33
|
+
if (node.posts) {
|
34
|
+
parts = parts.concat(path.map(print, "posts"));
|
37
35
|
}
|
38
|
-
if (
|
36
|
+
if (node.keywords) {
|
39
37
|
parts = parts.concat(path.map((kwargPath) => {
|
40
|
-
|
41
|
-
|
38
|
+
const kwarg = kwargPath.getValue();
|
39
|
+
const keyDoc = kwargPath.call(print, 0);
|
40
|
+
if (kwarg[1]) {
|
41
|
+
return group([keyDoc, " ", kwargPath.call(print, 1)]);
|
42
42
|
}
|
43
|
-
return
|
44
|
-
}, "
|
43
|
+
return keyDoc;
|
44
|
+
}, "keywords"));
|
45
45
|
}
|
46
|
-
if (
|
47
|
-
parts.push(
|
46
|
+
if (node.kwrest) {
|
47
|
+
parts.push(node.kwrest === "nil" ? "**nil" : path.call(print, "kwrest"));
|
48
48
|
}
|
49
|
-
if (block) {
|
50
|
-
parts.push(path.call(print, "
|
49
|
+
if (node.block) {
|
50
|
+
parts.push(path.call(print, "block"));
|
51
51
|
}
|
52
52
|
const contents = [join([",", line], parts)];
|
53
53
|
// You can put an extra comma at the end of block args between pipes to
|
@@ -59,7 +59,8 @@ const printParams = (path, opts, print) => {
|
|
59
59
|
// In ruby 2.5, the excessed comma is indicated by having a 0 in the rest
|
60
60
|
// param position. In ruby 2.6+ it's indicated by having an "excessed_comma"
|
61
61
|
// node in the rest position. Seems odd, but it's true.
|
62
|
-
if (rest === 0 ||
|
62
|
+
if (node.rest === 0 ||
|
63
|
+
(node.rest && node.rest.type === "excessed_comma")) {
|
63
64
|
contents.push(",");
|
64
65
|
}
|
65
66
|
// If the parent node is a paren then we skipped printing the parentheses so
|
@@ -84,6 +85,11 @@ const printParams = (path, opts, print) => {
|
|
84
85
|
return group(contents);
|
85
86
|
};
|
86
87
|
exports.printParams = printParams;
|
87
|
-
|
88
|
+
const printArgsForward = (path) => path.getValue().value;
|
89
|
+
exports.printArgsForward = printArgsForward;
|
88
90
|
exports.printKeywordRestParam = printRestParamSymbol("**");
|
89
91
|
exports.printRestParam = printRestParamSymbol("*");
|
92
|
+
const printExcessedComma = (path, opts, print) => {
|
93
|
+
return path.call(print, "value");
|
94
|
+
};
|
95
|
+
exports.printExcessedComma = printExcessedComma;
|