UNPKG

@sudoo/marked

Version:

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

43 lines (42 loc) 2.3 kB
"use strict"; /** * @author WMXPY * @namespace Operation_BinaryExpression * @description In */ 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.executeInBinaryOperator = void 0; const error_code_1 = require("../../declare/error-code"); const error_1 = require("../../util/error/error"); const sand_class_1 = require("../../variable/sand-class/sand-class"); const sand_class_instance_1 = require("../../variable/sand-class/sand-class-instance"); const sand_map_1 = require("../../variable/sand-map"); const executeInBinaryOperator = function (left, right, scope, trace) { return __awaiter(this, void 0, void 0, function* () { const assertedLeft = left; if (assertedLeft.type !== "Identifier") { throw (0, error_1.error)(error_code_1.ERROR_CODE.IN_BINARY_OPERATION_ONLY_ALLOW_ON_IDENTIFIER, String(left), undefined, trace); } const inOperationRight = yield this.execute(right, scope, trace); if (inOperationRight instanceof sand_map_1.SandMap) { return inOperationRight.has(assertedLeft.name); } if (inOperationRight instanceof sand_class_1.SandClass) { return inOperationRight.staticBody.has(assertedLeft.name); } if (inOperationRight instanceof sand_class_instance_1.SandClassInstance) { return inOperationRight.lookForHas(assertedLeft.name); } throw (0, error_1.error)(error_code_1.ERROR_CODE.IN_BINARY_OPERATION_ONLY_ALLOW_ON_MAP_OR_CLASS, String(inOperationRight), undefined, trace); }); }; exports.executeInBinaryOperator = executeInBinaryOperator;