twing
Version:
First-class Twig engine for Node.js
55 lines (54 loc) • 1.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createBaseError = void 0;
const createBaseError = (name, message, location, source, previous) => {
const baseError = Error(message);
baseError.name = name;
const error = Object.create(baseError, {
location: {
get: () => location
},
source: {
get: () => source
},
previous: {
value: previous
},
rootMessage: {
value: message
},
appendMessage: {
value: (value) => {
message += value;
updateRepresentation();
}
}
});
const updateRepresentation = () => {
let representation = message;
let dot = false;
if (representation.slice(-1) === '.') {
representation = representation.slice(0, -1);
dot = true;
}
let questionMark = false;
if (representation.slice(-1) === '?') {
representation = representation.slice(0, -1);
questionMark = true;
}
representation += ` in "${source.name}"`;
const { line, column } = location;
representation += ` at line ${line}, column ${column}`;
if (dot) {
representation += '.';
}
if (questionMark) {
representation += '?';
}
baseError.message = representation;
};
updateRepresentation();
Error.captureStackTrace(error, exports.createBaseError);
return error;
};
exports.createBaseError = createBaseError;