prettier 2.1.0 → 3.0.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.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -6
  3. data/README.md +16 -16
  4. data/exe/rbprettier +2 -2
  5. data/lib/prettier/rake/task.rb +5 -5
  6. data/lib/prettier.rb +11 -11
  7. data/package.json +9 -23
  8. data/rubocop.yml +6 -6
  9. data/{dist/parser → src}/getInfo.js +0 -1
  10. data/{dist/parser → src}/netcat.js +0 -1
  11. data/src/parseSync.js +212 -0
  12. data/src/plugin.js +161 -0
  13. data/{dist/parser → src}/server.rb +45 -31
  14. metadata +94 -78
  15. data/bin/console +0 -7
  16. data/dist/haml/embed.js +0 -53
  17. data/dist/haml/parser.js +0 -31
  18. data/dist/haml/parser.rb +0 -149
  19. data/dist/haml/printer.js +0 -336
  20. data/dist/parser/parseSync.js +0 -179
  21. data/dist/plugin.js +0 -143
  22. data/dist/prettier.js +0 -15
  23. data/dist/rbs/parser.js +0 -34
  24. data/dist/rbs/parser.rb +0 -155
  25. data/dist/rbs/printer.js +0 -525
  26. data/dist/ruby/embed.js +0 -115
  27. data/dist/ruby/location.js +0 -19
  28. data/dist/ruby/nodes/alias.js +0 -60
  29. data/dist/ruby/nodes/aref.js +0 -51
  30. data/dist/ruby/nodes/args.js +0 -138
  31. data/dist/ruby/nodes/arrays.js +0 -122
  32. data/dist/ruby/nodes/assign.js +0 -37
  33. data/dist/ruby/nodes/blocks.js +0 -90
  34. data/dist/ruby/nodes/calls.js +0 -263
  35. data/dist/ruby/nodes/case.js +0 -50
  36. data/dist/ruby/nodes/class.js +0 -54
  37. data/dist/ruby/nodes/commands.js +0 -138
  38. data/dist/ruby/nodes/conditionals.js +0 -246
  39. data/dist/ruby/nodes/constants.js +0 -35
  40. data/dist/ruby/nodes/flow.js +0 -59
  41. data/dist/ruby/nodes/hashes.js +0 -126
  42. data/dist/ruby/nodes/heredocs.js +0 -30
  43. data/dist/ruby/nodes/hooks.js +0 -35
  44. data/dist/ruby/nodes/ints.js +0 -27
  45. data/dist/ruby/nodes/lambdas.js +0 -70
  46. data/dist/ruby/nodes/loops.js +0 -75
  47. data/dist/ruby/nodes/massign.js +0 -60
  48. data/dist/ruby/nodes/methods.js +0 -50
  49. data/dist/ruby/nodes/operators.js +0 -68
  50. data/dist/ruby/nodes/params.js +0 -95
  51. data/dist/ruby/nodes/patterns.js +0 -119
  52. data/dist/ruby/nodes/regexp.js +0 -45
  53. data/dist/ruby/nodes/rescue.js +0 -86
  54. data/dist/ruby/nodes/return.js +0 -100
  55. data/dist/ruby/nodes/statements.js +0 -110
  56. data/dist/ruby/nodes/strings.js +0 -220
  57. data/dist/ruby/nodes/super.js +0 -26
  58. data/dist/ruby/nodes/undef.js +0 -31
  59. data/dist/ruby/nodes.js +0 -177
  60. data/dist/ruby/parser.js +0 -35
  61. data/dist/ruby/parser.rb +0 -9134
  62. data/dist/ruby/printer.js +0 -67
  63. data/dist/ruby/toProc.js +0 -91
  64. data/dist/types/haml.js +0 -4
  65. data/dist/types/plugin.js +0 -3
  66. data/dist/types/rbs.js +0 -4
  67. data/dist/types/ruby.js +0 -4
  68. data/dist/types/utils.js +0 -2
  69. data/dist/types.js +0 -34
  70. data/dist/utils/containsAssignment.js +0 -18
  71. data/dist/utils/getChildNodes.js +0 -305
  72. data/dist/utils/getTrailingComma.js +0 -6
  73. data/dist/utils/hasAncestor.js +0 -15
  74. data/dist/utils/inlineEnsureParens.js +0 -49
  75. data/dist/utils/isEmptyBodyStmt.js +0 -10
  76. data/dist/utils/isEmptyParams.js +0 -12
  77. data/dist/utils/isEmptyStmts.js +0 -10
  78. data/dist/utils/literal.js +0 -8
  79. data/dist/utils/literallineWithoutBreakParent.js +0 -8
  80. data/dist/utils/makeCall.js +0 -14
  81. data/dist/utils/noIndent.js +0 -11
  82. data/dist/utils/printEmptyCollection.js +0 -46
  83. data/dist/utils/skipAssignIndent.js +0 -19
  84. data/dist/utils.js +0 -32
data/dist/ruby/printer.js DELETED
@@ -1,67 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const prettier_1 = __importDefault(require("../prettier"));
7
- const utils_1 = require("../utils");
8
- const embed_1 = __importDefault(require("./embed"));
9
- const nodes_1 = __importDefault(require("./nodes"));
10
- const { trim } = prettier_1.default;
11
- const noComments = ["args", "args_add_block", "mlhs", "mlhs_paren"];
12
- const printer = {
13
- // Certain nodes are used more for organizational purposed than for actually
14
- // displaying content, so we tell prettier that we don't want comments
15
- // attached to them.
16
- canAttachComment(node) {
17
- return !noComments.includes(node.type);
18
- },
19
- embed: embed_1.default,
20
- // This function tells prettier how to recurse down our AST so that it can
21
- // find where it needs to attach the comments.
22
- getCommentChildNodes(node) {
23
- return (0, utils_1.getChildNodes)(node);
24
- },
25
- // This is an escape-hatch to ignore nodes in the tree. If you have a comment
26
- // that includes this pattern, then the entire node will be ignored and just
27
- // the original source will be printed out.
28
- hasPrettierIgnore(path) {
29
- const node = path.getValue();
30
- return ((node.comments &&
31
- node.comments.some((comment) => comment.value.includes("prettier-ignore"))) ||
32
- false);
33
- },
34
- // To be honest I'm not 100% sure this function is actually necessary, but it
35
- // *feels* like a block comment equivalent in JavaScript so I'm going to leave
36
- // it in place for now.
37
- isBlockComment(comment) {
38
- return comment.type === "embdoc";
39
- },
40
- // This function handles adding the format pragma to a source string. This is
41
- // an optional workflow for incremental adoption.
42
- insertPragma(text) {
43
- const boundary = text.startsWith("#") ? "\n" : "\n\n";
44
- return `# @format${boundary}${text}`;
45
- },
46
- // This is the generic node print function, used to convert any node in the
47
- // AST into its equivalent Doc representation.
48
- print(path, opts, print) {
49
- const node = path.getValue();
50
- const printer = nodes_1.default[node.type];
51
- if (!printer) {
52
- throw new Error(`Unsupported node type: ${node.type}`);
53
- }
54
- return printer(path, opts, print);
55
- },
56
- // This is the generic print function for any comment in the AST. It handles
57
- // both regular comments that begin with a # and embdoc comments, which are
58
- // surrounded by =begin..=end.
59
- printComment(path) {
60
- const comment = path.getValue();
61
- if (comment.type === "comment") {
62
- return `#${comment.value}`;
63
- }
64
- return [trim, comment.value];
65
- }
66
- };
67
- exports.default = printer;
data/dist/ruby/toProc.js DELETED
@@ -1,91 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function isPeriod(node) {
4
- // Older versions of Ruby didn't have a @period ripper event, so we need to
5
- // explicitly cast to any here.
6
- if (node === "::" || node === ".") {
7
- return true;
8
- }
9
- return node.type === "period";
10
- }
11
- // If you have a simple block that only calls a method on the single required
12
- // parameter that is passed to it, then you can replace that block with the
13
- // simpler `Symbol#to_proc`. Meaning, it would go from:
14
- //
15
- // [1, 2, 3].map { |i| i.to_s }
16
- //
17
- // to:
18
- //
19
- // [1, 2, 3].map(&:to_s)
20
- //
21
- // This works with `do` blocks as well.
22
- function toProc(path, node) {
23
- // Ensure that there are variables being passed to this block.
24
- const params = node.block_var && node.block_var.params;
25
- if (!params) {
26
- return null;
27
- }
28
- // Ensure there is one and only one parameter, and that it is required.
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) {
36
- return null;
37
- }
38
- // Get the list of statements from the block
39
- let statements;
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) {
43
- return null;
44
- }
45
- statements = node.bodystmt.stmts.body;
46
- }
47
- else {
48
- statements = node.stmts.body;
49
- }
50
- // Ensure the block contains only one statement
51
- if (statements.length !== 1) {
52
- return null;
53
- }
54
- // Ensure that statement is a call and that it has no comments attached
55
- const [call] = statements;
56
- if (call.type !== "call" || call.comments) {
57
- return null;
58
- }
59
- // Ensure the call is a method of the block argument
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") {
65
- return null;
66
- }
67
- // Ensure that we're not inside of a hash that is being passed to a key that
68
- // corresponds to `:if` or `:unless` to avoid problems with callbacks with
69
- // Rails. For more context, see:
70
- // https://github.com/prettier/plugin-ruby/issues/449
71
- let parentNode = null;
72
- if (path.getValue().type === "method_add_block") {
73
- parentNode = path.getParentNode();
74
- }
75
- else {
76
- parentNode = path.getParentNode(2);
77
- }
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)) {
82
- return null;
83
- }
84
- if (key.type === "symbol_literal" &&
85
- ["if", "unless"].includes(key.value.value)) {
86
- return null;
87
- }
88
- }
89
- return `&:${call.message.value}`;
90
- }
91
- exports.default = toProc;
data/dist/types/haml.js DELETED
@@ -1,4 +0,0 @@
1
- "use strict";
2
- // This file contains all of the types that represent objects being returned
3
- // from the HAML parser.
4
- Object.defineProperty(exports, "__esModule", { value: true });
data/dist/types/plugin.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- ;
data/dist/types/rbs.js DELETED
@@ -1,4 +0,0 @@
1
- "use strict";
2
- // This file contains all of the types that represent objects being returned
3
- // from the RBS parser.
4
- Object.defineProperty(exports, "__esModule", { value: true });
data/dist/types/ruby.js DELETED
@@ -1,4 +0,0 @@
1
- "use strict";
2
- // This file contains all of the types that represent objects being returned
3
- // from our ripper-based parser.
4
- Object.defineProperty(exports, "__esModule", { value: true });
data/dist/types/utils.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
data/dist/types.js DELETED
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
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);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Ruby = exports.RBS = exports.Plugin = exports.HAML = void 0;
30
- exports.HAML = __importStar(require("./types/haml"));
31
- exports.Plugin = __importStar(require("./types/plugin"));
32
- exports.RBS = __importStar(require("./types/rbs"));
33
- exports.Ruby = __importStar(require("./types/ruby"));
34
- __exportStar(require("./types/utils"), exports);
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const getChildNodes_1 = __importDefault(require("./getChildNodes"));
7
- // If the node is a type of assignment or if the node is a paren and nested
8
- // inside that paren is a node that is a type of assignment.
9
- function containsAssignment(node) {
10
- if (!node) {
11
- return false;
12
- }
13
- if (["assign", "massign", "opassign"].includes(node.type)) {
14
- return true;
15
- }
16
- return (0, getChildNodes_1.default)(node).some(containsAssignment);
17
- }
18
- exports.default = containsAssignment;
@@ -1,305 +0,0 @@
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;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function getTrailingComma(opts) {
4
- return ["all", "es5"].includes(opts.trailingComma);
5
- }
6
- exports.default = getTrailingComma;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function hasAncestor(path, types) {
4
- let parent = 0;
5
- let parentNode = path.getParentNode();
6
- while (parentNode) {
7
- if (types.includes(parentNode.type)) {
8
- return true;
9
- }
10
- parent += 1;
11
- parentNode = path.getParentNode(parent);
12
- }
13
- return false;
14
- }
15
- exports.default = hasAncestor;
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const needsParens = [
4
- "args",
5
- "assign",
6
- "assoc",
7
- "binary",
8
- "call",
9
- "massign",
10
- "opassign"
11
- ];
12
- // If you have a modifier statement (for instance an inline if statement or an
13
- // inline while loop) there are times when you need to wrap the entire statement
14
- // in parentheses. This occurs when you have something like:
15
- //
16
- // foo[:foo] =
17
- // if bar?
18
- // baz
19
- // end
20
- //
21
- // Normally we would shorten this to an inline version, which would result in:
22
- //
23
- // foo[:foo] = baz if bar?
24
- //
25
- // but this actually has different semantic meaning. The first example will
26
- // result in a nil being inserted into the hash for the :foo key, whereas the
27
- // second example will result in an empty hash because the if statement applies
28
- // to the entire assignment.
29
- //
30
- // We can fix this in a couple of ways. We can use the then keyword, as in:
31
- //
32
- // foo[:foo] = if bar? then baz end
33
- //
34
- // but I haven't actually seen this anywhere. We can also just leave it as is
35
- // with the multi-line version, but for a short predicate and short value it
36
- // looks pretty silly. The last option and the one I've selected here is to add
37
- // parentheses on both sides of the expression, as in:
38
- //
39
- // foo[:foo] = (baz if bar?)
40
- //
41
- // This approach maintains the nice conciseness of the inline version, while
42
- // keeping the correct semantic meaning.
43
- function inlineEnsureParens(path, parts) {
44
- if (needsParens.includes(path.getParentNode().type)) {
45
- return ["(", ...parts, ")"];
46
- }
47
- return parts;
48
- }
49
- exports.default = inlineEnsureParens;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const isEmptyStmts_1 = __importDefault(require("./isEmptyStmts"));
7
- function isEmptyBodyStmt(node) {
8
- return (0, isEmptyStmts_1.default)(node.stmts) && !node.rsc && !node.ens && !node.els;
9
- }
10
- exports.default = isEmptyBodyStmt;
@@ -1,12 +0,0 @@
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;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function isEmptyStmts(node) {
4
- return (node &&
5
- node.type === "statements" &&
6
- node.body.length === 1 &&
7
- node.body[0].type === "void_stmt" &&
8
- !node.body[0].comments);
9
- }
10
- exports.default = isEmptyStmts;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function literal(value) {
4
- return function printLiteral() {
5
- return value;
6
- };
7
- }
8
- exports.default = literal;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const literallineWithoutBreakParent = {
4
- type: "line",
5
- hard: true,
6
- literal: true
7
- };
8
- exports.default = literallineWithoutBreakParent;