prettier 0.20.0 → 0.20.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,18 +0,0 @@
1
- const { spawnSync } = require("child_process");
2
- const path = require("path");
3
-
4
- const parse = (text, _parsers, _opts) => {
5
- const child = spawnSync("ruby", [path.join(__dirname, "./parse.rb")], {
6
- input: text
7
- });
8
-
9
- const error = child.stderr.toString();
10
- if (error) {
11
- throw new Error(error);
12
- }
13
-
14
- const response = child.stdout.toString();
15
- return JSON.parse(response);
16
- };
17
-
18
- module.exports = parse;
@@ -1,64 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup' if ENV['CI']
4
- require 'haml'
5
-
6
- class Haml::Parser::ParseNode
7
- ESCAPE = /Haml::Helpers.html_escape\(\((.+)\)\)/.freeze
8
-
9
- def as_json
10
- case type
11
- when :comment, :doctype, :plain, :silent_script
12
- to_h.tap do |json|
13
- json.delete(:parent)
14
- json[:children] = children.map(&:as_json)
15
- end
16
- when :filter, :haml_comment
17
- to_h.tap { |json| json.delete(:parent) }
18
- when :root
19
- to_h.tap { |json| json[:children] = children.map(&:as_json) }
20
- when :script
21
- to_h.tap do |json|
22
- json.delete(:parent)
23
- json[:children] = children.map(&:as_json)
24
-
25
- if json[:value][:text].match?(ESCAPE)
26
- json[:value][:text].gsub!(ESCAPE) { $1 }
27
- json[:value].merge!(escape_html: 'escape_html', interpolate: true)
28
- end
29
- end
30
- when :tag
31
- to_h.tap do |json|
32
- json.delete(:parent)
33
-
34
- # For some reason this is actually using a symbol to represent a null
35
- # object ref instead of nil itself, so just replacing it here for
36
- # simplicity in the printer
37
- json[:value][:object_ref] = nil if json[:value][:object_ref] == :nil
38
-
39
- json.merge!(
40
- children: children.map(&:as_json),
41
- value:
42
- value.merge(dynamic_attributes: value[:dynamic_attributes].to_h)
43
- )
44
- end
45
- else
46
- raise ArgumentError, "Unsupported type: #{type}"
47
- end
48
- end
49
- end
50
-
51
- # If this is the main file we're executing, then most likely this is being
52
- # executed from the haml.js spawn. In that case, read the ruby source from
53
- # stdin and report back the AST over stdout.
54
- if $0 == __FILE__
55
- # Don't explicitly require JSON if there is already as JSON loaded, as this
56
- # can lead to all kinds of trouble where one version of it was already
57
- # "activated" by rubygems.
58
- require 'json' unless defined?(JSON)
59
-
60
- parser = Haml::Parser.new({})
61
- template = $stdin.read
62
-
63
- puts JSON.fast_generate(parser.call(template).as_json)
64
- end
@@ -1,38 +0,0 @@
1
- const { concat, hardline, join, markAsRoot } = require("../prettier");
2
-
3
- const comment = require("./nodes/comment");
4
- const doctype = require("./nodes/doctype");
5
- const filter = require("./nodes/filter");
6
- const hamlComment = require("./nodes/hamlComment");
7
- const script = require("./nodes/script");
8
- const silentScript = require("./nodes/silentScript");
9
- const tag = require("./nodes/tag");
10
-
11
- const nodes = {
12
- comment,
13
- doctype,
14
- filter,
15
- haml_comment: hamlComment,
16
- plain: (path, _opts, _print) => {
17
- const { value } = path.getValue();
18
-
19
- return value.text.startsWith("=") ? `\\${value.text}` : value.text;
20
- },
21
- root: (path, opts, print) =>
22
- markAsRoot(concat([join(hardline, path.map(print, "children")), hardline])),
23
- script,
24
- silent_script: silentScript,
25
- tag
26
- };
27
-
28
- const genericPrint = (path, opts, print) => {
29
- const { type } = path.getValue();
30
-
31
- if (!(type in nodes)) {
32
- throw new Error(`Unsupported node encountered: ${type}`);
33
- }
34
-
35
- return nodes[type](path, opts, print);
36
- };
37
-
38
- module.exports = genericPrint;