smartdown
Version:
A library for translating, rendering and interacting with Smartdown documents. Smartdown is an extension of Markdown that provides richer media support and reactive programming capability.
1 lines • 618 kB
JavaScript
var __BRYTHON__=__BRYTHON__||{};try{eval("async function* f(){}")}catch(e){console.warn("Your browser is not fully supported. If you are using Microsoft Edge, please upgrade to the latest version")}!function(e){var t;e.isWebWorker="undefined"!=typeof WorkerGlobalScope&&"function"==typeof importScripts&&navigator instanceof WorkerNavigator,e.isNode="undefined"!=typeof process&&"node"===process.release.name;var r,n=(t=e.isNode?{location:{href:"",origin:"",pathname:""},navigator:{userLanguage:""}}:self).location.href;if(e.protocol=n.split(":")[0],e.BigInt=t.BigInt,e.indexedDB=t.indexedDB,void 0===e.brython_path){var o;if(e.isWebWorker)(o=t.location.href).startsWith("blob:")&&(o=o.substr(5));else{var a=document.getElementsByTagName("script");o=a[a.length-1].src}var s=o.split("/");s.pop(),r=e.brython_path=s.join("/")+"/"}else e.brython_path.endsWith("/")||(e.brython_path+="/"),r=e.brython_path;var i=(t.location.origin+t.location.pathname).split("/");i.pop();var _=e.script_dir=i.join("/");if(e.__ARGV=[],e.webworkers={},e.$py_module_path={},e.file_cache={},e.$py_src={},e.path=[r+"Lib",r+"libs",_,r+"Lib/site-packages"],e.async_enabled=!1,e.async_enabled&&(e.block={}),e.imported={},e.precompiled={},e.frames_stack=[],e.builtins={},e.builtins_scope={id:"__builtins__",module:"__builtins__",binding:{}},e.builtin_funcs={},e.builtin_classes=[],e.__getattr__=function(e){return this[e]},e.__setattr__=function(t,r){if(!(["debug","stdout","stderr"].indexOf(t)>-1))throw e.builtins.AttributeError.$factory("__BRYTHON__ object has no attribute "+t);e[t]=r},e.language=t.navigator.userLanguage||t.navigator.language,e.locale="C",e.isWebWorker?e.charset="utf-8":e.charset=document.characterSet||document.inputEncoding||"utf-8",e.max_int=Math.pow(2,53)-1,e.min_int=-e.max_int,e.max_float=new Number(Number.MAX_VALUE),e.min_float=new Number(Number.MIN_VALUE),e.max_string_length=536870888,console.log("$B.max_string_length",e.max_string_length),e.$py_next_hash=Math.pow(2,53)-1,e.$py_UUID=0,e.lambda_magic=Math.random().toString(36).substr(2,8),e.set_func_names=function(t,r){if(t.$infos){var n=t.$infos.__name__;t.$infos.__module__=r,t.$infos.__qualname__=n}else n=t.__name__,t.$infos={__name__:n,__module__:r,__qualname__:n};for(var o in t.__module__=r,t)"function"==typeof t[o]&&(t[o].$infos={__doc__:t[o].__doc__||"",__module__:r,__qualname__:n+"."+o,__name__:o},"classmethod"==t[o].$type&&(t[o].__class__=e.method))},"undefined"!=typeof Storage){e.has_local_storage=!1;try{localStorage&&(e.local_storage=localStorage,e.has_local_storage=!0)}catch(e){}e.has_session_storage=!1;try{sessionStorage&&(e.session_storage=sessionStorage,e.has_session_storage=!0)}catch(e){}}else e.has_local_storage=!1,e.has_session_storage=!1;e.globals=function(){return e.frames_stack[e.frames_stack.length-1][3]},e.scripts={},e.$options={},e.update_VFS=function(t){e.VFS=e.VFS||{};var r=t.$timestamp;for(var n in void 0!==r&&delete t.$timestamp,t)e.VFS.hasOwnProperty(n)&&console.warn("Virtual File System: duplicate entry "+n),e.VFS[n]=t[n],e.VFS[n].timestamp=r},e.add_files=function(t){for(var r in e.files=e.files||{},t)e.files[r]=t[r]},e.python_to_js=function(t,r){e.meta_path=e.$meta_path.slice(),e.use_VFS||e.meta_path.shift(),void 0===r&&(r="__main__");var n=__BRYTHON__.py2js(t,r,r).to_js();return"(function() {\n var $locals_"+r+" = {}\n"+n+"\n}())"},t.py=function(t){var r=e.py2js(t[0],"script","script").to_js();e.set_import_paths(),new Function("$locals_script",r)({})}}(__BRYTHON__),__BRYTHON__.implementation=[3,9,2,"final",0],__BRYTHON__.__MAGIC__="3.9.2",__BRYTHON__.version_info=[3,9,0,"final",0],__BRYTHON__.compiled_date="2021-04-22 21:39:42.669205",__BRYTHON__.timestamp=1619120382669,__BRYTHON__.builtin_module_names=["_aio","_ajax","_base64","_binascii","_cmath","_io_classes","_json","_jsre","_locale","_multiprocessing","_posixsubprocess","_profile","_sre1","_sre_utils","_string","_strptime","_svg","_webcomponent","_webworker","_zlib_utils","array","bry_re","builtins","dis","encoding_cp932","hashlib","html_parser","long_int","marshal","math","module1","modulefinder","posix","python_re","python_re1","python_re2","random","unicodedata"],function($B){var js,$pos,res,$op;Number.isInteger=Number.isInteger||function(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e},Number.isSafeInteger=Number.isSafeInteger||function(e){return Number.isInteger(e)&&Math.abs(e)<=Number.MAX_SAFE_INTEGER};var _b_=$B.builtins,_window;_window=$B.isNode?{location:{href:"",origin:"",pathname:""}}:self,$B.parser={};var clone=$B.clone=function(e){var t={};for(var r in e)t[r]=e[r];return t};$B.last=function(e){return void 0===e&&console.log($B.frames_stack.slice()),e[e.length-1]},$B.list2obj=function(e,t){var r={},n=e.length;for(void 0===t&&(t=!0);n-- >0;)r[e[n]]=t;return r},$B.op2method={operations:{"**":"pow","//":"floordiv","<<":"lshift",">>":"rshift","+":"add","-":"sub","*":"mul","/":"truediv","%":"mod","@":"matmul"},augmented_assigns:{"//=":"ifloordiv",">>=":"irshift","<<=":"ilshift","**=":"ipow","+=":"iadd","-=":"isub","*=":"imul","/=":"itruediv","%=":"imod","&=":"iand","|=":"ior","^=":"ixor","@=":"imatmul"},binary:{"&":"and","|":"or","~":"invert","^":"xor"},comparisons:{"<":"lt",">":"gt","<=":"le",">=":"ge","==":"eq","!=":"ne"},boolean:{or:"or",and:"and",in:"in",not:"not",is:"is",not_in:"not_in",is_not:"is_not"},subset:function(){var e={},t=[];if("all"==arguments[0])(t=Object.keys($B.op2method)).splice(t.indexOf("subset"),1);else for(var r=0,n=arguments.length;r<n;r++)t.push(arguments[r]);for(r=0,n=t.length;r<n;r++){var o=t[r],a=$B.op2method[o];if(void 0===a)throw Error(o);for(var s in a)e[s]=a[s]}return e}};var $operators=$B.op2method.subset("all"),$augmented_assigns=$B.augmented_assigns=$B.op2method.augmented_assigns,noassign=$B.list2obj(["True","False","None","__debug__"]),$op_order=[["or"],["and"],["not"],["in","not_in"],["<","<=",">",">=","!=","==","is","is_not"],["|"],["^"],["&"],[">>","<<"],["+"],["-"],["*","@","/","//","%"],["unary_neg","unary_inv","unary_pos"],["**"]],$op_weight={},$weight=1;$op_order.forEach((function(e){e.forEach((function(e){$op_weight[e]=$weight})),$weight++}));var $loop_num=0,create_temp_name=$B.parser.create_temp_name=function(e){return(e||"$temp")+$loop_num++},replace_node=$B.parser.replace_node=function(e,t){var r=e.parent,n=get_rank_in_parent(e);r.children[n]=t,t.parent=r,t.bindings=e.bindings},get_rank_in_parent=$B.parser.get_rank_in_parent=function(e){return e.parent.children.indexOf(e)},add_identnode=$B.parser.add_identnode=function(e,t,r,n){var o=new $Node;o.parent=e,o.locals=e.locals,o.module=e.module;var a=new $NodeCtx(o),s=new $ExprCtx(a,"id",!0),i=(new $IdCtx(s,r),new $AssignCtx(s));return-1===t?e.add(o):e.insert(t,o),i.tree[1]=n,o},chained_comp_num=0,$_SyntaxError=$B.parser.$_SyntaxError=function(e,t,r){for(var n=e;"node"!==n.type;)n=n.parent;for(var o=n.node,a=o;void 0!==a.parent;)a=a.parent;var s=o.module,i=a.src,_=o.line_num;if(i&&(_=i.substr(0,$pos).split("\n").length),a.line_info&&(_=a.line_info),void 0!==r&&"number"==typeof r)throw $B.$IndentationError(s,t,i,$pos,_,a);Array.isArray(t)&&$B.$SyntaxError(s,t[0],i,$pos,_,a),"Triple string end not found"===t&&$B.$SyntaxError(s,"invalid syntax : triple string end not found",i,$pos,_,a);var l="invalid syntax";t.startsWith("token ")||(l+=" ("+t+")"),$B.$SyntaxError(s,l,i,$pos,_,a)};function SyntaxWarning(e,t){var r=$get_node(e),n=$get_module(e),o=n.src.split("\n"),a=`Module ${n.module}line ${r.line_num}:${t}\n `+o[r.line_num-1];$B.$getattr($B.stderr,"write")(a)}function check_assignment(e){for(var t=e,r=["assert","del","import","raise","return"];t;)r.indexOf(t.type)>-1?$_SyntaxError(e,"invalid syntax - assign"):"expr"==t.type&&"op"==t.tree[0].type&&(void 0!==$B.op2method.comparisons[t.tree[0].op]?$_SyntaxError(e,["cannot assign to comparison"]):$_SyntaxError(e,["cannot assign to operator"])),t=t.parent}var $Node=$B.parser.$Node=function(e){this.type=e,this.children=[]};$Node.prototype.add=function(e){this.children[this.children.length]=e,e.parent=this,e.module=this.module},$Node.prototype.insert=function(e,t){this.children.splice(e,0,t),t.parent=this,t.module=this.module},$Node.prototype.toString=function(){return"<object 'Node'>"},$Node.prototype.show=function(e){var t="";return"module"===this.type?(this.children.forEach((function(r){t+=r.show(e)})),t):(t+=" ".repeat(e=e||0),t+=this.C,this.children.length>0&&(t+="{"),t+="\n",this.children.forEach((function(r){t+="["+i+"] "+r.show(e+4)})),this.children.length>0&&(t+=" ".repeat(e),t+="}\n"),t)},$Node.prototype.to_js=function(e){if(void 0!==this.js)return this.js;if(this.res=[],this.unbound=[],"module"===this.type)return this.children.forEach((function(e){this.res.push(e.to_js())}),this),this.js=this.res.join(""),this.js;e=e||0;var t=this.C.to_js();return t&&(this.res.push(" ".repeat(e)),this.res.push(t),this.children.length>0&&this.res.push("{"),this.res.push("\n"),this.children.forEach((function(t){this.res.push(t.to_js(e+4))}),this),this.children.length>0&&(this.res.push(" ".repeat(e)),this.res.push("}\n"))),this.js=this.res.join(""),this.js},$Node.prototype.transform=function(e){if(this.has_await)return this.parent.insert(e,$NodeJS("var save_stack = $B.save_stack()")),this.parent.insert(e+2,$NodeJS("$B.restore_stack(save_stack, $locals)")),this.has_await=!1,1;if(this.has_yield&&!this.has_yield.transformed){var t=this.parent;if(this.has_yield.from){var r=new $Node,n=new $NodeCtx(r),o=new $ExprCtx(n,"js",!1),a=new $RawJSCtx(o,`var _i${this.has_yield.from_num}`),s=new $AssignCtx(o);new $ExprCtx(s).tree=this.has_yield.tree,t.insert(e,r),$get_node(this.has_yield);var i=this.has_yield.from_num,_=`$B.$import("sys",[],{})\n_i${i}=_b_.iter(_i${i})\nvar $failed${i}=false\ntry{var _y${i}=_b_.next(_i${i})}catch(_e){$B.set_exc(_e)\n$failed${i}=true\n$B.pmframe=$B.last($B.frames_stack)\n_e=$B.exception(_e)\nif(_e.__class__===_b_.StopIteration){var _r${i}=$B.$getattr(_e,"value")}else{throw _e}}\nif(! $failed${i}){while(true){var $failed1${i}=false\ntry{$B.leave_frame({$locals})\nvar _s${i}=yield _y${i}\n$B.frames_stack.push($top_frame)}catch(_e){if(_e.__class__===_b_.GeneratorExit){var $failed2${i}=false\ntry{var _m${i}=$B.$geatttr(_i${i},"close")}catch(_e1){$failed2${i}=true\nif(_e1.__class__ !==_b_.AttributeError){throw _e1}}\nif(! $failed2${i}){$B.$call(_m${i})()}\nthrow _e}else if($B.is_exc(_e,[_b_.BaseException])){var _x=$B.$call($B.$getattr($locals.sys,"exc_info"))()\nvar $failed3${i}=false\ntry{var _m${i}=$B.$getattr(_i${i},"throw")}catch(err){$failed3${i}=true\nif($B.is_exc(err,[_b_.AttributeError])){throw err}}\nif(! $failed3${i}){try{_y${i}=$B.$call(_m${i}).apply(null,_b_.list.$factory(_x${i}))}catch(err){if($B.$is_exc(err,[_b_.StopIteration])){_r${i}=$B.$getattr(err,"value")\nbreak}\nthrow err}}}}\nif(! $failed1${i}){try{if(_s${i}===_b_.None){_y${i}=_b_.next(_i${i})}else{_y${i}=$B.$call($B.$getattr(_i${i},"send"))(_s${i})}}catch(err){if($B.is_exc(err,[_b_.StopIteration])){_r${i}=$B.$getattr(err,"value")\nbreak}\nthrow err}}}}`;return t.insert(e+1,$NodeJS(_)),3}t.children.splice(e,1),"abstract_expr"===this.has_yield.tree[0].type?r=$NodeJS("var result = _b_.None"):(r=new $Node,n=new $NodeCtx(r),o=new $ExprCtx(n,"js",!1),a=new $RawJSCtx(o,"var result"),(s=new $AssignCtx(o)).tree[1]=this.has_yield.tree[0],a.parent=s),r.line_num=this.line_num,t.insert(e,r);var l=new $NodeJS("try");l.add($NodeJS("$B.leave_frame({$locals})")),l.add(this),t.insert(e+1,l),this.has_yield.to_js=function(){return"yield result"},this.has_yield.transformed=!0;for(var c=0;c<l.children.length;)void 0===($=l.children[c].transform(c))&&($=1),c+=$;var u=$NodeJS(`catch(err${this.line_num})`);return u.add($NodeJS("$B.frames_stack.push($top_frame)")),u.add($NodeJS(`throw err${this.line_num}`)),t.insert(e+2,u),t.insert(e+3,$NodeJS("$B.frames_stack.push($top_frame)")),2}if("module"!==this.type){var f,p=this.C.tree[0];for(void 0===p&&console.log(this),void 0!==p.transform&&(f=p.transform(this,e)),c=0;c<this.children.length;)void 0===($=this.children[c].transform(c))&&($=1),c+=$;return void 0===f&&(f=1),f}this.__doc__=$get_docstring(this);for(c=0;c<this.children.length;){var $;void 0===($=this.children[c].transform(c))&&($=1),c+=$}},$Node.prototype.clone=function(){var e=new $Node(this.type);for(var t in this)e[t]=this[t];return e},$Node.prototype.clone_tree=function(){var e=new $Node(this.type);for(var t in this)e[t]=this[t];e.children=[];for(var r=0,n=this.children.length;r<n;r++)e.add(this.children[r].clone_tree());return e};var $AbstractExprCtx=$B.parser.$AbstractExprCtx=function(e,t){this.type="abstract_expr",this.with_commas=t,this.parent=e,this.tree=[],e.tree[e.tree.length]=this};$AbstractExprCtx.prototype.toString=function(){return"(abstract_expr "+this.with_commas+") "+this.tree},$AbstractExprCtx.prototype.transition=function(e,t){var r=this,n=r.packed,o=r.is_await,a=r.assign;if(!a)switch(e){case"id":case"imaginary":case"int":case"float":case"str":case"bytes":case"[":case"(":case"{":case".":case"not":case"lambda":case"yield":r.parent.tree.pop();var s=r.with_commas;(r=r.parent).packed=n,r.is_await=o,a&&(console.log("set assign to parent",r),r.assign=a)}switch(e){case"await":return new $AwaitCtx(r);case"id":return new $IdCtx(new $ExprCtx(r,"id",s),t);case"str":return new $StringCtx(new $ExprCtx(r,"str",s),t);case"bytes":return new $StringCtx(new $ExprCtx(r,"bytes",s),t);case"int":return new $NumberCtx("int",new $ExprCtx(r,"int",s),t);case"float":return new $NumberCtx("float",new $ExprCtx(r,"float",s),t);case"imaginary":return new $NumberCtx("imaginary",new $ExprCtx(r,"imaginary",s),t);case"(":return new $ListOrTupleCtx(new $ExprCtx(r,"tuple",s),"tuple");case"[":return new $ListOrTupleCtx(new $ExprCtx(r,"list",s),"list");case"{":return new $DictOrSetCtx(new $ExprCtx(r,"dict_or_set",s));case".":return new $EllipsisCtx(new $ExprCtx(r,"ellipsis",s));case"not":return"op"==r.type&&"is"==r.op?(r.op="is_not",r):new $NotCtx(new $ExprCtx(r,"not",s));case"lambda":return new $LambdaCtx(new $ExprCtx(r,"lambda",s));case"op":var i=t;switch(i){case"*":return r.parent.tree.pop(),s=r.with_commas,r=r.parent,new $PackedCtx(new $ExprCtx(r,"expr",s));case"-":case"~":case"+":r.parent.tree.pop();var _=new $UnaryCtx(r.parent,i);if("-"==i)var l=new $OpCtx(_,"unary_neg");else l=new $OpCtx(_,"+"==i?"unary_pos":"unary_inv");return new $AbstractExprCtx(l,!1);case"not":return r.parent.tree.pop(),s=r.with_commas,r=r.parent,new $NotCtx(new $ExprCtx(r,"not",s))}$_SyntaxError(r,"token "+e+" after "+r);case"in":$_SyntaxError(r,"token "+e+" after "+r);case"yield":return new $AbstractExprCtx(new $YieldCtx(r),!0);case":":return"sub"==r.parent.type||"list_or_tuple"==r.parent.type&&"sub"==r.parent.parent.type?new $AbstractExprCtx(new $SliceCtx(r.parent),!1):$transition(r.parent,e,t);case")":case",":switch(r.parent.type){case"list_or_tuple":case"slice":case"call_arg":case"op":case"yield":break;case"annotation":$_SyntaxError(r,"empty annotation");default:$_SyntaxError(r,e)}}return $transition(r.parent,e,t)},$AbstractExprCtx.prototype.to_js=function(){return this.js_processed=!0,"list"===this.type?"["+$to_js(this.tree)+"]":$to_js(this.tree)};var $AliasCtx=$B.parser.$AliasCtx=function(e){this.type="ctx_manager_alias",this.parent=e,this.tree=[],e.tree[e.tree.length-1].alias=this};$AliasCtx.prototype.transition=function(e,t){var r=this;switch(e){case",":case":":return r.parent.set_alias(r.tree[0].tree[0]),$transition(r.parent,e,t)}$_SyntaxError(r,"token "+e+" after "+r)};var $AnnotationCtx=$B.parser.$AnnotationCtx=function(e){this.type="annotation",this.parent=e,this.tree=[],e.annotation=this;var t=$get_scope(e);if(void 0===t.binding.__annotations__&&(t.binding.__annotations__=!0,e.create_annotations=!0),"def"==t.ntype&&e.tree&&e.tree.length>0&&"id"==e.tree[0].type){var r=e.tree[0].value;t.globals&&t.globals.has(r)>-1&&$_SyntaxError(e,["annotated name '"+r+"' can't be global"]),t.annotations=t.annotations||new Set,t.annotations.add(r),e.$in_parens||(t.binding=t.binding||{},t.binding[r]=!0)}};$AnnotationCtx.prototype.toString=function(){return"(annotation) "+this.tree},$AnnotationCtx.prototype.transition=function(e,t){var r=this;return"eol"==e&&1==r.tree.length&&0==r.tree[0].tree.length?$_SyntaxError(r,"empty annotation"):":"==e&&"def"!=r.parent.type?$_SyntaxError(r,"more than one annotation"):"augm_assign"==e?$_SyntaxError(r,"augmented assign as annotation"):"op"==e&&$_SyntaxError(r,"operator as annotation"),$transition(r.parent,e)},$AnnotationCtx.prototype.to_js=function(){return $to_js(this.tree)};var $AssertCtx=$B.parser.$AssertCtx=function(e){this.type="assert",this.parent=e,this.tree=[],e.tree[e.tree.length]=this};function make_assign(e,t,r){var n=new $Node;n.id=r;var o=new $NodeCtx(n),a=new $ExprCtx(o,"left",!0);return a.tree=e.tree,new $AssignCtx(a).tree[1]=new $JSCode(t),n}$AssertCtx.prototype.toString=function(){return"(assert) "+this.tree},$AssertCtx.prototype.transition=function(e,t){var r=this;return","==e?(this.tree.length>1&&$_SyntaxError(r,"too many commas after assert"),new $AbstractExprCtx(this,!1)):"eol"==e?$transition(r.parent,e):void $_SyntaxError(r,e)},$AssertCtx.prototype.transform=function(e,t){if(this.tree.length>1)var r=this.tree[0],n=this.tree[1];else r=this.tree[0],n=null;if("expr"==this.tree[0].type&&"tuple"==this.tree[0].name&&this.tree[0].tree[0].tree.length>1){var o=_b_.SyntaxWarning.$factory("assertion is always true, perhaps remove parentheses?"),a=$get_module(this);$B.$syntax_err_line(o,a.filename,a.src,$pos,$get_node(this).line_num),$B.imported._warnings.warn(o)}var s=new $ConditionCtx(e.C,"if");new $NotCtx(s).tree=[r],e.C=s;var i=new $Node,_="throw _b_.AssertionError.$factory()";null!==n&&(_="throw _b_.AssertionError.$factory(_b_.str.$factory("+n.to_js()+"))"),new $NodeJSCtx(i,_),e.add(i)};var $AssignCtx=$B.parser.$AssignCtx=function(e,t){check_assignment(e),"expr"==e.type&&"lambda"==e.tree[0].type&&$_SyntaxError(e,["cannot assign to lambda"]),this.type="assign","expression"==t&&(this.expression=!0,console.log("parent of assign expr",e.parent)),e.parent.tree.pop(),e.parent.tree[e.parent.tree.length]=this,this.parent=e.parent,this.tree=[e];var r=$get_scope(this);if("expr"==e.type&&"call"==e.tree[0].type)$_SyntaxError(e,["cannot assign to function call "]);else if("list_or_tuple"==e.type||"expr"==e.type&&"list_or_tuple"==e.tree[0].type)"expr"==e.type&&(e=e.tree[0]),e.bind_ids(r);else if("assign"==e.type)e.tree.forEach((function(e){var t=e.tree[0];"id"==t.type&&$bind(t.value,r,this)}),this);else{var n=e.tree[0];if(n&&"id"==n.type)if(!0===noassign[n.value]&&$_SyntaxError(e,["cannot assign to keyword"]),n.bound=!0,r.globals&&r.globals.has(n.value)){var o=$get_module(e);n.global_module=o.module,$bind(n.value,o,this)}else $get_node(this).bound_before=Object.keys(r.binding),$bind(n.value,r,this);else["str","int","float","complex"].indexOf(n.type)>-1?$_SyntaxError(e,["cannot assign to literal"]):"unary"==n.type&&$_SyntaxError(e,["cannot assign to operator"])}};$AssignCtx.prototype.guess_type=function(){},$AssignCtx.prototype.toString=function(){return"(assign) "+this.tree[0]+"="+this.tree[1]},$AssignCtx.prototype.transition=function(e,t){var r=this;if("eol"==e)return"abstract_expr"==r.tree[1].type&&$_SyntaxError(r,"token "+e+" after "+r),r.guess_type(),$transition(r.parent,"eol");$_SyntaxError(r,"token "+e+" after "+r)},$AssignCtx.prototype.transform=function(e,t){for(var r=$get_scope(this),n=this.tree[0],o=this.tree[1],a=[];"assign"==n.type;)a.push(n.tree[1]),n=n.tree[0];if(a.length>0){a.push(n);var s=e.C;s.tree=[];var i=new $RawJSCtx(s,"var $temp"+$loop_num);return i.tree=s.tree,new $AssignCtx(i).tree[1]=o,a.forEach((function(r){"expr"==r.type&&"list_or_tuple"==r.tree[0].type&&"tuple"==r.tree[0].real&&1==r.tree[0].tree.length&&(r=r.tree[0].tree[0]);var n=new $Node,o=new $NodeCtx(n);n.locals=e.locals,n.line_num=e.line_num,e.parent.insert(t+1,n),r.parent=o;var a=new $AssignCtx(r);new $RawJSCtx(a,"$temp"+$loop_num)})),$loop_num++,void(this.tree[0]=n)}var _=null;switch(n.type){case"expr":if(n.tree.length>1)_=n.tree;else if("list_or_tuple"==n.tree[0].type||"target_list"==n.tree[0].type)_=n.tree[0].tree;else if("id"==n.tree[0].type){var l=n.tree[0].value;r.globals&&r.globals.has(l)||(n.tree[0].bound=!0)}break;case"target_list":case"list_or_tuple":_=n.tree}if(o=this.tree[1],null!==_){var c=null;if(("list"==o.type||"tuple"==o.type||"expr"==o.type&&o.tree.length>1)&&(c=o.tree),null!==c){if(c.length>_.length)throw Error("ValueError : too many values to unpack (expected "+_.length+")");if(c.length<_.length)throw Error("ValueError : need more than "+c.length+" to unpack");var u=[],f=0;(h=new $Node).line_num=e.line_num,new $NodeJSCtx(h,"void(0)"),u[f++]=h;var p="$temp"+$loop_num;(h=new $Node).line_num=e.line_num,new $NodeJSCtx(h,"var "+p+" = [], $pos = 0"),u[f++]=h,c.forEach((function(t){var r=p+"[$pos++] = "+t.to_js(),n=new $Node;n.line_num=e.line_num,new $NodeJSCtx(n,r),u[f++]=n}));var $=$get_node(this);_.forEach((function(t){var r=new $Node;r.id=$.module,r.locals=$.locals,r.line_num=e.line_num;var n=new $NodeCtx(r);t.parent=n,new $AssignCtx(t,!1).tree[1]=new $JSCode(p+"["+d+"]"),u[f++]=r}),this),e.parent.children.splice(t,1);for(var d=u.length-1;d>=0;d--)e.parent.insert(t,u[d]);$loop_num++}else{e.parent.children.splice(t,1);var h,m=create_temp_name("$right"),b=create_temp_name("$rlist");(h=$NodeJS("var "+m+" = $B.$getattr($B.$iter("+o.to_js()+'), "__next__");')).line_num=e.line_num,e.parent.insert(t++,h),e.parent.insert(t++,$NodeJS("var "+b+"=[], $pos=0;while(1){try{"+b+"[$pos++] = "+m+"()}catch(err){break}}"));var g=null,y=_.length;for(d=0;d<_.length;d++){var v=_[d];if("packed"==v.type||"expr"==v.type&&"packed"==v.tree[0].type){g=d,y--;break}}e.parent.insert(t++,$NodeJS("if("+b+".length<"+y+'){throw _b_.ValueError.$factory("need more than " +'+b+'.length + " value" + ('+b+'.length > 1 ? "s" : "") + " to unpack")}')),null==g&&e.parent.insert(t++,$NodeJS("if("+b+".length>"+y+'){throw _b_.ValueError.$factory("too many values to unpack (expected '+_.length+')")}')),_.forEach((function(n,o){var a=new $Node;a.id=r.id,a.line_num=e.line_num,e.parent.insert(t++,a);var s=new $NodeCtx(a);n.parent=s;var i=new $AssignCtx(n,!1),l=b;l+=null==g||o<g?"["+o+"]":o==g?".slice("+o+","+b+".length-"+(_.length-o-1)+")":"["+b+".length-"+(_.length-o)+"]",i.tree[1]=new $JSCode(l)})),$loop_num++}}else n.tree[0].bound&&"expr"==o.type&&"int"==o.name&&(e.bindings=e.bindings||{},e.bindings[n.tree[0].value]="int")},$AssignCtx.prototype.to_js=function(){if(this.js_processed=!0,"call"==this.parent.type)return'{$nat:"kw",name:'+this.tree[0].to_js()+",value:"+this.tree[1].to_js()+"}";for(var e=this.tree[0];"expr"==e.type&&!e.assign;)e=e.tree[0];var t=this.tree[1];if("attribute"==e.type||"sub"==e.type){var r=t.to_js(),n="",o="",a="$temp"+$loop_num;if("expr"!=t.type||void 0===t.tree[0]||"call"!=t.tree[0].type||"eval"!=t.tree[0].func.value&&"exec"!=t.tree[0].func.value?"expr"==t.type&&void 0!==t.tree[0]&&"sub"==t.tree[0].type?(n+="var "+a+" = "+r+";\n",o=a):o=r:(n+="var "+a+" = "+r+";\n",o=a),"attribute"==e.type){$loop_num++,e.func="setattr";var s=e.to_js();return e.func="getattr",e.assign_self?n+s[0]+o+s[1]+o+")":(n=(n+=s).substr(0,n.length-1))+","+o+");_b_.None;"}if("sub"==e.type){var i,_=e.value.to_js(),l="$temp"+$loop_num;return"id"==e.value.type&&(i=$get_node(this).locals[e.value.value]),$loop_num++,n="var "+l+" = "+_+"\n","list"!==i&&(n+="if(Array.isArray("+l+") && !"+l+".__class__){"),1==e.tree.length?n+="$B.set_list_key("+l+","+(e.tree[0].to_js()+""||"null")+","+t.to_js()+")":2==e.tree.length?n+="$B.set_list_slice("+l+","+(e.tree[0].to_js()+""||"null")+","+(e.tree[1].to_js()+""||"null")+","+t.to_js()+")":3==e.tree.length&&(n+="$B.set_list_slice_step("+l+","+(e.tree[0].to_js()+""||"null")+","+(e.tree[1].to_js()+""||"null")+","+(e.tree[2].to_js()+""||"null")+","+t.to_js()+")"),"list"==i||(n+="\n}else{",1==e.tree.length?n+="$B.$setitem("+e.value.to_js()+","+e.tree[0].to_js()+","+r+")};_b_.None;":(e.func="setitem",n=(n+=e.to_js()).substr(0,n.length-1),e.func="getitem",n+=","+r+")};_b_.None;")),n}}return e.to_js()+" = "+t.to_js()};var $AsyncCtx=$B.parser.$AsyncCtx=function(e){this.type="async",this.parent=e,e.async=!0};$AsyncCtx.prototype.toString=function(){return"(async)"},$AsyncCtx.prototype.transition=function(e,t){var r=this;if("def"==e)return $transition(r.parent,e,t);if("for"==e||"with"==e){var n=$get_scope(r).ntype;"def"!==n&&"generator"!=n&&$_SyntaxError(r,["'async "+e+"' outside async function"]);var o=$transition(r.parent,e,t);return o.parent.async=!0,o}$_SyntaxError(r,"token "+e+" after "+r)};var $AttrCtx=$B.parser.$AttrCtx=function(e){this.type="attribute",this.value=e.tree[0],this.parent=e,e.tree.pop(),e.tree[e.tree.length]=this,this.tree=[],this.func="getattr"};$AttrCtx.prototype.toString=function(){return"(attr) "+this.value+"."+this.name},$AttrCtx.prototype.transition=function(e,t){var r=this;if("id"===e){var n=t;return!0===noassign[n]&&$_SyntaxError(r,["cannot assign to "+n]),n=$mangle(n,r),r.name=n,r.parent}$_SyntaxError(r,e)},$AttrCtx.prototype.to_js=function(){this.js_processed=!0;var e=this.value.to_js();if("setattr"==this.func&&"id"==this.value.type){var t=$get_scope(this),r=t.parent;if("def"==t.ntype&&"class"==r.ntype){var n=t.C.tree[0].positional_list;if(this.value.value==n[0]&&r.C&&void 0===r.C.tree[0].args)return this.assign_self=!0,[e+".__class__ && "+e+".__dict__ && !"+e+".__class__.$has_setattr && ! "+e+".$is_class ? _b_.dict.$setitem("+e+".__dict__, '"+$B.from_alias(this.name)+"', ",") : $B.$setattr("+e+', "'+this.name+'", ']}}return"setattr"==this.func?"$B.$setattr("+e+',"'+this.name+'")':"$B.$getattr("+e+',"'+this.name+'")'};var $AugmentedAssignCtx=$B.parser.$AugmentedAssignCtx=function(e,t){check_assignment(e),this.type="augm_assign",this.C=e,this.parent=e.parent,e.parent.tree.pop(),e.parent.tree[e.parent.tree.length]=this,this.op=t,this.tree=[e];var r=this.scope=$get_scope(this);if("expr"==e.type){var n=e.tree[0];if("id"==n.type){var o=n.value;!0===noassign[o]?$_SyntaxError(e,["cannot assign to keyword"]):"def"!=r.ntype&&"generator"!=r.ntype||void 0!==r.binding[o]||void 0!==r.globals&&r.globals.has(o)||(n.unbound=!0)}else["str","int","float","complex"].indexOf(n.type)>-1&&$_SyntaxError(e,["cannot assign to literal"])}$get_node(this).bound_before=Object.keys(r.binding),this.module=r.module};$AugmentedAssignCtx.prototype.toString=function(){return"(augm assign) "+this.tree},$AugmentedAssignCtx.prototype.transition=function(e,t){var r=this;if("eol"==e)return"abstract_expr"==r.tree[1].type&&$_SyntaxError(r,"token "+e+" after "+r),$transition(r.parent,"eol");$_SyntaxError(r,"token "+e+" after "+r)},$AugmentedAssignCtx.prototype.transform=function(e,t){var r=this.C,n=this.op,o="__"+$operators[n]+"__",a=0,s=e.parent,i=e.line_num,_=!1;s.children.splice(t,1);var l="expr"==this.tree[0].type&&"id"==this.tree[0].tree[0].type;if(l){var c="int"==this.tree[0].tree[0].bindingType(this.scope);if(this.tree[0].tree[0].augm_assign=!0,$B.debug>0){var u=$NodeJS("if("+this.tree[0].to_js()+" === undefined){throw _b_.NameError.$factory(\"name '"+this.tree[0].tree[0].value+"' is not defined\")}");e.parent.insert(t,u),a++}var f=this.tree[0].tree[0].value,p=void 0!==this.scope.binding[f],$=this.tree[0].tree[0].unbound}var d="expr"==this.tree[1].type&&"int"==this.tree[1].tree[0].type;if(d){var h=this.tree[1].tree[0].value,m=parseInt(h[1],h[0]);d=m>$B.min_int&&m<$B.max_int}var b=d?this.tree[1].tree[0].to_js():"$temp";if(!d){(j=new $Node).line_num=i,_=!0,new $NodeJSCtx(j,"var $temp,$left;"),s.insert(t,j),a++,(j=new $Node).id=this.scope.id;var g=new $NodeCtx(j),y=new $ExprCtx(g,"js",!1),v=new $RawJSCtx(y,"$temp"),x=new $AssignCtx(y);x.tree[1]=this.tree[1],v.parent=x,s.insert(t+a,j),a++}var B="",w=!1;switch(n){case"+=":case"-=":case"*=":case"/=":if(l){var k=this.scope,E="$local_"+k.module.replace(/\./g,"_");switch(k.ntype){case"module":B=E;break;case"def":case"generator":B=k.globals&&k.globals.has(r.tree[0].value)?E:"$locals";break;case"class":var j=new $Node;_||(j.line_num=i,_=!0),new $NodeJSCtx(j,"var $left = "+r.to_js()),s.insert(t+a,j),w=!0,a++}}}var N=r.tree[0].to_js();if("id"==r.tree[0].type){var C=r.tree[0].firstBindingScopeId(),S=r.tree[0].value;N=C?"$locals_"+C.replace(/\./g,"_")+'["'+S+'"]':'$locals["'+S+'"]'}if(c&&d&&"//="!=n)return s.insert(t+a,$NodeJS(N+" "+n+" "+b)),a++;B=B&&!r.tree[0].unknown_binding&&!$;var A=n.charAt(0);if(B){var O=w?"$left":N;j=new $Node,_||(j.line_num=i,_=!0),T=d?"if(":'if(typeof $temp.valueOf() == "number" && ',T+=O+".constructor === Number",T+=" && Number.isSafeInteger("+N+A+b+")){"+(d?"(":'(typeof $temp == "number" && ')+"typeof "+O+' == "number") ? ',T+=N+n+b,new $NodeJSCtx(j,T+=" : "+N+" = new Number("+N+A+(d?b:b+".valueOf()")+")}"),s.insert(t+a,j),a++}if("sub"==r.tree[0].type&&("+="==n||"-="==n||"*="==n)&&1==r.tree[0].tree.length){var I="$B.augm_item_"+{"+=":"add","-=":"sub","*=":"mul"}[n]+"("+r.tree[0].value.to_js()+","+r.tree[0].tree[0].to_js()+","+b+");_b_.None;";return j=new $Node,_||(j.line_num=i,_=!0),new $NodeJSCtx(j,I),s.insert(t+a,j),void a++}j=new $Node,_||(j.line_num=i,_=!0);var T="";B&&(T+="else "),T+="if(! _b_.hasattr("+r.to_js()+',"'+o+'"))',new $NodeJSCtx(j,T),s.insert(t+a,j),a++;var F=new $Node;F.id=this.scope.id,F.line_num=e.line_num,j.add(F);var M=new $NodeCtx(F),J=new $ExprCtx(M,"clone",!1);$?new $RawJSCtx(J,N):(J.tree=r.tree,J.tree.forEach((function(e){e.parent=J})));var R=new $AssignCtx(J),L=new $OpCtx(J,n.substr(0,n.length-1));L.parent=R,new $RawJSCtx(L,b),R.tree.push(L),J.parent.tree.pop(),J.parent.tree.push(R);var P=$NodeJS("else");s.insert(t+a,P);var q=new $Node;q.line_num=e.line_num,P.add(q);var D=new $NodeCtx(q),z=new $ExprCtx(D,"clone",!1);$?(T=N,C||(T='$B.$local_search("'+S+'");'+N),new $RawJSCtx(z,T)):(z.tree=r.tree,z.tree.forEach((function(e){e.parent=z})));var V=new $AssignCtx(z);return V.tree.push($NodeJS("$B.$getattr("+r.to_js()+',"'+o+'")('+b+")")),z.parent.tree.pop(),z.parent.tree.push(V),!l||p||this.scope.blurred||(this.scope.binding[f]=void 0),a},$AugmentedAssignCtx.prototype.to_js=function(){return""};var $AwaitCtx=$B.parser.$AwaitCtx=function(e){this.type="await",this.parent=e,this.tree=[],e.tree.push(this);for(var t=e;t;)"list_or_tuple"==t.type&&(t.is_await=!0),t=t.parent};$AwaitCtx.prototype.transition=function(e,t){return this.parent.is_await=!0,$transition(this.parent,e,t)},$AwaitCtx.prototype.to_js=function(){return"var save_stack = $B.save_stack();await ($B.promise("+$to_js(this.tree)+"));$B.restore_stack(save_stack, $locals); "};var $BodyCtx=$B.parser.$BodyCtx=function(e){for(var t=e.parent;"node"!==t.type;)t=t.parent;var r=t.node,n=new $Node;return n.is_body_node=!0,n.line_num=r.line_num,r.insert(0,n),new $NodeCtx(n)},set_loop_context=$B.parser.set_loop_context=function(e,t){for(var r=e;"node"!==r.type;)r=r.parent;for(var n=r.node.parent,o=!1;;)if("module"==n.type)$_SyntaxError(e,t+" outside of a loop");else{var a=n.C.tree[0];if("condition"==a.type&&"while"==a.token){this.loop_ctx=a,a["has_"+t]=!0;break}switch(a.type){case"for":this.loop_ctx=a,a["has_"+t]=!0,o=!0;break;case"def":case"generator":case"class":$_SyntaxError(e,t+" outside of a loop");default:n=n.parent}if(o)break}},$BreakCtx=$B.parser.$BreakCtx=function(e){this.type="break",this.parent=e,e.tree[e.tree.length]=this,set_loop_context.apply(this,[e,"break"])};$BreakCtx.prototype.toString=function(){return"break "},$BreakCtx.prototype.transition=function(e,t){if("eol"==e)return $transition(this.parent,"eol");$_SyntaxError(this,e)},$BreakCtx.prototype.to_js=function(){this.js_processed=!0;var e=";$locals_"+$get_scope(this).id.replace(/\./g,"_")+'["$no_break'+this.loop_ctx.loop_num+'"] = false';return"asyncfor"!=this.loop_ctx.type?e+=";break":e+=";throw _b_.StopIteration.$factory("+this.loop_ctx.loop_num+")",e};var $CallArgCtx=$B.parser.$CallArgCtx=function(e){this.type="call_arg",this.parent=e,this.start=$pos,this.tree=[],e.tree.push(this),this.expect="id"};$CallArgCtx.prototype.toString=function(){return"call_arg "+this.tree},$CallArgCtx.prototype.transition=function(e,t){var r=this;switch(e){case"await":case"id":case"imaginary":case"int":case"float":case"str":case"bytes":case"[":case"(":case"{":case".":case"not":case"lambda":if("id"==r.expect){r.expect=",";var n=new $AbstractExprCtx(r,!1);return $transition(n,e,t)}break;case"=":if(","==r.expect)return new $ExprCtx(new $KwArgCtx(r),"kw_value",!1);break;case"for":this.parent.tree.length>1&&$_SyntaxError(r,"non-parenthesized generator expression");var o=new $ListOrTupleCtx(r,"gen_expr");o.vars=r.vars,o.locals=r.locals,o.intervals=[r.start],r.tree.pop(),o.expression=r.tree,r.tree=[o],o.tree=[];var a=new $ComprehensionCtx(o);return new $TargetListCtx(new $CompForCtx(a));case"op":if("id"==r.expect){var s=t;switch(r.expect=",",s){case"+":case"-":case"~":return $transition(new $AbstractExprCtx(r,!1),e,s);case"*":return new $StarArgCtx(r);case"**":return new $DoubleStarArgCtx(r)}}$_SyntaxError(r,"token "+e+" after "+r);case")":if(r.parent.kwargs&&$B.last(r.parent.tree).tree[0]&&-1==["kwarg","star_arg","double_star_arg"].indexOf($B.last(r.parent.tree).tree[0].type)&&$_SyntaxError(r,["non-keyword argument after keyword argument"]),r.tree.length>0){var i=r.tree[r.tree.length-1];"list_or_tuple"==i.type&&"gen_expr"==i.real&&i.intervals.push($pos)}return $transition(r.parent,e);case":":if(","==r.expect&&"lambda"==r.parent.parent.type)return $transition(r.parent.parent,e);break;case",":if(","==r.expect)return r.parent.kwargs&&-1==["kwarg","star_arg","double_star_arg"].indexOf($B.last(r.parent.tree).tree[0].type)&&$_SyntaxError(r,["non-keyword argument after keyword argument"]),$transition(r.parent,e,t)}$_SyntaxError(r,"token "+e+" after "+r)},$CallArgCtx.prototype.to_js=function(){return this.js_processed=!0,$to_js(this.tree)};var $CallCtx=$B.parser.$CallCtx=function(e){this.type="call",this.func=e.tree[0],void 0!==this.func&&(this.func.parent=this),this.parent=e,"class"!=e.type?(e.tree.pop(),e.tree[e.tree.length]=this):e.args=this,this.expect="id",this.tree=[],this.start=$pos,this.func&&"attribute"==this.func.type&&"wait"==this.func.name&&"id"==this.func.value.type&&"time"==this.func.value.value&&(console.log("call",this.func),$get_node(this).blocking={type:"wait",call:this}),this.func&&"input"==this.func.value&&($get_node(this).blocking={type:"input"})};$CallCtx.prototype.toString=function(){return"(call) "+this.func+"("+this.tree+")"},$CallCtx.prototype.transition=function(e,t){var r=this;switch(e){case",":return"id"==r.expect&&$_SyntaxError(r,e),r.expect="id",r;case"await":case"id":case"imaginary":case"int":case"float":case"str":case"bytes":case"[":case"(":case"{":case".":case"not":case"lambda":return r.expect=",",$transition(new $CallArgCtx(r),e,t);case")":return r.end=$pos,r.parent;case"op":switch(r.expect=",",t){case"-":case"~":case"+":return r.expect=",",$transition(new $CallArgCtx(r),e,t);case"*":return r.has_star=!0,new $StarArgCtx(r);case"**":return r.has_dstar=!0,new $DoubleStarArgCtx(r)}$_SyntaxError(r,e);case"yield":$_SyntaxError(r,e)}return $transition(r.parent,e,t)},$CallCtx.prototype.to_js=function(){this.js_processed=!0,this.tree.length>0&&0==this.tree[this.tree.length-1].tree.length&&this.tree.pop();var e=this.func.to_js();if(void 0!==this.func){if("classmethod"===this.func.value)return"_b_.classmethod.$factory("+$to_js(this.tree)+")";if("unary"==this.func.type){var t="$B.$getattr("+$to_js(this.tree);switch(this.func.op){case"+":return t+',"__pos__")()';case"-":return t+',"__neg__")()';case"~":return t+',"__invert__")()'}}var r,n=[],o=[],a=!1,s=[];if(this.tree.forEach((function(e){switch(e.type){case"star_arg":a=!0,n.push([e.tree[0].tree[0].to_js(),"*"]);break;case"double_star_arg":s.push(e.tree[0].tree[0].to_js());break;case"id":n.push([e.to_js(),"s"]);break;default:switch(e.tree[0].type){case"expr":case"list_or_tuple":case"op":default:n.push([e.to_js(),"s"]);break;case"kwarg":o.push(e.tree[0].tree[0].value+":"+e.tree[0].tree[1].to_js());break;case"star_arg":a=!0,n.push([e.tree[0].tree[0].to_js(),"*"]);break;case"double_star_arg":s.push(e.tree[0].tree[0].to_js())}}})),a){for(var i=[],_=0,l=n.length;_<l;_++)if(arg=n[_],"*"==arg[1])i.push("_b_.list.$factory("+arg[0]+")");else{var c=[n[_][0]];for(_++;_<l&&"s"==n[_][1];)c.push(n[_][0]),_++;_--,i.push("["+c.join(",")+"]")}for(r=i[0],_=1;_<i.length;_++)r+=".concat("+i[_]+")"}else{for(_=0,l=n.length;_<l;_++)n[_]=n[_][0];r=n.join(", ")}var u="{"+o.join(", ")+"}";u=s.length?'{$nat:"kw",kw:['+u+","+s.join(", ")+"]}":"{}"!=u?'{$nat:"kw",kw:'+u+"}":"",a&&u?r+=".concat(["+u+"])":r&&u?r+=","+u:r||(r=u);var f="$B.$call("+e+")"+(r=a?".apply(null,"+r+")":"("+r+")");return this.tree.length>-1&&"id"==this.func.type&&this.func.is_builtin&&void 0!==$B.builtin_funcs[this.func.value]?-1==["complex","bytes","bytearray","object","memoryview","int","float","str","list","tuple","dict","set","frozenset","range","slice","zip","bool","type","classmethod","staticmethod","enumerate","reversed","property","$$super","zip","map","filter"].indexOf(this.func.value)?e+r:e+".$factory"+r:f}};var $CaseCtx=$B.parser.$CaseCtx=function(e){this.type="case",e.tree=[this],this.parent=e,this.tree=[],this.expect="as"};$CaseCtx.prototype.set_alias=function(e){this.alias=e},$CaseCtx.prototype.transition=function(e,t){var r=this;switch(console.log("transition on case",e,t),e){case"as":return new $AbstractExprCtx(new $AliasCtx(r));case":":switch(r.expect){case"id":case"as":case":":return $BodyCtx(r)}}},$CaseCtx.prototype.to_js=function(){return console.log("to js",this),"if(subject == "+$to_js(this.tree)+")"};var $ClassCtx=$B.parser.$ClassCtx=function(e){this.type="class",this.parent=e,this.tree=[],e.tree[e.tree.length]=this,this.expect="id";var t=this.scope=$get_scope(this);this.parent.node.parent_block=t,this.parent.node.bound={},this.parent.node.binding={__annotations__:!0}};$ClassCtx.prototype.toString=function(){return"(class) "+this.name+" "+this.tree+" args "+this.args},$ClassCtx.prototype.transition=function(e,t){var r=this;switch(e){case"id":if("id"==r.expect)return r.set_name(t),r.expect="(:",r;break;case"(":return new $CallCtx(r);case":":return $BodyCtx(r)}$_SyntaxError(r,"token "+e+" after "+r)},$ClassCtx.prototype.set_name=function(e){var t=this.parent;this.random=$B.UUID(),this.name=e,this.id=t.node.module+"_"+e+"_"+this.random,this.binding={},this.parent.node.id=this.id;for(var r=this.scope,n=r,o=r,a=[];"class"==o.ntype;)a.splice(0,0,o.C.tree[0].name),o=o.parent;for(this.qualname=a.concat([e]).join(".");n.C&&"class"==n.C.tree[0].type;)n=n.parent;for(;n.C&&"def"!=n.C.tree[0].type&&"generator"!=n.C.tree[0].type;)n=n.parent;this.parent.node.parent_block=n,$bind(e,r,this),r.is_function&&-1==r.C.tree[0].locals.indexOf(e)&&r.C.tree[0].locals.push(e)},$ClassCtx.prototype.transform=function(e,t){this.doc_string=$get_docstring(e),this.module=$get_module(this).module.replace(/\./g,"_");var r="\n"+" ".repeat(e.indent+12),n=new $Node,o="$locals_"+this.id.replace(/\./g,"_");new $NodeJSCtx(n,i="var "+o+" = {__annotations__: $B.empty_dict()}, "+r+"$locals = "+o),e.insert(0,n);for(var a=this.scope;"__builtins__"!==a.parent_block.id;)a=a.parent_block;var s="$locals_"+a.id.replace(/\./g,"_"),i=" ".repeat(e.indent+4)+'$locals.$name = "'+this.name+'"'+r+'$locals.$qualname = "'+this.qualname+'"'+r+"$locals.$is_class = true; "+r+'$locals.$line_info = "'+e.line_num+","+this.module+'";'+r+'var $top_frame = ["'+o+'", $locals,"'+a.id+'", '+s+"]"+r+"$locals.$f_trace = $B.enter_frame($top_frame);"+r+"if($locals.$f_trace !== _b_.None){$locals.$f_trace = $B.trace_line()}";e.insert(1,$NodeJS(i)),e.add($NodeJS("if($locals.$f_trace !== _b_.None){$B.trace_return(_b_.None)}")),e.add($NodeJS("$B.leave_frame({$locals})"));var _=new $Node;new $NodeJSCtx(_,"return "+o+";"),e.insert(e.children.length,_);var l=new $Node;new $NodeJSCtx(l,")();"),e.parent.insert(t+1,l);var c="$locals_"+this.module+".__name__";t++,e.parent.insert(t+1,$NodeJS("$"+this.name+"_"+this.random+".__module__ = "+c));var u=$get_scope(this),f=";$locals_"+u.id.replace(/\./g,"_"),p=1;if((i=[(f+='["'+this.name+'"]')+' = $B.$class_constructor("'+this.name])[p++]='", $'+this.name+"_"+this.random,void 0!==this.args){var $=this.args.tree,d=[],h=[];$.forEach((function(e){"kwarg"==e.tree[0].type?h.push(e.tree[0]):d.push(e.to_js())})),i[p++]=", _b_.tuple.$factory(["+d.join(",")+"]),[";var m=new RegExp('"',"g"),b=[],g=0;d.forEach((function(e){b[g++]='"'+e.replace(m,'\\"')+'"'})),i[p++]=b.join(",")+"]",b=[],g=0,h.forEach((function(e){b[g++]='["'+e.tree[0].value+'",'+e.tree[1].to_js()+"]"})),i[p++]=",["+b.join(",")+"]"}else i[p++]=", _b_.tuple.$factory([]),[],[]";i[p++]=")";var y=new $Node;new $NodeJSCtx(y,i.join("")),t++,e.parent.insert(t+1,y),t++;var v=new $Node;if(i=f+".__doc__ = "+(this.doc_string||"_b_.None")+";",new $NodeJSCtx(v,i),e.parent.insert(t+1,v),"module"==u.ntype){var x=new $Node;new $NodeJSCtx(x,'$locals["'+this.name+'"] = '+this.name)}e.parent.insert(t+2,$NodeJS("_b_.None;")),this.transformed=!0},$ClassCtx.prototype.to_js=function(){return this.js_processed=!0,"var $"+this.name+"_"+this.random+" = (function()"};var $CompIfCtx=$B.parser.$CompIfCtx=function(e){this.type="comp_if",e.parent.intervals.push($pos),this.parent=e,this.tree=[],e.tree[e.tree.length]=this};$CompIfCtx.prototype.toString=function(){return"(comp if) "+this.tree},$CompIfCtx.prototype.transition=function(e,t){return $transition(this.parent,e,t)},$CompIfCtx.prototype.to_js=function(){return this.js_processed=!0,$to_js(this.tree)};var $ComprehensionCtx=$B.parser.$ComprehensionCtx=function(e){this.type="comprehension",this.parent=e,this.tree=[],e.tree[e.tree.length]=this};$ComprehensionCtx.prototype.toString=function(){return"(comprehension) "+this.tree},$ComprehensionCtx.prototype.transition=function(e,t){var r=this;switch(e){case"if":return new $AbstractExprCtx(new $CompIfCtx(r),!1);case"for":return new $TargetListCtx(new $CompForCtx(r))}return $transition(r.parent,e,t)},$ComprehensionCtx.prototype.to_js=function(){this.js_processed=!0;var e=[];return this.tree.forEach((function(t){e.push(t.start)})),e};var $CompForCtx=$B.parser.$CompForCtx=function(e){this.type="comp_for",e.parent.intervals.push($pos),this.parent=e,this.tree=[],this.expect="in",e.tree[e.tree.length]=this};$CompForCtx.prototype.toString=function(){return"(comp for) "+this.tree},$CompForCtx.prototype.transition=function(e,t){var r=this;return"in"==e&&"in"==r.expect?(r.expect=null,new $AbstractExprCtx(new $CompIterableCtx(r),!0)):null===r.expect?$transition(r.parent,e,t):void $_SyntaxError(r,"token "+e+" after "+r)},$CompForCtx.prototype.to_js=function(){return this.js_processed=!0,$to_js(this.tree)};var $CompIterableCtx=$B.parser.$CompIterableCtx=function(e){this.type="comp_iterable",this.parent=e,this.tree=[],e.tree[e.tree.length]=this};$CompIterableCtx.prototype.toString=function(){return"(comp iter) "+this.tree},$CompIterableCtx.prototype.transition=function(e,t){return $transition(this.parent,e,t)},$CompIterableCtx.prototype.to_js=function(){return this.js_processed=!0,$to_js(this.tree)};var $ConditionCtx=$B.parser.$ConditionCtx=function(e,t){this.type="condition",this.token=t,this.parent=e,this.tree=[],this.scope=$get_scope(this),"while"==t&&(this.loop_num=$loop_num++),e.tree[e.tree.length]=this};$ConditionCtx.prototype.toString=function(){return this.token+" "+this.tree},$ConditionCtx.prototype.transition=function(e,t){var r=this;if(":"==e)return"abstract_expr"==r.tree[0].type&&0==r.tree[0].tree.length&&$_SyntaxError(r,"token "+e+" after "+r),$BodyCtx(r);$_SyntaxError(r,"token "+e+" after "+r)},$ConditionCtx.prototype.transform=function(e,t){if($get_scope(this),"while"==this.token){e.parent.insert(t,$NodeJS('$locals["$no_break'+this.loop_num+'"] = true'));var r=$get_module(this).module;if("return"!=$B.last(e.children).C.tree[0].type){var n='$locals.$line_info = "'+e.line_num+","+r+'";if($locals.$f_trace !== _b_.None){$B.trace_line()};_b_.None;';e.add($NodeJS(n))}return 2}},$ConditionCtx.prototype.to_js=function(){this.js_processed=!0;var e=this.token;"elif"==e&&(e="else if");var t=[e+"($B.$bool("];if("while"==e)t.push('$locals["$no_break'+this.loop_num+'"] && ');else if("else if"==e){var r=$get_node(this).line_num+","+$get_scope(this).id;t.push('($B.set_line("'+r+'")) && ')}return 1==this.tree.length?t.push($to_js(this.tree)+"))"):(t.push(this.tree[0].to_js()+"))"),this.tree[1].tree.length>0&&t.push("{"+this.tree[1].to_js()+"}")),t.join("")};var $ContinueCtx=$B.parser.$ContinueCtx=function(e){this.type="continue",this.parent=e,$get_node(this).is_continue=!0,e.tree[e.tree.length]=this,set_loop_context.apply(this,[e,"continue"])};$ContinueCtx.prototype.toString=function(){return"(continue)"},$ContinueCtx.prototype.transition=function(e,t){var r=this;if("eol"==e)return r.parent;$_SyntaxError(r,"token "+e+" after "+r)},$ContinueCtx.prototype.to_js=function(){this.js_processed=!0;var e="continue";return this.loop_ctx.has_break&&(e=`$locals["$no_break${this.loop_ctx.loop_num}"]=true;${e}`),e};var $DebuggerCtx=$B.parser.$DebuggerCtx=function(e){this.type="continue",this.parent=e,e.tree[e.tree.length]=this};$DebuggerCtx.prototype.toString=function(){return"(debugger)"},$DebuggerCtx.prototype.transition=function(e,t){},$DebuggerCtx.prototype.to_js=function(){return this.js_processed=!0,"debugger"};var $DecoratorCtx=$B.parser.$DecoratorCtx=function(e){this.type="decorator",this.parent=e,e.tree[e.tree.length]=this,this.tree=[]};$DecoratorCtx.prototype.toString=function(){return"(decorator) "+this.tree},$DecoratorCtx.prototype.transition=function(e,t){var r=this;return"id"==e&&0==r.tree.length?$transition(new $AbstractExprCtx(r,!1),e,t):"eol"==e?$transition(r.parent,e):void $_SyntaxError(r,"token "+e+" after "+r)},$DecoratorCtx.prototype.transform=function(e,t){for(var r=t+1,n=e.parent.children,o=[this.tree];;)if(r>=n.length)$_SyntaxError(e.C,["decorator expects function"]);else if("node_js"==n[r].C.type)r++;else{if("decorator"!=n[r].C.tree[0].type)break;o.push(n[r].C.tree[0].tree),n.splice(r,1)}this.dec_ids=[],o.forEach((function(){this.dec_ids.push("$id"+$B.UUID())}),this);var a=n[r].C.tree[0];"def"==a.type&&(a.decorated=!0,a.alias="$dec"+$B.UUID());var s="",i=$get_scope(this),_='$locals["';i.globals&&i.globals.has(a.name)&&(_="$locals_"+$get_module(this).id+'["');var l=(_+=a.name+'"]')+" = ";o.forEach((function(e,t){l+="$B.$call("+this.dec_ids[t]+")(",s+=")"}),this),l+=(a.decorated?a.alias:_)+s+";",$bind(a.name,i,this),e.parent.insert(r+1,$NodeJS(l)),this.decorators=o},$DecoratorCtx.prototype.to_js=function(){this.js_processed=!0;var e=[];return this.decorators.forEach((function(t,r){e.push("var "+this.dec_ids[r]+" = "+$to_js(t)+";")}),this),e.join("")};var $DefCtx=$B.parser.$DefCtx=function(e){this.type="def",this.name=null,this.parent=e,this.tree=[],this.async=e.async,this.locals=[],e.tree[e.tree.length]=this,this.enclosing=[];var t=this.scope=$get_scope(this);t.C&&"class"==t.C.tree[0].type&&(this.class_name=t.C.tree[0].name),e.node.binding={};for(var r=t;r.C&&"class"==r.C.tree[0].type;)r=r.parent;for(;r.C&&"def"!=r.C.tree[0].type;)r=r.parent;this.parent.node.parent_block=r;var n=r;for(this.is_comp=n.is_comp;n&&n.C;){if("def"==n.C.tree[0].type){this.inside_function=!0;break}n=n.parent_block}this.module=t.module,this.root=$get_module(this),this.num=$loop_num,$loop_num++,this.positional_list=[],this.default_list=[],this.other_args=null,this.other_kw=null,this.after_star=[]};$DefCtx.prototype.set_name=function(e){try{e=$mangle(e,this.parent.tree[0])}catch(e){throw console.log(e),console.log("parent",this.parent),e}var t=new $IdCtx(this,e);this.name=e,this.id=this.scope.id+"_"+e,this.id=this.id.replace(/\./g,"_"),this.id+="_"+$B.UUID(),this.parent.node.id=this.id,this.parent.node.module=this.module,this.binding={};var r=this.scope;void 0!==r.globals&&r.globals.has(e)?$bind(e,this.root,this):$bind(e,r,this),t.bound=!0,r.is_function&&-1==r.C.tree[0].locals.indexOf(e)&&r.C.tree[0].locals.push(e)},$DefCtx.prototype.toString=function(){return"def "+this.name+"("+this.tree+")"},$DefCtx.prototype.transition=function(e,t){var r=this;switch(e){case"id":return r.name&&$_SyntaxError(r,"token "+e+" after "+r),r.set_name(t),r;case"(":return null==r.name&&$_SyntaxError(r,"missing name in function definition"),r.has_args=!0,new $FuncArgs(r);case"annotation":return new $AbstractExprCtx(new $AnnotationCtx(r),!0);case":":if(r.has_args)return $BodyCtx(r);$_SyntaxError(r,"missing function parameters");case"eol":r.has_args&&$_SyntaxError(r,"missing colon")}$_SyntaxError(r,"token "+e+" after "+r)},$DefCtx.prototype.transform=function(e,t){if(this.is_comp&&($get_node(this).is_comp=!0),void 0===this.transformed){var r=this.scope;this.doc_string=$get_docstring(e),this.rank=t;var n=e.indent+12;if(this.name.substr(0,15)=="lambda_"+$B.lambda_magic){var o=r.parent_block;o.C&&"def"==o.C.tree[0].type&&this.enclosing.push(o)}for(var a=this.parent.node;a.parent&&a.parent.is_def_func;)this.enclosing.push(a.parent.parent),a=a.parent.parent;var s=[],i=[],_=!1;this.argcount=0,this.kwonlyargcount=0,this.kwonlyargsdefaults=[],this.otherdefaults=[],this.varnames={},this.args=[],this.__defaults__=[],this.slots=[];var l=[],c=[],u=[];this.annotation&&u.push('"return":'+this.annotation.to_js()),this.func_name=this.tree[0].to_js();var f=this.func_name;this.decorated&&(this.func_name="var "+this.alias,f=this.alias),this.tree[1].tree.forEach((function(e){if("end_positional"==e.type?(this.args.push("/"),l.push('"/"'),_=!0):(this.args.push(e.name),this.varnames[e.name]=!0),"func_arg_id"==e.type?(this.star_arg?(this.kwonlyargcount++,e.has_default&&this.kwonlyargsdefaults.push(e.name)):(this.argcount++,e.has_default&&this.otherdefaults.push(e.name)),this.slots.push(e.name+":null"),l.push('"'+e.name+'"'),c.push(e.name+":"+e.name),e.tree.length>0&&(s.push('"'+e.name+'"'),i.push(e.name+":"+$to_js(e.tree)),this.__defaults__.push($to_js(e.tree)))):"func_star_arg"==e.type&&("*"==e.op?this.star_arg=e.name:"**"==e.op&&(this.kw_arg=e.name)),e.annotation){var t=$mangle(e.name,this);u.push(t+": "+e.annotation.to_js())}}),this),c="{"+c.join(", ")+