prettier 0.17.0 → 0.18.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 +329 -201
- data/CONTRIBUTING.md +1 -1
- data/README.md +21 -12
- data/package.json +6 -6
- data/src/haml/nodes/silentScript.js +32 -3
- data/src/haml/nodes/tag.js +1 -1
- data/src/haml/parse.rb +2 -0
- data/src/nodes/args.js +7 -0
- data/src/nodes/blocks.js +2 -3
- data/src/nodes/calls.js +1 -1
- data/src/nodes/commands.js +1 -1
- data/src/nodes/conditionals.js +11 -9
- data/src/nodes/ints.js +1 -1
- data/src/nodes/loops.js +16 -0
- data/src/nodes/params.js +3 -1
- data/src/nodes/strings.js +50 -73
- data/src/parse.js +8 -4
- data/src/ripper.rb +29 -21
- metadata +7 -8
- data/src/escapePattern.js +0 -45
data/src/parse.js
CHANGED
@@ -2,10 +2,14 @@ const { spawnSync } = require("child_process");
|
|
2
2
|
const path = require("path");
|
3
3
|
|
4
4
|
module.exports = (text, _parsers, _opts) => {
|
5
|
-
const child = spawnSync(
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
const child = spawnSync(
|
6
|
+
"ruby",
|
7
|
+
["--disable-gems", path.join(__dirname, "./ripper.rb")],
|
8
|
+
{
|
9
|
+
input: text,
|
10
|
+
maxBuffer: 10 * 1024 * 1024 // 10MB
|
11
|
+
}
|
12
|
+
);
|
9
13
|
|
10
14
|
const error = child.stderr.toString();
|
11
15
|
if (error) {
|
data/src/ripper.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
# We implement our own version checking here instead of using Gem::Version so
|
4
|
+
# that we can use the --disable-gems flag.
|
5
|
+
major, minor, * = RUBY_VERSION.split('.').map(&:to_i)
|
6
|
+
if (major < 2) || ((major == 2) && (minor < 5))
|
5
7
|
warn(
|
6
|
-
"Ruby version #{
|
7
|
-
"Please upgrade to #{
|
8
|
+
"Ruby version #{current_version} not supported. " \
|
9
|
+
"Please upgrade to #{required_version} or above."
|
8
10
|
)
|
9
11
|
|
10
12
|
exit 1
|
@@ -166,6 +168,7 @@ class RipperJS < Ripper
|
|
166
168
|
assoc_splat: [:@op, '**'],
|
167
169
|
arg_paren: :@lparen,
|
168
170
|
args_add_star: [:@op, '*'],
|
171
|
+
args_forward: [:@op, '...'],
|
169
172
|
begin: [:@kw, 'begin'],
|
170
173
|
blockarg: [:@op, '&'],
|
171
174
|
brace_block: :@lbrace,
|
@@ -290,7 +293,8 @@ class RipperJS < Ripper
|
|
290
293
|
super(*body).merge!(
|
291
294
|
start: node[:start],
|
292
295
|
char_start: node[:char_start],
|
293
|
-
char_end: char_pos
|
296
|
+
char_end: char_pos,
|
297
|
+
quote: node[:body]
|
294
298
|
)
|
295
299
|
end
|
296
300
|
end
|
@@ -319,14 +323,28 @@ class RipperJS < Ripper
|
|
319
323
|
# child node.
|
320
324
|
%i[dyna_symbol symbol_literal].each do |event|
|
321
325
|
define_method(:"on_#{event}") do |*body|
|
322
|
-
|
326
|
+
options =
|
323
327
|
if scanner_events.any? { |sevent| sevent[:type] == :@symbeg }
|
324
|
-
find_scanner_event(:@symbeg)
|
328
|
+
symbeg = find_scanner_event(:@symbeg)
|
329
|
+
|
330
|
+
{
|
331
|
+
char_start: symbeg[:char_start],
|
332
|
+
char_end: char_pos,
|
333
|
+
quote: symbeg[:body][1]
|
334
|
+
}
|
335
|
+
elsif scanner_events.any? { |sevent| sevent[:type] == :@label_end }
|
336
|
+
label_end = find_scanner_event(:@label_end)
|
337
|
+
|
338
|
+
{
|
339
|
+
char_start: char_start_for(body),
|
340
|
+
char_end: char_pos,
|
341
|
+
quote: label_end[:body][0]
|
342
|
+
}
|
325
343
|
else
|
326
|
-
char_start_for(body)
|
344
|
+
{ char_start: char_start_for(body), char_end: char_pos }
|
327
345
|
end
|
328
346
|
|
329
|
-
super(*body).merge!(
|
347
|
+
super(*body).merge!(options)
|
330
348
|
end
|
331
349
|
end
|
332
350
|
|
@@ -630,6 +648,8 @@ class RipperJS < Ripper
|
|
630
648
|
end
|
631
649
|
)
|
632
650
|
|
651
|
+
# This module contains miscellaneous fixes required to get the right
|
652
|
+
# structure.
|
633
653
|
prepend(
|
634
654
|
Module.new do
|
635
655
|
private
|
@@ -660,18 +680,6 @@ class RipperJS < Ripper
|
|
660
680
|
super(*body).tap { |node| node[:body][0][:body] << __end__ if __end__ }
|
661
681
|
end
|
662
682
|
|
663
|
-
# Adds the used quote type onto string nodes. This is necessary because
|
664
|
-
# we're going to have to stick to whatever quote the user chose if there
|
665
|
-
# are escape sequences within the string. For example, if you have '\n'
|
666
|
-
# we can't switch to double quotes without changing what it means.
|
667
|
-
def on_tstring_end(quote)
|
668
|
-
last_sexp.merge!(quote: quote)
|
669
|
-
end
|
670
|
-
|
671
|
-
def on_label_end(quote)
|
672
|
-
last_sexp.merge!(quote: quote[0]) # quote is ": or ':
|
673
|
-
end
|
674
|
-
|
675
683
|
# Normally access controls are reported as vcall nodes. This creates a
|
676
684
|
# new node type to explicitly track those nodes instead, so that the
|
677
685
|
# printer can add new lines as necessary.
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prettier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Deisz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,7 +72,6 @@ files:
|
|
72
72
|
- node_modules/prettier/index.js
|
73
73
|
- node_modules/prettier/third-party.js
|
74
74
|
- package.json
|
75
|
-
- src/escapePattern.js
|
76
75
|
- src/haml.js
|
77
76
|
- src/haml/embed.js
|
78
77
|
- src/haml/nodes/comment.js
|
@@ -139,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
138
|
- !ruby/object:Gem::Version
|
140
139
|
version: '0'
|
141
140
|
requirements: []
|
142
|
-
rubygems_version: 3.
|
141
|
+
rubygems_version: 3.1.2
|
143
142
|
signing_key:
|
144
143
|
specification_version: 4
|
145
144
|
summary: prettier plugin for the Ruby programming language
|
data/src/escapePattern.js
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* String literal syntax documentation from Ruby source (2.7.0-dev)
|
3
|
-
*
|
4
|
-
* Double-quote strings allow escaped characters such as <tt>\n</tt> for
|
5
|
-
* newline, <tt>\t</tt> for tab, etc. The full list of supported escape
|
6
|
-
* sequences are as follows:
|
7
|
-
*
|
8
|
-
* \a bell, ASCII 07h (BEL)
|
9
|
-
* \b backspace, ASCII 08h (BS)
|
10
|
-
* \t horizontal tab, ASCII 09h (TAB)
|
11
|
-
* \n newline (line feed), ASCII 0Ah (LF)
|
12
|
-
* \v vertical tab, ASCII 0Bh (VT)
|
13
|
-
* \f form feed, ASCII 0Ch (FF)
|
14
|
-
* \r carriage return, ASCII 0Dh (CR)
|
15
|
-
* \e escape, ASCII 1Bh (ESC)
|
16
|
-
* \s space, ASCII 20h (SPC)
|
17
|
-
* \\ backslash, \
|
18
|
-
* \nnn octal bit pattern, where nnn is 1-3 octal digits ([0-7])
|
19
|
-
* \xnn hexadecimal bit pattern, where nn is 1-2 hexadecimal digits ([0-9a-fA-F])
|
20
|
-
* \unnnn Unicode character, where nnnn is exactly 4 hexadecimal digits ([0-9a-fA-F])
|
21
|
-
* \u{nnnn ...} Unicode character(s), where each nnnn is 1-6 hexadecimal digits ([0-9a-fA-F])
|
22
|
-
* \cx or \C-x control character, where x is an ASCII printable character
|
23
|
-
* \M-x meta character, where x is an ASCII printable character
|
24
|
-
* \M-\C-x meta control character, where x is an ASCII printable character
|
25
|
-
* \M-\cx same as above
|
26
|
-
* \c\M-x same as above
|
27
|
-
* \c? or \C-? delete, ASCII 7Fh (DEL)
|
28
|
-
*
|
29
|
-
* In addition to disabling interpolation, single-quoted strings also disable all
|
30
|
-
* escape sequences except for the single-quote (<tt>\'</tt>) and backslash
|
31
|
-
* (<tt>\\\\</tt>).
|
32
|
-
*/
|
33
|
-
const patterns = [
|
34
|
-
"[abtnvfres\\\\]", // simple
|
35
|
-
"[0-7]{1,3}", // octal bits
|
36
|
-
"x[0-9a-fA-F]{1,2}", // hex bit
|
37
|
-
"u[0-9a-fA-F]{4}", // unicode char
|
38
|
-
"u\\{[0-9a-fA-F ]+\\}", // unicode chars
|
39
|
-
"c[ -~]|C\\-[ -~]", // control
|
40
|
-
"M\\-[ -~]", // meta
|
41
|
-
"M\\-\\\\C\\-[ -~]|M\\-\\\\c[ -~]|c\\\\M\\-[ -~]", // meta control
|
42
|
-
"c\\?|C\\-\\?" // delete
|
43
|
-
];
|
44
|
-
|
45
|
-
module.exports = new RegExp(`\\\\(${patterns.join("|")})`);
|