@sudoo/marked
Version:
JavaScript & TypeScript code runner in JavaScript, safe with marked territory, asynchronous
35 lines (34 loc) • 1.29 kB
JavaScript
;
/**
* @author WMXPY
* @namespace Operation
* @description Assignment
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAssignmentOperation = void 0;
const error_code_1 = require("../declare/error-code");
const error_1 = require("../util/error/error");
const getAssignmentOperation = (symbol) => {
switch (symbol) {
case "%=": return null;
case "&=": return null;
case "**=": return null;
case "*=": return (variable, value) => variable.set(variable.get() * value);
case "+=": return (variable, value) => variable.set(variable.get() + value);
case "-=": return (variable, value) => variable.set(variable.get() - value);
case "/=": return (variable, value) => {
if (value === 0) {
throw (0, error_1.error)(error_code_1.ERROR_CODE.CANNOT_DIVIDE_BY_ZERO, symbol);
}
return variable.set(variable.get() / value);
};
case "<<=": return null;
case "=": return (variable, value) => variable.set(value);
case ">>=": return null;
case ">>>=": return null;
case "^=": return null;
case "|=": return null;
}
return null;
};
exports.getAssignmentOperation = getAssignmentOperation;