UNPKG

@sudoo/marked

Version:

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

62 lines (61 loc) 3.32 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.declareVariableStackArray = void 0; const error_code_1 = require("../../declare/error-code"); const error_1 = require("../../util/error/error"); const sand_list_1 = require("../../variable/sand-list"); const register_1 = require("./register"); const declareVariableStackArray = function (node, type, declaration, scope, currentTrace, nextTrace) { return __awaiter(this, void 0, void 0, function* () { if (declaration.id.type !== "ArrayPattern") { throw (0, error_1.error)(error_code_1.ERROR_CODE.INTERNAL_ERROR, "Array 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_list_1.SandList)) { throw (0, error_1.error)(error_code_1.ERROR_CODE.DECLARATION_INIT_TYPE_NOT_MATCHED, declaration.init.type, node, currentTrace); } if (initValue.length < declaration.id.elements.length) { throw (0, error_1.error)(error_code_1.ERROR_CODE.DECLARATION_INIT_SIZE_NOT_MATCHED, initValue.length.toString(), node, currentTrace); } const bindRegisterScopeVariable = register_1.registerScopeVariableWithValue.bind(this); for (let i = 0; i < declaration.id.elements.length; i++) { const pattern = declaration.id.elements[i]; if (!pattern) { throw (0, error_1.error)(error_code_1.ERROR_CODE.UNDEFINED_BESIDES_DECLARATION_NOT_SUPPORT, undefined, node, currentTrace); } switch (pattern.type) { case "Identifier": { const id = pattern.name; const initPattern = initValue.get(i); const value = yield bindRegisterScopeVariable(node, type, id, initPattern, scope, currentTrace); results.push({ id, value }); break; } default: { throw (0, error_1.error)(error_code_1.ERROR_CODE.BESIDES_DECLARATION_NOT_SUPPORT, pattern.type, node, currentTrace); } } } return results; }); }; exports.declareVariableStackArray = declareVariableStackArray;