js-beautify 1.8.8 → 1.8.9
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.
- package/CHANGELOG.md +13 -11
- package/README.md +13 -13
- package/js/lib/beautifier.js +47 -11
- package/js/lib/beautifier.min.js +1 -1
- package/js/lib/beautify-css.js +5 -1
- package/js/lib/beautify-html.js +17 -4
- package/js/lib/beautify.js +24 -6
- package/js/lib/cli.js +516 -485
- package/js/src/cli.js +516 -485
- package/js/src/css/index.js +5 -1
- package/js/src/html/beautifier.js +12 -3
- package/js/src/html/index.js +5 -1
- package/js/src/index.js +1 -0
- package/js/src/javascript/beautifier.js +19 -5
- package/js/src/javascript/index.js +5 -1
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
|
+
## v1.8.9
|
|
3
|
+
|
|
4
|
+
### Description
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
### Closed Issues
|
|
8
|
+
* Won't run from CLI - bad option name `files` ([#1583](https://github.com/beautify-web/js-beautify/issues/1583))
|
|
9
|
+
* in the .vue file `space_after_anon_function` is invalid ([#1425](https://github.com/beautify-web/js-beautify/issues/1425))
|
|
10
|
+
* Add function default_options() to beautifier.js ([#1364](https://github.com/beautify-web/js-beautify/issues/1364))
|
|
11
|
+
* Support globs in CLI ([#787](https://github.com/beautify-web/js-beautify/issues/787))
|
|
12
|
+
|
|
13
|
+
|
|
2
14
|
## v1.8.8
|
|
3
15
|
|
|
4
16
|
### Description
|
|
@@ -19,7 +31,7 @@
|
|
|
19
31
|
* HTML: add an option to preserve manual wrapping of attributes ([#1125](https://github.com/beautify-web/js-beautify/issues/1125))
|
|
20
32
|
* js-beautify adds a space between # and include ([#1114](https://github.com/beautify-web/js-beautify/issues/1114))
|
|
21
33
|
* space_after_anon_function doesn't work with anon async functions ([#1034](https://github.com/beautify-web/js-beautify/issues/1034))
|
|
22
|
-
* Space before function arguments (space-after-function) ([#608](https://github.com/beautify-web/js-beautify/issues/608))
|
|
34
|
+
* Space before function arguments (space-after-function) (space-after-named-function) ([#608](https://github.com/beautify-web/js-beautify/issues/608))
|
|
23
35
|
|
|
24
36
|
|
|
25
37
|
## v1.8.6
|
|
@@ -46,16 +58,6 @@ Broader adoption of 1.8.x revealed a few more high priority fixes
|
|
|
46
58
|
* unindent_chained_methods broken ([#1533](https://github.com/beautify-web/js-beautify/issues/1533))
|
|
47
59
|
|
|
48
60
|
|
|
49
|
-
## v1.8.1
|
|
50
|
-
|
|
51
|
-
### Description
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
### Closed Issues
|
|
55
|
-
* Why npm is a dependency? ([#1516](https://github.com/beautify-web/js-beautify/issues/1516))
|
|
56
|
-
* indent_inner_html not working in v1.8.0 ([#1514](https://github.com/beautify-web/js-beautify/issues/1514))
|
|
57
|
-
|
|
58
|
-
|
|
59
61
|
## v1.8.0
|
|
60
62
|
|
|
61
63
|
### Description
|
package/README.md
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# JS Beautifier
|
|
2
|
-
[](https://ci.appveyor.com/project/beautify-web/js-beautify/branch/master)
|
|
2
|
+
[](https://dev.azure.com/beautifier-io/js-beautify/_build/latest?definitionId=1)
|
|
4
3
|
|
|
5
4
|
[](https://pypi.python.org/pypi/jsbeautifier)
|
|
6
5
|
[](https://cdnjs.com/libraries/js-beautify)
|
|
@@ -62,17 +61,17 @@ JS Beautifier is hosted on two CDN services: [cdnjs](https://cdnjs.com/libraries
|
|
|
62
61
|
|
|
63
62
|
To pull the latest version from one of these services include one set of the script tags below in your document:
|
|
64
63
|
```html
|
|
65
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.
|
|
66
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.
|
|
67
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.
|
|
64
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.9/beautify.js"></script>
|
|
65
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.9/beautify-css.js"></script>
|
|
66
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.9/beautify-html.js"></script>
|
|
68
67
|
|
|
69
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.
|
|
70
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.
|
|
71
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.
|
|
68
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.9/beautify.min.js"></script>
|
|
69
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.9/beautify-css.min.js"></script>
|
|
70
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.8.9/beautify-html.min.js"></script>
|
|
72
71
|
|
|
73
|
-
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.8.
|
|
74
|
-
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.8.
|
|
75
|
-
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.8.
|
|
72
|
+
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.8.9/js/lib/beautify.js"></script>
|
|
73
|
+
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.8.9/js/lib/beautify-css.js"></script>
|
|
74
|
+
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.8.9/js/lib/beautify-html.js"></script>
|
|
76
75
|
```
|
|
77
76
|
|
|
78
77
|
Older versions are available by changing the version number.
|
|
@@ -160,7 +159,7 @@ CLI Options:
|
|
|
160
159
|
-r, --replace Write output in-place, replacing input
|
|
161
160
|
-o, --outfile Write output to file (default stdout)
|
|
162
161
|
--config Path to config file
|
|
163
|
-
--type [js|css|html] ["js"]
|
|
162
|
+
--type [js|css|html] ["js"] Select beautifier type (NOTE: Does *not* filter files, only defines which beautifier type to run)
|
|
164
163
|
-q, --quiet Suppress logging to stdout
|
|
165
164
|
-h, --help Show this help
|
|
166
165
|
-v, --version Show the version
|
|
@@ -201,6 +200,7 @@ Which correspond to the underscored option keys for both library interfaces
|
|
|
201
200
|
"indent_size": 4,
|
|
202
201
|
"indent_char": " ",
|
|
203
202
|
"indent_with_tabs": false,
|
|
203
|
+
"editorconfig": false,
|
|
204
204
|
"eol": "\n",
|
|
205
205
|
"end_with_newline": false,
|
|
206
206
|
"indent_level": 0,
|
|
@@ -377,4 +377,4 @@ Thanks also to Jason Diamond, Patrick Hof, Nochum Sossonko, Andreas Schneider, D
|
|
|
377
377
|
Vasilevsky, Vital Batmanov, Ron Baldwin, Gabriel Harrison, Chris J. Shull,
|
|
378
378
|
Mathias Bynens, Vittorio Gambaletta and others.
|
|
379
379
|
|
|
380
|
-
(README.md: js-beautify@1.8.
|
|
380
|
+
(README.md: js-beautify@1.8.9)
|
package/js/lib/beautifier.js
CHANGED
|
@@ -138,6 +138,7 @@ function style_html(html_source, options, js, css) {
|
|
|
138
138
|
css = css || css_beautify;
|
|
139
139
|
return html_beautify(html_source, options, js, css);
|
|
140
140
|
}
|
|
141
|
+
style_html.defaultOptions = html_beautify.defaultOptions;
|
|
141
142
|
|
|
142
143
|
module.exports.js = js_beautify;
|
|
143
144
|
module.exports.css = css_beautify;
|
|
@@ -179,7 +180,8 @@ module.exports.html = style_html;
|
|
|
179
180
|
|
|
180
181
|
|
|
181
182
|
|
|
182
|
-
var Beautifier = __webpack_require__(2).Beautifier
|
|
183
|
+
var Beautifier = __webpack_require__(2).Beautifier,
|
|
184
|
+
Options = __webpack_require__(6).Options;
|
|
183
185
|
|
|
184
186
|
function js_beautify(js_source_text, options) {
|
|
185
187
|
var beautifier = new Beautifier(js_source_text, options);
|
|
@@ -187,6 +189,9 @@ function js_beautify(js_source_text, options) {
|
|
|
187
189
|
}
|
|
188
190
|
|
|
189
191
|
module.exports = js_beautify;
|
|
192
|
+
module.exports.defaultOptions = function() {
|
|
193
|
+
return new Options();
|
|
194
|
+
};
|
|
190
195
|
|
|
191
196
|
|
|
192
197
|
/***/ }),
|
|
@@ -767,13 +772,24 @@ Beautifier.prototype.handle_start_expr = function(current_token) {
|
|
|
767
772
|
// function name() vs function name ()
|
|
768
773
|
// function* name() vs function* name ()
|
|
769
774
|
// async name() vs async name ()
|
|
770
|
-
|
|
775
|
+
// In ES6, you can also define the method properties of an object
|
|
776
|
+
// var obj = {a: function() {}}
|
|
777
|
+
// It can be abbreviated
|
|
778
|
+
// var obj = {a() {}}
|
|
779
|
+
// var obj = { a() {}} vs var obj = { a () {}}
|
|
780
|
+
// var obj = { * a() {}} vs var obj = { * a () {}}
|
|
781
|
+
var peek_back_two = this._tokens.peek(-3);
|
|
782
|
+
if (this._options.space_after_named_function && peek_back_two) {
|
|
771
783
|
// peek starts at next character so -1 is current token
|
|
772
784
|
var peek_back_three = this._tokens.peek(-4);
|
|
773
|
-
var peek_back_two = this._tokens.peek(-3);
|
|
774
785
|
if (reserved_array(peek_back_two, ['async', 'function']) ||
|
|
775
|
-
(reserved_array(peek_back_three, ['async', 'function'])
|
|
786
|
+
(peek_back_two.text === '*' && reserved_array(peek_back_three, ['async', 'function']))) {
|
|
776
787
|
this._output.space_before_token = true;
|
|
788
|
+
} else if (this._flags.mode === MODE.ObjectLiteral) {
|
|
789
|
+
if ((peek_back_two.text === '{' || peek_back_two.text === ',') ||
|
|
790
|
+
(peek_back_two.text === '*' && (peek_back_three.text === '{' || peek_back_three.text === ','))) {
|
|
791
|
+
this._output.space_before_token = true;
|
|
792
|
+
}
|
|
777
793
|
}
|
|
778
794
|
}
|
|
779
795
|
} else {
|
|
@@ -791,10 +807,8 @@ Beautifier.prototype.handle_start_expr = function(current_token) {
|
|
|
791
807
|
(this._flags.last_token.text === '*' &&
|
|
792
808
|
(in_array(this._last_last_text, ['function', 'yield']) ||
|
|
793
809
|
(this._flags.mode === MODE.ObjectLiteral && in_array(this._last_last_text, ['{', ',']))))) {
|
|
794
|
-
|
|
795
810
|
this._output.space_before_token = this._options.space_after_anon_function;
|
|
796
811
|
}
|
|
797
|
-
|
|
798
812
|
}
|
|
799
813
|
|
|
800
814
|
if (this._flags.last_token.text === ';' || this._flags.last_token.type === TOKEN.START_BLOCK) {
|
|
@@ -945,6 +959,11 @@ Beautifier.prototype.handle_start_block = function(current_token) {
|
|
|
945
959
|
}
|
|
946
960
|
this.print_token(current_token);
|
|
947
961
|
this.indent();
|
|
962
|
+
|
|
963
|
+
// Except for specific cases, open braces are followed by a new line.
|
|
964
|
+
if (!empty_braces && !(this._options.brace_preserve_inline && this._flags.inline_frame)) {
|
|
965
|
+
this.print_newline();
|
|
966
|
+
}
|
|
948
967
|
};
|
|
949
968
|
|
|
950
969
|
Beautifier.prototype.handle_end_block = function(current_token) {
|
|
@@ -3381,7 +3400,8 @@ module.exports.Directives = Directives;
|
|
|
3381
3400
|
|
|
3382
3401
|
|
|
3383
3402
|
|
|
3384
|
-
var Beautifier = __webpack_require__(14).Beautifier
|
|
3403
|
+
var Beautifier = __webpack_require__(14).Beautifier,
|
|
3404
|
+
Options = __webpack_require__(15).Options;
|
|
3385
3405
|
|
|
3386
3406
|
function css_beautify(source_text, options) {
|
|
3387
3407
|
var beautifier = new Beautifier(source_text, options);
|
|
@@ -3389,6 +3409,9 @@ function css_beautify(source_text, options) {
|
|
|
3389
3409
|
}
|
|
3390
3410
|
|
|
3391
3411
|
module.exports = css_beautify;
|
|
3412
|
+
module.exports.defaultOptions = function() {
|
|
3413
|
+
return new Options();
|
|
3414
|
+
};
|
|
3392
3415
|
|
|
3393
3416
|
|
|
3394
3417
|
/***/ }),
|
|
@@ -3924,7 +3947,8 @@ module.exports.Options = Options;
|
|
|
3924
3947
|
|
|
3925
3948
|
|
|
3926
3949
|
|
|
3927
|
-
var Beautifier = __webpack_require__(17).Beautifier
|
|
3950
|
+
var Beautifier = __webpack_require__(17).Beautifier,
|
|
3951
|
+
Options = __webpack_require__(18).Options;
|
|
3928
3952
|
|
|
3929
3953
|
function style_html(html_source, options, js_beautify, css_beautify) {
|
|
3930
3954
|
var beautifier = new Beautifier(html_source, options, js_beautify, css_beautify);
|
|
@@ -3932,6 +3956,9 @@ function style_html(html_source, options, js_beautify, css_beautify) {
|
|
|
3932
3956
|
}
|
|
3933
3957
|
|
|
3934
3958
|
module.exports = style_html;
|
|
3959
|
+
module.exports.defaultOptions = function() {
|
|
3960
|
+
return new Options();
|
|
3961
|
+
};
|
|
3935
3962
|
|
|
3936
3963
|
|
|
3937
3964
|
/***/ }),
|
|
@@ -4252,7 +4279,10 @@ Beautifier.prototype.beautify = function() {
|
|
|
4252
4279
|
};
|
|
4253
4280
|
|
|
4254
4281
|
Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_token) {
|
|
4255
|
-
var parser_token = {
|
|
4282
|
+
var parser_token = {
|
|
4283
|
+
text: raw_token.text,
|
|
4284
|
+
type: raw_token.type
|
|
4285
|
+
};
|
|
4256
4286
|
printer.alignment_size = 0;
|
|
4257
4287
|
last_tag_token.tag_complete = true;
|
|
4258
4288
|
|
|
@@ -4280,7 +4310,10 @@ Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_t
|
|
|
4280
4310
|
};
|
|
4281
4311
|
|
|
4282
4312
|
Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, tokens) {
|
|
4283
|
-
var parser_token = {
|
|
4313
|
+
var parser_token = {
|
|
4314
|
+
text: raw_token.text,
|
|
4315
|
+
type: raw_token.type
|
|
4316
|
+
};
|
|
4284
4317
|
printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '');
|
|
4285
4318
|
if (last_tag_token.is_unformatted) {
|
|
4286
4319
|
printer.add_raw_token(raw_token);
|
|
@@ -4344,7 +4377,10 @@ Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_
|
|
|
4344
4377
|
};
|
|
4345
4378
|
|
|
4346
4379
|
Beautifier.prototype._handle_text = function(printer, raw_token, last_tag_token) {
|
|
4347
|
-
var parser_token = {
|
|
4380
|
+
var parser_token = {
|
|
4381
|
+
text: raw_token.text,
|
|
4382
|
+
type: 'TK_CONTENT'
|
|
4383
|
+
};
|
|
4348
4384
|
if (last_tag_token.custom_beautifier) { //check if we need to format javascript
|
|
4349
4385
|
this._print_custom_beatifier_text(printer, raw_token, last_tag_token);
|
|
4350
4386
|
} else if (last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) {
|