react / react-0.13.3 / examples / basic-commonjs / node_modules / browserify / node_modules / umd / node_modules / uglify-js / lib / parse.js
80743 views/***********************************************************************12A JavaScript tokenizer / parser / beautifier / compressor.3https://github.com/mishoo/UglifyJS245-------------------------------- (C) ---------------------------------67Author: Mihai Bazon8<[email protected]>9http://mihai.bazon.net/blog1011Distributed under the BSD license:1213Copyright 2012 (c) Mihai Bazon <[email protected]>14Parser based on parse-js (http://marijn.haverbeke.nl/parse-js/).1516Redistribution and use in source and binary forms, with or without17modification, are permitted provided that the following conditions18are met:1920* Redistributions of source code must retain the above21copyright notice, this list of conditions and the following22disclaimer.2324* Redistributions in binary form must reproduce the above25copyright notice, this list of conditions and the following26disclaimer in the documentation and/or other materials27provided with the distribution.2829THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY30EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE31IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR32PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE33LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,34OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,35PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR36PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY37THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR38TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF39THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF40SUCH DAMAGE.4142***********************************************************************/4344"use strict";4546var KEYWORDS = 'break case catch const continue debugger default delete do else finally for function if in instanceof new return switch throw try typeof var void while with';47var KEYWORDS_ATOM = 'false null true';48var RESERVED_WORDS = 'abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized this throws transient volatile yield'49+ " " + KEYWORDS_ATOM + " " + KEYWORDS;50var KEYWORDS_BEFORE_EXPRESSION = 'return new delete throw else case';5152KEYWORDS = makePredicate(KEYWORDS);53RESERVED_WORDS = makePredicate(RESERVED_WORDS);54KEYWORDS_BEFORE_EXPRESSION = makePredicate(KEYWORDS_BEFORE_EXPRESSION);55KEYWORDS_ATOM = makePredicate(KEYWORDS_ATOM);5657var OPERATOR_CHARS = makePredicate(characters("+-*&%=<>!?|~^"));5859var RE_HEX_NUMBER = /^0x[0-9a-f]+$/i;60var RE_OCT_NUMBER = /^0[0-7]+$/;61var RE_DEC_NUMBER = /^\d*\.?\d*(?:e[+-]?\d*(?:\d\.?|\.?\d)\d*)?$/i;6263var OPERATORS = makePredicate([64"in",65"instanceof",66"typeof",67"new",68"void",69"delete",70"++",71"--",72"+",73"-",74"!",75"~",76"&",77"|",78"^",79"*",80"/",81"%",82">>",83"<<",84">>>",85"<",86">",87"<=",88">=",89"==",90"===",91"!=",92"!==",93"?",94"=",95"+=",96"-=",97"/=",98"*=",99"%=",100">>=",101"<<=",102">>>=",103"|=",104"^=",105"&=",106"&&",107"||"108]);109110var WHITESPACE_CHARS = makePredicate(characters(" \u00a0\n\r\t\f\u000b\u200b\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\uFEFF"));111112var PUNC_BEFORE_EXPRESSION = makePredicate(characters("[{(,.;:"));113114var PUNC_CHARS = makePredicate(characters("[]{}(),;:"));115116var REGEXP_MODIFIERS = makePredicate(characters("gmsiy"));117118/* -----[ Tokenizer ]----- */119120// regexps adapted from http://xregexp.com/plugins/#unicode121var UNICODE = {122letter: 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\\u037F\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u048A-\\u052F\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0620-\\u064A\\u066E\\u066F\\u0671-\\u06D3\\u06D5\\u06E5\\u06E6\\u06EE\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4\\u07F5\\u07FA\\u0800-\\u0815\\u081A\\u0824\\u0828\\u0840-\\u0858\\u08A0-\\u08B2\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0971-\\u0980\\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-\\u0C39\\u0C3D\\u0C58\\u0C59\\u0C60\\u0C61\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDE\\u0CE0\\u0CE1\\u0CF1\\u0CF2\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D3A\\u0D3D\\u0D4E\\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-\\u0EDF\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8C\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10A0-\\u10C5\\u10C7\\u10CD\\u10D0-\\u10FA\\u10FC-\\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-\\u167F\\u1681-\\u169A\\u16A0-\\u16EA\\u16EE-\\u16F8\\u1700-\\u170C\\u170E-\\u1711\\u1720-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17D7\\u17DC\\u1820-\\u1877\\u1880-\\u18A8\\u18AA\\u18B0-\\u18F5\\u1900-\\u191E\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19AB\\u19C1-\\u19C7\\u1A00-\\u1A16\\u1A20-\\u1A54\\u1AA7\\u1B05-\\u1B33\\u1B45-\\u1B4B\\u1B83-\\u1BA0\\u1BAE\\u1BAF\\u1BBA-\\u1BE5\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C7D\\u1CE9-\\u1CEC\\u1CEE-\\u1CF1\\u1CF5\\u1CF6\\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-\\u209C\\u2102\\u2107\\u210A-\\u2113\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u212F-\\u2139\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2160-\\u2188\\u2C00-\\u2C2E\\u2C30-\\u2C5E\\u2C60-\\u2CE4\\u2CEB-\\u2CEE\\u2CF2\\u2CF3\\u2D00-\\u2D25\\u2D27\\u2D2D\\u2D30-\\u2D67\\u2D6F\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u2E2F\\u3005-\\u3007\\u3021-\\u3029\\u3031-\\u3035\\u3038-\\u303C\\u3041-\\u3096\\u309D-\\u309F\\u30A1-\\u30FA\\u30FC-\\u30FF\\u3105-\\u312D\\u3131-\\u318E\\u31A0-\\u31BA\\u31F0-\\u31FF\\u3400-\\u4DB5\\u4E00-\\u9FCC\\uA000-\\uA48C\\uA4D0-\\uA4FD\\uA500-\\uA60C\\uA610-\\uA61F\\uA62A\\uA62B\\uA640-\\uA66E\\uA67F-\\uA69D\\uA6A0-\\uA6EF\\uA717-\\uA71F\\uA722-\\uA788\\uA78B-\\uA78E\\uA790-\\uA7AD\\uA7B0\\uA7B1\\uA7F7-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA8F2-\\uA8F7\\uA8FB\\uA90A-\\uA925\\uA930-\\uA946\\uA960-\\uA97C\\uA984-\\uA9B2\\uA9CF\\uA9E0-\\uA9E4\\uA9E6-\\uA9EF\\uA9FA-\\uA9FE\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAA60-\\uAA76\\uAA7A\\uAA7E-\\uAAAF\\uAAB1\\uAAB5\\uAAB6\\uAAB9-\\uAABD\\uAAC0\\uAAC2\\uAADB-\\uAADD\\uAAE0-\\uAAEA\\uAAF2-\\uAAF4\\uAB01-\\uAB06\\uAB09-\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uAB30-\\uAB5A\\uAB5C-\\uAB5F\\uAB64\\uAB65\\uABC0-\\uABE2\\uAC00-\\uD7A3\\uD7B0-\\uD7C6\\uD7CB-\\uD7FB\\uF900-\\uFA6D\\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]"),123digit: new RegExp("[\\u0030-\\u0039\\u0660-\\u0669\\u06F0-\\u06F9\\u07C0-\\u07C9\\u0966-\\u096F\\u09E6-\\u09EF\\u0A66-\\u0A6F\\u0AE6-\\u0AEF\\u0B66-\\u0B6F\\u0BE6-\\u0BEF\\u0C66-\\u0C6F\\u0CE6-\\u0CEF\\u0D66-\\u0D6F\\u0DE6-\\u0DEF\\u0E50-\\u0E59\\u0ED0-\\u0ED9\\u0F20-\\u0F29\\u1040-\\u1049\\u1090-\\u1099\\u17E0-\\u17E9\\u1810-\\u1819\\u1946-\\u194F\\u19D0-\\u19D9\\u1A80-\\u1A89\\u1A90-\\u1A99\\u1B50-\\u1B59\\u1BB0-\\u1BB9\\u1C40-\\u1C49\\u1C50-\\u1C59\\uA620-\\uA629\\uA8D0-\\uA8D9\\uA900-\\uA909\\uA9D0-\\uA9D9\\uA9F0-\\uA9F9\\uAA50-\\uAA59\\uABF0-\\uABF9\\uFF10-\\uFF19]"),124non_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]"),125space_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]"),126connector_punctuation: new RegExp("[\\u005F\\u203F\\u2040\\u2054\\uFE33\\uFE34\\uFE4D-\\uFE4F\\uFF3F]")127};128129function is_letter(code) {130return (code >= 97 && code <= 122)131|| (code >= 65 && code <= 90)132|| (code >= 0xaa && UNICODE.letter.test(String.fromCharCode(code)));133};134135function is_digit(code) {136return code >= 48 && code <= 57;137};138139function is_alphanumeric_char(code) {140return is_digit(code) || is_letter(code);141};142143function is_unicode_digit(code) {144return UNICODE.digit.test(String.fromCharCode(code));145}146147function is_unicode_combining_mark(ch) {148return UNICODE.non_spacing_mark.test(ch) || UNICODE.space_combining_mark.test(ch);149};150151function is_unicode_connector_punctuation(ch) {152return UNICODE.connector_punctuation.test(ch);153};154155function is_identifier(name) {156return !RESERVED_WORDS(name) && /^[a-z_$][a-z0-9_$]*$/i.test(name);157};158159function is_identifier_start(code) {160return code == 36 || code == 95 || is_letter(code);161};162163function is_identifier_char(ch) {164var code = ch.charCodeAt(0);165return is_identifier_start(code)166|| is_digit(code)167|| code == 8204 // \u200c: zero-width non-joiner <ZWNJ>168|| code == 8205 // \u200d: zero-width joiner <ZWJ> (in my ECMA-262 PDF, this is also 200c)169|| is_unicode_combining_mark(ch)170|| is_unicode_connector_punctuation(ch)171|| is_unicode_digit(code)172;173};174175function is_identifier_string(str){176return /^[a-z_$][a-z0-9_$]*$/i.test(str);177};178179function parse_js_number(num) {180if (RE_HEX_NUMBER.test(num)) {181return parseInt(num.substr(2), 16);182} else if (RE_OCT_NUMBER.test(num)) {183return parseInt(num.substr(1), 8);184} else if (RE_DEC_NUMBER.test(num)) {185return parseFloat(num);186}187};188189function JS_Parse_Error(message, filename, line, col, pos) {190this.message = message;191this.filename = filename;192this.line = line;193this.col = col;194this.pos = pos;195this.stack = new Error().stack;196};197198JS_Parse_Error.prototype.toString = function() {199return this.message + " (line: " + this.line + ", col: " + this.col + ", pos: " + this.pos + ")" + "\n\n" + this.stack;200};201202function js_error(message, filename, line, col, pos) {203throw new JS_Parse_Error(message, filename, line, col, pos);204};205206function is_token(token, type, val) {207return token.type == type && (val == null || token.value == val);208};209210var EX_EOF = {};211212function tokenizer($TEXT, filename, html5_comments) {213214var S = {215text : $TEXT,216filename : filename,217pos : 0,218tokpos : 0,219line : 1,220tokline : 0,221col : 0,222tokcol : 0,223newline_before : false,224regex_allowed : false,225comments_before : []226};227228function peek() { return S.text.charAt(S.pos); };229230function next(signal_eof, in_string) {231var ch = S.text.charAt(S.pos++);232if (signal_eof && !ch)233throw EX_EOF;234if ("\r\n\u2028\u2029".indexOf(ch) >= 0) {235S.newline_before = S.newline_before || !in_string;236++S.line;237S.col = 0;238if (!in_string && ch == "\r" && peek() == "\n") {239// treat a \r\n sequence as a single \n240++S.pos;241ch = "\n";242}243} else {244++S.col;245}246return ch;247};248249function forward(i) {250while (i-- > 0) next();251};252253function looking_at(str) {254return S.text.substr(S.pos, str.length) == str;255};256257function find(what, signal_eof) {258var pos = S.text.indexOf(what, S.pos);259if (signal_eof && pos == -1) throw EX_EOF;260return pos;261};262263function start_token() {264S.tokline = S.line;265S.tokcol = S.col;266S.tokpos = S.pos;267};268269var prev_was_dot = false;270function token(type, value, is_comment) {271S.regex_allowed = ((type == "operator" && !UNARY_POSTFIX(value)) ||272(type == "keyword" && KEYWORDS_BEFORE_EXPRESSION(value)) ||273(type == "punc" && PUNC_BEFORE_EXPRESSION(value)));274prev_was_dot = (type == "punc" && value == ".");275var ret = {276type : type,277value : value,278line : S.tokline,279col : S.tokcol,280pos : S.tokpos,281endline : S.line,282endcol : S.col,283endpos : S.pos,284nlb : S.newline_before,285file : filename286};287if (!is_comment) {288ret.comments_before = S.comments_before;289S.comments_before = [];290// make note of any newlines in the comments that came before291for (var i = 0, len = ret.comments_before.length; i < len; i++) {292ret.nlb = ret.nlb || ret.comments_before[i].nlb;293}294}295S.newline_before = false;296return new AST_Token(ret);297};298299function skip_whitespace() {300var ch;301while (WHITESPACE_CHARS(ch = peek()) || ch == "\u2028" || ch == "\u2029")302next();303};304305function read_while(pred) {306var ret = "", ch, i = 0;307while ((ch = peek()) && pred(ch, i++))308ret += next();309return ret;310};311312function parse_error(err) {313js_error(err, filename, S.tokline, S.tokcol, S.tokpos);314};315316function read_num(prefix) {317var has_e = false, after_e = false, has_x = false, has_dot = prefix == ".";318var num = read_while(function(ch, i){319var code = ch.charCodeAt(0);320switch (code) {321case 120: case 88: // xX322return has_x ? false : (has_x = true);323case 101: case 69: // eE324return has_x ? true : has_e ? false : (has_e = after_e = true);325case 45: // -326return after_e || (i == 0 && !prefix);327case 43: // +328return after_e;329case (after_e = false, 46): // .330return (!has_dot && !has_x && !has_e) ? (has_dot = true) : false;331}332return is_alphanumeric_char(code);333});334if (prefix) num = prefix + num;335var valid = parse_js_number(num);336if (!isNaN(valid)) {337return token("num", valid);338} else {339parse_error("Invalid syntax: " + num);340}341};342343function read_escaped_char(in_string) {344var ch = next(true, in_string);345switch (ch.charCodeAt(0)) {346case 110 : return "\n";347case 114 : return "\r";348case 116 : return "\t";349case 98 : return "\b";350case 118 : return "\u000b"; // \v351case 102 : return "\f";352case 48 : return "\0";353case 120 : return String.fromCharCode(hex_bytes(2)); // \x354case 117 : return String.fromCharCode(hex_bytes(4)); // \u355case 10 : return ""; // newline356case 13 : // \r357if (peek() == "\n") { // DOS newline358next(true, in_string);359return "";360}361}362return ch;363};364365function hex_bytes(n) {366var num = 0;367for (; n > 0; --n) {368var digit = parseInt(next(true), 16);369if (isNaN(digit))370parse_error("Invalid hex-character pattern in string");371num = (num << 4) | digit;372}373return num;374};375376var read_string = with_eof_error("Unterminated string constant", function(quote_char){377var quote = next(), ret = "";378for (;;) {379var ch = next(true, true);380if (ch == "\\") {381// read OctalEscapeSequence (XXX: deprecated if "strict mode")382// https://github.com/mishoo/UglifyJS/issues/178383var octal_len = 0, first = null;384ch = read_while(function(ch){385if (ch >= "0" && ch <= "7") {386if (!first) {387first = ch;388return ++octal_len;389}390else if (first <= "3" && octal_len <= 2) return ++octal_len;391else if (first >= "4" && octal_len <= 1) return ++octal_len;392}393return false;394});395if (octal_len > 0) ch = String.fromCharCode(parseInt(ch, 8));396else ch = read_escaped_char(true);397}398else if (ch == quote) break;399ret += ch;400}401var tok = token("string", ret);402tok.quote = quote_char;403return tok;404});405406function skip_line_comment(type) {407var regex_allowed = S.regex_allowed;408var i = find("\n"), ret;409if (i == -1) {410ret = S.text.substr(S.pos);411S.pos = S.text.length;412} else {413ret = S.text.substring(S.pos, i);414S.pos = i;415}416S.col = S.tokcol + (S.pos - S.tokpos);417S.comments_before.push(token(type, ret, true));418S.regex_allowed = regex_allowed;419return next_token();420};421422var skip_multiline_comment = with_eof_error("Unterminated multiline comment", function(){423var regex_allowed = S.regex_allowed;424var i = find("*/", true);425var text = S.text.substring(S.pos, i);426var a = text.split("\n"), n = a.length;427// update stream position428S.pos = i + 2;429S.line += n - 1;430if (n > 1) S.col = a[n - 1].length;431else S.col += a[n - 1].length;432S.col += 2;433var nlb = S.newline_before = S.newline_before || text.indexOf("\n") >= 0;434S.comments_before.push(token("comment2", text, true));435S.regex_allowed = regex_allowed;436S.newline_before = nlb;437return next_token();438});439440function read_name() {441var backslash = false, name = "", ch, escaped = false, hex;442while ((ch = peek()) != null) {443if (!backslash) {444if (ch == "\\") escaped = backslash = true, next();445else if (is_identifier_char(ch)) name += next();446else break;447}448else {449if (ch != "u") parse_error("Expecting UnicodeEscapeSequence -- uXXXX");450ch = read_escaped_char();451if (!is_identifier_char(ch)) parse_error("Unicode char: " + ch.charCodeAt(0) + " is not valid in identifier");452name += ch;453backslash = false;454}455}456if (KEYWORDS(name) && escaped) {457hex = name.charCodeAt(0).toString(16).toUpperCase();458name = "\\u" + "0000".substr(hex.length) + hex + name.slice(1);459}460return name;461};462463var read_regexp = with_eof_error("Unterminated regular expression", function(regexp){464var prev_backslash = false, ch, in_class = false;465while ((ch = next(true))) if (prev_backslash) {466regexp += "\\" + ch;467prev_backslash = false;468} else if (ch == "[") {469in_class = true;470regexp += ch;471} else if (ch == "]" && in_class) {472in_class = false;473regexp += ch;474} else if (ch == "/" && !in_class) {475break;476} else if (ch == "\\") {477prev_backslash = true;478} else {479regexp += ch;480}481var mods = read_name();482return token("regexp", new RegExp(regexp, mods));483});484485function read_operator(prefix) {486function grow(op) {487if (!peek()) return op;488var bigger = op + peek();489if (OPERATORS(bigger)) {490next();491return grow(bigger);492} else {493return op;494}495};496return token("operator", grow(prefix || next()));497};498499function handle_slash() {500next();501switch (peek()) {502case "/":503next();504return skip_line_comment("comment1");505case "*":506next();507return skip_multiline_comment();508}509return S.regex_allowed ? read_regexp("") : read_operator("/");510};511512function handle_dot() {513next();514return is_digit(peek().charCodeAt(0))515? read_num(".")516: token("punc", ".");517};518519function read_word() {520var word = read_name();521if (prev_was_dot) return token("name", word);522return KEYWORDS_ATOM(word) ? token("atom", word)523: !KEYWORDS(word) ? token("name", word)524: OPERATORS(word) ? token("operator", word)525: token("keyword", word);526};527528function with_eof_error(eof_error, cont) {529return function(x) {530try {531return cont(x);532} catch(ex) {533if (ex === EX_EOF) parse_error(eof_error);534else throw ex;535}536};537};538539function next_token(force_regexp) {540if (force_regexp != null)541return read_regexp(force_regexp);542skip_whitespace();543start_token();544if (html5_comments) {545if (looking_at("<!--")) {546forward(4);547return skip_line_comment("comment3");548}549if (looking_at("-->") && S.newline_before) {550forward(3);551return skip_line_comment("comment4");552}553}554var ch = peek();555if (!ch) return token("eof");556var code = ch.charCodeAt(0);557switch (code) {558case 34: case 39: return read_string(ch);559case 46: return handle_dot();560case 47: return handle_slash();561}562if (is_digit(code)) return read_num();563if (PUNC_CHARS(ch)) return token("punc", next());564if (OPERATOR_CHARS(ch)) return read_operator();565if (code == 92 || is_identifier_start(code)) return read_word();566parse_error("Unexpected character '" + ch + "'");567};568569next_token.context = function(nc) {570if (nc) S = nc;571return S;572};573574return next_token;575576};577578/* -----[ Parser (constants) ]----- */579580var UNARY_PREFIX = makePredicate([581"typeof",582"void",583"delete",584"--",585"++",586"!",587"~",588"-",589"+"590]);591592var UNARY_POSTFIX = makePredicate([ "--", "++" ]);593594var ASSIGNMENT = makePredicate([ "=", "+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=" ]);595596var PRECEDENCE = (function(a, ret){597for (var i = 0; i < a.length; ++i) {598var b = a[i];599for (var j = 0; j < b.length; ++j) {600ret[b[j]] = i + 1;601}602}603return ret;604})(605[606["||"],607["&&"],608["|"],609["^"],610["&"],611["==", "===", "!=", "!=="],612["<", ">", "<=", ">=", "in", "instanceof"],613[">>", "<<", ">>>"],614["+", "-"],615["*", "/", "%"]616],617{}618);619620var STATEMENTS_WITH_LABELS = array_to_hash([ "for", "do", "while", "switch" ]);621622var ATOMIC_START_TOKEN = array_to_hash([ "atom", "num", "string", "regexp", "name" ]);623624/* -----[ Parser ]----- */625626function parse($TEXT, options) {627628options = defaults(options, {629strict : false,630filename : null,631toplevel : null,632expression : false,633html5_comments : true,634bare_returns : false,635});636637var S = {638input : (typeof $TEXT == "string"639? tokenizer($TEXT, options.filename,640options.html5_comments)641: $TEXT),642token : null,643prev : null,644peeked : null,645in_function : 0,646in_directives : true,647in_loop : 0,648labels : []649};650651S.token = next();652653function is(type, value) {654return is_token(S.token, type, value);655};656657function peek() { return S.peeked || (S.peeked = S.input()); };658659function next() {660S.prev = S.token;661if (S.peeked) {662S.token = S.peeked;663S.peeked = null;664} else {665S.token = S.input();666}667S.in_directives = S.in_directives && (668S.token.type == "string" || is("punc", ";")669);670return S.token;671};672673function prev() {674return S.prev;675};676677function croak(msg, line, col, pos) {678var ctx = S.input.context();679js_error(msg,680ctx.filename,681line != null ? line : ctx.tokline,682col != null ? col : ctx.tokcol,683pos != null ? pos : ctx.tokpos);684};685686function token_error(token, msg) {687croak(msg, token.line, token.col);688};689690function unexpected(token) {691if (token == null)692token = S.token;693token_error(token, "Unexpected token: " + token.type + " (" + token.value + ")");694};695696function expect_token(type, val) {697if (is(type, val)) {698return next();699}700token_error(S.token, "Unexpected token " + S.token.type + " «" + S.token.value + "»" + ", expected " + type + " «" + val + "»");701};702703function expect(punc) { return expect_token("punc", punc); };704705function can_insert_semicolon() {706return !options.strict && (707S.token.nlb || is("eof") || is("punc", "}")708);709};710711function semicolon() {712if (is("punc", ";")) next();713else if (!can_insert_semicolon()) unexpected();714};715716function parenthesised() {717expect("(");718var exp = expression(true);719expect(")");720return exp;721};722723function embed_tokens(parser) {724return function() {725var start = S.token;726var expr = parser();727var end = prev();728expr.start = start;729expr.end = end;730return expr;731};732};733734function handle_regexp() {735if (is("operator", "/") || is("operator", "/=")) {736S.peeked = null;737S.token = S.input(S.token.value.substr(1)); // force regexp738}739};740741var statement = embed_tokens(function() {742var tmp;743handle_regexp();744switch (S.token.type) {745case "string":746var dir = S.in_directives, stat = simple_statement();747// XXXv2: decide how to fix directives748if (dir && stat.body instanceof AST_String && !is("punc", ",")) {749return new AST_Directive({750start : stat.body.start,751end : stat.body.end,752quote : stat.body.quote,753value : stat.body.value,754});755}756return stat;757case "num":758case "regexp":759case "operator":760case "atom":761return simple_statement();762763case "name":764return is_token(peek(), "punc", ":")765? labeled_statement()766: simple_statement();767768case "punc":769switch (S.token.value) {770case "{":771return new AST_BlockStatement({772start : S.token,773body : block_(),774end : prev()775});776case "[":777case "(":778return simple_statement();779case ";":780next();781return new AST_EmptyStatement();782default:783unexpected();784}785786case "keyword":787switch (tmp = S.token.value, next(), tmp) {788case "break":789return break_cont(AST_Break);790791case "continue":792return break_cont(AST_Continue);793794case "debugger":795semicolon();796return new AST_Debugger();797798case "do":799return new AST_Do({800body : in_loop(statement),801condition : (expect_token("keyword", "while"), tmp = parenthesised(), semicolon(), tmp)802});803804case "while":805return new AST_While({806condition : parenthesised(),807body : in_loop(statement)808});809810case "for":811return for_();812813case "function":814return function_(AST_Defun);815816case "if":817return if_();818819case "return":820if (S.in_function == 0 && !options.bare_returns)821croak("'return' outside of function");822return new AST_Return({823value: ( is("punc", ";")824? (next(), null)825: can_insert_semicolon()826? null827: (tmp = expression(true), semicolon(), tmp) )828});829830case "switch":831return new AST_Switch({832expression : parenthesised(),833body : in_loop(switch_body_)834});835836case "throw":837if (S.token.nlb)838croak("Illegal newline after 'throw'");839return new AST_Throw({840value: (tmp = expression(true), semicolon(), tmp)841});842843case "try":844return try_();845846case "var":847return tmp = var_(), semicolon(), tmp;848849case "const":850return tmp = const_(), semicolon(), tmp;851852case "with":853return new AST_With({854expression : parenthesised(),855body : statement()856});857858default:859unexpected();860}861}862});863864function labeled_statement() {865var label = as_symbol(AST_Label);866if (find_if(function(l){ return l.name == label.name }, S.labels)) {867// ECMA-262, 12.12: An ECMAScript program is considered868// syntactically incorrect if it contains a869// LabelledStatement that is enclosed by a870// LabelledStatement with the same Identifier as label.871croak("Label " + label.name + " defined twice");872}873expect(":");874S.labels.push(label);875var stat = statement();876S.labels.pop();877if (!(stat instanceof AST_IterationStatement)) {878// check for `continue` that refers to this label.879// those should be reported as syntax errors.880// https://github.com/mishoo/UglifyJS2/issues/287881label.references.forEach(function(ref){882if (ref instanceof AST_Continue) {883ref = ref.label.start;884croak("Continue label `" + label.name + "` refers to non-IterationStatement.",885ref.line, ref.col, ref.pos);886}887});888}889return new AST_LabeledStatement({ body: stat, label: label });890};891892function simple_statement(tmp) {893return new AST_SimpleStatement({ body: (tmp = expression(true), semicolon(), tmp) });894};895896function break_cont(type) {897var label = null, ldef;898if (!can_insert_semicolon()) {899label = as_symbol(AST_LabelRef, true);900}901if (label != null) {902ldef = find_if(function(l){ return l.name == label.name }, S.labels);903if (!ldef)904croak("Undefined label " + label.name);905label.thedef = ldef;906}907else if (S.in_loop == 0)908croak(type.TYPE + " not inside a loop or switch");909semicolon();910var stat = new type({ label: label });911if (ldef) ldef.references.push(stat);912return stat;913};914915function for_() {916expect("(");917var init = null;918if (!is("punc", ";")) {919init = is("keyword", "var")920? (next(), var_(true))921: expression(true, true);922if (is("operator", "in")) {923if (init instanceof AST_Var && init.definitions.length > 1)924croak("Only one variable declaration allowed in for..in loop");925next();926return for_in(init);927}928}929return regular_for(init);930};931932function regular_for(init) {933expect(";");934var test = is("punc", ";") ? null : expression(true);935expect(";");936var step = is("punc", ")") ? null : expression(true);937expect(")");938return new AST_For({939init : init,940condition : test,941step : step,942body : in_loop(statement)943});944};945946function for_in(init) {947var lhs = init instanceof AST_Var ? init.definitions[0].name : null;948var obj = expression(true);949expect(")");950return new AST_ForIn({951init : init,952name : lhs,953object : obj,954body : in_loop(statement)955});956};957958var function_ = function(ctor) {959var in_statement = ctor === AST_Defun;960var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null;961if (in_statement && !name)962unexpected();963expect("(");964return new ctor({965name: name,966argnames: (function(first, a){967while (!is("punc", ")")) {968if (first) first = false; else expect(",");969a.push(as_symbol(AST_SymbolFunarg));970}971next();972return a;973})(true, []),974body: (function(loop, labels){975++S.in_function;976S.in_directives = true;977S.in_loop = 0;978S.labels = [];979var a = block_();980--S.in_function;981S.in_loop = loop;982S.labels = labels;983return a;984})(S.in_loop, S.labels)985});986};987988function if_() {989var cond = parenthesised(), body = statement(), belse = null;990if (is("keyword", "else")) {991next();992belse = statement();993}994return new AST_If({995condition : cond,996body : body,997alternative : belse998});999};10001001function block_() {1002expect("{");1003var a = [];1004while (!is("punc", "}")) {1005if (is("eof")) unexpected();1006a.push(statement());1007}1008next();1009return a;1010};10111012function switch_body_() {1013expect("{");1014var a = [], cur = null, branch = null, tmp;1015while (!is("punc", "}")) {1016if (is("eof")) unexpected();1017if (is("keyword", "case")) {1018if (branch) branch.end = prev();1019cur = [];1020branch = new AST_Case({1021start : (tmp = S.token, next(), tmp),1022expression : expression(true),1023body : cur1024});1025a.push(branch);1026expect(":");1027}1028else if (is("keyword", "default")) {1029if (branch) branch.end = prev();1030cur = [];1031branch = new AST_Default({1032start : (tmp = S.token, next(), expect(":"), tmp),1033body : cur1034});1035a.push(branch);1036}1037else {1038if (!cur) unexpected();1039cur.push(statement());1040}1041}1042if (branch) branch.end = prev();1043next();1044return a;1045};10461047function try_() {1048var body = block_(), bcatch = null, bfinally = null;1049if (is("keyword", "catch")) {1050var start = S.token;1051next();1052expect("(");1053var name = as_symbol(AST_SymbolCatch);1054expect(")");1055bcatch = new AST_Catch({1056start : start,1057argname : name,1058body : block_(),1059end : prev()1060});1061}1062if (is("keyword", "finally")) {1063var start = S.token;1064next();1065bfinally = new AST_Finally({1066start : start,1067body : block_(),1068end : prev()1069});1070}1071if (!bcatch && !bfinally)1072croak("Missing catch/finally blocks");1073return new AST_Try({1074body : body,1075bcatch : bcatch,1076bfinally : bfinally1077});1078};10791080function vardefs(no_in, in_const) {1081var a = [];1082for (;;) {1083a.push(new AST_VarDef({1084start : S.token,1085name : as_symbol(in_const ? AST_SymbolConst : AST_SymbolVar),1086value : is("operator", "=") ? (next(), expression(false, no_in)) : null,1087end : prev()1088}));1089if (!is("punc", ","))1090break;1091next();1092}1093return a;1094};10951096var var_ = function(no_in) {1097return new AST_Var({1098start : prev(),1099definitions : vardefs(no_in, false),1100end : prev()1101});1102};11031104var const_ = function() {1105return new AST_Const({1106start : prev(),1107definitions : vardefs(false, true),1108end : prev()1109});1110};11111112var new_ = function() {1113var start = S.token;1114expect_token("operator", "new");1115var newexp = expr_atom(false), args;1116if (is("punc", "(")) {1117next();1118args = expr_list(")");1119} else {1120args = [];1121}1122return subscripts(new AST_New({1123start : start,1124expression : newexp,1125args : args,1126end : prev()1127}), true);1128};11291130function as_atom_node() {1131var tok = S.token, ret;1132switch (tok.type) {1133case "name":1134case "keyword":1135ret = _make_symbol(AST_SymbolRef);1136break;1137case "num":1138ret = new AST_Number({ start: tok, end: tok, value: tok.value });1139break;1140case "string":1141ret = new AST_String({1142start : tok,1143end : tok,1144value : tok.value,1145quote : tok.quote1146});1147break;1148case "regexp":1149ret = new AST_RegExp({ start: tok, end: tok, value: tok.value });1150break;1151case "atom":1152switch (tok.value) {1153case "false":1154ret = new AST_False({ start: tok, end: tok });1155break;1156case "true":1157ret = new AST_True({ start: tok, end: tok });1158break;1159case "null":1160ret = new AST_Null({ start: tok, end: tok });1161break;1162}1163break;1164}1165next();1166return ret;1167};11681169var expr_atom = function(allow_calls) {1170if (is("operator", "new")) {1171return new_();1172}1173var start = S.token;1174if (is("punc")) {1175switch (start.value) {1176case "(":1177next();1178var ex = expression(true);1179ex.start = start;1180ex.end = S.token;1181expect(")");1182return subscripts(ex, allow_calls);1183case "[":1184return subscripts(array_(), allow_calls);1185case "{":1186return subscripts(object_(), allow_calls);1187}1188unexpected();1189}1190if (is("keyword", "function")) {1191next();1192var func = function_(AST_Function);1193func.start = start;1194func.end = prev();1195return subscripts(func, allow_calls);1196}1197if (ATOMIC_START_TOKEN[S.token.type]) {1198return subscripts(as_atom_node(), allow_calls);1199}1200unexpected();1201};12021203function expr_list(closing, allow_trailing_comma, allow_empty) {1204var first = true, a = [];1205while (!is("punc", closing)) {1206if (first) first = false; else expect(",");1207if (allow_trailing_comma && is("punc", closing)) break;1208if (is("punc", ",") && allow_empty) {1209a.push(new AST_Hole({ start: S.token, end: S.token }));1210} else {1211a.push(expression(false));1212}1213}1214next();1215return a;1216};12171218var array_ = embed_tokens(function() {1219expect("[");1220return new AST_Array({1221elements: expr_list("]", !options.strict, true)1222});1223});12241225var object_ = embed_tokens(function() {1226expect("{");1227var first = true, a = [];1228while (!is("punc", "}")) {1229if (first) first = false; else expect(",");1230if (!options.strict && is("punc", "}"))1231// allow trailing comma1232break;1233var start = S.token;1234var type = start.type;1235var name = as_property_name();1236if (type == "name" && !is("punc", ":")) {1237if (name == "get") {1238a.push(new AST_ObjectGetter({1239start : start,1240key : as_atom_node(),1241value : function_(AST_Accessor),1242end : prev()1243}));1244continue;1245}1246if (name == "set") {1247a.push(new AST_ObjectSetter({1248start : start,1249key : as_atom_node(),1250value : function_(AST_Accessor),1251end : prev()1252}));1253continue;1254}1255}1256expect(":");1257a.push(new AST_ObjectKeyVal({1258start : start,1259quote : start.quote,1260key : name,1261value : expression(false),1262end : prev()1263}));1264}1265next();1266return new AST_Object({ properties: a });1267});12681269function as_property_name() {1270var tmp = S.token;1271next();1272switch (tmp.type) {1273case "num":1274case "string":1275case "name":1276case "operator":1277case "keyword":1278case "atom":1279return tmp.value;1280default:1281unexpected();1282}1283};12841285function as_name() {1286var tmp = S.token;1287next();1288switch (tmp.type) {1289case "name":1290case "operator":1291case "keyword":1292case "atom":1293return tmp.value;1294default:1295unexpected();1296}1297};12981299function _make_symbol(type) {1300var name = S.token.value;1301return new (name == "this" ? AST_This : type)({1302name : String(name),1303start : S.token,1304end : S.token1305});1306};13071308function as_symbol(type, noerror) {1309if (!is("name")) {1310if (!noerror) croak("Name expected");1311return null;1312}1313var sym = _make_symbol(type);1314next();1315return sym;1316};13171318var subscripts = function(expr, allow_calls) {1319var start = expr.start;1320if (is("punc", ".")) {1321next();1322return subscripts(new AST_Dot({1323start : start,1324expression : expr,1325property : as_name(),1326end : prev()1327}), allow_calls);1328}1329if (is("punc", "[")) {1330next();1331var prop = expression(true);1332expect("]");1333return subscripts(new AST_Sub({1334start : start,1335expression : expr,1336property : prop,1337end : prev()1338}), allow_calls);1339}1340if (allow_calls && is("punc", "(")) {1341next();1342return subscripts(new AST_Call({1343start : start,1344expression : expr,1345args : expr_list(")"),1346end : prev()1347}), true);1348}1349return expr;1350};13511352var maybe_unary = function(allow_calls) {1353var start = S.token;1354if (is("operator") && UNARY_PREFIX(start.value)) {1355next();1356handle_regexp();1357var ex = make_unary(AST_UnaryPrefix, start.value, maybe_unary(allow_calls));1358ex.start = start;1359ex.end = prev();1360return ex;1361}1362var val = expr_atom(allow_calls);1363while (is("operator") && UNARY_POSTFIX(S.token.value) && !S.token.nlb) {1364val = make_unary(AST_UnaryPostfix, S.token.value, val);1365val.start = start;1366val.end = S.token;1367next();1368}1369return val;1370};13711372function make_unary(ctor, op, expr) {1373if ((op == "++" || op == "--") && !is_assignable(expr))1374croak("Invalid use of " + op + " operator");1375return new ctor({ operator: op, expression: expr });1376};13771378var expr_op = function(left, min_prec, no_in) {1379var op = is("operator") ? S.token.value : null;1380if (op == "in" && no_in) op = null;1381var prec = op != null ? PRECEDENCE[op] : null;1382if (prec != null && prec > min_prec) {1383next();1384var right = expr_op(maybe_unary(true), prec, no_in);1385return expr_op(new AST_Binary({1386start : left.start,1387left : left,1388operator : op,1389right : right,1390end : right.end1391}), min_prec, no_in);1392}1393return left;1394};13951396function expr_ops(no_in) {1397return expr_op(maybe_unary(true), 0, no_in);1398};13991400var maybe_conditional = function(no_in) {1401var start = S.token;1402var expr = expr_ops(no_in);1403if (is("operator", "?")) {1404next();1405var yes = expression(false);1406expect(":");1407return new AST_Conditional({1408start : start,1409condition : expr,1410consequent : yes,1411alternative : expression(false, no_in),1412end : prev()1413});1414}1415return expr;1416};14171418function is_assignable(expr) {1419if (!options.strict) return true;1420if (expr instanceof AST_This) return false;1421return (expr instanceof AST_PropAccess || expr instanceof AST_Symbol);1422};14231424var maybe_assign = function(no_in) {1425var start = S.token;1426var left = maybe_conditional(no_in), val = S.token.value;1427if (is("operator") && ASSIGNMENT(val)) {1428if (is_assignable(left)) {1429next();1430return new AST_Assign({1431start : start,1432left : left,1433operator : val,1434right : maybe_assign(no_in),1435end : prev()1436});1437}1438croak("Invalid assignment");1439}1440return left;1441};14421443var expression = function(commas, no_in) {1444var start = S.token;1445var expr = maybe_assign(no_in);1446if (commas && is("punc", ",")) {1447next();1448return new AST_Seq({1449start : start,1450car : expr,1451cdr : expression(true, no_in),1452end : peek()1453});1454}1455return expr;1456};14571458function in_loop(cont) {1459++S.in_loop;1460var ret = cont();1461--S.in_loop;1462return ret;1463};14641465if (options.expression) {1466return expression(true);1467}14681469return (function(){1470var start = S.token;1471var body = [];1472while (!is("eof"))1473body.push(statement());1474var end = prev();1475var toplevel = options.toplevel;1476if (toplevel) {1477toplevel.body = toplevel.body.concat(body);1478toplevel.end = end;1479} else {1480toplevel = new AST_Toplevel({ start: start, body: body, end: end });1481}1482return toplevel;1483})();14841485};148614871488