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/patterns.js
CHANGED
@@ -18,16 +18,16 @@ const printPatternArg = (path, opts, print) => {
|
|
18
18
|
return path.call(print);
|
19
19
|
};
|
20
20
|
const printAryPtn = (path, opts, print) => {
|
21
|
-
const
|
21
|
+
const node = path.getValue();
|
22
22
|
let argDocs = [];
|
23
|
-
if (
|
24
|
-
argDocs = argDocs.concat(path.map((argPath) => printPatternArg(argPath, opts, print), "
|
23
|
+
if (node.reqs.length > 0) {
|
24
|
+
argDocs = argDocs.concat(path.map((argPath) => printPatternArg(argPath, opts, print), "reqs"));
|
25
25
|
}
|
26
|
-
if (
|
27
|
-
argDocs.push(["*", path.call(print, "
|
26
|
+
if (node.rest) {
|
27
|
+
argDocs.push(["*", path.call(print, "rest")]);
|
28
28
|
}
|
29
|
-
if (
|
30
|
-
argDocs = argDocs.concat(path.map(print, "
|
29
|
+
if (node.posts.length > 0) {
|
30
|
+
argDocs = argDocs.concat(path.map(print, "posts"));
|
31
31
|
}
|
32
32
|
let argDoc = group(join([",", line], argDocs));
|
33
33
|
// There are a couple of cases where we _must_ use brackets. They include:
|
@@ -41,37 +41,37 @@ const printAryPtn = (path, opts, print) => {
|
|
41
41
|
// Consider the difference between `in key: first, second` and
|
42
42
|
// `in key: [first, second]`.
|
43
43
|
if (argDocs.length === 1 ||
|
44
|
-
constant ||
|
44
|
+
node.constant ||
|
45
45
|
patterns.includes(path.getParentNode().type)) {
|
46
46
|
argDoc = ["[", argDoc, "]"];
|
47
47
|
}
|
48
|
-
if (constant) {
|
49
|
-
return [path.call(print, "
|
48
|
+
if (node.constant) {
|
49
|
+
return [path.call(print, "constant"), argDoc];
|
50
50
|
}
|
51
51
|
return argDoc;
|
52
52
|
};
|
53
53
|
exports.printAryPtn = printAryPtn;
|
54
54
|
const printFndPtn = (path, opts, print) => {
|
55
|
-
const
|
55
|
+
const node = path.getValue();
|
56
56
|
const docs = [
|
57
57
|
"[",
|
58
58
|
group(join([",", line], [
|
59
|
-
["*", path.call(print, "
|
60
|
-
...path.map(print, "
|
61
|
-
["*", path.call(print, "
|
59
|
+
["*", path.call(print, "left")],
|
60
|
+
...path.map(print, "values"),
|
61
|
+
["*", path.call(print, "right")]
|
62
62
|
])),
|
63
63
|
"]"
|
64
64
|
];
|
65
|
-
if (constant) {
|
66
|
-
return [path.call(print, "
|
65
|
+
if (node.constant) {
|
66
|
+
return [path.call(print, "constant"), docs];
|
67
67
|
}
|
68
68
|
return docs;
|
69
69
|
};
|
70
70
|
exports.printFndPtn = printFndPtn;
|
71
71
|
const printHshPtn = (path, opts, print) => {
|
72
|
-
const
|
72
|
+
const node = path.getValue();
|
73
73
|
let args = [];
|
74
|
-
if (
|
74
|
+
if (node.keywords.length > 0) {
|
75
75
|
const printPair = (pairPath) => {
|
76
76
|
const parts = [pairPath.call(print, 0)];
|
77
77
|
if (pairPath.getValue()[1]) {
|
@@ -79,20 +79,20 @@ const printHshPtn = (path, opts, print) => {
|
|
79
79
|
}
|
80
80
|
return parts;
|
81
81
|
};
|
82
|
-
args = args.concat(path.map(printPair, "
|
82
|
+
args = args.concat(path.map(printPair, "keywords"));
|
83
83
|
}
|
84
|
-
if (
|
85
|
-
args.push(["**", path.call(print, "
|
84
|
+
if (node.kwrest) {
|
85
|
+
args.push(["**", path.call(print, "kwrest")]);
|
86
86
|
}
|
87
87
|
args = group(join([",", line], args));
|
88
|
-
if (constant) {
|
88
|
+
if (node.constant) {
|
89
89
|
args = ["[", args, "]"];
|
90
90
|
}
|
91
91
|
else if (patterns.includes(path.getParentNode().type)) {
|
92
92
|
args = ["{ ", args, " }"];
|
93
93
|
}
|
94
|
-
if (constant) {
|
95
|
-
return [path.call(print, "
|
94
|
+
if (node.constant) {
|
95
|
+
return [path.call(print, "constant"), args];
|
96
96
|
}
|
97
97
|
return args;
|
98
98
|
};
|
@@ -101,22 +101,19 @@ const printIn = (path, opts, print) => {
|
|
101
101
|
const keyword = "in ";
|
102
102
|
const parts = [
|
103
103
|
keyword,
|
104
|
-
align(keyword.length, path.call((valuePath) => printPatternArg(valuePath, opts, print), "
|
105
|
-
indent([hardline, path.call(print, "
|
104
|
+
align(keyword.length, path.call((valuePath) => printPatternArg(valuePath, opts, print), "pattern")),
|
105
|
+
indent([hardline, path.call(print, "stmts")])
|
106
106
|
];
|
107
|
-
if (path.getValue().
|
108
|
-
parts.push(hardline, path.call(print, "
|
107
|
+
if (path.getValue().cons) {
|
108
|
+
parts.push(hardline, path.call(print, "cons"));
|
109
109
|
}
|
110
110
|
return group(parts);
|
111
111
|
};
|
112
112
|
exports.printIn = printIn;
|
113
|
-
const printRAssign = (path, opts, print) =>
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
group(indent([line, rightDoc]))
|
120
|
-
]);
|
121
|
-
};
|
113
|
+
const printRAssign = (path, opts, print) => group([
|
114
|
+
path.call(print, "value"),
|
115
|
+
" ",
|
116
|
+
path.call(print, "op"),
|
117
|
+
group(indent([line, path.call(print, "pattern")]))
|
118
|
+
]);
|
122
119
|
exports.printRAssign = printRAssign;
|
data/dist/ruby/nodes/regexp.js
CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.printRegexpLiteral = void 0;
|
4
4
|
const utils_1 = require("../../utils");
|
5
5
|
function hasContent(node, pattern) {
|
6
|
-
return node.
|
6
|
+
return node.parts.some((part) => part.type === "tstring_content" && pattern.test(part.value));
|
7
7
|
}
|
8
8
|
// If the first part of this regex is plain string content, we have a space
|
9
9
|
// or an =, and we're contained within a command or command_call node, then we
|
@@ -11,10 +11,10 @@ function hasContent(node, pattern) {
|
|
11
11
|
// operator, e.g. foo / bar/ or foo /=bar/
|
12
12
|
function forwardSlashIsAmbiguous(path) {
|
13
13
|
const node = path.getValue();
|
14
|
-
const
|
15
|
-
return (
|
16
|
-
|
17
|
-
[" ", "="].includes(
|
14
|
+
const firstPart = node.parts[0];
|
15
|
+
return (firstPart &&
|
16
|
+
firstPart.type === "tstring_content" &&
|
17
|
+
[" ", "="].includes(firstPart.value[0]) &&
|
18
18
|
(0, utils_1.hasAncestor)(path, ["command", "command_call"]));
|
19
19
|
}
|
20
20
|
// This function is responsible for printing out regexp_literal nodes. They can
|
@@ -26,7 +26,7 @@ function forwardSlashIsAmbiguous(path) {
|
|
26
26
|
// itself. In that case we switch over to using %r with braces.
|
27
27
|
const printRegexpLiteral = (path, opts, print) => {
|
28
28
|
const node = path.getValue();
|
29
|
-
const docs = path.map(print, "
|
29
|
+
const docs = path.map(print, "parts");
|
30
30
|
// We should use braces if using a forward slash would be ambiguous in the
|
31
31
|
// current context or if there's a forward slash in the content of the regexp.
|
32
32
|
const useBraces = forwardSlashIsAmbiguous(path) || hasContent(node, /\//);
|
data/dist/ruby/nodes/rescue.js
CHANGED
@@ -5,12 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.printRetry = exports.printRedo = exports.printRescueMod = exports.printRescueEx = exports.printRescue = exports.printEnsure = exports.printBegin = void 0;
|
7
7
|
const prettier_1 = __importDefault(require("../../prettier"));
|
8
|
-
const utils_1 = require("../../utils");
|
9
8
|
const { align, group, hardline, indent, join, line } = prettier_1.default;
|
10
9
|
const printBegin = (path, opts, print) => {
|
11
10
|
return [
|
12
11
|
"begin",
|
13
|
-
indent([hardline, path.
|
12
|
+
indent([hardline, path.call(print, "bodystmt")]),
|
14
13
|
hardline,
|
15
14
|
"end"
|
16
15
|
];
|
@@ -18,15 +17,16 @@ const printBegin = (path, opts, print) => {
|
|
18
17
|
exports.printBegin = printBegin;
|
19
18
|
const printEnsure = (path, opts, print) => {
|
20
19
|
return [
|
21
|
-
path.call(print, "
|
22
|
-
indent([hardline, path.call(print, "
|
20
|
+
path.call(print, "keyword"),
|
21
|
+
indent([hardline, path.call(print, "stmts")])
|
23
22
|
];
|
24
23
|
};
|
25
24
|
exports.printEnsure = printEnsure;
|
26
25
|
const printRescue = (path, opts, print) => {
|
26
|
+
const node = path.getValue();
|
27
27
|
const parts = ["rescue"];
|
28
|
-
if (
|
29
|
-
parts.push(align("rescue ".length, path.call(print, "
|
28
|
+
if (node.extn) {
|
29
|
+
parts.push(align("rescue ".length, path.call(print, "extn")));
|
30
30
|
}
|
31
31
|
else {
|
32
32
|
// If you don't specify an error to rescue in a `begin/rescue` block, then
|
@@ -34,14 +34,14 @@ const printRescue = (path, opts, print) => {
|
|
34
34
|
// just going to explicitly add it.
|
35
35
|
parts.push(" StandardError");
|
36
36
|
}
|
37
|
-
const
|
38
|
-
if (
|
39
|
-
parts.push(indent([hardline,
|
37
|
+
const stmtsDoc = path.call(print, "stmts");
|
38
|
+
if (stmtsDoc.length > 0) {
|
39
|
+
parts.push(indent([hardline, stmtsDoc]));
|
40
40
|
}
|
41
41
|
// This is the next clause on the `begin` statement, either another
|
42
42
|
// `rescue`, and `ensure`, or an `else` clause.
|
43
|
-
if (
|
44
|
-
parts.push([hardline, path.call(print, "
|
43
|
+
if (node.cons) {
|
44
|
+
parts.push([hardline, path.call(print, "cons")]);
|
45
45
|
}
|
46
46
|
return group(parts);
|
47
47
|
};
|
@@ -49,37 +49,38 @@ exports.printRescue = printRescue;
|
|
49
49
|
// This is a container node that we're adding into the AST that isn't present in
|
50
50
|
// Ripper solely so that we have a nice place to attach inline comments.
|
51
51
|
const printRescueEx = (path, opts, print) => {
|
52
|
-
const
|
52
|
+
const node = path.getValue();
|
53
53
|
const parts = [];
|
54
|
-
if (
|
54
|
+
if (node.extns) {
|
55
55
|
// If there's just one exception being rescued, then it's just going to be a
|
56
56
|
// single doc node.
|
57
|
-
let exceptionDoc = path.call(print, "
|
57
|
+
let exceptionDoc = path.call(print, "extns");
|
58
58
|
// If there are multiple exceptions being rescued, then we're going to have
|
59
59
|
// multiple doc nodes returned as an array that we need to join together.
|
60
|
-
if (["mrhs_add_star", "mrhs_new_from_args"].includes(
|
60
|
+
if (["mrhs", "mrhs_add_star", "mrhs_new_from_args"].includes(node.extns.type)) {
|
61
61
|
exceptionDoc = group(join([",", line], exceptionDoc));
|
62
62
|
}
|
63
63
|
parts.push(" ", exceptionDoc);
|
64
64
|
}
|
65
|
-
if (
|
66
|
-
parts.push(" => ", path.call(print, "
|
65
|
+
if (node.var) {
|
66
|
+
parts.push(" => ", path.call(print, "var"));
|
67
67
|
}
|
68
68
|
return group(parts);
|
69
69
|
};
|
70
70
|
exports.printRescueEx = printRescueEx;
|
71
71
|
const printRescueMod = (path, opts, print) => {
|
72
|
-
const [statementDoc, valueDoc] = path.map(print, "body");
|
73
72
|
return [
|
74
73
|
"begin",
|
75
|
-
indent([hardline,
|
74
|
+
indent([hardline, path.call(print, "stmt")]),
|
76
75
|
hardline,
|
77
76
|
"rescue StandardError",
|
78
|
-
indent([hardline,
|
77
|
+
indent([hardline, path.call(print, "value")]),
|
79
78
|
hardline,
|
80
79
|
"end"
|
81
80
|
];
|
82
81
|
};
|
83
82
|
exports.printRescueMod = printRescueMod;
|
84
|
-
|
85
|
-
exports.
|
83
|
+
const printRedo = (path) => path.getValue().value;
|
84
|
+
exports.printRedo = printRedo;
|
85
|
+
const printRetry = (path) => path.getValue().value;
|
86
|
+
exports.printRetry = printRetry;
|
data/dist/ruby/nodes/return.js
CHANGED
@@ -5,12 +5,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.printReturn0 = exports.printReturn = void 0;
|
7
7
|
const prettier_1 = __importDefault(require("../../prettier"));
|
8
|
-
const utils_1 = require("../../utils");
|
9
8
|
const { group, ifBreak, indent, line, join, softline } = prettier_1.default;
|
10
9
|
// You can't skip the parentheses if you have comments or certain operators with
|
11
10
|
// lower precedence than the return keyword.
|
12
|
-
function canSkipParens(
|
13
|
-
const stmts =
|
11
|
+
function canSkipParens(paren) {
|
12
|
+
const stmts = paren.cnts;
|
13
|
+
// return(
|
14
|
+
// foo
|
15
|
+
// bar
|
16
|
+
// )
|
17
|
+
if (stmts.body.length !== 1) {
|
18
|
+
return false;
|
19
|
+
}
|
14
20
|
// return(
|
15
21
|
// # a
|
16
22
|
// b
|
@@ -20,49 +26,67 @@ function canSkipParens(args) {
|
|
20
26
|
}
|
21
27
|
const stmt = stmts.body[0];
|
22
28
|
// return (a or b)
|
23
|
-
if (stmt.type === "binary" && ["and", "or"].includes(stmt.
|
29
|
+
if (stmt.type === "binary" && ["and", "or"].includes(stmt.op)) {
|
24
30
|
return false;
|
25
31
|
}
|
26
32
|
// return (not a)
|
27
|
-
if (stmt.type === "
|
33
|
+
if (stmt.type === "not") {
|
28
34
|
return false;
|
29
35
|
}
|
30
36
|
return true;
|
31
37
|
}
|
32
38
|
const printReturn = (path, opts, print) => {
|
33
|
-
|
34
|
-
let
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
if (args.
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
39
|
+
const node = path.getValue();
|
40
|
+
let parts = "";
|
41
|
+
let joining = false;
|
42
|
+
if (node.args.type === "args_add_block") {
|
43
|
+
const args = node.args.args;
|
44
|
+
const steps = ["args", "args"];
|
45
|
+
if (args.type === "args" && args.parts.length === 1 && args.parts[0]) {
|
46
|
+
// This is the first and only argument being passed to the return keyword.
|
47
|
+
let arg = args.parts[0];
|
48
|
+
steps.push("parts", 0);
|
49
|
+
// If the body of the return contains parens, then just skip directly to
|
50
|
+
// the content of the parens so that we can skip printing parens if we
|
51
|
+
// don't want them.
|
52
|
+
if (arg.type === "paren") {
|
53
|
+
// If we can't skip over the parentheses, then we know we can just bail
|
54
|
+
// out here and print the only argument as normal since it's a paren.
|
55
|
+
if (!canSkipParens(arg)) {
|
56
|
+
return ["return", path.call(print, "args")];
|
57
|
+
}
|
58
|
+
arg = arg.cnts.body[0];
|
59
|
+
steps.push("cnts", "body", 0);
|
60
|
+
}
|
61
|
+
// If we're returning an array literal that isn't a special array that has
|
62
|
+
// at least 2 elements, then we want to grab the arguments so that we can
|
63
|
+
// print them out as if they were normal return arguments.
|
64
|
+
if (arg.type === "array" && arg.cnts) {
|
65
|
+
const contents = arg.cnts;
|
66
|
+
if (contents.type === "args" && contents.parts.length > 1) {
|
67
|
+
// If we have just regular arguments and we have more than 1.
|
68
|
+
steps.push("cnts");
|
69
|
+
}
|
70
|
+
}
|
52
71
|
}
|
72
|
+
// We're doing this weird dance with the steps variable because it's
|
73
|
+
// possible that you're printing an array nested under some parentheses, in
|
74
|
+
// which case we still want to descend down that far. For example,
|
75
|
+
// return([1, 2, 3]) should print as return 1, 2, 3.
|
76
|
+
parts = path.call((targetPath) => {
|
77
|
+
const target = targetPath.getValue();
|
78
|
+
joining = target.type === "args" || target.type === "args_add_block";
|
79
|
+
return print(targetPath);
|
80
|
+
}, ...steps);
|
53
81
|
}
|
54
|
-
//
|
55
|
-
//
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
// be a singular doc as opposed to an array.
|
60
|
-
const value = Array.isArray(parts) ? join([",", line], parts) : parts;
|
61
|
-
// We only get here if we have comments somewhere that would prevent us from
|
62
|
-
// skipping the parentheses.
|
63
|
-
if (args.body.length === 1 && args.body[0].type === "paren") {
|
64
|
-
return ["return", value];
|
82
|
+
// If we didn't hit any of our special cases, then just print out the
|
83
|
+
// arguments normally here.
|
84
|
+
if (parts === "") {
|
85
|
+
parts = path.call(print, "args");
|
86
|
+
joining = true;
|
65
87
|
}
|
88
|
+
const useBrackets = Array.isArray(parts) && parts.length > 1;
|
89
|
+
const value = joining ? join([",", line], parts) : parts;
|
66
90
|
return group([
|
67
91
|
"return",
|
68
92
|
ifBreak(useBrackets ? " [" : "(", " "),
|
@@ -72,4 +96,5 @@ const printReturn = (path, opts, print) => {
|
|
72
96
|
]);
|
73
97
|
};
|
74
98
|
exports.printReturn = printReturn;
|
75
|
-
|
99
|
+
const printReturn0 = (path) => path.getValue().value;
|
100
|
+
exports.printReturn0 = printReturn0;
|
@@ -3,40 +3,41 @@ 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.printStatements = exports.printProgram = exports.printComment = exports.printEndContent = exports.printParen = exports.printBodyStmt = void 0;
|
7
7
|
const prettier_1 = __importDefault(require("../../prettier"));
|
8
8
|
const utils_1 = require("../../utils");
|
9
|
+
const location_1 = require("../location");
|
9
10
|
const { breakParent, dedent, group, hardline, indent, join, line, literalline, softline, trim } = prettier_1.default;
|
10
11
|
const printBodyStmt = (path, opts, print) => {
|
11
|
-
const
|
12
|
+
const node = path.getValue();
|
12
13
|
const parts = [];
|
13
|
-
if (!(0, utils_1.isEmptyStmts)(stmts)) {
|
14
|
-
parts.push(path.call(print, "
|
14
|
+
if (!(0, utils_1.isEmptyStmts)(node.stmts)) {
|
15
|
+
parts.push(path.call(print, "stmts"));
|
15
16
|
}
|
16
|
-
if (
|
17
|
-
parts.push(dedent([hardline, path.call(print, "
|
17
|
+
if (node.rsc) {
|
18
|
+
parts.push(dedent([hardline, path.call(print, "rsc")]));
|
18
19
|
}
|
19
|
-
if (
|
20
|
+
if (node.els) {
|
20
21
|
// Before Ruby 2.6, this piece of bodystmt was an explicit "else" node
|
21
22
|
/* istanbul ignore next */
|
22
|
-
const stmts =
|
23
|
-
? path.call(print, "
|
24
|
-
: path.call(print, "
|
23
|
+
const stmts = node.els.type === "else"
|
24
|
+
? path.call(print, "els", "body", 0)
|
25
|
+
: path.call(print, "els");
|
25
26
|
parts.push([dedent([hardline, "else"]), hardline, stmts]);
|
26
27
|
}
|
27
|
-
if (
|
28
|
-
parts.push(dedent([hardline, path.call(print, "
|
28
|
+
if (node.ens) {
|
29
|
+
parts.push(dedent([hardline, path.call(print, "ens")]));
|
29
30
|
}
|
30
31
|
return group(parts);
|
31
32
|
};
|
32
33
|
exports.printBodyStmt = printBodyStmt;
|
33
|
-
const argNodeTypes = ["args", "
|
34
|
+
const argNodeTypes = ["args", "args_add_block"];
|
34
35
|
const printParen = (path, opts, print) => {
|
35
|
-
const contentNode = path.getValue().
|
36
|
+
const contentNode = path.getValue().cnts;
|
36
37
|
if (!contentNode) {
|
37
38
|
return [path.call(print, "lparen"), ")"];
|
38
39
|
}
|
39
|
-
let contentDoc = path.call(print, "
|
40
|
+
let contentDoc = path.call(print, "cnts");
|
40
41
|
// If the content is params, we're going to let it handle its own parentheses
|
41
42
|
// so that it breaks nicely.
|
42
43
|
if (contentNode.type === "params") {
|
@@ -56,19 +57,17 @@ const printParen = (path, opts, print) => {
|
|
56
57
|
};
|
57
58
|
exports.printParen = printParen;
|
58
59
|
const printEndContent = (path) => {
|
59
|
-
const
|
60
|
-
return [trim, "__END__", literalline,
|
60
|
+
const node = path.getValue();
|
61
|
+
return [trim, "__END__", literalline, node.value];
|
61
62
|
};
|
62
63
|
exports.printEndContent = printEndContent;
|
63
64
|
const printComment = (path, opts) => {
|
64
65
|
return opts.printer.printComment(path, opts);
|
65
66
|
};
|
66
67
|
exports.printComment = printComment;
|
67
|
-
const printProgram = (path, opts, print) =>
|
68
|
-
return [join(hardline, path.map(print, "body")), hardline];
|
69
|
-
};
|
68
|
+
const printProgram = (path, opts, print) => [path.call(print, "stmts"), hardline];
|
70
69
|
exports.printProgram = printProgram;
|
71
|
-
const
|
70
|
+
const printStatements = (path, opts, print) => {
|
72
71
|
const stmts = path.getValue().body;
|
73
72
|
// This is a special case where we have only comments inside a statement
|
74
73
|
// list. In this case we want to avoid doing any kind of line number
|
@@ -93,19 +92,19 @@ const printStmts = (path, opts, print) => {
|
|
93
92
|
if (lineNo === null) {
|
94
93
|
parts.push(printed);
|
95
94
|
}
|
96
|
-
else if (stmt.
|
95
|
+
else if ((0, location_1.getStartLine)(stmt.loc) - lineNo > 1 ||
|
97
96
|
[stmt.type, stmts[index - 1].type].includes("access_ctrl")) {
|
98
97
|
parts.push(hardline, hardline, printed);
|
99
98
|
}
|
100
|
-
else if (stmt.
|
99
|
+
else if ((0, location_1.getStartLine)(stmt.loc) !== lineNo ||
|
101
100
|
path.getParentNode().type !== "string_embexpr") {
|
102
101
|
parts.push(hardline, printed);
|
103
102
|
}
|
104
103
|
else {
|
105
104
|
parts.push("; ", printed);
|
106
105
|
}
|
107
|
-
lineNo = stmt.
|
106
|
+
lineNo = (0, location_1.getEndLine)(stmt.loc);
|
108
107
|
});
|
109
108
|
return parts;
|
110
109
|
};
|
111
|
-
exports.
|
110
|
+
exports.printStatements = printStatements;
|