prettier 0.21.0 → 1.0.1

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 (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +112 -7
  3. data/CONTRIBUTING.md +4 -4
  4. data/README.md +18 -14
  5. data/package.json +9 -6
  6. data/src/embed.js +27 -8
  7. data/src/nodes.js +5 -2
  8. data/src/nodes/alias.js +29 -31
  9. data/src/nodes/aref.js +26 -26
  10. data/src/nodes/args.js +55 -47
  11. data/src/nodes/arrays.js +132 -106
  12. data/src/nodes/assign.js +32 -32
  13. data/src/nodes/blocks.js +8 -3
  14. data/src/nodes/calls.js +163 -60
  15. data/src/nodes/case.js +11 -7
  16. data/src/nodes/class.js +74 -0
  17. data/src/nodes/commands.js +36 -31
  18. data/src/nodes/conditionals.js +44 -30
  19. data/src/nodes/constants.js +39 -21
  20. data/src/nodes/flow.js +11 -1
  21. data/src/nodes/hashes.js +90 -109
  22. data/src/nodes/heredocs.js +34 -0
  23. data/src/nodes/hooks.js +21 -22
  24. data/src/nodes/ints.js +27 -20
  25. data/src/nodes/lambdas.js +14 -27
  26. data/src/nodes/loops.js +10 -5
  27. data/src/nodes/massign.js +87 -65
  28. data/src/nodes/methods.js +48 -73
  29. data/src/nodes/operators.js +70 -39
  30. data/src/nodes/params.js +26 -16
  31. data/src/nodes/patterns.js +108 -33
  32. data/src/nodes/regexp.js +45 -14
  33. data/src/nodes/rescue.js +72 -59
  34. data/src/nodes/statements.js +86 -44
  35. data/src/nodes/strings.js +95 -85
  36. data/src/nodes/super.js +35 -0
  37. data/src/nodes/undef.js +42 -0
  38. data/src/parser.js +86 -0
  39. data/src/parser.rb +2400 -621
  40. data/src/printer.js +90 -0
  41. data/src/ruby.js +19 -41
  42. data/src/toProc.js +4 -4
  43. data/src/utils.js +24 -88
  44. data/src/utils/literalLineNoBreak.js +7 -0
  45. data/src/utils/printEmptyCollection.js +42 -0
  46. metadata +12 -49
  47. data/src/nodes/scopes.js +0 -61
  48. data/src/parse.js +0 -37
  49. data/src/print.js +0 -23
@@ -1,61 +0,0 @@
1
- const {
2
- concat,
3
- group,
4
- hardline,
5
- ifBreak,
6
- indent,
7
- line
8
- } = require("../prettier");
9
-
10
- module.exports = {
11
- class: (path, opts, print) => {
12
- const [_constant, superclass, statements] = path.getValue().body;
13
-
14
- const parts = ["class ", path.call(print, "body", 0)];
15
- if (superclass) {
16
- parts.push(" < ", path.call(print, "body", 1));
17
- }
18
-
19
- // If the body is empty, we can replace with a ;
20
- const stmts = statements.body[0].body;
21
- if (stmts.length === 1 && stmts[0].type === "void_stmt") {
22
- return group(concat([concat(parts), ifBreak(line, "; "), "end"]));
23
- }
24
-
25
- return group(
26
- concat([
27
- concat(parts),
28
- indent(concat([hardline, path.call(print, "body", 2)])),
29
- concat([hardline, "end"])
30
- ])
31
- );
32
- },
33
- class_name_error: (_path, _opts, _print) => {
34
- throw new Error("class/module name must be CONSTANT");
35
- },
36
- module: (path, opts, print) => {
37
- const declaration = group(concat(["module ", path.call(print, "body", 0)]));
38
-
39
- // If the body is empty, we can replace with a ;
40
- const stmts = path.getValue().body[1].body[0].body;
41
- if (stmts.length === 1 && stmts[0].type === "void_stmt") {
42
- return group(concat([declaration, ifBreak(line, "; "), "end"]));
43
- }
44
-
45
- return group(
46
- concat([
47
- declaration,
48
- indent(concat([hardline, path.call(print, "body", 1)])),
49
- concat([hardline, "end"])
50
- ])
51
- );
52
- },
53
- sclass: (path, opts, print) =>
54
- group(
55
- concat([
56
- concat(["class << ", path.call(print, "body", 0)]),
57
- indent(concat([hardline, path.call(print, "body", 1)])),
58
- concat([hardline, "end"])
59
- ])
60
- )
61
- };
@@ -1,37 +0,0 @@
1
- const { spawnSync } = require("child_process");
2
- const path = require("path");
3
-
4
- // In order to properly parse ruby code, we need to tell the ruby process to
5
- // parse using UTF-8. Unfortunately, the way that you accomplish this looks
6
- // differently depending on your platform. This object below represents all of
7
- // the possible values of process.platform per:
8
- // https://nodejs.org/api/process.html#process_process_platform
9
- const LANG = {
10
- aix: "C.UTF-8",
11
- darwin: "en_US.UTF-8",
12
- freebsd: "C.UTF-8",
13
- linux: "C.UTF-8",
14
- openbsd: "C.UTF-8",
15
- sunos: "C.UTF-8",
16
- win32: ".UTF-8"
17
- }[process.platform];
18
-
19
- module.exports = (text, _parsers, _opts) => {
20
- const child = spawnSync(
21
- "ruby",
22
- ["--disable-gems", path.join(__dirname, "./parser.rb")],
23
- {
24
- env: Object.assign({}, process.env, { LANG }),
25
- input: text,
26
- maxBuffer: 10 * 1024 * 1024 // 10MB
27
- }
28
- );
29
-
30
- const error = child.stderr.toString();
31
- if (error) {
32
- throw new Error(error);
33
- }
34
-
35
- const response = child.stdout.toString();
36
- return JSON.parse(response);
37
- };
@@ -1,23 +0,0 @@
1
- const { printComments } = require("./utils");
2
- const nodes = require("./nodes");
3
-
4
- module.exports = (path, opts, print) => {
5
- const { type, body, comments, start } = path.getValue();
6
-
7
- if (type in nodes) {
8
- const printed = nodes[type](path, opts, print);
9
-
10
- if (comments) {
11
- return printComments(printed, start, comments);
12
- }
13
- return printed;
14
- }
15
-
16
- if (type[0] === "@") {
17
- return body;
18
- }
19
-
20
- throw new Error(
21
- `Unsupported node encountered: ${type}\n${JSON.stringify(body, null, 2)}`
22
- );
23
- };