@sudoo/marked
Version:
JavaScript & TypeScript code runner in JavaScript, safe with marked territory, asynchronous
53 lines (52 loc) • 2.84 kB
JavaScript
;
/**
* @author WMXPY
* @namespace Operation_VariableDeclaration
* @description Declaration
*/
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.declareVariableStack = void 0;
const error_code_1 = require("../../declare/error-code");
const error_1 = require("../../util/error/error");
const array_1 = require("./array");
const object_1 = require("./object");
const register_1 = require("./register");
const declareVariableStack = function (node, scope, currentTrace, nextTrace) {
return __awaiter(this, void 0, void 0, function* () {
const type = node.kind;
for (const declaration of node.declarations) {
switch (declaration.id.type) {
case "Identifier": {
const results = [];
const id = declaration.id.name;
const bindRegisterScopeVariable = register_1.registerScopeVariableWithExpression.bind(this);
const result = yield bindRegisterScopeVariable(node, type, id, declaration.init, scope, currentTrace, nextTrace);
results.push({ id, value: result });
return results;
}
case "ArrayPattern": {
const bindingDeclareVariableStackArray = array_1.declareVariableStackArray.bind(this);
return yield bindingDeclareVariableStackArray(node, type, declaration, scope, currentTrace, nextTrace);
}
case "ObjectPattern": {
const bindingDeclareVariableStackObject = object_1.declareVariableStackObject.bind(this);
return yield bindingDeclareVariableStackObject(node, type, declaration, scope, currentTrace, nextTrace);
}
default: {
throw (0, error_1.error)(error_code_1.ERROR_CODE.BESIDES_DECLARATION_NOT_SUPPORT, declaration.id.type, node, currentTrace);
}
}
}
throw (0, error_1.error)(error_code_1.ERROR_CODE.INTERNAL_ERROR, "No Declaration", node, currentTrace);
});
};
exports.declareVariableStack = declareVariableStack;