@jplorg/jpl
Version:
JPL interpreter
78 lines (73 loc) • 2.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.JPLZeroDivisionError = exports.JPLTypeError = exports.JPLTypeConversionError = exports.JPLReferenceError = void 0;
var _types = require("../types");
var _execution = _interopRequireDefault(require("./execution"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function format(value, replacements) {
return replacements.length > 0 ? (0, _types.template)(value, ...replacements) : (0, _types.displayValue)(value);
}
/**
* JPL error type for generic runtime errors.
*
* `value` can by of any type.
* If at least one replacement is specified, the value is formatted as a template.
*/
class JPLRuntimeError extends _execution.default {
constructor(value, ...replacements) {
const message = format(value, replacements);
super(message, 'JPLRuntimeError');
this.value = replacements.length > 0 ? message : (0, _types.normalize)(value);
}
}
var _default = exports.default = JPLRuntimeError;
/**
* JPL runtime error type for type errors.
*
* `value` can by of any type.
* If at least one replacement is specified, the value is formatted as a template.
*/
class JPLTypeError extends JPLRuntimeError {
constructor(value, ...replacements) {
super(`TypeError - ${format(value, replacements)}`);
}
}
/**
* JPL runtime error type for reference errors.
*
* `value` can by of any type.
* If at least one replacement is specified, the value is formatted as a template.
*/
exports.JPLTypeError = JPLTypeError;
class JPLReferenceError extends JPLRuntimeError {
constructor(value, ...replacements) {
super(`ReferenceError - ${format(value, replacements)}`);
}
}
/**
* JPL runtime error type for zero division errors.
*
* `value` can by of any type.
* If at least one replacement is specified, the value is formatted as a template.
*/
exports.JPLReferenceError = JPLReferenceError;
class JPLZeroDivisionError extends JPLRuntimeError {
constructor(value, ...replacements) {
super(`ZeroDivisionError - ${format(value, replacements)}`);
}
}
/**
* JPL runtime error type for type conversion errors.
*
* `value` can by of any type.
* If at least one replacement is specified, the value is formatted as a template.
*/
exports.JPLZeroDivisionError = JPLZeroDivisionError;
class JPLTypeConversionError extends JPLRuntimeError {
constructor(value, ...replacements) {
super(`TypeConversionError - ${format(value, replacements)}`);
}
}
exports.JPLTypeConversionError = JPLTypeConversionError;