ocoge/lib/beautify.min.js

1 line
73 KiB
JavaScript
Raw Normal View History

!function(){!function(){"use strict";var i=[function(t,e,u){var i=u(1).Beautifier,n=u(5).Options;t.exports=function(t,e){return new i(t,e).beautify()},t.exports.defaultOptions=function(){return new n}},function(t,e,u){var i=u(2).Output,n=u(3).Token,o=u(4),_=u(5).Options,s=u(7).Tokenizer,r=u(7).line_starters,h=u(7).positionable_operators,p=u(7).TOKEN;function l(t,e){return-1!==e.indexOf(t)}function a(t,e){return t&&t.type===p.RESERVED&&t.text===e}function f(t,e){return t&&t.type===p.RESERVED&&l(t.text,e)}var c=["case","return","do","if","throw","else","await","break","continue","async"],d=function(t){for(var e={},u=0;u<t.length;u++)e[t[u].replace(/-/g,"_")]=t[u];return e}(["before-newline","after-newline","preserve-newline"]),b=[d.before_newline,d.preserve_newline],g="BlockStatement",k="Statement",m="ObjectLiteral",w="ArrayLiteral",y="ForInitializer",x="Conditional",v="Expression";function E(t,e){e.multiline_frame||e.mode===y||e.mode===x||t.remove_indent(e.start_line_index)}function R(t){return t===w}function O(t){return l(t,[v,y,x])}function T(t,e){e=e||{},this._source_text=t||"",this._output=null,this._tokens=null,this._last_last_text=null,this._flags=null,this._previous_flags=null,this._flag_store=null,this._options=new _(e)}T.prototype.create_flags=function(t,e){var u=0;return t&&(u=t.indentation_level,!this._output.just_added_newline()&&t.line_indent_level>u&&(u=t.line_indent_level)),{mode:e,parent:t,last_token:t?t.last_token:new n(p.START_BLOCK,""),last_word:t?t.last_word:"",declaration_statement:!1,declaration_assignment:!1,multiline_frame:!1,inline_frame:!1,if_block:!1,else_block:!1,class_start_block:!1,do_block:!1,do_while:!1,import_block:!1,in_case_statement:!1,in_case:!1,case_body:!1,case_block:!1,indentation_level:u,alignment:0,line_indent_level:t?t.line_indent_level:u,start_line_index:this._output.get_line_number(),ternary_depth:0}},T.prototype._reset=function(t){var e=t.match(/^[\t ]*/)[0],e=(this._last_last_text="",this._output=new i(this._options,e),this._output.raw=this._options.test_output_raw,this._flag_store=[],this.set_mode(g),new s(t,this._options));return this._tokens=e.tokenize(),t},T.prototype.beautify=function(){if(this._options.disabled)return this._source_text;for(var t=this._reset(this._source_text),e=this._options.eol,u=("auto"===this._options.eol&&(e="\n",t&&o.lineBreak.test(t||"")&&(e=t.match(o.lineBreak)[0])),this._tokens.next());u;)this.handle_token(u),this._last_last_text=this._flags.last_token.text,this._flags.last_token=u,u=this._tokens.next();return this._output.get_code(e)},T.prototype.handle_token=function(t,e){t.type===p.START_EXPR?this.handle_start_expr(t):t.type===p.END_EXPR?this.handle_end_expr(t):t.type===p.START_BLOCK?this.handle_start_block(t):t.type===p.END_BLOCK?this.handle_end_block(t):t.type===p.WORD||t.type===p.RESERVED?this.handle_word(t):t.type===p.SEMICOLON?this.handle_semicolon(t):t.type===p.STRING?this.handle_string(t):t.type===p.EQUALS?this.handle_equals(t):t.type===p.OPERATOR?this.handle_operator(t):t.type===p.COMMA?this.handle_comma(t):t.type===p.BLOCK_COMMENT?this.handle_block_comment(t,e):t.type===p.COMMENT?this.handle_comment(t,e):t.type===p.DOT?this.handle_dot(t):t.type===p.EOF?this.handle_eof(t):(t.type,p.UNKNOWN,this.handle_unknown(t,e))},T.prototype.handle_whitespace_and_comments=function(t,e){var u=t.newlines,i=this._options.keep_array_indentation&&R(this._flags.mode);if(t.comments_before)for(var n=t.comments_before.next();n;)this.handle_whitespace_and_comments(n,e),this.handle_token(n,e),n=t.comments_before.next();if(i)for(var _=0;_<u;_+=1)this.print_newline(0<_,e);else if(this._options.max_preserve_newlines&&u>this._options.max_preserve_newlines&&(u=this._options.max_preserve_newlines),this._options.preserve_newlines&&1<u){this.print_newline(!1,e);for(var s=1;s<u;s+=1)this.print_newline(!0,e)}};var A=["async","break","continue","return","throw","yield"];T.prototype.allow_wrap_or_preserved_newline=function(t,e){e=void 0!==e&&e,this._output.just_added_newline()||(e=this._options.preserve_newlines&&t.newlines||e,(l(this._flags.last_token.text,h)||l(t.text