prettier 2.1.0 → 3.0.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 +24 -6
- data/README.md +16 -16
- data/exe/rbprettier +2 -2
- data/lib/prettier/rake/task.rb +5 -5
- data/lib/prettier.rb +11 -11
- data/package.json +9 -23
- data/rubocop.yml +6 -6
- data/{dist/parser → src}/getInfo.js +0 -1
- data/{dist/parser → src}/netcat.js +0 -1
- data/src/parseSync.js +212 -0
- data/src/plugin.js +161 -0
- data/{dist/parser → src}/server.rb +45 -31
- metadata +94 -78
- data/bin/console +0 -7
- data/dist/haml/embed.js +0 -53
- data/dist/haml/parser.js +0 -31
- data/dist/haml/parser.rb +0 -149
- data/dist/haml/printer.js +0 -336
- data/dist/parser/parseSync.js +0 -179
- data/dist/plugin.js +0 -143
- data/dist/prettier.js +0 -15
- data/dist/rbs/parser.js +0 -34
- data/dist/rbs/parser.rb +0 -155
- data/dist/rbs/printer.js +0 -525
- data/dist/ruby/embed.js +0 -115
- data/dist/ruby/location.js +0 -19
- data/dist/ruby/nodes/alias.js +0 -60
- data/dist/ruby/nodes/aref.js +0 -51
- data/dist/ruby/nodes/args.js +0 -138
- data/dist/ruby/nodes/arrays.js +0 -122
- data/dist/ruby/nodes/assign.js +0 -37
- data/dist/ruby/nodes/blocks.js +0 -90
- data/dist/ruby/nodes/calls.js +0 -263
- data/dist/ruby/nodes/case.js +0 -50
- data/dist/ruby/nodes/class.js +0 -54
- data/dist/ruby/nodes/commands.js +0 -138
- data/dist/ruby/nodes/conditionals.js +0 -246
- data/dist/ruby/nodes/constants.js +0 -35
- data/dist/ruby/nodes/flow.js +0 -59
- data/dist/ruby/nodes/hashes.js +0 -126
- data/dist/ruby/nodes/heredocs.js +0 -30
- data/dist/ruby/nodes/hooks.js +0 -35
- data/dist/ruby/nodes/ints.js +0 -27
- data/dist/ruby/nodes/lambdas.js +0 -70
- data/dist/ruby/nodes/loops.js +0 -75
- data/dist/ruby/nodes/massign.js +0 -60
- data/dist/ruby/nodes/methods.js +0 -50
- data/dist/ruby/nodes/operators.js +0 -68
- data/dist/ruby/nodes/params.js +0 -95
- data/dist/ruby/nodes/patterns.js +0 -119
- data/dist/ruby/nodes/regexp.js +0 -45
- data/dist/ruby/nodes/rescue.js +0 -86
- data/dist/ruby/nodes/return.js +0 -100
- data/dist/ruby/nodes/statements.js +0 -110
- data/dist/ruby/nodes/strings.js +0 -220
- data/dist/ruby/nodes/super.js +0 -26
- data/dist/ruby/nodes/undef.js +0 -31
- data/dist/ruby/nodes.js +0 -177
- data/dist/ruby/parser.js +0 -35
- data/dist/ruby/parser.rb +0 -9134
- data/dist/ruby/printer.js +0 -67
- data/dist/ruby/toProc.js +0 -91
- data/dist/types/haml.js +0 -4
- data/dist/types/plugin.js +0 -3
- data/dist/types/rbs.js +0 -4
- data/dist/types/ruby.js +0 -4
- data/dist/types/utils.js +0 -2
- data/dist/types.js +0 -34
- data/dist/utils/containsAssignment.js +0 -18
- data/dist/utils/getChildNodes.js +0 -305
- data/dist/utils/getTrailingComma.js +0 -6
- data/dist/utils/hasAncestor.js +0 -15
- data/dist/utils/inlineEnsureParens.js +0 -49
- data/dist/utils/isEmptyBodyStmt.js +0 -10
- data/dist/utils/isEmptyParams.js +0 -12
- data/dist/utils/isEmptyStmts.js +0 -10
- data/dist/utils/literal.js +0 -8
- data/dist/utils/literallineWithoutBreakParent.js +0 -8
- data/dist/utils/makeCall.js +0 -14
- data/dist/utils/noIndent.js +0 -11
- data/dist/utils/printEmptyCollection.js +0 -46
- data/dist/utils/skipAssignIndent.js +0 -19
- data/dist/utils.js +0 -32
data/dist/ruby/nodes/return.js
DELETED
@@ -1,100 +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
|
-
exports.printReturn0 = exports.printReturn = void 0;
|
7
|
-
const prettier_1 = __importDefault(require("../../prettier"));
|
8
|
-
const { group, ifBreak, indent, line, join, softline } = prettier_1.default;
|
9
|
-
// You can't skip the parentheses if you have comments or certain operators with
|
10
|
-
// lower precedence than the return keyword.
|
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
|
-
}
|
20
|
-
// return(
|
21
|
-
// # a
|
22
|
-
// b
|
23
|
-
// )
|
24
|
-
if (stmts.comments) {
|
25
|
-
return false;
|
26
|
-
}
|
27
|
-
const stmt = stmts.body[0];
|
28
|
-
// return (a or b)
|
29
|
-
if (stmt.type === "binary" && ["and", "or"].includes(stmt.op)) {
|
30
|
-
return false;
|
31
|
-
}
|
32
|
-
// return (not a)
|
33
|
-
if (stmt.type === "not") {
|
34
|
-
return false;
|
35
|
-
}
|
36
|
-
return true;
|
37
|
-
}
|
38
|
-
const printReturn = (path, opts, print) => {
|
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
|
-
}
|
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);
|
81
|
-
}
|
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;
|
87
|
-
}
|
88
|
-
const useBrackets = Array.isArray(parts) && parts.length > 1;
|
89
|
-
const value = joining ? join([",", line], parts) : parts;
|
90
|
-
return group([
|
91
|
-
"return",
|
92
|
-
ifBreak(useBrackets ? " [" : "(", " "),
|
93
|
-
indent([softline, value]),
|
94
|
-
softline,
|
95
|
-
ifBreak(useBrackets ? "]" : ")", "")
|
96
|
-
]);
|
97
|
-
};
|
98
|
-
exports.printReturn = printReturn;
|
99
|
-
const printReturn0 = (path) => path.getValue().value;
|
100
|
-
exports.printReturn0 = printReturn0;
|
@@ -1,110 +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
|
-
exports.printStatements = exports.printProgram = exports.printComment = exports.printEndContent = exports.printParen = exports.printBodyStmt = void 0;
|
7
|
-
const prettier_1 = __importDefault(require("../../prettier"));
|
8
|
-
const utils_1 = require("../../utils");
|
9
|
-
const location_1 = require("../location");
|
10
|
-
const { breakParent, dedent, group, hardline, indent, join, line, literalline, softline, trim } = prettier_1.default;
|
11
|
-
const printBodyStmt = (path, opts, print) => {
|
12
|
-
const node = path.getValue();
|
13
|
-
const parts = [];
|
14
|
-
if (!(0, utils_1.isEmptyStmts)(node.stmts)) {
|
15
|
-
parts.push(path.call(print, "stmts"));
|
16
|
-
}
|
17
|
-
if (node.rsc) {
|
18
|
-
parts.push(dedent([hardline, path.call(print, "rsc")]));
|
19
|
-
}
|
20
|
-
if (node.els) {
|
21
|
-
// Before Ruby 2.6, this piece of bodystmt was an explicit "else" node
|
22
|
-
/* istanbul ignore next */
|
23
|
-
const stmts = node.els.type === "else"
|
24
|
-
? path.call(print, "els", "body", 0)
|
25
|
-
: path.call(print, "els");
|
26
|
-
parts.push([dedent([hardline, "else"]), hardline, stmts]);
|
27
|
-
}
|
28
|
-
if (node.ens) {
|
29
|
-
parts.push(dedent([hardline, path.call(print, "ens")]));
|
30
|
-
}
|
31
|
-
return group(parts);
|
32
|
-
};
|
33
|
-
exports.printBodyStmt = printBodyStmt;
|
34
|
-
const argNodeTypes = ["args", "args_add_block"];
|
35
|
-
const printParen = (path, opts, print) => {
|
36
|
-
const contentNode = path.getValue().cnts;
|
37
|
-
if (!contentNode) {
|
38
|
-
return [path.call(print, "lparen"), ")"];
|
39
|
-
}
|
40
|
-
let contentDoc = path.call(print, "cnts");
|
41
|
-
// If the content is params, we're going to let it handle its own parentheses
|
42
|
-
// so that it breaks nicely.
|
43
|
-
if (contentNode.type === "params") {
|
44
|
-
return contentDoc;
|
45
|
-
}
|
46
|
-
// If we have an arg type node as the contents, then it's going to return an
|
47
|
-
// array, so we need to explicitly join that content here.
|
48
|
-
if (argNodeTypes.includes(contentNode.type)) {
|
49
|
-
contentDoc = join([",", line], contentDoc);
|
50
|
-
}
|
51
|
-
return group([
|
52
|
-
path.call(print, "lparen"),
|
53
|
-
indent([softline, contentDoc]),
|
54
|
-
softline,
|
55
|
-
")"
|
56
|
-
]);
|
57
|
-
};
|
58
|
-
exports.printParen = printParen;
|
59
|
-
const printEndContent = (path) => {
|
60
|
-
const node = path.getValue();
|
61
|
-
return [trim, "__END__", literalline, node.value];
|
62
|
-
};
|
63
|
-
exports.printEndContent = printEndContent;
|
64
|
-
const printComment = (path, opts) => {
|
65
|
-
return opts.printer.printComment(path, opts);
|
66
|
-
};
|
67
|
-
exports.printComment = printComment;
|
68
|
-
const printProgram = (path, opts, print) => [path.call(print, "stmts"), hardline];
|
69
|
-
exports.printProgram = printProgram;
|
70
|
-
const printStatements = (path, opts, print) => {
|
71
|
-
const stmts = path.getValue().body;
|
72
|
-
// This is a special case where we have only comments inside a statement
|
73
|
-
// list. In this case we want to avoid doing any kind of line number
|
74
|
-
// tracking and just print out the comments.
|
75
|
-
if (stmts.length === 1 &&
|
76
|
-
stmts[0].type === "void_stmt" &&
|
77
|
-
stmts[0].comments) {
|
78
|
-
const nodePath = path;
|
79
|
-
const comments = nodePath.map((commentPath) => {
|
80
|
-
commentPath.getValue().printed = true;
|
81
|
-
return opts.printer.printComment(commentPath, opts);
|
82
|
-
}, "body", 0, "comments");
|
83
|
-
return [breakParent, join(hardline, comments)];
|
84
|
-
}
|
85
|
-
const parts = [];
|
86
|
-
let lineNo = null;
|
87
|
-
stmts.forEach((stmt, index) => {
|
88
|
-
if (stmt.type === "void_stmt") {
|
89
|
-
return;
|
90
|
-
}
|
91
|
-
const printed = path.call(print, "body", index);
|
92
|
-
if (lineNo === null) {
|
93
|
-
parts.push(printed);
|
94
|
-
}
|
95
|
-
else if ((0, location_1.getStartLine)(stmt.loc) - lineNo > 1 ||
|
96
|
-
[stmt.type, stmts[index - 1].type].includes("access_ctrl")) {
|
97
|
-
parts.push(hardline, hardline, printed);
|
98
|
-
}
|
99
|
-
else if ((0, location_1.getStartLine)(stmt.loc) !== lineNo ||
|
100
|
-
path.getParentNode().type !== "string_embexpr") {
|
101
|
-
parts.push(hardline, printed);
|
102
|
-
}
|
103
|
-
else {
|
104
|
-
parts.push("; ", printed);
|
105
|
-
}
|
106
|
-
lineNo = (0, location_1.getEndLine)(stmt.loc);
|
107
|
-
});
|
108
|
-
return parts;
|
109
|
-
};
|
110
|
-
exports.printStatements = printStatements;
|
data/dist/ruby/nodes/strings.js
DELETED
@@ -1,220 +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
|
-
exports.printXStringLiteral = exports.printSymbolLiteral = exports.printStringLiteral = exports.printStringEmbExpr = exports.printStringDVar = exports.printStringConcat = exports.printDynaSymbol = exports.printChar = void 0;
|
7
|
-
const prettier_1 = __importDefault(require("../../prettier"));
|
8
|
-
const location_1 = require("../location");
|
9
|
-
const { group, hardline, indent, literalline, removeLines, softline, join } = prettier_1.default;
|
10
|
-
// If there is some part of this string that matches an escape sequence or that
|
11
|
-
// contains the interpolation pattern ("#{"), then we are locked into whichever
|
12
|
-
// quote the user chose. (If they chose single quotes, then double quoting
|
13
|
-
// would activate the escape sequence, and if they chose double quotes, then
|
14
|
-
// single quotes would deactivate it.)
|
15
|
-
function isQuoteLocked(node) {
|
16
|
-
return node.parts.some((part) => part.type === "tstring_content" &&
|
17
|
-
(part.value.includes("#{") || part.value.includes("\\")));
|
18
|
-
}
|
19
|
-
// A string is considered to be able to use single quotes if it contains only
|
20
|
-
// plain string content and that content does not contain a single quote.
|
21
|
-
function isSingleQuotable(node) {
|
22
|
-
return node.parts.every((part) => part.type === "tstring_content" && !part.value.includes("'"));
|
23
|
-
}
|
24
|
-
const quotePattern = new RegExp("\\\\([\\s\\S])|(['\"])", "g");
|
25
|
-
function normalizeQuotes(content, enclosingQuote) {
|
26
|
-
// Escape and unescape single and double quotes as needed to be able to
|
27
|
-
// enclose `content` with `enclosingQuote`.
|
28
|
-
return content.replace(quotePattern, (match, escaped, quote) => {
|
29
|
-
if (quote === enclosingQuote) {
|
30
|
-
return `\\${quote}`;
|
31
|
-
}
|
32
|
-
if (quote) {
|
33
|
-
return quote;
|
34
|
-
}
|
35
|
-
return `\\${escaped}`;
|
36
|
-
});
|
37
|
-
}
|
38
|
-
const quotePairs = {
|
39
|
-
"(": ")",
|
40
|
-
"[": "]",
|
41
|
-
"{": "}",
|
42
|
-
"<": ">"
|
43
|
-
};
|
44
|
-
function getClosingQuote(quote) {
|
45
|
-
if (!quote.startsWith("%")) {
|
46
|
-
return quote;
|
47
|
-
}
|
48
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
49
|
-
const boundary = /%[Qq]?(.)/.exec(quote)[1];
|
50
|
-
if (boundary in quotePairs) {
|
51
|
-
return quotePairs[boundary];
|
52
|
-
}
|
53
|
-
return boundary;
|
54
|
-
}
|
55
|
-
// Prints a @CHAR node. @CHAR nodes are special character strings that usually
|
56
|
-
// are strings of length 1. If they're any longer than we'll try to apply the
|
57
|
-
// correct quotes.
|
58
|
-
const printChar = (path, opts) => {
|
59
|
-
const { value } = path.getValue();
|
60
|
-
if (value.length !== 2) {
|
61
|
-
return value;
|
62
|
-
}
|
63
|
-
const quote = opts.rubySingleQuote ? "'" : '"';
|
64
|
-
return [quote, value.slice(1), quote];
|
65
|
-
};
|
66
|
-
exports.printChar = printChar;
|
67
|
-
const printPercentSDynaSymbol = (path, opts, print) => {
|
68
|
-
const node = path.getValue();
|
69
|
-
const parts = [];
|
70
|
-
// Push on the quote, which includes the opening character.
|
71
|
-
parts.push(node.quote);
|
72
|
-
path.each((childPath) => {
|
73
|
-
const childNode = childPath.getValue();
|
74
|
-
if (childNode.type !== "tstring_content") {
|
75
|
-
// Here we are printing an embedded variable or expression.
|
76
|
-
parts.push(print(childPath));
|
77
|
-
}
|
78
|
-
else {
|
79
|
-
// Here we are printing plain string content.
|
80
|
-
parts.push(join(literalline, childNode.value.split("\n")));
|
81
|
-
}
|
82
|
-
}, "parts");
|
83
|
-
// Push on the closing character, which is the opposite of the third
|
84
|
-
// character from the opening.
|
85
|
-
parts.push(quotePairs[node.quote[2]]);
|
86
|
-
return parts;
|
87
|
-
};
|
88
|
-
// We don't actually want to print %s symbols, as they're much more rarely seen
|
89
|
-
// in the wild. But we're going to be forced into it if it's a multi-line symbol
|
90
|
-
// or if the quoting would get super complicated.
|
91
|
-
function shouldPrintPercentSDynaSymbol(node) {
|
92
|
-
// We shouldn't print a %s dyna symbol if it was not already that way in the
|
93
|
-
// original source.
|
94
|
-
if (node.quote[0] !== "%") {
|
95
|
-
return false;
|
96
|
-
}
|
97
|
-
// Here we're going to check if there is a closing character, a new line, or a
|
98
|
-
// quote in the content of the dyna symbol. If there is, then quoting could
|
99
|
-
// get weird, so just bail out and stick to the original bounds in the source.
|
100
|
-
const closing = quotePairs[node.quote[2]];
|
101
|
-
return node.parts.some((child) => child.type === "tstring_content" &&
|
102
|
-
(child.value.includes("\n") ||
|
103
|
-
child.value.includes(closing) ||
|
104
|
-
child.value.includes("'") ||
|
105
|
-
child.value.includes('"')));
|
106
|
-
}
|
107
|
-
// Prints a dynamic symbol. Assumes there's a quote property attached to the
|
108
|
-
// node that will tell us which quote to use when printing. We're just going to
|
109
|
-
// use whatever quote was provided.
|
110
|
-
//
|
111
|
-
// In the case of a plain dyna symbol, node.quote will be either :" or :'
|
112
|
-
// For %s dyna symbols, node.quote will be %s[, %s(, %s{, or %s<
|
113
|
-
const printDynaSymbol = (path, opts, print) => {
|
114
|
-
const node = path.getValue();
|
115
|
-
if (shouldPrintPercentSDynaSymbol(node)) {
|
116
|
-
return printPercentSDynaSymbol(path, opts, print);
|
117
|
-
}
|
118
|
-
const parts = [];
|
119
|
-
let quote;
|
120
|
-
if (isQuoteLocked(node)) {
|
121
|
-
if (node.quote.startsWith("%")) {
|
122
|
-
quote = opts.rubySingleQuote ? "'" : '"';
|
123
|
-
}
|
124
|
-
else if (node.quote.startsWith(":")) {
|
125
|
-
quote = node.quote.slice(1);
|
126
|
-
}
|
127
|
-
else {
|
128
|
-
quote = node.quote;
|
129
|
-
}
|
130
|
-
}
|
131
|
-
else {
|
132
|
-
quote = opts.rubySingleQuote && isSingleQuotable(node) ? "'" : '"';
|
133
|
-
}
|
134
|
-
parts.push(quote);
|
135
|
-
path.each((childPath) => {
|
136
|
-
const child = childPath.getValue();
|
137
|
-
if (child.type !== "tstring_content") {
|
138
|
-
parts.push(print(childPath));
|
139
|
-
}
|
140
|
-
else {
|
141
|
-
parts.push(join(literalline, normalizeQuotes(child.value, quote).split("\n")));
|
142
|
-
}
|
143
|
-
}, "parts");
|
144
|
-
parts.push(quote);
|
145
|
-
// If we're inside of an assoc_new node as the key, then it will handle
|
146
|
-
// printing the : on its own since it could change sides.
|
147
|
-
const parentNode = path.getParentNode();
|
148
|
-
if (parentNode.type !== "assoc" || parentNode.key !== node) {
|
149
|
-
parts.unshift(":");
|
150
|
-
}
|
151
|
-
return parts;
|
152
|
-
};
|
153
|
-
exports.printDynaSymbol = printDynaSymbol;
|
154
|
-
const printStringConcat = (path, opts, print) => {
|
155
|
-
return group([
|
156
|
-
path.call(print, "left"),
|
157
|
-
" \\",
|
158
|
-
indent([hardline, path.call(print, "right")])
|
159
|
-
]);
|
160
|
-
};
|
161
|
-
exports.printStringConcat = printStringConcat;
|
162
|
-
// Prints out an interpolated variable in the string by converting it into an
|
163
|
-
// embedded expression.
|
164
|
-
const printStringDVar = (path, opts, print) => ["#{", path.call(print, "var"), "}"];
|
165
|
-
exports.printStringDVar = printStringDVar;
|
166
|
-
const printStringEmbExpr = (path, opts, print) => {
|
167
|
-
const node = path.getValue();
|
168
|
-
const doc = path.call(print, "stmts");
|
169
|
-
// If the contents of this embedded expression were originally on the same
|
170
|
-
// line in the source, then we're going to leave them in place and assume
|
171
|
-
// that's the way the developer wanted this expression represented.
|
172
|
-
if ((0, location_1.getStartLine)(node.loc) === (0, location_1.getEndLine)(node.loc)) {
|
173
|
-
return ["#{", removeLines(doc), "}"];
|
174
|
-
}
|
175
|
-
return group(["#{", indent([softline, doc]), [softline, "}"]]);
|
176
|
-
};
|
177
|
-
exports.printStringEmbExpr = printStringEmbExpr;
|
178
|
-
// Prints out a literal string. This function does its best to respect the
|
179
|
-
// wishes of the user with regards to single versus double quotes, but if the
|
180
|
-
// string contains any escape expressions then it will just keep the original
|
181
|
-
// quotes.
|
182
|
-
const printStringLiteral = (path, { rubySingleQuote }, print) => {
|
183
|
-
const node = path.getValue();
|
184
|
-
// If the string is empty, it will not have any parts, so just print out the
|
185
|
-
// quotes corresponding to the config
|
186
|
-
if (node.parts.length === 0) {
|
187
|
-
return rubySingleQuote ? "''" : '""';
|
188
|
-
}
|
189
|
-
// Determine the quote that should enclose the new string
|
190
|
-
let quote;
|
191
|
-
if (isQuoteLocked(node)) {
|
192
|
-
quote = node.quote;
|
193
|
-
}
|
194
|
-
else {
|
195
|
-
quote = rubySingleQuote && isSingleQuotable(node) ? "'" : '"';
|
196
|
-
}
|
197
|
-
const parts = path.map((partPath) => {
|
198
|
-
const part = partPath.getValue();
|
199
|
-
// In this case, the part of the string is an embedded expression
|
200
|
-
if (part.type !== "tstring_content") {
|
201
|
-
return print(partPath);
|
202
|
-
}
|
203
|
-
// In this case, the part of the string is just regular string content
|
204
|
-
return join(literalline, normalizeQuotes(part.value, quote).split("\n"));
|
205
|
-
}, "parts");
|
206
|
-
return [quote, ...parts, getClosingQuote(quote)];
|
207
|
-
};
|
208
|
-
exports.printStringLiteral = printStringLiteral;
|
209
|
-
// Prints out a symbol literal. Its child will always be the ident that
|
210
|
-
// represents the string content of the symbol.
|
211
|
-
const printSymbolLiteral = (path, opts, print) => {
|
212
|
-
return [":", path.call(print, "value")];
|
213
|
-
};
|
214
|
-
exports.printSymbolLiteral = printSymbolLiteral;
|
215
|
-
// Prints out an xstring literal. Its child is an array of string parts,
|
216
|
-
// including plain string content and interpolated content.
|
217
|
-
const printXStringLiteral = (path, opts, print) => {
|
218
|
-
return ["`", ...path.map(print, "parts"), "`"];
|
219
|
-
};
|
220
|
-
exports.printXStringLiteral = printXStringLiteral;
|
data/dist/ruby/nodes/super.js
DELETED
@@ -1,26 +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
|
-
exports.printZSuper = exports.printSuper = void 0;
|
7
|
-
const prettier_1 = __importDefault(require("../../prettier"));
|
8
|
-
const { align, group, join, line } = prettier_1.default;
|
9
|
-
const printSuper = (path, opts, print) => {
|
10
|
-
const { args } = path.getValue();
|
11
|
-
if (args.type === "arg_paren") {
|
12
|
-
// In case there are explicitly no arguments but they are using parens,
|
13
|
-
// we assume they are attempting to override a parent method and pass no
|
14
|
-
// arguments up.
|
15
|
-
return args.args === null ? "super()" : ["super", path.call(print, "args")];
|
16
|
-
}
|
17
|
-
const keyword = "super ";
|
18
|
-
return group([
|
19
|
-
keyword,
|
20
|
-
align(keyword.length, group(join([",", line], path.call(print, "args"))))
|
21
|
-
]);
|
22
|
-
};
|
23
|
-
exports.printSuper = printSuper;
|
24
|
-
// Version of super without any parens or args.
|
25
|
-
const printZSuper = (path) => path.getValue().value;
|
26
|
-
exports.printZSuper = printZSuper;
|
data/dist/ruby/nodes/undef.js
DELETED
@@ -1,31 +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
|
-
exports.printUndef = void 0;
|
7
|
-
const prettier_1 = __importDefault(require("../../prettier"));
|
8
|
-
const { addTrailingComment, align, group, join, line } = prettier_1.default;
|
9
|
-
const printUndef = (path, opts, print) => {
|
10
|
-
const symsDocs = path.map((symbolPath) => {
|
11
|
-
const symbolNode = symbolPath.getValue();
|
12
|
-
// If we're not printing a symbol literal then it's a dyna symbol, so
|
13
|
-
// we're just going to print that node on its own.
|
14
|
-
if (symbolNode.type !== "symbol_literal") {
|
15
|
-
return print(symbolPath);
|
16
|
-
}
|
17
|
-
// We need to make sure we copy over any comments before we do the
|
18
|
-
// printing so they get printed as well.
|
19
|
-
if (symbolNode.comments) {
|
20
|
-
symbolNode.comments.forEach((comment) => {
|
21
|
-
addTrailingComment(symbolNode.value, comment);
|
22
|
-
});
|
23
|
-
}
|
24
|
-
// If we're printing a symbol literal, then we want to descend into it and
|
25
|
-
// just print the underlying contents so that it prints as a bare word.
|
26
|
-
return symbolPath.call(print, "value");
|
27
|
-
}, "syms");
|
28
|
-
const keyword = "undef ";
|
29
|
-
return group([keyword, align(keyword.length, join([",", line], symsDocs))]);
|
30
|
-
};
|
31
|
-
exports.printUndef = printUndef;
|
data/dist/ruby/nodes.js
DELETED
@@ -1,177 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const alias_1 = require("./nodes/alias");
|
4
|
-
const aref_1 = require("./nodes/aref");
|
5
|
-
const args_1 = require("./nodes/args");
|
6
|
-
const arrays_1 = require("./nodes/arrays");
|
7
|
-
const assign_1 = require("./nodes/assign");
|
8
|
-
const blocks_1 = require("./nodes/blocks");
|
9
|
-
const calls_1 = require("./nodes/calls");
|
10
|
-
const case_1 = require("./nodes/case");
|
11
|
-
const class_1 = require("./nodes/class");
|
12
|
-
const commands_1 = require("./nodes/commands");
|
13
|
-
const conditionals_1 = require("./nodes/conditionals");
|
14
|
-
const constants_1 = require("./nodes/constants");
|
15
|
-
const flow_1 = require("./nodes/flow");
|
16
|
-
const hashes_1 = require("./nodes/hashes");
|
17
|
-
const heredocs_1 = require("./nodes/heredocs");
|
18
|
-
const hooks_1 = require("./nodes/hooks");
|
19
|
-
const ints_1 = require("./nodes/ints");
|
20
|
-
const lambdas_1 = require("./nodes/lambdas");
|
21
|
-
const loops_1 = require("./nodes/loops");
|
22
|
-
const massign_1 = require("./nodes/massign");
|
23
|
-
const methods_1 = require("./nodes/methods");
|
24
|
-
const operators_1 = require("./nodes/operators");
|
25
|
-
const params_1 = require("./nodes/params");
|
26
|
-
const patterns_1 = require("./nodes/patterns");
|
27
|
-
const regexp_1 = require("./nodes/regexp");
|
28
|
-
const rescue_1 = require("./nodes/rescue");
|
29
|
-
const return_1 = require("./nodes/return");
|
30
|
-
const statements_1 = require("./nodes/statements");
|
31
|
-
const strings_1 = require("./nodes/strings");
|
32
|
-
const super_1 = require("./nodes/super");
|
33
|
-
const undef_1 = require("./nodes/undef");
|
34
|
-
const printToken = (path) => path.getValue().value;
|
35
|
-
const printVoidStmt = () => "";
|
36
|
-
const nodes = {
|
37
|
-
BEGIN: hooks_1.printBEGIN,
|
38
|
-
CHAR: strings_1.printChar,
|
39
|
-
END: hooks_1.printEND,
|
40
|
-
__end__: statements_1.printEndContent,
|
41
|
-
access_ctrl: methods_1.printAccessControl,
|
42
|
-
alias: alias_1.printAlias,
|
43
|
-
aref: aref_1.printAref,
|
44
|
-
aref_field: aref_1.printArefField,
|
45
|
-
arg_paren: args_1.printArgParen,
|
46
|
-
args: args_1.printArgs,
|
47
|
-
args_add_block: args_1.printArgsAddBlock,
|
48
|
-
args_forward: params_1.printArgsForward,
|
49
|
-
arg_star: args_1.printArgStar,
|
50
|
-
array: arrays_1.printArray,
|
51
|
-
aryptn: patterns_1.printAryPtn,
|
52
|
-
assign: assign_1.printAssign,
|
53
|
-
assoc: hashes_1.printAssoc,
|
54
|
-
assoc_splat: hashes_1.printAssocSplat,
|
55
|
-
assoclist_from_args: hashes_1.printHashContents,
|
56
|
-
backref: printToken,
|
57
|
-
backtick: printToken,
|
58
|
-
bare_assoc_hash: hashes_1.printHashContents,
|
59
|
-
begin: rescue_1.printBegin,
|
60
|
-
binary: operators_1.printBinary,
|
61
|
-
block_var: blocks_1.printBlockVar,
|
62
|
-
blockarg: args_1.printBlockArg,
|
63
|
-
bodystmt: statements_1.printBodyStmt,
|
64
|
-
brace_block: blocks_1.printBraceBlock,
|
65
|
-
break: flow_1.printBreak,
|
66
|
-
call: calls_1.printCall,
|
67
|
-
case: case_1.printCase,
|
68
|
-
class: class_1.printClass,
|
69
|
-
command: commands_1.printCommand,
|
70
|
-
command_call: commands_1.printCommandCall,
|
71
|
-
comment: statements_1.printComment,
|
72
|
-
const: printToken,
|
73
|
-
const_path_field: constants_1.printConstPath,
|
74
|
-
const_path_ref: constants_1.printConstPath,
|
75
|
-
const_ref: constants_1.printConstRef,
|
76
|
-
cvar: printToken,
|
77
|
-
def: methods_1.printDef,
|
78
|
-
def_endless: methods_1.printDefEndless,
|
79
|
-
defined: constants_1.printDefined,
|
80
|
-
defs: methods_1.printDef,
|
81
|
-
do_block: blocks_1.printDoBlock,
|
82
|
-
dot2: operators_1.printDot2,
|
83
|
-
dot3: operators_1.printDot3,
|
84
|
-
dyna_symbol: strings_1.printDynaSymbol,
|
85
|
-
else: conditionals_1.printElse,
|
86
|
-
elsif: conditionals_1.printElsif,
|
87
|
-
embdoc: statements_1.printComment,
|
88
|
-
ensure: rescue_1.printEnsure,
|
89
|
-
excessed_comma: params_1.printExcessedComma,
|
90
|
-
fcall: calls_1.printCallContainer,
|
91
|
-
field: constants_1.printField,
|
92
|
-
float: printToken,
|
93
|
-
fndptn: patterns_1.printFndPtn,
|
94
|
-
for: loops_1.printFor,
|
95
|
-
gvar: printToken,
|
96
|
-
hash: hashes_1.printHash,
|
97
|
-
heredoc: heredocs_1.printHeredoc,
|
98
|
-
heredoc_beg: printToken,
|
99
|
-
hshptn: patterns_1.printHshPtn,
|
100
|
-
ident: printToken,
|
101
|
-
if: conditionals_1.printIf,
|
102
|
-
if_mod: conditionals_1.printIfModifier,
|
103
|
-
ifop: conditionals_1.printTernary,
|
104
|
-
imaginary: printToken,
|
105
|
-
in: patterns_1.printIn,
|
106
|
-
int: ints_1.printInt,
|
107
|
-
ivar: printToken,
|
108
|
-
kw: printToken,
|
109
|
-
kwrest_param: params_1.printKeywordRestParam,
|
110
|
-
label: printToken,
|
111
|
-
lambda: lambdas_1.printLambda,
|
112
|
-
lbrace: printToken,
|
113
|
-
lparen: printToken,
|
114
|
-
massign: massign_1.printMAssign,
|
115
|
-
method_add_arg: calls_1.printMethodAddArg,
|
116
|
-
method_add_block: calls_1.printMethodAddBlock,
|
117
|
-
mlhs: massign_1.printMLHS,
|
118
|
-
mlhs_paren: massign_1.printMLHSParen,
|
119
|
-
module: class_1.printModule,
|
120
|
-
mrhs: massign_1.printMRHS,
|
121
|
-
mrhs_add_star: massign_1.printMRHSAddStar,
|
122
|
-
mrhs_new_from_args: massign_1.printMRHSNewFromArgs,
|
123
|
-
next: flow_1.printNext,
|
124
|
-
not: operators_1.printNot,
|
125
|
-
op: printToken,
|
126
|
-
opassign: assign_1.printOpAssign,
|
127
|
-
params: params_1.printParams,
|
128
|
-
paren: statements_1.printParen,
|
129
|
-
period: printToken,
|
130
|
-
program: statements_1.printProgram,
|
131
|
-
qsymbols: arrays_1.printQsymbols,
|
132
|
-
qwords: arrays_1.printQwords,
|
133
|
-
rassign: patterns_1.printRAssign,
|
134
|
-
rational: printToken,
|
135
|
-
redo: rescue_1.printRedo,
|
136
|
-
regexp_literal: regexp_1.printRegexpLiteral,
|
137
|
-
rescue: rescue_1.printRescue,
|
138
|
-
rescue_ex: rescue_1.printRescueEx,
|
139
|
-
rescue_mod: rescue_1.printRescueMod,
|
140
|
-
rest_param: params_1.printRestParam,
|
141
|
-
retry: rescue_1.printRetry,
|
142
|
-
return0: return_1.printReturn0,
|
143
|
-
return: return_1.printReturn,
|
144
|
-
sclass: class_1.printSClass,
|
145
|
-
statements: statements_1.printStatements,
|
146
|
-
string_concat: strings_1.printStringConcat,
|
147
|
-
string_dvar: strings_1.printStringDVar,
|
148
|
-
string_embexpr: strings_1.printStringEmbExpr,
|
149
|
-
string_literal: strings_1.printStringLiteral,
|
150
|
-
super: super_1.printSuper,
|
151
|
-
symbol_literal: strings_1.printSymbolLiteral,
|
152
|
-
symbols: arrays_1.printSymbols,
|
153
|
-
top_const_field: constants_1.printTopConst,
|
154
|
-
top_const_ref: constants_1.printTopConst,
|
155
|
-
tstring_content: printToken,
|
156
|
-
unary: operators_1.printUnary,
|
157
|
-
undef: undef_1.printUndef,
|
158
|
-
unless: conditionals_1.printUnless,
|
159
|
-
unless_mod: conditionals_1.printUnlessModifier,
|
160
|
-
until: loops_1.printUntil,
|
161
|
-
until_mod: loops_1.printUntil,
|
162
|
-
var_alias: alias_1.printAlias,
|
163
|
-
var_field: assign_1.printVarField,
|
164
|
-
var_ref: assign_1.printVarRef,
|
165
|
-
vcall: calls_1.printCallContainer,
|
166
|
-
void_stmt: printVoidStmt,
|
167
|
-
when: case_1.printWhen,
|
168
|
-
while: loops_1.printWhile,
|
169
|
-
while_mod: loops_1.printWhile,
|
170
|
-
word: arrays_1.printWord,
|
171
|
-
words: arrays_1.printWords,
|
172
|
-
xstring_literal: strings_1.printXStringLiteral,
|
173
|
-
yield0: flow_1.printYield0,
|
174
|
-
yield: flow_1.printYield,
|
175
|
-
zsuper: super_1.printZSuper
|
176
|
-
};
|
177
|
-
exports.default = nodes;
|