@sudoo/marked
Version:
JavaScript & TypeScript code runner in JavaScript, safe with marked territory, asynchronous
41 lines (40 loc) • 2.02 kB
JavaScript
;
/**
* @author WMXPY
* @namespace Evaluate
* @description Static Block
*/
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.staticBlockEvaluation = exports.mountStaticBlock = void 0;
const error_code_1 = require("../declare/error-code");
const error_1 = require("../util/error/error");
const trace_class_1 = require("../variable/trace/trace-class");
const variable_1 = require("../declare/variable");
const mountStaticBlock = (sandbox) => {
sandbox.mount("StaticBlock", exports.staticBlockEvaluation);
};
exports.mountStaticBlock = mountStaticBlock;
const staticBlockEvaluation = 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);
}
const nextTrace = trace.stack(node);
const subScope = scope.child();
subScope.register(variable_1.VARIABLE_TYPE.CONSTANT)(trace.sandClass.className, trace.sandClass.staticBody);
subScope.replaceThis(trace.sandClass.staticBody);
for (const statement of node.body) {
yield this.execute(statement, subScope, nextTrace);
}
});
};
exports.staticBlockEvaluation = staticBlockEvaluation;