uglifier 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of uglifier might be problematic. Click here for more details.

data/Gemfile CHANGED
@@ -3,8 +3,8 @@ source "http://rubygems.org"
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
 
6
- gem "execjs"
7
- gem "json"
6
+ gem "execjs", ">=0.3.0"
7
+ gem "multi_json"
8
8
 
9
9
  # Add dependencies to develop your gem here.
10
10
  # Include everything needed to run rake, tests, features, etc.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.1
1
+ 0.5.2
data/build.js CHANGED
@@ -1,9 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- var fs = require("fs");
4
- var stitch = require("stitch");
5
- var UglifyJS = require("./vendor/uglifyjs");
6
- var uglify = UglifyJS.uglify;
3
+ var fs = require("fs");
4
+ var stitch = require("stitch");
7
5
 
8
6
  var package = stitch.createPackage({
9
7
  paths: [__dirname + "/vendor/uglifyjs/lib"]
@@ -13,14 +11,11 @@ package.compile(function(err, source) {
13
11
  if (err) throw err;
14
12
 
15
13
  source = "(function(global) {" +
16
- source + ";" +
17
- "global.UglifyJS = {};" +
18
- "global.UglifyJS.parser = this.require('parse-js');" +
19
- "global.UglifyJS.uglify = this.require('process');" +
20
- "}).call({}, this)";
21
-
22
- var ast = UglifyJS.parser.parse(source);
23
- source = uglify.gen_code(uglify.ast_squeeze(uglify.ast_mangle(ast)));
14
+ source + ";\n" +
15
+ "global.UglifyJS = {};\n" +
16
+ "global.UglifyJS.parser = this.require('parse-js');\n" +
17
+ "global.UglifyJS.uglify = this.require('process');\n" +
18
+ "}).call({}, this);\n";
24
19
 
25
20
  fs.writeFile(__dirname + "/lib/uglify.js", source, function(err) {
26
21
  if (err) throw err;
data/lib/uglifier.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  require "execjs"
2
+ require "multi_json"
3
+ require "multi_json/vendor/ok_json"
2
4
 
3
5
  class Uglifier
4
6
  Error = ExecJS::Error
7
+ # MultiJson.engine = :json_gem
5
8
 
6
9
  DEFAULTS = {
7
10
  :mangle => true, # Mangle variables names
@@ -37,7 +40,7 @@ class Uglifier
37
40
 
38
41
  js = []
39
42
  js << "var result = '';"
40
- js << "var source = #{source.to_json};"
43
+ js << "var source = #{encode(source)};"
41
44
  js << "var ast = UglifyJS.parser.parse(source);"
42
45
 
43
46
  if @options[:copyright]
@@ -51,18 +54,18 @@ class Uglifier
51
54
  end
52
55
 
53
56
  if @options[:mangle]
54
- js << "ast = UglifyJS.uglify.ast_mangle(ast, #{mangle_options.to_json});"
57
+ js << "ast = UglifyJS.uglify.ast_mangle(ast, #{mangle_options});"
55
58
  end
56
59
 
57
60
  if @options[:squeeze]
58
- js << "ast = UglifyJS.uglify.ast_squeeze(ast, #{squeeze_options.to_json});"
61
+ js << "ast = UglifyJS.uglify.ast_squeeze(ast, #{MultiJson.encode(squeeze_options)});"
59
62
  end
60
63
 
61
64
  if @options[:unsafe]
62
65
  js << "ast = UglifyJS.uglify.ast_squeeze_more(ast);"
63
66
  end
64
67
 
65
- js << "result += UglifyJS.uglify.gen_code(ast, #{gen_code_options.to_json});"
68
+ js << "result += UglifyJS.uglify.gen_code(ast, #{MultiJson.encode(gen_code_options)});"
66
69
  js << "return result;"
67
70
 
68
71
  @context.exec js.join("\n")
@@ -71,8 +74,12 @@ class Uglifier
71
74
 
72
75
  private
73
76
 
77
+ def encode(source)
78
+ OkJson.strenc(source)
79
+ end
80
+
74
81
  def mangle_options
75
- @options[:toplevel]
82
+ @options[:toplevel] && MultiJson.encode(@options[:toplevel]) || "false"
76
83
  end
77
84
 
78
85
  def squeeze_options
data/lib/uglify.js CHANGED
@@ -1 +1,3014 @@
1
- (function(a){(function(){if(!this.require){var a={},b={},c=function(f,g){var h=b[f],i=d(g,f),j;if(h)return h;if(!(j=a[i]||a[i=d(i,"./index")]))throw"module '"+f+"' not found";h={id:f,exports:{}};try{b[f]=h.exports,j(h.exports,function(a){return c(a,e(i))},h);return b[f]=h.exports}catch(k){delete b[f];throw k}},d=function(a,b){var c=[],d,e;/^\.\.?(\/|$)/.test(b)?d=[a,b].join("/").split("/"):d=b.split("/");for(var f=0,g=d.length;f<g;f++)e=d[f],e==".."?c.pop():e!="."&&e!=""&&c.push(e);return c.join("/")},e=function(a){return a.split("/").slice(0,-1).join("/")};this.require=function(a){return c(a,"")},this.require.define=function(b){for(var c in b)a[c]=b[c]}}return this.require.define}).call(this)({"parse-js":function(a,b,c){function S(a,b){return Object.prototype.hasOwnProperty.call(a,b)}function R(a,b){for(var c=b.length;--c>=0;)if(b[c]===a)return!0;return!1}function Q(a){return a.split("")}function P(a,b){return Array.prototype.slice.call(a,b==null?0:b)}function O(a){var b={};for(var c=0;c<a.length;++c)b[a[c]]=!0;return b}function N(a){a instanceof Function&&(a=a());for(var b=1,c=arguments.length;--c>0;++b)arguments[b]();return a}function M(a){var b=P(arguments,1);return function(){return a.apply(this,b.concat(P(arguments)))}}function L(a,b,c){function bl(a){try{++d.in_loop;return a()}finally{--d.in_loop}}function bk(a,b){arguments.length==0&&(a=!0);var c=bj(b);if(a&&e("punc",",")){g();return p("seq",c,bk(!0,b))}return c}function bj(a){var b=bh(a),c=d.token.value;if(e("operator")&&S(G,c)){if(bi(b)){g();return p("assign",G[c],b,bj(a))}i("Invalid assignment")}return b}function bi(a){if(!b)return!0;switch(a[0]){case"dot":case"sub":case"new":case"call":return!0;case"name":return a[1]!="this"}}function bh(a){var b=bg(a);if(e("operator","?")){g();var c=bk(!1);m(":");return p("conditional",b,c,bk(!1,a))}return b}function bg(a){return bf(Z(!0),0,a)}function bf(a,b,c){var f=e("operator")?d.token.value:null;f&&f=="in"&&c&&(f=null);var h=f!=null?H[f]:null;if(h!=null&&h>b){g();var i=bf(Z(!0),h,c);return bf(p("binary",f,a,i),b,c)}return a}function be(a,b,c){(b=="++"||b=="--")&&!bi(c)&&i("Invalid use of "+b+" operator");return p(a,b,c)}function bd(a,b){if(e("punc",".")){g();return bd(p("dot",a,bc()),b)}if(e("punc","[")){g();return bd(p("sub",a,N(bk,M(m,"]"))),b)}if(b&&e("punc","(")){g();return bd(p("call",a,$(")")),!0)}if(b&&e("operator")&&S(F,d.token.value))return N(M(be,"unary-postfix",d.token.value,a),g);return a}function bc(){switch(d.token.type){case"name":case"operator":case"keyword":case"atom":return N(d.token.value,g);default:k()}}function bb(){switch(d.token.type){case"num":case"string":return N(d.token.value,g)}return bc()}function ba(){var a=!0,c=[];while(!e("punc","}")){a?a=!1:m(",");if(!b&&e("punc","}"))break;var f=d.token.type,h=bb();f!="name"||h!="get"&&h!="set"||!!e("punc",":")?(m(":"),c.push([h,bk(!1)])):c.push([bc(),C(!1),h])}g();return p("object",c)}function _(){return p("array",$("]",!b,!0))}function $(a,b,c){var d=!0,f=[];while(!e("punc",a)){d?d=!1:m(",");if(b&&e("punc",a))break;e("punc",",")&&c?f.push(["atom","undefined"]):f.push(bk(!1))}g();return f}function Z(a){if(e("operator","new")){g();return Y()}if(e("operator")&&S(E,d.token.value))return be("unary-prefix",N(d.token.value,g),Z(a));if(e("punc")){switch(d.token.value){case"(":g();return bd(N(bk,M(m,")")),a);case"[":g();return bd(_(),a);case"{":g();return bd(ba(),a)}k()}if(e("keyword","function")){g();return bd(C(!1),a)}if(S(J,d.token.type)){var b=d.token.type=="regexp"?p("regexp",d.token.value[0],d.token.value[1]):p(d.token.type,d.token.value);return bd(N(b,g),a)}k()}function Y(){var a=Z(!1),b;e("punc","(")?(g(),b=$(")")):b=[];return bd(p("new",a,b),!0)}function X(){return p("const",V())}function W(a){return p("var",V(a))}function V(a){var b=[];for(;;){e("name")||k();var c=d.token.value;g(),e("operator","=")?(g(),b.push([c,bk(!1,a)])):b.push([c]);if(!e("punc",","))break;g()}return b}function U(){var a=Q(),b,c;if(e("keyword","catch")){g(),m("("),e("name")||i("Name expected");var f=d.token.value;g(),m(")"),b=[f,Q()]}e("keyword","finally")&&(g(),c=Q()),!b&&!c&&i("Missing catch/finally blocks");return p("try",a,b,c)}function Q(){m("{");var a=[];while(!e("punc","}"))e("eof")&&k(),a.push(s());g();return a}function O(){var a=q(),b=s(),c;e("keyword","else")&&(g(),c=s());return p("if",a,b,c)}function L(a){var b=e("name")?N(d.token.value,g):null;a&&!b&&k(),m("(");return p(a?"defun":"function",b,function(a,b){while(!e("punc",")"))a?a=!1:m(","),e("name")||k(),b.push(d.token.value),g();g();return b}(!0,[]),function(){++d.in_function;var a=d.in_loop;d.in_loop=0;var b=Q();--d.in_function,d.in_loop=a;return b}())}function z(a){var b=a[0]=="var"?p("name",a[1][0]):a;g();var c=bk();m(")");return p("for-in",a,b,c,bl(s))}function y(a){m(";");var b=e("punc",";")?null:bk();m(";");var c=e("punc",")")?null:bk();m(")");return p("for",a,b,c,bl(s))}function x(){m("(");var a=null;if(!e("punc",";")){a=e("keyword","var")?(g(),W(!0)):bk(!0,!0);if(e("operator","in"))return z(a)}return y(a)}function w(a){var b=e("name")?d.token.value:null;b!=null?(g(),R(b,d.labels)||i("Label "+b+" without matching loop or statement")):d.in_loop==0&&i(a+" not inside a loop or switch"),o();return p(a,b)}function v(){return p("stat",N(bk,o))}function u(a){d.labels.push(a);var c=d.token,e=s();b&&!S(I,e[0])&&k(c),d.labels.pop();return p("label",a,e)}function t(){e("operator","/")&&(d.peeked=null,d.token=d.input(!0));switch(d.token.type){case"num":case"string":case"regexp":case"operator":case"atom":return v();case"name":return B(f(),"punc",":")?u(N(d.token.value,g,g)):v();case"punc":switch(d.token.value){case"{":return p("block",Q());case"[":case"(":return v();case";":g();return p("block");default:k()};case"keyword":switch(N(d.token.value,g)){case"break":return w("break");case"continue":return w("continue");case"debugger":o();return p("debugger");case"do":return function(a){l("keyword","while");return p("do",N(q,o),a)}(bl(s));case"for":return x();case"function":return C(!0);case"if":return O();case"return":d.in_function==0&&i("'return' outside of function");return p("return",e("punc",";")?(g(),null):n()?null:N(bk,o));case"switch":return p("switch",q(),T());case"throw":return p("throw",N(bk,o));case"try":return U();case"var":return N(W,o);case"const":return N(X,o);case"while":return p("while",q(),bl(s));case"with":return p("with",q(),s());default:k()}}}function r(a,b,c){return a instanceof K?a:new K(a,b,c)}function q(){m("(");var a=bk();m(")");return a}function p(){return P(arguments)}function o(){e("punc",";")?g():n()||k()}function n(){return!b&&(d.token.nlb||e("eof")||e("punc","}"))}function m(a){return l("punc",a)}function l(a,b){if(e(a,b))return g();j(d.token,"Unexpected token "+d.token.type+", expected "+a)}function k(a){a==null&&(a=d.token),j(a,"Unexpected token: "+a.type+" ("+a.value+")")}function j(a,b){i(b,a.line,a.col)}function i(a,b,c,e){var f=d.input.context();A(a,b!=null?b:f.tokline,c!=null?c:f.tokcol,e!=null?e:f.tokpos)}function h(){return d.prev}function g(){d.prev=d.token,d.peeked?(d.token=d.peeked,d.peeked=null):d.token=d.input();return d.token}function f(){return d.peeked||(d.peeked=d.input())}function e(a,b){return B(d.token,a,b)}var d={input:typeof a=="string"?D(a,!0):a,token:null,prev:null,peeked:null,in_function:0,in_loop:0,labels:[]};d.token=g();var s=c?function(){var a=d.token,b=t.apply(this,arguments);b[0]=r(b[0],a,h());return b}:t,C=c?function(){var a=h(),b=L.apply(this,arguments);b[0]=r(b[0],a,h());return b}:L,T=M(bl,function(){m("{");var a=[],b=null;while(!e("punc","}"))e("eof")&&k(),e("keyword","case")?(g(),b=[],a.push([bk(),b]),m(":")):e("keyword","default")?(g(),m(":"),b=[],a.push([null,b])):(b||k(),b.push(s()));g();return a});return p("toplevel",function(a){while(!e("eof"))a.push(s());return a}([]))}function K(a,b,c){this.name=a,this.start=b,this.end=c}function D(a){function O(a){if(a)return I();q(),k();var b=c();if(!b)return p("eof");if(s(b))return v();if(b=='"'||b=="'")return D();if(S(o,b))return p("punc",e());if(b==".")return L();if(b=="/")return K();if(S(h,b))return J();if(b=="\\"||w(b))return M();u("Unexpected character '"+b+"'")}function N(a,b){try{return b()}catch(c){if(c===C)u(a);else throw c}}function M(){var a=H();return S(d,a)?S(l,a)?p("operator",a):S(g,a)?p("atom",a):p("keyword",a):p("name",a)}function L(){e();return s(c())?v("."):p("punc",".")}function K(){e();var a=b.regex_allowed;switch(c()){case"/":b.comments_before.push(E()),b.regex_allowed=a;return O();case"*":b.comments_before.push(G()),b.regex_allowed=a;return O()}return b.regex_allowed?I():J("/")}function J(a){function b(a){if(!c())return a;var d=a+c();if(S(l,d)){e();return b(d)}return a}return p("operator",b(a||e()))}function I(){return N("Unterminated regular expression",function(){var a=!1,b="",c,d=!1;while(c=e(!0))if(a)b+="\\"+c,a=!1;else if(c=="[")d=!0,b+=c;else if(c=="]"&&d)d=!1,b+=c;else{if(c=="/"&&!d)break;c=="\\"?a=!0:b+=c}var f=H();return p("regexp",[b,f])})}function H(){var a=!1,b="",d;while((d=c())!=null)if(!a)if(d=="\\")a=!0,e();else if(x(d))b+=e();else break;else d!="u"&&u("Expecting UnicodeEscapeSequence -- uXXXX"),d=z(),x(d)||u("Unicode char: "+d.charCodeAt(0)+" is not valid in identifier"),b+=d,a=!1;return b}function G(){e();return N("Unterminated multiline comment",function(){var a=j("*/",!0),c=b.text.substring(b.pos,a),d=p("comment2",c,!0);b.pos=a+2,b.line+=c.split("\n").length-1,b.newline_before=c.indexOf("\n")>=0,/^@cc_on/i.test(c)&&(T("WARNING: at line "+b.line),T('*** Found "conditional comment": '+c),T("*** UglifyJS DISCARDS ALL COMMENTS. This means your code might no longer work properly in Internet Explorer."));return d})}function E(){e();var a=j("\n"),c;a==-1?(c=b.text.substr(b.pos),b.pos=b.text.length):(c=b.text.substring(b.pos,a),b.pos=a);return p("comment1",c,!0)}function D(){return N("Unterminated string constant",function(){var a=e(),b="";for(;;){var c=e(!0);if(c=="\\")c=z();else if(c==a)break;b+=c}return p("string",b)})}function B(a){var b=0;for(;a>0;--a){var c=parseInt(e(!0),16);isNaN(c)&&u("Invalid hex-character pattern in string"),b=b<<4|c}return b}function z(){var a=e(!0);switch(a){case"n":return"\n";case"r":return"\r";case"t":return"\t";case"b":return"\b";case"v":return" ";case"f":return"\f";case"0":return"";case"x":return String.fromCharCode(B(2));case"u":return String.fromCharCode(B(4));default:return a}}function v(a){var b=!1,c=!1,d=!1,e=a==".",f=r(function(f,g){if(f=="x"||f=="X"){if(d)return!1;return d=!0}if(!d&&(f=="E"||f=="e")){if(b)return!1;return b=c=!0}if(f=="-"){if(c||g==0&&!a)return!0;return!1}if(f=="+")return c;c=!1;if(f=="."){if(!e&&!d)return e=!0;return!1}return t(f)});a&&(f=a+f);var g=y(f);if(!isNaN(g))return p("num",g);u("Invalid syntax: "+f)}function u(a){A(a,b.tokline,b.tokcol,b.tokpos)}function r(a){var b="",d=c(),f=0;while(d&&a(d,f++))b+=e(),d=c();return b}function q(){while(S(m,c()))e()}function p(a,c,d){b.regex_allowed=a=="operator"&&!S(F,c)||a=="keyword"&&S(f,c)||a=="punc"&&S(n,c);var e={type:a,value:c,line:b.tokline,col:b.tokcol,pos:b.tokpos,nlb:b.newline_before};d||(e.comments_before=b.comments_before,b.comments_before=[]),b.newline_before=!1;return e}function k(){b.tokline=b.line,b.tokcol=b.col,b.tokpos=b.pos}function j(a,c){var d=b.text.indexOf(a,b.pos);if(c&&d==-1)throw C;return d}function i(){return!b.peek()}function e(a){var c=b.text.charAt(b.pos++);if(a&&!c)throw C;c=="\n"?(b.newline_before=!0,++b.line,b.col=0):++b.col;return c}function c(){return b.text.charAt(b.pos)}var b={text:a.replace(/\r\n?|[\n\u2028\u2029]/g,"\n").replace(/^\uFEFF/,""),pos:0,tokpos:0,line:0,tokline:0,col:0,tokcol:0,newline_before:!1,regex_allowed:!1,comments_before:[]};O.context=function(a){a&&(b=a);return b};return O}function B(a,b,c){return a.type==b&&(c==null||a.value==c)}function A(a,b,c,d){throw new z(a,b,c,d)}function z(a,b,c,d){this.message=a,this.line=b,this.col=c,this.pos=d;try{({})()}catch(e){this.stack=e.stack}}function y(a){if(i.test(a))return parseInt(a.substr(2),16);if(j.test(a))return parseInt(a.substr(1),8);if(k.test(a))return parseFloat(a)}function x(a){return w(a)||u(a)||s(a)||v(a)||a=="‌"||a=="‍"}function w(a){return a=="$"||a=="_"||r(a)}function v(a){return q.connector_punctuation.test(a)}function u(a){return q.non_spacing_mark.test(a)||q.space_combining_mark.test(a)}function t(a){return s(a)||r(a)}function s(a){a=a.charCodeAt(0);return a>=48&&a<=57}function r(a){return q.letter.test(a)}var d=O(["break","case","catch","const","continue","default","delete","do","else","finally","for","function","if","in","instanceof","new","return","switch","throw","try","typeof","var","void","while","with"]),e=O(["abstract","boolean","byte","char","class","debugger","double","enum","export","extends","final","float","goto","implements","import","int","interface","long","native","package","private","protected","public","short","static","super","synchronized","throws","transient","volatile"]),f=O(["return","new","delete","throw","else","case"]),g=O(["false","null","true","undefined"]),h=O(Q("+-*&%=<>!?|~^")),i=/^0x[0-9a-f]+$/i,j=/^0[0-7]+$/,k=/^\d*\.?\d*(?:e[+-]?\d*(?:\d\.?|\.?\d)\d*)?$/i,l=O(["in","instanceof","typeof","new","void","delete","++","--","+","-","!","~","&","|","^","*","/","%",">>","<<",">>>","<",">","<=",">=","==","===","!=","!==","?","=","+=","-=","/=","*=","%=",">>=","<<=",">>>=","|=","^=","&=","&&","||"]),m=O(Q(" \n\r\t​")),n=O(Q("[{}(,.;:")),o=O(Q("[]{}(),;:")),p=O(Q("gmsiy")),q={letter:new RegExp("[\\u0041-\\u005A\\u0061-\\u007A\\u00AA\\u00B5\\u00BA\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0370-\\u0374\\u0376\\u0377\\u037A-\\u037D\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u048A-\\u0523\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0621-\\u064A\\u066E\\u066F\\u0671-\\u06D3\\u06D5\\u06E5\\u06E6\\u06EE\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4\\u07F5\\u07FA\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0971\\u0972\\u097B-\\u097F\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC\\u09DD\\u09DF-\\u09E1\\u09F0\\u09F1\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0\\u0AE1\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C33\\u0C35-\\u0C39\\u0C3D\\u0C58\\u0C59\\u0C60\\u0C61\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDE\\u0CE0\\u0CE1\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D28\\u0D2A-\\u0D39\\u0D3D\\u0D60\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32\\u0E33\\u0E40-\\u0E46\\u0E81\\u0E82\\u0E84\\u0E87\\u0E88\\u0E8A\\u0E8D\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB0\\u0EB2\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EDC\\u0EDD\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8B\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10A0-\\u10C5\\u10D0-\\u10FA\\u10FC\\u1100-\\u1159\\u115F-\\u11A2\\u11A8-\\u11F9\\u1200-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F4\\u1401-\\u166C\\u166F-\\u1676\\u1681-\\u169A\\u16A0-\\u16EA\\u1700-\\u170C\\u170E-\\u1711\\u1720-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17D7\\u17DC\\u1820-\\u1877\\u1880-\\u18A8\\u18AA\\u1900-\\u191C\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19A9\\u19C1-\\u19C7\\u1A00-\\u1A16\\u1B05-\\u1B33\\u1B45-\\u1B4B\\u1B83-\\u1BA0\\u1BAE\\u1BAF\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C7D\\u1D00-\\u1DBF\\u1E00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4\\u1FF6-\\u1FFC\\u2071\\u207F\\u2090-\\u2094\\u2102\\u2107\\u210A-\\u2113\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u212F-\\u2139\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2183\\u2184\\u2C00-\\u2C2E\\u2C30-\\u2C5E\\u2C60-\\u2C6F\\u2C71-\\u2C7D\\u2C80-\\u2CE4\\u2D00-\\u2D25\\u2D30-\\u2D65\\u2D6F\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u2E2F\\u3005\\u3006\\u3031-\\u3035\\u303B\\u303C\\u3041-\\u3096\\u309D-\\u309F\\u30A1-\\u30FA\\u30FC-\\u30FF\\u3105-\\u312D\\u3131-\\u318E\\u31A0-\\u31B7\\u31F0-\\u31FF\\u3400\\u4DB5\\u4E00\\u9FC3\\uA000-\\uA48C\\uA500-\\uA60C\\uA610-\\uA61F\\uA62A\\uA62B\\uA640-\\uA65F\\uA662-\\uA66E\\uA67F-\\uA697\\uA717-\\uA71F\\uA722-\\uA788\\uA78B\\uA78C\\uA7FB-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA90A-\\uA925\\uA930-\\uA946\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAC00\\uD7A3\\uF900-\\uFA2D\\uFA30-\\uFA6A\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF21-\\uFF3A\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC]"),non_spacing_mark:new RegExp("[\\u0300-\\u036F\\u0483-\\u0487\\u0591-\\u05BD\\u05BF\\u05C1\\u05C2\\u05C4\\u05C5\\u05C7\\u0610-\\u061A\\u064B-\\u065E\\u0670\\u06D6-\\u06DC\\u06DF-\\u06E4\\u06E7\\u06E8\\u06EA-\\u06ED\\u0711\\u0730-\\u074A\\u07A6-\\u07B0\\u07EB-\\u07F3\\u0816-\\u0819\\u081B-\\u0823\\u0825-\\u0827\\u0829-\\u082D\\u0900-\\u0902\\u093C\\u0941-\\u0948\\u094D\\u0951-\\u0955\\u0962\\u0963\\u0981\\u09BC\\u09C1-\\u09C4\\u09CD\\u09E2\\u09E3\\u0A01\\u0A02\\u0A3C\\u0A41\\u0A42\\u0A47\\u0A48\\u0A4B-\\u0A4D\\u0A51\\u0A70\\u0A71\\u0A75\\u0A81\\u0A82\\u0ABC\\u0AC1-\\u0AC5\\u0AC7\\u0AC8\\u0ACD\\u0AE2\\u0AE3\\u0B01\\u0B3C\\u0B3F\\u0B41-\\u0B44\\u0B4D\\u0B56\\u0B62\\u0B63\\u0B82\\u0BC0\\u0BCD\\u0C3E-\\u0C40\\u0C46-\\u0C48\\u0C4A-\\u0C4D\\u0C55\\u0C56\\u0C62\\u0C63\\u0CBC\\u0CBF\\u0CC6\\u0CCC\\u0CCD\\u0CE2\\u0CE3\\u0D41-\\u0D44\\u0D4D\\u0D62\\u0D63\\u0DCA\\u0DD2-\\u0DD4\\u0DD6\\u0E31\\u0E34-\\u0E3A\\u0E47-\\u0E4E\\u0EB1\\u0EB4-\\u0EB9\\u0EBB\\u0EBC\\u0EC8-\\u0ECD\\u0F18\\u0F19\\u0F35\\u0F37\\u0F39\\u0F71-\\u0F7E\\u0F80-\\u0F84\\u0F86\\u0F87\\u0F90-\\u0F97\\u0F99-\\u0FBC\\u0FC6\\u102D-\\u1030\\u1032-\\u1037\\u1039\\u103A\\u103D\\u103E\\u1058\\u1059\\u105E-\\u1060\\u1071-\\u1074\\u1082\\u1085\\u1086\\u108D\\u109D\\u135F\\u1712-\\u1714\\u1732-\\u1734\\u1752\\u1753\\u1772\\u1773\\u17B7-\\u17BD\\u17C6\\u17C9-\\u17D3\\u17DD\\u180B-\\u180D\\u18A9\\u1920-\\u1922\\u1927\\u1928\\u1932\\u1939-\\u193B\\u1A17\\u1A18\\u1A56\\u1A58-\\u1A5E\\u1A60\\u1A62\\u1A65-\\u1A6C\\u1A73-\\u1A7C\\u1A7F\\u1B00-\\u1B03\\u1B34\\u1B36-\\u1B3A\\u1B3C\\u1B42\\u1B6B-\\u1B73\\u1B80\\u1B81\\u1BA2-\\u1BA5\\u1BA8\\u1BA9\\u1C2C-\\u1C33\\u1C36\\u1C37\\u1CD0-\\u1CD2\\u1CD4-\\u1CE0\\u1CE2-\\u1CE8\\u1CED\\u1DC0-\\u1DE6\\u1DFD-\\u1DFF\\u20D0-\\u20DC\\u20E1\\u20E5-\\u20F0\\u2CEF-\\u2CF1\\u2DE0-\\u2DFF\\u302A-\\u302F\\u3099\\u309A\\uA66F\\uA67C\\uA67D\\uA6F0\\uA6F1\\uA802\\uA806\\uA80B\\uA825\\uA826\\uA8C4\\uA8E0-\\uA8F1\\uA926-\\uA92D\\uA947-\\uA951\\uA980-\\uA982\\uA9B3\\uA9B6-\\uA9B9\\uA9BC\\uAA29-\\uAA2E\\uAA31\\uAA32\\uAA35\\uAA36\\uAA43\\uAA4C\\uAAB0\\uAAB2-\\uAAB4\\uAAB7\\uAAB8\\uAABE\\uAABF\\uAAC1\\uABE5\\uABE8\\uABED\\uFB1E\\uFE00-\\uFE0F\\uFE20-\\uFE26]"),space_combining_mark:new RegExp("[\\u0903\\u093E-\\u0940\\u0949-\\u094C\\u094E\\u0982\\u0983\\u09BE-\\u09C0\\u09C7\\u09C8\\u09CB\\u09CC\\u09D7\\u0A03\\u0A3E-\\u0A40\\u0A83\\u0ABE-\\u0AC0\\u0AC9\\u0ACB\\u0ACC\\u0B02\\u0B03\\u0B3E\\u0B40\\u0B47\\u0B48\\u0B4B\\u0B4C\\u0B57\\u0BBE\\u0BBF\\u0BC1\\u0BC2\\u0BC6-\\u0BC8\\u0BCA-\\u0BCC\\u0BD7\\u0C01-\\u0C03\\u0C41-\\u0C44\\u0C82\\u0C83\\u0CBE\\u0CC0-\\u0CC4\\u0CC7\\u0CC8\\u0CCA\\u0CCB\\u0CD5\\u0CD6\\u0D02\\u0D03\\u0D3E-\\u0D40\\u0D46-\\u0D48\\u0D4A-\\u0D4C\\u0D57\\u0D82\\u0D83\\u0DCF-\\u0DD1\\u0DD8-\\u0DDF\\u0DF2\\u0DF3\\u0F3E\\u0F3F\\u0F7F\\u102B\\u102C\\u1031\\u1038\\u103B\\u103C\\u1056\\u1057\\u1062-\\u1064\\u1067-\\u106D\\u1083\\u1084\\u1087-\\u108C\\u108F\\u109A-\\u109C\\u17B6\\u17BE-\\u17C5\\u17C7\\u17C8\\u1923-\\u1926\\u1929-\\u192B\\u1930\\u1931\\u1933-\\u1938\\u19B0-\\u19C0\\u19C8\\u19C9\\u1A19-\\u1A1B\\u1A55\\u1A57\\u1A61\\u1A63\\u1A64\\u1A6D-\\u1A72\\u1B04\\u1B35\\u1B3B\\u1B3D-\\u1B41\\u1B43\\u1B44\\u1B82\\u1BA1\\u1BA6\\u1BA7\\u1BAA\\u1C24-\\u1C2B\\u1C34\\u1C35\\u1CE1\\u1CF2\\uA823\\uA824\\uA827\\uA880\\uA881\\uA8B4-\\uA8C3\\uA952\\uA953\\uA983\\uA9B4\\uA9B5\\uA9BA\\uA9BB\\uA9BD-\\uA9C0\\uAA2F\\uAA30\\uAA33\\uAA34\\uAA4D\\uAA7B\\uABE3\\uABE4\\uABE6\\uABE7\\uABE9\\uABEA\\uABEC]"),connector_punctuation:new RegExp("[\\u005F\\u203F\\u2040\\u2054\\uFE33\\uFE34\\uFE4D-\\uFE4F\\uFF3F]")};z.prototype.toString=function(){return this.message+" (line: "+this.line+", col: "+this.col+", pos: "+this.pos+")"+"\n\n"+this.stack};var C={},E=O(["typeof","void","delete","--","++","!","~","-","+"]),F=O(["--","++"]),G=function(a,b,c){while(c<a.length)b[a[c]]=a[c].substr(0,a[c].length-1),c++;return b}(["+=","-=","/=","*=","%=",">>=","<<=",">>>=","|=","^=","&="],{"=":!0},0),H=function(a,b){for(var c=0,d=1;c<a.length;++c,++d){var e=a[c];for(var f=0;f<e.length;++f)b[e[f]]=d}return b}([["||"],["&&"],["|"],["^"],["&"],["==","===","!=","!=="],["<",">","<=",">=","in","instanceof"],[">>","<<",">>>"],["+","-"],["*","/","%"]],{}),I=O(["for","do","while","switch"]),J=O(["atom","num","string","regexp","name"]);K.prototype.toString=function(){return this.name};var T=function(){};a.tokenizer=D,a.parse=L,a.slice=P,a.curry=M,a.member=R,a.array_to_hash=O,a.PRECEDENCE=H,a.KEYWORDS_ATOM=g,a.RESERVED_WORDS=e,a.KEYWORDS=d,a.ATOMIC_START_TOKEN=J,a.OPERATORS=l,a.is_alphanumeric_char=t,a.set_logger=function(a){T=a}},process:function(a,b,c){function G(a,b){return Object.prototype.hasOwnProperty.call(a,b)}function F(a){return/^[a-z_$][a-z0-9_$]*$/i.test(a)&&a!="this"&&!G(d.KEYWORDS_ATOM,a)&&!G(d.RESERVED_WORDS,a)&&!G(d.KEYWORDS,a)}function E(a,b){var c={};a===!0&&(a={});for(var d in b)G(b,d)&&(c[d]=a&&G(a,d)?a[d]:b[d]);return c}function D(a,b){if(b<=0)return"";if(b==1)return a;var c=D(a,b>>1);c+=c,b&1&&(c+=a);return c}function C(a,b){var c=[0];d.parse(function(){function j(){var a=e.apply(this,arguments);out:{if(g&&g.type=="keyword")break out;if(h(a)>b)switch(a.type){case"keyword":case"atom":case"name":case"punc":i(a);break out}}g=a;return a}function i(a){f=a.pos,c.push(f)}function h(a){return a.pos-f}var e=d.tokenizer(a),f=0,g;j.context=function(){return e.context.apply(this,arguments)};return j}());return c.map(function(b,d){return a.substring(b,c[d+1]||a.length)}).join("\n")}function B(a,b){function N(a){var b=a[0],c=x[b];if(!c)throw new Error("Can't find generator for \""+b+'"');M.push(a);var d=c.apply(b,a.slice(1));M.pop();return d}function L(a){var b=a[0],c=a[1];c!=null&&(b=q([n(b),"=",N(c)]));return b}function K(a){if(!a)return";";if(a.length==0)return"{}";return"{"+k+p(function(){return I(a).join(k)})+k+o("}")}function J(a){var b=a.length;if(b==0)return"{}";return"{"+k+H(a,function(a,d){var e=a[1].length>0,f=p(function(){return o(a[0]?q(["case",N(a[0])+":"]):"default:")},.5)+(e?k+p(function(){return I(a[1]).join(k)}):"");!c&&e&&d<b-1&&(f+=";");return f}).join(k)+k+o("}")}function I(a){for(var b=[],d=a.length-1,e=0;e<=d;++e){var g=a[e],h=N(g);h!=";"&&(!c&&e==d&&(g[0]=="while"&&t(g[2])||f(g[0],["for","for-in"])&&t(g[4])||g[0]=="if"&&t(g[2])&&!g[3]||g[0]=="if"&&g[3]&&t(g[3])?h=h.replace(/;*\s*$/,";"):h=h.replace(/;+\s*$/,"")),b.push(h))}return H(b,o)}function C(a,b,c,d){var e=d||"function";a&&(e+=" "+n(a)),e+="("+r(H(b,n))+")";return q([e,K(c)])}function B(a){if(a[0]=="do")return N(["block",[a]]);var b=a;for(;;){var c=b[0];if(c=="if"){if(!b[3])return N(["block",[a]]);b=b[3]}else if(c=="while"||c=="do")b=b[2];else if(c=="for"||c=="for-in")b=b[4];else break}return N(a)}function w(a){var b=a.toString(10),c=[b.replace(/^0\./,".")],d;Math.floor(a)===a?(c.push("0x"+a.toString(16).toLowerCase(),"0"+a.toString(8)),(d=/^(.*?)(0+)$/.exec(a))&&c.push(d[1]+"e"+d[2].length)):(d=/^0?\.(0+)(.*)$/.exec(a))&&c.push(d[2]+"e-"+(d[1].length+d[2].length),b.substr(b.indexOf(".")));return u(c)}function v(a){if(a[0]=="function"||a[0]=="object"){var b=e(M),c=b.pop(),d=b.pop();while(d){if(d[0]=="stat")return!0;if((d[0]=="seq"||d[0]=="call"||d[0]=="dot"||d[0]=="sub"||d[0]=="conditional")&&d[1]===c||(d[0]=="binary"||d[0]=="assign"||d[0]=="unary-postfix")&&d[2]===c)c=d,d=b.pop();else return!1}}return!G(y,a[0])}function u(a){if(a.length==1)return a[0];if(a.length==2){var b=a[1];a=a[0];return a.length<=b.length?a:b}return u([a[0],u(a.slice(1))])}function s(a){var b=N(a);for(var c=1;c<arguments.length;++c){var d=arguments[c];if(d instanceof Function&&d(a)||a[0]==d)return"("+b+")"}return b}function r(a){return a.join(","+l)}function q(a){if(c)return a.join(" ");var b=[];for(var d=0;d<a.length;++d){var e=a[d+1];b.push(a[d]),e&&(/[a-z0-9_\x24]$/i.test(a[d].toString())&&/^[a-z0-9_\x24]/i.test(e.toString())||/[\+\-]$/.test(a[d].toString())&&/^[\+\-]/.test(e.toString()))&&b.push(" ")}return b.join("")}function p(a,b){b==null&&(b=1),j+=b;try{return a.apply(null,e(arguments,1))}finally{j-=b}}function o(a){a==null&&(a=""),c&&(a=D(" ",b.indent_start+j*b.indent_level)+a);return a}function n(a){a=a.toString(),b.ascii_only&&(a=A(a));return a}function m(a){return z(a,b.ascii_only)}b=E(b,{indent_start:0,indent_level:4,quote_keys:!1,space_colon:!1,beautify:!1,ascii_only:!1});var c=!!b.beautify,j=0,k=c?"\n":"",l=c?" ":"",x={string:m,num:w,name:n,toplevel:function(a){return I(a).join(k+k)},block:K,"var":function(a){return"var "+r(H(a,L))+";"},"const":function(a){return"const "+r(H(a,L))+";"},"try":function(a,b,c){var d=["try",K(a)];b&&d.push("catch","("+b[0]+")",K(b[1])),c&&d.push("finally",K(c));return q(d)},"throw":function(a){return q(["throw",N(a)])+";"},"new":function(a,b){b=b.length>0?"("+r(H(b,N))+")":"";return q(["new",s(a,"seq","binary","conditional","assign",function(a){var b=i(),c={};try{b.with_walkers({call:function(){throw c},"function":function(){return this}},function(){b.walk(a)})}catch(d){if(d===c)return!0;throw d}})+b])},"switch":function(a,b){return q(["switch","("+N(a)+")",J(b)])},"break":function(a){var b="break";a!=null&&(b+=" "+n(a));return b+";"},"continue":function(a){var b="continue";a!=null&&(b+=" "+n(a));return b+";"},conditional:function(a,b,c){return q([s(a,"assign","seq","conditional"),"?",s(b,"seq"),":",s(c,"seq")])},assign:function(a,b,c){a&&a!==!0?a+="=":a="=";return q([N(b),a,s(c,"seq")])},dot:function(a){var b=N(a),c=1;a[0]=="num"?/\./.test(a[1])||(b+="."):v(a)&&(b="("+b+")");while(c<arguments.length)b+="."+n(arguments[c++]);return b},call:function(a,b){var c=N(a);v(a)&&(c="("+c+")");return c+"("+r(H(b,function(a){return s(a,"seq")}))+")"},"function":C,defun:C,"if":function(a,b,c){var d=["if","("+N(a)+")",c?B(b):N(b)];c&&d.push("else",N(c));return q(d)},"for":function(a,b,c,d){var e=["for"];a=(a!=null?N(a):"").replace(/;*\s*$/,";"+l),b=(b!=null?N(b):"").replace(/;*\s*$/,";"+l),c=(c!=null?N(c):"").replace(/;*\s*$/,"");var f=a+b+c;f=="; ; "&&(f=";;"),e.push("("+f+")",N(d));return q(e)},"for-in":function(a,b,c,d){return q(["for","("+(a?N(a).replace(/;+$/,""):N(b)),"in",N(c)+")",N(d)])},"while":function(a,b){return q(["while","("+N(a)+")",N(b)])},"do":function(a,b){return q(["do",N(b),"while","("+N(a)+")"])+";"},"return":function(a){var b=["return"];a!=null&&b.push(N(a));return q(b)+";"},binary:function(a,b,c){var d=N(b),e=N(c);if(f(b[0],["assign","conditional","seq"])||b[0]=="binary"&&g[a]>g[b[1]])d="("+d+")";if(f(c[0],["assign","conditional","seq"])||c[0]=="binary"&&g[a]>=g[c[1]]&&(c[1]!=a||!f(a,["&&","||","*"])))e="("+e+")";return q([d,a,e])},"unary-prefix":function(a,b){var c=N(b);b[0]=="num"||b[0]=="unary-prefix"&&!G(h,a+b[1])||!v(b)||(c="("+c+")");return a+(d.is_alphanumeric_char(a.charAt(0))?" ":"")+c},"unary-postfix":function(a,b){var c=N(b);b[0]=="num"||b[0]=="unary-postfix"&&!G(h,a+b[1])||!v(b)||(c="("+c+")");return c+a},sub:function(a,b){var c=N(a);v(a)&&(c="("+c+")");return c+"["+N(b)+"]"},object:function(a){if(a.length==0)return"{}";return"{"+k+p(function(){return H(a,function(a){if(a.length==3)return o(C(a[0],a[1][2],a[1][3],a[2]));var d=a[0],e=N(a[1]);b.quote_keys?d=m(d):(typeof d=="number"||!c&&+d+""==d)&&parseFloat(d)>=0?d=w(+d):F(d)||(d=m(d));return o(q(c&&b.space_colon?[d,":",e]:[d+":",e]))}).join(","+k)})+k+o("}")},regexp:function(a,b){return"/"+a+"/"+b},array:function(a){if(a.length==0)return"[]";return q(["[",r(H(a,function(a){if(!c&&a[0]=="atom"&&a[1]=="undefined")return"";return s(a,"seq")})),"]"])},stat:function(a){return N(a).replace(/;*\s*$/,";")},seq:function(){return r(H(e(arguments),N))},label:function(a,b){return q([n(a),":",N(b)])},"with":function(a,b){return q(["with","("+N(a)+")",N(b)])},atom:function(a){return n(a)}},M=[];return N(a)}function A(a){return a.replace(/[\u0080-\uffff]/g,function(a){var b=a.charCodeAt(0).toString(16);while(b.length<4)b="0"+b;return"\\u"+b})}function z(a,b){var c=0,d=0;a=a.replace(/[\\\b\f\n\r\t\x22\x27\u2028\u2029]/g,function(a){switch(a){case"\\":return"\\\\";case"\b":return"\\b";case"\f":return"\\f";case"\n":return"\\n";case"\r":return"\\r";case"\t":return"\\t";case"\u2028":return"\\u2028";case"\u2029":return"\\u2029";case'"':++c;return'"';case"'":++d;return"'"}return a}),b&&(a=A(a));return c>d?"'"+a.replace(/\x27/g,"\\'")+"'":'"'+a.replace(/\x22/g,'\\"')+'"'}function x(a,b){function y(a,b){return v(a,function(a,c){if(!c){w(b);return["block"]}return["for",null,null,null,d(b)]})}function x(a,b,c){a=d(a),b=d(b),c=d(c),t(b)?(a=h(a),b=c,c=null):t(c)?c=null:function(){var d=B(a),e=h(a),f=B(e);if(f.length<d.length){var g=b;b=c,c=g,a=e}}();if(t(c)&&t(b))return["stat",a];var e=["if",a,b,c];b[0]=="if"&&t(b[3])&&t(c)?e=o(e,d(["if",["binary","&&",a,b[1]],b[2]])):b[0]=="stat"?c?c[0]=="stat"&&(e=o(e,["stat",s(a,b[1],c[1])])):e=o(e,["stat",s(a,b[1])]):c&&b[0]==c[0]&&(b[0]=="return"||b[0]=="throw")&&b[1]&&c[1]?e=o(e,[b[0],s(a,b[1],c[1])]):c&&q(b)?(e=[["if",a,b]],c[0]=="block"?c[1]&&(e=e.concat(c[1])):e.push(c),e=d(["block",e])):b&&q(c)&&(e=[["if",h(a),c]],b[0]=="block"?b[1]&&(e=e.concat(b[1])):e.push(b),e=d(["block",e]));return e}function u(a,b,c){return v(a,function(a,d){if(d){w(c);return b}w(b);return c},function(){return x(a,b,c)})}function n(a,c){a=a.reduce(function(a,b){b[0]=="block"?b[1]&&a.push.apply(a,b[1]):a.push(b);return a},[]),a=function(b,c){a.forEach(function(a){c&&(a[0]=="var"&&c[0]=="var"||a[0]=="const"&&c[0]=="const")?c[1]=c[1].concat(a[1]):(b.push(a),c=a)});return b}([]),b.dead_code&&(a=function(c,d){a.forEach(function(a){d?f(a[0],["function","defun","var","const"])?c.push(a):b.no_warnings||w(a):(c.push(a),f(a[0],["return","throw","break","continue"])&&(d=!0))});return c}([])),b.make_seqs&&(a=function(b,c){a.forEach(function(a){c&&c[0]=="stat"&&a[0]=="stat"?c[1]=["seq",c[1],a[1]]:(b.push(a),c=a)});return b}([])),c=="lambda"&&(a=function(b,c,d){while(b<a.length){d=a[b++];if(d[0]=="if"&&!d[3]){if(d[2][0]=="return"&&d[2][1]==null){c.push(u(h(d[1]),["block",a.slice(b)]));break}var e=p(d[2]);if(e[0]=="return"&&e[1]==null){c.push(u(d[1],["block",d[2][1].slice(0,-1)],["block",a.slice(b)]));break}}c.push(d)}return c}(0,[]));return a}function m(a,b,c){return[this[0],a,b,j(c.scope,function(){return n(H(c,d),"lambda")})]}function k(a){a!=null&&a[0]=="block"&&a[1]&&(a[1].length==1?a=a[1][0]:a[1].length==0&&(a=["block"]));return a}function j(a,b){var c=g;g=a;var d=b();d.scope=a,g=c;return d}function h(a){var c=["unary-prefix","!",a];switch(a[0]){case"unary-prefix":return a[1]=="!"&&r(a[2])?a[2]:c;case"seq":a=e(a),a[a.length-1]=h(a[a.length-1]);return a;case"conditional":return o(c,["conditional",a[1],h(a[2]),h(a[3])]);case"binary":var d=a[1],f=a[2],g=a[3];if(!b.keep_comps)switch(d){case"<=":return["binary",">",f,g];case"<":return["binary",">=",f,g];case">=":return["binary","<",f,g];case">":return["binary","<=",f,g]}switch(d){case"==":return["binary","!=",f,g];case"!=":return["binary","==",f,g];case"===":return["binary","!==",f,g];case"!==":return["binary","===",f,g];case"&&":return o(c,["binary","||",h(f),h(g)]);case"||":return o(c,["binary","&&",h(f),h(g)])}}return c}b=E(b,{make_seqs:!0,dead_code:!0,keep_comps:!0,no_warnings:!1});var c=i(),d=c.walk,g;return c.with_walkers({sub:function(a,b){if(b[0]=="string"){var c=b[1];if(F(c))return["dot",d(a),c];if(/^[1-9][0-9]*$/.test(c)||c==="0")return["sub",d(a),["num",parseInt(c,10)]]}},"if":u,toplevel:function(a){return["toplevel",j(this.scope,function(){return n(H(a,d))})]},"switch":function(a,b){var c=b.length-1;return["switch",d(a),H(b,function(a,b){var e=n(H(a[1],d));if(b==c&&e.length>0){var f=e[e.length-1];f[0]=="break"&&!f[1]&&e.pop()}return[a[0]?d(a[0]):null,e]})]},"function":function(){var a=m.apply(this,arguments);a[1]&&!G(g.refs,a[1])&&(a[1]=null);return a},defun:m,block:function(a){if(a)return k(["block",n(H(a,d))])},binary:function(a,b,c){return v(["binary",a,d(b),d(c)],function(a){return o(d(a),this)},function(){return this})},conditional:function(a,b,c){return s(d(a),d(b),d(c))},"try":function(a,b,c){return["try",n(H(a,d)),b!=null?[b[0],n(H(b[1],d))]:null,c!=null?n(H(c,d)):null]},"unary-prefix":function(a,b){b=d(b);var c=["unary-prefix",a,b];a=="!"&&(c=o(c,h(b)));return v(c,function(a,b){return d(a)},function(){return c})},name:function(a){switch(a){case"true":return["unary-prefix","!",["num",0]];case"false":return["unary-prefix","!",["num",1]]}},"new":function(a,b){if(a[0]=="name"&&a[1]=="Array"&&!g.has("Array"))return b.length!=1?["array",b]:["call",["name","Array"],b]},call:function(a,b){if(a[0]=="name"&&a[1]=="Array"&&b.length!=1&&!g.has("Array"))return["array",b]},"while":y,"do":y},function(){return d(l(a))})}function w(a){t(a)||n("Dropping unreachable code: "+B(a,!0))}function u(a){return a[0]=="string"||a[0]=="unary-prefix"&&a[1]=="typeof"||a[0]=="binary"&&a[1]=="+"&&(u(a[2])||u(a[3]))}function t(a){return!a||a[0]=="block"&&(!a[1]||a[1].length==0)}function s(a,b,c){return a[0]=="unary-prefix"&&a[1]=="!"?c?["conditional",a[2],c,b]:["binary","||",a[2],b]:c?["conditional",a,b,c]:["binary","&&",a,b]}function r(a){return a[0]=="unary-prefix"&&f(a[1],["!","delete"])||a[0]=="binary"&&f(a[1],["in","instanceof","==","!=","===","!==","<","<=",">=",">"])||a[0]=="binary"&&f(a[1],["&&","||"])&&r(a[2])&&r(a[3])||a[0]=="conditional"&&r(a[2])&&r(a[3])||a[0]=="assign"&&a[1]===!0&&r(a[3])||a[0]=="seq"&&r(a[a.length-1])}function q(a){if(a){a=p(a);if(a[0]=="return"||a[0]=="break"||a[0]=="continue"||a[0]=="throw")return!0}}function p(a){if(a[0]=="block"&&a[1]&&a[1].length>0)return a[1][a[1].length-1];return a}function o(a,b){return B(a).length>B(b[0]=="stat"?b[1]:b).length?b:a}function m(a,b){function k(a){return[this[0],H(a,function(a){return[g(a[0]),d(a[1])]})]}function j(a,b){var c=e;e=a;for(var d in a.names)G(a.names,d)&&g(d,!0);var f=b();f.scope=a,e=c;return f}function h(a,b,c){a&&(a=g(a)),c=j(c.scope,function(){b=H(b,function(a){return g(a)});return H(c,d)});return[this[0],a,b,c]}function g(a,c){if(!b.toplevel&&!e.parent)return a;if(b.except&&f(a,b.except))return a;return e.get_mangled(a,c)}var c=i(),d=c.walk,e;b=b||{};return c.with_walkers({"function":h,defun:function(){var a=h.apply(this,arguments);switch(c.parent()[0]){case"toplevel":case"function":case"defun":return H.at_top(a)}return a},"var":k,"const":k,name:function(a){return[this[0],g(a)]},"try":function(a,b,c){return[this[0],H(a,d),b!=null?[g(b[0]),H(b[1],d)]:null,c!=null?H(c,d):null]},toplevel:function(a){var b=this;return j(b.scope,function(){return[b[0],H(a,d)]})}},function(){return d(l(a))})}function l(a){function k(a,b,c){return[this[0],g(a),b,f(function(){H(b,g);return H(c,d)})]}function h(a){b.refs[a]=!0}function g(a){return b.define(a)}function f(a){b=new j(b);var c=b.body=a();c.scope=b,b=b.parent;return c}var b=null,c=i(),d=c.walk,e=[];return f(function(){function i(a,b){for(b=a.children.length;--b>=0;)i(a.children[b]);for(b in a.refs)if(G(a.refs,b))for(var c=a.has(b),d=a;d;d=d.parent){d.refs[b]=c;if(d===c)break}}var f=c.with_walkers({"function":k,defun:k,"with":function(a,c){for(var d=b;d;d=d.parent)d.uses_with=!0},"var":function(a){H(a,function(a){g(a[0])})},"const":function(a){H(a,function(a){g(a[0])})},"try":function(a,b,c){if(b!=null)return[this[0],H(a,d),[g(b[0]),H(b[1],d)],c!=null?H(c,d):null]},name:function(a){a=="eval"&&e.push(b),h(a)}},function(){return d(a)});H(e,function(a){if(!a.has("eval"))while(a)a.uses_eval=!0,a=a.parent}),i(b);return f})}function j(a){this.names={},this.mangled={},this.rev_mangled={},this.cname=-1,this.refs={},this.uses_with=!1,this.uses_eval=!1,this.parent=a,this.children=[],a?(this.level=a.level+1,a.children.push(this)):this.level=0}function i(a){function h(a,b){var c={},e;for(e in a)G(a,e)&&(c[e]=d[e],d[e]=a[e]);var f=b();for(e in c)G(c,e)&&(c[e]?d[e]=c[e]:delete d[e]);return f}function g(a){if(a==null)return null;try{f.push(a);var b=a[0],e=d[b];if(e){var g=e.apply(a,a.slice(1));if(g!=null)return g}e=c[b];return e.apply(a,a.slice(1))}finally{f.pop()}}function b(a){return[this[0],H(a,function(a){var b=[a[0]];a.length>1&&(b[1]=g(a[1]));return b})]}var c={string:function(a){return[this[0],a]},num:function(a){return[this[0],a]},name:function(a){return[this[0],a]},toplevel:function(a){return[this[0],H(a,g)]},block:function(a){var b=[this[0]];a!=null&&b.push(H(a,g));return b},"var":b,"const":b,"try":function(a,b,c){return[this[0],H(a,g),b!=null?[b[0],H(b[1],g)]:null,c!=null?H(c,g):null]},"throw":function(a){return[this[0],g(a)]},"new":function(a,b){return[this[0],g(a),H(b,g)]},"switch":function(a,b){return[this[0],g(a),H(b,function(a){return[a[0]?g(a[0]):null,H(a[1],g)]})]},"break":function(a){return[this[0],a]},"continue":function(a){return[this[0],a]},conditional:function(a,b,c){return[this[0],g(a),g(b),g(c)]},assign:function(a,b,c){return[this[0],a,g(b),g(c)]},dot:function(a){return[this[0],g(a)].concat(e(arguments,1))},call:function(a,b){return[this[0],g(a),H(b,g)]},"function":function(a,b,c){return[this[0],a,b.slice(),H(c,g)]},defun:function(a,b,c){return[this[0],a,b.slice(),H(c,g)]},"if":function(a,b,c){return[this[0],g(a),g(b),g(c)]},"for":function(a,b,c,d){return[this[0],g(a),g(b),g(c),g(d)]},"for-in":function(a,b,c,d){return[this[0],g(a),g(b),g(c),g(d)]},"while":function(a,b){return[this[0],g(a),g(b)]},"do":function(a,b){return[this[0],g(a),g(b)]},"return":function(a){return[this[0],g(a)]},binary:function(a,b,c){return[this[0],a,g(b),g(c)]},"unary-prefix":function(a,b){return[this[0],a,g(b)]},"unary-postfix":function(a,b){return[this[0],a,g(b)]},sub:function(a,b){return[this[0],g(a),g(b)]},object:function(a){return[this[0],H(a,function(a){return a.length==2?[a[0],g(a[1])]:[a[0],g(a[1]),a[2]]})]},regexp:function(a,b){return[this[0],a,b]},array:function(a){return[this[0],H(a,g)]},stat:function(a){return[this[0],g(a)]},seq:function(){return[this[0]].concat(H(e(arguments),g))},label:function(a,b){return[this[0],a,g(b)]},"with":function(a,b){return[this[0],g(a),g(b)]},atom:function(a){return[this[0],a]}},d={},f=[];return{walk:g,with_walkers:h,parent:function(){return f[f.length-2]},stack:function(){return f}}}var d=b("./parse-js"),e=d.slice,f=d.member,g=d.PRECEDENCE,h=d.OPERATORS,k=function(){var a="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_";return function(b){var c="";do c=a.charAt(b%54)+c,b=Math.floor(b/54);while(b>0);return c}}();j.prototype={has:function(a){for(var b=this;b;b=b.parent)if(G(b.names,a))return b},has_mangled:function(a){for(var b=this;b;b=b.parent)if(G(b.rev_mangled,a))return b},toJSON:function(){return{names:this.names,uses_eval:this.uses_eval,uses_with:this.uses_with}},next_mangled:function(){for(;;){var a=k(++this.cname),b;b=this.has_mangled(a);if(b&&this.refs[b.rev_mangled[a]]===b)continue;b=this.has(a);if(b&&b!==this&&this.refs[a]===b&&!b.has_mangled(a))continue;if(G(this.refs,a)&&this.refs[a]==null)continue;if(!F(a))continue;return a}},get_mangled:function(a,b){if(this.uses_eval||this.uses_with)return a;var c=this.has(a);if(!c)return a;if(G(c.mangled,a))return c.mangled[a];if(!b)return a;var d=c.next_mangled();c.rev_mangled[d]=a;return c.mangled[a]=d},define:function(a){if(a!=null)return this.names[a]=a}};var n=function(){},v=function(){function b(c){switch(c[0]){case"string":case"num":return c[1];case"name":case"atom":switch(c[1]){case"true":return!0;case"false":return!1}break;case"unary-prefix":switch(c[1]){case"!":return!b(c[2]);case"typeof":return typeof b(c[2]);case"~":return~b(c[2]);case"-":return-b(c[2]);case"+":return+b(c[2])}break;case"binary":var d=c[2],e=c[3];switch(c[1]){case"&&":return b(d)&&b(e);case"||":return b(d)||b(e);case"|":return b(d)|b(e);case"&":return b(d)&b(e);case"^":return b(d)^b(e);case"+":return b(d)+b(e);case"*":return b(d)*b(e);case"/":return b(d)/b(e);case"-":return b(d)-b(e);case"<<":return b(d)<<b(e);case">>":return b(d)>>b(e);case">>>":return b(d)>>>b(e);case"==":return b(d)==b(e);case"===":return b(d)===b(e);case"!=":return b(d)!=b(e);case"!==":return b(d)!==b(e);case"<":return b(d)<b(e);case"<=":return b(d)<=b(e);case">":return b(d)>b(e);case">=":return b(d)>=b(e);case"in":return b(d)in b(e);case"instanceof":return b(d)instanceof b(e)}}throw a}var a={};return function(c,d,e){try{var f=b(c),g;switch(typeof f){case"string":g=["string",f];break;case"number":g=["num",f];break;case"boolean":g=["name",String(f)];break;default:throw new Error("Can't handle constant of type: "+typeof f)}return d.call(c,g,f)}catch(h){if(h===a){c[0]=="binary"&&(c[1]=="==="||c[1]=="!==")&&(u(c[2])&&u(c[3])||r(c[2])&&r(c[3]))&&(c[1]=c[1].substr(0,2));return e?e.call(c,c):null}throw h}}}(),y=d.array_to_hash(["name","array","object","string","dot","sub","call","regexp"]),H;(function(){function a(a){this.v=a}H=function(b,c,d){var e=[];for(var f=0;f<b.length;++f){var g=c.call(d,b[f],f);g instanceof a?e.unshift(g.v):e.push(g)}return e},H.at_top=function(b){return new a(b)}})(),a.ast_walker=i,a.ast_mangle=m,a.ast_squeeze=x,a.gen_code=B,a.ast_add_scope=l,a.set_logger=function(a){n=a},a.make_string=z,a.split_lines=C,a.MAP=H,a.ast_squeeze_more=b("./squeeze-more").ast_squeeze_more},"squeeze-more":function(a,b,c){function j(a){var b=e.ast_walker(),c=b.walk;return b.with_walkers({call:function(a,b){if(a[0]=="dot"&&a[2]=="toString"&&b.length==0)return["binary","+",a[1],["string",""]]}},function(){return c(a)})}var d=b("./parse-js"),e=b("./process"),f=d.slice,g=d.member,h=d.PRECEDENCE,i=d.OPERATORS;a.ast_squeeze_more=j}}),a.UglifyJS={},a.UglifyJS.parser=this.require("parse-js"),a.UglifyJS.uglify=this.require("process")}).call({},this)
1
+ (function(global) {
2
+ (function(/*! Stitch !*/) {
3
+ if (!this.require) {
4
+ var modules = {}, cache = {}, require = function(name, root) {
5
+ var module = cache[name], path = expand(root, name), fn;
6
+ if (module) {
7
+ return module;
8
+ } else if (fn = modules[path] || modules[path = expand(path, './index')]) {
9
+ module = {id: name, exports: {}};
10
+ try {
11
+ cache[name] = module.exports;
12
+ fn(module.exports, function(name) {
13
+ return require(name, dirname(path));
14
+ }, module);
15
+ return cache[name] = module.exports;
16
+ } catch (err) {
17
+ delete cache[name];
18
+ throw err;
19
+ }
20
+ } else {
21
+ throw 'module \'' + name + '\' not found';
22
+ }
23
+ }, expand = function(root, name) {
24
+ var results = [], parts, part;
25
+ if (/^\.\.?(\/|$)/.test(name)) {
26
+ parts = [root, name].join('/').split('/');
27
+ } else {
28
+ parts = name.split('/');
29
+ }
30
+ for (var i = 0, length = parts.length; i < length; i++) {
31
+ part = parts[i];
32
+ if (part == '..') {
33
+ results.pop();
34
+ } else if (part != '.' && part != '') {
35
+ results.push(part);
36
+ }
37
+ }
38
+ return results.join('/');
39
+ }, dirname = function(path) {
40
+ return path.split('/').slice(0, -1).join('/');
41
+ };
42
+ this.require = function(name) {
43
+ return require(name, '');
44
+ }
45
+ this.require.define = function(bundle) {
46
+ for (var key in bundle)
47
+ modules[key] = bundle[key];
48
+ };
49
+ }
50
+ return this.require.define;
51
+ }).call(this)({"parse-js": function(exports, require, module) {
52
+ /***********************************************************************
53
+
54
+ A JavaScript tokenizer / parser / beautifier / compressor.
55
+
56
+ This version is suitable for Node.js. With minimal changes (the
57
+ exports stuff) it should work on any JS platform.
58
+
59
+ This file contains the tokenizer/parser. It is a port to JavaScript
60
+ of parse-js [1], a JavaScript parser library written in Common Lisp
61
+ by Marijn Haverbeke. Thank you Marijn!
62
+
63
+ [1] http://marijn.haverbeke.nl/parse-js/
64
+
65
+ Exported functions:
66
+
67
+ - tokenizer(code) -- returns a function. Call the returned
68
+ function to fetch the next token.
69
+
70
+ - parse(code) -- returns an AST of the given JavaScript code.
71
+
72
+ -------------------------------- (C) ---------------------------------
73
+
74
+ Author: Mihai Bazon
75
+ <mihai.bazon@gmail.com>
76
+ http://mihai.bazon.net/blog
77
+
78
+ Distributed under the BSD license:
79
+
80
+ Copyright 2010 (c) Mihai Bazon <mihai.bazon@gmail.com>
81
+ Based on parse-js (http://marijn.haverbeke.nl/parse-js/).
82
+
83
+ Redistribution and use in source and binary forms, with or without
84
+ modification, are permitted provided that the following conditions
85
+ are met:
86
+
87
+ * Redistributions of source code must retain the above
88
+ copyright notice, this list of conditions and the following
89
+ disclaimer.
90
+
91
+ * Redistributions in binary form must reproduce the above
92
+ copyright notice, this list of conditions and the following
93
+ disclaimer in the documentation and/or other materials
94
+ provided with the distribution.
95
+
96
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
97
+ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
98
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
99
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
100
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
101
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
102
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
103
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
104
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
105
+ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
106
+ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
107
+ SUCH DAMAGE.
108
+
109
+ ***********************************************************************/
110
+
111
+ /* -----[ Tokenizer (constants) ]----- */
112
+
113
+ var KEYWORDS = array_to_hash([
114
+ "break",
115
+ "case",
116
+ "catch",
117
+ "const",
118
+ "continue",
119
+ "default",
120
+ "delete",
121
+ "do",
122
+ "else",
123
+ "finally",
124
+ "for",
125
+ "function",
126
+ "if",
127
+ "in",
128
+ "instanceof",
129
+ "new",
130
+ "return",
131
+ "switch",
132
+ "throw",
133
+ "try",
134
+ "typeof",
135
+ "var",
136
+ "void",
137
+ "while",
138
+ "with"
139
+ ]);
140
+
141
+ var RESERVED_WORDS = array_to_hash([
142
+ "abstract",
143
+ "boolean",
144
+ "byte",
145
+ "char",
146
+ "class",
147
+ "debugger",
148
+ "double",
149
+ "enum",
150
+ "export",
151
+ "extends",
152
+ "final",
153
+ "float",
154
+ "goto",
155
+ "implements",
156
+ "import",
157
+ "int",
158
+ "interface",
159
+ "long",
160
+ "native",
161
+ "package",
162
+ "private",
163
+ "protected",
164
+ "public",
165
+ "short",
166
+ "static",
167
+ "super",
168
+ "synchronized",
169
+ "throws",
170
+ "transient",
171
+ "volatile"
172
+ ]);
173
+
174
+ var KEYWORDS_BEFORE_EXPRESSION = array_to_hash([
175
+ "return",
176
+ "new",
177
+ "delete",
178
+ "throw",
179
+ "else",
180
+ "case"
181
+ ]);
182
+
183
+ var KEYWORDS_ATOM = array_to_hash([
184
+ "false",
185
+ "null",
186
+ "true",
187
+ "undefined"
188
+ ]);
189
+
190
+ var OPERATOR_CHARS = array_to_hash(characters("+-*&%=<>!?|~^"));
191
+
192
+ var RE_HEX_NUMBER = /^0x[0-9a-f]+$/i;
193
+ var RE_OCT_NUMBER = /^0[0-7]+$/;
194
+ var RE_DEC_NUMBER = /^\d*\.?\d*(?:e[+-]?\d*(?:\d\.?|\.?\d)\d*)?$/i;
195
+
196
+ var OPERATORS = array_to_hash([
197
+ "in",
198
+ "instanceof",
199
+ "typeof",
200
+ "new",
201
+ "void",
202
+ "delete",
203
+ "++",
204
+ "--",
205
+ "+",
206
+ "-",
207
+ "!",
208
+ "~",
209
+ "&",
210
+ "|",
211
+ "^",
212
+ "*",
213
+ "/",
214
+ "%",
215
+ ">>",
216
+ "<<",
217
+ ">>>",
218
+ "<",
219
+ ">",
220
+ "<=",
221
+ ">=",
222
+ "==",
223
+ "===",
224
+ "!=",
225
+ "!==",
226
+ "?",
227
+ "=",
228
+ "+=",
229
+ "-=",
230
+ "/=",
231
+ "*=",
232
+ "%=",
233
+ ">>=",
234
+ "<<=",
235
+ ">>>=",
236
+ "|=",
237
+ "^=",
238
+ "&=",
239
+ "&&",
240
+ "||"
241
+ ]);
242
+
243
+ var WHITESPACE_CHARS = array_to_hash(characters(" \n\r\t\u200b"));
244
+
245
+ var PUNC_BEFORE_EXPRESSION = array_to_hash(characters("[{}(,.;:"));
246
+
247
+ var PUNC_CHARS = array_to_hash(characters("[]{}(),;:"));
248
+
249
+ var REGEXP_MODIFIERS = array_to_hash(characters("gmsiy"));
250
+
251
+ /* -----[ Tokenizer ]----- */
252
+
253
+ // regexps adapted from http://xregexp.com/plugins/#unicode
254
+ var UNICODE = {
255
+ letter: new RegExp("[\\u0041-\\u005A\\u0061-\\u007A\\u00AA\\u00B5\\u00BA\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0370-\\u0374\\u0376\\u0377\\u037A-\\u037D\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u048A-\\u0523\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0621-\\u064A\\u066E\\u066F\\u0671-\\u06D3\\u06D5\\u06E5\\u06E6\\u06EE\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4\\u07F5\\u07FA\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0971\\u0972\\u097B-\\u097F\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC\\u09DD\\u09DF-\\u09E1\\u09F0\\u09F1\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0\\u0AE1\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C33\\u0C35-\\u0C39\\u0C3D\\u0C58\\u0C59\\u0C60\\u0C61\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDE\\u0CE0\\u0CE1\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D28\\u0D2A-\\u0D39\\u0D3D\\u0D60\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32\\u0E33\\u0E40-\\u0E46\\u0E81\\u0E82\\u0E84\\u0E87\\u0E88\\u0E8A\\u0E8D\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB0\\u0EB2\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EDC\\u0EDD\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8B\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10A0-\\u10C5\\u10D0-\\u10FA\\u10FC\\u1100-\\u1159\\u115F-\\u11A2\\u11A8-\\u11F9\\u1200-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F4\\u1401-\\u166C\\u166F-\\u1676\\u1681-\\u169A\\u16A0-\\u16EA\\u1700-\\u170C\\u170E-\\u1711\\u1720-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17D7\\u17DC\\u1820-\\u1877\\u1880-\\u18A8\\u18AA\\u1900-\\u191C\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19A9\\u19C1-\\u19C7\\u1A00-\\u1A16\\u1B05-\\u1B33\\u1B45-\\u1B4B\\u1B83-\\u1BA0\\u1BAE\\u1BAF\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C7D\\u1D00-\\u1DBF\\u1E00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4\\u1FF6-\\u1FFC\\u2071\\u207F\\u2090-\\u2094\\u2102\\u2107\\u210A-\\u2113\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u212F-\\u2139\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2183\\u2184\\u2C00-\\u2C2E\\u2C30-\\u2C5E\\u2C60-\\u2C6F\\u2C71-\\u2C7D\\u2C80-\\u2CE4\\u2D00-\\u2D25\\u2D30-\\u2D65\\u2D6F\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u2E2F\\u3005\\u3006\\u3031-\\u3035\\u303B\\u303C\\u3041-\\u3096\\u309D-\\u309F\\u30A1-\\u30FA\\u30FC-\\u30FF\\u3105-\\u312D\\u3131-\\u318E\\u31A0-\\u31B7\\u31F0-\\u31FF\\u3400\\u4DB5\\u4E00\\u9FC3\\uA000-\\uA48C\\uA500-\\uA60C\\uA610-\\uA61F\\uA62A\\uA62B\\uA640-\\uA65F\\uA662-\\uA66E\\uA67F-\\uA697\\uA717-\\uA71F\\uA722-\\uA788\\uA78B\\uA78C\\uA7FB-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA90A-\\uA925\\uA930-\\uA946\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAC00\\uD7A3\\uF900-\\uFA2D\\uFA30-\\uFA6A\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF21-\\uFF3A\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC]"),
256
+ non_spacing_mark: new RegExp("[\\u0300-\\u036F\\u0483-\\u0487\\u0591-\\u05BD\\u05BF\\u05C1\\u05C2\\u05C4\\u05C5\\u05C7\\u0610-\\u061A\\u064B-\\u065E\\u0670\\u06D6-\\u06DC\\u06DF-\\u06E4\\u06E7\\u06E8\\u06EA-\\u06ED\\u0711\\u0730-\\u074A\\u07A6-\\u07B0\\u07EB-\\u07F3\\u0816-\\u0819\\u081B-\\u0823\\u0825-\\u0827\\u0829-\\u082D\\u0900-\\u0902\\u093C\\u0941-\\u0948\\u094D\\u0951-\\u0955\\u0962\\u0963\\u0981\\u09BC\\u09C1-\\u09C4\\u09CD\\u09E2\\u09E3\\u0A01\\u0A02\\u0A3C\\u0A41\\u0A42\\u0A47\\u0A48\\u0A4B-\\u0A4D\\u0A51\\u0A70\\u0A71\\u0A75\\u0A81\\u0A82\\u0ABC\\u0AC1-\\u0AC5\\u0AC7\\u0AC8\\u0ACD\\u0AE2\\u0AE3\\u0B01\\u0B3C\\u0B3F\\u0B41-\\u0B44\\u0B4D\\u0B56\\u0B62\\u0B63\\u0B82\\u0BC0\\u0BCD\\u0C3E-\\u0C40\\u0C46-\\u0C48\\u0C4A-\\u0C4D\\u0C55\\u0C56\\u0C62\\u0C63\\u0CBC\\u0CBF\\u0CC6\\u0CCC\\u0CCD\\u0CE2\\u0CE3\\u0D41-\\u0D44\\u0D4D\\u0D62\\u0D63\\u0DCA\\u0DD2-\\u0DD4\\u0DD6\\u0E31\\u0E34-\\u0E3A\\u0E47-\\u0E4E\\u0EB1\\u0EB4-\\u0EB9\\u0EBB\\u0EBC\\u0EC8-\\u0ECD\\u0F18\\u0F19\\u0F35\\u0F37\\u0F39\\u0F71-\\u0F7E\\u0F80-\\u0F84\\u0F86\\u0F87\\u0F90-\\u0F97\\u0F99-\\u0FBC\\u0FC6\\u102D-\\u1030\\u1032-\\u1037\\u1039\\u103A\\u103D\\u103E\\u1058\\u1059\\u105E-\\u1060\\u1071-\\u1074\\u1082\\u1085\\u1086\\u108D\\u109D\\u135F\\u1712-\\u1714\\u1732-\\u1734\\u1752\\u1753\\u1772\\u1773\\u17B7-\\u17BD\\u17C6\\u17C9-\\u17D3\\u17DD\\u180B-\\u180D\\u18A9\\u1920-\\u1922\\u1927\\u1928\\u1932\\u1939-\\u193B\\u1A17\\u1A18\\u1A56\\u1A58-\\u1A5E\\u1A60\\u1A62\\u1A65-\\u1A6C\\u1A73-\\u1A7C\\u1A7F\\u1B00-\\u1B03\\u1B34\\u1B36-\\u1B3A\\u1B3C\\u1B42\\u1B6B-\\u1B73\\u1B80\\u1B81\\u1BA2-\\u1BA5\\u1BA8\\u1BA9\\u1C2C-\\u1C33\\u1C36\\u1C37\\u1CD0-\\u1CD2\\u1CD4-\\u1CE0\\u1CE2-\\u1CE8\\u1CED\\u1DC0-\\u1DE6\\u1DFD-\\u1DFF\\u20D0-\\u20DC\\u20E1\\u20E5-\\u20F0\\u2CEF-\\u2CF1\\u2DE0-\\u2DFF\\u302A-\\u302F\\u3099\\u309A\\uA66F\\uA67C\\uA67D\\uA6F0\\uA6F1\\uA802\\uA806\\uA80B\\uA825\\uA826\\uA8C4\\uA8E0-\\uA8F1\\uA926-\\uA92D\\uA947-\\uA951\\uA980-\\uA982\\uA9B3\\uA9B6-\\uA9B9\\uA9BC\\uAA29-\\uAA2E\\uAA31\\uAA32\\uAA35\\uAA36\\uAA43\\uAA4C\\uAAB0\\uAAB2-\\uAAB4\\uAAB7\\uAAB8\\uAABE\\uAABF\\uAAC1\\uABE5\\uABE8\\uABED\\uFB1E\\uFE00-\\uFE0F\\uFE20-\\uFE26]"),
257
+ space_combining_mark: new RegExp("[\\u0903\\u093E-\\u0940\\u0949-\\u094C\\u094E\\u0982\\u0983\\u09BE-\\u09C0\\u09C7\\u09C8\\u09CB\\u09CC\\u09D7\\u0A03\\u0A3E-\\u0A40\\u0A83\\u0ABE-\\u0AC0\\u0AC9\\u0ACB\\u0ACC\\u0B02\\u0B03\\u0B3E\\u0B40\\u0B47\\u0B48\\u0B4B\\u0B4C\\u0B57\\u0BBE\\u0BBF\\u0BC1\\u0BC2\\u0BC6-\\u0BC8\\u0BCA-\\u0BCC\\u0BD7\\u0C01-\\u0C03\\u0C41-\\u0C44\\u0C82\\u0C83\\u0CBE\\u0CC0-\\u0CC4\\u0CC7\\u0CC8\\u0CCA\\u0CCB\\u0CD5\\u0CD6\\u0D02\\u0D03\\u0D3E-\\u0D40\\u0D46-\\u0D48\\u0D4A-\\u0D4C\\u0D57\\u0D82\\u0D83\\u0DCF-\\u0DD1\\u0DD8-\\u0DDF\\u0DF2\\u0DF3\\u0F3E\\u0F3F\\u0F7F\\u102B\\u102C\\u1031\\u1038\\u103B\\u103C\\u1056\\u1057\\u1062-\\u1064\\u1067-\\u106D\\u1083\\u1084\\u1087-\\u108C\\u108F\\u109A-\\u109C\\u17B6\\u17BE-\\u17C5\\u17C7\\u17C8\\u1923-\\u1926\\u1929-\\u192B\\u1930\\u1931\\u1933-\\u1938\\u19B0-\\u19C0\\u19C8\\u19C9\\u1A19-\\u1A1B\\u1A55\\u1A57\\u1A61\\u1A63\\u1A64\\u1A6D-\\u1A72\\u1B04\\u1B35\\u1B3B\\u1B3D-\\u1B41\\u1B43\\u1B44\\u1B82\\u1BA1\\u1BA6\\u1BA7\\u1BAA\\u1C24-\\u1C2B\\u1C34\\u1C35\\u1CE1\\u1CF2\\uA823\\uA824\\uA827\\uA880\\uA881\\uA8B4-\\uA8C3\\uA952\\uA953\\uA983\\uA9B4\\uA9B5\\uA9BA\\uA9BB\\uA9BD-\\uA9C0\\uAA2F\\uAA30\\uAA33\\uAA34\\uAA4D\\uAA7B\\uABE3\\uABE4\\uABE6\\uABE7\\uABE9\\uABEA\\uABEC]"),
258
+ connector_punctuation: new RegExp("[\\u005F\\u203F\\u2040\\u2054\\uFE33\\uFE34\\uFE4D-\\uFE4F\\uFF3F]")
259
+ };
260
+
261
+ function is_letter(ch) {
262
+ return UNICODE.letter.test(ch);
263
+ };
264
+
265
+ function is_digit(ch) {
266
+ ch = ch.charCodeAt(0);
267
+ return ch >= 48 && ch <= 57; //XXX: find out if "UnicodeDigit" means something else than 0..9
268
+ };
269
+
270
+ function is_alphanumeric_char(ch) {
271
+ return is_digit(ch) || is_letter(ch);
272
+ };
273
+
274
+ function is_unicode_combining_mark(ch) {
275
+ return UNICODE.non_spacing_mark.test(ch) || UNICODE.space_combining_mark.test(ch);
276
+ };
277
+
278
+ function is_unicode_connector_punctuation(ch) {
279
+ return UNICODE.connector_punctuation.test(ch);
280
+ };
281
+
282
+ function is_identifier_start(ch) {
283
+ return ch == "$" || ch == "_" || is_letter(ch);
284
+ };
285
+
286
+ function is_identifier_char(ch) {
287
+ return is_identifier_start(ch)
288
+ || is_unicode_combining_mark(ch)
289
+ || is_digit(ch)
290
+ || is_unicode_connector_punctuation(ch)
291
+ || ch == "\u200c" // zero-width non-joiner <ZWNJ>
292
+ || ch == "\u200d" // zero-width joiner <ZWJ> (in my ECMA-262 PDF, this is also 200c)
293
+ ;
294
+ };
295
+
296
+ function parse_js_number(num) {
297
+ if (RE_HEX_NUMBER.test(num)) {
298
+ return parseInt(num.substr(2), 16);
299
+ } else if (RE_OCT_NUMBER.test(num)) {
300
+ return parseInt(num.substr(1), 8);
301
+ } else if (RE_DEC_NUMBER.test(num)) {
302
+ return parseFloat(num);
303
+ }
304
+ };
305
+
306
+ function JS_Parse_Error(message, line, col, pos) {
307
+ this.message = message;
308
+ this.line = line;
309
+ this.col = col;
310
+ this.pos = pos;
311
+ try {
312
+ ({})();
313
+ } catch(ex) {
314
+ this.stack = ex.stack;
315
+ };
316
+ };
317
+
318
+ JS_Parse_Error.prototype.toString = function() {
319
+ return this.message + " (line: " + this.line + ", col: " + this.col + ", pos: " + this.pos + ")" + "\n\n" + this.stack;
320
+ };
321
+
322
+ function js_error(message, line, col, pos) {
323
+ throw new JS_Parse_Error(message, line, col, pos);
324
+ };
325
+
326
+ function is_token(token, type, val) {
327
+ return token.type == type && (val == null || token.value == val);
328
+ };
329
+
330
+ var EX_EOF = {};
331
+
332
+ function tokenizer($TEXT) {
333
+
334
+ var S = {
335
+ text : $TEXT.replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uFEFF/, ''),
336
+ pos : 0,
337
+ tokpos : 0,
338
+ line : 0,
339
+ tokline : 0,
340
+ col : 0,
341
+ tokcol : 0,
342
+ newline_before : false,
343
+ regex_allowed : false,
344
+ comments_before : []
345
+ };
346
+
347
+ function peek() { return S.text.charAt(S.pos); };
348
+
349
+ function next(signal_eof) {
350
+ var ch = S.text.charAt(S.pos++);
351
+ if (signal_eof && !ch)
352
+ throw EX_EOF;
353
+ if (ch == "\n") {
354
+ S.newline_before = true;
355
+ ++S.line;
356
+ S.col = 0;
357
+ } else {
358
+ ++S.col;
359
+ }
360
+ return ch;
361
+ };
362
+
363
+ function eof() {
364
+ return !S.peek();
365
+ };
366
+
367
+ function find(what, signal_eof) {
368
+ var pos = S.text.indexOf(what, S.pos);
369
+ if (signal_eof && pos == -1) throw EX_EOF;
370
+ return pos;
371
+ };
372
+
373
+ function start_token() {
374
+ S.tokline = S.line;
375
+ S.tokcol = S.col;
376
+ S.tokpos = S.pos;
377
+ };
378
+
379
+ function token(type, value, is_comment) {
380
+ S.regex_allowed = ((type == "operator" && !HOP(UNARY_POSTFIX, value)) ||
381
+ (type == "keyword" && HOP(KEYWORDS_BEFORE_EXPRESSION, value)) ||
382
+ (type == "punc" && HOP(PUNC_BEFORE_EXPRESSION, value)));
383
+ var ret = {
384
+ type : type,
385
+ value : value,
386
+ line : S.tokline,
387
+ col : S.tokcol,
388
+ pos : S.tokpos,
389
+ nlb : S.newline_before
390
+ };
391
+ if (!is_comment) {
392
+ ret.comments_before = S.comments_before;
393
+ S.comments_before = [];
394
+ }
395
+ S.newline_before = false;
396
+ return ret;
397
+ };
398
+
399
+ function skip_whitespace() {
400
+ while (HOP(WHITESPACE_CHARS, peek()))
401
+ next();
402
+ };
403
+
404
+ function read_while(pred) {
405
+ var ret = "", ch = peek(), i = 0;
406
+ while (ch && pred(ch, i++)) {
407
+ ret += next();
408
+ ch = peek();
409
+ }
410
+ return ret;
411
+ };
412
+
413
+ function parse_error(err) {
414
+ js_error(err, S.tokline, S.tokcol, S.tokpos);
415
+ };
416
+
417
+ function read_num(prefix) {
418
+ var has_e = false, after_e = false, has_x = false, has_dot = prefix == ".";
419
+ var num = read_while(function(ch, i){
420
+ if (ch == "x" || ch == "X") {
421
+ if (has_x) return false;
422
+ return has_x = true;
423
+ }
424
+ if (!has_x && (ch == "E" || ch == "e")) {
425
+ if (has_e) return false;
426
+ return has_e = after_e = true;
427
+ }
428
+ if (ch == "-") {
429
+ if (after_e || (i == 0 && !prefix)) return true;
430
+ return false;
431
+ }
432
+ if (ch == "+") return after_e;
433
+ after_e = false;
434
+ if (ch == ".") {
435
+ if (!has_dot && !has_x)
436
+ return has_dot = true;
437
+ return false;
438
+ }
439
+ return is_alphanumeric_char(ch);
440
+ });
441
+ if (prefix)
442
+ num = prefix + num;
443
+ var valid = parse_js_number(num);
444
+ if (!isNaN(valid)) {
445
+ return token("num", valid);
446
+ } else {
447
+ parse_error("Invalid syntax: " + num);
448
+ }
449
+ };
450
+
451
+ function read_escaped_char() {
452
+ var ch = next(true);
453
+ switch (ch) {
454
+ case "n" : return "\n";
455
+ case "r" : return "\r";
456
+ case "t" : return "\t";
457
+ case "b" : return "\b";
458
+ case "v" : return "\v";
459
+ case "f" : return "\f";
460
+ case "0" : return "\0";
461
+ case "x" : return String.fromCharCode(hex_bytes(2));
462
+ case "u" : return String.fromCharCode(hex_bytes(4));
463
+ default : return ch;
464
+ }
465
+ };
466
+
467
+ function hex_bytes(n) {
468
+ var num = 0;
469
+ for (; n > 0; --n) {
470
+ var digit = parseInt(next(true), 16);
471
+ if (isNaN(digit))
472
+ parse_error("Invalid hex-character pattern in string");
473
+ num = (num << 4) | digit;
474
+ }
475
+ return num;
476
+ };
477
+
478
+ function read_string() {
479
+ return with_eof_error("Unterminated string constant", function(){
480
+ var quote = next(), ret = "";
481
+ for (;;) {
482
+ var ch = next(true);
483
+ if (ch == "\\") ch = read_escaped_char();
484
+ else if (ch == quote) break;
485
+ ret += ch;
486
+ }
487
+ return token("string", ret);
488
+ });
489
+ };
490
+
491
+ function read_line_comment() {
492
+ next();
493
+ var i = find("\n"), ret;
494
+ if (i == -1) {
495
+ ret = S.text.substr(S.pos);
496
+ S.pos = S.text.length;
497
+ } else {
498
+ ret = S.text.substring(S.pos, i);
499
+ S.pos = i;
500
+ }
501
+ return token("comment1", ret, true);
502
+ };
503
+
504
+ function read_multiline_comment() {
505
+ next();
506
+ return with_eof_error("Unterminated multiline comment", function(){
507
+ var i = find("*/", true),
508
+ text = S.text.substring(S.pos, i),
509
+ tok = token("comment2", text, true);
510
+ S.pos = i + 2;
511
+ S.line += text.split("\n").length - 1;
512
+ S.newline_before = text.indexOf("\n") >= 0;
513
+
514
+ // https://github.com/mishoo/UglifyJS/issues/#issue/100
515
+ if (/^@cc_on/i.test(text)) {
516
+ warn("WARNING: at line " + S.line);
517
+ warn("*** Found \"conditional comment\": " + text);
518
+ warn("*** UglifyJS DISCARDS ALL COMMENTS. This means your code might no longer work properly in Internet Explorer.");
519
+ }
520
+
521
+ return tok;
522
+ });
523
+ };
524
+
525
+ function read_name() {
526
+ var backslash = false, name = "", ch;
527
+ while ((ch = peek()) != null) {
528
+ if (!backslash) {
529
+ if (ch == "\\") backslash = true, next();
530
+ else if (is_identifier_char(ch)) name += next();
531
+ else break;
532
+ }
533
+ else {
534
+ if (ch != "u") parse_error("Expecting UnicodeEscapeSequence -- uXXXX");
535
+ ch = read_escaped_char();
536
+ if (!is_identifier_char(ch)) parse_error("Unicode char: " + ch.charCodeAt(0) + " is not valid in identifier");
537
+ name += ch;
538
+ backslash = false;
539
+ }
540
+ }
541
+ return name;
542
+ };
543
+
544
+ function read_regexp() {
545
+ return with_eof_error("Unterminated regular expression", function(){
546
+ var prev_backslash = false, regexp = "", ch, in_class = false;
547
+ while ((ch = next(true))) if (prev_backslash) {
548
+ regexp += "\\" + ch;
549
+ prev_backslash = false;
550
+ } else if (ch == "[") {
551
+ in_class = true;
552
+ regexp += ch;
553
+ } else if (ch == "]" && in_class) {
554
+ in_class = false;
555
+ regexp += ch;
556
+ } else if (ch == "/" && !in_class) {
557
+ break;
558
+ } else if (ch == "\\") {
559
+ prev_backslash = true;
560
+ } else {
561
+ regexp += ch;
562
+ }
563
+ var mods = read_name();
564
+ return token("regexp", [ regexp, mods ]);
565
+ });
566
+ };
567
+
568
+ function read_operator(prefix) {
569
+ function grow(op) {
570
+ if (!peek()) return op;
571
+ var bigger = op + peek();
572
+ if (HOP(OPERATORS, bigger)) {
573
+ next();
574
+ return grow(bigger);
575
+ } else {
576
+ return op;
577
+ }
578
+ };
579
+ return token("operator", grow(prefix || next()));
580
+ };
581
+
582
+ function handle_slash() {
583
+ next();
584
+ var regex_allowed = S.regex_allowed;
585
+ switch (peek()) {
586
+ case "/":
587
+ S.comments_before.push(read_line_comment());
588
+ S.regex_allowed = regex_allowed;
589
+ return next_token();
590
+ case "*":
591
+ S.comments_before.push(read_multiline_comment());
592
+ S.regex_allowed = regex_allowed;
593
+ return next_token();
594
+ }
595
+ return S.regex_allowed ? read_regexp() : read_operator("/");
596
+ };
597
+
598
+ function handle_dot() {
599
+ next();
600
+ return is_digit(peek())
601
+ ? read_num(".")
602
+ : token("punc", ".");
603
+ };
604
+
605
+ function read_word() {
606
+ var word = read_name();
607
+ return !HOP(KEYWORDS, word)
608
+ ? token("name", word)
609
+ : HOP(OPERATORS, word)
610
+ ? token("operator", word)
611
+ : HOP(KEYWORDS_ATOM, word)
612
+ ? token("atom", word)
613
+ : token("keyword", word);
614
+ };
615
+
616
+ function with_eof_error(eof_error, cont) {
617
+ try {
618
+ return cont();
619
+ } catch(ex) {
620
+ if (ex === EX_EOF) parse_error(eof_error);
621
+ else throw ex;
622
+ }
623
+ };
624
+
625
+ function next_token(force_regexp) {
626
+ if (force_regexp)
627
+ return read_regexp();
628
+ skip_whitespace();
629
+ start_token();
630
+ var ch = peek();
631
+ if (!ch) return token("eof");
632
+ if (is_digit(ch)) return read_num();
633
+ if (ch == '"' || ch == "'") return read_string();
634
+ if (HOP(PUNC_CHARS, ch)) return token("punc", next());
635
+ if (ch == ".") return handle_dot();
636
+ if (ch == "/") return handle_slash();
637
+ if (HOP(OPERATOR_CHARS, ch)) return read_operator();
638
+ if (ch == "\\" || is_identifier_start(ch)) return read_word();
639
+ parse_error("Unexpected character '" + ch + "'");
640
+ };
641
+
642
+ next_token.context = function(nc) {
643
+ if (nc) S = nc;
644
+ return S;
645
+ };
646
+
647
+ return next_token;
648
+
649
+ };
650
+
651
+ /* -----[ Parser (constants) ]----- */
652
+
653
+ var UNARY_PREFIX = array_to_hash([
654
+ "typeof",
655
+ "void",
656
+ "delete",
657
+ "--",
658
+ "++",
659
+ "!",
660
+ "~",
661
+ "-",
662
+ "+"
663
+ ]);
664
+
665
+ var UNARY_POSTFIX = array_to_hash([ "--", "++" ]);
666
+
667
+ var ASSIGNMENT = (function(a, ret, i){
668
+ while (i < a.length) {
669
+ ret[a[i]] = a[i].substr(0, a[i].length - 1);
670
+ i++;
671
+ }
672
+ return ret;
673
+ })(
674
+ ["+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&="],
675
+ { "=": true },
676
+ 0
677
+ );
678
+
679
+ var PRECEDENCE = (function(a, ret){
680
+ for (var i = 0, n = 1; i < a.length; ++i, ++n) {
681
+ var b = a[i];
682
+ for (var j = 0; j < b.length; ++j) {
683
+ ret[b[j]] = n;
684
+ }
685
+ }
686
+ return ret;
687
+ })(
688
+ [
689
+ ["||"],
690
+ ["&&"],
691
+ ["|"],
692
+ ["^"],
693
+ ["&"],
694
+ ["==", "===", "!=", "!=="],
695
+ ["<", ">", "<=", ">=", "in", "instanceof"],
696
+ [">>", "<<", ">>>"],
697
+ ["+", "-"],
698
+ ["*", "/", "%"]
699
+ ],
700
+ {}
701
+ );
702
+
703
+ var STATEMENTS_WITH_LABELS = array_to_hash([ "for", "do", "while", "switch" ]);
704
+
705
+ var ATOMIC_START_TOKEN = array_to_hash([ "atom", "num", "string", "regexp", "name" ]);
706
+
707
+ /* -----[ Parser ]----- */
708
+
709
+ function NodeWithToken(str, start, end) {
710
+ this.name = str;
711
+ this.start = start;
712
+ this.end = end;
713
+ };
714
+
715
+ NodeWithToken.prototype.toString = function() { return this.name; };
716
+
717
+ function parse($TEXT, exigent_mode, embed_tokens) {
718
+
719
+ var S = {
720
+ input : typeof $TEXT == "string" ? tokenizer($TEXT, true) : $TEXT,
721
+ token : null,
722
+ prev : null,
723
+ peeked : null,
724
+ in_function : 0,
725
+ in_loop : 0,
726
+ labels : []
727
+ };
728
+
729
+ S.token = next();
730
+
731
+ function is(type, value) {
732
+ return is_token(S.token, type, value);
733
+ };
734
+
735
+ function peek() { return S.peeked || (S.peeked = S.input()); };
736
+
737
+ function next() {
738
+ S.prev = S.token;
739
+ if (S.peeked) {
740
+ S.token = S.peeked;
741
+ S.peeked = null;
742
+ } else {
743
+ S.token = S.input();
744
+ }
745
+ return S.token;
746
+ };
747
+
748
+ function prev() {
749
+ return S.prev;
750
+ };
751
+
752
+ function croak(msg, line, col, pos) {
753
+ var ctx = S.input.context();
754
+ js_error(msg,
755
+ line != null ? line : ctx.tokline,
756
+ col != null ? col : ctx.tokcol,
757
+ pos != null ? pos : ctx.tokpos);
758
+ };
759
+
760
+ function token_error(token, msg) {
761
+ croak(msg, token.line, token.col);
762
+ };
763
+
764
+ function unexpected(token) {
765
+ if (token == null)
766
+ token = S.token;
767
+ token_error(token, "Unexpected token: " + token.type + " (" + token.value + ")");
768
+ };
769
+
770
+ function expect_token(type, val) {
771
+ if (is(type, val)) {
772
+ return next();
773
+ }
774
+ token_error(S.token, "Unexpected token " + S.token.type + ", expected " + type);
775
+ };
776
+
777
+ function expect(punc) { return expect_token("punc", punc); };
778
+
779
+ function can_insert_semicolon() {
780
+ return !exigent_mode && (
781
+ S.token.nlb || is("eof") || is("punc", "}")
782
+ );
783
+ };
784
+
785
+ function semicolon() {
786
+ if (is("punc", ";")) next();
787
+ else if (!can_insert_semicolon()) unexpected();
788
+ };
789
+
790
+ function as() {
791
+ return slice(arguments);
792
+ };
793
+
794
+ function parenthesised() {
795
+ expect("(");
796
+ var ex = expression();
797
+ expect(")");
798
+ return ex;
799
+ };
800
+
801
+ function add_tokens(str, start, end) {
802
+ return str instanceof NodeWithToken ? str : new NodeWithToken(str, start, end);
803
+ };
804
+
805
+ var statement = embed_tokens ? function() {
806
+ var start = S.token;
807
+ var ast = $statement.apply(this, arguments);
808
+ ast[0] = add_tokens(ast[0], start, prev());
809
+ return ast;
810
+ } : $statement;
811
+
812
+ function $statement() {
813
+ if (is("operator", "/")) {
814
+ S.peeked = null;
815
+ S.token = S.input(true); // force regexp
816
+ }
817
+ switch (S.token.type) {
818
+ case "num":
819
+ case "string":
820
+ case "regexp":
821
+ case "operator":
822
+ case "atom":
823
+ return simple_statement();
824
+
825
+ case "name":
826
+ return is_token(peek(), "punc", ":")
827
+ ? labeled_statement(prog1(S.token.value, next, next))
828
+ : simple_statement();
829
+
830
+ case "punc":
831
+ switch (S.token.value) {
832
+ case "{":
833
+ return as("block", block_());
834
+ case "[":
835
+ case "(":
836
+ return simple_statement();
837
+ case ";":
838
+ next();
839
+ return as("block");
840
+ default:
841
+ unexpected();
842
+ }
843
+
844
+ case "keyword":
845
+ switch (prog1(S.token.value, next)) {
846
+ case "break":
847
+ return break_cont("break");
848
+
849
+ case "continue":
850
+ return break_cont("continue");
851
+
852
+ case "debugger":
853
+ semicolon();
854
+ return as("debugger");
855
+
856
+ case "do":
857
+ return (function(body){
858
+ expect_token("keyword", "while");
859
+ return as("do", prog1(parenthesised, semicolon), body);
860
+ })(in_loop(statement));
861
+
862
+ case "for":
863
+ return for_();
864
+
865
+ case "function":
866
+ return function_(true);
867
+
868
+ case "if":
869
+ return if_();
870
+
871
+ case "return":
872
+ if (S.in_function == 0)
873
+ croak("'return' outside of function");
874
+ return as("return",
875
+ is("punc", ";")
876
+ ? (next(), null)
877
+ : can_insert_semicolon()
878
+ ? null
879
+ : prog1(expression, semicolon));
880
+
881
+ case "switch":
882
+ return as("switch", parenthesised(), switch_block_());
883
+
884
+ case "throw":
885
+ return as("throw", prog1(expression, semicolon));
886
+
887
+ case "try":
888
+ return try_();
889
+
890
+ case "var":
891
+ return prog1(var_, semicolon);
892
+
893
+ case "const":
894
+ return prog1(const_, semicolon);
895
+
896
+ case "while":
897
+ return as("while", parenthesised(), in_loop(statement));
898
+
899
+ case "with":
900
+ return as("with", parenthesised(), statement());
901
+
902
+ default:
903
+ unexpected();
904
+ }
905
+ }
906
+ };
907
+
908
+ function labeled_statement(label) {
909
+ S.labels.push(label);
910
+ var start = S.token, stat = statement();
911
+ if (exigent_mode && !HOP(STATEMENTS_WITH_LABELS, stat[0]))
912
+ unexpected(start);
913
+ S.labels.pop();
914
+ return as("label", label, stat);
915
+ };
916
+
917
+ function simple_statement() {
918
+ return as("stat", prog1(expression, semicolon));
919
+ };
920
+
921
+ function break_cont(type) {
922
+ var name = is("name") ? S.token.value : null;
923
+ if (name != null) {
924
+ next();
925
+ if (!member(name, S.labels))
926
+ croak("Label " + name + " without matching loop or statement");
927
+ }
928
+ else if (S.in_loop == 0)
929
+ croak(type + " not inside a loop or switch");
930
+ semicolon();
931
+ return as(type, name);
932
+ };
933
+
934
+ function for_() {
935
+ expect("(");
936
+ var init = null;
937
+ if (!is("punc", ";")) {
938
+ init = is("keyword", "var")
939
+ ? (next(), var_(true))
940
+ : expression(true, true);
941
+ if (is("operator", "in"))
942
+ return for_in(init);
943
+ }
944
+ return regular_for(init);
945
+ };
946
+
947
+ function regular_for(init) {
948
+ expect(";");
949
+ var test = is("punc", ";") ? null : expression();
950
+ expect(";");
951
+ var step = is("punc", ")") ? null : expression();
952
+ expect(")");
953
+ return as("for", init, test, step, in_loop(statement));
954
+ };
955
+
956
+ function for_in(init) {
957
+ var lhs = init[0] == "var" ? as("name", init[1][0]) : init;
958
+ next();
959
+ var obj = expression();
960
+ expect(")");
961
+ return as("for-in", init, lhs, obj, in_loop(statement));
962
+ };
963
+
964
+ var function_ = embed_tokens ? function() {
965
+ var start = prev();
966
+ var ast = $function_.apply(this, arguments);
967
+ ast[0] = add_tokens(ast[0], start, prev());
968
+ return ast;
969
+ } : $function_;
970
+
971
+ function $function_(in_statement) {
972
+ var name = is("name") ? prog1(S.token.value, next) : null;
973
+ if (in_statement && !name)
974
+ unexpected();
975
+ expect("(");
976
+ return as(in_statement ? "defun" : "function",
977
+ name,
978
+ // arguments
979
+ (function(first, a){
980
+ while (!is("punc", ")")) {
981
+ if (first) first = false; else expect(",");
982
+ if (!is("name")) unexpected();
983
+ a.push(S.token.value);
984
+ next();
985
+ }
986
+ next();
987
+ return a;
988
+ })(true, []),
989
+ // body
990
+ (function(){
991
+ ++S.in_function;
992
+ var loop = S.in_loop;
993
+ S.in_loop = 0;
994
+ var a = block_();
995
+ --S.in_function;
996
+ S.in_loop = loop;
997
+ return a;
998
+ })());
999
+ };
1000
+
1001
+ function if_() {
1002
+ var cond = parenthesised(), body = statement(), belse;
1003
+ if (is("keyword", "else")) {
1004
+ next();
1005
+ belse = statement();
1006
+ }
1007
+ return as("if", cond, body, belse);
1008
+ };
1009
+
1010
+ function block_() {
1011
+ expect("{");
1012
+ var a = [];
1013
+ while (!is("punc", "}")) {
1014
+ if (is("eof")) unexpected();
1015
+ a.push(statement());
1016
+ }
1017
+ next();
1018
+ return a;
1019
+ };
1020
+
1021
+ var switch_block_ = curry(in_loop, function(){
1022
+ expect("{");
1023
+ var a = [], cur = null;
1024
+ while (!is("punc", "}")) {
1025
+ if (is("eof")) unexpected();
1026
+ if (is("keyword", "case")) {
1027
+ next();
1028
+ cur = [];
1029
+ a.push([ expression(), cur ]);
1030
+ expect(":");
1031
+ }
1032
+ else if (is("keyword", "default")) {
1033
+ next();
1034
+ expect(":");
1035
+ cur = [];
1036
+ a.push([ null, cur ]);
1037
+ }
1038
+ else {
1039
+ if (!cur) unexpected();
1040
+ cur.push(statement());
1041
+ }
1042
+ }
1043
+ next();
1044
+ return a;
1045
+ });
1046
+
1047
+ function try_() {
1048
+ var body = block_(), bcatch, bfinally;
1049
+ if (is("keyword", "catch")) {
1050
+ next();
1051
+ expect("(");
1052
+ if (!is("name"))
1053
+ croak("Name expected");
1054
+ var name = S.token.value;
1055
+ next();
1056
+ expect(")");
1057
+ bcatch = [ name, block_() ];
1058
+ }
1059
+ if (is("keyword", "finally")) {
1060
+ next();
1061
+ bfinally = block_();
1062
+ }
1063
+ if (!bcatch && !bfinally)
1064
+ croak("Missing catch/finally blocks");
1065
+ return as("try", body, bcatch, bfinally);
1066
+ };
1067
+
1068
+ function vardefs(no_in) {
1069
+ var a = [];
1070
+ for (;;) {
1071
+ if (!is("name"))
1072
+ unexpected();
1073
+ var name = S.token.value;
1074
+ next();
1075
+ if (is("operator", "=")) {
1076
+ next();
1077
+ a.push([ name, expression(false, no_in) ]);
1078
+ } else {
1079
+ a.push([ name ]);
1080
+ }
1081
+ if (!is("punc", ","))
1082
+ break;
1083
+ next();
1084
+ }
1085
+ return a;
1086
+ };
1087
+
1088
+ function var_(no_in) {
1089
+ return as("var", vardefs(no_in));
1090
+ };
1091
+
1092
+ function const_() {
1093
+ return as("const", vardefs());
1094
+ };
1095
+
1096
+ function new_() {
1097
+ var newexp = expr_atom(false), args;
1098
+ if (is("punc", "(")) {
1099
+ next();
1100
+ args = expr_list(")");
1101
+ } else {
1102
+ args = [];
1103
+ }
1104
+ return subscripts(as("new", newexp, args), true);
1105
+ };
1106
+
1107
+ function expr_atom(allow_calls) {
1108
+ if (is("operator", "new")) {
1109
+ next();
1110
+ return new_();
1111
+ }
1112
+ if (is("operator") && HOP(UNARY_PREFIX, S.token.value)) {
1113
+ return make_unary("unary-prefix",
1114
+ prog1(S.token.value, next),
1115
+ expr_atom(allow_calls));
1116
+ }
1117
+ if (is("punc")) {
1118
+ switch (S.token.value) {
1119
+ case "(":
1120
+ next();
1121
+ return subscripts(prog1(expression, curry(expect, ")")), allow_calls);
1122
+ case "[":
1123
+ next();
1124
+ return subscripts(array_(), allow_calls);
1125
+ case "{":
1126
+ next();
1127
+ return subscripts(object_(), allow_calls);
1128
+ }
1129
+ unexpected();
1130
+ }
1131
+ if (is("keyword", "function")) {
1132
+ next();
1133
+ return subscripts(function_(false), allow_calls);
1134
+ }
1135
+ if (HOP(ATOMIC_START_TOKEN, S.token.type)) {
1136
+ var atom = S.token.type == "regexp"
1137
+ ? as("regexp", S.token.value[0], S.token.value[1])
1138
+ : as(S.token.type, S.token.value);
1139
+ return subscripts(prog1(atom, next), allow_calls);
1140
+ }
1141
+ unexpected();
1142
+ };
1143
+
1144
+ function expr_list(closing, allow_trailing_comma, allow_empty) {
1145
+ var first = true, a = [];
1146
+ while (!is("punc", closing)) {
1147
+ if (first) first = false; else expect(",");
1148
+ if (allow_trailing_comma && is("punc", closing)) break;
1149
+ if (is("punc", ",") && allow_empty) {
1150
+ a.push([ "atom", "undefined" ]);
1151
+ } else {
1152
+ a.push(expression(false));
1153
+ }
1154
+ }
1155
+ next();
1156
+ return a;
1157
+ };
1158
+
1159
+ function array_() {
1160
+ return as("array", expr_list("]", !exigent_mode, true));
1161
+ };
1162
+
1163
+ function object_() {
1164
+ var first = true, a = [];
1165
+ while (!is("punc", "}")) {
1166
+ if (first) first = false; else expect(",");
1167
+ if (!exigent_mode && is("punc", "}"))
1168
+ // allow trailing comma
1169
+ break;
1170
+ var type = S.token.type;
1171
+ var name = as_property_name();
1172
+ if (type == "name" && (name == "get" || name == "set") && !is("punc", ":")) {
1173
+ a.push([ as_name(), function_(false), name ]);
1174
+ } else {
1175
+ expect(":");
1176
+ a.push([ name, expression(false) ]);
1177
+ }
1178
+ }
1179
+ next();
1180
+ return as("object", a);
1181
+ };
1182
+
1183
+ function as_property_name() {
1184
+ switch (S.token.type) {
1185
+ case "num":
1186
+ case "string":
1187
+ return prog1(S.token.value, next);
1188
+ }
1189
+ return as_name();
1190
+ };
1191
+
1192
+ function as_name() {
1193
+ switch (S.token.type) {
1194
+ case "name":
1195
+ case "operator":
1196
+ case "keyword":
1197
+ case "atom":
1198
+ return prog1(S.token.value, next);
1199
+ default:
1200
+ unexpected();
1201
+ }
1202
+ };
1203
+
1204
+ function subscripts(expr, allow_calls) {
1205
+ if (is("punc", ".")) {
1206
+ next();
1207
+ return subscripts(as("dot", expr, as_name()), allow_calls);
1208
+ }
1209
+ if (is("punc", "[")) {
1210
+ next();
1211
+ return subscripts(as("sub", expr, prog1(expression, curry(expect, "]"))), allow_calls);
1212
+ }
1213
+ if (allow_calls && is("punc", "(")) {
1214
+ next();
1215
+ return subscripts(as("call", expr, expr_list(")")), true);
1216
+ }
1217
+ if (allow_calls && is("operator") && HOP(UNARY_POSTFIX, S.token.value)) {
1218
+ return prog1(curry(make_unary, "unary-postfix", S.token.value, expr),
1219
+ next);
1220
+ }
1221
+ return expr;
1222
+ };
1223
+
1224
+ function make_unary(tag, op, expr) {
1225
+ if ((op == "++" || op == "--") && !is_assignable(expr))
1226
+ croak("Invalid use of " + op + " operator");
1227
+ return as(tag, op, expr);
1228
+ };
1229
+
1230
+ function expr_op(left, min_prec, no_in) {
1231
+ var op = is("operator") ? S.token.value : null;
1232
+ if (op && op == "in" && no_in) op = null;
1233
+ var prec = op != null ? PRECEDENCE[op] : null;
1234
+ if (prec != null && prec > min_prec) {
1235
+ next();
1236
+ var right = expr_op(expr_atom(true), prec, no_in);
1237
+ return expr_op(as("binary", op, left, right), min_prec, no_in);
1238
+ }
1239
+ return left;
1240
+ };
1241
+
1242
+ function expr_ops(no_in) {
1243
+ return expr_op(expr_atom(true), 0, no_in);
1244
+ };
1245
+
1246
+ function maybe_conditional(no_in) {
1247
+ var expr = expr_ops(no_in);
1248
+ if (is("operator", "?")) {
1249
+ next();
1250
+ var yes = expression(false);
1251
+ expect(":");
1252
+ return as("conditional", expr, yes, expression(false, no_in));
1253
+ }
1254
+ return expr;
1255
+ };
1256
+
1257
+ function is_assignable(expr) {
1258
+ if (!exigent_mode) return true;
1259
+ switch (expr[0]) {
1260
+ case "dot":
1261
+ case "sub":
1262
+ case "new":
1263
+ case "call":
1264
+ return true;
1265
+ case "name":
1266
+ return expr[1] != "this";
1267
+ }
1268
+ };
1269
+
1270
+ function maybe_assign(no_in) {
1271
+ var left = maybe_conditional(no_in), val = S.token.value;
1272
+ if (is("operator") && HOP(ASSIGNMENT, val)) {
1273
+ if (is_assignable(left)) {
1274
+ next();
1275
+ return as("assign", ASSIGNMENT[val], left, maybe_assign(no_in));
1276
+ }
1277
+ croak("Invalid assignment");
1278
+ }
1279
+ return left;
1280
+ };
1281
+
1282
+ function expression(commas, no_in) {
1283
+ if (arguments.length == 0)
1284
+ commas = true;
1285
+ var expr = maybe_assign(no_in);
1286
+ if (commas && is("punc", ",")) {
1287
+ next();
1288
+ return as("seq", expr, expression(true, no_in));
1289
+ }
1290
+ return expr;
1291
+ };
1292
+
1293
+ function in_loop(cont) {
1294
+ try {
1295
+ ++S.in_loop;
1296
+ return cont();
1297
+ } finally {
1298
+ --S.in_loop;
1299
+ }
1300
+ };
1301
+
1302
+ return as("toplevel", (function(a){
1303
+ while (!is("eof"))
1304
+ a.push(statement());
1305
+ return a;
1306
+ })([]));
1307
+
1308
+ };
1309
+
1310
+ /* -----[ Utilities ]----- */
1311
+
1312
+ function curry(f) {
1313
+ var args = slice(arguments, 1);
1314
+ return function() { return f.apply(this, args.concat(slice(arguments))); };
1315
+ };
1316
+
1317
+ function prog1(ret) {
1318
+ if (ret instanceof Function)
1319
+ ret = ret();
1320
+ for (var i = 1, n = arguments.length; --n > 0; ++i)
1321
+ arguments[i]();
1322
+ return ret;
1323
+ };
1324
+
1325
+ function array_to_hash(a) {
1326
+ var ret = {};
1327
+ for (var i = 0; i < a.length; ++i)
1328
+ ret[a[i]] = true;
1329
+ return ret;
1330
+ };
1331
+
1332
+ function slice(a, start) {
1333
+ return Array.prototype.slice.call(a, start == null ? 0 : start);
1334
+ };
1335
+
1336
+ function characters(str) {
1337
+ return str.split("");
1338
+ };
1339
+
1340
+ function member(name, array) {
1341
+ for (var i = array.length; --i >= 0;)
1342
+ if (array[i] === name)
1343
+ return true;
1344
+ return false;
1345
+ };
1346
+
1347
+ function HOP(obj, prop) {
1348
+ return Object.prototype.hasOwnProperty.call(obj, prop);
1349
+ };
1350
+
1351
+ var warn = function() {};
1352
+
1353
+ /* -----[ Exports ]----- */
1354
+
1355
+ exports.tokenizer = tokenizer;
1356
+ exports.parse = parse;
1357
+ exports.slice = slice;
1358
+ exports.curry = curry;
1359
+ exports.member = member;
1360
+ exports.array_to_hash = array_to_hash;
1361
+ exports.PRECEDENCE = PRECEDENCE;
1362
+ exports.KEYWORDS_ATOM = KEYWORDS_ATOM;
1363
+ exports.RESERVED_WORDS = RESERVED_WORDS;
1364
+ exports.KEYWORDS = KEYWORDS;
1365
+ exports.ATOMIC_START_TOKEN = ATOMIC_START_TOKEN;
1366
+ exports.OPERATORS = OPERATORS;
1367
+ exports.is_alphanumeric_char = is_alphanumeric_char;
1368
+ exports.set_logger = function(logger) {
1369
+ warn = logger;
1370
+ };
1371
+ }, "process": function(exports, require, module) {/***********************************************************************
1372
+
1373
+ A JavaScript tokenizer / parser / beautifier / compressor.
1374
+
1375
+ This version is suitable for Node.js. With minimal changes (the
1376
+ exports stuff) it should work on any JS platform.
1377
+
1378
+ This file implements some AST processors. They work on data built
1379
+ by parse-js.
1380
+
1381
+ Exported functions:
1382
+
1383
+ - ast_mangle(ast, options) -- mangles the variable/function names
1384
+ in the AST. Returns an AST.
1385
+
1386
+ - ast_squeeze(ast) -- employs various optimizations to make the
1387
+ final generated code even smaller. Returns an AST.
1388
+
1389
+ - gen_code(ast, options) -- generates JS code from the AST. Pass
1390
+ true (or an object, see the code for some options) as second
1391
+ argument to get "pretty" (indented) code.
1392
+
1393
+ -------------------------------- (C) ---------------------------------
1394
+
1395
+ Author: Mihai Bazon
1396
+ <mihai.bazon@gmail.com>
1397
+ http://mihai.bazon.net/blog
1398
+
1399
+ Distributed under the BSD license:
1400
+
1401
+ Copyright 2010 (c) Mihai Bazon <mihai.bazon@gmail.com>
1402
+
1403
+ Redistribution and use in source and binary forms, with or without
1404
+ modification, are permitted provided that the following conditions
1405
+ are met:
1406
+
1407
+ * Redistributions of source code must retain the above
1408
+ copyright notice, this list of conditions and the following
1409
+ disclaimer.
1410
+
1411
+ * Redistributions in binary form must reproduce the above
1412
+ copyright notice, this list of conditions and the following
1413
+ disclaimer in the documentation and/or other materials
1414
+ provided with the distribution.
1415
+
1416
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
1417
+ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1418
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1419
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
1420
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
1421
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
1422
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
1423
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1424
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
1425
+ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
1426
+ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1427
+ SUCH DAMAGE.
1428
+
1429
+ ***********************************************************************/
1430
+
1431
+ var jsp = require("./parse-js"),
1432
+ slice = jsp.slice,
1433
+ member = jsp.member,
1434
+ PRECEDENCE = jsp.PRECEDENCE,
1435
+ OPERATORS = jsp.OPERATORS;
1436
+
1437
+ /* -----[ helper for AST traversal ]----- */
1438
+
1439
+ function ast_walker(ast) {
1440
+ function _vardefs(defs) {
1441
+ return [ this[0], MAP(defs, function(def){
1442
+ var a = [ def[0] ];
1443
+ if (def.length > 1)
1444
+ a[1] = walk(def[1]);
1445
+ return a;
1446
+ }) ];
1447
+ };
1448
+ var walkers = {
1449
+ "string": function(str) {
1450
+ return [ this[0], str ];
1451
+ },
1452
+ "num": function(num) {
1453
+ return [ this[0], num ];
1454
+ },
1455
+ "name": function(name) {
1456
+ return [ this[0], name ];
1457
+ },
1458
+ "toplevel": function(statements) {
1459
+ return [ this[0], MAP(statements, walk) ];
1460
+ },
1461
+ "block": function(statements) {
1462
+ var out = [ this[0] ];
1463
+ if (statements != null)
1464
+ out.push(MAP(statements, walk));
1465
+ return out;
1466
+ },
1467
+ "var": _vardefs,
1468
+ "const": _vardefs,
1469
+ "try": function(t, c, f) {
1470
+ return [
1471
+ this[0],
1472
+ MAP(t, walk),
1473
+ c != null ? [ c[0], MAP(c[1], walk) ] : null,
1474
+ f != null ? MAP(f, walk) : null
1475
+ ];
1476
+ },
1477
+ "throw": function(expr) {
1478
+ return [ this[0], walk(expr) ];
1479
+ },
1480
+ "new": function(ctor, args) {
1481
+ return [ this[0], walk(ctor), MAP(args, walk) ];
1482
+ },
1483
+ "switch": function(expr, body) {
1484
+ return [ this[0], walk(expr), MAP(body, function(branch){
1485
+ return [ branch[0] ? walk(branch[0]) : null,
1486
+ MAP(branch[1], walk) ];
1487
+ }) ];
1488
+ },
1489
+ "break": function(label) {
1490
+ return [ this[0], label ];
1491
+ },
1492
+ "continue": function(label) {
1493
+ return [ this[0], label ];
1494
+ },
1495
+ "conditional": function(cond, t, e) {
1496
+ return [ this[0], walk(cond), walk(t), walk(e) ];
1497
+ },
1498
+ "assign": function(op, lvalue, rvalue) {
1499
+ return [ this[0], op, walk(lvalue), walk(rvalue) ];
1500
+ },
1501
+ "dot": function(expr) {
1502
+ return [ this[0], walk(expr) ].concat(slice(arguments, 1));
1503
+ },
1504
+ "call": function(expr, args) {
1505
+ return [ this[0], walk(expr), MAP(args, walk) ];
1506
+ },
1507
+ "function": function(name, args, body) {
1508
+ return [ this[0], name, args.slice(), MAP(body, walk) ];
1509
+ },
1510
+ "defun": function(name, args, body) {
1511
+ return [ this[0], name, args.slice(), MAP(body, walk) ];
1512
+ },
1513
+ "if": function(conditional, t, e) {
1514
+ return [ this[0], walk(conditional), walk(t), walk(e) ];
1515
+ },
1516
+ "for": function(init, cond, step, block) {
1517
+ return [ this[0], walk(init), walk(cond), walk(step), walk(block) ];
1518
+ },
1519
+ "for-in": function(vvar, key, hash, block) {
1520
+ return [ this[0], walk(vvar), walk(key), walk(hash), walk(block) ];
1521
+ },
1522
+ "while": function(cond, block) {
1523
+ return [ this[0], walk(cond), walk(block) ];
1524
+ },
1525
+ "do": function(cond, block) {
1526
+ return [ this[0], walk(cond), walk(block) ];
1527
+ },
1528
+ "return": function(expr) {
1529
+ return [ this[0], walk(expr) ];
1530
+ },
1531
+ "binary": function(op, left, right) {
1532
+ return [ this[0], op, walk(left), walk(right) ];
1533
+ },
1534
+ "unary-prefix": function(op, expr) {
1535
+ return [ this[0], op, walk(expr) ];
1536
+ },
1537
+ "unary-postfix": function(op, expr) {
1538
+ return [ this[0], op, walk(expr) ];
1539
+ },
1540
+ "sub": function(expr, subscript) {
1541
+ return [ this[0], walk(expr), walk(subscript) ];
1542
+ },
1543
+ "object": function(props) {
1544
+ return [ this[0], MAP(props, function(p){
1545
+ return p.length == 2
1546
+ ? [ p[0], walk(p[1]) ]
1547
+ : [ p[0], walk(p[1]), p[2] ]; // get/set-ter
1548
+ }) ];
1549
+ },
1550
+ "regexp": function(rx, mods) {
1551
+ return [ this[0], rx, mods ];
1552
+ },
1553
+ "array": function(elements) {
1554
+ return [ this[0], MAP(elements, walk) ];
1555
+ },
1556
+ "stat": function(stat) {
1557
+ return [ this[0], walk(stat) ];
1558
+ },
1559
+ "seq": function() {
1560
+ return [ this[0] ].concat(MAP(slice(arguments), walk));
1561
+ },
1562
+ "label": function(name, block) {
1563
+ return [ this[0], name, walk(block) ];
1564
+ },
1565
+ "with": function(expr, block) {
1566
+ return [ this[0], walk(expr), walk(block) ];
1567
+ },
1568
+ "atom": function(name) {
1569
+ return [ this[0], name ];
1570
+ }
1571
+ };
1572
+
1573
+ var user = {};
1574
+ var stack = [];
1575
+ function walk(ast) {
1576
+ if (ast == null)
1577
+ return null;
1578
+ try {
1579
+ stack.push(ast);
1580
+ var type = ast[0];
1581
+ var gen = user[type];
1582
+ if (gen) {
1583
+ var ret = gen.apply(ast, ast.slice(1));
1584
+ if (ret != null)
1585
+ return ret;
1586
+ }
1587
+ gen = walkers[type];
1588
+ return gen.apply(ast, ast.slice(1));
1589
+ } finally {
1590
+ stack.pop();
1591
+ }
1592
+ };
1593
+
1594
+ function with_walkers(walkers, cont){
1595
+ var save = {}, i;
1596
+ for (i in walkers) if (HOP(walkers, i)) {
1597
+ save[i] = user[i];
1598
+ user[i] = walkers[i];
1599
+ }
1600
+ var ret = cont();
1601
+ for (i in save) if (HOP(save, i)) {
1602
+ if (!save[i]) delete user[i];
1603
+ else user[i] = save[i];
1604
+ }
1605
+ return ret;
1606
+ };
1607
+
1608
+ return {
1609
+ walk: walk,
1610
+ with_walkers: with_walkers,
1611
+ parent: function() {
1612
+ return stack[stack.length - 2]; // last one is current node
1613
+ },
1614
+ stack: function() {
1615
+ return stack;
1616
+ }
1617
+ };
1618
+ };
1619
+
1620
+ /* -----[ Scope and mangling ]----- */
1621
+
1622
+ function Scope(parent) {
1623
+ this.names = {}; // names defined in this scope
1624
+ this.mangled = {}; // mangled names (orig.name => mangled)
1625
+ this.rev_mangled = {}; // reverse lookup (mangled => orig.name)
1626
+ this.cname = -1; // current mangled name
1627
+ this.refs = {}; // names referenced from this scope
1628
+ this.uses_with = false; // will become TRUE if with() is detected in this or any subscopes
1629
+ this.uses_eval = false; // will become TRUE if eval() is detected in this or any subscopes
1630
+ this.parent = parent; // parent scope
1631
+ this.children = []; // sub-scopes
1632
+ if (parent) {
1633
+ this.level = parent.level + 1;
1634
+ parent.children.push(this);
1635
+ } else {
1636
+ this.level = 0;
1637
+ }
1638
+ };
1639
+
1640
+ var base54 = (function(){
1641
+ var DIGITS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_";
1642
+ return function(num) {
1643
+ var ret = "";
1644
+ do {
1645
+ ret = DIGITS.charAt(num % 54) + ret;
1646
+ num = Math.floor(num / 54);
1647
+ } while (num > 0);
1648
+ return ret;
1649
+ };
1650
+ })();
1651
+
1652
+ Scope.prototype = {
1653
+ has: function(name) {
1654
+ for (var s = this; s; s = s.parent)
1655
+ if (HOP(s.names, name))
1656
+ return s;
1657
+ },
1658
+ has_mangled: function(mname) {
1659
+ for (var s = this; s; s = s.parent)
1660
+ if (HOP(s.rev_mangled, mname))
1661
+ return s;
1662
+ },
1663
+ toJSON: function() {
1664
+ return {
1665
+ names: this.names,
1666
+ uses_eval: this.uses_eval,
1667
+ uses_with: this.uses_with
1668
+ };
1669
+ },
1670
+
1671
+ next_mangled: function() {
1672
+ // we must be careful that the new mangled name:
1673
+ //
1674
+ // 1. doesn't shadow a mangled name from a parent
1675
+ // scope, unless we don't reference the original
1676
+ // name from this scope OR from any sub-scopes!
1677
+ // This will get slow.
1678
+ //
1679
+ // 2. doesn't shadow an original name from a parent
1680
+ // scope, in the event that the name is not mangled
1681
+ // in the parent scope and we reference that name
1682
+ // here OR IN ANY SUBSCOPES!
1683
+ //
1684
+ // 3. doesn't shadow a name that is referenced but not
1685
+ // defined (possibly global defined elsewhere).
1686
+ for (;;) {
1687
+ var m = base54(++this.cname), prior;
1688
+
1689
+ // case 1.
1690
+ prior = this.has_mangled(m);
1691
+ if (prior && this.refs[prior.rev_mangled[m]] === prior)
1692
+ continue;
1693
+
1694
+ // case 2.
1695
+ prior = this.has(m);
1696
+ if (prior && prior !== this && this.refs[m] === prior && !prior.has_mangled(m))
1697
+ continue;
1698
+
1699
+ // case 3.
1700
+ if (HOP(this.refs, m) && this.refs[m] == null)
1701
+ continue;
1702
+
1703
+ // I got "do" once. :-/
1704
+ if (!is_identifier(m))
1705
+ continue;
1706
+
1707
+ return m;
1708
+ }
1709
+ },
1710
+ get_mangled: function(name, newMangle) {
1711
+ if (this.uses_eval || this.uses_with) return name; // no mangle if eval or with is in use
1712
+ var s = this.has(name);
1713
+ if (!s) return name; // not in visible scope, no mangle
1714
+ if (HOP(s.mangled, name)) return s.mangled[name]; // already mangled in this scope
1715
+ if (!newMangle) return name; // not found and no mangling requested
1716
+
1717
+ var m = s.next_mangled();
1718
+ s.rev_mangled[m] = name;
1719
+ return s.mangled[name] = m;
1720
+ },
1721
+ define: function(name) {
1722
+ if (name != null)
1723
+ return this.names[name] = name;
1724
+ }
1725
+ };
1726
+
1727
+ function ast_add_scope(ast) {
1728
+
1729
+ var current_scope = null;
1730
+ var w = ast_walker(), walk = w.walk;
1731
+ var having_eval = [];
1732
+
1733
+ function with_new_scope(cont) {
1734
+ current_scope = new Scope(current_scope);
1735
+ var ret = current_scope.body = cont();
1736
+ ret.scope = current_scope;
1737
+ current_scope = current_scope.parent;
1738
+ return ret;
1739
+ };
1740
+
1741
+ function define(name) {
1742
+ return current_scope.define(name);
1743
+ };
1744
+
1745
+ function reference(name) {
1746
+ current_scope.refs[name] = true;
1747
+ };
1748
+
1749
+ function _lambda(name, args, body) {
1750
+ return [ this[0], define(name), args, with_new_scope(function(){
1751
+ MAP(args, define);
1752
+ return MAP(body, walk);
1753
+ })];
1754
+ };
1755
+
1756
+ return with_new_scope(function(){
1757
+ // process AST
1758
+ var ret = w.with_walkers({
1759
+ "function": _lambda,
1760
+ "defun": _lambda,
1761
+ "with": function(expr, block) {
1762
+ for (var s = current_scope; s; s = s.parent)
1763
+ s.uses_with = true;
1764
+ },
1765
+ "var": function(defs) {
1766
+ MAP(defs, function(d){ define(d[0]) });
1767
+ },
1768
+ "const": function(defs) {
1769
+ MAP(defs, function(d){ define(d[0]) });
1770
+ },
1771
+ "try": function(t, c, f) {
1772
+ if (c != null) return [
1773
+ this[0],
1774
+ MAP(t, walk),
1775
+ [ define(c[0]), MAP(c[1], walk) ],
1776
+ f != null ? MAP(f, walk) : null
1777
+ ];
1778
+ },
1779
+ "name": function(name) {
1780
+ if (name == "eval")
1781
+ having_eval.push(current_scope);
1782
+ reference(name);
1783
+ }
1784
+ }, function(){
1785
+ return walk(ast);
1786
+ });
1787
+
1788
+ // the reason why we need an additional pass here is
1789
+ // that names can be used prior to their definition.
1790
+
1791
+ // scopes where eval was detected and their parents
1792
+ // are marked with uses_eval, unless they define the
1793
+ // "eval" name.
1794
+ MAP(having_eval, function(scope){
1795
+ if (!scope.has("eval")) while (scope) {
1796
+ scope.uses_eval = true;
1797
+ scope = scope.parent;
1798
+ }
1799
+ });
1800
+
1801
+ // for referenced names it might be useful to know
1802
+ // their origin scope. current_scope here is the
1803
+ // toplevel one.
1804
+ function fixrefs(scope, i) {
1805
+ // do children first; order shouldn't matter
1806
+ for (i = scope.children.length; --i >= 0;)
1807
+ fixrefs(scope.children[i]);
1808
+ for (i in scope.refs) if (HOP(scope.refs, i)) {
1809
+ // find origin scope and propagate the reference to origin
1810
+ for (var origin = scope.has(i), s = scope; s; s = s.parent) {
1811
+ s.refs[i] = origin;
1812
+ if (s === origin) break;
1813
+ }
1814
+ }
1815
+ };
1816
+ fixrefs(current_scope);
1817
+
1818
+ return ret;
1819
+ });
1820
+
1821
+ };
1822
+
1823
+ /* -----[ mangle names ]----- */
1824
+
1825
+ function ast_mangle(ast, options) {
1826
+ var w = ast_walker(), walk = w.walk, scope;
1827
+ options = options || {};
1828
+
1829
+ function get_mangled(name, newMangle) {
1830
+ if (!options.toplevel && !scope.parent) return name; // don't mangle toplevel
1831
+ if (options.except && member(name, options.except))
1832
+ return name;
1833
+ return scope.get_mangled(name, newMangle);
1834
+ };
1835
+
1836
+ function _lambda(name, args, body) {
1837
+ if (name) name = get_mangled(name);
1838
+ body = with_scope(body.scope, function(){
1839
+ args = MAP(args, function(name){ return get_mangled(name) });
1840
+ return MAP(body, walk);
1841
+ });
1842
+ return [ this[0], name, args, body ];
1843
+ };
1844
+
1845
+ function with_scope(s, cont) {
1846
+ var _scope = scope;
1847
+ scope = s;
1848
+ for (var i in s.names) if (HOP(s.names, i)) {
1849
+ get_mangled(i, true);
1850
+ }
1851
+ var ret = cont();
1852
+ ret.scope = s;
1853
+ scope = _scope;
1854
+ return ret;
1855
+ };
1856
+
1857
+ function _vardefs(defs) {
1858
+ return [ this[0], MAP(defs, function(d){
1859
+ return [ get_mangled(d[0]), walk(d[1]) ];
1860
+ }) ];
1861
+ };
1862
+
1863
+ return w.with_walkers({
1864
+ "function": _lambda,
1865
+ "defun": function() {
1866
+ // move function declarations to the top when
1867
+ // they are not in some block.
1868
+ var ast = _lambda.apply(this, arguments);
1869
+ switch (w.parent()[0]) {
1870
+ case "toplevel":
1871
+ case "function":
1872
+ case "defun":
1873
+ return MAP.at_top(ast);
1874
+ }
1875
+ return ast;
1876
+ },
1877
+ "var": _vardefs,
1878
+ "const": _vardefs,
1879
+ "name": function(name) {
1880
+ return [ this[0], get_mangled(name) ];
1881
+ },
1882
+ "try": function(t, c, f) {
1883
+ return [ this[0],
1884
+ MAP(t, walk),
1885
+ c != null ? [ get_mangled(c[0]), MAP(c[1], walk) ] : null,
1886
+ f != null ? MAP(f, walk) : null ];
1887
+ },
1888
+ "toplevel": function(body) {
1889
+ var self = this;
1890
+ return with_scope(self.scope, function(){
1891
+ return [ self[0], MAP(body, walk) ];
1892
+ });
1893
+ }
1894
+ }, function() {
1895
+ return walk(ast_add_scope(ast));
1896
+ });
1897
+ };
1898
+
1899
+ /* -----[
1900
+ - compress foo["bar"] into foo.bar,
1901
+ - remove block brackets {} where possible
1902
+ - join consecutive var declarations
1903
+ - various optimizations for IFs:
1904
+ - if (cond) foo(); else bar(); ==> cond?foo():bar();
1905
+ - if (cond) foo(); ==> cond&&foo();
1906
+ - if (foo) return bar(); else return baz(); ==> return foo?bar():baz(); // also for throw
1907
+ - if (foo) return bar(); else something(); ==> {if(foo)return bar();something()}
1908
+ ]----- */
1909
+
1910
+ var warn = function(){};
1911
+
1912
+ function best_of(ast1, ast2) {
1913
+ return gen_code(ast1).length > gen_code(ast2[0] == "stat" ? ast2[1] : ast2).length ? ast2 : ast1;
1914
+ };
1915
+
1916
+ function last_stat(b) {
1917
+ if (b[0] == "block" && b[1] && b[1].length > 0)
1918
+ return b[1][b[1].length - 1];
1919
+ return b;
1920
+ }
1921
+
1922
+ function aborts(t) {
1923
+ if (t) {
1924
+ t = last_stat(t);
1925
+ if (t[0] == "return" || t[0] == "break" || t[0] == "continue" || t[0] == "throw")
1926
+ return true;
1927
+ }
1928
+ };
1929
+
1930
+ function boolean_expr(expr) {
1931
+ return ( (expr[0] == "unary-prefix"
1932
+ && member(expr[1], [ "!", "delete" ])) ||
1933
+
1934
+ (expr[0] == "binary"
1935
+ && member(expr[1], [ "in", "instanceof", "==", "!=", "===", "!==", "<", "<=", ">=", ">" ])) ||
1936
+
1937
+ (expr[0] == "binary"
1938
+ && member(expr[1], [ "&&", "||" ])
1939
+ && boolean_expr(expr[2])
1940
+ && boolean_expr(expr[3])) ||
1941
+
1942
+ (expr[0] == "conditional"
1943
+ && boolean_expr(expr[2])
1944
+ && boolean_expr(expr[3])) ||
1945
+
1946
+ (expr[0] == "assign"
1947
+ && expr[1] === true
1948
+ && boolean_expr(expr[3])) ||
1949
+
1950
+ (expr[0] == "seq"
1951
+ && boolean_expr(expr[expr.length - 1]))
1952
+ );
1953
+ };
1954
+
1955
+ function make_conditional(c, t, e) {
1956
+ if (c[0] == "unary-prefix" && c[1] == "!") {
1957
+ return e ? [ "conditional", c[2], e, t ] : [ "binary", "||", c[2], t ];
1958
+ } else {
1959
+ return e ? [ "conditional", c, t, e ] : [ "binary", "&&", c, t ];
1960
+ }
1961
+ };
1962
+
1963
+ function empty(b) {
1964
+ return !b || (b[0] == "block" && (!b[1] || b[1].length == 0));
1965
+ };
1966
+
1967
+ function is_string(node) {
1968
+ return (node[0] == "string" ||
1969
+ node[0] == "unary-prefix" && node[1] == "typeof" ||
1970
+ node[0] == "binary" && node[1] == "+" &&
1971
+ (is_string(node[2]) || is_string(node[3])));
1972
+ };
1973
+
1974
+ var when_constant = (function(){
1975
+
1976
+ var $NOT_CONSTANT = {};
1977
+
1978
+ // this can only evaluate constant expressions. If it finds anything
1979
+ // not constant, it throws $NOT_CONSTANT.
1980
+ function evaluate(expr) {
1981
+ switch (expr[0]) {
1982
+ case "string":
1983
+ case "num":
1984
+ return expr[1];
1985
+ case "name":
1986
+ case "atom":
1987
+ switch (expr[1]) {
1988
+ case "true": return true;
1989
+ case "false": return false;
1990
+ }
1991
+ break;
1992
+ case "unary-prefix":
1993
+ switch (expr[1]) {
1994
+ case "!": return !evaluate(expr[2]);
1995
+ case "typeof": return typeof evaluate(expr[2]);
1996
+ case "~": return ~evaluate(expr[2]);
1997
+ case "-": return -evaluate(expr[2]);
1998
+ case "+": return +evaluate(expr[2]);
1999
+ }
2000
+ break;
2001
+ case "binary":
2002
+ var left = expr[2], right = expr[3];
2003
+ switch (expr[1]) {
2004
+ case "&&" : return evaluate(left) && evaluate(right);
2005
+ case "||" : return evaluate(left) || evaluate(right);
2006
+ case "|" : return evaluate(left) | evaluate(right);
2007
+ case "&" : return evaluate(left) & evaluate(right);
2008
+ case "^" : return evaluate(left) ^ evaluate(right);
2009
+ case "+" : return evaluate(left) + evaluate(right);
2010
+ case "*" : return evaluate(left) * evaluate(right);
2011
+ case "/" : return evaluate(left) / evaluate(right);
2012
+ case "-" : return evaluate(left) - evaluate(right);
2013
+ case "<<" : return evaluate(left) << evaluate(right);
2014
+ case ">>" : return evaluate(left) >> evaluate(right);
2015
+ case ">>>" : return evaluate(left) >>> evaluate(right);
2016
+ case "==" : return evaluate(left) == evaluate(right);
2017
+ case "===" : return evaluate(left) === evaluate(right);
2018
+ case "!=" : return evaluate(left) != evaluate(right);
2019
+ case "!==" : return evaluate(left) !== evaluate(right);
2020
+ case "<" : return evaluate(left) < evaluate(right);
2021
+ case "<=" : return evaluate(left) <= evaluate(right);
2022
+ case ">" : return evaluate(left) > evaluate(right);
2023
+ case ">=" : return evaluate(left) >= evaluate(right);
2024
+ case "in" : return evaluate(left) in evaluate(right);
2025
+ case "instanceof" : return evaluate(left) instanceof evaluate(right);
2026
+ }
2027
+ }
2028
+ throw $NOT_CONSTANT;
2029
+ };
2030
+
2031
+ return function(expr, yes, no) {
2032
+ try {
2033
+ var val = evaluate(expr), ast;
2034
+ switch (typeof val) {
2035
+ case "string": ast = [ "string", val ]; break;
2036
+ case "number": ast = [ "num", val ]; break;
2037
+ case "boolean": ast = [ "name", String(val) ]; break;
2038
+ default: throw new Error("Can't handle constant of type: " + (typeof val));
2039
+ }
2040
+ return yes.call(expr, ast, val);
2041
+ } catch(ex) {
2042
+ if (ex === $NOT_CONSTANT) {
2043
+ if (expr[0] == "binary"
2044
+ && (expr[1] == "===" || expr[1] == "!==")
2045
+ && ((is_string(expr[2]) && is_string(expr[3]))
2046
+ || (boolean_expr(expr[2]) && boolean_expr(expr[3])))) {
2047
+ expr[1] = expr[1].substr(0, 2);
2048
+ }
2049
+ return no ? no.call(expr, expr) : null;
2050
+ }
2051
+ else throw ex;
2052
+ }
2053
+ };
2054
+
2055
+ })();
2056
+
2057
+ function warn_unreachable(ast) {
2058
+ if (!empty(ast))
2059
+ warn("Dropping unreachable code: " + gen_code(ast, true));
2060
+ };
2061
+
2062
+ function ast_squeeze(ast, options) {
2063
+ options = defaults(options, {
2064
+ make_seqs : true,
2065
+ dead_code : true,
2066
+ keep_comps : true,
2067
+ no_warnings : false
2068
+ });
2069
+
2070
+ var w = ast_walker(), walk = w.walk, scope;
2071
+
2072
+ function negate(c) {
2073
+ var not_c = [ "unary-prefix", "!", c ];
2074
+ switch (c[0]) {
2075
+ case "unary-prefix":
2076
+ return c[1] == "!" && boolean_expr(c[2]) ? c[2] : not_c;
2077
+ case "seq":
2078
+ c = slice(c);
2079
+ c[c.length - 1] = negate(c[c.length - 1]);
2080
+ return c;
2081
+ case "conditional":
2082
+ return best_of(not_c, [ "conditional", c[1], negate(c[2]), negate(c[3]) ]);
2083
+ case "binary":
2084
+ var op = c[1], left = c[2], right = c[3];
2085
+ if (!options.keep_comps) switch (op) {
2086
+ case "<=" : return [ "binary", ">", left, right ];
2087
+ case "<" : return [ "binary", ">=", left, right ];
2088
+ case ">=" : return [ "binary", "<", left, right ];
2089
+ case ">" : return [ "binary", "<=", left, right ];
2090
+ }
2091
+ switch (op) {
2092
+ case "==" : return [ "binary", "!=", left, right ];
2093
+ case "!=" : return [ "binary", "==", left, right ];
2094
+ case "===" : return [ "binary", "!==", left, right ];
2095
+ case "!==" : return [ "binary", "===", left, right ];
2096
+ case "&&" : return best_of(not_c, [ "binary", "||", negate(left), negate(right) ]);
2097
+ case "||" : return best_of(not_c, [ "binary", "&&", negate(left), negate(right) ]);
2098
+ }
2099
+ break;
2100
+ }
2101
+ return not_c;
2102
+ };
2103
+
2104
+ function with_scope(s, cont) {
2105
+ var _scope = scope;
2106
+ scope = s;
2107
+ var ret = cont();
2108
+ ret.scope = s;
2109
+ scope = _scope;
2110
+ return ret;
2111
+ };
2112
+
2113
+ function rmblock(block) {
2114
+ if (block != null && block[0] == "block" && block[1]) {
2115
+ if (block[1].length == 1)
2116
+ block = block[1][0];
2117
+ else if (block[1].length == 0)
2118
+ block = [ "block" ];
2119
+ }
2120
+ return block;
2121
+ };
2122
+
2123
+ function _lambda(name, args, body) {
2124
+ return [ this[0], name, args, with_scope(body.scope, function(){
2125
+ return tighten(MAP(body, walk), "lambda");
2126
+ }) ];
2127
+ };
2128
+
2129
+ // we get here for blocks that have been already transformed.
2130
+ // this function does a few things:
2131
+ // 1. discard useless blocks
2132
+ // 2. join consecutive var declarations
2133
+ // 3. remove obviously dead code
2134
+ // 4. transform consecutive statements using the comma operator
2135
+ // 5. if block_type == "lambda" and it detects constructs like if(foo) return ... - rewrite like if (!foo) { ... }
2136
+ function tighten(statements, block_type) {
2137
+ statements = statements.reduce(function(a, stat){
2138
+ if (stat[0] == "block") {
2139
+ if (stat[1]) {
2140
+ a.push.apply(a, stat[1]);
2141
+ }
2142
+ } else {
2143
+ a.push(stat);
2144
+ }
2145
+ return a;
2146
+ }, []);
2147
+
2148
+ statements = (function(a, prev){
2149
+ statements.forEach(function(cur){
2150
+ if (prev && ((cur[0] == "var" && prev[0] == "var") ||
2151
+ (cur[0] == "const" && prev[0] == "const"))) {
2152
+ prev[1] = prev[1].concat(cur[1]);
2153
+ } else {
2154
+ a.push(cur);
2155
+ prev = cur;
2156
+ }
2157
+ });
2158
+ return a;
2159
+ })([]);
2160
+
2161
+ if (options.dead_code) statements = (function(a, has_quit){
2162
+ statements.forEach(function(st){
2163
+ if (has_quit) {
2164
+ if (member(st[0], [ "function", "defun" , "var", "const" ])) {
2165
+ a.push(st);
2166
+ }
2167
+ else if (!options.no_warnings)
2168
+ warn_unreachable(st);
2169
+ }
2170
+ else {
2171
+ a.push(st);
2172
+ if (member(st[0], [ "return", "throw", "break", "continue" ]))
2173
+ has_quit = true;
2174
+ }
2175
+ });
2176
+ return a;
2177
+ })([]);
2178
+
2179
+ if (options.make_seqs) statements = (function(a, prev) {
2180
+ statements.forEach(function(cur){
2181
+ if (prev && prev[0] == "stat" && cur[0] == "stat") {
2182
+ prev[1] = [ "seq", prev[1], cur[1] ];
2183
+ } else {
2184
+ a.push(cur);
2185
+ prev = cur;
2186
+ }
2187
+ });
2188
+ return a;
2189
+ })([]);
2190
+
2191
+ if (block_type == "lambda") statements = (function(i, a, stat){
2192
+ while (i < statements.length) {
2193
+ stat = statements[i++];
2194
+ if (stat[0] == "if" && !stat[3]) {
2195
+ if (stat[2][0] == "return" && stat[2][1] == null) {
2196
+ a.push(make_if(negate(stat[1]), [ "block", statements.slice(i) ]));
2197
+ break;
2198
+ }
2199
+ var last = last_stat(stat[2]);
2200
+ if (last[0] == "return" && last[1] == null) {
2201
+ a.push(make_if(stat[1], [ "block", stat[2][1].slice(0, -1) ], [ "block", statements.slice(i) ]));
2202
+ break;
2203
+ }
2204
+ }
2205
+ a.push(stat);
2206
+ }
2207
+ return a;
2208
+ })(0, []);
2209
+
2210
+ return statements;
2211
+ };
2212
+
2213
+ function make_if(c, t, e) {
2214
+ return when_constant(c, function(ast, val){
2215
+ if (val) {
2216
+ warn_unreachable(e);
2217
+ return t;
2218
+ } else {
2219
+ warn_unreachable(t);
2220
+ return e;
2221
+ }
2222
+ }, function() {
2223
+ return make_real_if(c, t, e);
2224
+ });
2225
+ };
2226
+
2227
+ function make_real_if(c, t, e) {
2228
+ c = walk(c);
2229
+ t = walk(t);
2230
+ e = walk(e);
2231
+
2232
+ if (empty(t)) {
2233
+ c = negate(c);
2234
+ t = e;
2235
+ e = null;
2236
+ } else if (empty(e)) {
2237
+ e = null;
2238
+ } else {
2239
+ // if we have both else and then, maybe it makes sense to switch them?
2240
+ (function(){
2241
+ var a = gen_code(c);
2242
+ var n = negate(c);
2243
+ var b = gen_code(n);
2244
+ if (b.length < a.length) {
2245
+ var tmp = t;
2246
+ t = e;
2247
+ e = tmp;
2248
+ c = n;
2249
+ }
2250
+ })();
2251
+ }
2252
+ if (empty(e) && empty(t))
2253
+ return [ "stat", c ];
2254
+ var ret = [ "if", c, t, e ];
2255
+ if (t[0] == "if" && empty(t[3]) && empty(e)) {
2256
+ ret = best_of(ret, walk([ "if", [ "binary", "&&", c, t[1] ], t[2] ]));
2257
+ }
2258
+ else if (t[0] == "stat") {
2259
+ if (e) {
2260
+ if (e[0] == "stat") {
2261
+ ret = best_of(ret, [ "stat", make_conditional(c, t[1], e[1]) ]);
2262
+ }
2263
+ }
2264
+ else {
2265
+ ret = best_of(ret, [ "stat", make_conditional(c, t[1]) ]);
2266
+ }
2267
+ }
2268
+ else if (e && t[0] == e[0] && (t[0] == "return" || t[0] == "throw") && t[1] && e[1]) {
2269
+ ret = best_of(ret, [ t[0], make_conditional(c, t[1], e[1] ) ]);
2270
+ }
2271
+ else if (e && aborts(t)) {
2272
+ ret = [ [ "if", c, t ] ];
2273
+ if (e[0] == "block") {
2274
+ if (e[1]) ret = ret.concat(e[1]);
2275
+ }
2276
+ else {
2277
+ ret.push(e);
2278
+ }
2279
+ ret = walk([ "block", ret ]);
2280
+ }
2281
+ else if (t && aborts(e)) {
2282
+ ret = [ [ "if", negate(c), e ] ];
2283
+ if (t[0] == "block") {
2284
+ if (t[1]) ret = ret.concat(t[1]);
2285
+ } else {
2286
+ ret.push(t);
2287
+ }
2288
+ ret = walk([ "block", ret ]);
2289
+ }
2290
+ return ret;
2291
+ };
2292
+
2293
+ function _do_while(cond, body) {
2294
+ return when_constant(cond, function(cond, val){
2295
+ if (!val) {
2296
+ warn_unreachable(body);
2297
+ return [ "block" ];
2298
+ } else {
2299
+ return [ "for", null, null, null, walk(body) ];
2300
+ }
2301
+ });
2302
+ };
2303
+
2304
+ return w.with_walkers({
2305
+ "sub": function(expr, subscript) {
2306
+ if (subscript[0] == "string") {
2307
+ var name = subscript[1];
2308
+ if (is_identifier(name))
2309
+ return [ "dot", walk(expr), name ];
2310
+ else if (/^[1-9][0-9]*$/.test(name) || name === "0")
2311
+ return [ "sub", walk(expr), [ "num", parseInt(name, 10) ] ];
2312
+ }
2313
+ },
2314
+ "if": make_if,
2315
+ "toplevel": function(body) {
2316
+ return [ "toplevel", with_scope(this.scope, function(){
2317
+ return tighten(MAP(body, walk));
2318
+ }) ];
2319
+ },
2320
+ "switch": function(expr, body) {
2321
+ var last = body.length - 1;
2322
+ return [ "switch", walk(expr), MAP(body, function(branch, i){
2323
+ var block = tighten(MAP(branch[1], walk));
2324
+ if (i == last && block.length > 0) {
2325
+ var node = block[block.length - 1];
2326
+ if (node[0] == "break" && !node[1])
2327
+ block.pop();
2328
+ }
2329
+ return [ branch[0] ? walk(branch[0]) : null, block ];
2330
+ }) ];
2331
+ },
2332
+ "function": function() {
2333
+ var ret = _lambda.apply(this, arguments);
2334
+ if (ret[1] && !HOP(scope.refs, ret[1])) {
2335
+ ret[1] = null;
2336
+ }
2337
+ return ret;
2338
+ },
2339
+ "defun": _lambda,
2340
+ "block": function(body) {
2341
+ if (body) return rmblock([ "block", tighten(MAP(body, walk)) ]);
2342
+ },
2343
+ "binary": function(op, left, right) {
2344
+ return when_constant([ "binary", op, walk(left), walk(right) ], function yes(c){
2345
+ return best_of(walk(c), this);
2346
+ }, function no() {
2347
+ return this;
2348
+ });
2349
+ },
2350
+ "conditional": function(c, t, e) {
2351
+ return make_conditional(walk(c), walk(t), walk(e));
2352
+ },
2353
+ "try": function(t, c, f) {
2354
+ return [
2355
+ "try",
2356
+ tighten(MAP(t, walk)),
2357
+ c != null ? [ c[0], tighten(MAP(c[1], walk)) ] : null,
2358
+ f != null ? tighten(MAP(f, walk)) : null
2359
+ ];
2360
+ },
2361
+ "unary-prefix": function(op, expr) {
2362
+ expr = walk(expr);
2363
+ var ret = [ "unary-prefix", op, expr ];
2364
+ if (op == "!")
2365
+ ret = best_of(ret, negate(expr));
2366
+ return when_constant(ret, function(ast, val){
2367
+ return walk(ast); // it's either true or false, so minifies to !0 or !1
2368
+ }, function() { return ret });
2369
+ },
2370
+ "name": function(name) {
2371
+ switch (name) {
2372
+ case "true": return [ "unary-prefix", "!", [ "num", 0 ]];
2373
+ case "false": return [ "unary-prefix", "!", [ "num", 1 ]];
2374
+ }
2375
+ },
2376
+ "new": function(ctor, args) {
2377
+ if (ctor[0] == "name" && ctor[1] == "Array" && !scope.has("Array")) {
2378
+ if (args.length != 1) {
2379
+ return [ "array", args ];
2380
+ } else {
2381
+ return [ "call", [ "name", "Array" ], args ];
2382
+ }
2383
+ }
2384
+ },
2385
+ "call": function(expr, args) {
2386
+ if (expr[0] == "name" && expr[1] == "Array" && args.length != 1 && !scope.has("Array")) {
2387
+ return [ "array", args ];
2388
+ }
2389
+ },
2390
+ "while": _do_while,
2391
+ "do": _do_while
2392
+ }, function() {
2393
+ return walk(ast_add_scope(ast));
2394
+ });
2395
+ };
2396
+
2397
+ /* -----[ re-generate code from the AST ]----- */
2398
+
2399
+ var DOT_CALL_NO_PARENS = jsp.array_to_hash([
2400
+ "name",
2401
+ "array",
2402
+ "object",
2403
+ "string",
2404
+ "dot",
2405
+ "sub",
2406
+ "call",
2407
+ "regexp"
2408
+ ]);
2409
+
2410
+ function make_string(str, ascii_only) {
2411
+ var dq = 0, sq = 0;
2412
+ str = str.replace(/[\\\b\f\n\r\t\x22\x27\u2028\u2029]/g, function(s){
2413
+ switch (s) {
2414
+ case "\\": return "\\\\";
2415
+ case "\b": return "\\b";
2416
+ case "\f": return "\\f";
2417
+ case "\n": return "\\n";
2418
+ case "\r": return "\\r";
2419
+ case "\t": return "\\t";
2420
+ case "\u2028": return "\\u2028";
2421
+ case "\u2029": return "\\u2029";
2422
+ case '"': ++dq; return '"';
2423
+ case "'": ++sq; return "'";
2424
+ }
2425
+ return s;
2426
+ });
2427
+ if (ascii_only) str = to_ascii(str);
2428
+ if (dq > sq) return "'" + str.replace(/\x27/g, "\\'") + "'";
2429
+ else return '"' + str.replace(/\x22/g, '\\"') + '"';
2430
+ };
2431
+
2432
+ function to_ascii(str) {
2433
+ return str.replace(/[\u0080-\uffff]/g, function(ch) {
2434
+ var code = ch.charCodeAt(0).toString(16);
2435
+ while (code.length < 4) code = "0" + code;
2436
+ return "\\u" + code;
2437
+ });
2438
+ };
2439
+
2440
+ function gen_code(ast, options) {
2441
+ options = defaults(options, {
2442
+ indent_start : 0,
2443
+ indent_level : 4,
2444
+ quote_keys : false,
2445
+ space_colon : false,
2446
+ beautify : false,
2447
+ ascii_only : false
2448
+ });
2449
+ var beautify = !!options.beautify;
2450
+ var indentation = 0,
2451
+ newline = beautify ? "\n" : "",
2452
+ space = beautify ? " " : "";
2453
+
2454
+ function encode_string(str) {
2455
+ return make_string(str, options.ascii_only);
2456
+ };
2457
+
2458
+ function make_name(name) {
2459
+ name = name.toString();
2460
+ if (options.ascii_only)
2461
+ name = to_ascii(name);
2462
+ return name;
2463
+ };
2464
+
2465
+ function indent(line) {
2466
+ if (line == null)
2467
+ line = "";
2468
+ if (beautify)
2469
+ line = repeat_string(" ", options.indent_start + indentation * options.indent_level) + line;
2470
+ return line;
2471
+ };
2472
+
2473
+ function with_indent(cont, incr) {
2474
+ if (incr == null) incr = 1;
2475
+ indentation += incr;
2476
+ try { return cont.apply(null, slice(arguments, 1)); }
2477
+ finally { indentation -= incr; }
2478
+ };
2479
+
2480
+ function add_spaces(a) {
2481
+ if (beautify)
2482
+ return a.join(" ");
2483
+ var b = [];
2484
+ for (var i = 0; i < a.length; ++i) {
2485
+ var next = a[i + 1];
2486
+ b.push(a[i]);
2487
+ if (next &&
2488
+ ((/[a-z0-9_\x24]$/i.test(a[i].toString()) && /^[a-z0-9_\x24]/i.test(next.toString())) ||
2489
+ (/[\+\-]$/.test(a[i].toString()) && /^[\+\-]/.test(next.toString())))) {
2490
+ b.push(" ");
2491
+ }
2492
+ }
2493
+ return b.join("");
2494
+ };
2495
+
2496
+ function add_commas(a) {
2497
+ return a.join("," + space);
2498
+ };
2499
+
2500
+ function parenthesize(expr) {
2501
+ var gen = make(expr);
2502
+ for (var i = 1; i < arguments.length; ++i) {
2503
+ var el = arguments[i];
2504
+ if ((el instanceof Function && el(expr)) || expr[0] == el)
2505
+ return "(" + gen + ")";
2506
+ }
2507
+ return gen;
2508
+ };
2509
+
2510
+ function best_of(a) {
2511
+ if (a.length == 1) {
2512
+ return a[0];
2513
+ }
2514
+ if (a.length == 2) {
2515
+ var b = a[1];
2516
+ a = a[0];
2517
+ return a.length <= b.length ? a : b;
2518
+ }
2519
+ return best_of([ a[0], best_of(a.slice(1)) ]);
2520
+ };
2521
+
2522
+ function needs_parens(expr) {
2523
+ if (expr[0] == "function" || expr[0] == "object") {
2524
+ // dot/call on a literal function requires the
2525
+ // function literal itself to be parenthesized
2526
+ // only if it's the first "thing" in a
2527
+ // statement. This means that the parent is
2528
+ // "stat", but it could also be a "seq" and
2529
+ // we're the first in this "seq" and the
2530
+ // parent is "stat", and so on. Messy stuff,
2531
+ // but it worths the trouble.
2532
+ var a = slice($stack), self = a.pop(), p = a.pop();
2533
+ while (p) {
2534
+ if (p[0] == "stat") return true;
2535
+ if (((p[0] == "seq" || p[0] == "call" || p[0] == "dot" || p[0] == "sub" || p[0] == "conditional") && p[1] === self) ||
2536
+ ((p[0] == "binary" || p[0] == "assign" || p[0] == "unary-postfix") && p[2] === self)) {
2537
+ self = p;
2538
+ p = a.pop();
2539
+ } else {
2540
+ return false;
2541
+ }
2542
+ }
2543
+ }
2544
+ return !HOP(DOT_CALL_NO_PARENS, expr[0]);
2545
+ };
2546
+
2547
+ function make_num(num) {
2548
+ var str = num.toString(10), a = [ str.replace(/^0\./, ".") ], m;
2549
+ if (Math.floor(num) === num) {
2550
+ a.push("0x" + num.toString(16).toLowerCase(), // probably pointless
2551
+ "0" + num.toString(8)); // same.
2552
+ if ((m = /^(.*?)(0+)$/.exec(num))) {
2553
+ a.push(m[1] + "e" + m[2].length);
2554
+ }
2555
+ } else if ((m = /^0?\.(0+)(.*)$/.exec(num))) {
2556
+ a.push(m[2] + "e-" + (m[1].length + m[2].length),
2557
+ str.substr(str.indexOf(".")));
2558
+ }
2559
+ return best_of(a);
2560
+ };
2561
+
2562
+ var generators = {
2563
+ "string": encode_string,
2564
+ "num": make_num,
2565
+ "name": make_name,
2566
+ "toplevel": function(statements) {
2567
+ return make_block_statements(statements)
2568
+ .join(newline + newline);
2569
+ },
2570
+ "block": make_block,
2571
+ "var": function(defs) {
2572
+ return "var " + add_commas(MAP(defs, make_1vardef)) + ";";
2573
+ },
2574
+ "const": function(defs) {
2575
+ return "const " + add_commas(MAP(defs, make_1vardef)) + ";";
2576
+ },
2577
+ "try": function(tr, ca, fi) {
2578
+ var out = [ "try", make_block(tr) ];
2579
+ if (ca) out.push("catch", "(" + ca[0] + ")", make_block(ca[1]));
2580
+ if (fi) out.push("finally", make_block(fi));
2581
+ return add_spaces(out);
2582
+ },
2583
+ "throw": function(expr) {
2584
+ return add_spaces([ "throw", make(expr) ]) + ";";
2585
+ },
2586
+ "new": function(ctor, args) {
2587
+ args = args.length > 0 ? "(" + add_commas(MAP(args, make)) + ")" : "";
2588
+ return add_spaces([ "new", parenthesize(ctor, "seq", "binary", "conditional", "assign", function(expr){
2589
+ var w = ast_walker(), has_call = {};
2590
+ try {
2591
+ w.with_walkers({
2592
+ "call": function() { throw has_call },
2593
+ "function": function() { return this }
2594
+ }, function(){
2595
+ w.walk(expr);
2596
+ });
2597
+ } catch(ex) {
2598
+ if (ex === has_call)
2599
+ return true;
2600
+ throw ex;
2601
+ }
2602
+ }) + args ]);
2603
+ },
2604
+ "switch": function(expr, body) {
2605
+ return add_spaces([ "switch", "(" + make(expr) + ")", make_switch_block(body) ]);
2606
+ },
2607
+ "break": function(label) {
2608
+ var out = "break";
2609
+ if (label != null)
2610
+ out += " " + make_name(label);
2611
+ return out + ";";
2612
+ },
2613
+ "continue": function(label) {
2614
+ var out = "continue";
2615
+ if (label != null)
2616
+ out += " " + make_name(label);
2617
+ return out + ";";
2618
+ },
2619
+ "conditional": function(co, th, el) {
2620
+ return add_spaces([ parenthesize(co, "assign", "seq", "conditional"), "?",
2621
+ parenthesize(th, "seq"), ":",
2622
+ parenthesize(el, "seq") ]);
2623
+ },
2624
+ "assign": function(op, lvalue, rvalue) {
2625
+ if (op && op !== true) op += "=";
2626
+ else op = "=";
2627
+ return add_spaces([ make(lvalue), op, parenthesize(rvalue, "seq") ]);
2628
+ },
2629
+ "dot": function(expr) {
2630
+ var out = make(expr), i = 1;
2631
+ if (expr[0] == "num") {
2632
+ if (!/\./.test(expr[1]))
2633
+ out += ".";
2634
+ } else if (needs_parens(expr))
2635
+ out = "(" + out + ")";
2636
+ while (i < arguments.length)
2637
+ out += "." + make_name(arguments[i++]);
2638
+ return out;
2639
+ },
2640
+ "call": function(func, args) {
2641
+ var f = make(func);
2642
+ if (needs_parens(func))
2643
+ f = "(" + f + ")";
2644
+ return f + "(" + add_commas(MAP(args, function(expr){
2645
+ return parenthesize(expr, "seq");
2646
+ })) + ")";
2647
+ },
2648
+ "function": make_function,
2649
+ "defun": make_function,
2650
+ "if": function(co, th, el) {
2651
+ var out = [ "if", "(" + make(co) + ")", el ? make_then(th) : make(th) ];
2652
+ if (el) {
2653
+ out.push("else", make(el));
2654
+ }
2655
+ return add_spaces(out);
2656
+ },
2657
+ "for": function(init, cond, step, block) {
2658
+ var out = [ "for" ];
2659
+ init = (init != null ? make(init) : "").replace(/;*\s*$/, ";" + space);
2660
+ cond = (cond != null ? make(cond) : "").replace(/;*\s*$/, ";" + space);
2661
+ step = (step != null ? make(step) : "").replace(/;*\s*$/, "");
2662
+ var args = init + cond + step;
2663
+ if (args == "; ; ") args = ";;";
2664
+ out.push("(" + args + ")", make(block));
2665
+ return add_spaces(out);
2666
+ },
2667
+ "for-in": function(vvar, key, hash, block) {
2668
+ return add_spaces([ "for", "(" +
2669
+ (vvar ? make(vvar).replace(/;+$/, "") : make(key)),
2670
+ "in",
2671
+ make(hash) + ")", make(block) ]);
2672
+ },
2673
+ "while": function(condition, block) {
2674
+ return add_spaces([ "while", "(" + make(condition) + ")", make(block) ]);
2675
+ },
2676
+ "do": function(condition, block) {
2677
+ return add_spaces([ "do", make(block), "while", "(" + make(condition) + ")" ]) + ";";
2678
+ },
2679
+ "return": function(expr) {
2680
+ var out = [ "return" ];
2681
+ if (expr != null) out.push(make(expr));
2682
+ return add_spaces(out) + ";";
2683
+ },
2684
+ "binary": function(operator, lvalue, rvalue) {
2685
+ var left = make(lvalue), right = make(rvalue);
2686
+ // XXX: I'm pretty sure other cases will bite here.
2687
+ // we need to be smarter.
2688
+ // adding parens all the time is the safest bet.
2689
+ if (member(lvalue[0], [ "assign", "conditional", "seq" ]) ||
2690
+ lvalue[0] == "binary" && PRECEDENCE[operator] > PRECEDENCE[lvalue[1]]) {
2691
+ left = "(" + left + ")";
2692
+ }
2693
+ if (member(rvalue[0], [ "assign", "conditional", "seq" ]) ||
2694
+ rvalue[0] == "binary" && PRECEDENCE[operator] >= PRECEDENCE[rvalue[1]] &&
2695
+ !(rvalue[1] == operator && member(operator, [ "&&", "||", "*" ]))) {
2696
+ right = "(" + right + ")";
2697
+ }
2698
+ return add_spaces([ left, operator, right ]);
2699
+ },
2700
+ "unary-prefix": function(operator, expr) {
2701
+ var val = make(expr);
2702
+ if (!(expr[0] == "num" || (expr[0] == "unary-prefix" && !HOP(OPERATORS, operator + expr[1])) || !needs_parens(expr)))
2703
+ val = "(" + val + ")";
2704
+ return operator + (jsp.is_alphanumeric_char(operator.charAt(0)) ? " " : "") + val;
2705
+ },
2706
+ "unary-postfix": function(operator, expr) {
2707
+ var val = make(expr);
2708
+ if (!(expr[0] == "num" || (expr[0] == "unary-postfix" && !HOP(OPERATORS, operator + expr[1])) || !needs_parens(expr)))
2709
+ val = "(" + val + ")";
2710
+ return val + operator;
2711
+ },
2712
+ "sub": function(expr, subscript) {
2713
+ var hash = make(expr);
2714
+ if (needs_parens(expr))
2715
+ hash = "(" + hash + ")";
2716
+ return hash + "[" + make(subscript) + "]";
2717
+ },
2718
+ "object": function(props) {
2719
+ if (props.length == 0)
2720
+ return "{}";
2721
+ return "{" + newline + with_indent(function(){
2722
+ return MAP(props, function(p){
2723
+ if (p.length == 3) {
2724
+ // getter/setter. The name is in p[0], the arg.list in p[1][2], the
2725
+ // body in p[1][3] and type ("get" / "set") in p[2].
2726
+ return indent(make_function(p[0], p[1][2], p[1][3], p[2]));
2727
+ }
2728
+ var key = p[0], val = make(p[1]);
2729
+ if (options.quote_keys) {
2730
+ key = encode_string(key);
2731
+ } else if ((typeof key == "number" || !beautify && +key + "" == key)
2732
+ && parseFloat(key) >= 0) {
2733
+ key = make_num(+key);
2734
+ } else if (!is_identifier(key)) {
2735
+ key = encode_string(key);
2736
+ }
2737
+ return indent(add_spaces(beautify && options.space_colon
2738
+ ? [ key, ":", val ]
2739
+ : [ key + ":", val ]));
2740
+ }).join("," + newline);
2741
+ }) + newline + indent("}");
2742
+ },
2743
+ "regexp": function(rx, mods) {
2744
+ return "/" + rx + "/" + mods;
2745
+ },
2746
+ "array": function(elements) {
2747
+ if (elements.length == 0) return "[]";
2748
+ return add_spaces([ "[", add_commas(MAP(elements, function(el){
2749
+ if (!beautify && el[0] == "atom" && el[1] == "undefined") return "";
2750
+ return parenthesize(el, "seq");
2751
+ })), "]" ]);
2752
+ },
2753
+ "stat": function(stmt) {
2754
+ return make(stmt).replace(/;*\s*$/, ";");
2755
+ },
2756
+ "seq": function() {
2757
+ return add_commas(MAP(slice(arguments), make));
2758
+ },
2759
+ "label": function(name, block) {
2760
+ return add_spaces([ make_name(name), ":", make(block) ]);
2761
+ },
2762
+ "with": function(expr, block) {
2763
+ return add_spaces([ "with", "(" + make(expr) + ")", make(block) ]);
2764
+ },
2765
+ "atom": function(name) {
2766
+ return make_name(name);
2767
+ }
2768
+ };
2769
+
2770
+ // The squeezer replaces "block"-s that contain only a single
2771
+ // statement with the statement itself; technically, the AST
2772
+ // is correct, but this can create problems when we output an
2773
+ // IF having an ELSE clause where the THEN clause ends in an
2774
+ // IF *without* an ELSE block (then the outer ELSE would refer
2775
+ // to the inner IF). This function checks for this case and
2776
+ // adds the block brackets if needed.
2777
+ function make_then(th) {
2778
+ if (th[0] == "do") {
2779
+ // https://github.com/mishoo/UglifyJS/issues/#issue/57
2780
+ // IE croaks with "syntax error" on code like this:
2781
+ // if (foo) do ... while(cond); else ...
2782
+ // we need block brackets around do/while
2783
+ return make([ "block", [ th ]]);
2784
+ }
2785
+ var b = th;
2786
+ while (true) {
2787
+ var type = b[0];
2788
+ if (type == "if") {
2789
+ if (!b[3])
2790
+ // no else, we must add the block
2791
+ return make([ "block", [ th ]]);
2792
+ b = b[3];
2793
+ }
2794
+ else if (type == "while" || type == "do") b = b[2];
2795
+ else if (type == "for" || type == "for-in") b = b[4];
2796
+ else break;
2797
+ }
2798
+ return make(th);
2799
+ };
2800
+
2801
+ function make_function(name, args, body, keyword) {
2802
+ var out = keyword || "function";
2803
+ if (name) {
2804
+ out += " " + make_name(name);
2805
+ }
2806
+ out += "(" + add_commas(MAP(args, make_name)) + ")";
2807
+ return add_spaces([ out, make_block(body) ]);
2808
+ };
2809
+
2810
+ function make_block_statements(statements) {
2811
+ for (var a = [], last = statements.length - 1, i = 0; i <= last; ++i) {
2812
+ var stat = statements[i];
2813
+ var code = make(stat);
2814
+ if (code != ";") {
2815
+ if (!beautify && i == last) {
2816
+ if ((stat[0] == "while" && empty(stat[2])) ||
2817
+ (member(stat[0], [ "for", "for-in"] ) && empty(stat[4])) ||
2818
+ (stat[0] == "if" && empty(stat[2]) && !stat[3]) ||
2819
+ (stat[0] == "if" && stat[3] && empty(stat[3]))) {
2820
+ code = code.replace(/;*\s*$/, ";");
2821
+ } else {
2822
+ code = code.replace(/;+\s*$/, "");
2823
+ }
2824
+ }
2825
+ a.push(code);
2826
+ }
2827
+ }
2828
+ return MAP(a, indent);
2829
+ };
2830
+
2831
+ function make_switch_block(body) {
2832
+ var n = body.length;
2833
+ if (n == 0) return "{}";
2834
+ return "{" + newline + MAP(body, function(branch, i){
2835
+ var has_body = branch[1].length > 0, code = with_indent(function(){
2836
+ return indent(branch[0]
2837
+ ? add_spaces([ "case", make(branch[0]) + ":" ])
2838
+ : "default:");
2839
+ }, 0.5) + (has_body ? newline + with_indent(function(){
2840
+ return make_block_statements(branch[1]).join(newline);
2841
+ }) : "");
2842
+ if (!beautify && has_body && i < n - 1)
2843
+ code += ";";
2844
+ return code;
2845
+ }).join(newline) + newline + indent("}");
2846
+ };
2847
+
2848
+ function make_block(statements) {
2849
+ if (!statements) return ";";
2850
+ if (statements.length == 0) return "{}";
2851
+ return "{" + newline + with_indent(function(){
2852
+ return make_block_statements(statements).join(newline);
2853
+ }) + newline + indent("}");
2854
+ };
2855
+
2856
+ function make_1vardef(def) {
2857
+ var name = def[0], val = def[1];
2858
+ if (val != null)
2859
+ name = add_spaces([ make_name(name), "=", make(val) ]);
2860
+ return name;
2861
+ };
2862
+
2863
+ var $stack = [];
2864
+
2865
+ function make(node) {
2866
+ var type = node[0];
2867
+ var gen = generators[type];
2868
+ if (!gen)
2869
+ throw new Error("Can't find generator for \"" + type + "\"");
2870
+ $stack.push(node);
2871
+ var ret = gen.apply(type, node.slice(1));
2872
+ $stack.pop();
2873
+ return ret;
2874
+ };
2875
+
2876
+ return make(ast);
2877
+ };
2878
+
2879
+ function split_lines(code, max_line_length) {
2880
+ var splits = [ 0 ];
2881
+ jsp.parse(function(){
2882
+ var next_token = jsp.tokenizer(code);
2883
+ var last_split = 0;
2884
+ var prev_token;
2885
+ function current_length(tok) {
2886
+ return tok.pos - last_split;
2887
+ };
2888
+ function split_here(tok) {
2889
+ last_split = tok.pos;
2890
+ splits.push(last_split);
2891
+ };
2892
+ function custom(){
2893
+ var tok = next_token.apply(this, arguments);
2894
+ out: {
2895
+ if (prev_token) {
2896
+ if (prev_token.type == "keyword") break out;
2897
+ }
2898
+ if (current_length(tok) > max_line_length) {
2899
+ switch (tok.type) {
2900
+ case "keyword":
2901
+ case "atom":
2902
+ case "name":
2903
+ case "punc":
2904
+ split_here(tok);
2905
+ break out;
2906
+ }
2907
+ }
2908
+ }
2909
+ prev_token = tok;
2910
+ return tok;
2911
+ };
2912
+ custom.context = function() {
2913
+ return next_token.context.apply(this, arguments);
2914
+ };
2915
+ return custom;
2916
+ }());
2917
+ return splits.map(function(pos, i){
2918
+ return code.substring(pos, splits[i + 1] || code.length);
2919
+ }).join("\n");
2920
+ };
2921
+
2922
+ /* -----[ Utilities ]----- */
2923
+
2924
+ function repeat_string(str, i) {
2925
+ if (i <= 0) return "";
2926
+ if (i == 1) return str;
2927
+ var d = repeat_string(str, i >> 1);
2928
+ d += d;
2929
+ if (i & 1) d += str;
2930
+ return d;
2931
+ };
2932
+
2933
+ function defaults(args, defs) {
2934
+ var ret = {};
2935
+ if (args === true)
2936
+ args = {};
2937
+ for (var i in defs) if (HOP(defs, i)) {
2938
+ ret[i] = (args && HOP(args, i)) ? args[i] : defs[i];
2939
+ }
2940
+ return ret;
2941
+ };
2942
+
2943
+ function is_identifier(name) {
2944
+ return /^[a-z_$][a-z0-9_$]*$/i.test(name)
2945
+ && name != "this"
2946
+ && !HOP(jsp.KEYWORDS_ATOM, name)
2947
+ && !HOP(jsp.RESERVED_WORDS, name)
2948
+ && !HOP(jsp.KEYWORDS, name);
2949
+ };
2950
+
2951
+ function HOP(obj, prop) {
2952
+ return Object.prototype.hasOwnProperty.call(obj, prop);
2953
+ };
2954
+
2955
+ // some utilities
2956
+
2957
+ var MAP;
2958
+
2959
+ (function(){
2960
+ MAP = function(a, f, o) {
2961
+ var ret = [];
2962
+ for (var i = 0; i < a.length; ++i) {
2963
+ var val = f.call(o, a[i], i);
2964
+ if (val instanceof AtTop) ret.unshift(val.v);
2965
+ else ret.push(val);
2966
+ }
2967
+ return ret;
2968
+ };
2969
+ MAP.at_top = function(val) { return new AtTop(val) };
2970
+ function AtTop(val) { this.v = val };
2971
+ })();
2972
+
2973
+ /* -----[ Exports ]----- */
2974
+
2975
+ exports.ast_walker = ast_walker;
2976
+ exports.ast_mangle = ast_mangle;
2977
+ exports.ast_squeeze = ast_squeeze;
2978
+ exports.gen_code = gen_code;
2979
+ exports.ast_add_scope = ast_add_scope;
2980
+ exports.set_logger = function(logger) { warn = logger };
2981
+ exports.make_string = make_string;
2982
+ exports.split_lines = split_lines;
2983
+ exports.MAP = MAP;
2984
+
2985
+ // keep this last!
2986
+ exports.ast_squeeze_more = require("./squeeze-more").ast_squeeze_more;
2987
+ }, "squeeze-more": function(exports, require, module) {var jsp = require("./parse-js"),
2988
+ pro = require("./process"),
2989
+ slice = jsp.slice,
2990
+ member = jsp.member,
2991
+ PRECEDENCE = jsp.PRECEDENCE,
2992
+ OPERATORS = jsp.OPERATORS;
2993
+
2994
+ function ast_squeeze_more(ast) {
2995
+ var w = pro.ast_walker(), walk = w.walk;
2996
+ return w.with_walkers({
2997
+ "call": function(expr, args) {
2998
+ if (expr[0] == "dot" && expr[2] == "toString" && args.length == 0) {
2999
+ // foo.toString() ==> foo+""
3000
+ return [ "binary", "+", expr[1], [ "string", "" ]];
3001
+ }
3002
+ }
3003
+ }, function() {
3004
+ return walk(ast);
3005
+ });
3006
+ };
3007
+
3008
+ exports.ast_squeeze_more = ast_squeeze_more;
3009
+ }});
3010
+ ;
3011
+ global.UglifyJS = {};
3012
+ global.UglifyJS.parser = this.require('parse-js');
3013
+ global.UglifyJS.uglify = this.require('process');
3014
+ }).call({}, this);