UNPKG

easy-api.ts

Version:

A powerful library to create your own API with ease.

1 lines 1.35 kB
Object.defineProperty(exports,"__esModule",{value:!0});let APIFunction_1=require("../../classes/structures/APIFunction"),Error_1=require("../../classes/structures/Error"),Util_1=require("../../classes/internal/Util"),STATEMENTS_DIR=__dirname.replace(/core/g,"xtry");class TryStatement extends APIFunction_1.APIFunction{name="$xtry";description="Executes a try statement.";parameters=[{name:"Code",description:"Statement code to be executed.",type:APIFunction_1.ParamType.String,required:!0,rest:!1,defaultValue:null}];usage="$xtry[code]";returns=APIFunction_1.ParamType.Unknown;compile=!1;aliases=[];async run(e,[t]){(n=e.extend()).functions.clear();var r=[],n=(n.setInternalVar("eats:try_statement",r),n.functions.load(STATEMENTS_DIR,e=>void 0!==e.parent&&e.parent.name===this.name),await Util_1.Util.resolveCode(n,t),"$ensure"===r.at(-1)?.name?r.pop()??null:null),t=r.shift(),r=r.shift();if(!t||"$begin"!==t.name)throw new Error_1.IllegalStatementError(this,"$begin",t?.name??"none");if(!r||"$rescue"!==r.name)throw new Error_1.IllegalStatementError(this,"$rescue",r?.name??"none");if(n&&"$ensure"!==n.name)throw new Error_1.IllegalStatementError(this,"$ensure",n.name);try{await Util_1.Util.resolveCode(e,t.code)}catch(t){await Util_1.Util.resolveCode(e,r.code)}finally{n&&await Util_1.Util.resolveCode(e,n.code)}}}exports.default=TryStatement;