Skip to content

Commit

Permalink
Release: 1.8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Sep 4, 2018
1 parent 8f827c7 commit b8d4f5c
Show file tree
Hide file tree
Showing 7 changed files with 656 additions and 614 deletions.
513 changes: 258 additions & 255 deletions js/lib/beautifier.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/lib/beautifier.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/lib/beautifier.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/lib/beautifier.min.js.map

Large diffs are not rendered by default.

72 changes: 42 additions & 30 deletions js/lib/beautify-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,24 @@ IndentCache.prototype.get_level_string = function(level) {
};


function Output(indent_string, baseIndentString) {
function Output(options, baseIndentString) {
var indent_string = options.indent_char;
if (options.indent_size > 1) {
indent_string = new Array(options.indent_size + 1).join(options.indent_char);
}

// Set to null to continue support for auto detection of base indent level.
baseIndentString = baseIndentString || '';
if (options.indent_level > 0) {
baseIndentString = new Array(options.indent_level + 1).join(indent_string);
}

this.__indent_cache = new IndentCache(baseIndentString, indent_string);
this.__alignment_cache = new IndentCache('', ' ');
this.baseIndentLength = baseIndentString.length;
this.indent_length = indent_string.length;
this.raw = false;
this._end_with_newline = options.end_with_newline;

this.__lines = [];
this.previous_line = null;
Expand Down Expand Up @@ -359,10 +370,10 @@ Output.prototype.add_new_line = function(force_newline) {
return true;
};

Output.prototype.get_code = function(end_with_newline, eol) {
Output.prototype.get_code = function(eol) {
var sweet_code = this.__lines.join('\n').replace(/[\r\n\t ]+$/, '');

if (end_with_newline) {
if (this._end_with_newline) {
sweet_code += '\n';
}

Expand Down Expand Up @@ -461,7 +472,8 @@ module.exports.Output = Output;
/***/ }),
/* 3 */,
/* 4 */,
/* 5 */
/* 5 */,
/* 6 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
Expand Down Expand Up @@ -509,7 +521,7 @@ function Options(options, merge_child_field) {
this.indent_level = this._get_number('indent_level');

this.preserve_newlines = this._get_boolean('preserve_newlines', true);
this.max_preserve_newlines = this.max_preserve_newlines = this._get_number('max_preserve_newlines', 32786);
this.max_preserve_newlines = this._get_number('max_preserve_newlines', 32786);
if (!this.preserve_newlines) {
this.max_preserve_newlines = 0;
}
Expand All @@ -520,16 +532,6 @@ function Options(options, merge_child_field) {
this.indent_size = 1;
}

this.indent_string = this.indent_char;
if (this.indent_size > 1) {
this.indent_string = new Array(this.indent_size + 1).join(this.indent_char);
}
// Set to null to continue support for auto detection of base indent level.
this.base_indent_string = null;
if (this.indent_level > 0) {
this.base_indent_string = new Array(this.indent_level + 1).join(this.indent_string);
}

// Backwards compat with 1.3.x
this.wrap_line_length = this._get_number('wrap_line_length', this._get_number('max_char'));

Expand Down Expand Up @@ -577,6 +579,22 @@ Options.prototype._get_number = function(name, default_value) {
};

Options.prototype._get_selection = function(name, selection_list, default_value) {
var result = this._get_selection_list(name, selection_list, default_value);
if (result.length !== 1) {
throw new Error(
"Invalid Option Value: The option '" + name + "' can only be one of the following values:\n" +
selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
}

return result[0];
};


Options.prototype._get_selection_list = function(name, selection_list, default_value) {
if (!selection_list || selection_list.length === 0) {
throw new Error("Selection list cannot be empty.");
}

default_value = default_value || [selection_list[0]];
if (!this._is_valid_selection(default_value, selection_list)) {
throw new Error("Invalid Default Value!");
Expand All @@ -585,7 +603,8 @@ Options.prototype._get_selection = function(name, selection_list, default_value)
var result = this._get_array(name, default_value);
if (!this._is_valid_selection(result, selection_list)) {
throw new Error(
"Invalid Option Value: The option '" + name + "' must be one of the following values\n" + selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
"Invalid Option Value: The option '" + name + "' can contain only the following values:\n" +
selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
}

return result;
Expand Down Expand Up @@ -638,8 +657,8 @@ module.exports.normalizeOpts = _normalizeOpts;
module.exports.mergeOpts = _mergeOpts;

/***/ }),
/* 6 */,
/* 7 */
/* 7 */,
/* 8 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
Expand Down Expand Up @@ -793,7 +812,6 @@ InputScanner.prototype.lookBack = function(testVal) {
module.exports.InputScanner = InputScanner;

/***/ }),
/* 8 */,
/* 9 */,
/* 10 */,
/* 11 */,
Expand Down Expand Up @@ -877,7 +895,7 @@ module.exports = css_beautify;

var Options = __webpack_require__(14).Options;
var Output = __webpack_require__(2).Output;
var InputScanner = __webpack_require__(7).InputScanner;
var InputScanner = __webpack_require__(8).InputScanner;

var lineBreak = /\r\n|[\r\n]/;
var allLineBreaks = /\r\n|[\r\n]/g;
Expand Down Expand Up @@ -1020,15 +1038,9 @@ Beautifier.prototype.beautify = function() {
source_text = source_text.replace(allLineBreaks, '\n');

// reset
var baseIndentString = '';
if (this._options.base_indent_string) {
baseIndentString = this._options.base_indent_string;
} else {
var match = source_text.match(/^[\t ]*/);
baseIndentString = match[0];
}
var baseIndentString = source_text.match(/^[\t ]*/)[0];

this._output = new Output(this._options.indent_string, baseIndentString);
this._output = new Output(this._options, baseIndentString);
this._input = new InputScanner(source_text);
this._indentLevel = 0;
this._nestedLevel = 0;
Expand Down Expand Up @@ -1283,7 +1295,7 @@ Beautifier.prototype.beautify = function() {
}
}

var sweetCode = this._output.get_code(this._options.end_with_newline, eol);
var sweetCode = this._output.get_code(eol);

return sweetCode;
};
Expand Down Expand Up @@ -1325,7 +1337,7 @@ module.exports.Beautifier = Beautifier;



var BaseOptions = __webpack_require__(5).Options;
var BaseOptions = __webpack_require__(6).Options;

function Options(options) {
BaseOptions.call(this, options, 'css');
Expand Down
Loading

0 comments on commit b8d4f5c

Please sign in to comment.