js-beautify 1.7.0 → 1.7.4

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 (50) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/CONTRIBUTING.md +3 -3
  3. package/README.md +15 -12
  4. package/js/bin/css-beautify.js +4 -0
  5. package/js/bin/html-beautify.js +4 -0
  6. package/js/bin/js-beautify.js +4 -0
  7. package/js/config/defaults.json +18 -0
  8. package/js/lib/beautify-css.js +1046 -0
  9. package/js/lib/beautify-html.js +1387 -0
  10. package/js/lib/beautify.js +2820 -0
  11. package/js/lib/cli.js +623 -0
  12. package/js/lib/unpackers/javascriptobfuscator_unpacker.js +103 -0
  13. package/js/lib/unpackers/myobfuscate_unpacker.js +90 -0
  14. package/js/lib/unpackers/p_a_c_k_e_r_unpacker.js +83 -0
  15. package/js/lib/unpackers/urlencode_unpacker.js +73 -0
  16. package/js/src/core/acorn.js +63 -0
  17. package/js/src/core/inputscanner.js +95 -0
  18. package/js/src/core/options.js +48 -0
  19. package/js/src/core/output.js +234 -0
  20. package/js/src/core/token.js +49 -0
  21. package/js/src/css/beautifier.js +477 -0
  22. package/js/src/css/index.js +36 -0
  23. package/js/src/html/beautifier.js +1035 -0
  24. package/js/src/html/index.js +36 -0
  25. package/js/src/index.js +27 -0
  26. package/js/src/javascript/beautifier.js +1449 -0
  27. package/js/src/javascript/index.js +36 -0
  28. package/js/src/javascript/tokenizer.js +620 -0
  29. package/js/test/amd-beautify-tests.js +62 -0
  30. package/js/test/generated/beautify-css-tests.js +1393 -0
  31. package/js/test/generated/beautify-html-tests.js +3212 -0
  32. package/js/test/generated/beautify-javascript-tests.js +5896 -0
  33. package/js/test/node-beautify-html-perf-tests.js +51 -0
  34. package/js/test/node-beautify-perf-tests.js +50 -0
  35. package/js/test/node-beautify-tests.js +45 -0
  36. package/js/test/requirejs-html-beautify.html +58 -0
  37. package/js/test/resources/configerror/.jsbeautifyrc +6 -0
  38. package/js/test/resources/configerror/subDir1/subDir2/empty.txt +0 -0
  39. package/js/test/resources/editorconfig/.editorconfig +6 -0
  40. package/js/test/resources/editorconfig/cr/.editorconfig +3 -0
  41. package/js/test/resources/editorconfig/crlf/.editorconfig +3 -0
  42. package/js/test/resources/editorconfig/error/.editorconfig +1 -0
  43. package/js/test/resources/editorconfig/example-base.js +3 -0
  44. package/js/test/resources/example1.js +3 -0
  45. package/js/test/resources/indent11chars/.jsbeautifyrc +6 -0
  46. package/js/test/resources/indent11chars/subDir1/subDir2/empty.txt +0 -0
  47. package/js/test/run-tests +17 -0
  48. package/js/test/sanitytest.js +144 -0
  49. package/js/test/shell-smoke-test.sh +383 -0
  50. package/package.json +1 -1
@@ -0,0 +1,234 @@
1
+ /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
2
+ /*
3
+
4
+ The MIT License (MIT)
5
+
6
+ Copyright (c) 2007-2017 Einar Lielmanis, Liam Newman, and contributors.
7
+
8
+ Permission is hereby granted, free of charge, to any person
9
+ obtaining a copy of this software and associated documentation files
10
+ (the "Software"), to deal in the Software without restriction,
11
+ including without limitation the rights to use, copy, modify, merge,
12
+ publish, distribute, sublicense, and/or sell copies of the Software,
13
+ and to permit persons to whom the Software is furnished to do so,
14
+ subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be
17
+ included in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
23
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
24
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ */
28
+
29
+ function OutputLine(parent) {
30
+ var _character_count = 0;
31
+ // use indent_count as a marker for lines that have preserved indentation
32
+ var _indent_count = -1;
33
+
34
+ var _items = [];
35
+ var _empty = true;
36
+
37
+ this.set_indent = function(level) {
38
+ _character_count = parent.baseIndentLength + level * parent.indent_length;
39
+ _indent_count = level;
40
+ };
41
+
42
+ this.get_character_count = function() {
43
+ return _character_count;
44
+ };
45
+
46
+ this.is_empty = function() {
47
+ return _empty;
48
+ };
49
+
50
+ this.last = function() {
51
+ if (!this._empty) {
52
+ return _items[_items.length - 1];
53
+ } else {
54
+ return null;
55
+ }
56
+ };
57
+
58
+ this.push = function(input) {
59
+ _items.push(input);
60
+ _character_count += input.length;
61
+ _empty = false;
62
+ };
63
+
64
+ this.pop = function() {
65
+ var item = null;
66
+ if (!_empty) {
67
+ item = _items.pop();
68
+ _character_count -= item.length;
69
+ _empty = _items.length === 0;
70
+ }
71
+ return item;
72
+ };
73
+
74
+ this.remove_indent = function() {
75
+ if (_indent_count > 0) {
76
+ _indent_count -= 1;
77
+ _character_count -= parent.indent_length;
78
+ }
79
+ };
80
+
81
+ this.trim = function() {
82
+ while (this.last() === ' ') {
83
+ _items.pop();
84
+ _character_count -= 1;
85
+ }
86
+ _empty = _items.length === 0;
87
+ };
88
+
89
+ this.toString = function() {
90
+ var result = '';
91
+ if (!this._empty) {
92
+ if (_indent_count >= 0) {
93
+ result = parent.indent_cache[_indent_count];
94
+ }
95
+ result += _items.join('');
96
+ }
97
+ return result;
98
+ };
99
+ }
100
+
101
+ function Output(indent_string, baseIndentString) {
102
+ baseIndentString = baseIndentString || '';
103
+ this.indent_cache = [baseIndentString];
104
+ this.baseIndentLength = baseIndentString.length;
105
+ this.indent_length = indent_string.length;
106
+ this.raw = false;
107
+
108
+ var lines = [];
109
+ this.baseIndentString = baseIndentString;
110
+ this.indent_string = indent_string;
111
+ this.previous_line = null;
112
+ this.current_line = null;
113
+ this.space_before_token = false;
114
+
115
+ this.add_outputline = function() {
116
+ this.previous_line = this.current_line;
117
+ this.current_line = new OutputLine(this);
118
+ lines.push(this.current_line);
119
+ };
120
+
121
+ // initialize
122
+ this.add_outputline();
123
+
124
+
125
+ this.get_line_number = function() {
126
+ return lines.length;
127
+ };
128
+
129
+ // Using object instead of string to allow for later expansion of info about each line
130
+ this.add_new_line = function(force_newline) {
131
+ if (this.get_line_number() === 1 && this.just_added_newline()) {
132
+ return false; // no newline on start of file
133
+ }
134
+
135
+ if (force_newline || !this.just_added_newline()) {
136
+ if (!this.raw) {
137
+ this.add_outputline();
138
+ }
139
+ return true;
140
+ }
141
+
142
+ return false;
143
+ };
144
+
145
+ this.get_code = function(end_with_newline, eol) {
146
+ var sweet_code = lines.join('\n').replace(/[\r\n\t ]+$/, '');
147
+
148
+ if (end_with_newline) {
149
+ sweet_code += '\n';
150
+ }
151
+
152
+ if (eol !== '\n') {
153
+ sweet_code = sweet_code.replace(/[\n]/g, eol);
154
+ }
155
+
156
+ return sweet_code;
157
+ };
158
+
159
+ this.set_indent = function(level) {
160
+ // Never indent your first output indent at the start of the file
161
+ if (lines.length > 1) {
162
+ while (level >= this.indent_cache.length) {
163
+ this.indent_cache.push(this.indent_cache[this.indent_cache.length - 1] + this.indent_string);
164
+ }
165
+
166
+ this.current_line.set_indent(level);
167
+ return true;
168
+ }
169
+ this.current_line.set_indent(0);
170
+ return false;
171
+ };
172
+
173
+ this.add_raw_token = function(token) {
174
+ for (var x = 0; x < token.newlines; x++) {
175
+ this.add_outputline();
176
+ }
177
+ this.current_line.push(token.whitespace_before);
178
+ this.current_line.push(token.text);
179
+ this.space_before_token = false;
180
+ };
181
+
182
+ this.add_token = function(printable_token) {
183
+ this.add_space_before_token();
184
+ this.current_line.push(printable_token);
185
+ };
186
+
187
+ this.add_space_before_token = function() {
188
+ if (this.space_before_token && !this.just_added_newline()) {
189
+ this.current_line.push(' ');
190
+ }
191
+ this.space_before_token = false;
192
+ };
193
+
194
+ this.remove_indent = function(index) {
195
+ var output_length = lines.length;
196
+ while (index < output_length) {
197
+ lines[index].remove_indent();
198
+ index++;
199
+ }
200
+ };
201
+
202
+ this.trim = function(eat_newlines) {
203
+ eat_newlines = (eat_newlines === undefined) ? false : eat_newlines;
204
+
205
+ this.current_line.trim(indent_string, baseIndentString);
206
+
207
+ while (eat_newlines && lines.length > 1 &&
208
+ this.current_line.is_empty()) {
209
+ lines.pop();
210
+ this.current_line = lines[lines.length - 1];
211
+ this.current_line.trim();
212
+ }
213
+
214
+ this.previous_line = lines.length > 1 ? lines[lines.length - 2] : null;
215
+ };
216
+
217
+ this.just_added_newline = function() {
218
+ return this.current_line.is_empty();
219
+ };
220
+
221
+ this.just_added_blankline = function() {
222
+ if (this.just_added_newline()) {
223
+ if (lines.length === 1) {
224
+ return true; // start of the file and newline = blank
225
+ }
226
+
227
+ var line = lines[lines.length - 2];
228
+ return line.is_empty();
229
+ }
230
+ return false;
231
+ };
232
+ }
233
+
234
+ module.exports.Output = Output;
@@ -0,0 +1,49 @@
1
+ /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
2
+ /*
3
+
4
+ The MIT License (MIT)
5
+
6
+ Copyright (c) 2007-2017 Einar Lielmanis, Liam Newman, and contributors.
7
+
8
+ Permission is hereby granted, free of charge, to any person
9
+ obtaining a copy of this software and associated documentation files
10
+ (the "Software"), to deal in the Software without restriction,
11
+ including without limitation the rights to use, copy, modify, merge,
12
+ publish, distribute, sublicense, and/or sell copies of the Software,
13
+ and to permit persons to whom the Software is furnished to do so,
14
+ subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be
17
+ included in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
23
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
24
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ */
28
+
29
+ function Token(type, text, newlines, whitespace_before, parent) {
30
+ this.type = type;
31
+ this.text = text;
32
+
33
+ // comments_before are
34
+ // comments that have a new line before them
35
+ // and may or may not have a newline after
36
+ // this is a set of comments before
37
+ this.comments_before = /* inline comment*/ [];
38
+
39
+
40
+ this.comments_after = []; // no new line before and newline after
41
+ this.newlines = newlines || 0;
42
+ this.wanted_newline = newlines > 0;
43
+ this.whitespace_before = whitespace_before || '';
44
+ this.parent = parent || null;
45
+ this.opened = null;
46
+ this.directives = null;
47
+ }
48
+
49
+ module.exports.Token = Token;