UNPKG

@sudoo/marked

Version:

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

56 lines (55 loc) 3.1 kB
"use strict"; /** * @author WMXPY * @namespace Operation_VariableDeclaration * @description Array */ 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.declareVariableStackObject = void 0; const error_code_1 = require("../../declare/error-code"); const error_1 = require("../../util/error/error"); const sand_map_1 = require("../../variable/sand-map"); const register_1 = require("./register"); const declareVariableStackObject = function (node, type, declaration, scope, currentTrace, nextTrace) { return __awaiter(this, void 0, void 0, function* () { if (declaration.id.type !== "ObjectPattern") { throw (0, error_1.error)(error_code_1.ERROR_CODE.INTERNAL_ERROR, "Object Pattern Only", node, currentTrace); } const results = []; if (typeof declaration.init === "undefined" || declaration.init === null) { throw (0, error_1.error)(error_code_1.ERROR_CODE.UNDEFINED_BESIDES_DECLARATION_NOT_SUPPORT, undefined, node, currentTrace); } const initValue = yield this.execute(declaration.init, scope, nextTrace); if (!(initValue instanceof sand_map_1.SandMap)) { throw (0, error_1.error)(error_code_1.ERROR_CODE.DECLARATION_INIT_TYPE_NOT_MATCHED, declaration.init.type, node, currentTrace); } const bindRegisterScopeVariable = register_1.registerScopeVariableWithValue.bind(this); for (const pattern of declaration.id.properties) { if (!pattern) { throw (0, error_1.error)(error_code_1.ERROR_CODE.UNDEFINED_BESIDES_DECLARATION_NOT_SUPPORT, undefined, node, currentTrace); } if (pattern.type !== "Property") { throw (0, error_1.error)(error_code_1.ERROR_CODE.BESIDES_DECLARATION_NOT_SUPPORT, pattern.type, node, currentTrace); } if (pattern.key.type !== "Identifier") { throw (0, error_1.error)(error_code_1.ERROR_CODE.BESIDES_DECLARATION_NOT_SUPPORT, pattern.key.type, node, currentTrace); } const id = pattern.key.name; const initPattern = initValue.get(id); const value = yield bindRegisterScopeVariable(node, type, id, initPattern, scope, currentTrace); results.push({ id, value }); } return results; }); }; exports.declareVariableStackObject = declareVariableStackObject;