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/js/src/css/index.js
CHANGED
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
|
|
29
29
|
'use strict';
|
|
30
30
|
|
|
31
|
-
var Beautifier = require('./beautifier').Beautifier
|
|
31
|
+
var Beautifier = require('./beautifier').Beautifier,
|
|
32
|
+
Options = require('./options').Options;
|
|
32
33
|
|
|
33
34
|
function css_beautify(source_text, options) {
|
|
34
35
|
var beautifier = new Beautifier(source_text, options);
|
|
@@ -36,3 +37,6 @@ function css_beautify(source_text, options) {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
module.exports = css_beautify;
|
|
40
|
+
module.exports.defaultOptions = function() {
|
|
41
|
+
return new Options();
|
|
42
|
+
};
|
|
@@ -311,7 +311,10 @@ Beautifier.prototype.beautify = function() {
|
|
|
311
311
|
};
|
|
312
312
|
|
|
313
313
|
Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_token) {
|
|
314
|
-
var parser_token = {
|
|
314
|
+
var parser_token = {
|
|
315
|
+
text: raw_token.text,
|
|
316
|
+
type: raw_token.type
|
|
317
|
+
};
|
|
315
318
|
printer.alignment_size = 0;
|
|
316
319
|
last_tag_token.tag_complete = true;
|
|
317
320
|
|
|
@@ -339,7 +342,10 @@ Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_t
|
|
|
339
342
|
};
|
|
340
343
|
|
|
341
344
|
Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, tokens) {
|
|
342
|
-
var parser_token = {
|
|
345
|
+
var parser_token = {
|
|
346
|
+
text: raw_token.text,
|
|
347
|
+
type: raw_token.type
|
|
348
|
+
};
|
|
343
349
|
printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '');
|
|
344
350
|
if (last_tag_token.is_unformatted) {
|
|
345
351
|
printer.add_raw_token(raw_token);
|
|
@@ -403,7 +409,10 @@ Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_
|
|
|
403
409
|
};
|
|
404
410
|
|
|
405
411
|
Beautifier.prototype._handle_text = function(printer, raw_token, last_tag_token) {
|
|
406
|
-
var parser_token = {
|
|
412
|
+
var parser_token = {
|
|
413
|
+
text: raw_token.text,
|
|
414
|
+
type: 'TK_CONTENT'
|
|
415
|
+
};
|
|
407
416
|
if (last_tag_token.custom_beautifier) { //check if we need to format javascript
|
|
408
417
|
this._print_custom_beatifier_text(printer, raw_token, last_tag_token);
|
|
409
418
|
} else if (last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) {
|
package/js/src/html/index.js
CHANGED
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
|
|
29
29
|
'use strict';
|
|
30
30
|
|
|
31
|
-
var Beautifier = require('./beautifier').Beautifier
|
|
31
|
+
var Beautifier = require('./beautifier').Beautifier,
|
|
32
|
+
Options = require('./options').Options;
|
|
32
33
|
|
|
33
34
|
function style_html(html_source, options, js_beautify, css_beautify) {
|
|
34
35
|
var beautifier = new Beautifier(html_source, options, js_beautify, css_beautify);
|
|
@@ -36,3 +37,6 @@ function style_html(html_source, options, js_beautify, css_beautify) {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
module.exports = style_html;
|
|
40
|
+
module.exports.defaultOptions = function() {
|
|
41
|
+
return new Options();
|
|
42
|
+
};
|
package/js/src/index.js
CHANGED
|
@@ -37,6 +37,7 @@ function style_html(html_source, options, js, css) {
|
|
|
37
37
|
css = css || css_beautify;
|
|
38
38
|
return html_beautify(html_source, options, js, css);
|
|
39
39
|
}
|
|
40
|
+
style_html.defaultOptions = html_beautify.defaultOptions;
|
|
40
41
|
|
|
41
42
|
module.exports.js = js_beautify;
|
|
42
43
|
module.exports.css = css_beautify;
|
|
@@ -571,13 +571,24 @@ Beautifier.prototype.handle_start_expr = function(current_token) {
|
|
|
571
571
|
// function name() vs function name ()
|
|
572
572
|
// function* name() vs function* name ()
|
|
573
573
|
// async name() vs async name ()
|
|
574
|
-
|
|
574
|
+
// In ES6, you can also define the method properties of an object
|
|
575
|
+
// var obj = {a: function() {}}
|
|
576
|
+
// It can be abbreviated
|
|
577
|
+
// var obj = {a() {}}
|
|
578
|
+
// var obj = { a() {}} vs var obj = { a () {}}
|
|
579
|
+
// var obj = { * a() {}} vs var obj = { * a () {}}
|
|
580
|
+
var peek_back_two = this._tokens.peek(-3);
|
|
581
|
+
if (this._options.space_after_named_function && peek_back_two) {
|
|
575
582
|
// peek starts at next character so -1 is current token
|
|
576
583
|
var peek_back_three = this._tokens.peek(-4);
|
|
577
|
-
var peek_back_two = this._tokens.peek(-3);
|
|
578
584
|
if (reserved_array(peek_back_two, ['async', 'function']) ||
|
|
579
|
-
(reserved_array(peek_back_three, ['async', 'function'])
|
|
585
|
+
(peek_back_two.text === '*' && reserved_array(peek_back_three, ['async', 'function']))) {
|
|
580
586
|
this._output.space_before_token = true;
|
|
587
|
+
} else if (this._flags.mode === MODE.ObjectLiteral) {
|
|
588
|
+
if ((peek_back_two.text === '{' || peek_back_two.text === ',') ||
|
|
589
|
+
(peek_back_two.text === '*' && (peek_back_three.text === '{' || peek_back_three.text === ','))) {
|
|
590
|
+
this._output.space_before_token = true;
|
|
591
|
+
}
|
|
581
592
|
}
|
|
582
593
|
}
|
|
583
594
|
} else {
|
|
@@ -595,10 +606,8 @@ Beautifier.prototype.handle_start_expr = function(current_token) {
|
|
|
595
606
|
(this._flags.last_token.text === '*' &&
|
|
596
607
|
(in_array(this._last_last_text, ['function', 'yield']) ||
|
|
597
608
|
(this._flags.mode === MODE.ObjectLiteral && in_array(this._last_last_text, ['{', ',']))))) {
|
|
598
|
-
|
|
599
609
|
this._output.space_before_token = this._options.space_after_anon_function;
|
|
600
610
|
}
|
|
601
|
-
|
|
602
611
|
}
|
|
603
612
|
|
|
604
613
|
if (this._flags.last_token.text === ';' || this._flags.last_token.type === TOKEN.START_BLOCK) {
|
|
@@ -749,6 +758,11 @@ Beautifier.prototype.handle_start_block = function(current_token) {
|
|
|
749
758
|
}
|
|
750
759
|
this.print_token(current_token);
|
|
751
760
|
this.indent();
|
|
761
|
+
|
|
762
|
+
// Except for specific cases, open braces are followed by a new line.
|
|
763
|
+
if (!empty_braces && !(this._options.brace_preserve_inline && this._flags.inline_frame)) {
|
|
764
|
+
this.print_newline();
|
|
765
|
+
}
|
|
752
766
|
};
|
|
753
767
|
|
|
754
768
|
Beautifier.prototype.handle_end_block = function(current_token) {
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
|
|
29
29
|
'use strict';
|
|
30
30
|
|
|
31
|
-
var Beautifier = require('./beautifier').Beautifier
|
|
31
|
+
var Beautifier = require('./beautifier').Beautifier,
|
|
32
|
+
Options = require('./options').Options;
|
|
32
33
|
|
|
33
34
|
function js_beautify(js_source_text, options) {
|
|
34
35
|
var beautifier = new Beautifier(js_source_text, options);
|
|
@@ -36,3 +37,6 @@ function js_beautify(js_source_text, options) {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
module.exports = js_beautify;
|
|
40
|
+
module.exports.defaultOptions = function() {
|
|
41
|
+
return new Options();
|
|
42
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js-beautify",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.9",
|
|
4
4
|
"description": "beautifier.io for node",
|
|
5
5
|
"main": "js/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -45,8 +45,9 @@
|
|
|
45
45
|
],
|
|
46
46
|
"license": "MIT",
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"config-chain": "
|
|
49
|
-
"editorconfig": "^0.15.
|
|
48
|
+
"config-chain": "^1.1.12",
|
|
49
|
+
"editorconfig": "^0.15.2",
|
|
50
|
+
"glob": "^7.1.3",
|
|
50
51
|
"mkdirp": "~0.5.0",
|
|
51
52
|
"nopt": "~4.0.1"
|
|
52
53
|
},
|
|
@@ -54,10 +55,10 @@
|
|
|
54
55
|
"benchmark": "^2.1.4",
|
|
55
56
|
"jshint": "^2.9.6",
|
|
56
57
|
"mocha": "^5.2.0",
|
|
57
|
-
"mustache": "^
|
|
58
|
-
"node-static": "^0.7.
|
|
58
|
+
"mustache": "^3.0.1",
|
|
59
|
+
"node-static": "^0.7.11",
|
|
59
60
|
"requirejs": "^2.3.6",
|
|
60
|
-
"webpack": "^4.
|
|
61
|
-
"webpack-command": "^0.4.
|
|
61
|
+
"webpack": "^4.26.0",
|
|
62
|
+
"webpack-command": "^0.4.2"
|
|
62
63
|
}
|
|
63
64
|
}
|