@sudoo/marked
Version:
JavaScript & TypeScript code runner in JavaScript, safe with marked territory, asynchronous
43 lines (42 loc) • 2.14 kB
JavaScript
;
/**
* @author WMXPY
* @namespace Operation_VariableDeclaration
* @description Register
*/
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.registerScopeVariableWithValue = exports.registerScopeVariableWithExpression = void 0;
const error_code_1 = require("../../declare/error-code");
const error_1 = require("../../util/error/error");
const registerScopeVariableWithExpression = function (node, variableType, id, expression, scope, currentTrace, nextTrace) {
return __awaiter(this, void 0, void 0, function* () {
if (scope.exist(id)) {
throw (0, error_1.error)(error_code_1.ERROR_CODE.DUPLICATED_VARIABLE, id, node, currentTrace);
}
const value = expression
? yield this.execute(expression, scope, nextTrace)
: undefined;
scope.register(variableType)(id, value);
return value;
});
};
exports.registerScopeVariableWithExpression = registerScopeVariableWithExpression;
const registerScopeVariableWithValue = function (node, variableType, id, value, scope, currentTrace) {
return __awaiter(this, void 0, void 0, function* () {
if (scope.exist(id)) {
throw (0, error_1.error)(error_code_1.ERROR_CODE.DUPLICATED_VARIABLE, id, node, currentTrace);
}
scope.register(variableType)(id, value);
return value;
});
};
exports.registerScopeVariableWithValue = registerScopeVariableWithValue;