prettier 2.0.0 → 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 +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/printer.js
CHANGED
@@ -4,18 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
const prettier_1 = __importDefault(require("../prettier"));
|
7
|
+
const utils_1 = require("../utils");
|
7
8
|
const embed_1 = __importDefault(require("./embed"));
|
8
9
|
const nodes_1 = __importDefault(require("./nodes"));
|
9
10
|
const { trim } = prettier_1.default;
|
10
|
-
const noComments = [
|
11
|
-
"args",
|
12
|
-
"args_add_block",
|
13
|
-
"args_add_star",
|
14
|
-
"mlhs",
|
15
|
-
"mlhs_add_post",
|
16
|
-
"mlhs_add_star",
|
17
|
-
"mlhs_paren"
|
18
|
-
];
|
11
|
+
const noComments = ["args", "args_add_block", "mlhs", "mlhs_paren"];
|
19
12
|
const printer = {
|
20
13
|
// Certain nodes are used more for organizational purposed than for actually
|
21
14
|
// displaying content, so we tell prettier that we don't want comments
|
@@ -25,61 +18,9 @@ const printer = {
|
|
25
18
|
},
|
26
19
|
embed: embed_1.default,
|
27
20
|
// This function tells prettier how to recurse down our AST so that it can
|
28
|
-
// find where it needs to attach the comments.
|
29
|
-
// abysmal, but we're going to leave it as is to get this out.
|
21
|
+
// find where it needs to attach the comments.
|
30
22
|
getCommentChildNodes(node) {
|
31
|
-
|
32
|
-
case "heredoc":
|
33
|
-
return [node.beging];
|
34
|
-
case "aryptn":
|
35
|
-
return [node.body[0]]
|
36
|
-
.concat(node.body[1])
|
37
|
-
.concat(node.body[2])
|
38
|
-
.concat(node.body[3]);
|
39
|
-
case "hshptn": {
|
40
|
-
const pairs = node.body[1];
|
41
|
-
const values = pairs.reduce((left, right) => left.concat(right), []);
|
42
|
-
return [node.body[0]].concat(values).concat(node.body[2]);
|
43
|
-
}
|
44
|
-
case "params": {
|
45
|
-
const [reqs, optls, rest, post, kwargs, kwargRest, block] = node.body;
|
46
|
-
let parts = reqs || [];
|
47
|
-
(optls || []).forEach((optl) => {
|
48
|
-
parts = parts.concat(optl);
|
49
|
-
});
|
50
|
-
if (rest) {
|
51
|
-
parts.push(rest);
|
52
|
-
}
|
53
|
-
parts = parts.concat(post || []);
|
54
|
-
(kwargs || []).forEach((kwarg) => {
|
55
|
-
if (kwarg[1]) {
|
56
|
-
parts = parts.concat(kwarg);
|
57
|
-
}
|
58
|
-
else {
|
59
|
-
parts.push(kwarg[0]);
|
60
|
-
}
|
61
|
-
});
|
62
|
-
if (kwargRest && kwargRest !== "nil") {
|
63
|
-
parts.push(kwargRest);
|
64
|
-
}
|
65
|
-
if (block) {
|
66
|
-
parts.push(block);
|
67
|
-
}
|
68
|
-
return parts;
|
69
|
-
}
|
70
|
-
case "brace_block":
|
71
|
-
return [node.body[0], node.body[1], node.beging];
|
72
|
-
case "do_block":
|
73
|
-
return [node.body[0], node.body[1], node.beging];
|
74
|
-
case "paren":
|
75
|
-
return [node.lparen, node.body[0]];
|
76
|
-
default: {
|
77
|
-
if (Array.isArray(node.body)) {
|
78
|
-
return node.body.filter((child) => child && typeof child === "object");
|
79
|
-
}
|
80
|
-
return [];
|
81
|
-
}
|
82
|
-
}
|
23
|
+
return (0, utils_1.getChildNodes)(node);
|
83
24
|
},
|
84
25
|
// This is an escape-hatch to ignore nodes in the tree. If you have a comment
|
85
26
|
// that includes this pattern, then the entire node will be ignored and just
|
@@ -94,7 +35,7 @@ const printer = {
|
|
94
35
|
// *feels* like a block comment equivalent in JavaScript so I'm going to leave
|
95
36
|
// it in place for now.
|
96
37
|
isBlockComment(comment) {
|
97
|
-
return comment.type === "
|
38
|
+
return comment.type === "embdoc";
|
98
39
|
},
|
99
40
|
// This function handles adding the format pragma to a source string. This is
|
100
41
|
// an optional workflow for incremental adoption.
|
@@ -107,20 +48,17 @@ const printer = {
|
|
107
48
|
print(path, opts, print) {
|
108
49
|
const node = path.getValue();
|
109
50
|
const printer = nodes_1.default[node.type];
|
110
|
-
if (printer) {
|
111
|
-
|
112
|
-
}
|
113
|
-
if (node.type[0] === "@") {
|
114
|
-
return node.body;
|
51
|
+
if (!printer) {
|
52
|
+
throw new Error(`Unsupported node type: ${node.type}`);
|
115
53
|
}
|
116
|
-
|
54
|
+
return printer(path, opts, print);
|
117
55
|
},
|
118
56
|
// This is the generic print function for any comment in the AST. It handles
|
119
57
|
// both regular comments that begin with a # and embdoc comments, which are
|
120
58
|
// surrounded by =begin..=end.
|
121
59
|
printComment(path) {
|
122
60
|
const comment = path.getValue();
|
123
|
-
if (comment.type === "
|
61
|
+
if (comment.type === "comment") {
|
124
62
|
return `#${comment.value}`;
|
125
63
|
}
|
126
64
|
return [trim, comment.value];
|
data/dist/ruby/toProc.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
function
|
3
|
+
function isPeriod(node) {
|
4
4
|
// Older versions of Ruby didn't have a @period ripper event, so we need to
|
5
5
|
// explicitly cast to any here.
|
6
6
|
if (node === "::" || node === ".") {
|
7
7
|
return true;
|
8
8
|
}
|
9
|
-
return node.type === "
|
9
|
+
return node.type === "period";
|
10
10
|
}
|
11
11
|
// If you have a simple block that only calls a method on the single required
|
12
12
|
// parameter that is passed to it, then you can replace that block with the
|
@@ -20,74 +20,72 @@ function isCall(node) {
|
|
20
20
|
//
|
21
21
|
// This works with `do` blocks as well.
|
22
22
|
function toProc(path, node) {
|
23
|
-
const [variables, blockContents] = node.body;
|
24
23
|
// Ensure that there are variables being passed to this block.
|
25
|
-
const params =
|
24
|
+
const params = node.block_var && node.block_var.params;
|
26
25
|
if (!params) {
|
27
26
|
return null;
|
28
27
|
}
|
29
28
|
// Ensure there is one and only one parameter, and that it is required.
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
if (params.reqs.length !== 1 ||
|
30
|
+
params.opts.length !== 0 ||
|
31
|
+
params.rest ||
|
32
|
+
params.posts.length !== 0 ||
|
33
|
+
params.keywords.length !== 0 ||
|
34
|
+
params.kwrest ||
|
35
|
+
params.block) {
|
35
36
|
return null;
|
36
37
|
}
|
38
|
+
// Get the list of statements from the block
|
37
39
|
let statements;
|
38
|
-
if (
|
39
|
-
//
|
40
|
-
|
41
|
-
const rescueElseEnsure = blockContents.body.slice(1);
|
42
|
-
// You can’t use the to_proc shortcut if you’re rescuing
|
43
|
-
if (rescueElseEnsure.some(Boolean)) {
|
40
|
+
if (node.type === "do_block") {
|
41
|
+
// If you have any other clauses on the bodystmt, then we can't transform.
|
42
|
+
if (node.bodystmt.rsc || node.bodystmt.els || node.bodystmt.ens) {
|
44
43
|
return null;
|
45
44
|
}
|
46
|
-
statements =
|
45
|
+
statements = node.bodystmt.stmts.body;
|
47
46
|
}
|
48
47
|
else {
|
49
|
-
|
50
|
-
statements = blockContents;
|
48
|
+
statements = node.stmts.body;
|
51
49
|
}
|
52
50
|
// Ensure the block contains only one statement
|
53
|
-
if (statements.
|
51
|
+
if (statements.length !== 1) {
|
54
52
|
return null;
|
55
53
|
}
|
56
54
|
// Ensure that statement is a call and that it has no comments attached
|
57
|
-
const [
|
58
|
-
if (
|
55
|
+
const [call] = statements;
|
56
|
+
if (call.type !== "call" || call.comments) {
|
59
57
|
return null;
|
60
58
|
}
|
61
59
|
// Ensure the call is a method of the block argument
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
method.type !== "@ident") {
|
60
|
+
if (call.receiver.type !== "var_ref" ||
|
61
|
+
call.receiver.value.value !== params.reqs[0].value ||
|
62
|
+
!isPeriod(call.op) ||
|
63
|
+
call.message === "call" ||
|
64
|
+
call.message.type !== "ident") {
|
68
65
|
return null;
|
69
66
|
}
|
70
67
|
// Ensure that we're not inside of a hash that is being passed to a key that
|
71
68
|
// corresponds to `:if` or `:unless` to avoid problems with callbacks with
|
72
69
|
// Rails. For more context, see:
|
73
70
|
// https://github.com/prettier/plugin-ruby/issues/449
|
74
|
-
let
|
71
|
+
let parentNode = null;
|
75
72
|
if (path.getValue().type === "method_add_block") {
|
76
|
-
|
73
|
+
parentNode = path.getParentNode();
|
77
74
|
}
|
78
75
|
else {
|
79
|
-
|
76
|
+
parentNode = path.getParentNode(2);
|
80
77
|
}
|
81
|
-
if (
|
82
|
-
const
|
83
|
-
|
78
|
+
if (parentNode && parentNode.type === "assoc") {
|
79
|
+
const assocNode = parentNode;
|
80
|
+
const key = assocNode.key;
|
81
|
+
if (key.type === "label" && ["if:", "unless:"].includes(key.value)) {
|
84
82
|
return null;
|
85
83
|
}
|
86
84
|
if (key.type === "symbol_literal" &&
|
87
|
-
["if", "unless"].includes(key.
|
85
|
+
["if", "unless"].includes(key.value.value)) {
|
88
86
|
return null;
|
89
87
|
}
|
90
88
|
}
|
91
|
-
return `&:${
|
89
|
+
return `&:${call.message.value}`;
|
92
90
|
}
|
93
91
|
exports.default = toProc;
|
data/dist/types.js
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
3
|
if (k2 === undefined) k2 = k;
|
4
|
-
Object.
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
5
9
|
}) : (function(o, m, k, k2) {
|
6
10
|
if (k2 === undefined) k2 = k;
|
7
11
|
o[k2] = m[k];
|
@@ -1,5 +1,9 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const getChildNodes_1 = __importDefault(require("./getChildNodes"));
|
3
7
|
// If the node is a type of assignment or if the node is a paren and nested
|
4
8
|
// inside that paren is a node that is a type of assignment.
|
5
9
|
function containsAssignment(node) {
|
@@ -9,7 +13,6 @@ function containsAssignment(node) {
|
|
9
13
|
if (["assign", "massign", "opassign"].includes(node.type)) {
|
10
14
|
return true;
|
11
15
|
}
|
12
|
-
|
13
|
-
return Array.isArray(anyNode.body) && anyNode.body.some(containsAssignment);
|
16
|
+
return (0, getChildNodes_1.default)(node).some(containsAssignment);
|
14
17
|
}
|
15
18
|
exports.default = containsAssignment;
|
@@ -0,0 +1,305 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
function throwBadNode(node) {
|
4
|
+
throw new Error(`Unknown node ${node.type}`);
|
5
|
+
}
|
6
|
+
function getChildNodes(node) {
|
7
|
+
switch (node.type) {
|
8
|
+
case "CHAR":
|
9
|
+
case "__end__":
|
10
|
+
case "backref":
|
11
|
+
case "backtick":
|
12
|
+
case "const":
|
13
|
+
case "cvar":
|
14
|
+
case "float":
|
15
|
+
case "gvar":
|
16
|
+
case "heredoc_beg":
|
17
|
+
case "ident":
|
18
|
+
case "imaginary":
|
19
|
+
case "int":
|
20
|
+
case "ivar":
|
21
|
+
case "kw":
|
22
|
+
case "label":
|
23
|
+
case "lbrace":
|
24
|
+
case "lparen":
|
25
|
+
case "op":
|
26
|
+
case "period":
|
27
|
+
case "rational":
|
28
|
+
case "tstring_content":
|
29
|
+
return [];
|
30
|
+
case "BEGIN":
|
31
|
+
return [node.lbrace, node.stmts];
|
32
|
+
case "END":
|
33
|
+
return [node.lbrace, node.stmts];
|
34
|
+
case "access_ctrl":
|
35
|
+
return [node.value];
|
36
|
+
case "alias":
|
37
|
+
return [node.left, node.right];
|
38
|
+
case "aref":
|
39
|
+
return [node.collection, node.index];
|
40
|
+
case "aref_field":
|
41
|
+
return [node.collection, node.index];
|
42
|
+
case "arg_paren":
|
43
|
+
return [node.args];
|
44
|
+
case "args":
|
45
|
+
return node.parts;
|
46
|
+
case "args_add_block":
|
47
|
+
return [node.args, node.block];
|
48
|
+
case "args_forward":
|
49
|
+
return [];
|
50
|
+
case "arg_star":
|
51
|
+
return [node.value];
|
52
|
+
case "array":
|
53
|
+
return [node.cnts];
|
54
|
+
case "aryptn":
|
55
|
+
return [node.constant, ...node.reqs, node.rest, ...node.posts];
|
56
|
+
case "assign":
|
57
|
+
return [node.target, node.value];
|
58
|
+
case "assoc":
|
59
|
+
return [node.key, node.value];
|
60
|
+
case "assoc_splat":
|
61
|
+
return [node.value];
|
62
|
+
case "assoclist_from_args":
|
63
|
+
return node.assocs;
|
64
|
+
case "bare_assoc_hash":
|
65
|
+
return node.assocs;
|
66
|
+
case "begin":
|
67
|
+
return [node.bodystmt];
|
68
|
+
case "binary":
|
69
|
+
return [node.left, node.right];
|
70
|
+
case "block_var":
|
71
|
+
return [node.params, ...node.locals];
|
72
|
+
case "blockarg":
|
73
|
+
return [node.name];
|
74
|
+
case "bodystmt":
|
75
|
+
return [node.stmts, node.rsc, node.els, node.ens];
|
76
|
+
case "brace_block":
|
77
|
+
return [node.lbrace, node.block_var, node.stmts];
|
78
|
+
case "break":
|
79
|
+
return [node.args];
|
80
|
+
case "call": {
|
81
|
+
const childNodes = [node.receiver];
|
82
|
+
if (node.op !== "::") {
|
83
|
+
childNodes.push(node.op);
|
84
|
+
}
|
85
|
+
if (node.message !== "call") {
|
86
|
+
childNodes.push(node.message);
|
87
|
+
}
|
88
|
+
return childNodes;
|
89
|
+
}
|
90
|
+
case "case":
|
91
|
+
return [node.value, node.cons];
|
92
|
+
case "class":
|
93
|
+
return [node.constant, node.superclass, node.bodystmt];
|
94
|
+
case "command":
|
95
|
+
return [node.message, node.args];
|
96
|
+
case "command_call":
|
97
|
+
return [node.receiver, node.message, node.args];
|
98
|
+
case "const_path_field":
|
99
|
+
return [node.parent, node.constant];
|
100
|
+
case "const_path_ref":
|
101
|
+
return [node.parent, node.constant];
|
102
|
+
case "const_ref":
|
103
|
+
return [node.constant];
|
104
|
+
case "def":
|
105
|
+
return [node.name, node.params, node.bodystmt];
|
106
|
+
case "def_endless":
|
107
|
+
return [node.name, node.paren, node.stmt];
|
108
|
+
case "defined":
|
109
|
+
return [node.value];
|
110
|
+
case "defs":
|
111
|
+
return [node.target, node.op, node.name, node.params, node.bodystmt];
|
112
|
+
case "do_block":
|
113
|
+
return [node.keyword, node.block_var, node.bodystmt];
|
114
|
+
case "dot2":
|
115
|
+
return [node.left, node.right];
|
116
|
+
case "dot3":
|
117
|
+
return [node.left, node.right];
|
118
|
+
case "dyna_symbol":
|
119
|
+
return node.parts;
|
120
|
+
case "else":
|
121
|
+
return [node.stmts];
|
122
|
+
case "elsif":
|
123
|
+
return [node.pred, node.stmts, node.cons];
|
124
|
+
case "ensure":
|
125
|
+
return [node.keyword, node.stmts];
|
126
|
+
case "excessed_comma":
|
127
|
+
return [];
|
128
|
+
case "fcall":
|
129
|
+
return [node.value];
|
130
|
+
case "field": {
|
131
|
+
const childNodes = [node.parent];
|
132
|
+
if (node.op !== "::") {
|
133
|
+
childNodes.push(node.op);
|
134
|
+
}
|
135
|
+
childNodes.push(node.name);
|
136
|
+
return childNodes;
|
137
|
+
}
|
138
|
+
case "fndptn":
|
139
|
+
return [node.constant, node.left, ...node.values, node.right];
|
140
|
+
case "for":
|
141
|
+
return [node.index, node.collection, node.stmts];
|
142
|
+
case "hash":
|
143
|
+
return [node.cnts];
|
144
|
+
case "heredoc":
|
145
|
+
return [node.beging, ...node.parts];
|
146
|
+
case "hshptn": {
|
147
|
+
const childNodes = [node.constant];
|
148
|
+
node.keywords.forEach(([key, value]) => {
|
149
|
+
childNodes.push(key, value);
|
150
|
+
});
|
151
|
+
childNodes.push(node.kwrest);
|
152
|
+
return childNodes;
|
153
|
+
}
|
154
|
+
case "if":
|
155
|
+
return [node.pred, node.stmts, node.cons];
|
156
|
+
case "ifop":
|
157
|
+
return [node.pred, node.tthy, node.flsy];
|
158
|
+
case "if_mod":
|
159
|
+
return [node.stmt, node.pred];
|
160
|
+
case "in":
|
161
|
+
return [node.pattern, node.stmts, node.cons];
|
162
|
+
case "kwrest_param":
|
163
|
+
return [node.name];
|
164
|
+
case "lambda":
|
165
|
+
return [node.params, node.stmts];
|
166
|
+
case "massign":
|
167
|
+
return [node.target, node.value];
|
168
|
+
case "method_add_arg":
|
169
|
+
return [node.call, node.args];
|
170
|
+
case "method_add_block":
|
171
|
+
return [node.call, node.block];
|
172
|
+
case "mlhs":
|
173
|
+
return node.parts;
|
174
|
+
case "mlhs_paren":
|
175
|
+
return [node.cnts];
|
176
|
+
case "module":
|
177
|
+
return [node.constant, node.bodystmt];
|
178
|
+
case "mrhs":
|
179
|
+
return node.parts;
|
180
|
+
case "mrhs_add_star":
|
181
|
+
return [node.mrhs, node.star];
|
182
|
+
case "mrhs_new_from_args":
|
183
|
+
return [node.args];
|
184
|
+
case "next":
|
185
|
+
return [node.args];
|
186
|
+
case "not":
|
187
|
+
return [node.value];
|
188
|
+
case "opassign":
|
189
|
+
return [node.target, node.op, node.value];
|
190
|
+
case "params": {
|
191
|
+
let childNodes = [...node.reqs];
|
192
|
+
node.opts.forEach(([key, value]) => {
|
193
|
+
childNodes.push(key, value);
|
194
|
+
});
|
195
|
+
childNodes.push(node.rest);
|
196
|
+
childNodes = childNodes.concat(node.posts);
|
197
|
+
node.keywords.forEach(([key, value]) => {
|
198
|
+
childNodes.push(key);
|
199
|
+
if (value) {
|
200
|
+
childNodes.push(value);
|
201
|
+
}
|
202
|
+
});
|
203
|
+
if (node.kwrest && node.kwrest !== "nil") {
|
204
|
+
childNodes.push(node.kwrest);
|
205
|
+
}
|
206
|
+
if (node.block) {
|
207
|
+
childNodes.push(node.block);
|
208
|
+
}
|
209
|
+
return childNodes;
|
210
|
+
}
|
211
|
+
case "paren":
|
212
|
+
return [node.lparen, node.cnts];
|
213
|
+
case "program":
|
214
|
+
return [node.stmts];
|
215
|
+
case "qsymbols":
|
216
|
+
return [];
|
217
|
+
case "qwords":
|
218
|
+
return [];
|
219
|
+
case "rassign":
|
220
|
+
return [node.value, node.op, node.pattern];
|
221
|
+
case "redo":
|
222
|
+
return [];
|
223
|
+
case "regexp_literal":
|
224
|
+
return node.parts;
|
225
|
+
case "rescue":
|
226
|
+
return [node.extn, node.stmts, node.cons];
|
227
|
+
case "rescue_ex":
|
228
|
+
return [node.extns, node.var];
|
229
|
+
case "rescue_mod":
|
230
|
+
return [node.stmt, node.value];
|
231
|
+
case "rest_param":
|
232
|
+
return [node.name];
|
233
|
+
case "retry":
|
234
|
+
return [];
|
235
|
+
case "return":
|
236
|
+
return [node.args];
|
237
|
+
case "return0":
|
238
|
+
return [];
|
239
|
+
case "sclass":
|
240
|
+
return [node.target, node.bodystmt];
|
241
|
+
case "statements":
|
242
|
+
return node.body;
|
243
|
+
case "string_concat":
|
244
|
+
return [node.left, node.right];
|
245
|
+
case "string_dvar":
|
246
|
+
return [node.var];
|
247
|
+
case "string_embexpr":
|
248
|
+
return [node.stmts];
|
249
|
+
case "string_literal":
|
250
|
+
return node.parts;
|
251
|
+
case "super":
|
252
|
+
return [node.args];
|
253
|
+
case "symbol_literal":
|
254
|
+
return [node.value];
|
255
|
+
case "symbols":
|
256
|
+
return [];
|
257
|
+
case "top_const_field":
|
258
|
+
return [node.constant];
|
259
|
+
case "top_const_ref":
|
260
|
+
return [node.constant];
|
261
|
+
case "unary":
|
262
|
+
return [node.value];
|
263
|
+
case "undef":
|
264
|
+
return node.syms;
|
265
|
+
case "unless":
|
266
|
+
return [node.pred, node.stmts, node.cons];
|
267
|
+
case "unless_mod":
|
268
|
+
return [node.stmt, node.pred];
|
269
|
+
case "until":
|
270
|
+
return [node.pred, node.stmts];
|
271
|
+
case "until_mod":
|
272
|
+
return [node.stmt, node.pred];
|
273
|
+
case "var_alias":
|
274
|
+
return [node.left, node.right];
|
275
|
+
case "var_field":
|
276
|
+
return [node.value];
|
277
|
+
case "var_ref":
|
278
|
+
return [node.value];
|
279
|
+
case "vcall":
|
280
|
+
return [node.value];
|
281
|
+
case "void_stmt":
|
282
|
+
return [];
|
283
|
+
case "when":
|
284
|
+
return [node.args, node.stmts, node.cons];
|
285
|
+
case "while":
|
286
|
+
return [node.pred, node.stmts];
|
287
|
+
case "while_mod":
|
288
|
+
return [node.stmt, node.pred];
|
289
|
+
case "word":
|
290
|
+
return node.parts;
|
291
|
+
case "words":
|
292
|
+
return [];
|
293
|
+
case "xstring_literal":
|
294
|
+
return node.parts;
|
295
|
+
case "yield":
|
296
|
+
return [node.args];
|
297
|
+
case "yield0":
|
298
|
+
return [];
|
299
|
+
case "zsuper":
|
300
|
+
return [];
|
301
|
+
default:
|
302
|
+
throwBadNode(node);
|
303
|
+
}
|
304
|
+
}
|
305
|
+
exports.default = getChildNodes;
|
@@ -5,6 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
const isEmptyStmts_1 = __importDefault(require("./isEmptyStmts"));
|
7
7
|
function isEmptyBodyStmt(node) {
|
8
|
-
return (0, isEmptyStmts_1.default)(node.
|
8
|
+
return (0, isEmptyStmts_1.default)(node.stmts) && !node.rsc && !node.ens && !node.els;
|
9
9
|
}
|
10
10
|
exports.default = isEmptyBodyStmt;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
function isEmptyParams(node) {
|
4
|
+
return (node.reqs.length === 0 &&
|
5
|
+
node.opts.length === 0 &&
|
6
|
+
!node.rest &&
|
7
|
+
node.posts.length === 0 &&
|
8
|
+
node.keywords.length === 0 &&
|
9
|
+
!node.kwrest &&
|
10
|
+
!node.block);
|
11
|
+
}
|
12
|
+
exports.default = isEmptyParams;
|
data/dist/utils/isEmptyStmts.js
CHANGED
data/dist/utils/makeCall.js
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
const makeCall = (path, opts, print) => {
|
4
|
-
const
|
4
|
+
const node = path.getValue();
|
5
|
+
const operator = node.op;
|
5
6
|
// Ignoring the next block for coverage information because it's only relevant
|
6
7
|
// in Ruby 2.5 and below.
|
7
8
|
/* istanbul ignore next */
|
8
|
-
if ([".", "&."].includes(
|
9
|
-
return
|
9
|
+
if ([".", "&."].includes(operator)) {
|
10
|
+
return operator;
|
10
11
|
}
|
11
|
-
return
|
12
|
+
return operator === "::" ? "." : path.call(print, "op");
|
12
13
|
};
|
13
14
|
exports.default = makeCall;
|
@@ -4,10 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
const prettier_1 = __importDefault(require("../prettier"));
|
7
|
+
const location_1 = require("../ruby/location");
|
7
8
|
const { group, hardline, indent, join, line } = prettier_1.default;
|
8
9
|
function containedWithin(node) {
|
9
10
|
return function containedWithinNode(comment) {
|
10
|
-
return comment.
|
11
|
+
return ((0, location_1.getStartChar)(comment.loc) >= (0, location_1.getStartChar)(node.loc) &&
|
12
|
+
(0, location_1.getEndChar)(comment.loc) <= (0, location_1.getEndChar)(node.loc));
|
11
13
|
};
|
12
14
|
}
|
13
15
|
// Empty collections are array or hash literals that do not contain any
|
@@ -6,10 +6,14 @@ const skippable = [
|
|
6
6
|
"hash",
|
7
7
|
"heredoc",
|
8
8
|
"lambda",
|
9
|
-
"
|
9
|
+
"qsymbols",
|
10
|
+
"qwords",
|
11
|
+
"regexp_literal",
|
12
|
+
"symbols",
|
13
|
+
"words"
|
10
14
|
];
|
11
15
|
function skipAssignIndent(node) {
|
12
16
|
return (skippable.includes(node.type) ||
|
13
|
-
(node.type === "call" && skipAssignIndent(node.
|
17
|
+
(node.type === "call" && skipAssignIndent(node.receiver)));
|
14
18
|
}
|
15
19
|
exports.default = skipAssignIndent;
|