├── .eslintrc ├── .gitignore ├── .prettierignore ├── .prettierrc.json ├── .travis.yml ├── README.md ├── dist ├── fnMatch.js ├── index.d.ts ├── index.js └── test.d.ts ├── docs ├── README.md ├── css │ ├── github-light.css │ ├── mui.css │ └── styles.css ├── img │ ├── cheesy_logo.png │ ├── logo.ai │ └── pizza.svg ├── index.html ├── js │ ├── fnMatch.js │ ├── index.js │ └── viz.js └── main.js ├── examples └── test.ts ├── jest.config.ts ├── package-lock.json ├── package.json ├── spec ├── array_test.js ├── destructuring_test.js ├── function_test.js └── simple_test.js ├── src └── index.ts ├── test ├── index.html └── test.js ├── tsconfig.json └── webpack.config.js /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "jest": true 4 | }, 5 | "parserOptions": { 6 | "ecmaVersion": 6 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | node_modules 3 | .ignore 4 | .DS_Store 5 | notes -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | dist 2 | docs -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | sudo: false 3 | node_js: 4 | - "16" 5 | install: 6 | - npm install 7 | script: 8 | - npm test 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 | # fnMatch 6 | 7 | This is a very simple implementation of pattern matching using **no syntax extensions**. That means you can use it **without a transpiler**; just include it on your project/website. 8 | 9 | ## Quick example: 10 | 11 | You can do this in **OCaml**: 12 | 13 | ```ocaml 14 | let rec fib n = match n with 15 | | 0 -> 1 16 | | 1 -> 1 17 | | x -> fib (x-2) + fib (x-1) 18 | ``` 19 | 20 | **JavaScript** using fnMatch: 21 | 22 | ```javascript 23 | let fib = (n) => 24 | match(n)( 25 | (x = 0) => 1, 26 | (x = 1) => 1, 27 | (x) => fib(x - 2) + fib(x - 1) 28 | ); 29 | ``` 30 | 31 | ## Installation 32 | 33 | - node 34 | 35 | ``` 36 | npm i fnMatch 37 | ``` 38 | 39 | - web 40 | 41 | ``` 42 | 43 | ``` 44 | 45 | ## Usage 46 | 47 | Instead of extending the language, it just uses **_functions_**. That's it. Just import `fnMatch` anywhere: 48 | 49 | ```javascript 50 | const { match, func } = require("fnMatch"); 51 | ``` 52 | 53 | It supports: 54 | 55 | - Shape matching through **object deconstruction**: 56 | 57 | ```javascript 58 | let group = { 59 | course: "CS 3410", 60 | members: [ 61 | { name: "Ajay", age: 22 }, 62 | { name: "Seung", age: 23 }, 63 | { name: "Adi", age: 22 }, 64 | ], 65 | }; 66 | 67 | match(group)( 68 | ({ club, members }) => {}, // doesn't match, missing "club" 69 | ({ course, members: [first, ...rest] }) => {}, // matches! 70 | ({ course, members }) => {} // would match if previous didn't 71 | ); 72 | ``` 73 | 74 | - Value matching through **default value syntax**: 75 | 76 | ```javascript 77 | match("hello")( 78 | (_ = "hey") => {}, // doesn't match 79 | (_ = "world") => {}, // doesn't match 80 | (_ = "hello") => {} // matches! 81 | ); 82 | ``` 83 | 84 | - **Binding** (of course, these are _functions_ after all!) 85 | 86 | ```javascript 87 | match({ name: "Ajay" })( 88 | ({ name }) => conosle.log(`Hello ${name}!`), // matches, name is "Ajay" 89 | () => console.log("Hello, someone!") // would match if previous didn't 90 | ); 91 | ``` 92 | 93 | - Alternative syntax: **pattern definition before evaluation**: 94 | 95 | ```javascript 96 | func( 97 | ({ name }) => conosle.log(`Hello ${name}!`), // matches, name is "Ajay" 98 | () => console.log("Hello, someone!") // would match if previous didn't 99 | )({ name: "Ajay" }); 100 | ``` 101 | 102 | Woah woah woah. Why would I want to do a pattern match by defining the patterns first and passing in the value later? Well, because this is an expression, and this way of doing things is useful for defining functions, _a la_ OCaml's `function` keyword: 103 | 104 | OCaml: 105 | 106 | ```ocaml 107 | let rec fib = function 108 | | 0 -> 1 109 | | 1 -> 1 110 | | x -> fib (x-2) + fib (x-1) 111 | ``` 112 | 113 | JavaScript: 114 | 115 | ```javascript 116 | let fib = func( 117 | (_ = 0) => 1 118 | (_ = 1) => 1 119 | (x) => fib(x-2) + fib(x-1) 120 | ); 121 | ``` 122 | 123 | - And of course, "match" and "func" are **expressions** evaluating to the return the value of the matched function. Here's a more complex example: 124 | 125 | ```javascript 126 | const process_response = func( 127 | ({ status: s = 200, data: d = null }) => Error("Data is null"), 128 | ({ status: s = 200, data: d = [] }) => Error("Data is empty"), 129 | ({ status: s = 200, data }) => data, // return data 130 | ({ errors: [h, ...t] }) => Error(`Non-empty errors. ${t.length + 1} total.`), 131 | ({ status }) => Error(`Status ${status}, no errors reported`), 132 | (_) => Error("Invalid response") 133 | ); 134 | 135 | const print_response = (response) => { 136 | const result = process_response(response); 137 | if (result instanceof Error) throw result; 138 | console.log(`Recieved ${result}!`); 139 | }; 140 | ``` 141 | 142 | ## Things to note 143 | 144 | - **Patterns are tested in order**, from top to bottom: 145 | 146 | ```javascript 147 | // This prints "default" 148 | match({ name: "Ajay" })( 149 | (_) => console.log("default"), 150 | ({ name }) => console.log(name) 151 | ); 152 | 153 | // This prints "Ajay" 154 | match({ name: "Ajay" })( 155 | ({ name }) => console.log(name), 156 | (_) => console.log("default") 157 | ); 158 | ``` 159 | 160 | - `() => {}` matches **_undefined_**, not **_all_** (aka, `() => {}` !== `(_) => {}`): 161 | 162 | ```javascript 163 | // This prints "undefined" 164 | match()( 165 | () => console.log("undefined"), 166 | (_) => console.log("anything") 167 | ); 168 | 169 | // This prints "anything" 170 | match(3)( 171 | () => console.log("undefined"), 172 | (_) => console.log("anything") 173 | ); 174 | ``` 175 | 176 | - **Array semantics** are a little different from how JavaScript normally works: 177 | 178 | ### Array semantics 179 | 180 | For the sake of usability, the semantics used for array matching are different from how calling a function with that destructs an array would have you believe. Let's illustrate with 2 examples: 181 | 182 | - Identifiers will always match a value in the array, whereas on function calls they are assigned `undefined` if there's nothing for them to match 183 | 184 | ```javascript 185 | // Javascrpt 186 | (([x, ...y]) => console.log(x, y))([]); // logs "undefined []" 187 | 188 | // fnMatch 189 | func(([x, ...y]) => console.log(x, y))([]); // logs nothing, doesn't match 190 | ``` 191 | 192 | - Patterns without a "rest clause" (ie, `...t`) will only match patterns of that same length (similar to how Ocaml works) 193 | 194 | ```javascript 195 | // Javascrpt 196 | (([x, y]) => console.log(x, y))([1, 2, 3]); // logs "1 2" 197 | 198 | // fnMatch 199 | func(([x, y]) => console.log(x, y))([1, 2, 3]); // logs nothing, doesn't match 200 | ``` 201 | 202 | ### Disclaimer 203 | 204 | This was very quickly thrown together, so it's very much not optimized in any way. See the source for details on maybe not low-hanging, but definitley juicy performance improvements that could be made. 205 | 206 | Happy matching! 207 | 208 | --- 209 | 210 | [![Build Status](https://travis-ci.org/mrkev/fnMatch.svg?branch=master)](https://travis-ci.org/mrkev/fnMatch) 211 | [![Coverage Status](https://coveralls.io/repos/github/mrkev/fnMatch/badge.svg?branch=master)](https://coveralls.io/github/mrkev/fnMatch?branch=master) 212 | -------------------------------------------------------------------------------- /dist/index.d.ts: -------------------------------------------------------------------------------- 1 | declare type ExtractReturnTypes any)[]> = [ 2 | ...{ 3 | [K in keyof T]: T[K] extends (...args: any[]) => infer R ? R : never; 4 | } 5 | ]; 6 | declare type MatchResult any)[]> = ExtractReturnTypes[number]; 7 | export declare const match: (v: VL) => any)[]>(...cases: CS) => MatchResult | undefined; 8 | export declare const func: any)[]>(...cases: CS) => (v: VL) => MatchResult | undefined; 9 | export {}; 10 | -------------------------------------------------------------------------------- /dist/index.js: -------------------------------------------------------------------------------- 1 | !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.fnMatch=t():e.fnMatch=t()}(self,(()=>(()=>{"use strict";var __webpack_modules__={326:(e,t)=>{function n(e,t){for(var n=0;n":9,"<=":9,">=":9,in:9,instanceof:9,"<<":10,">>":10,">>>":10,"+":11,"-":11,"*":12,"%":12,"/":12,"**":13},a=17;t.NEEDS_PARENTHESES=a;var i,s,c,l,u,p,d={ArrayExpression:20,TaggedTemplateExpression:20,ThisExpression:20,Identifier:20,PrivateIdentifier:20,Literal:18,TemplateLiteral:20,Super:20,SequenceExpression:20,MemberExpression:19,ChainExpression:19,CallExpression:19,NewExpression:19,ArrowFunctionExpression:a,ClassExpression:a,FunctionExpression:a,ObjectExpression:a,UpdateExpression:16,UnaryExpression:15,AwaitExpression:15,BinaryExpression:14,LogicalExpression:13,ConditionalExpression:4,AssignmentExpression:3,YieldExpression:2,RestElement:1};function f(e,t){var n=e.generator;if(e.write("("),null!=t&&t.length>0){n[t[0].type](t[0],e);for(var r=t.length,o=1;o0){e.write(r);for(var i=1;i0){n.VariableDeclarator(r[0],e);for(var a=1;a0){t.write(r),o&&null!=e.comments&&y(t,e.comments,a,r);for(var s=i.length,c=0;c0){for(;o0&&t.write(", ");var a=n[o],i=a.type[6];if("D"===i)t.write(a.local.name,a),o++;else{if("N"!==i)break;t.write("* as "+a.local.name,a),o++}}if(o0)for(var o=0;;){var a=n[o],i=a.local.name;if(t.write(i,a),i!==a.exported.name&&t.write(" as "+a.exported.name),!(++o "),"O"===e.body.type[0]?(t.write("("),this.ObjectExpression(e.body,t),t.write(")")):this[e.body.type](e.body,t)},ThisExpression:function(e,t){t.write("this",e)},Super:function(e,t){t.write("super",e)},RestElement:c=function(e,t){t.write("..."),this[e.argument.type](e.argument,t)},SpreadElement:c,YieldExpression:function(e,t){t.write(e.delegate?"yield*":"yield"),e.argument&&(t.write(" "),this[e.argument.type](e.argument,t))},AwaitExpression:function(e,t){t.write("await ",e),w(t,e.argument,e)},TemplateLiteral:function(e,t){var n=e.quasis,r=e.expressions;t.write("`");for(var o=r.length,a=0;a0)for(var n=e.elements,r=n.length,o=0;;){var a=n[o];if(null!=a&&this[a.type](a,t),!(++o0){t.write(r),o&&null!=e.comments&&y(t,e.comments,a,r);for(var i=","+r,s=e.properties,c=s.length,l=0;;){var u=s[l];if(o&&null!=u.comments&&y(t,u.comments,a,r),t.write(a),this[u.type](u,t),!(++l0)for(var n=e.properties,r=n.length,o=0;this[n[o].type](n[o],t),++o1)&&("U"!==o[0]||"n"!==o[1]&&"p"!==o[1]||!r.prefix||r.operator[0]!==n||"+"!==n&&"-"!==n)||t.write(" "),a?(t.write(n.length>1?" (":"("),this[o](r,t),t.write(")")):this[o](r,t)}else this[e.argument.type](e.argument,t),t.write(e.operator)},UpdateExpression:function(e,t){e.prefix?(t.write(e.operator),this[e.argument.type](e.argument,t)):(this[e.argument.type](e.argument,t),t.write(e.operator))},AssignmentExpression:function(e,t){this[e.left.type](e.left,t),t.write(" "+e.operator+" "),this[e.right.type](e.right,t)},AssignmentPattern:function(e,t){this[e.left.type](e.left,t),t.write(" = "),this[e.right.type](e.right,t)},BinaryExpression:l=function(e,t){var n="in"===e.operator;n&&t.write("("),w(t,e.left,e,!1),t.write(" "+e.operator+" "),w(t,e.right,e,!0),n&&t.write(")")},LogicalExpression:l,ConditionalExpression:function(e,t){var n=e.test,r=t.expressionsPrecedence[n.type];r===a||r<=t.expressionsPrecedence.ConditionalExpression?(t.write("("),this[n.type](n,t),t.write(")")):this[n.type](n,t),t.write(" ? "),this[e.consequent.type](e.consequent,t),t.write(" : "),this[e.alternate.type](e.alternate,t)},NewExpression:function(e,t){t.write("new ");var n=t.expressionsPrecedence[e.callee.type];n===a||n0&&(this.lineEndSize>0&&(1===l.length?e[c-1]===l:e.endsWith(l))?(this.line+=this.lineEndSize,this.column=0):this.column+=c)}},{key:"toString",value:function(){return this.output}}])&&n(t.prototype,r),e}()},951:(e,t,n)=>{n.r(t),n.d(t,{Context:()=>dt,CoverCallState:()=>St,CoverParenthesizedState:()=>ht,ESTree:()=>nr,Escape:()=>xt,Flags:()=>ft,Labels:()=>mt,ModifierState:()=>yt,NumericState:()=>wt,ObjectState:()=>vt,Parser:()=>or,RegexFlags:()=>kt,RegexState:()=>Et,Scanner:()=>rr,ScannerState:()=>gt,addLabel:()=>At,characterType:()=>s,constructError:()=>cn,consume:()=>Dt,consumeSemicolon:()=>Pt,descKeyword:()=>i,errorMessages:()=>sn,expect:()=>Lt,finishNode:()=>Ot,getLocation:()=>Xt,hasBit:()=>_t,hasLabel:()=>Ct,isEndOfCaseOrDefaultClauses:()=>Gt,isEqualTagNames:()=>Zt,isInOrOf:()=>an,isInstanceField:()=>en,isLexical:()=>qt,isPropertyWithPrivateFieldKey:()=>$t,isValidIdentifier:()=>Jt,isValidIdentifierPart:()=>c,isValidIdentifierStart:()=>l,isValidSimpleAssignmentTarget:()=>Vt,lookahead:()=>Bt,mustEscape:()=>u,nameIsArgumentsOrEval:()=>Wt,nextToken:()=>Nt,nextTokenIsFuncKeywordOnSameLine:()=>Ut,nextTokenIsLeftParen:()=>Yt,nextTokenIsLeftParenOrPeriod:()=>jt,nextTokenisIdentifierOrParen:()=>Kt,parse:()=>Zn,parseAndClassifyIdentifier:()=>zt,parseExpressionCoverGrammar:()=>Rt,parseModule:()=>tr,parseScript:()=>er,parseSource:()=>Wn,popLabel:()=>It,reinterpret:()=>Ft,report:()=>un,restoreExpressionCoverGrammar:()=>Mt,setPendingError:()=>Qt,setPendingExpressionError:()=>nn,swapContext:()=>Ht,tokenDesc:()=>o,tolerant:()=>pn,validateAsyncArgumentList:()=>on,validateBreakOrContinueLabel:()=>bt,validateCoverParenthesizedExpression:()=>rn,validateParams:()=>Tt,validateUpdateExpression:()=>tn,version:()=>ar});const r=["end of source","identifier","number","string","regular expression","false","true","null","template continuation","template end","=>","(","{",".","...","}",")",";",",","[","]",":","?","'",'"',"","++","--","=","<<=",">>=",">>>=","**=","+=","-=","*=","/=","%=","^=","|=","&=","typeof","delete","void","!","~","+","-","in","instanceof","*","%","/","**","&&","||","===","!==","==","!=","<=",">=","<",">","<<",">>",">>>","&","|","^","var","let","const","break","case","catch","class","continue","debugger","default","do","else","export","extends","finally","for","function","if","import","new","return","super","switch","this","throw","try","while","with","implements","interface","package","private","protected","public","static","yield","as","async","await","constructor","get","set","from","of","#","eval","arguments","enum","BigInt","@","JSXText","KeyOf","ReadOnly","is","unique","declare","type","namespace","abstract","module","global","require","target"];function o(e){return r[255&e]}const a=Object.create(null,{this:{value:33566815},function:{value:33566808},if:{value:12377},return:{value:12380},var:{value:33566791},else:{value:12370},for:{value:12374},new:{value:33566811},in:{value:167786289},typeof:{value:302002218},while:{value:12386},case:{value:12363},break:{value:12362},try:{value:12385},catch:{value:12364},delete:{value:302002219},throw:{value:302002272},switch:{value:33566814},continue:{value:12366},default:{value:12368},instanceof:{value:167786290},do:{value:12369},void:{value:302002220},finally:{value:12373},arguments:{value:37879925},keyof:{value:131194},readonly:{value:131195},unique:{value:131197},declare:{value:131198},async:{value:594028},await:{value:34017389},class:{value:33566797},const:{value:33566793},constructor:{value:69742},debugger:{value:12367},enum:{value:12406},eval:{value:37879924},export:{value:12371},extends:{value:12372},false:{value:33566725},from:{value:69745},get:{value:69743},implements:{value:20579},import:{value:33566810},interface:{value:20580},let:{value:33574984},null:{value:33566727},of:{value:69746},package:{value:20581},private:{value:20582},protected:{value:20583},public:{value:20584},set:{value:69744},static:{value:20585},super:{value:33566813},true:{value:33566726},with:{value:12387},yield:{value:1107316842},is:{value:131196},type:{value:131199},namespace:{value:131200},abstract:{value:131201},as:{value:167843947},module:{value:131202},global:{value:131203},require:{value:131204},target:{value:131205}});function i(e){return 0|a[e]}const s=[0,0,0,0,0,0,0,0,0,16,48,16,16,48,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,9,9,9,9,9,9,9,9,9,9,0,0,0,0,0,0,0,7,7,7,7,7,7,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,3,0,7,7,7,7,7,7,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0];function c(e){return 0!=(1&p[0+(e>>>5)]>>>e)}function l(e){return 0!=(1&p[34816+(e>>>5)]>>>e)}function u(e){return 0!=(1&p[69632+(e>>>5)]>>>e)}const p=((e,t)=>{const n=new Uint32Array(104448);let r=0,o=0;for(;r<3392;){const a=e[r++];if(a<0)o-=a;else{let i=e[r++];2&a&&(i=t[i]),1&a?n.fill(i,o,o+=e[r++]):n[o++]=i}}return n})([-1,2,28,2,29,2,5,-1,0,77595648,3,46,2,3,0,14,2,57,2,58,3,0,3,0,3168796671,0,4294956992,2,1,2,0,2,59,3,0,4,0,4294966523,3,0,4,2,15,2,60,2,0,0,4294836735,0,3221225471,0,4294901942,2,61,0,134152192,3,0,2,0,4294951935,3,0,2,0,2683305983,0,2684354047,2,17,2,0,0,4294961151,3,0,2,2,20,2,0,0,608174079,2,0,2,127,2,6,2,62,-1,2,64,2,26,2,1,3,0,3,0,4294901711,2,40,0,4089839103,0,2961209759,0,1342439375,0,4294543342,0,3547201023,0,1577204103,0,4194240,0,4294688750,2,2,0,80831,0,4261478351,0,4294549486,2,2,0,2965387679,0,196559,0,3594373100,0,3288319768,0,8469959,2,171,0,4294828031,0,3825204735,0,123747807,0,65487,2,3,0,4092591615,0,1080049119,0,458703,2,3,2,0,0,2163244511,0,4227923919,0,4236247020,2,68,0,4284449919,0,851904,2,4,2,16,0,67076095,-1,2,69,0,1006628014,0,4093591391,-1,0,50331649,0,3265266687,2,34,0,4294844415,0,4278190047,2,23,2,125,-1,3,0,2,2,33,2,0,2,9,2,0,2,13,2,14,3,0,10,2,71,2,0,2,72,2,73,2,74,2,0,2,75,2,0,2,10,0,261632,2,19,3,0,2,2,11,2,4,3,0,18,2,76,2,5,3,0,2,2,77,0,2088959,2,31,2,8,0,909311,3,0,2,0,814743551,2,42,0,67057664,3,0,2,2,45,2,0,2,32,2,0,2,18,2,7,0,268374015,2,30,2,51,2,0,2,78,0,134153215,-1,2,6,2,0,2,7,0,2684354559,0,67044351,0,1073676416,-2,3,0,2,2,43,0,1046528,3,0,3,2,8,2,0,2,41,0,4294960127,2,9,2,39,2,10,0,4294377472,2,21,3,0,7,0,4227858431,3,0,8,2,11,2,0,2,80,2,9,2,0,2,81,2,82,2,83,-1,2,122,0,1048577,2,84,2,12,-1,2,12,0,131042,2,85,2,86,2,87,2,0,2,35,-83,2,0,2,53,2,7,3,0,4,0,1046559,2,0,2,13,2,0,0,2147516671,2,24,3,88,2,2,0,-16,2,89,0,524222462,2,4,2,0,0,4269801471,2,4,2,0,2,14,2,79,2,15,3,0,2,2,49,2,16,-1,2,17,-16,3,0,205,2,18,-2,3,0,655,2,19,3,0,36,2,70,-1,2,17,2,9,3,0,8,2,91,2,119,2,0,0,3220242431,3,0,3,2,20,2,22,2,92,3,0,2,2,93,2,21,-1,2,22,2,0,2,27,2,0,2,8,3,0,2,0,67043391,0,3909091327,2,0,2,25,2,8,2,23,3,0,2,0,67076097,2,7,2,0,2,24,0,67059711,0,4236247039,3,0,2,0,939524103,0,8191999,2,97,2,98,2,14,2,95,3,0,3,0,67057663,3,0,349,2,99,2,100,2,6,-264,3,0,11,2,25,3,0,2,2,21,-1,0,3774349439,2,101,2,102,3,0,2,2,20,2,26,3,0,10,2,9,2,17,2,0,2,47,2,0,2,27,2,103,2,19,0,1638399,2,169,2,104,3,0,3,2,23,2,28,2,29,2,5,2,30,2,0,2,7,2,105,-1,2,106,2,107,2,108,-1,3,0,3,2,16,-2,2,0,2,31,-3,2,146,-4,2,23,2,0,2,37,0,1,2,0,2,63,2,32,2,16,2,9,2,0,2,109,-1,3,0,4,2,9,2,33,2,110,2,6,2,0,2,111,2,0,2,50,-4,3,0,9,2,24,2,18,2,27,-4,2,112,2,113,2,18,2,24,2,7,-2,2,114,2,18,2,21,-2,2,0,2,115,-2,0,4277137519,0,2269118463,-1,3,23,2,-1,2,34,2,38,2,0,3,18,2,2,36,2,20,-3,3,0,2,2,35,-1,2,0,2,36,2,0,2,36,2,0,2,48,-14,2,23,2,44,2,37,-5,3,0,2,2,38,0,2147549120,2,0,2,16,2,17,2,130,2,0,2,52,0,4294901872,0,5242879,3,0,2,0,402595359,-1,2,118,0,1090519039,-2,2,120,2,39,2,0,2,55,2,40,0,4226678271,0,3766565279,0,2039759,-4,3,0,2,0,1140787199,-1,3,0,2,0,67043519,-5,2,0,0,4282384383,0,1056964609,-1,3,0,2,0,67043345,-1,2,0,2,41,2,42,-1,2,10,2,43,-6,2,0,2,16,-3,3,0,2,0,2147484671,-8,2,0,2,7,2,44,2,0,0,603979727,-1,2,0,2,45,-8,2,54,2,46,0,67043329,2,123,2,47,0,8388351,-2,2,124,0,3028287487,2,48,2,126,0,33259519,2,42,-9,2,24,-8,3,0,28,2,21,-3,3,0,3,2,49,3,0,6,2,50,-85,3,0,33,2,49,-126,3,0,18,2,38,-269,3,0,17,2,45,2,7,2,42,-2,2,17,2,51,2,0,2,24,0,67043343,2,128,2,19,-21,3,0,2,-4,3,0,2,0,4294901791,2,7,2,164,-2,0,3,3,0,191,2,20,3,0,23,2,36,-296,3,0,8,2,7,-2,2,17,3,0,11,2,6,-72,3,0,3,2,129,0,1677656575,-166,0,4161266656,0,4071,0,15360,-4,0,28,-13,3,0,2,2,52,2,0,2,131,2,132,2,56,2,0,2,133,2,134,2,135,3,0,10,2,136,2,137,2,14,3,52,2,3,53,2,3,54,2,0,4294954999,2,0,-16,2,0,2,90,2,0,0,2105343,0,4160749584,0,65534,-42,0,4194303871,0,2011,-62,3,0,6,0,8323103,-1,3,0,2,2,55,-37,2,56,2,140,2,141,2,142,2,143,2,144,-138,3,0,1334,2,24,-1,3,0,129,2,31,3,0,6,2,9,3,0,180,2,145,3,0,233,0,1,-96,3,0,16,2,9,-22583,3,0,7,2,19,-6130,3,5,2,-1,0,69207040,3,46,2,3,0,14,2,57,2,58,-3,0,3168731136,0,4294956864,2,1,2,0,2,59,3,0,4,0,4294966275,3,0,4,2,15,2,60,2,0,2,35,-1,2,17,2,61,-1,2,0,2,62,0,4294885376,3,0,2,0,3145727,0,2617294944,0,4294770688,2,19,2,63,3,0,2,0,131135,2,94,0,70256639,0,71303167,0,272,2,45,2,62,-1,2,64,-2,2,96,0,603979775,0,4278255616,0,4294836227,0,4294549473,0,600178175,0,2952806400,0,268632067,0,4294543328,0,57540095,0,1577058304,0,1835008,0,4294688736,2,65,2,66,0,33554435,2,121,2,65,2,147,0,131075,0,3594373096,0,67094296,2,66,-1,2,67,0,603979263,2,156,0,3,0,4294828001,0,602930687,2,180,0,393219,2,67,0,671088639,0,2154840064,0,4227858435,0,4236247008,2,68,2,38,-1,2,4,0,917503,2,38,-1,2,69,0,537783470,0,4026531935,-1,0,1,-1,2,34,2,70,0,7936,-3,2,0,0,2147485695,0,1010761728,0,4292984930,0,16387,2,0,2,13,2,14,3,0,10,2,71,2,0,2,72,2,73,2,74,2,0,2,75,2,0,2,16,-1,2,19,3,0,2,2,11,2,4,3,0,18,2,76,2,5,3,0,2,2,77,0,253951,3,20,2,0,122879,2,0,2,8,0,276824064,-2,3,0,2,2,45,2,0,0,4294903295,2,0,2,18,2,7,-1,2,17,2,51,2,0,2,78,2,42,-1,2,24,2,0,2,31,-2,0,128,-2,2,79,2,8,0,4064,-1,2,117,0,4227907585,2,0,2,116,2,0,2,50,2,196,2,9,2,39,2,10,-1,0,6544896,3,0,6,-2,3,0,8,2,11,2,0,2,80,2,9,2,0,2,81,2,82,2,83,-3,2,84,2,12,-3,2,85,2,86,2,87,2,0,2,35,-83,2,0,2,53,2,7,3,0,4,0,817183,2,0,2,13,2,0,0,33023,2,24,3,88,2,-17,2,89,0,524157950,2,4,2,0,2,90,2,4,2,0,2,14,2,79,2,15,3,0,2,2,49,2,16,-1,2,17,-16,3,0,205,2,18,-2,3,0,655,2,19,3,0,36,2,70,-1,2,17,2,9,3,0,8,2,91,0,3072,2,0,0,2147516415,2,9,3,0,2,2,19,2,22,2,92,3,0,2,2,93,2,21,-1,2,22,0,4294965179,0,7,2,0,2,8,2,92,2,8,-1,0,1761345536,2,94,2,95,2,38,2,23,2,96,2,36,2,162,0,2080440287,2,0,2,35,2,138,0,3296722943,2,0,0,1046675455,0,939524101,0,1837055,2,97,2,98,2,14,2,95,3,0,3,0,7,3,0,349,2,99,2,100,2,6,-264,3,0,11,2,25,3,0,2,2,21,-1,0,2700607615,2,101,2,102,3,0,2,2,20,2,26,3,0,10,2,9,2,17,2,0,2,47,2,0,2,27,2,103,-3,2,104,3,0,3,2,23,-1,3,5,2,2,30,2,0,2,7,2,105,-1,2,106,2,107,2,108,-1,3,0,3,2,16,-2,2,0,2,31,-8,2,23,2,0,2,37,-1,2,0,2,63,2,32,2,18,2,9,2,0,2,109,-1,3,0,4,2,9,2,17,2,110,2,6,2,0,2,111,2,0,2,50,-4,3,0,9,2,24,2,18,2,27,-4,2,112,2,113,2,18,2,24,2,7,-2,2,114,2,18,2,21,-2,2,0,2,115,-2,0,4277075969,2,18,-1,3,23,2,-1,2,34,2,139,2,0,3,18,2,2,36,2,20,-3,3,0,2,2,35,-1,2,0,2,36,2,0,2,36,2,0,2,50,-14,2,23,2,44,2,116,-5,2,117,2,41,-2,2,117,2,19,2,17,2,35,2,117,2,38,0,4294901776,0,4718591,2,117,2,36,0,335544350,-1,2,118,2,119,-2,2,120,2,39,2,7,-1,2,121,2,65,0,3758161920,0,3,-4,2,0,2,31,2,174,-1,2,0,2,19,0,176,-5,2,0,2,49,2,182,-1,2,0,2,19,2,194,-1,2,0,2,62,-2,2,16,-7,2,0,2,119,-3,3,0,2,2,122,-8,0,4294965249,0,67633151,0,4026597376,2,0,0,536871887,-1,2,0,2,45,-8,2,54,2,49,0,1,2,123,2,19,-3,2,124,2,37,2,125,2,126,0,16778239,-10,2,36,-8,3,0,28,2,21,-3,3,0,3,2,49,3,0,6,2,50,-85,3,0,33,2,49,-126,3,0,18,2,38,-269,3,0,17,2,45,2,7,-3,2,17,2,127,2,0,2,19,2,50,2,128,2,19,-21,3,0,2,-4,3,0,2,0,65567,-1,2,26,-2,0,3,3,0,191,2,20,3,0,23,2,36,-296,3,0,8,2,7,-2,2,17,3,0,11,2,6,-72,3,0,3,2,129,2,130,-187,3,0,2,2,52,2,0,2,131,2,132,2,56,2,0,2,133,2,134,2,135,3,0,10,2,136,2,137,2,14,3,52,2,3,53,2,3,54,2,2,138,-129,3,0,6,2,139,-1,3,0,2,2,50,-37,2,56,2,140,2,141,2,142,2,143,2,144,-138,3,0,1334,2,24,-1,3,0,129,2,31,3,0,6,2,9,3,0,180,2,145,3,0,233,0,1,-96,3,0,16,2,9,-28719,2,0,0,1,-1,2,122,2,0,0,8193,-21,0,50331648,0,10255,0,4,-11,2,66,2,168,-1,0,71680,-1,2,157,0,4292900864,0,805306431,-5,2,146,-1,2,176,-1,0,6144,-2,2,123,-1,2,150,-1,2,153,2,147,2,161,2,0,0,3223322624,2,36,0,4,-4,2,188,0,205128192,0,1333757536,0,2147483696,0,423953,0,747766272,0,2717763192,0,4286578751,0,278545,2,148,0,4294886464,0,33292336,0,417809,2,148,0,1329579616,0,4278190128,0,700594195,0,1006647527,0,4286497336,0,4160749631,2,149,0,469762560,0,4171219488,0,16711728,2,149,0,202375680,0,3214918176,0,4294508592,0,139280,-1,0,983584,2,190,0,58720275,0,3489923072,0,10517376,0,4293066815,0,1,0,2013265920,2,175,2,0,0,17816169,0,3288339281,0,201375904,2,0,-2,0,256,0,122880,0,16777216,2,146,0,4160757760,2,0,-6,2,163,-11,0,3263218176,-1,0,49664,0,2160197632,0,8388802,-1,0,12713984,-1,2,150,2,155,2,158,-2,2,159,-20,0,3758096385,-2,2,151,0,4292878336,2,22,2,166,0,4294057984,-2,2,160,2,152,2,172,-2,2,151,-1,2,179,-1,2,167,2,122,0,4026593280,0,14,0,4292919296,-1,2,154,0,939588608,-1,0,805306368,-1,2,122,0,1610612736,2,152,2,153,3,0,2,-2,2,154,2,155,-3,0,267386880,-1,2,156,0,7168,-1,0,65024,2,150,2,157,2,158,-7,2,165,-8,2,159,-1,0,1426112704,2,160,-1,2,185,0,271581216,0,2149777408,2,19,2,157,2,122,0,851967,0,3758129152,-1,2,19,2,178,-4,2,154,-20,2,192,2,161,-56,0,3145728,2,184,-1,2,191,2,122,-1,2,162,2,122,-4,0,32505856,-1,2,163,-1,0,2147385088,2,22,1,2155905152,2,-3,2,164,2,0,2,165,-2,2,166,-6,2,167,0,4026597375,0,1,-1,0,1,-1,2,168,-3,2,139,2,66,-2,2,162,2,177,-1,2,173,2,122,-6,2,122,-213,2,167,-657,2,17,-36,2,169,-1,2,186,-10,0,4294963200,-5,2,170,-5,2,158,2,0,2,24,-1,0,4227919872,-1,2,170,-2,0,4227874752,-3,0,2146435072,2,155,-2,0,1006649344,2,122,-1,2,22,0,201375744,-3,0,134217720,2,22,0,4286677377,0,32896,-1,2,171,-3,2,172,-349,2,173,2,174,2,175,3,0,264,-11,2,176,-2,2,158,2,0,0,520617856,0,2692743168,0,36,-3,0,524284,-11,2,19,-1,2,183,-1,2,181,0,3221291007,2,158,-1,0,524288,0,2158720,-3,2,155,0,1,-4,2,122,0,3808625411,0,3489628288,0,4096,0,1207959680,0,3221274624,2,0,-3,2,177,0,120,0,7340032,-2,0,4026564608,2,4,2,19,2,160,3,0,4,2,155,-1,2,178,2,175,-1,0,8176,2,179,2,177,2,180,-1,0,4290773232,2,0,-4,2,160,2,187,0,15728640,2,175,-1,2,157,-1,0,4294934512,3,0,4,-9,2,22,2,167,2,181,3,0,4,0,704,0,1849688064,0,4194304,-1,2,122,0,4294901887,2,0,0,130547712,0,1879048192,0,2080374784,3,0,2,-1,2,182,2,183,-1,0,17829776,0,2025848832,0,4261477888,-2,2,0,-1,0,4286580608,-1,0,29360128,2,184,0,16252928,0,3791388672,2,39,3,0,2,-2,2,193,2,0,-1,2,26,-1,0,66584576,-1,2,189,3,0,9,2,122,3,0,4,-1,2,157,2,158,3,0,5,-2,0,245760,0,2147418112,-1,2,146,2,199,0,4227923456,-1,2,185,2,186,2,22,-2,2,176,0,4292870145,0,262144,2,122,3,0,2,0,1073758848,2,187,-1,0,4227921920,2,188,0,68289024,0,528402016,0,4292927536,3,0,4,-2,0,2483027968,2,0,-2,2,189,3,0,5,-1,2,184,2,160,2,0,-2,0,4227923936,2,63,-1,2,170,2,94,2,0,2,150,2,154,3,0,6,-1,2,175,3,0,3,-2,0,2146959360,3,0,8,-2,2,157,-1,2,190,2,117,-1,2,151,3,0,8,2,191,0,8388608,2,171,2,169,2,183,0,4286578944,3,0,2,0,1152,0,1266679808,2,189,0,576,0,4261707776,2,94,3,0,9,2,151,3,0,8,-28,2,158,3,0,3,-3,0,4292902912,-6,2,96,3,0,85,-33,2,164,3,0,126,-18,2,192,3,0,269,-17,2,151,2,122,0,4294917120,3,0,2,2,19,0,4290822144,-2,0,67174336,0,520093700,2,17,3,0,21,-2,2,177,3,0,3,-2,0,65504,2,122,2,49,3,0,2,2,92,-191,2,123,-23,2,26,3,0,296,-8,2,122,3,0,2,2,19,-11,2,175,3,0,72,-3,0,3758159872,0,201391616,3,0,155,-7,2,167,-1,0,384,-1,0,133693440,-3,2,193,-2,2,30,3,0,4,2,166,-2,2,22,2,151,3,0,4,-2,2,185,-1,2,146,0,335552923,2,194,-1,0,538974272,0,2214592512,0,132e3,-10,0,192,-8,0,12288,-21,0,134213632,0,4294901761,3,0,42,0,100663424,0,4294965284,3,0,62,-6,0,4286578784,2,0,-2,0,1006696448,3,0,24,2,37,-1,2,195,3,0,10,2,194,0,4110942569,0,1432950139,0,2701658217,0,4026532864,0,4026532881,2,0,2,47,3,0,8,-1,2,154,-2,2,166,0,98304,0,65537,2,167,2,169,-2,2,154,-1,2,63,2,0,2,116,2,197,2,175,0,4294770176,2,30,3,0,4,-30,2,195,2,196,-3,2,166,-2,2,151,2,0,2,154,-1,2,189,-1,2,157,2,198,3,0,2,2,154,2,122,-1,0,193331200,-1,0,4227923960,2,197,-1,3,0,3,2,198,3,0,44,-1334,2,22,2,0,-129,2,195,-6,2,160,-180,2,199,-233,2,4,3,0,96,-16,2,160,3,0,22583,-7,2,17,3,0,6128],[4294967295,4294967291,4092460543,4294828015,4294967294,134217726,268435455,2147483647,1048575,1073741823,3892314111,1061158911,536805376,4294910143,4160749567,4294901759,134217727,4294901760,4194303,65535,262143,67108863,4286578688,536870911,8388607,4294918143,4294443008,255,67043328,2281701374,4294967232,2097151,4294903807,4294902783,4294967039,511,524287,131071,127,4294902271,4294549487,16777215,1023,67047423,4294901888,33554431,4286578687,4294770687,67043583,32767,15,2047999,4292870143,4294934527,4294966783,67045375,4294967279,262083,20511,4290772991,41943039,493567,2047,4294959104,1071644671,602799615,65536,4294828e3,805044223,4277151126,8191,1031749119,4294917631,2134769663,4286578493,4282253311,4294942719,33540095,4294905855,4294967264,2868854591,1608515583,265232348,534519807,2147614720,1060109444,4093640016,17376,2139062143,224,4169138175,4294909951,4294967292,4294965759,4294966272,4294901823,4294967280,8289918,4294934399,4294901775,4294965375,1602223615,4294967259,268369920,4292804608,486341884,4294963199,3087007615,1073692671,4128527,4279238655,4294902015,4294966591,2445279231,3670015,3238002687,63,4294967288,4294705151,4095,3221208447,4294549472,2147483648,4294705152,4294966143,64,4294966719,16383,3774873592,536807423,67043839,3758096383,3959414372,3755993023,2080374783,4294835295,4294967103,4160749565,4087,31,184024726,2862017156,1593309078,268434431,268434414,4294901763,536870912,2952790016,202506752,139264,402653184,4261412864,4227922944,2147532800,61440,3758096384,117440512,65280,4227858432,3233808384,3221225472,4294965248,32768,57152,4294934528,67108864,4293918720,4290772992,25165824,57344,4278190080,65472,4227907584,65520,1920,4026531840,49152,4160749568,4294836224,63488,1073741824,4294967040,251658240,196608,12582912,2097152,65408,64512,417808,4227923712,48,512,4294967168,4294966784,16,4292870144,4227915776,65528,4294950912,65532]);function d(e){const{index:t}=e,n=e.source.charCodeAt(t);if(n<55296||n>56319)return n;const r=e.source.charCodeAt(t+1);return r<56320||r>57343?n:65536+((1023&n)<<10)|1023&r}const f=e=>0!=(1&s[e])||c(e);function m(e){switch(e){case 0:return"\\0";case 8:return"\\b";case 9:return"\\t";case 10:return"\\n";case 11:return"\\v";case 12:return"\\f";case 13:return"\\r";default:return u(e)?e<16?`\\x0${e.toString(16)}`:e<256?`\\x${e.toString(16)}`:e<4096?`\\u0${e.toString(16)}`:e<65536?`\\u${e.toString(16)}`:`\\u{${e.toString(16)}}`:x(e)}}function w(e,t){return e.source.charCodeAt(e.index)===t&&(e.index++,e.column++,!0)}function g(e,t){e.flags|=ft.NewLine,e.index++,0==(t>.LastIsCR)&&(e.column=0,e.line++)}function y(e,t){return t&dt.InClass&&l(e.source.charCodeAt(e.index))||un(e,1,o(e.token)),115}function h(e){e.flags|=ft.NewLine,e.index++,e.column=0,e.line++}const x=e=>e<=65535?String.fromCharCode(e):String.fromCharCode(55296+(e-65536>>10),56320+(e-65536&1023));function k(e){return e.index++,e.column++,e.index>=e.source.length&&un(e,14),d(e)}function S(e){return e<48?-1:e<=57?e-48:e<65?-1:e<=70?e-65+10:e<97?-1:e<=102?e-97+10:-1}function E(e,t){e.index++,e.column++,t>65535&&e.index++}function v(e,t,n){switch(n){case 98:return 8;case 102:return 12;case 114:return 13;case 110:return 10;case 116:return 9;case 118:return 11;case 13:case 10:case 8232:case 8233:return e.column=-1,e.line++,xt.Empty;case 48:case 49:case 50:case 51:{let r=n-48,o=e.index+1,a=e.column+1,i=e.source.charCodeAt(o);if(i<48||i>55){if(0!==r||56===i||57===i){if(t&dt.Strict)return xt.StrictOctal;e.flags|=ft.HasOctal}}else{if(t&dt.Strict)return xt.StrictOctal;e.flags|=ft.HasOctal,e.lastValue=i,r=8*r+(i-48),o++,a++,i=e.source.charCodeAt(o),i>=48&&i<=55&&(e.lastValue=i,r=8*r+(i-48),o++,a++),e.index=o-1,e.column=a-1}return r}case 52:case 53:case 54:case 55:{if(t&dt.Strict)return xt.StrictOctal;let r=n-48;const o=e.index+1,a=e.column+1,i=e.source.charCodeAt(o);return i>=48&&i<=55&&(r=8*r+(i-48),e.lastValue=i,e.index=o,e.column=a),r}case 56:case 57:return xt.EightOrNine;case 120:{const t=S(e.lastValue=k(e));if(t<0)return xt.InvalidHex;const n=S(e.lastValue=k(e));return n<0?xt.InvalidHex:t<<4|n}case 117:{let t=e.lastValue=k(e);if(123===t){t=e.lastValue=k(e);let n=S(t);if(n<0)return xt.InvalidHex;for(t=e.lastValue=k(e);125!==t;){const r=S(t);if(r<0)return xt.InvalidHex;if(n=16*n+r,n>1114111)return xt.OutOfRange;t=e.lastValue=k(e)}return n}{let n=S(t);if(n<0)return xt.InvalidHex;for(let r=0;r<3;r++){t=e.lastValue=k(e);const r=S(t);if(r<0)return xt.InvalidHex;n=16*n+r}return n}}default:return e.source.charCodeAt(e.index)}}function b(e,t,n){switch(n){case xt.Empty:return;case xt.StrictOctal:un(e,t&dt.TaggedTemplate?76:11);case xt.EightOrNine:un(e,13);case xt.InvalidHex:un(e,75,"hexadecimal");case xt.OutOfRange:un(e,14)}}function A(e,t,n){const{index:r,lastValue:o}=e;let a="";e.index++,e.column++;let i=e.source.charCodeAt(e.index);for(;i!==n;){switch(i){case 13:case 10:un(e,6);case 92:if(i=k(e),i>128)a+=x(i);else{e.lastValue=i;const n=v(e,t,i);n>=0?a+=x(n):b(e,t,n),i=e.lastValue}break;default:a+=x(i)}i=k(e)}return e.index++,e.column++,e.tokenRaw=e.source.slice(r,e.index),e.tokenValue=a,e.lastValue=o,33554435}function I(e,t){return e.index>=e.length&&un(e,9),e.index--,e.column--,C(e,t)}function C(e,t){const{index:n,lastValue:r}=e;let o=!0,a="",i=k(e);e:for(;96!==i;){switch(i){case 36:{const t=e.index+1;if(t=128)a+=x(i);else{e.lastValue=i;const n=v(e,t|dt.Strict,i);if(n>=0)a+=x(n);else{if(n!==xt.Empty&&t&dt.TaggedTemplate){a=void 0,i=O(e,e.lastValue),i<0&&(o=!1);break e}b(e,t|dt.TaggedTemplate,n)}i=e.lastValue}break;case 13:case 10:case 8232:case 8233:e.column=-1,e.line++;default:null!=a&&(a+=x(i))}i=k(e)}return e.index++,e.column++,e.tokenValue=a,e.lastValue=r,o?(e.tokenRaw=e.source.slice(n+1,e.index-1),33554441):(e.tokenRaw=e.source.slice(n+1,e.index-2),33554440)}function O(e,t){for(;96!==t;){if(36===t&&123===e.source.charCodeAt(e.index+1))return e.index++,e.column++,-t;t=k(e)}return t}function L(e,t){e.index++,e.column++;let n=wt.None,r=S(e.source.charCodeAt(e.index));for(r<0&&un(e,0),e.index++,e.column++;e.index=48&&r<=57)||s>=n)break;a=a*n+s,e.index++,e.column++,o++}return 0===o&&un(e,0),i&wt.SeenSeparator&&un(e,59),T(e,t,a,w(e,110))}function N(e,t){switch(e.source.charCodeAt(e.index)){case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:{t&dt.Strict&&un(e,0);let n=e.index,r=e.column,o=0;for(e.flags|=ft.HasOctal;n55)return P(e,t);o=8*o+(a-48),n++,r++}}return e.index=n,e.column=r,T(e,t,o,w(e,110))}case 56:case 57:e.flags|=ft.HasOctal;default:return t&dt.OptionsNext&&95===e.source.charCodeAt(e.index)&&un(e,60),P(e,t)}}function _(e,t){let n=e.source.charCodeAt(e.index);43!==n&&45!==n||(e.index++,e.column++,n=e.source.charCodeAt(e.index)),n>=48&&n<=57||un(e,0);const r=e.index,o=M(e);return e.source.substring(t,r)+o}function P(e,t,n=wt.None){let r=n&wt.Float?0:H(e,t);const o=e.source.charCodeAt(e.index);if(46!==o&&95!==o&&!l(o))return T(e,t,r);w(e,46)&&(t&dt.OptionsNext&&95===e.source.charCodeAt(e.index)&&un(e,60),n|=wt.Float,r=`${r}.${M(e)}`);const a=e.index;return w(e,110)&&(n&wt.Float&&un(e,0),n|=wt.BigInt),(w(e,101)||w(e,69))&&(n|=wt.Float,r+=_(e,a)),l(e.source.charCodeAt(e.index))&&un(e,0),T(e,t,n&wt.Float?parseFloat(r):parseInt(r,10),!!(n&wt.BigInt))}function R(e,t){return e.index++,e.column++,t&wt.SeenSeparator&&un(e,59),t|wt.SeenSeparator}function M(e){let t=e.index,n=wt.None,r="";e:for(;e.index=48&&o<=57||95===o;)t&dt.OptionsNext&&95===o?(n=R(e,n),o=e.source.charCodeAt(e.index)):(n&=~wt.SeenSeparator,r=10*r+(o-48),e.index++,e.column++,o=e.source.charCodeAt(e.index));return n&wt.SeenSeparator&&un(e,59),r}function T(e,t,n,r=!1){return e.tokenValue=n,t&dt.OptionsRaw&&(e.tokenRaw=e.source.slice(e.startIndex,e.index)),r?33554551:33554434}function F(e,t,n){let r=e.index,o="",a=!1;n&&E(e,n);e:for(;e.index=55296&&n<=56319&&(n=(1023&n)<<10|1023&e.source.charCodeAt(t+1)|65536),!f(n))break e;E(e,n)}}r=2&&s<=11){const n=i(o);if(n>0)return a&&(t&dt.DisallowEscapedKeyword&&pn(e,t,3),e.flags|=ft.EscapedKeyword),n}return t&dt.OptionsRawidentifiers&&(e.tokenRaw=e.source.slice(r,e.index)),33685505}function B(e,t,n){return l(n=d(e))||un(e,10,m(n)),F(e,t,n)}function V(e){const{index:t}=e;if(t+5=0;)n=n<<4|r,n>1114111&&un(e,89),e.index++,e.column++,r=S(e.source.charCodeAt(e.index));125!==e.source.charCodeAt(e.index)&&un(e,75,"unicode"),w(e,125)}else for(let r=0;r<4;r++){t=e.source.charCodeAt(e.index);const r=S(t);r<0&&un(e,75,"unicode"),n=n<<4|r,e.index++,e.column++}return n}(e);return n>=55296&&n<=56319&&un(e,74),f(n)||un(e,75,"unicode"),x(n)}un(e,0)}function X(e,t,n,r){return t&dt.Module&&un(e,90),J(e,t,n,r)}function J(e,t,n,r){const o=e.index,a=!!(t&dt.OptionsComments);for(;e.index128)switch(o){case 8232:case 8233:r=r&~gt.LastIsCR|gt.NewLine,h(e);break;case 65519:case 160:case 5760:case 8192:case 8193:case 8194:case 8195:case 8196:case 8197:case 8198:case 8199:case 8200:case 8201:case 8202:case 8239:case 8287:case 12288:case 65279:case 8205:e.index++,e.column++;break;default:return B(e,t,o)}else switch(o){case 13:r|=gt.NewLine|gt.LastIsCR,h(e);break;case 10:g(e,r),r=r&~gt.LastIsCR|gt.NewLine;break;case 9:case 11:case 12:case 32:e.index++,e.column++;break;case 40:return e.index++,e.column++,50331659;case 41:return e.index++,e.column++,16;case 44:return e.index++,e.column++,16777234;case 58:return e.index++,e.column++,16777237;case 59:return e.index++,e.column++,17825809;case 63:return e.index++,e.column++,22;case 93:return e.index++,e.column++,20;case 123:return e.index++,e.column++,41943052;case 125:return e.index++,e.column++,17825807;case 126:return e.index++,e.column++,301989934;case 91:return e.index++,e.column++,41943059;case 64:return e.index++,e.column++,120;case 47:if(e.index++,e.column++,e.index>=e.length)return 167774773;switch(e.source.charCodeAt(e.index)){case 47:e.index++,e.column++,r=J(e,t,r,"SingleLine");continue;case 42:e.index++,e.column++,r=q(e,t,r);continue;case 61:return e.index++,e.column++,100663333;default:return 167774773}case 45:switch(e.index++,e.column++,e.source.charCodeAt(e.index)){case 45:if(e.index++,e.column++,(r>.NewLine||n)&&w(e,62)){r=X(e,t,r,"HTMLClose");continue}return 570425372;case 61:return e.index++,e.column++,67108899;default:return 436209968}case 60:if(e.index++,e.column++,w(e,33)&&w(e,45)&&w(e,45)){r=X(e,t,r,"HTMLOpen");continue}switch(e.source.charCodeAt(e.index)){case 60:return e.index++,e.column++,w(e,61)?67108894:167774273;case 61:return e.index++,e.column++,167774013;case 47:{if(!(t&dt.OptionsJSX))break;const n=e.index+1;if(n=e.length)return 167774771;const t=e.source.charCodeAt(e.index);return 61===t?(e.index++,e.column++,67108900):42!==t?167774771:(e.index++,e.column++,w(e,61)?67108897:167775030)}case 43:{if(e.index++,e.column++,e.index>=e.length)return 436209967;const t=e.source.charCodeAt(e.index);return 43===t?(e.index++,e.column++,570425371):61===t?(e.index++,e.column++,67108898):436209967}case 92:return F(e,t);case 61:{e.index++,e.column++;const t=e.source.charCodeAt(e.index);return 61===t?(e.index++,e.column++,w(e,61)?167773753:167773755):62===t?(e.index++,e.column++,10):83886109}case 62:{if(e.index++,e.column++,e.index>=e.length)return 167774016;if(t&dt.InJSXChild)return 167774016;let n=e.source.charCodeAt(e.index);return 61===n?(e.index++,e.column++,167774014):62!==n?167774016:(e.index++,e.column++,n=e.source.charCodeAt(e.index),62===n?(e.index++,e.column++,w(e,61)?67108896:167774275):61===n?(e.index++,e.column++,67108895):167774274)}case 94:return e.index++,e.column++,w(e,61)?67108903:167773254;case 96:return C(e,t);case 124:{e.index++,e.column++;const t=e.source.charCodeAt(e.index);return 124===t?(e.index++,e.column++,169869624):61===t?(e.index++,e.column++,67108904):167772997}case 46:{let n=e.index+1;const r=e.source.charCodeAt(n);return r>=48&&r<=57?(P(e,t,wt.Float),33554434):46===r&&(n++,n=e.source.length&&un(e,7)}const o=e.index-1;let a=kt.Empty;const{index:i}=e;e:for(;e.index=e.source.length)return 1048576;e.lastIndex=e.startIndex=e.index;const t=e.source.charCodeAt(e.index);if(60===t)return e.index++,e.column++,w(e,47)?25:167774015;if(123===t)return e.index++,e.column++,41943052;for(;e.index=e.source.length&&un(e,6);return e.index++,e.column++,t&dt.OptionsRaw&&(e.tokenRaw=e.source.slice(r,e.index)),e.tokenValue=o,33554435}(e,t,n);default:return Nt(e,t)}}(e,t)){case 33554435:return He(e,t);case 41943052:return we(e,t|dt.InJSXChild);case 167774015:return ee(e,t|dt.InJSXChild);default:return void pn(e,t,87)}}function de(e,t){const n=Xt(e);if(41943052===e.token)return ce(e,t);Ee(e);const r=ue(e,t);return Ot(t,e,n,{type:"JSXAttribute",value:83886109===e.token?pe(e,t):null,name:r})}function fe(e,t){return Ot(t,e,Xt(e),{type:"JSXEmptyExpression"})}function me(e,t){const n=Xt(e);Lt(e,t,14);const r=ve(e,t);return Lt(e,t,17825807),Ot(t,e,n,{type:"JSXSpreadChild",expression:r})}function we(e,t){const n=Xt(e);Lt(e,t,41943052),17825807===e.token&&pn(e,t,84);const r=Rt(e,t&~dt.InJSXChild,Ae);return Lt(e,t,17825807),Ot(t,e,n,{type:"JSXExpressionContainer",expression:r})}function ge(e,t){const n=Xt(e);if(Lt(e,t,41943052),14===e.token)return me(e,t);const r=17825807===e.token?fe(e,t):Rt(e,t,Ae);return ne(e),Ot(t,e,n,{type:"JSXExpressionContainer",expression:r})}function ye(e,t){const n=Xt(e);return Lt(e,t,25),Lt(e,t,167774016),Ot(t,e,n,{type:"JSXClosingFragment"})}function he(e,t){const n=Xt(e);Lt(e,t,25);const r=Se(e,t);return t&dt.InJSXChild?Lt(e,t,167774016):ne(e),Ot(t,e,n,{type:"JSXClosingElement",name:r})}function xe(e,t){const{token:n,tokenValue:r,tokenRaw:a}=e;135168&n||pn(e,t,1,o(e.token));const i=Xt(e);Nt(e,t);const s=Ot(t,e,i,{type:"JSXIdentifier",name:r});return t&dt.OptionsRawidentifiers&&(s.raw=a),s}function ke(e,t,n,r){return Ee(e),Ot(t,e,r,{type:"JSXMemberExpression",object:n,property:xe(e,t)})}function Se(e,t){const n=Xt(e);Ee(e);let r=xe(e,t);if(16777237===e.token)return le(e,t,r,n);for(;Dt(e,t,16777229);)r=ke(e,t,r,n);return r}function Ee(e){const{token:t}=e;if(135168&t){const t=e.index;let n=e.source.charCodeAt(e.index);for(;e.index"),Lt(e,t,10),$e(e,t&~dt.Async,r,n,yt.None)}(e,t&=~dt.Async,n,a);if(_t(e.token,67108864)){r=e.token,t&dt.Strict&&Wt(a.name)?pn(e,t,17):Dt(e,t,83886109)?(e.flags&ft.AllowDestructuring||pn(e,t,73),t&dt.InParameter||Ft(e,t,a),t&dt.InParen&&(e.flags|=ft.SimpleParameterList),262144&e.token?(Qt(e),e.flags|=ft.HasAwait):t&dt.InParen&&t&(dt.Strict|dt.Yield)&&1073741824&e.token&&(Qt(e),e.flags|=ft.HasYield)):(Vt(a)||pn(e,t,5),e.flags&=~(ft.AllowDestructuring|ft.AllowBinding),Nt(e,t));const i=Rt(e,t|dt.AllowIn,Ae);return e.pendingExpressionError=null,Ot(t,e,n,{type:"AssignmentExpression",left:a,operator:o(r),right:i})}return a}function Ie(e,t,n,r,a=Ce(e,t)){const i=t&dt.AllowIn^dt.AllowIn;for(;_t(e.token,167772160);){const s=e.token,c=3840&s,l=(167775030===s)<<8;if(i&&167786289===s)break;if(c+l<=n)break;Nt(e,t),a=Ot(t,e,r,{type:2097152&s?"LogicalExpression":"BinaryExpression",left:a,right:Ie(e,t&~dt.AllowIn,c,Xt(e)),operator:o(s)})}return a}function Ce(e,t){const n=Xt(e),{token:r}=e;if(_t(r,301989888)){Nt(e,t),e.flags&ft.EscapedKeyword&&pn(e,t,3);const a=Rt(e,t,Ce);return 167775030===e.token&&pn(e,t,1,o(e.token)),t&dt.Strict&&302002219===r&&("Identifier"===a.type?pn(e,t,43):$t(a)&&pn(e,t,44)),Ot(t,e,n,{type:"UnaryExpression",operator:o(r),argument:a,prefix:!0})}return t&dt.Async&&262144&r?function(e,t,n){return t&dt.InParameter&&pn(e,t,52),Lt(e,t,34017389),Ot(t,e,n,{type:"AwaitExpression",argument:Ce(e,t)})}(e,t,n):function(e,t,n){const{token:r}=e;if(_t(e.token,570425344)){Nt(e,t);const a=De(e,t,n);return tn(e,t,a,"Prefix"),Ot(t,e,n,{type:"UpdateExpression",argument:a,operator:o(r),prefix:!0})}if(t&dt.OptionsJSX&&167774015===r)return ee(e,t|dt.InJSXChild);const a=De(e,t,n);if(_t(e.token,570425344)&&!(e.flags&ft.NewLine)){tn(e,t,a,"Postfix");const r=e.token;return Nt(e,t),Ot(t,e,n,{type:"UpdateExpression",argument:a,operator:o(r),prefix:!1})}return a}(e,t,n)}function Oe(e,t,n=[]){const r=Xt(e);return Lt(e,t,14),t&dt.InParen&&262144&e.token&&(e.flags|=ft.HasAwait),Ot(t,e,r,{type:"RestElement",argument:Y(e,t,n)})}function Le(e,t){const n=Xt(e);return Lt(e,t,14),Ot(t,e,n,{type:"SpreadElement",argument:Mt(e,t|dt.AllowIn,Ae)})}function De(e,t,n){const r=t&dt.OptionsNext&&33566810===e.token?ot(e,t|dt.AllowIn):Ne(e,t|dt.AllowIn,n);return function(e,t,n,r){for(;;){if(r=Ne(e,t,n,r),50331659!==e.token)return r;r=Ot(t,e,n,{type:"CallExpression",callee:r,arguments:_e(e,t&~dt.AllowDecorator)})}}(e,t|dt.AllowIn,n,r)}function Ne(e,t,n,r=Re(e,t)){for(;;)switch(e.token){case 16777229:Dt(e,t,16777229),e.flags=e.flags&~ft.AllowBinding|ft.AllowDestructuring,r=Ot(t,e,n,{type:"MemberExpression",object:r,computed:!1,property:Be(e,t)});continue;case 41943059:{Dt(e,t,41943059),e.flags=e.flags&~ft.AllowBinding|ft.AllowDestructuring;const o=ve(e,t);Lt(e,t,20),r=Ot(t,e,n,{type:"MemberExpression",object:r,computed:!0,property:o});continue}case 33554441:r=Ot(t,e,n,{type:"TaggedTemplateExpression",tag:r,quasi:st(e,t)});continue;case 33554440:r=Ot(t,e,n,{type:"TaggedTemplateExpression",tag:r,quasi:ct(e,t|dt.TaggedTemplate)});continue;default:return r}}function _e(e,t){Lt(e,t,50331659);const n=[];for(;16!==e.token;)14===e.token?n.push(Le(e,t)):(t&dt.Yield&&_t(e.token,1073741824)&&(e.flags|=ft.HasYield,Qt(e)),n.push(Rt(e,t|dt.AllowIn,Ae))),16!==e.token&&Lt(e,t,16777234);return Lt(e,t,16),n}function Pe(e,t){Lt(e,t,50331659);const n=[];let{token:r}=e,o=St.Empty;for(;16!==e.token&&(14===e.token?(e.flags|=ft.SimpleParameterList,n.push(Le(e,t)),o=St.HasSpread):(r=e.token,o=on(e,t,o),n.push(Mt(e,t|dt.AllowIn,Ae))),Dt(e,t,16777234)&&(e.flags&=~ft.AllowDestructuring,o&St.HasSpread&&(o=St.SeenSpread)),16!==e.token););return Lt(e,t,16),10===e.token&&(o&St.SeenSpread?pn(e,t,78):o&St.EvalOrArguments?(t&dt.Strict&&pn(e,t,47),e.flags|=ft.StrictEvalArguments):o&St.Yield?(t&dt.Strict&&pn(e,t,51),e.flags|=ft.HasStrictReserved):e.flags&ft.HasYield?pn(e,t,51):(o&St.Await||e.flags&ft.HasAwait)&&pn(e,t,52)),n}function Re(e,t){switch(e.token){case 33685505:return Me(e,t);case 33554434:case 33554435:return He(e,t);case 594028:return function(e,t){return Bt(e,t,Ut)?Je(e,t):Me(e,t)}(e,t);case 50331659:return function(e,t){if(Lt(e,t,50331659),Dt(e,t,16)){if(e.flags&=~(ft.AllowDestructuring|ft.AllowBinding),10===e.token)return[]}else if(14===e.token){const n=[Oe(e,t)];return Lt(e,t,16),e.flags=e.flags&~(ft.AllowDestructuring|ft.AllowBinding)|ft.SimpleParameterList,10!==e.token&&pn(e,t,1,o(e.token)),n}const n=Xt(e);let r=rn(e,ht.None),a=Mt(e,t|dt.AllowIn,Ae);if(16777234===e.token){r|=ht.SequenceExpression;const i=[a];for(;Dt(e,t|dt.DisallowEscapedKeyword,16777234);){if(14===e.token){e.flags&ft.AllowBinding||pn(e,t,77),e.flags|=ft.SimpleParameterList;const n=Oe(e,t);return Lt(e,t,16),10!==e.token&&pn(e,t,78),i.push(n),i}if(Dt(e,t,16))return 10!==e.token&&pn(e,t,1,o(e.token)),i;r=rn(e,r),i.push(Mt(e,t,Ae))}a=Ot(t,e,n,{type:"SequenceExpression",expressions:i})}return Lt(e,t,16),10===e.token?(r&ht.HasEvalOrArguments?(t&dt.Strict&&pn(e,t,47),e.flags|=ft.StrictEvalArguments):r&ht.HasReservedWords?(t&dt.Strict&&pn(e,t,50),e.flags|=ft.HasStrictReserved):e.flags&ft.AllowBinding?e.flags&ft.HasYield?pn(e,t,51):t&dt.Async&&e.flags&ft.HasAwait&&pn(e,t,52):pn(e,t,77),e.flags&=~(ft.AllowBinding|ft.HasAwait|ft.HasYield),r&ht.SequenceExpression?a.expressions:[a]):(e.flags&=~(ft.HasAwait|ft.HasYield|ft.AllowBinding),Vt(a)||(e.flags&=~ft.AllowDestructuring),a)}(e,t|dt.InParen);case 41943059:return Mt(e,t,Ve);case 41943052:return Mt(e,t,je);case 33566808:return Xe(e,t);case 33566727:case 33566726:case 33566725:return function(e,t){const n=Xt(e),{token:r}=e,a=o(r);e.flags&ft.EscapedKeyword&&pn(e,t,3),Nt(e,t);const i=Ot(t,e,n,{type:"Literal",value:33566727===r?null:"true"===a});return t&dt.OptionsRaw&&(i.raw=a),i}(e,t);case 120:case 33566797:return function(e,t){const n=Xt(e);let r=[];t&dt.OptionsExperimental&&(r=pt(e,t)),Lt(e,t|dt.DisallowEscapedKeyword,33566797);const{token:o}=e;let a=vt.None,i=null,s=null;41943052!==o&&12372!==o&&(t&dt.Async&&262144&o&&pn(e,t,48),i=U(e,t|dt.Strict)),Dt(e,t,12372)&&(s=De(e,t|dt.Strict,n),a|=vt.Heritage);const c=et(e,t|dt.Strict,a);return Ot(t,e,n,t&dt.OptionsExperimental?{type:"ClassExpression",id:i,superClass:s,body:c,decorators:r}:{type:"ClassExpression",id:i,superClass:s,body:c})}(e,t);case 33566811:return function(e,t){const n=Xt(e),r=Me(e,t);return Dt(e,t|dt.DisallowEscapedKeyword,16777229)?("target"===e.tokenValue&&t&(dt.InParameter|dt.InFunctionBody)||pn(e,t,53),at(e,t,r,n)):Ot(t,e,n,{type:"NewExpression",callee:it(e,t,n),arguments:50331659===e.token?_e(e,t):[]})}(e,t);case 33566813:return function(e,t){const n=Xt(e);switch(Lt(e,t,33566813),e.token){case 50331659:t&dt.AllowSuperProperty||pn(e,t,54);break;case 41943059:case 16777229:t&dt.Method||pn(e,t,55);break;default:pn(e,t,56)}return Ot(t,e,n,{type:"Super"})}(e,t);case 33554551:return Te(e,t);case 33566815:return function(e,t){e.flags&ft.EscapedKeyword&&pn(e,t,3);const n=Xt(e);return Nt(e,t|dt.DisallowEscapedKeyword),Ot(t,e,n,{type:"ThisExpression"})}(e,t);case 115:return Be(e,t);case 167774773:case 100663333:return K(e,t),function(e,t){const n=Xt(e),{tokenRegExp:r,tokenValue:o,tokenRaw:a}=e;Nt(e,t);const i=Ot(t,e,n,{type:"Literal",value:o,regex:r});return t&dt.OptionsRaw&&(i.raw=a),i}(e,t);case 33554441:return st(e,t);case 33554440:return ct(e,t);case 33574984:return function(e,t){t&dt.Strict&&pn(e,t,50);const n=Xt(e),r=e.tokenValue;return Nt(e,t),e.flags&ft.NewLine&&41943059===e.token&&pn(e,t,1,"let"),Ot(t,e,n,{type:"Identifier",name:r})}(e,t);case 12369:if(t&dt.OptionsExperimental)return function(e,t){const n=Xt(e);return Lt(e,t,12369),Ot(t,e,n,{type:"DoExpression",body:Rn(e,t)})}(e,t);default:return zt(e,t)}}function Me(e,t){const n=Xt(e),r=e.tokenValue;Nt(e,t|dt.TaggedTemplate);const o=Ot(t,e,n,{type:"Identifier",name:r});return t&dt.OptionsRawidentifiers&&(o.raw=e.tokenRaw),o}function He(e,t){const n=Xt(e),r=e.tokenValue;t&dt.Strict&&e.flags&ft.HasOctal&&pn(e,t,61),Nt(e,t);const o=Ot(t,e,n,{type:"Literal",value:r});return t&dt.OptionsRaw&&(o.raw=e.tokenRaw),o}function Te(e,t){const n=Xt(e),{tokenValue:r,tokenRaw:o}=e;Nt(e,t);const a=Ot(t,e,n,{type:"Literal",value:r,bigint:o});return t&dt.OptionsRaw&&(a.raw=e.tokenRaw),a}function Fe(e,t,n){return 135168&n||pn(e,t,4,o(n)),Me(e,t)}function Be(e,t){if(!Dt(e,t,115))return Fe(e,t,e.token);const{tokenValue:n}=e,r=Xt(e),o=n;return Nt(e,t),Ot(t,e,r,{type:"PrivateName",name:o})}function Ve(e,t){const n=Xt(e);Lt(e,t,41943059);const r=[];for(;20!==e.token;)Dt(e,t,16777234)?r.push(null):14===e.token?(r.push(Le(e,t)),20!==e.token&&(e.flags&=~(ft.AllowDestructuring|ft.AllowBinding),Lt(e,t,16777234))):(r.push(Mt(e,t|dt.AllowIn,Ae)),20!==e.token&&Lt(e,t,16777234));return Lt(e,t,20),Ot(t,e,n,{type:"ArrayExpression",elements:r})}function Xe(e,t){const n=Xt(e);Lt(e,t,33566808);const r=Dt(e,t,167774771)?yt.Generator:yt.None;let o=null;const{token:a}=e;135168&a&&(4194304&a&&(t&dt.Strict&&pn(e,t,47),e.flags|=ft.StrictEvalArguments),1073741824&e.token&&r&yt.Generator&&pn(e,t,49),o=U(e,t));const{params:i,body:s}=Ht(e,t&~(dt.Method|dt.AllowSuperProperty),r,ze);return Ot(t,e,n,{type:"FunctionExpression",params:i,body:s,async:!1,generator:!!(r&yt.Generator),expression:!1,id:o})}function Je(e,t){const n=Xt(e);Lt(e,t,594028),Lt(e,t,33566808);const r=Dt(e,t,167774771)?yt.Generator:yt.None,o=yt.Await;let a=null;const{token:i}=e;135168&i&&(4194304&i&&((t&dt.Strict||o&yt.Await)&&pn(e,t,47),e.flags|=ft.StrictFunctionName),262144&i&&pn(e,t,48),1073741824&e.token&&r&yt.Generator&&pn(e,t,49),a=U(e,t));const{params:s,body:c}=Ht(e,t&~(dt.Method|dt.AllowSuperProperty),r|o,ze);return Ot(t,e,n,{type:"FunctionExpression",params:s,body:c,async:!0,generator:!!(r&yt.Generator),expression:!1,id:a})}function qe(e,t){switch(e.token){case 33554434:case 33554435:return He(e,t);case 41943059:return function(e,t){Lt(e,t,41943059);const n=Ae(e,t|dt.AllowIn);return Lt(e,t,20),n}(e,t);default:return Me(e,t)}}function Ge(e,t){const n=Xt(e);return Lt(e,t,14),8388608&e.token&&(e.flags&=~ft.AllowDestructuring),Ot(t,e,n,{type:"SpreadElement",argument:Ae(e,t|dt.AllowIn)})}function je(e,t){const n=Xt(e);Lt(e,t,41943052);const r=[];for(;17825807!==e.token;)r.push(14===e.token?Ge(e,t):Ke(e,t)),17825807!==e.token&&Lt(e,t,16777234);return Lt(e,t,17825807),e.flags&=~ft.HasProtoField,Ot(t,e,n,{type:"ObjectExpression",properties:r})}function Ke(e,t){const n=Xt(e),r=e.flags;let a,i=Dt(e,t,167774771)?vt.Generator|vt.Method:vt.Method;const s=e.token;let c=qe(e,t);return 16777216&e.token||(r&ft.EscapedKeyword?pn(e,t,3):i&vt.Generator||!(524288&s)||e.flags&ft.NewLine?69743===s?(i=i&~vt.Method|vt.Getter,c=qe(e,t)):69744===s&&(i=i&~vt.Method|vt.Setter,c=qe(e,t)):(i|=Dt(e,t,167774771)?vt.Generator|vt.Async:vt.Async,c=qe(e,t)),i&(vt.Getter|vt.Setter)&&i&vt.Generator&&pn(e,t,1,o(e.token))),50331659===e.token?a=Ye(e,t,i):(i&=~vt.Method,16777237===e.token?(i&(vt.Async|vt.Generator)?pn(e,t,1,o(e.token)):41943059!==s&&"__proto__"===e.tokenValue&&(e.flags&ft.HasProtoField?nn(e,63):e.flags|=ft.HasProtoField),Lt(e,t,16777237),262144&e.token&&(e.flags|=ft.HasAwait),a=Mt(e,t,Ae)):(i&(vt.Generator|vt.Async)||!Jt(t,s)?pn(e,t,1,o(s)):t&(dt.Strict|dt.Yield)&&1073741824&s&&(Qt(e),e.flags|=ft.HasYield),i|=vt.Shorthand,83886109===e.token?(t&dt.Strict&&4194304&s?un(e,47):nn(e,91),Lt(e,t,83886109),t&(dt.Strict|dt.Yield|dt.Async)&&1074003968&e.token&&(Qt(e),e.flags|=1073741824&e.token?ft.HasYield:ft.HasAwait),a=W(e,t,c,n)):(262144&s&&(t&dt.Async&&pn(e,t,46),Qt(e),e.flags|=ft.HasAwait),a=c))),Ot(t,e,n,{type:"Property",key:c,value:a,kind:i&vt.Getter|i&vt.Setter?i&vt.Setter?"set":"get":"init",computed:41943059===s,method:!!(i&vt.Method),shorthand:!!(i&vt.Shorthand)})}function Ye(e,t,n){const r=Xt(e),o=n&vt.Generator?yt.Generator:yt.None,a=n&vt.Async?yt.Await:yt.None,{params:i,body:s}=Ht(e,t|dt.Method,o|a,ze,n);return Ot(t,e,r,{type:"FunctionExpression",params:i,body:s,async:!!(n&vt.Async),generator:!!(n&vt.Generator),expression:!1,id:null})}function Ue(e,t,n,r,o){return e.flags&=~(ft.AllowDestructuring|ft.AllowBinding),e.flags&ft.NewLine&&pn(e,t,36,"async"),Lt(e,t,10),$e(e,t|dt.Async,o,r,n)}function $e(e,t,n,r,o){e.pendingExpressionError=null;for(const r in n)Ft(e,t|dt.InParameter,n[r]);const a=41943052!==e.token;return Ot(t,e,r,{type:"ArrowFunctionExpression",body:a?Rt(e,t&~(dt.Yield|dt.InParameter),Ae):Ht(e,t&~(dt.Yield|dt.AllowDecorator)|dt.InFunctionBody,o,We),params:n,id:null,async:!!(o&yt.Await),generator:!1,expression:a})}function ze(e,t,n){const r=Qe(e,t|dt.InParameter,n),o=r.args;return{params:r.params,body:We(e,t&~dt.AllowDecorator|dt.InFunctionBody,o)}}function We(e,t,n){const r=Xt(e);Lt(e,t|dt.DisallowEscapedKeyword,41943052);const o=[];for(;33554435===e.token;){const{tokenRaw:n,tokenValue:r}=e;o.push(Dn(e,t)),12===n.length&&"use strict"===r&&(e.flags&ft.SimpleParameterList?pn(e,t,64):e.flags&(ft.HasStrictReserved|ft.StrictFunctionName)?pn(e,t,50):e.flags&ft.StrictEvalArguments&&pn(e,t,47),t|=dt.Strict)}t&dt.Strict&&Tt(e,t,n);const{labelSet:a}=e;e.labelSet={};const i=e.flags;for(e.flags=e.flags&~(ft.StrictFunctionName|ft.StrictEvalArguments|ft.InSwitchStatement|ft.InIterationStatement)|ft.AllowDestructuring;17825807!==e.token;)o.push(hn(e,t));return i&ft.InIterationStatement&&(e.flags|=ft.InIterationStatement),i&ft.InSwitchStatement&&(e.flags|=ft.InSwitchStatement),e.labelSet=a,Lt(e,t,17825807),Ot(t,e,r,{type:"BlockStatement",body:o})}function Qe(e,t,n){Lt(e,t,50331659),e.flags&=~(ft.SimpleParameterList|ft.HasStrictReserved);const r=[],o=[];for(;16!==e.token;){if(14===e.token){n&vt.Setter&&pn(e,t,67),e.flags|=ft.SimpleParameterList,o.push(Oe(e,t,r));break}if(o.push(Ze(e,t,r)),!Dt(e,t,16777234))break;if(16===e.token)break}return n&vt.Setter&&1!==o.length&&pn(e,t,66,"Setter","one",""),n&vt.Getter&&o.length>0&&pn(e,t,66,"Getter","no","s"),Lt(e,t,16),{params:o,args:r}}function Ze(e,t,n){const r=Xt(e);135168&e.token?(_t(e.token,20480)&&(t&dt.Strict&&pn(e,t,50),e.flags|=ft.StrictFunctionName),_t(e.token,4194304)&&(t&dt.Strict&&pn(e,t,47),e.flags|=ft.StrictEvalArguments)):e.flags|=ft.SimpleParameterList;const o=Y(e,t,n);return Dt(e,t,83886109)?(1074003968&e.token&&t&(dt.Yield|dt.Async)&&pn(e,t,262144&e.token?52:51),e.flags|=ft.SimpleParameterList,Ot(t,e,r,{type:"AssignmentPattern",left:o,right:Rt(e,t,Ae)})):o}function et(e,t,n){const r=Xt(e);Lt(e,t,41943052);const o=[];let a=[];for(;17825807!==e.token;)Dt(e,t,17825809)||(t&dt.OptionsExperimental&&(a=pt(e,t),17825807===e.token&&un(e,92),0!==a.length&&"constructor"===e.tokenValue&&un(e,93)),o.push(t&dt.OptionsNext&&115===e.token?rt(e,t,a):tt(e,t,n,a)));return e.flags&=~ft.HasConstructor,Lt(e,t,17825807),Ot(t,e,r,{type:"ClassBody",body:o})}function tt(e,t,n,r){const a=Xt(e);let{tokenValue:i,token:s}=e;const c=e.flags;Dt(e,t,167774771)&&(n|=vt.Generator),41943059===e.token&&(n|=vt.Computed),"constructor"===e.tokenValue&&(n&vt.Generator?pn(e,t,45,"generator"):n&vt.Heritage&&(t|=dt.AllowSuperProperty),n|=vt.Constructor);let l,u=qe(e,t);if(!(16777216&e.token)){if(c&ft.EscapedKeyword&&pn(e,t,3),20585===s&&(s=e.token,Dt(e,t,167774771)&&(n|=vt.Generator),i=e.tokenValue,41943059===e.token&&(n|=vt.Computed),"prototype"===e.tokenValue&&pn(e,t,65),n|=vt.Static,u=qe(e,t),t&dt.OptionsNext&&en(e)))return"constructor"===i&&pn(e,t,1,o(e.token)),nt(e,t,u,n,a,r);50331659!==e.token&&(!(524288&s)||n&vt.Generator||e.flags&ft.NewLine?69743!==s&&69744!==s||(n|=69743===s?vt.Getter:vt.Setter,i=e.tokenValue,41943059===e.token&&(n|=vt.Computed),u=qe(e,t&~dt.Strict)):(s=e.token,i=e.tokenValue,n|=vt.Async,Dt(e,t,167774771)&&(n|=vt.Generator),41943059===e.token&&(n|=vt.Computed),u=qe(e,t)),"prototype"===i?pn(e,t,65):n&vt.Static||"constructor"!==i||pn(e,t,45,"accessor"))}if(50331659===e.token)!(n&vt.Computed)&&n&vt.Constructor&&(e.flags&ft.HasConstructor?un(e,12):e.flags|=ft.HasConstructor),l=Ye(e,t,n);else{if(t&dt.OptionsNext)return nt(e,t,u,n,a,r);pn(e,t,1,o(s))}const p=n&vt.Constructor?"constructor":n&vt.Getter?"get":n&vt.Setter?"set":"method";return Ot(t,e,a,t&dt.OptionsExperimental?{type:"MethodDefinition",kind:p,static:!!(n&vt.Static),computed:!!(n&vt.Computed),key:u,value:l,decorators:r}:{type:"MethodDefinition",kind:p,static:!!(n&vt.Static),computed:!!(n&vt.Computed),key:u,value:l})}function nt(e,t,n,r,o,a){r&vt.Constructor&&pn(e,t,0);let i=null;return r&(vt.Async|vt.Generator)&&pn(e,t,0),Dt(e,t,83886109)&&(4194304&e.token&&pn(e,t,47),i=Ae(e,t)),Dt(e,t,16777234),Ot(t,e,o,t&dt.OptionsExperimental?{type:"FieldDefinition",key:n,value:i,computed:!!(r&vt.Computed),static:!!(r&vt.Static),decorators:a}:{type:"FieldDefinition",key:n,value:i,computed:!!(r&vt.Computed),static:!!(r&vt.Static)})}function rt(e,t,n){const r=Xt(e);Lt(e,t|dt.InClass,115),"constructor"===e.tokenValue&&pn(e,t,41);const o=function(e,t,n){const r=e.tokenValue;return Nt(e,t),Ot(t,e,n,{type:"PrivateName",name:r})}(e,t,r);if(50331659===e.token)return function(e,t,n,r,o){const a=Ye(e,t|dt.Strict,vt.None);return e.flags&=~(ft.AllowDestructuring|ft.AllowBinding),Ot(t,e,r,t&dt.OptionsExperimental?{type:"MethodDefinition",kind:"method",static:!1,computed:!1,key:n,value:a,decorators:o}:{type:"MethodDefinition",kind:"method",static:!1,computed:!1,key:n,value:a})}(e,t,o,r,n);let a=null;return Dt(e,t,83886109)&&(4194304&e.token&&pn(e,t,47),a=Ae(e,t)),Dt(e,t,16777234),Ot(t,e,r,t&dt.OptionsExperimental?{type:"FieldDefinition",key:o,value:a,computed:!1,static:!1,decorators:n}:{type:"FieldDefinition",key:o,value:a,computed:!1,static:!1})}function ot(e,t){const n=Xt(e),r=Me(e,t);if(Dt(e,t,16777229)){if(t&dt.Module&&"meta"===e.tokenValue)return at(e,t,r,n);pn(e,t,1,o(e.token))}let a=function(e,t,n){return Ot(t,e,n,{type:"Import"})}(e,t,n);Lt(e,t,50331659);const i=Rt(e,t|dt.AllowIn,Ae);return Lt(e,t,16),a=Ot(t,e,n,{type:"CallExpression",callee:a,arguments:[i]}),a}function at(e,t,n,r){return Ot(t,e,r,{meta:n,type:"MetaProperty",property:Me(e,t)})}function it(e,t,n){const{token:r}=e;return t&dt.OptionsNext&&33566810===r?(Bt(e,t,Yt)&&pn(e,t,1,o(r)),ot(e,t)):Ne(e,t,n)}function st(e,t){return Ot(t,e,Xt(e),{type:"TemplateLiteral",expressions:[],quasis:[lt(e,t)]})}function ct(e,t,n=[],r=[]){const o=Xt(e),{tokenValue:a,tokenRaw:i}=e;Lt(e,t,33554440),n.push(ve(e,t));const s=Xt(e);return r.push(function(e,t,n=null,r,o){return e.token=I(e,t),Ot(t,e,o,{type:"TemplateElement",value:{cooked:n,raw:r},tail:!1})}(e,t,a,i,o)),33554441===e.token?r.push(lt(e,t,s)):ct(e,t,n,r),Ot(t,e,o,{type:"TemplateLiteral",expressions:n,quasis:r})}function lt(e,t,n=Xt(e)){const{tokenValue:r,tokenRaw:o}=e;return Lt(e,t,33554441),Ot(t,e,n,{type:"TemplateElement",value:{cooked:r,raw:o},tail:!0})}function ut(e,t){const n=Xt(e);return Ot(t,e,n,{type:"Decorator",expression:De(e,t,n)})}function pt(e,t){const n=[];for(;Dt(e,t,120);)n.push(ut(e,t|dt.AllowDecorator));return n}var dt,ft,mt,wt,gt,yt,ht,xt,kt,St,Et,vt;function bt(e,t,n,r){const o=Ct(e,n);o||pn(e,t,32,n),!r||o&mt.Nested||pn(e,t,31,n)}function At(e,t){var n;void 0===e.labelSet&&(e.labelSet={}),e.labelSet[`$${t}`]=12369===(n=e.token)||12386===n||12374===n?mt.Nested:mt.NotNested}function It(e,t){e.labelSet[`$${t}`]=mt.None}function Ct(e,t){return e.labelSet?e.labelSet[`$${t}`]:mt.None}function Ot(e,t,n,r){const{lastIndex:o,lastLine:a,lastColumn:i,sourceFile:s,index:c}=t;return e&dt.LocationTracker&&(e&dt.OptionsRanges&&(r.start=n.index,r.end=o),e&dt.OptionsLoc&&(r.loc={start:{line:n.line,column:n.column},end:{line:a,column:i}},s&&(r.loc.source=s))),r}function Lt(e,t,n,r=1){return e.token!==n&&un(e,r,o(e.token)),Nt(e,t),!0}function Dt(e,t,n){return e.token===n&&(Nt(e,t),!0)}function Nt(e,t){return e.lastIndex=e.index,e.lastLine=e.line,e.lastColumn=e.column,e.token=j(e,t)}!function(e){e[e.Empty=0]="Empty",e[e.OptionsNext=1]="OptionsNext",e[e.OptionsRanges=2]="OptionsRanges",e[e.OptionsJSX=4]="OptionsJSX",e[e.OptionsRaw=8]="OptionsRaw",e[e.OptionsLoc=16]="OptionsLoc",e[e.OptionsGlobalReturn=32]="OptionsGlobalReturn",e[e.OptionsComments=64]="OptionsComments",e[e.OptionsShebang=128]="OptionsShebang",e[e.OptionsRawidentifiers=256]="OptionsRawidentifiers",e[e.OptionsTolerant=512]="OptionsTolerant",e[e.OptionsNode=1024]="OptionsNode",e[e.OptionsExperimental=2048]="OptionsExperimental",e[e.Strict=4096]="Strict",e[e.Module=8192]="Module",e[e.TaggedTemplate=16384]="TaggedTemplate",e[e.InClass=32768]="InClass",e[e.AllowIn=65536]="AllowIn",e[e.Async=131072]="Async",e[e.Yield=262144]="Yield",e[e.InParameter=524288]="InParameter",e[e.InFunctionBody=1048576]="InFunctionBody",e[e.AllowSingleStatement=2097152]="AllowSingleStatement",e[e.BlockScope=4194304]="BlockScope",e[e.ForStatement=8388608]="ForStatement",e[e.RequireIdentifier=16777216]="RequireIdentifier",e[e.Method=33554432]="Method",e[e.AllowSuperProperty=67108864]="AllowSuperProperty",e[e.InParen=134217728]="InParen",e[e.InJSXChild=268435456]="InJSXChild",e[e.DisallowEscapedKeyword=536870912]="DisallowEscapedKeyword",e[e.AllowDecorator=1073741824]="AllowDecorator",e[e.LocationTracker=18]="LocationTracker"}(dt||(dt={})),function(e){e[e.None=0]="None",e[e.NewLine=1]="NewLine",e[e.AllowBinding=2]="AllowBinding",e[e.AllowDestructuring=4]="AllowDestructuring",e[e.SimpleParameterList=8]="SimpleParameterList",e[e.InSwitchStatement=16]="InSwitchStatement",e[e.InIterationStatement=32]="InIterationStatement",e[e.HasStrictReserved=64]="HasStrictReserved",e[e.HasOctal=128]="HasOctal",e[e.SimpleAssignmentTarget=256]="SimpleAssignmentTarget",e[e.HasProtoField=512]="HasProtoField",e[e.StrictFunctionName=1024]="StrictFunctionName",e[e.StrictEvalArguments=2048]="StrictEvalArguments",e[e.InFunctionBody=4096]="InFunctionBody",e[e.HasAwait=8192]="HasAwait",e[e.HasYield=16384]="HasYield",e[e.EscapedKeyword=32768]="EscapedKeyword",e[e.HasConstructor=65536]="HasConstructor"}(ft||(ft={})),function(e){e[e.None=0]="None",e[e.NotNested=1]="NotNested",e[e.Nested=2]="Nested"}(mt||(mt={})),function(e){e[e.None=0]="None",e[e.SeenSeparator=1]="SeenSeparator",e[e.EigthOrNine=2]="EigthOrNine",e[e.Float=4]="Float",e[e.BigInt=8]="BigInt"}(wt||(wt={})),function(e){e[e.None=0]="None",e[e.NewLine=1]="NewLine",e[e.LastIsCR=2]="LastIsCR"}(gt||(gt={})),function(e){e[e.None=0]="None",e[e.Generator=1]="Generator",e[e.Await=2]="Await"}(yt||(yt={})),function(e){e[e.None=0]="None",e[e.SequenceExpression=1]="SequenceExpression",e[e.HasEvalOrArguments=2]="HasEvalOrArguments",e[e.HasReservedWords=4]="HasReservedWords",e[e.HasYield=8]="HasYield",e[e.HasBinding=16]="HasBinding"}(ht||(ht={})),function(e){e[e.Empty=-1]="Empty",e[e.StrictOctal=-2]="StrictOctal",e[e.EightOrNine=-3]="EightOrNine",e[e.InvalidHex=-4]="InvalidHex",e[e.OutOfRange=-5]="OutOfRange"}(xt||(xt={})),function(e){e[e.Empty=0]="Empty",e[e.IgnoreCase=1]="IgnoreCase",e[e.Global=2]="Global",e[e.Multiline=4]="Multiline",e[e.Unicode=8]="Unicode",e[e.Sticky=16]="Sticky",e[e.DotAll=32]="DotAll"}(kt||(kt={})),function(e){e[e.Empty=0]="Empty",e[e.SeenSpread=1]="SeenSpread",e[e.HasSpread=2]="HasSpread",e[e.SimpleParameter=4]="SimpleParameter",e[e.EvalOrArguments=8]="EvalOrArguments",e[e.Yield=16]="Yield",e[e.Await=32]="Await"}(St||(St={})),function(e){e[e.Empty=0]="Empty",e[e.Escape=1]="Escape",e[e.Class=2]="Class"}(Et||(Et={})),function(e){e[e.None=0]="None",e[e.Async=1]="Async",e[e.Generator=2]="Generator",e[e.Getter=4]="Getter",e[e.Setter=8]="Setter",e[e.Computed=16]="Computed",e[e.Method=32]="Method",e[e.Shorthand=64]="Shorthand",e[e.Static=128]="Static",e[e.Constructor=256]="Constructor",e[e.Heritage=512]="Heritage"}(vt||(vt={}));const _t=(e,t)=>(e&t)===t;function Pt(e,t){return 1048576&e.token||e.flags&ft.NewLine?Dt(e,t,17825809):un(e,!(t&dt.Async)&&262144&e.token?38:1,o(e.token))}function Rt(e,t,n){const{flags:r,pendingExpressionError:o}=e;e.flags|=ft.AllowBinding|ft.AllowDestructuring,e.pendingExpressionError=void 0;const a=n(e,t);if(e.pendingExpressionError){const{error:n,line:r,column:o,index:a}=e.pendingExpressionError;cn(e,t,a,r,o,n)}return e.flags&=~(ft.AllowBinding|ft.AllowDestructuring),r&ft.AllowBinding&&(e.flags|=ft.AllowBinding),r&ft.AllowDestructuring&&(e.flags|=ft.AllowDestructuring),e.pendingExpressionError=o,a}function Mt(e,t,n){const{flags:r,pendingExpressionError:o}=e;e.flags|=ft.AllowBinding|ft.AllowDestructuring,e.pendingExpressionError=void 0;const a=n(e,t);return e.flags&ft.AllowBinding&&r&ft.AllowBinding||(e.flags&=~ft.AllowBinding),e.flags&ft.AllowDestructuring&&r&ft.AllowDestructuring||(e.flags&=~ft.AllowDestructuring),e.pendingExpressionError=o||e.pendingExpressionError,a}function Ht(e,t,n,r,o=vt.None){return t&=~(dt.Async|dt.Yield|dt.InParameter),n&yt.Generator&&(t|=dt.Yield),n&yt.Await&&(t|=dt.Async),r(e,t,o)}function Tt(e,t,n){const r=new Map;for(let o=0;o{switch(n.type){case"Identifier":t&dt.Strict&&Wt(n.name)&&un(e,3);case"ArrayPattern":case"AssignmentPattern":case"ObjectPattern":case"RestElement":case"MetaProperty":return;case"ArrayExpression":n.type="ArrayPattern";for(let r=0;rn[t]));cn(e,dt.Empty,r,o,a,i)}function pn(e,t,n,...r){const{index:o,line:a,column:i}=ln(e);cn(e,t,o,a,i,sn[n].replace(/%(\d+)/g,((e,t)=>r[t])))}function dn(e,t){const n=Xt(e);let r=[];t&dt.OptionsExperimental&&(r=pt(e,t)),Lt(e,t|dt.DisallowEscapedKeyword,33566797);const o=t&dt.RequireIdentifier&&33685505!==e.token?null:U(e,t|dt.Strict|dt.DisallowEscapedKeyword);let a=vt.None,i=null;Dt(e,t,12372)&&(i=De(e,t|dt.Strict,n),a|=vt.Heritage);const s=et(e,t&~dt.RequireIdentifier|dt.Strict|dt.InClass,a);return Ot(t,e,n,t&dt.OptionsExperimental?{type:"ClassDeclaration",id:o,superClass:i,body:s,decorators:r}:{type:"ClassDeclaration",id:o,superClass:i,body:s})}function fn(e,t){const n=Xt(e);Lt(e,t,33566808);let r=yt.None;return Dt(e,t,167774771)&&(t&dt.AllowSingleStatement&&!(t&dt.InFunctionBody)&&pn(e,t,22),r=yt.Generator),mn(e,t,r,n)}function mn(e,t,n,r){const{token:o}=e;let a=null;t&dt.Yield&&1073741824&o&&pn(e,t,49),t&dt.Async&&262144&o&&pn(e,t,48),50331659!==o?a=U(e,t):t&dt.RequireIdentifier||pn(e,t,39);const{params:i,body:s}=Ht(e,t&~(dt.Method|dt.AllowSuperProperty|dt.RequireIdentifier),n,ze);return Ot(t,e,r,{type:"FunctionDeclaration",params:i,body:s,async:!!(n&yt.Await),generator:!!(n&yt.Generator),expression:!1,id:a})}function wn(e,t){const n=Xt(e);Lt(e,t,594028),Lt(e,t,33566808);const r=yt.Await;return mn(e,t,(Dt(e,t,167774771)?yt.Generator:yt.None)|r,n)}function gn(e,t,n){const r=Xt(e),a=0!=(8388608&e.token),i=Y(e,t);let s=null;return Dt(e,t|dt.DisallowEscapedKeyword,83886109)?(s=Rt(e,t&~(dt.BlockScope|dt.ForStatement),Ae),an(e.token)&&(t&dt.ForStatement||a)&&(167786289===e.token?(t&(dt.BlockScope|dt.Strict|dt.Async)||a)&&pn(e,t,25,o(e.token)):pn(e,t,25,o(e.token)))):an(e.token)||!n&&!a||pn(e,t,24,n?"const":"destructuring"),Ot(t,e,r,{type:"VariableDeclarator",init:s,id:i})}function yn(e,t,n){const r=[gn(e,t,n)];for(;Dt(e,t,16777234);)r.push(gn(e,t,n));return t&dt.ForStatement&&an(e.token)&&1!==r.length&&pn(e,t,26,o(e.token)),r}function hn(e,t){switch(e.token){case 33566808:return fn(e,t);case 120:case 33566797:return dn(e,t);case 33574984:return function(e,t,n=!0){return Bt(e,t,qt)?Vn(e,t|dt.BlockScope,n):Nn(e,t)}(e,t|dt.AllowIn);case 33566793:return Vn(e,t|dt.BlockScope|dt.AllowIn);case 594028:return function(e,t){return Bt(e,t,Ut)?wn(e,t):xn(e,t)}(e,t);case 33566810:if(t&dt.OptionsNext&&Bt(e,t,jt))return Ln(e,t|dt.AllowIn);case 12371:t&dt.Module&&pn(e,t,34,o(e.token));default:return xn(e,t|dt.AllowSingleStatement)}}function xn(e,t){switch(e.token){case 33566791:return Vn(e,t|dt.AllowIn);case 17825809:return kn(e,t);case 33566814:return Fn(e,t);case 41943052:return Rn(e,t);case 12380:return Mn(e,t);case 12377:return vn(e,t);case 12369:return _n(e,t);case 12386:return Pn(e,t);case 12387:return Tn(e,t);case 12362:return En(e,t);case 12366:return Sn(e,t);case 12367:return An(e,t);case 302002272:return On(e,t);case 12385:return In(e,t|dt.DisallowEscapedKeyword);case 12374:return function(e,t){const n=Xt(e);Lt(e,t,12374);const r=!!(t&dt.Async&&Dt(e,t,34017389));Lt(e,t|dt.DisallowEscapedKeyword,50331659);const{token:o}=e;let a,i=null,s=null,c=null,l="ForStatement",u=null,p=null;33566793===o||33574984===o&&Bt(e,t,qt)?c=Vn(e,t&~dt.AllowIn|dt.BlockScope,!1):33566791===o?c=Vn(e,t&~dt.AllowIn,!1):17825809!==o&&(s=Xt(e),i=Mt(e,t&~dt.AllowIn|dt.DisallowEscapedKeyword,Ae)),Dt(e,t,69746)?(l="ForOfStatement",i?(e.flags&ft.AllowDestructuring&&"AssignmentExpression"!==i.type||pn(e,t,73),Ft(e,t,i)):i=c,a=Ae(e,t|dt.AllowIn)):Dt(e,t,167786289)?(i?(e.flags&ft.AllowDestructuring||pn(e,t,73),Ft(e,t,i)):i=c,l="ForInStatement",a=ve(e,t&~dt.AllowDecorator|dt.AllowIn)):(16777234===e.token&&(i=be(e,t,i,s)),c&&(i=c),Lt(e,t,17825809),u=17825809!==e.token?ve(e,t&~dt.AllowDecorator|dt.AllowIn):null,Lt(e,t,17825809),p=16!==e.token?ve(e,t&~dt.AllowDecorator|dt.AllowIn):null),Lt(e,t,16);const d=Hn(e,t);return Ot(t,e,n,"ForOfStatement"===l?{type:l,body:d,left:i,right:a,await:r}:a?{type:l,body:d,left:i,right:a}:{type:l,body:d,init:i,test:u,update:p})}(e,t|dt.ForStatement);case 594028:return Bt(e,t,Ut)&&pn(e,t,35),Nn(e,t|dt.AllowSingleStatement);case 33566808:pn(e,t,t&dt.Strict?19:20);case 33566797:pn(e,t,21,o(e.token));default:return Nn(e,t)}}function kn(e,t){const n=Xt(e);return Nt(e,t),Ot(t,e,n,{type:"EmptyStatement"})}function Sn(e,t){const n=Xt(e);Nt(e,t),e.flags&(ft.InSwitchStatement|ft.InIterationStatement)||pn(e,t,30,o(e.token));let r=null;if(!(e.flags&ft.NewLine)&&135168&e.token){const{tokenValue:n}=e;r=Me(e,t),bt(e,t,n,!0)}return Pt(e,t),Ot(t,e,n,{type:"ContinueStatement",label:r})}function En(e,t){const n=Xt(e);Nt(e,t);let r=null;if(!(e.flags&ft.NewLine)&&135168&e.token){const{tokenValue:n}=e;r=Me(e,t),bt(e,t,n,!1)}else e.flags&(ft.InSwitchStatement|ft.InIterationStatement)||pn(e,t,30,"break");return Pt(e,t),Ot(t,e,n,{type:"BreakStatement",label:r})}function vn(e,t){const n=Xt(e);Nt(e,t),Lt(e,t,50331659);const r=ve(e,t&~dt.AllowDecorator|dt.AllowIn);return Lt(e,t,16),Ot(t,e,n,{type:"IfStatement",test:r,consequent:bn(e,t|dt.DisallowEscapedKeyword),alternate:Dt(e,t,12370)?bn(e,t):null})}function bn(e,t){return t&dt.Strict||33566808!==e.token?xn(e,t&~dt.AllowSingleStatement):fn(e,t)}function An(e,t){const n=Xt(e);return Nt(e,t),Pt(e,t),Ot(t,e,n,{type:"DebuggerStatement"})}function In(e,t){const n=Xt(e);Nt(e,t);const r=Rn(e,t),o=12364===e.token?Cn(e,t):null,a=Dt(e,t,12373)?Rn(e,t):null;return o||a||pn(e,t,79),Ot(t,e,n,{type:"TryStatement",block:r,handler:o,finalizer:a})}function Cn(e,t){const n=Xt(e);Nt(e,t);let r=null;if(Dt(e,t,50331659)){const n=[];r=Y(e,t,n),Tt(e,t,n),Lt(e,t,16)}return Ot(t,e,n,{type:"CatchClause",param:r,body:Rn(e,t)})}function On(e,t){const n=Xt(e);Nt(e,t),e.flags&ft.NewLine&&pn(e,t,80);const r=ve(e,t&~dt.AllowDecorator|dt.AllowIn);return Pt(e,t),Ot(t,e,n,{type:"ThrowStatement",argument:r})}function Ln(e,t){const n=Xt(e),r=ve(e,t&~dt.AllowDecorator|dt.AllowIn);return Pt(e,t),Ot(t,e,n,{type:"ExpressionStatement",expression:r})}function Dn(e,t){const n=Xt(e),r=e.tokenRaw.slice(1,-1),o=ve(e,t&~dt.AllowDecorator|dt.AllowIn);return Pt(e,t),Ot(t,e,n,{type:"ExpressionStatement",expression:o,directive:r})}function Nn(e,t){const n=Xt(e),{tokenValue:r,token:o}=e,a=ve(e,t&~(dt.AllowSingleStatement|dt.AllowDecorator)|dt.AllowIn);if(135168&o&&16777237===e.token){t&dt.Yield&&1073741824&o&&pn(e,t,57),Lt(e,t,16777237,83),Ct(e,r)&&pn(e,t,29,r),At(e,r);const i=!(t&dt.Strict)&&t&dt.AllowSingleStatement&&33566808===e.token?fn(e,t):xn(e,t);return It(e,r),Ot(t,e,n,{type:"LabeledStatement",label:a,body:i})}return Pt(e,t),Ot(t,e,n,{type:"ExpressionStatement",expression:a})}function _n(e,t){const n=Xt(e);Nt(e,t);const r=Hn(e,t);Lt(e,t,12386),Lt(e,t,50331659);const o=ve(e,t&~dt.AllowDecorator|dt.AllowIn);return Lt(e,t,16),Dt(e,t,17825809),Ot(t,e,n,{type:"DoWhileStatement",body:r,test:o})}function Pn(e,t){const n=Xt(e);Nt(e,t),Lt(e,t,50331659);const r=ve(e,t&~dt.AllowDecorator|dt.AllowIn);return Lt(e,t,16),Ot(t,e,n,{type:"WhileStatement",test:r,body:Hn(e,t)})}function Rn(e,t){const n=Xt(e),r=[];for(Lt(e,t,41943052);17825807!==e.token;)r.push(hn(e,t));return Lt(e,t,17825807),Ot(t,e,n,{type:"BlockStatement",body:r})}function Mn(e,t){const n=Xt(e);t&(dt.OptionsGlobalReturn|dt.InFunctionBody)||pn(e,t,18),e.flags&ft.EscapedKeyword&&pn(e,t,3),Nt(e,t);const r=1048576&e.token||e.flags&ft.NewLine?null:ve(e,t&~(dt.InFunctionBody|dt.AllowDecorator)|dt.AllowIn);return Pt(e,t),Ot(t,e,n,{type:"ReturnStatement",argument:r})}function Hn(e,t){const n=e.flags;e.flags|=ft.InIterationStatement|ft.AllowDestructuring;const r=xn(e,t&~dt.AllowSingleStatement|dt.DisallowEscapedKeyword);return e.flags=n,r}function Tn(e,t){t&dt.Strict&&pn(e,t,37);const n=Xt(e);Nt(e,t),Lt(e,t,50331659);const r=ve(e,t&~dt.AllowDecorator|dt.AllowIn);return Lt(e,t,16),Ot(t,e,n,{type:"WithStatement",object:r,body:xn(e,t&~dt.AllowSingleStatement)})}function Fn(e,t){const n=Xt(e);Nt(e,t),Lt(e,t,50331659);const r=ve(e,t&~dt.AllowDecorator|dt.AllowIn);Lt(e,t,16),Lt(e,t|dt.DisallowEscapedKeyword,41943052);const o=[],a=e.flags;e.flags|=ft.InSwitchStatement;let i=!1;for(;17825807!==e.token;){const n=Bn(e,t);o.push(n),null===n.test&&(i&&pn(e,t,33),i=!0)}return e.flags=a,Lt(e,t,17825807),Ot(t,e,n,{type:"SwitchStatement",discriminant:r,cases:o})}function Bn(e,t){const n=Xt(e);let r=null;Dt(e,t,12363)?r=ve(e,t&~dt.AllowDecorator|dt.AllowIn):Lt(e,t,12368),Lt(e,t,16777237);const o=[];for(;!Gt(e);)o.push(hn(e,t|dt.AllowIn));return Ot(t,e,n,{type:"SwitchCase",test:r,consequent:o})}function Vn(e,t,n=!0){const r=Xt(e),{token:a}=e,i=33566793===a;Nt(e,t);const s=yn(e,t,i);return n&&Pt(e,t),Ot(t,e,r,{type:"VariableDeclaration",kind:o(a),declarations:s})}function Xn(e,t){Nt(e,t);const n=[];for(;1048576!==e.token;)n.push(33554435===e.token?Dn(e,t):Jn(e,t|dt.AllowIn));return n}function Jn(e,t){switch(e.token){case 120:return pt(e,t);case 12371:return qn(e,t);case 33566810:if(!(t&dt.OptionsNext&&Bt(e,t,jt)))return jn(e,t);default:return hn(e,t)}}function qn(e,t){const n=Xt(e),r=[];let a=null,i=null;switch(Lt(e,t|dt.DisallowEscapedKeyword,12371),e.token){case 167774771:return function(e,t,n){Lt(e,t,167774771);const r=$n(e,t);return Pt(e,t),Ot(t,e,n,{type:"ExportAllDeclaration",source:r})}(e,t,n);case 12368:return function(e,t,n){let r;switch(Lt(e,t|dt.DisallowEscapedKeyword,12368),e.token){case 33566808:r=fn(e,t|dt.RequireIdentifier);break;case 120:case 33566797:r=dn(e,t&~dt.AllowIn|dt.RequireIdentifier);break;case 594028:r=function(e,t){return Bt(e,t,Ut)?wn(e,t|dt.RequireIdentifier):Ae(e,t|dt.AllowIn)}(e,t|dt.RequireIdentifier);break;default:r=Ae(e,t|dt.AllowIn),Pt(e,t)}return Ot(t,e,n,{type:"ExportDefaultDeclaration",declaration:r})}(e,t,n);case 41943052:{Lt(e,t,41943052);let n=!1;for(;17825807!==e.token;)69743!==e.token&&12288&e.token&&(n=!0,Qt(e)),r.push(Gn(e,t)),17825807!==e.token&&Lt(e,t,16777234);Lt(e,t|dt.DisallowEscapedKeyword,17825807),69745===e.token?a=$n(e,t):n&&pn(e,t,46),Pt(e,t);break}case 33566797:i=dn(e,t);break;case 33574984:case 33566793:i=Vn(e,t|dt.BlockScope);break;case 33566791:i=Vn(e,t);break;case 33566808:i=fn(e,t);break;case 594028:if(Bt(e,t,Ut)){i=wn(e,t);break}default:un(e,1,o(e.token))}return Ot(t,e,n,{type:"ExportNamedDeclaration",source:a,specifiers:r,declaration:i})}function Gn(e,t){const n=Xt(e),r=Fe(e,t|dt.DisallowEscapedKeyword,e.token);return Ot(t,e,n,{type:"ExportSpecifier",local:r,exported:Dt(e,t,167843947)?Fe(e,t,e.token):r})}function jn(e,t){const n=Xt(e);let r;Lt(e,t,33566810);let a=[];return 33554435===e.token?r=He(e,t):(a=function(e,t){const n=[];switch(e.token){case 33685505:if(n.push(function(e,t){return Ot(t,e,Xt(e),{type:"ImportDefaultSpecifier",local:Me(e,t)})}(e,t)),Dt(e,t,16777234))switch(e.token){case 167774771:Un(e,t,n);break;case 41943052:Kn(e,t,n);break;default:pn(e,t,1,o(e.token))}break;case 41943052:Kn(e,t,n);break;case 167774771:Un(e,t,n);break;default:un(e,1,o(e.token))}return n}(e,t|dt.DisallowEscapedKeyword),r=$n(e,t)),Pt(e,t),Ot(t,e,n,{type:"ImportDeclaration",specifiers:a,source:r})}function Kn(e,t,n){for(Lt(e,t,41943052);17825807!==e.token;)n.push(Yn(e,t)),17825807!==e.token&&Lt(e,t,16777234);Lt(e,t,17825807)}function Yn(e,t){const n=Xt(e),{token:r}=e,o=Fe(e,t|dt.DisallowEscapedKeyword,r);let a;return Dt(e,t,167843947)?a=U(e,t):(_t(r,12288)&&pn(e,t,46),_t(r,4194304)&&pn(e,t,47),a=o),Ot(t,e,n,{type:"ImportSpecifier",local:a,imported:o})}function Un(e,t,n){const r=Xt(e);Lt(e,t,167774771),Lt(e,t,167843947,82);const o=U(e,t);n.push(Ot(t,e,r,{type:"ImportNamespaceSpecifier",local:o}))}function $n(e,t){return Lt(e,t,69745),33554435!==e.token&&un(e,1,o(e.token)),He(e,t)}function zn(e,t){return{source:e,length:e.length,index:0,line:1,column:0,startIndex:0,startColumn:0,startLine:1,lastIndex:0,lastColumn:0,lastLine:0,pendingExpressionError:void 0,flags:ft.AllowDestructuring,token:1048576,tokenRaw:"",lastValue:0,comments:[],sourceFile:t,tokenRegExp:void 0,tokenValue:void 0,labelSet:void 0,errorLocation:void 0,errors:[]}}function Wn(e,t,n){let r="";t&&(t.module&&(n|=dt.Module),t.next&&(n|=dt.OptionsNext),t.jsx&&(n|=dt.OptionsJSX),t.ranges&&(n|=dt.OptionsRanges),t.loc&&(n|=dt.OptionsLoc),t.raw&&(n|=dt.OptionsRaw),t.rawIdentifier&&(n|=dt.OptionsRawidentifiers),t.globalReturn&&(n|=dt.OptionsGlobalReturn),t.skipShebang&&(n|=dt.OptionsShebang),t.tolerant&&(n|=dt.OptionsTolerant),t.source&&(r=t.source),t.comments&&(n|=dt.OptionsComments),t.impliedStrict&&(n|=dt.Strict),t.experimental&&(n|=dt.OptionsExperimental),t.node&&(n|=dt.OptionsNode));const o=zn(e,r),a=n&dt.Module?Xn(o,n):Qn(o,n),i={type:"Program",sourceType:n&dt.Module?"module":"script",body:a};return n&dt.LocationTracker&&(n&dt.OptionsRanges&&(i.start=0,i.end=e.length),n&dt.OptionsLoc&&(i.loc={start:{line:1,column:0},end:{line:o.line,column:o.column}},r&&(i.loc.source=r))),n&dt.OptionsComments&&(i.comments=o.comments),n&dt.OptionsTolerant&&(i.errors=o.errors),i}function Qn(e,t){const n=[];let r=!0;for(Nt(e,t|dt.DisallowEscapedKeyword);1048576!==e.token;)r&&33554435!==e.token&&(r=!1),r?(t&dt.Strict||12!==e.tokenRaw.length||"use strict"!==e.tokenValue||(t|=dt.Strict),n.push(Dn(e,t))):n.push(hn(e,t));return n}function Zn(e,t){return t&&t.module?tr(e,t):er(e,t)}function er(e,t){return Wn(e,t,dt.Empty)}function tr(e,t){return Wn(e,t,dt.Strict|dt.Module)}var nr=Object.freeze({}),rr=Object.freeze({scanIdentifier:F,scanMaybeIdentifier:B,scanHexIntegerLiteral:L,scanOctalOrBinary:D,scanImplicitOctalDigits:N,scanSignedInteger:_,scanNumericLiteral:P,scanNumericSeparator:R,scanDecimalDigitsOrSeparator:M,scanDecimalAsSmi:H,scanRegularExpression:K,scan:j,scanEscapeSequence:v,throwStringError:b,scanString:A,consumeTemplateBrace:I,scanTemplate:C,skipSingleHTMLComment:X,skipSingleLineComment:J,skipMultiLineComment:q,addComment:G,nextUnicodeChar:d,isIdentifierPart:f,escapeInvalidCharacters:m,consumeOpt:w,consumeLineFeed:g,scanPrivateName:y,advanceNewline:h,fromCodePoint:x,readNext:k,toHex:S,advanceOnMaybeAstral:E});const or=Object.freeze({parseClassDeclaration:dn,parseFunctionDeclaration:fn,parseAsyncFunctionOrAsyncGeneratorDeclaration:wn,parseVariableDeclarationList:yn,parseExpression:ve,parseSequenceExpression:be,parseAssignmentExpression:Ae,parseRestElement:Oe,parseLeftHandSideExpression:De,parsePrimaryExpression:Re,parseIdentifier:Me,parseLiteral:He,parseBigIntLiteral:Te,parseIdentifierName:Fe,parseFunctionExpression:Xe,parseAsyncFunctionOrAsyncGeneratorExpression:Je,parsePropertyName:qe,parseObjectLiteral:je,parseFormalListAndBody:ze,parseFunctionBody:We,parseFormalParameters:Qe,parseFormalParameterList:Ze,parseClassBodyAndElementList:et,parseClassElement:tt,parseDecorators:pt,parseModuleItemList:Xn,parseModuleItem:Jn,parseExportDeclaration:qn,parseImportDeclaration:jn,createParser:zn,parseSource:Wn,parseStatementList:Qn,parse:Zn,parseScript:er,parseModule:tr,parseBindingIdentifierOrPattern:Y,parseBindingIdentifier:U,parseAssignmentRestElement:$,parseAssignmentPattern:W,parseBindingInitializer:Q,parseStatementListItem:hn,parseStatement:xn,parseEmptyStatement:kn,parseContinueStatement:Sn,parseBreakStatement:En,parseIfStatement:vn,parseDebuggerStatement:An,parseTryStatement:In,parseCatchBlock:Cn,parseThrowStatement:On,parseExpressionStatement:Ln,parseDirective:Dn,parseExpressionOrLabelledStatement:Nn,parseDoWhileStatement:_n,parseWhileStatement:Pn,parseBlockStatement:Rn,parseReturnStatement:Mn,parseIterationStatement:Hn,parseWithStatement:Tn,parseSwitchStatement:Fn,parseCaseOrDefaultClauses:Bn,parseVariableStatement:Vn,parseJSXRootElement:ee,parseJSXOpeningElement:te,nextJSXToken:ne,scanJSXToken:re,parseJSXText:ae,parseJSXAttributes:se,parseJSXSpreadAttribute:ce,parseJSXNamespacedName:le,parseJSXAttributeName:ue,parseJSXAttribute:de,parseJSXEmptyExpression:fe,parseJSXSpreadChild:me,parseJSXExpressionContainer:we,parseJSXExpression:ge,parseJSXClosingFragment:ye,parseJSXClosingElement:he,parseJSXIdentifier:xe,parseJSXMemberExpression:ke,parseJSXElementName:Se,scanJSXIdentifier:Ee}),ar="1.6.9"},63:e=>{e.exports=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var r,o,a;if(Array.isArray(t)){if((r=t.length)!=n.length)return!1;for(o=r;0!=o--;)if(!e(t[o],n[o]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((r=(a=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(o=r;0!=o--;)if(!Object.prototype.hasOwnProperty.call(n,a[o]))return!1;for(o=r;0!=o--;){var i=a[o];if(!e(t[i],n[i]))return!1}return!0}return t!=t&&n!=n}},607:function(__unused_webpack_module,exports,__webpack_require__){var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.func=exports.match=void 0;const cherow_1=__webpack_require__(951),astring_1=__webpack_require__(326),fast_deep_equal_1=__importDefault(__webpack_require__(63)),ast_equals_value=(a,v)=>{let x;return eval("x = "+(0,astring_1.generate)(a)),(0,fast_deep_equal_1.default)(v,x)},matchObjectPattern=(e,t)=>{if("object"!=typeof e)return!1;for(var n=0;n!0,matchAssignmentPattern=(e,t)=>ast_equals_value(t,e),matchArrayPattern=(e,t)=>{for(let n=0;ne===t,matches=(e,t)=>void 0===t?matchEmpty(e,t):"Identifier"===t.type?matchIdentifier(e,t.name):"ObjectPattern"===t.type?matchObjectPattern(e,t.properties):"AssignmentPattern"===t.type?matchAssignmentPattern(e,t.right):"ArrayPattern"===t.type&&matchArrayPattern(e,t.elements),match=e=>(...t)=>{const n=t.map((e=>e.toString())).map((e=>e.match(/function\s*\(/)?`let x = ${e}`:e)).map((e=>(0,cherow_1.parseScript)(e))).map((({body:[e]})=>{let t=null;switch(e.type){case"ExpressionStatement":t=e.expression.params[0];break;case"FunctionDeclaration":t=e.params[0];break;case"VariableDeclaration":t=e.declarations[0].init.params[0];break;default:throw new Error("Invalid pattern: "+e.type)}return t}));for(let r=0;rt=>(0,exports.match)(t)(...e);exports.func=func}},__webpack_module_cache__={};function __webpack_require__(e){var t=__webpack_module_cache__[e];if(void 0!==t)return t.exports;var n=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e].call(n.exports,n,n.exports,__webpack_require__),n.exports}__webpack_require__.d=(e,t)=>{for(var n in t)__webpack_require__.o(t,n)&&!__webpack_require__.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__=__webpack_require__(607);return __webpack_exports__})())); -------------------------------------------------------------------------------- /dist/test.d.ts: -------------------------------------------------------------------------------- 1 | export {}; 2 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # fsmgen 2 | 3 | Generates fsm diagrams from a simple language. 4 | -------------------------------------------------------------------------------- /docs/css/github-light.css: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2016 GitHub, Inc. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | */ 25 | 26 | .pl-c /* comment */ { 27 | color: #969896; 28 | } 29 | 30 | .pl-c1 /* constant, variable.other.constant, support, meta.property-name, support.constant, support.variable, meta.module-reference, markup.raw, meta.diff.header */, 31 | .pl-s .pl-v /* string variable */ { 32 | color: #0086b3; 33 | } 34 | 35 | .pl-e /* entity */, 36 | .pl-en /* entity.name */ { 37 | color: #795da3; 38 | } 39 | 40 | .pl-smi /* variable.parameter.function, storage.modifier.package, storage.modifier.import, storage.type.java, variable.other */, 41 | .pl-s .pl-s1 /* string source */ { 42 | color: #333; 43 | } 44 | 45 | .pl-ent /* entity.name.tag */ { 46 | color: #63a35c; 47 | } 48 | 49 | .pl-k /* keyword, storage, storage.type */ { 50 | color: #a71d5d; 51 | } 52 | 53 | .pl-s /* string */, 54 | .pl-pds /* punctuation.definition.string, string.regexp.character-class */, 55 | .pl-s .pl-pse .pl-s1 /* string punctuation.section.embedded source */, 56 | .pl-sr /* string.regexp */, 57 | .pl-sr .pl-cce /* string.regexp constant.character.escape */, 58 | .pl-sr .pl-sre /* string.regexp source.ruby.embedded */, 59 | .pl-sr .pl-sra /* string.regexp string.regexp.arbitrary-repitition */ { 60 | color: #183691; 61 | } 62 | 63 | .pl-v /* variable */ { 64 | color: #ed6a43; 65 | } 66 | 67 | .pl-id /* invalid.deprecated */ { 68 | color: #b52a1d; 69 | } 70 | 71 | .pl-ii /* invalid.illegal */ { 72 | color: #f8f8f8; 73 | background-color: #b52a1d; 74 | } 75 | 76 | .pl-sr .pl-cce /* string.regexp constant.character.escape */ { 77 | font-weight: bold; 78 | color: #63a35c; 79 | } 80 | 81 | .pl-ml /* markup.list */ { 82 | color: #693a17; 83 | } 84 | 85 | .pl-mh /* markup.heading */, 86 | .pl-mh .pl-en /* markup.heading entity.name */, 87 | .pl-ms /* meta.separator */ { 88 | font-weight: bold; 89 | color: #1d3e81; 90 | } 91 | 92 | .pl-mq /* markup.quote */ { 93 | color: #008080; 94 | } 95 | 96 | .pl-mi /* markup.italic */ { 97 | font-style: italic; 98 | color: #333; 99 | } 100 | 101 | .pl-mb /* markup.bold */ { 102 | font-weight: bold; 103 | color: #333; 104 | } 105 | 106 | .pl-md /* markup.deleted, meta.diff.header.from-file */ { 107 | color: #bd2c00; 108 | background-color: #ffecec; 109 | } 110 | 111 | .pl-mi1 /* markup.inserted, meta.diff.header.to-file */ { 112 | color: #55a532; 113 | background-color: #eaffea; 114 | } 115 | 116 | .pl-mdr /* meta.diff.range */ { 117 | font-weight: bold; 118 | color: #795da3; 119 | } 120 | 121 | .pl-mo /* meta.output */ { 122 | color: #1d3e81; 123 | } 124 | 125 | -------------------------------------------------------------------------------- /docs/css/mui.css: -------------------------------------------------------------------------------- 1 | /** 2 | * MUI Tabs module 3 | */ 4 | 5 | .mui-tabs__bar { 6 | list-style: none; 7 | padding-left: 0; 8 | margin-bottom: 0; 9 | background-color: transparent; 10 | white-space: nowrap; 11 | overflow-x: auto; 12 | padding-bottom: 14px; 13 | } 14 | 15 | .mui-tabs__bar>li { 16 | display: inline-block; 17 | width: auto; 18 | float: auto; 19 | border-right: none; 20 | height: auto; 21 | } 22 | 23 | .mui-tabs__bar>li>a { 24 | display: block; 25 | white-space: nowrap; 26 | text-transform: uppercase; 27 | font-weight: 500; 28 | color: rgba(0, 0, 0, 0.87); 29 | cursor: default; 30 | height: 36px; 31 | line-height: 40px; 32 | padding-left: 12px; 33 | padding-right: 12px; 34 | -webkit-user-select: none; 35 | -moz-user-select: none; 36 | -ms-user-select: none; 37 | user-select: none; 38 | } 39 | 40 | .mui-tabs__bar>li>a:hover { 41 | text-decoration: none; 42 | } 43 | 44 | .mui-tabs__bar>li.mui--is-active { 45 | border-bottom: 2px solid #2196F3; 46 | } 47 | 48 | .mui-tabs__bar>li.mui--is-active>a { 49 | color: #2196F3; 50 | } 51 | 52 | .mui-tabs__bar.mui-tabs__bar--justified { 53 | display: table; 54 | width: 100%; 55 | table-layout: fixed; 56 | } 57 | 58 | .mui-tabs__bar.mui-tabs__bar--justified>li { 59 | display: table-cell; 60 | } 61 | 62 | .mui-tabs__bar.mui-tabs__bar--justified>li>a { 63 | text-align: center; 64 | padding-left: 0px; 65 | padding-right: 0px; 66 | } 67 | 68 | .mui-tabs__pane { 69 | display: none; 70 | height: 100%; 71 | overflow: scroll; 72 | } 73 | 74 | .mui-tabs__pane.mui--is-active { 75 | display: block; 76 | } 77 | -------------------------------------------------------------------------------- /docs/css/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #fff; 3 | padding:50px; 4 | font: 14px/1.5 "Noto Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; 5 | color:#727272; 6 | font-weight:400; 7 | } 8 | 9 | h1, h2, h3, h4, h5, h6 { 10 | color:#222; 11 | margin:0 0 20px; 12 | } 13 | 14 | p, ul, ol, table, pre, dl { 15 | margin:0 0 20px; 16 | } 17 | 18 | h1, h2, h3 { 19 | line-height:1.1; 20 | } 21 | 22 | h1 { 23 | font-size:28px; 24 | margin-bottom:0.52em; 25 | } 26 | 27 | h2 { 28 | color:#393939; 29 | } 30 | 31 | h3, h4, h5, h6 { 32 | color:#494949; 33 | } 34 | 35 | a { 36 | color:#39c; 37 | text-decoration:none; 38 | } 39 | 40 | a:hover { 41 | color:#069; 42 | } 43 | 44 | a small { 45 | font-size:11px; 46 | color:#777; 47 | margin-top:-0.3em; 48 | display:block; 49 | } 50 | 51 | a:hover small { 52 | color:#777; 53 | } 54 | 55 | .wrapper { 56 | width:860px; 57 | margin:0 auto; 58 | } 59 | 60 | blockquote { 61 | border-left:1px solid #e5e5e5; 62 | margin:0; 63 | padding:0 0 0 20px; 64 | font-style:italic; 65 | } 66 | 67 | code, pre { 68 | font-family:Monaco, Bitstream Vera Sans Mono, Lucida Console, Terminal, Consolas, Liberation Mono, DejaVu Sans Mono, Courier New, monospace; 69 | color:#333; 70 | font-size:10px; 71 | } 72 | 73 | pre { 74 | padding:8px 15px; 75 | background: #f8f8f8; 76 | border-radius:5px; 77 | border:1px solid #e5e5e5; 78 | overflow-x: auto; 79 | } 80 | 81 | table { 82 | width:100%; 83 | border-collapse:collapse; 84 | } 85 | 86 | th, td { 87 | text-align:left; 88 | padding:5px 10px; 89 | border-bottom:1px solid #e5e5e5; 90 | } 91 | 92 | dt { 93 | color:#444; 94 | font-weight:700; 95 | } 96 | 97 | th { 98 | color:#444; 99 | } 100 | 101 | img { 102 | max-width:100%; 103 | } 104 | 105 | header { 106 | width:270px; 107 | height: 76%; 108 | float:left; 109 | position:fixed; 110 | -webkit-font-smoothing:subpixel-antialiased; 111 | } 112 | 113 | header ul { 114 | list-style:none; 115 | height:40px; 116 | padding:0; 117 | background: #f4f4f4; 118 | border-radius:5px; 119 | border:1px solid #e0e0e0; 120 | width:270px; 121 | } 122 | 123 | /*header li { 124 | width:89px; 125 | float:left; 126 | border-right:1px solid #e0e0e0; 127 | height:40px; 128 | } 129 | */ 130 | 131 | 132 | header li:first-child a { 133 | border-radius:5px 0 0 5px; 134 | } 135 | 136 | header li:last-child a { 137 | border-radius:0 5px 5px 0; 138 | } 139 | 140 | header ul a { 141 | line-height:1; 142 | font-size:11px; 143 | color:#999; 144 | display:block; 145 | text-align:center; 146 | padding-top:6px; 147 | height:34px; 148 | } 149 | 150 | header ul a:hover { 151 | color:#999; 152 | } 153 | 154 | header ul a:active { 155 | background-color:#f0f0f0; 156 | } 157 | 158 | strong { 159 | color:#222; 160 | font-weight:700; 161 | } 162 | 163 | header ul li + li + li { 164 | border-right:none; 165 | width:89px; 166 | } 167 | 168 | header ul a strong { 169 | font-size:14px; 170 | display:block; 171 | color:#222; 172 | } 173 | 174 | section { 175 | width:560px; 176 | float:right; 177 | padding-bottom:50px; 178 | } 179 | 180 | small { 181 | font-size:11px; 182 | } 183 | 184 | hr { 185 | border:0; 186 | background:#e5e5e5; 187 | height:1px; 188 | margin:0 0 20px; 189 | } 190 | 191 | footer { 192 | width:270px; 193 | float:left; 194 | position:fixed; 195 | bottom:50px; 196 | -webkit-font-smoothing:subpixel-antialiased; 197 | } 198 | 199 | @media print, screen and (max-width: 960px) { 200 | 201 | div.wrapper { 202 | width:auto; 203 | margin:0; 204 | } 205 | 206 | header, section, footer { 207 | float:none; 208 | position:static; 209 | width:auto; 210 | } 211 | 212 | header { 213 | padding-right:320px; 214 | } 215 | 216 | section { 217 | border:1px solid #e5e5e5; 218 | border-width:1px 0; 219 | padding:20px 0; 220 | margin:0 0 20px; 221 | } 222 | 223 | header a small { 224 | display:inline; 225 | } 226 | 227 | header ul { 228 | position:absolute; 229 | right:50px; 230 | top:52px; 231 | } 232 | } 233 | 234 | @media print, screen and (max-width: 720px) { 235 | body { 236 | word-wrap:break-word; 237 | } 238 | 239 | header { 240 | padding:0; 241 | } 242 | 243 | header ul, header p.view { 244 | position:static; 245 | } 246 | 247 | pre, code { 248 | word-wrap:normal; 249 | } 250 | } 251 | 252 | @media print, screen and (max-width: 480px) { 253 | body { 254 | padding:15px; 255 | } 256 | 257 | header ul { 258 | width:99%; 259 | } 260 | 261 | header li, header ul li + li + li { 262 | width:33%; 263 | } 264 | } 265 | 266 | @media print { 267 | body { 268 | padding:0.4in; 269 | font-size:12pt; 270 | color:#444; 271 | } 272 | } 273 | -------------------------------------------------------------------------------- /docs/img/cheesy_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrkev/fnMatch/751e5e9e028e9eb2f4bc2792b8aa94932c368d14/docs/img/cheesy_logo.png -------------------------------------------------------------------------------- /docs/img/logo.ai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrkev/fnMatch/751e5e9e028e9eb2f4bc2792b8aa94932c368d14/docs/img/logo.ai -------------------------------------------------------------------------------- /docs/img/pizza.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | fnMatch by mrkev 8 | 9 | 10 | 11 | 12 | 13 | 14 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 34 | 35 | 36 | 47 | 48 | 49 | 62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 |
70 | 71 |

fnMatch

72 |

Pattern matching without a transpiler.

73 | 74 |
    75 |
  1. 76 | Usage 77 |
  2. 78 | 79 |
  3. 80 | Values 81 |
  4. 82 |
  5. 83 | Arrays 84 |
  6. 85 |
  7. 86 | Objects 87 |
  8. 88 |
  9. 89 | Notes 90 |
  10. 91 |
92 | 93 |
94 | 95 |

Usage

96 | 97 |
 98 | match(value)(pattern1, pattern2, ...etc)
 99 | func(pattern1, pattern2, ...etc)(value)
100 | 101 |

Learn More

102 | 103 |

104 | View the Project on GitHub 105 | mrkev/fnMatch 106 | 107 |

108 |

109 | Hosted on GitHub Pages — Theme by 110 | orderedlist 111 | 112 |

113 | 114 |
115 | 116 |
117 |

Values

118 |
119 | match("hello")(
120 |   (_ = "hey") => {}, // doesn't match
121 |   (_ = "world") => {}, // doesn't match
122 |   (_ = "hello") => {}, // matches!
123 | )
124 | 
125 | 126 |

"Nothing" vs "Anything"

127 | 128 |
129 | 
130 | // Prints "undefined"
131 | match()(
132 |   () => console.log('undefined'),
133 |   (_) => console.log('anything'),
134 | );
135 | 
136 | // Prints "anything"
137 | match(3)(
138 |   () => console.log('undefined'),
139 |   (_) => console.log('anything'),
140 | );
141 | 
142 | 
143 | 144 | 145 |
146 | 147 |
148 | 149 |

OCaml-like exact semantics

150 |
// This prints nothing
151 | match([])(
152 |   ([x, ...y]) => console.log(x, y)
153 | )
154 | 
155 | 156 |
157 | 158 |
159 | 160 |

Destructuring

161 | 162 |
163 | const contacts = [
164 |   {name: {first: "Ajay"}, last: "Gandhi"},
165 |   {name: {first: "Seunghee", last: "Han"}},
166 |   {name: "Evil Galactic Empire, Inc.", kind: "company"}
167 | ]
168 | match(contacts)(
169 |   ([{kind = "company", name}, ..._]) => console.log("Found company:", name)
170 | )
171 | 
172 |

Renaming

173 |
174 | const contacts = [
175 |   {name: {first: "Ajay"}, last: "Gandhi"},
176 |   {name: {first: "Seunghee", last: "Han"}},
177 |   {name: "Evil Galactic Empire, Inc.", kind: "company"}
178 | ]
179 | match(contacts)(
180 |   ([{name: {first:first_person}}, ..._]) => console.log("First contact is", first_person)
181 | )
182 | 
183 | 184 | 185 |
186 | 187 |
188 | 189 |

Top to bottom

190 |
191 | // Prints "matches"
192 | match({name: "Ajay", age: 22})(
193 |   ({name}) => console.log("matches"),
194 |   ({name, age}) => console.log("too late!")
195 | )
196 | 
197 | 198 |

It's an expression

199 |
200 | const a = match(3)(
201 |   (_ = 3) => 4,
202 |   (_) => 0,
203 | );
204 | console.log(a) // Prints 4
205 | 
206 | 207 |

It's Just Functions

208 | 209 |
210 | const value = {
211 |   name: 'Ajay',
212 |   value: {
213 |     x: 34,
214 |   },
215 | };
216 | 
217 | function destructNotes ({notes}) { return notes; }
218 | let destructErrors = ({ errors }) => errors;
219 | let destructResult = function ({result}) { return result; }
220 | 
221 | let getResult = func(
222 |   destructNotes,
223 |   destructErrors,
224 |   destructResult
225 | );
226 | 
227 | console.log(getResult({notes: "This works!"}))
228 | 
229 | 230 | 231 |
232 | 233 | 234 |
235 | 236 | 237 | 238 |
239 | 240 | 260 |
261 |

262 |       
263 |       
264 |       
265 | 
266 |       
267 | 268 | 269 |
270 |
271 | 272 | 273 |
274 | 275 | 276 |
277 | 278 |
279 |
280 | 281 | 282 | 283 | -------------------------------------------------------------------------------- /docs/main.js: -------------------------------------------------------------------------------- 1 | 2 | /** Setup editor */ 3 | const editor = CodeMirror.fromTextArea(document.getElementById('fsm_src'), { 4 | lineWrapping: true, 5 | lineNumbers: true, 6 | mode: 'javascript', 7 | styleActiveLine: true, 8 | }); 9 | 10 | const log_pre = document.getElementById('errors'); // For error messages 11 | 12 | /** Run */ 13 | d3.select('#run_button').on('click', () => { 14 | repl_console.clear(); 15 | run_script(editor.getValue()); 16 | }); 17 | 18 | d3.select('#clear_button').on('click', () => { 19 | repl_console.clear(); 20 | }); 21 | 22 | const repl_console = { 23 | clear() { 24 | log_pre.textContent = ''; 25 | }, 26 | log(...args) { 27 | log_pre.textContent = log_pre.textContent + args.join(' ') + '\n'; 28 | }, 29 | error(err) { 30 | this.log(err.message); 31 | }, 32 | }; 33 | 34 | const __CONSOLE = console; 35 | const { match, func } = fnMatch; 36 | 37 | const run_script = (s) => { 38 | const f = new Function('console', s) 39 | f(repl_console) 40 | }; -------------------------------------------------------------------------------- /examples/test.ts: -------------------------------------------------------------------------------- 1 | import { match } from "../src/index"; 2 | 3 | type Person = { 4 | name: string; 5 | age?: number; 6 | props?: { 7 | x: number; 8 | }; 9 | }; 10 | 11 | const value: Person = { 12 | name: "Ajay", 13 | props: { 14 | x: 34, 15 | }, 16 | }; 17 | 18 | /** 19 | * First an example then explanations. Each pattern has a 20 | * brief explanation of what it matches. 21 | */ 22 | 23 | const result = match(value)( 24 | // some object with name and age, where name is some x === "Ajay" 25 | ({ name: x = "Ajay", age }) => { 26 | return age < 18 ? "Hello young boi!" : "Hello boi!"; 27 | }, 28 | 29 | // some object with name and age, where name is some x === "Ajay" 30 | ({ name, age }) => `Hello ${age} years old ${name}`, 31 | 32 | // some array, where the first element is an object with 33 | // name. Call name "n", call the rest of the array "rest". 34 | ([{ name: n }, ...rest]) => { 35 | return `Hello ${n}, and ${rest.length} others!`; 36 | }, 37 | 38 | // some x equal to "hello" 39 | (x = "Ajay") => "Hello boi!", 40 | 41 | // some x 42 | (x) => `Hello ${x}`, 43 | ); 44 | 45 | console.log(result); 46 | 47 | /** 48 | * You can also import "func", which essentially a shortcut for this 49 | * very common pattern: 50 | * 51 | * let f = (value) => match(value)(...) 52 | * 53 | * The above is equivalent to; 54 | * 55 | * let f = func(...) 56 | */ 57 | 58 | import { func } from "../src/index"; 59 | 60 | const format = func( 61 | (x = 42) => "the answer", 62 | (x = 10) => "diez", 63 | (x = 5) => "one hand", 64 | () => "some number", 65 | ); 66 | 67 | Array.from(Array(20).keys()).map((n) => console.log(format(n))); 68 | 69 | console.log( 70 | match({ members: [1, 2, 3, 4] })( 71 | ({ members: { list: x } }) => console.log("doesn't match"), 72 | ({ members: [x, ...rest] }) => console.log(x, rest), 73 | ), 74 | ); 75 | -------------------------------------------------------------------------------- /jest.config.ts: -------------------------------------------------------------------------------- 1 | // jest.config.ts 2 | import type { Config } from "@jest/types"; 3 | 4 | const config: Config.InitialOptions = { 5 | preset: "ts-jest", 6 | testEnvironment: "node", 7 | verbose: true, 8 | testRegex: "./spec/.*.(js|ts)$", 9 | rootDir: ".", 10 | // automock: true, 11 | }; 12 | 13 | export default config; 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fnmatch", 3 | "version": "1.0.2", 4 | "description": "Function-based matching", 5 | "main": "dist/fnMatch.js", 6 | "types": "dist/index.d.ts", 7 | "scripts": { 8 | "test": "jest", 9 | "build": "npx webpack" 10 | }, 11 | "author": "Kevin Chavez (http://mrkev.github.io)", 12 | "license": "ISC", 13 | "dependencies": { 14 | "astring": "^1.8.6", 15 | "cherow": "^1.6.9", 16 | "fast-deep-equal": "^3.1.3" 17 | }, 18 | "devDependencies": { 19 | "@types/jest": "^29.5.4", 20 | "jest": "^29.6.4", 21 | "prettier": "3.0.3", 22 | "ts-jest": "^29.1.1", 23 | "ts-loader": "^9.4.4", 24 | "ts-node": "^10.9.1", 25 | "typescript": "^5.2.2", 26 | "webpack": "^5.88.2", 27 | "webpack-cli": "^5.1.4" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spec/array_test.js: -------------------------------------------------------------------------------- 1 | const { func } = require("../src"); 2 | 3 | let arrayFunc = func( 4 | ([a, b, c]) => `${a}, ${b}, ${c}`, 5 | ([a, b, ...c]) => `${a}, ${b} [${c}]`, 6 | ([a, b]) => `${a}, ${b}`, 7 | ([a, ...b]) => `${a} [${b}]`, 8 | ([]) => "[]" 9 | ); 10 | 11 | test("ARRAY_TEST_1", () => { 12 | expect(arrayFunc([0, 2, 3, 4, 5])).toBe("0, 2 [3,4,5]"); 13 | }); 14 | 15 | test("ARRAY_TEST_2", () => { 16 | expect(arrayFunc([0, 2, 3, 4])).toBe("0, 2 [3,4]"); 17 | }); 18 | 19 | test("ARRAY_TEST_3", () => { 20 | expect(arrayFunc([0, 2, 3])).toBe("0, 2, 3"); 21 | }); 22 | 23 | test("ARRAY_TEST_4", () => { 24 | expect(arrayFunc([0, 2])).toBe("0, 2 []"); 25 | }); 26 | 27 | test("ARRAY_TEST_5", () => { 28 | expect(arrayFunc([0])).toBe("0 []"); 29 | }); 30 | 31 | test("ARRAY_TEST_6", () => { 32 | expect(arrayFunc([])).toBe("[]"); 33 | }); 34 | 35 | test("nothing", () => { 36 | const nothing = func(([x, ...y]) => console.log(x, y))([]); 37 | expect(nothing).toBe(undefined); 38 | }); 39 | -------------------------------------------------------------------------------- /spec/destructuring_test.js: -------------------------------------------------------------------------------- 1 | const { func } = require("../src"); 2 | 3 | const contacts = [ 4 | { 5 | name: { 6 | first: "Ajay", 7 | }, 8 | last: "Gandhi", 9 | }, 10 | { 11 | name: { 12 | first: "Seunghee", 13 | last: "Han", 14 | }, 15 | }, 16 | { 17 | name: "Evil Galactic Empire, Inc.", 18 | kind: "company", 19 | }, 20 | ]; 21 | 22 | const first_company = func(([{ kind = "company", name }, ..._]) => name); 23 | const first_contact = func( 24 | ([ 25 | { 26 | name: { first }, 27 | }, 28 | ..._ 29 | ]) => first 30 | ); 31 | 32 | test("no company", () => { 33 | expect(first_company(contacts)).toBe(undefined); 34 | }); 35 | 36 | test("first contact", () => { 37 | expect(first_contact(contacts)).toBe("Ajay"); 38 | }); 39 | -------------------------------------------------------------------------------- /spec/function_test.js: -------------------------------------------------------------------------------- 1 | const { match, func } = require("../src"); 2 | 3 | const value = { 4 | name: "Ajay", 5 | value: { 6 | x: 34, 7 | }, 8 | }; 9 | 10 | function destructNotes({ notes }) { 11 | return notes; 12 | } 13 | 14 | let destructErrors = ({ errors }) => errors; 15 | let destructResult = function ({ result }) { 16 | return result; 17 | }; 18 | 19 | let getResult = func(destructNotes, destructErrors, destructResult); 20 | 21 | test("first contact", () => { 22 | expect(getResult({ notes: "This works!" })).toBe("This works!"); 23 | }); 24 | -------------------------------------------------------------------------------- /spec/simple_test.js: -------------------------------------------------------------------------------- 1 | const { func } = require("../src"); 2 | 3 | const simple = func( 4 | () => "undefined", 5 | (_) => "anything" 6 | ); 7 | 8 | test("undefined", () => { 9 | expect(simple()).toBe("undefined"); 10 | }); 11 | 12 | test("anything", () => { 13 | expect(simple(3)).toBe("anything"); 14 | }); 15 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { parseScript } from "cherow"; 2 | import { generate } from "astring"; 3 | import equal from "fast-deep-equal"; 4 | import type { 5 | AssignmentProperty, 6 | Node, 7 | Pattern, 8 | RestElement, 9 | } from "cherow/dist/types/estree"; 10 | 11 | /** 12 | * TODO: 13 | * - Implement own function parser to replace cherow: just needs functions. 14 | * - Implement AST, value comparison to get rid of pretty-printer, eval 15 | */ 16 | 17 | const ast_equals_value = (a: Node, v: unknown): boolean => { 18 | let x; 19 | // I know I know. You're reading this so you care, I'll take 20 | // any correct PR implementing an AST to value comparison 21 | // function that doesn't use eval. 22 | eval("x = " + generate(a)); 23 | return equal(v, x); 24 | }; 25 | 26 | /********************************** Matchers **********************************/ 27 | 28 | /** ({x, y, z}) => ... */ 29 | const matchObjectPattern = ( 30 | v: any, 31 | ps: (AssignmentProperty | RestElement)[], 32 | ) => { 33 | if (typeof v !== "object") return false; 34 | for (var i = 0; i < ps.length; i++) { 35 | const prop = ps[i]; 36 | if (!v.hasOwnProperty((prop as any).key.name)) return false; 37 | if (!matches(v[(prop as any).key.name], (prop as any).value)) return false; 38 | } 39 | return true; 40 | }; 41 | 42 | /** x => ... */ 43 | const matchIdentifier = (v: unknown, n: string) => true; 44 | 45 | /** (x = 5) => ... */ 46 | const matchAssignmentPattern = (v: unknown, r: Node) => { 47 | return ast_equals_value(r, v); 48 | }; 49 | 50 | /** ([h, h2, ...t]) => ... */ 51 | const matchArrayPattern = (v: any, e: Pattern[]) => { 52 | for (let i = 0; i < e.length; i++) { 53 | // there can only be one (last) RestElement by ES standards 54 | if (e[i].type === "RestElement") return true; 55 | if (i < v.length && matches(v[i], e[i])) continue; 56 | return false; 57 | } 58 | // no rest element? lengths must match 59 | return e.length === v.length; 60 | }; 61 | 62 | /** () => ... */ 63 | const matchEmpty = (v: unknown, n: Node) => v === n; // always false? 64 | 65 | /************************************ Main ************************************/ 66 | 67 | const matches = (v: unknown, n: Node) => { 68 | if (n === undefined) return matchEmpty(v, n); 69 | if (n.type === "Identifier") return matchIdentifier(v, n.name); 70 | if (n.type === "ObjectPattern") return matchObjectPattern(v, n.properties); 71 | if (n.type === "AssignmentPattern") { 72 | return matchAssignmentPattern(v, n.right); 73 | } 74 | if (n.type === "ArrayPattern") { 75 | return matchArrayPattern(v, n.elements as any); 76 | } else return false; 77 | }; 78 | 79 | type ZeroCase = () => any; 80 | type OneCase = (arg: any) => any; 81 | type AnyCase = (arg: any) => any | (() => any); 82 | 83 | type MatchResult = [] extends Required< 84 | Parameters 85 | > 86 | ? ReturnType 87 | : ReturnType | undefined; 88 | 89 | export function match(v: VL) { 90 | return (...cases: CS): MatchResult => { 91 | const patterns = cases 92 | .map((pat) => pat.toString()) 93 | .map((str) => 94 | // Trick to make it work with anonymous functions 95 | !str.match(/function\s*\(/) ? str : `let x = ${str}`, 96 | ) 97 | .map((str) => parseScript(str)) 98 | .map(({ body: [node] }) => { 99 | let decl = null; 100 | switch (node.type) { 101 | case "ExpressionStatement": 102 | decl = (node.expression as any).params[0]; 103 | break; 104 | case "FunctionDeclaration": 105 | decl = node.params[0]; 106 | break; 107 | case "VariableDeclaration": 108 | decl = (node as any).declarations[0].init.params[0]; 109 | break; 110 | default: 111 | throw new Error("Invalid pattern: " + node.type); 112 | } 113 | return decl; 114 | 115 | // const decl = ( 116 | // { 117 | // // ArrowFunctionExpression: () => {} 118 | // ExpressionStatement: ({ expression }) => expression.params[0], 119 | // // function x () {} 120 | // FunctionDeclaration: ({ params }) => params[0], 121 | // // FunctionExpression: function () {} (from trick above) 122 | // VariableDeclaration: ({ declarations }) => 123 | // declarations[0].init.params[0], 124 | // } as { [key: string]: (node: Node) => void } 125 | // )[node.type]; 126 | // if (!decl) throw new Error("Invalid pattern: " + node.type); 127 | // return decl(node); 128 | }); 129 | 130 | for (let match = 0; match < patterns.length; match++) { 131 | if (matches(v, patterns[match])) { 132 | return cases[match](v as any); 133 | } 134 | } 135 | 136 | // Can we ensure exhaustiveness? 137 | return undefined as any; 138 | }; 139 | } 140 | 141 | export function func( 142 | ...cases: CS 143 | ) { 144 | return (v: VL) => match(v)(...cases); 145 | } 146 | 147 | ///////////////// WORKS. 148 | /// if () => 2 ........ no undefined in return 149 | /// if not ............... undefined in return 150 | 151 | // type RetT = [] extends Required> 152 | // ? [true, ReturnType] 153 | // : [false, ReturnType | undefined]; 154 | 155 | // declare function foo(...args: CS): RetT; 156 | 157 | // const a = foo( 158 | // (x = "foo") => 2, 159 | // // () => 2, 160 | // ); 161 | 162 | // const x = [() => 2]; 163 | // type Y = Required>; 164 | 165 | // type Foo = [] | [x: unknown]; 166 | 167 | // type X = [] extends Foo ? true : false; 168 | 169 | // const b = match(2)( 170 | // // some object with name and age, where name is some x === "Ajay" 171 | // ({ name: x = "Ajay", age }) => { 172 | // return age < 18 ? "Hello young boi!" : "Hello boi!"; 173 | // }, 174 | 175 | // // some object with name and age, where name is some x === "Ajay" 176 | // ({ name, age }) => `Hello ${age} years old ${name}`, 177 | 178 | // // some array, where the first element is an object with 179 | // // name. Call name "n", call the rest of the array "rest". 180 | // ([{ name: n }, ...rest]) => { 181 | // return `Hello ${n}, and ${rest.length} others!`; 182 | // }, 183 | 184 | // // some x equal to "hello" 185 | // (x = "Ajay") => "Hello boi!", 186 | 187 | // // some x 188 | // (x) => `Hello ${x}`, 189 | 190 | // () => "ello", 191 | // ); 192 | -------------------------------------------------------------------------------- /test/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Document 7 | 8 | 9 | 10 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | const { match, func } = require("../src"); 2 | 3 | const value = { 4 | name: "Ajay", 5 | value: { 6 | x: 34, 7 | }, 8 | }; 9 | 10 | /** 11 | * First an example then explanations. Each pattern has a 12 | * brief explanation of what it matches. 13 | */ 14 | 15 | const result = match(value)( 16 | // some object with name and age, where name is some x === "Ajay" 17 | ({ name: x = "Ajay", age }) => { 18 | return age < 18 ? "Hello young boi!" : "Hello boi!"; 19 | }, 20 | 21 | // some object with name and age, where name is some x === "Ajay" 22 | ({ name, age }) => `Hello ${age} years old ${name}`, 23 | 24 | // some array, where the first element is an object with 25 | // name. Call name "n", call the rest of the array "rest". 26 | ([{ name: n }, ...rest]) => { 27 | return `Hello ${n}, and ${rest.length} others!`; 28 | }, 29 | 30 | // some x equal to "hello" 31 | (x = "Ajay") => "Hello boi!", 32 | 33 | // some x 34 | (x) => `Hello ${x}` 35 | ); 36 | 37 | console.log(result); 38 | 39 | /** 40 | * You can also import "func", which essentially a shortcut for this 41 | * very common pattern: 42 | * 43 | * let f = (value) => match(value)(...) 44 | * 45 | * The above is equivalent to; 46 | * 47 | * let f = func(...) 48 | */ 49 | 50 | const format = func( 51 | (x = 42) => "the answer", 52 | (x = 10) => "diez", 53 | (x = 5) => "one hand", 54 | (_) => "some number", 55 | () => "no number" 56 | ); 57 | 58 | [...Array(20).keys()].map((n) => console.log(format(n))); 59 | 60 | /** 61 | * And match arrays. 62 | */ 63 | 64 | match({ members: [1, 2, 3, 4] })( 65 | ({ members: { list: x } }) => console.log("doesn't match"), 66 | ({ members: [x, ...rest] }) => console.log(x, rest) 67 | ); 68 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "types": ["node", "jest"], 5 | "declaration": true, 6 | "allowJs": true, 7 | "skipLibCheck": true, 8 | "esModuleInterop": true, 9 | "allowSyntheticDefaultImports": true, 10 | "strict": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "module": "commonjs", 13 | "moduleResolution": "node", 14 | "resolveJsonModule": true, 15 | "isolatedModules": true, 16 | "baseUrl": "./src", 17 | "noFallthroughCasesInSwitch": true, 18 | "outDir": "./dist" 19 | }, 20 | "compileOnSave": true, 21 | "include": ["src"] 22 | } 23 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | 3 | const output = { 4 | path: path.resolve(__dirname, "dist"), 5 | filename: "fnMatch.js", 6 | library: "fnMatch", 7 | libraryTarget: "umd", 8 | }; 9 | 10 | const tsSetup = { 11 | resolve: { 12 | extensions: [".ts", ".js"], 13 | }, 14 | module: { 15 | rules: [ 16 | { 17 | test: /\.tsx?$/, 18 | use: "ts-loader", 19 | exclude: /node_modules/, 20 | }, 21 | ], 22 | }, 23 | }; 24 | 25 | const config = { 26 | entry: "./src/index.ts", 27 | optimization: { 28 | minimize: true, 29 | }, 30 | output, 31 | mode: "production", 32 | ...tsSetup, 33 | }; 34 | 35 | // output to both ./dist and ./docs/js 36 | module.exports = [ 37 | config, 38 | { 39 | ...config, 40 | output: { ...output, path: path.resolve(__dirname, "docs", "js") }, 41 | }, 42 | ]; 43 | --------------------------------------------------------------------------------