prettier 1.5.5 → 1.6.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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -1
  3. data/CONTRIBUTING.md +2 -2
  4. data/README.md +31 -12
  5. data/node_modules/prettier/bin-prettier.js +13702 -11629
  6. data/node_modules/prettier/index.js +19198 -16572
  7. data/node_modules/prettier/parser-angular.js +61 -40
  8. data/node_modules/prettier/parser-babel.js +22 -1
  9. data/node_modules/prettier/parser-espree.js +22 -1
  10. data/node_modules/prettier/parser-flow.js +22 -1
  11. data/node_modules/prettier/parser-glimmer.js +1 -1
  12. data/node_modules/prettier/parser-graphql.js +1 -1
  13. data/node_modules/prettier/parser-html.js +82 -63
  14. data/node_modules/prettier/parser-markdown.js +24 -9
  15. data/node_modules/prettier/parser-meriyah.js +22 -1
  16. data/node_modules/prettier/parser-postcss.js +22 -1
  17. data/node_modules/prettier/parser-typescript.js +22 -1
  18. data/node_modules/prettier/parser-yaml.js +2 -2
  19. data/node_modules/prettier/third-party.js +1042 -833
  20. data/package.json +3 -3
  21. data/rubocop.yml +9 -0
  22. data/src/haml/parser.js +5 -4
  23. data/src/haml/printer.js +428 -18
  24. data/src/parser/parseSync.js +8 -6
  25. data/src/plugin.js +1 -1
  26. data/src/rbs/parser.js +1 -3
  27. data/src/rbs/printer.js +35 -7
  28. data/src/ruby/nodes/args.js +66 -22
  29. data/src/ruby/nodes/calls.js +8 -1
  30. data/src/ruby/nodes/conditionals.js +47 -45
  31. data/src/ruby/nodes/hashes.js +5 -14
  32. data/src/ruby/nodes/params.js +2 -9
  33. data/src/ruby/nodes/strings.js +95 -2
  34. data/src/ruby/parser.js +1 -3
  35. data/src/ruby/parser.rb +52 -29
  36. data/src/ruby/printer.js +10 -1
  37. data/src/utils/inlineEnsureParens.js +1 -0
  38. data/src/utils/skipAssignIndent.js +8 -1
  39. metadata +3 -12
  40. data/src/haml/nodes/comment.js +0 -27
  41. data/src/haml/nodes/doctype.js +0 -34
  42. data/src/haml/nodes/filter.js +0 -16
  43. data/src/haml/nodes/hamlComment.js +0 -21
  44. data/src/haml/nodes/plain.js +0 -6
  45. data/src/haml/nodes/root.js +0 -8
  46. data/src/haml/nodes/script.js +0 -33
  47. data/src/haml/nodes/silentScript.js +0 -59
  48. data/src/haml/nodes/tag.js +0 -232
@@ -1,232 +0,0 @@
1
- const {
2
- align,
3
- concat,
4
- fill,
5
- group,
6
- hardline,
7
- ifBreak,
8
- indent,
9
- join,
10
- line,
11
- softline
12
- } = require("../../prettier");
13
-
14
- function getDynamicAttributes(header, attributes) {
15
- const pairs = attributes
16
- .slice(1, -2)
17
- .split(",")
18
- .map((pair) => pair.slice(1).split('" => '));
19
-
20
- const parts = [concat([pairs[0][0], "=", pairs[0][1]])];
21
- pairs.slice(1).forEach((pair) => {
22
- parts.push(line, concat([pair[0], "=", pair[1]]));
23
- });
24
-
25
- return group(concat(["(", align(header + 1, fill(parts)), ")"]));
26
- }
27
-
28
- function getHashValue(value, opts) {
29
- if (typeof value !== "string") {
30
- return value.toString();
31
- }
32
-
33
- // This is a very special syntax created by the parser to let us know that
34
- // this should be printed literally instead of as a string.
35
- if (value.startsWith("&")) {
36
- return value.slice(1);
37
- }
38
-
39
- const quote = opts.rubySingleQuote && !value.includes("#{") ? "'" : '"';
40
- return `${quote}${value}${quote}`;
41
- }
42
-
43
- function getHashKey(key, opts) {
44
- let quoted = key;
45
- const joiner = opts.rubyHashLabel ? ":" : " =>";
46
-
47
- if (key.includes(":") || key.includes("-")) {
48
- const quote = opts.rubySingleQuote ? "'" : '"';
49
- quoted = `${quote}${key}${quote}`;
50
- }
51
-
52
- return `${opts.rubyHashLabel ? "" : ":"}${quoted}${joiner}`;
53
- }
54
-
55
- function getKeyValuePair(key, value, opts) {
56
- return `${getHashKey(key, opts)} ${getHashValue(value, opts)}`;
57
- }
58
-
59
- function getStaticAttributes(header, attributes, opts) {
60
- const keys = Object.keys(attributes).filter(
61
- (name) => !["class", "id"].includes(name)
62
- );
63
-
64
- const parts = [getKeyValuePair(keys[0], attributes[keys[0]], opts)];
65
-
66
- keys.slice(1).forEach((key) => {
67
- parts.push(",", line, getKeyValuePair(key, attributes[key], opts));
68
- });
69
-
70
- return group(concat(["{", align(header + 1, fill(parts)), "}"]));
71
- }
72
-
73
- function getAttributesObject(object, opts, level = 0) {
74
- if (typeof object !== "object") {
75
- return getHashValue(object, opts);
76
- }
77
-
78
- const boundary = level === 0 ? softline : line;
79
- const parts = Object.keys(object).map((key) =>
80
- concat([
81
- getHashKey(key, opts),
82
- " ",
83
- getAttributesObject(object[key], opts, level + 1)
84
- ])
85
- );
86
-
87
- // If we have support for multi-line attributes laid out like a regular hash,
88
- // then we print them that way here.
89
- if (opts.supportsMultiline) {
90
- return group(
91
- concat([
92
- "{",
93
- indent(group(concat([boundary, join(concat([",", line]), parts)]))),
94
- boundary,
95
- "}"
96
- ])
97
- );
98
- }
99
-
100
- // Otherwise, if we only have one attribute, then just print it inline
101
- // regardless of how long it is.
102
- if (parts.length === 0) {
103
- return group(concat(["{", parts[0], "}"]));
104
- }
105
-
106
- // Otherwise, depending on how long the line is it will split the content into
107
- // multi-line attributes that old Haml understands.
108
- return group(
109
- concat([
110
- "{",
111
- parts[0],
112
- ",",
113
- align(
114
- opts.headerLength + 1,
115
- concat([line, join(concat([",", line]), parts.slice(1))])
116
- ),
117
- "}"
118
- ])
119
- );
120
- }
121
-
122
- function getHeader(value, opts, supportsMultiline) {
123
- const { attributes } = value;
124
- const parts = [];
125
-
126
- if (value.name !== "div") {
127
- parts.push(`%${value.name}`);
128
- }
129
-
130
- if (attributes.class) {
131
- parts.push(`.${attributes.class.replace(/ /g, ".")}`);
132
- }
133
-
134
- if (attributes.id) {
135
- parts.push(`#${attributes.id}`);
136
- }
137
-
138
- if (value.dynamic_attributes.new) {
139
- parts.push(
140
- getDynamicAttributes(parts.join("").length, value.dynamic_attributes.new)
141
- );
142
- }
143
-
144
- if (
145
- Object.keys(attributes).some((name) => name !== "class" && name !== "id")
146
- ) {
147
- parts.push(getStaticAttributes(parts.join("").length, attributes, opts));
148
- }
149
-
150
- if (value.dynamic_attributes.old) {
151
- if (parts.length === 0) {
152
- parts.push("%div");
153
- }
154
-
155
- if (typeof value.dynamic_attributes.old === "string") {
156
- parts.push(value.dynamic_attributes.old);
157
- } else {
158
- parts.push(
159
- getAttributesObject(
160
- value.dynamic_attributes.old,
161
- Object.assign({}, opts, {
162
- supportsMultiline,
163
- headerLength: parts.join("").length
164
- })
165
- )
166
- );
167
- }
168
- }
169
-
170
- if (value.object_ref) {
171
- if (parts.length === 0) {
172
- parts.push("%div");
173
- }
174
- parts.push(value.object_ref);
175
- }
176
-
177
- if (value.nuke_outer_whitespace) {
178
- parts.push(">");
179
- }
180
-
181
- if (value.nuke_inner_whitespace) {
182
- parts.push("<");
183
- }
184
-
185
- if (value.self_closing) {
186
- parts.push("/");
187
- }
188
-
189
- if (value.value) {
190
- const prefix = value.parse ? "= " : ifBreak("", " ");
191
-
192
- return group(
193
- concat([
194
- group(concat(parts)),
195
- indent(concat([softline, prefix, value.value]))
196
- ])
197
- );
198
- }
199
-
200
- // In case none of the other if statements have matched and we're printing a
201
- // div, we need to explicitly add it back into the array.
202
- if (parts.length === 0 && value.name === "div") {
203
- parts.push("%div");
204
- }
205
-
206
- return group(concat(parts));
207
- }
208
-
209
- // https://haml.info/docs/yardoc/file.REFERENCE.html#element-name-
210
- function tag(path, opts, print) {
211
- const { children, value } = path.getValue();
212
-
213
- // This is kind of a total hack in that I don't think you're really supposed
214
- // to directly use `path.stack`, but it's the easiest way to get the root node
215
- // without having to know how many levels deep we are.
216
- const { supports_multiline } = path.stack[0];
217
-
218
- const header = getHeader(value, opts, supports_multiline);
219
-
220
- if (children.length === 0) {
221
- return header;
222
- }
223
-
224
- return group(
225
- concat([
226
- header,
227
- indent(concat([hardline, join(hardline, path.map(print, "children"))]))
228
- ])
229
- );
230
- }
231
-
232
- module.exports = tag;