UNPKG

@sudoo/marked

Version:

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

136 lines (135 loc) 3.92 kB
"use strict"; /** * @author WMXPY * @namespace Parse * @description Snapshot Scope Variable */ Object.defineProperty(exports, "__esModule", { value: true }); exports.parseSnapshotScopeVariable = 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_function_1 = require("../variable/sand-function/sand-function"); const sand_list_1 = require("../variable/sand-list"); const bigint_1 = require("../variable/sand-literal/bigint"); const regexp_1 = require("../variable/sand-literal/regexp"); const sand_map_1 = require("../variable/sand-map"); const variable_1 = require("../variable/variable"); const parseSnapshotScopeVariable = (variable) => { if (!(variable instanceof variable_1.Variable)) { throw (0, error_1.error)(error_code_1.ERROR_CODE.INTERNAL_ERROR, "Scope variable is not variable"); } const value = variable.get(); if (value instanceof bigint_1.SandLiteralBigInt) { return { type: "bigint", value: value.toNativeBigInt(), native: false, mutable: variable.mutable, }; } if (value instanceof sand_class_1.SandClass) { return { type: "class", value: value.body.map, native: false, mutable: variable.mutable, }; } if (value instanceof sand_class_instance_1.SandClassInstance) { return { type: "class-instance", value: value.body.map, native: false, mutable: variable.mutable, }; } if (value instanceof regexp_1.SandLiteralRegExp) { return { type: "regexp", value: value.toNativeRegExp(), native: false, mutable: variable.mutable, }; } if (value instanceof sand_list_1.SandList) { return { type: "list", value: value.list, native: false, mutable: variable.mutable, }; } if (value instanceof sand_map_1.SandMap) { return { type: "map", value: value.map, native: false, mutable: variable.mutable, }; } if (value instanceof sand_function_1.SandFunction) { return { type: "function", value: "[Marked Function]", native: false, mutable: false, }; } if (typeof value === "function") { return { type: "function", value: "[Marked Native Function]", native: true, mutable: variable.mutable, }; } if (typeof value === "number") { return { type: "number", value, native: false, mutable: variable.mutable, }; } if (typeof value === "string") { return { type: "string", value, native: false, mutable: variable.mutable, }; } if (typeof value === "boolean") { return { type: "boolean", value, native: false, mutable: variable.mutable, }; } if (typeof value === "undefined") { return { type: "undefined", value, native: false, mutable: variable.mutable, }; } if (value === null) { return { type: "null", value, native: false, mutable: variable.mutable, }; } return { type: "unknown", value, native: false, mutable: variable.mutable, }; }; exports.parseSnapshotScopeVariable = parseSnapshotScopeVariable;