Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Originally converted to javascript by Vital, <vital76@gmail.com> "End braces on own line" added by Chris J. Shull, <chrisjshull@gmail.com> Parsing improvements for brace-less statements by Liam Newman <bitwiseman@beautifier.io>
The options are: indent_size (default 4) - indentation size, indent_char (default space) - character to indent with, preserve_newlines (default true) - whether existing line breaks should be preserved, max_preserve_newlines (default unlimited) - maximum number of line breaks to be preserved in one chunk,
jslint_happy (default false) - if true, then jslint-stricter mode is enforced.
jslint_happy !jslint_happy --------------------------------- function () function()
switch () { switch() { case 1: case 1: break; break; } }
space_after_anon_function (default false) - should the space before an anonymous function's parens be added, "function()" vs "function ()", NOTE: This option is overriden by jslint_happy (i.e. if jslint_happy is true, space_after_anon_function is true by design)
brace_style (default "collapse") - "collapse" | "expand" | "end-expand" | "none" | any of the former + ",preserve-inline" put braces on the same line as control statements (default), or put braces on own line (Allman / ANSI style), or just put end braces on own line, or attempt to keep them where they are. preserve-inline will try to preserve inline blocks of curly braces
space_before_conditional (default true) - should the space before conditional statement be added, "if(true)" vs "if (true)",
unescape_strings (default false) - should printable characters in strings encoded in \xNN notation be unescaped, "example" vs "\x65\x78\x61\x6d\x70\x6c\x65"
wrap_line_length (default unlimited) - lines should wrap at next opportunity after this number of characters. NOTE: This is not a hard limit. Lines will continue until a point where a newline would be preserved if it were present.
end_with_newline (default false) - end output with a newline
/* GENERATED_BUILD_OUTPUT */ var legacy_beautify_js = /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports, __webpack_require__) {
"use strict"; /*jshint node:true */ /*
The MIT License (MIT)
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var Beautifier = __webpack_require__(1).Beautifier,
Options = __webpack_require__(5).Options;
function js_beautify(js_source_text, options) { var beautifier = new Beautifier(js_source_text, options); return beautifier.beautify();
}
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var Output = __webpack_require__(2).Output; var Token = __webpack_require__(3).Token; var acorn = __webpack_require__(4); var Options = __webpack_require__(5).Options; var Tokenizer = __webpack_require__(7).Tokenizer; var line_starters = __webpack_require__(7).line_starters; var positionable_operators = __webpack_require__(7).positionable_operators; var TOKEN = __webpack_require__(7).TOKEN;
function in_array(what, arr) { return arr.indexOf(what) !== -1;
}
function ltrim(s) { return s.replace(/^\s+/g, '');
}
function generateMapFromStrings(list) { var result = {}; for (var x = 0; x < list.length; x++) { // make the mapped names underscored instead of dash
result[list[x].replace(/-/g, '_')] = list[x];
} return result;
}
function reserved_array(token, words) { return token && token.type === TOKEN.RESERVED && in_array(token.text, words);
} // Unsure of what they mean, but they work. Worth cleaning up in future. var special_words = ['case', 'return', 'do', 'if', 'throw', 'else', 'await', 'break', 'continue', 'async'];
var validPositionValues = ['before-newline', 'after-newline', 'preserve-newline'];
// Generate map from array var OPERATOR_POSITION = generateMapFromStrings(validPositionValues);
var OPERATOR_POSITION_BEFORE_OR_PRESERVE = [OPERATOR_POSITION.before_newline, OPERATOR_POSITION.preserve_newline];
function remove_redundant_indentation(output, frame) { // This implementation is effective but has some issues: // - can cause line wrap to happen too soon due to indent removal // after wrap points are calculated // These issues are minor compared to ugly indentation.
// remove one indent from each line inside this section
output.remove_indent(frame.start_line_index);
}
// we could use just string.split, but // IE doesn't like returning empty strings function split_linebreaks(s) { //return s.split(/\x0d\x0a|\x0a/);
s = s.replace(acorn.allLineBreaks, '\n'); var out = [],
idx = s.indexOf("\n"); while (idx !== -1) {
out.push(s.substring(0, idx));
s = s.substring(idx + 1);
idx = s.indexOf("\n");
} if (s.length) {
out.push(s);
} return out;
}
function is_array(mode) { return mode === MODE.ArrayLiteral;
}
function is_expression(mode) { return in_array(mode, [MODE.Expression, MODE.ForInitializer, MODE.Conditional]);
}
function all_lines_start_with(lines, c) { for (var i = 0; i < lines.length; i++) { var line = lines[i].trim(); if (line.charAt(0) !== c) { returnfalse;
}
} returntrue;
}
function each_line_matches_indent(lines, indent) { var i = 0,
len = lines.length,
line; for (; i < len; i++) {
line = lines[i]; // allow empty lines to pass through if (line && line.indexOf(indent) !== 0) { returnfalse;
}
} returntrue;
}
this._flag_store = null; this._options = new Options(options);
}
Beautifier.prototype.create_flags = function(flags_base, mode) { var next_indent_level = 0; if (flags_base) {
next_indent_level = flags_base.indentation_level; if (!this._output.just_added_newline() &&
flags_base.line_indent_level > next_indent_level) {
next_indent_level = flags_base.line_indent_level;
}
}
var next_flags = {
mode: mode,
parent: flags_base,
last_token: flags_base ? flags_base.last_token : new Token(TOKEN.START_BLOCK, ''), // last token text
last_word: flags_base ? flags_base.last_word : '', // last TOKEN.WORD passed
declaration_statement: false,
declaration_assignment: false,
multiline_frame: false,
inline_frame: false,
if_block: false,
else_block: false,
do_block: false,
do_while: false,
import_block: false,
in_case_statement: false, // switch(..){ INSIDE HERE }
in_case: false, // we're on the exact line with "case 0:"
case_body: false, // the indented case-action block
indentation_level: next_indent_level,
alignment: 0,
line_indent_level: flags_base ? flags_base.line_indent_level : next_indent_level,
start_line_index: this._output.get_line_number(),
ternary_depth: 0
}; return next_flags;
};
Beautifier.prototype._reset = function(source_text) { var baseIndentString = source_text.match(/^[\t ]*/)[0];
this._last_last_text = ''; // pre-last token text this._output = new Output(this._options, baseIndentString);
// If testing the ignore directive, start with output disable set to true this._output.raw = this._options.test_output_raw;
// Stack of parsing/formatting states, including MODE. // We tokenize, parse, and output in an almost purely a forward-only stream of token input // and formatted output. This makes the beautifier less accurate than full parsers // but also far more tolerant of syntax errors. // // For example, the default mode is MODE.BlockStatement. If we see a '{' we push a new frame of type // MODE.BlockStatement on the the stack, even though it could be object literal. If we later // encounter a ":", we'll switch to to MODE.ObjectLiteral. If we then see a ";", // most full parsers would die, but the beautifier gracefully falls back to // MODE.BlockStatement and continues on. this._flag_store = []; this.set_mode(MODE.BlockStatement); var tokenizer = new Tokenizer(source_text, this._options); this._tokens = tokenizer.tokenize(); return source_text;
};
Beautifier.prototype.beautify = function() { // if disabled, return the input unchanged. if (this._options.disabled) { returnthis._source_text;
}
var sweet_code; var source_text = this._reset(this._source_text);
var eol = this._options.eol; if (this._options.eol === 'auto') {
eol = '\n'; if (source_text && acorn.lineBreak.test(source_text || '')) {
eol = source_text.match(acorn.lineBreak)[0];
}
}
var current_token = this._tokens.next(); while (current_token) { this.handle_token(current_token);
Beautifier.prototype.handle_whitespace_and_comments = function(current_token, preserve_statement_flags) { var newlines = current_token.newlines; var keep_whitespace = this._options.keep_array_indentation && is_array(this._flags.mode);
if (current_token.comments_before) { var comment_token = current_token.comments_before.next(); while (comment_token) { // The cleanest handling of inline comments is to treat them as though they aren't there. // Just continue formatting and the behavior should be logical. // Also ignore unknown tokens. Again, this should result in better behavior. this.handle_whitespace_and_comments(comment_token, preserve_statement_flags); this.handle_token(comment_token, preserve_statement_flags);
comment_token = current_token.comments_before.next();
}
}
if (keep_whitespace) { for (var i = 0; i < newlines; i += 1) { this.print_newline(i > 0, preserve_statement_flags);
}
} else { if (this._options.max_preserve_newlines && newlines > this._options.max_preserve_newlines) {
newlines = this._options.max_preserve_newlines;
}
if (this._options.preserve_newlines) { if (newlines > 1) { this.print_newline(false, preserve_statement_flags); for (var j = 1; j < newlines; j += 1) { this.print_newline(true, preserve_statement_flags);
}
}
}
}
};
var newline_restricted_tokens = ['async', 'break', 'continue', 'return', 'throw', 'yield'];
if (shouldPreserveOrForce) { this.print_newline(false, true);
} elseif (this._options.wrap_line_length) { if (reserved_array(this._flags.last_token, newline_restricted_tokens)) { // These tokens should never have a newline inserted // between them and the following expression. return;
} this._output.set_wrap_point();
}
};
Beautifier.prototype.print_token = function(current_token) { if (this._output.raw) { this._output.add_raw_token(current_token); return;
}
if (this._options.comma_first && current_token.previous && current_token.previous.type === TOKEN.COMMA && this._output.just_added_newline()) { if (this._output.previous_line.last() === ',') { var popped = this._output.previous_line.pop(); // if the comma was already at the start of the line, // pull back onto that line and reprint the indentation if (this._output.previous_line.is_empty()) { this._output.previous_line.push(popped); this._output.trim(true); this._output.current_line.pop(); this._output.trim();
}
// add the comma in front of the next token this.print_token_line_indentation(current_token); this._output.add_token(','); this._output.space_before_token = true;
}
}
// Issue #276: // If starting a new statement with [if, for, while, do], push to a new line. // if (a) if (b) if(c) d(); else e(); else f(); if (!this.start_of_object_property()) { this.allow_wrap_or_preserved_newline(current_token,
reserved_array(current_token, ['do', 'for', 'if', 'while']));
} returntrue;
} returnfalse;
};
Beautifier.prototype.handle_start_expr = function(current_token) { // The conditional starts the statement if appropriate. if (!this.start_of_statement(current_token)) { this.handle_whitespace_and_comments(current_token);
}
var next_mode = MODE.Expression; if (current_token.text === '[') {
if (this._flags.last_token.type === TOKEN.WORD || this._flags.last_token.text === ')') { // this is array index specifier, break immediately // a[x], fn()[x] if (reserved_array(this._flags.last_token, line_starters)) { this._output.space_before_token = true;
} this.print_token(current_token); this.set_mode(next_mode); this.indent(); if (this._options.space_in_paren) { this._output.space_before_token = true;
} return;
}
next_mode = MODE.ArrayLiteral; if (is_array(this._flags.mode)) { if (this._flags.last_token.text === '[' ||
(this._flags.last_token.text === ',' && (this._last_last_text === ']' || this._last_last_text === '}'))) { // ], [ goes to new line // }, [ goes to new line if (!this._options.keep_array_indentation) { this.print_newline();
}
}
}
if (!in_array(this._flags.last_token.type, [TOKEN.START_EXPR, TOKEN.END_EXPR, TOKEN.WORD, TOKEN.OPERATOR])) { this._output.space_before_token = true;
}
} else { if (this._flags.last_token.type === TOKEN.RESERVED) { if (this._flags.last_token.text === 'for') { this._output.space_before_token = this._options.space_before_conditional;
next_mode = MODE.ForInitializer;
} elseif (in_array(this._flags.last_token.text, ['if', 'while'])) { this._output.space_before_token = this._options.space_before_conditional;
next_mode = MODE.Conditional;
} elseif (in_array(this._flags.last_word, ['await', 'async'])) { // Should be a space between await and an IIFE, or async and an arrow function this._output.space_before_token = true;
} elseif (this._flags.last_token.text === 'import' && current_token.whitespace_before === '') { this._output.space_before_token = false;
} elseif (in_array(this._flags.last_token.text, line_starters) || this._flags.last_token.text === 'catch') { this._output.space_before_token = true;
}
} elseif (this._flags.last_token.type === TOKEN.EQUALS || this._flags.last_token.type === TOKEN.OPERATOR) { // Support of this kind of newline preservation. // a = (b && // (c || d)); if (!this.start_of_object_property()) { this.allow_wrap_or_preserved_newline(current_token);
}
} elseif (this._flags.last_token.type === TOKEN.WORD) { this._output.space_before_token = false;
// function name() vs function name () // function* name() vs function* name () // async name() vs async name () // In ES6, you can also define the method properties of an object // var obj = {a: function() {}} // It can be abbreviated // var obj = {a() {}} // var obj = { a() {}} vs var obj = { a () {}} // var obj = { * a() {}} vs var obj = { * a () {}} var peek_back_two = this._tokens.peek(-3); if (this._options.space_after_named_function && peek_back_two) { // peek starts at next character so -1 is current token var peek_back_three = this._tokens.peek(-4); if (reserved_array(peek_back_two, ['async', 'function']) ||
(peek_back_two.text === '*' && reserved_array(peek_back_three, ['async', 'function']))) { this._output.space_before_token = true;
} elseif (this._flags.mode === MODE.ObjectLiteral) { if ((peek_back_two.text === '{' || peek_back_two.text === ',') ||
(peek_back_two.text === '*' && (peek_back_three.text === '{' || peek_back_three.text === ','))) { this._output.space_before_token = true;
}
}
}
} else { // Support preserving wrapped arrow function expressions // a.b('c', // () => d.e // ) this.allow_wrap_or_preserved_newline(current_token);
}
// function() vs function () // yield*() vs yield* () // function*() vs function* () if ((this._flags.last_token.type === TOKEN.RESERVED && (this._flags.last_word === 'function' || this._flags.last_word === 'typeof')) ||
(this._flags.last_token.text === '*' &&
(in_array(this._last_last_text, ['function', 'yield']) ||
(this._flags.mode === MODE.ObjectLiteral && in_array(this._last_last_text, ['{', ',']))))) { this._output.space_before_token = this._options.space_after_anon_function;
}
}
if (this._flags.last_token.text === ';' || this._flags.last_token.type === TOKEN.START_BLOCK) { this.print_newline();
} elseif (this._flags.last_token.type === TOKEN.END_EXPR || this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.END_BLOCK || this._flags.last_token.text === '.' || this._flags.last_token.type === TOKEN.COMMA) { // do nothing on (( and )( and ][ and ]( and .( // TODO: Consider whether forcing this is required. Review failing tests when removed. this.allow_wrap_or_preserved_newline(current_token, current_token.newlines);
}
this.print_token(current_token); this.set_mode(next_mode); if (this._options.space_in_paren) { this._output.space_before_token = true;
}
// In all cases, if we newline while inside an expression it should be indented. this.indent();
};
Beautifier.prototype.handle_end_expr = function(current_token) { // statements inside expressions are not valid syntax, but... // statements must all be closed when their container closes while (this._flags.mode === MODE.Statement) { this.restore_mode();
}
// Check if this is should be treated as a ObjectLiteral var next_token = this._tokens.peek(); var second_token = this._tokens.peek(1); if (this._flags.last_word === 'switch' && this._flags.last_token.type === TOKEN.END_EXPR) { this.set_mode(MODE.BlockStatement); this._flags.in_case_statement = true;
} elseif (this._flags.case_body) { this.set_mode(MODE.BlockStatement);
} elseif (second_token && (
(in_array(second_token.text, [':', ',']) && in_array(next_token.type, [TOKEN.STRING, TOKEN.WORD, TOKEN.RESERVED])) ||
(in_array(next_token.text, ['get', 'set', '...']) && in_array(second_token.type, [TOKEN.WORD, TOKEN.RESERVED]))
)) { // We don't support TypeScript,but we didn't break it for a very long time. // We'll try to keep not breaking it. if (!in_array(this._last_last_text, ['class', 'interface'])) { this.set_mode(MODE.ObjectLiteral);
} else { this.set_mode(MODE.BlockStatement);
}
} elseif (this._flags.last_token.type === TOKEN.OPERATOR && this._flags.last_token.text === '=>') { // arrow function: (param1, paramN) => { statements } this.set_mode(MODE.BlockStatement);
} elseif (in_array(this._flags.last_token.type, [TOKEN.EQUALS, TOKEN.START_EXPR, TOKEN.COMMA, TOKEN.OPERATOR]) ||
reserved_array(this._flags.last_token, ['return', 'throw', 'import', 'default'])
) { // Detecting shorthand function syntax is difficult by scanning forward, // so check the surrounding context. // If the block is being returned, imported, export default, passed as arg, // assigned with = or assigned in a nested object, treat as an ObjectLiteral. this.set_mode(MODE.ObjectLiteral);
} else { this.set_mode(MODE.BlockStatement);
}
var empty_braces = !next_token.comments_before && next_token.text === '}'; var empty_anonymous_function = empty_braces && this._flags.last_word === 'function' && this._flags.last_token.type === TOKEN.END_EXPR;
if (this._options.brace_preserve_inline) // check for inline, set inline_frame if so
{ // search forward for a newline wanted inside this block var index = 0; var check_token = null; this._flags.inline_frame = true; do {
index += 1;
check_token = this._tokens.peek(index - 1); if (check_token.newlines) { this._flags.inline_frame = false; break;
}
} while (check_token.type !== TOKEN.EOF &&
!(check_token.type === TOKEN.END_BLOCK && check_token.opened === current_token));
}
// Except for specific cases, open braces are followed by a new line. if (!empty_braces && !(this._options.brace_preserve_inline && this._flags.inline_frame)) { this.print_newline();
}
};
Beautifier.prototype.handle_end_block = function(current_token) { // statements must all be closed when their container closes this.handle_whitespace_and_comments(current_token);
while (this._flags.mode === MODE.Statement) { this.restore_mode();
}
var empty_braces = this._flags.last_token.type === TOKEN.START_BLOCK;
if (this._flags.inline_frame && !empty_braces) { // try inline_frame (only set if this._options.braces-preserve-inline) first this._output.space_before_token = true;
} elseif (this._options.brace_style === "expand") { if (!empty_braces) { this.print_newline();
}
} else { // skip {} if (!empty_braces) { if (is_array(this._flags.mode) && this._options.keep_array_indentation) { // we REALLY need a newline here, but newliner would skip that this._options.keep_array_indentation = false; this.print_newline(); this._options.keep_array_indentation = true;
if (this._flags.do_block && !this._flags.do_while) { if (reserved_word(current_token, 'while')) { // do {} ## while () this._output.space_before_token = true; this.print_token(current_token); this._output.space_before_token = true; this._flags.do_while = true; return;
} else { // do {} should always have while as the next word. // if we don't see the expected while, recover this.print_newline(); this._flags.do_block = false;
}
}
// if may be followed by else, or not // Bare/inline ifs are tricky // Need to unwind the modes correctly: if (a) if (b) c(); else d(); else e(); if (this._flags.if_block) { if (!this._flags.else_block && reserved_word(current_token, 'else')) { this._flags.else_block = true;
} else { while (this._flags.mode === MODE.Statement) { this.restore_mode();
} this._flags.if_block = false; this._flags.else_block = false;
}
}
if (this._flags.in_case_statement && reserved_array(current_token, ['case', 'default'])) { this.print_newline(); if (this._flags.last_token.type !== TOKEN.END_BLOCK && (this._flags.case_body || this._options.jslint_happy)) { // switch cases following one another this.deindent();
} this._flags.case_body = false;
Beautifier.prototype.handle_semicolon = function(current_token) { if (this.start_of_statement(current_token)) { // The conditional starts the statement if appropriate. // Semicolon can be the start (and end) of a statement this._output.space_before_token = false;
} else { this.handle_whitespace_and_comments(current_token);
}
var next_token = this._tokens.peek(); while (this._flags.mode === MODE.Statement &&
!(this._flags.if_block && reserved_word(next_token, 'else')) &&
!this._flags.do_block) { this.restore_mode();
}
// hacky but effective for the moment if (this._flags.import_block) { this._flags.import_block = false;
} this.print_token(current_token);
};
Beautifier.prototype.handle_string = function(current_token) { if (this.start_of_statement(current_token)) { // The conditional starts the statement if appropriate. // One difference - strings want at least a space before this._output.space_before_token = true;
} else { this.handle_whitespace_and_comments(current_token); if (this._flags.last_token.type === TOKEN.RESERVED || this._flags.last_token.type === TOKEN.WORD || this._flags.inline_frame) { this._output.space_before_token = true;
} elseif (this._flags.last_token.type === TOKEN.COMMA || this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.EQUALS || this._flags.last_token.type === TOKEN.OPERATOR) { if (!this.start_of_object_property()) { this.allow_wrap_or_preserved_newline(current_token);
}
} else { this.print_newline();
}
} this.print_token(current_token);
};
Beautifier.prototype.handle_equals = function(current_token) { if (this.start_of_statement(current_token)) { // The conditional starts the statement if appropriate.
} else { this.handle_whitespace_and_comments(current_token);
}
if (this._flags.declaration_statement) { // just got an '=' in a var-line, different formatting/line-breaking, etc will now be done this._flags.declaration_assignment = true;
} this._output.space_before_token = true; this.print_token(current_token); this._output.space_before_token = true;
};
this.print_token(current_token); this._output.space_before_token = true; if (this._flags.declaration_statement) { if (is_expression(this._flags.parent.mode)) { // do not break on comma, for(var a = 1, b = 2) this._flags.declaration_assignment = false;
}
if (this._flags.declaration_assignment) { this._flags.declaration_assignment = false; this.print_newline(false, true);
} elseif (this._options.comma_first) { // for comma-first, we want to allow a newline before the comma // to turn into a newline after the comma, which we will fixup later this.allow_wrap_or_preserved_newline(current_token);
}
} elseif (this._flags.mode === MODE.ObjectLiteral ||
(this._flags.mode === MODE.Statement && this._flags.parent.mode === MODE.ObjectLiteral)) { if (this._flags.mode === MODE.Statement) { this.restore_mode();
}
if (!this._flags.inline_frame) { this.print_newline();
}
} elseif (this._options.comma_first) { // EXPR or DO_BLOCK // for comma-first, we want to allow a newline before the comma // to turn into a newline after the comma, which we will fixup later this.allow_wrap_or_preserved_newline(current_token);
}
};
if (this.start_of_statement(current_token)) { // The conditional starts the statement if appropriate.
} else { var preserve_statement_flags = !isGeneratorAsterisk; this.handle_whitespace_and_comments(current_token, preserve_statement_flags);
}
if (reserved_array(this._flags.last_token, special_words)) { // "return" had a special handling in TK_WORD. Now we need to return the favor this._output.space_before_token = true; this.print_token(current_token); return;
}
// hack for actionscript's import .*; if (current_token.text === '*' && this._flags.last_token.type === TOKEN.DOT) { this.print_token(current_token); return;
}
if (current_token.text === '::') { // no spaces around exotic namespacing syntax operator this.print_token(current_token); return;
}
// Allow line wrapping between operators when operator_position is // set to before or preserve if (this._flags.last_token.type === TOKEN.OPERATOR && in_array(this._options.operator_position, OPERATOR_POSITION_BEFORE_OR_PRESERVE)) { this.allow_wrap_or_preserved_newline(current_token);
}
if (current_token.text === ':' && this._flags.in_case) { this.print_token(current_token);
var space_before = true; var space_after = true; var in_ternary = false; if (current_token.text === ':') { if (this._flags.ternary_depth === 0) { // Colon is invalid javascript outside of ternary and object, but do our best to guess what was meant.
space_before = false;
} else { this._flags.ternary_depth -= 1;
in_ternary = true;
}
} elseif (current_token.text === '?') { this._flags.ternary_depth += 1;
}
// let's handle the operator_position option prior to any conflicting logic if (!isUnary && !isGeneratorAsterisk && this._options.preserve_newlines && in_array(current_token.text, positionable_operators)) { var isColon = current_token.text === ':'; var isTernaryColon = (isColon && in_ternary); var isOtherColon = (isColon && !in_ternary);
switch (this._options.operator_position) { case OPERATOR_POSITION.before_newline: // if the current token is : and it's not a ternary statement then we set space_before to false this._output.space_before_token = !isOtherColon;
this.print_token(current_token);
if (!isColon || isTernaryColon) { this.allow_wrap_or_preserved_newline(current_token);
}
this._output.space_before_token = true; return;
case OPERATOR_POSITION.after_newline: // if the current token is anything but colon, or (via deduction) it's a colon and in a ternary statement, // then print a newline.
case OPERATOR_POSITION.preserve_newline: if (!isOtherColon) { this.allow_wrap_or_preserved_newline(current_token);
}
// if we just added a newline, or the current token is : and it's not a ternary statement, // then we set space_before to false
space_before = !(this._output.just_added_newline() || isOtherColon);
// http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1 // if there is a newline between -- or ++ and anything else we should preserve it. if (current_token.newlines && (current_token.text === '--' || current_token.text === '++')) { this.print_newline(false, true);
}
if (this._flags.last_token.text === ';' && is_expression(this._flags.mode)) { // for (;; ++i) // ^^^
space_before = true;
}
if (this._flags.last_token.type === TOKEN.RESERVED) {
space_before = true;
} elseif (this._flags.last_token.type === TOKEN.END_EXPR) {
space_before = !(this._flags.last_token.text === ']' && (current_token.text === '--' || current_token.text === '++'));
} elseif (this._flags.last_token.type === TOKEN.OPERATOR) { // a++ + ++b; // a - -b
space_before = in_array(current_token.text, ['--', '-', '++', '+']) && in_array(this._flags.last_token.text, ['--', '-', '++', '+']); // + and - are not unary when preceeded by -- or ++ operator // a-- + b // a * +b // a - -b if (in_array(current_token.text, ['+', '-']) && in_array(this._flags.last_token.text, ['--', '++'])) {
space_after = true;
}
}
Beautifier.prototype.handle_block_comment = function(current_token, preserve_statement_flags) { if (this._output.raw) { this._output.add_raw_token(current_token); if (current_token.directives && current_token.directives.preserve === 'end') { // If we're testing the raw output behavior, do not allow a directive to turn it off. this._output.raw = this._options.test_output_raw;
} return;
}
if (current_token.directives) { this.print_newline(false, preserve_statement_flags); this.print_token(current_token); if (current_token.directives.preserve === 'start') { this._output.raw = true;
} this.print_newline(false, true); return;
}
Beautifier.prototype.print_block_commment = function(current_token, preserve_statement_flags) { var lines = split_linebreaks(current_token.text); var j; // iterator for this case var javadoc = false; var starless = false; var lastIndent = current_token.whitespace_before; var lastIndentLength = lastIndent.length;
// block comment starts with a new line this.print_newline(false, preserve_statement_flags);
// first line always indented this.print_token_line_indentation(current_token); this._output.add_token(lines[0]); this.print_newline(false, preserve_statement_flags);
Beautifier.prototype.handle_dot = function(current_token) { if (this.start_of_statement(current_token)) { // The conditional starts the statement if appropriate.
} else { this.handle_whitespace_and_comments(current_token, true);
}
if (reserved_array(this._flags.last_token, special_words)) { this._output.space_before_token = false;
} else { // allow preserved newlines before dots in general // force newlines on dots after close paren when break_chained - for bar().baz() this.allow_wrap_or_preserved_newline(current_token, this._flags.last_token.text === ')' && this._options.break_chained_methods);
}
// Only unindent chained method dot if this dot starts a new line. // Otherwise the automatic extra indentation removal will handle the over indent if (this._options.unindent_chained_methods && this._output.just_added_newline()) { this.deindent();
}
"use strict"; /*jshint node:true */ /* The MIT License (MIT)
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction,
--> --------------------
--> maximum size reached
--> --------------------
Messung V0.5
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.