UNPKG

@sudoo/marked

Version:

JavaScript & TypeScript code runner in JavaScript, safe with marked territory, asynchronous

52 lines (51 loc) 2.48 kB
"use strict"; /** * @author WMXPY * @namespace Evaluate * @description Method Definition */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.methodDefinitionEvaluation = exports.mountMethodDefinition = void 0; const error_code_1 = require("../declare/error-code"); const error_1 = require("../util/error/error"); const sand_function_1 = require("../variable/sand-function/sand-function"); const trace_class_1 = require("../variable/trace/trace-class"); const mountMethodDefinition = (sandbox) => { sandbox.mount("MethodDefinition", exports.methodDefinitionEvaluation); }; exports.mountMethodDefinition = mountMethodDefinition; const methodDefinitionEvaluation = function (node, scope, trace) { return __awaiter(this, void 0, void 0, function* () { if (!(trace instanceof trace_class_1.TraceClass)) { throw (0, error_1.error)(error_code_1.ERROR_CODE.TRACE_SHOULD_BE_CLASS_TRACE, void 0, node, trace); } if (node.key.type !== "Identifier") { throw (0, error_1.error)(error_code_1.ERROR_CODE.PROPERTY_SHOULD_BE_IDENTIFIER, "Key", node, trace); } const key = node.key.name; const value = yield this.execute(node.value, scope, trace); if (!(value instanceof sand_function_1.SandFunction)) { throw (0, error_1.error)(error_code_1.ERROR_CODE.INTERNAL_ERROR, void 0, node, trace); } if (node.kind === "constructor") { trace.sandClass.setClassConstructor(value); return true; } if (node.static) { trace.sandClass.staticBody.set(key, value); return true; } trace.sandClass.body.set(key, value); return true; }); }; exports.methodDefinitionEvaluation = methodDefinitionEvaluation;