@sudoo/marked
Version:
JavaScript & TypeScript code runner in JavaScript, safe with marked territory, asynchronous
51 lines (50 loc) • 2.54 kB
JavaScript
;
/**
* @author WMXPY
* @namespace Evaluate
* @description Property 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.propertyDefinitionEvaluation = exports.mountPropertyDefinition = 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 mountPropertyDefinition = (sandbox) => {
sandbox.mount("PropertyDefinition", exports.propertyDefinitionEvaluation);
};
exports.mountPropertyDefinition = mountPropertyDefinition;
const propertyDefinitionEvaluation = 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 subScope = scope.child();
subScope.register(variable_1.VARIABLE_TYPE.CONSTANT)(trace.sandClass.className, trace.sandClass.staticBody);
if (node.static) {
subScope.replaceThis(trace.sandClass.staticBody);
const value = yield this.execute(node.value, subScope, trace);
trace.sandClass.staticBody.set(key, value);
}
else {
subScope.replaceThis(trace.sandClass.body);
const value = yield this.execute(node.value, subScope, trace);
trace.sandClass.body.set(key, value);
}
return true;
});
};
exports.propertyDefinitionEvaluation = propertyDefinitionEvaluation;