js-beautify 1.9.0-beta2 → 1.9.0
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 +162 -48
- package/README.md +10 -10
- package/js/lib/beautifier.js +685 -382
- package/js/lib/beautifier.min.js +1 -1
- package/js/lib/beautify-css.js +75 -35
- package/js/lib/beautify-html.js +565 -285
- package/js/lib/beautify.js +584 -140
- package/js/src/core/directives.js +2 -2
- package/js/src/core/inputscanner.js +58 -18
- package/js/src/core/output.js +3 -6
- package/js/src/core/pattern.js +94 -0
- package/js/src/core/templatablepattern.js +179 -0
- package/js/src/core/tokenizer.js +7 -22
- package/js/src/core/whitespacepattern.js +105 -0
- package/js/src/html/beautifier.js +34 -24
- package/js/src/html/tokenizer.js +48 -32
- package/js/src/javascript/acorn.js +4 -3
- package/js/src/javascript/beautifier.js +5 -6
- package/js/src/javascript/tokenizer.js +105 -82
- package/package.json +3 -3
- package/js/src/html/templatablereader.js +0 -160
package/js/lib/beautify-css.js
CHANGED
|
@@ -149,7 +149,7 @@ var legacy_beautify_css =
|
|
|
149
149
|
/******/
|
|
150
150
|
/******/
|
|
151
151
|
/******/ // Load entry module and return exports
|
|
152
|
-
/******/ return __webpack_require__(__webpack_require__.s =
|
|
152
|
+
/******/ return __webpack_require__(__webpack_require__.s = 15);
|
|
153
153
|
/******/ })
|
|
154
154
|
/************************************************************************/
|
|
155
155
|
/******/ ([
|
|
@@ -282,14 +282,11 @@ OutputLine.prototype.last = function() {
|
|
|
282
282
|
|
|
283
283
|
OutputLine.prototype.push = function(item) {
|
|
284
284
|
this.__items.push(item);
|
|
285
|
-
this.__character_count += item.length;
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
OutputLine.prototype.push_raw = function(item) {
|
|
289
|
-
this.push(item);
|
|
290
285
|
var last_newline_index = item.lastIndexOf('\n');
|
|
291
286
|
if (last_newline_index !== -1) {
|
|
292
287
|
this.__character_count = item.length - last_newline_index;
|
|
288
|
+
} else {
|
|
289
|
+
this.__character_count += item.length;
|
|
293
290
|
}
|
|
294
291
|
};
|
|
295
292
|
|
|
@@ -502,7 +499,7 @@ Output.prototype.add_raw_token = function(token) {
|
|
|
502
499
|
}
|
|
503
500
|
this.current_line.set_indent(-1);
|
|
504
501
|
this.current_line.push(token.whitespace_before);
|
|
505
|
-
this.current_line.
|
|
502
|
+
this.current_line.push(token.text);
|
|
506
503
|
this.space_before_token = false;
|
|
507
504
|
this.non_breaking_space = false;
|
|
508
505
|
this.previous_token_wrapped = false;
|
|
@@ -811,6 +808,8 @@ module.exports.mergeOpts = _mergeOpts;
|
|
|
811
808
|
|
|
812
809
|
|
|
813
810
|
|
|
811
|
+
var regexp_has_sticky = RegExp.prototype.hasOwnProperty('sticky');
|
|
812
|
+
|
|
814
813
|
function InputScanner(input_string) {
|
|
815
814
|
this.__input = input_string || '';
|
|
816
815
|
this.__input_length = this.__input.length;
|
|
@@ -850,14 +849,32 @@ InputScanner.prototype.peek = function(index) {
|
|
|
850
849
|
return val;
|
|
851
850
|
};
|
|
852
851
|
|
|
852
|
+
// This is a JavaScript only helper function (not in python)
|
|
853
|
+
// Javascript doesn't have a match method
|
|
854
|
+
// and not all implementation support "sticky" flag.
|
|
855
|
+
// If they do not support sticky then both this.match() and this.test() method
|
|
856
|
+
// must get the match and check the index of the match.
|
|
857
|
+
// If sticky is supported and set, this method will use it.
|
|
858
|
+
// Otherwise it will check that global is set, and fall back to the slower method.
|
|
859
|
+
InputScanner.prototype.__match = function(pattern, index) {
|
|
860
|
+
pattern.lastIndex = index;
|
|
861
|
+
var pattern_match = pattern.exec(this.__input);
|
|
862
|
+
|
|
863
|
+
if (pattern_match && !(regexp_has_sticky && pattern.sticky)) {
|
|
864
|
+
if (pattern_match.index !== index) {
|
|
865
|
+
pattern_match = null;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
return pattern_match;
|
|
870
|
+
};
|
|
871
|
+
|
|
853
872
|
InputScanner.prototype.test = function(pattern, index) {
|
|
854
873
|
index = index || 0;
|
|
855
874
|
index += this.__position;
|
|
856
|
-
pattern.lastIndex = index;
|
|
857
875
|
|
|
858
876
|
if (index >= 0 && index < this.__input_length) {
|
|
859
|
-
|
|
860
|
-
return pattern_match && pattern_match.index === index;
|
|
877
|
+
return !!this.__match(pattern, index);
|
|
861
878
|
} else {
|
|
862
879
|
return false;
|
|
863
880
|
}
|
|
@@ -871,9 +888,8 @@ InputScanner.prototype.testChar = function(pattern, index) {
|
|
|
871
888
|
};
|
|
872
889
|
|
|
873
890
|
InputScanner.prototype.match = function(pattern) {
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
if (pattern_match && pattern_match.index === this.__position) {
|
|
891
|
+
var pattern_match = this.__match(pattern, this.__position);
|
|
892
|
+
if (pattern_match) {
|
|
877
893
|
this.__position += pattern_match[0].length;
|
|
878
894
|
} else {
|
|
879
895
|
pattern_match = null;
|
|
@@ -881,28 +897,30 @@ InputScanner.prototype.match = function(pattern) {
|
|
|
881
897
|
return pattern_match;
|
|
882
898
|
};
|
|
883
899
|
|
|
884
|
-
InputScanner.prototype.read = function(
|
|
900
|
+
InputScanner.prototype.read = function(starting_pattern, until_pattern, until_after) {
|
|
885
901
|
var val = '';
|
|
886
|
-
var match
|
|
887
|
-
if (
|
|
888
|
-
|
|
889
|
-
if (
|
|
890
|
-
val +=
|
|
902
|
+
var match;
|
|
903
|
+
if (starting_pattern) {
|
|
904
|
+
match = this.match(starting_pattern);
|
|
905
|
+
if (match) {
|
|
906
|
+
val += match[0];
|
|
891
907
|
}
|
|
892
908
|
}
|
|
909
|
+
if (until_pattern && (match || !starting_pattern)) {
|
|
910
|
+
val += this.readUntil(until_pattern, until_after);
|
|
911
|
+
}
|
|
893
912
|
return val;
|
|
894
913
|
};
|
|
895
914
|
|
|
896
|
-
InputScanner.prototype.readUntil = function(pattern,
|
|
915
|
+
InputScanner.prototype.readUntil = function(pattern, until_after) {
|
|
897
916
|
var val = '';
|
|
898
917
|
var match_index = this.__position;
|
|
899
918
|
pattern.lastIndex = this.__position;
|
|
900
919
|
var pattern_match = pattern.exec(this.__input);
|
|
901
920
|
if (pattern_match) {
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
match_index = pattern_match.index;
|
|
921
|
+
match_index = pattern_match.index;
|
|
922
|
+
if (until_after) {
|
|
923
|
+
match_index += pattern_match[0].length;
|
|
906
924
|
}
|
|
907
925
|
} else {
|
|
908
926
|
match_index = this.__input_length;
|
|
@@ -917,6 +935,26 @@ InputScanner.prototype.readUntilAfter = function(pattern) {
|
|
|
917
935
|
return this.readUntil(pattern, true);
|
|
918
936
|
};
|
|
919
937
|
|
|
938
|
+
InputScanner.prototype.get_regexp = function(pattern, match_from) {
|
|
939
|
+
var result = null;
|
|
940
|
+
var flags = 'g';
|
|
941
|
+
if (match_from && regexp_has_sticky) {
|
|
942
|
+
flags = 'y';
|
|
943
|
+
}
|
|
944
|
+
// strings are converted to regexp
|
|
945
|
+
if (typeof pattern === "string" && pattern !== '') {
|
|
946
|
+
// result = new RegExp(pattern.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), flags);
|
|
947
|
+
result = new RegExp(pattern, flags);
|
|
948
|
+
} else if (pattern) {
|
|
949
|
+
result = new RegExp(pattern.source, flags);
|
|
950
|
+
}
|
|
951
|
+
return result;
|
|
952
|
+
};
|
|
953
|
+
|
|
954
|
+
InputScanner.prototype.get_literal_regexp = function(literal_string) {
|
|
955
|
+
return RegExp(literal_string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));
|
|
956
|
+
};
|
|
957
|
+
|
|
920
958
|
/* css beautifier legacy helpers */
|
|
921
959
|
InputScanner.prototype.peekUntilAfter = function(pattern) {
|
|
922
960
|
var start = this.__position;
|
|
@@ -931,14 +969,15 @@ InputScanner.prototype.lookBack = function(testVal) {
|
|
|
931
969
|
.toLowerCase() === testVal;
|
|
932
970
|
};
|
|
933
971
|
|
|
934
|
-
|
|
935
972
|
module.exports.InputScanner = InputScanner;
|
|
936
973
|
|
|
937
974
|
|
|
938
975
|
/***/ }),
|
|
939
976
|
/* 9 */,
|
|
940
977
|
/* 10 */,
|
|
941
|
-
/* 11
|
|
978
|
+
/* 11 */,
|
|
979
|
+
/* 12 */,
|
|
980
|
+
/* 13 */
|
|
942
981
|
/***/ (function(module, exports, __webpack_require__) {
|
|
943
982
|
|
|
944
983
|
"use strict";
|
|
@@ -978,7 +1017,7 @@ function Directives(start_block_pattern, end_block_pattern) {
|
|
|
978
1017
|
this.__directives_block_pattern = new RegExp(start_block_pattern + / beautify( \w+[:]\w+)+ /.source + end_block_pattern, 'g');
|
|
979
1018
|
this.__directive_pattern = / (\w+)[:](\w+)/g;
|
|
980
1019
|
|
|
981
|
-
this.__directives_end_ignore_pattern = new RegExp(
|
|
1020
|
+
this.__directives_end_ignore_pattern = new RegExp(start_block_pattern + /\sbeautify\signore:end\s/.source + end_block_pattern, 'g');
|
|
982
1021
|
}
|
|
983
1022
|
|
|
984
1023
|
Directives.prototype.get_directives = function(text) {
|
|
@@ -999,7 +1038,7 @@ Directives.prototype.get_directives = function(text) {
|
|
|
999
1038
|
};
|
|
1000
1039
|
|
|
1001
1040
|
Directives.prototype.readIgnored = function(input) {
|
|
1002
|
-
return input.
|
|
1041
|
+
return input.readUntilAfter(this.__directives_end_ignore_pattern);
|
|
1003
1042
|
};
|
|
1004
1043
|
|
|
1005
1044
|
|
|
@@ -1007,7 +1046,8 @@ module.exports.Directives = Directives;
|
|
|
1007
1046
|
|
|
1008
1047
|
|
|
1009
1048
|
/***/ }),
|
|
1010
|
-
/*
|
|
1049
|
+
/* 14 */,
|
|
1050
|
+
/* 15 */
|
|
1011
1051
|
/***/ (function(module, exports, __webpack_require__) {
|
|
1012
1052
|
|
|
1013
1053
|
"use strict";
|
|
@@ -1041,8 +1081,8 @@ module.exports.Directives = Directives;
|
|
|
1041
1081
|
|
|
1042
1082
|
|
|
1043
1083
|
|
|
1044
|
-
var Beautifier = __webpack_require__(
|
|
1045
|
-
Options = __webpack_require__(
|
|
1084
|
+
var Beautifier = __webpack_require__(16).Beautifier,
|
|
1085
|
+
Options = __webpack_require__(17).Options;
|
|
1046
1086
|
|
|
1047
1087
|
function css_beautify(source_text, options) {
|
|
1048
1088
|
var beautifier = new Beautifier(source_text, options);
|
|
@@ -1056,7 +1096,7 @@ module.exports.defaultOptions = function() {
|
|
|
1056
1096
|
|
|
1057
1097
|
|
|
1058
1098
|
/***/ }),
|
|
1059
|
-
/*
|
|
1099
|
+
/* 16 */
|
|
1060
1100
|
/***/ (function(module, exports, __webpack_require__) {
|
|
1061
1101
|
|
|
1062
1102
|
"use strict";
|
|
@@ -1090,10 +1130,10 @@ module.exports.defaultOptions = function() {
|
|
|
1090
1130
|
|
|
1091
1131
|
|
|
1092
1132
|
|
|
1093
|
-
var Options = __webpack_require__(
|
|
1133
|
+
var Options = __webpack_require__(17).Options;
|
|
1094
1134
|
var Output = __webpack_require__(2).Output;
|
|
1095
1135
|
var InputScanner = __webpack_require__(8).InputScanner;
|
|
1096
|
-
var Directives = __webpack_require__(
|
|
1136
|
+
var Directives = __webpack_require__(13).Directives;
|
|
1097
1137
|
|
|
1098
1138
|
var directives_core = new Directives(/\/\*/, /\*\//);
|
|
1099
1139
|
|
|
@@ -1515,7 +1555,7 @@ module.exports.Beautifier = Beautifier;
|
|
|
1515
1555
|
|
|
1516
1556
|
|
|
1517
1557
|
/***/ }),
|
|
1518
|
-
/*
|
|
1558
|
+
/* 17 */
|
|
1519
1559
|
/***/ (function(module, exports, __webpack_require__) {
|
|
1520
1560
|
|
|
1521
1561
|
"use strict";
|