@sudoo/marked
Version:
JavaScript & TypeScript code runner in JavaScript, safe with marked territory, asynchronous
73 lines (72 loc) • 2.49 kB
JavaScript
;
/**
* @author WMXPY
* @namespace Log
* @description Log Recorder
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.MarkedLogRecorder = void 0;
class MarkedLogRecorder {
static create() {
return new MarkedLogRecorder();
}
constructor() {
this._executeLogs = [];
}
get length() {
return this._executeLogs.length;
}
get executeLogs() {
return this._executeLogs;
}
putExecuteLog(log) {
this._executeLogs.push(log);
return this;
}
findExecuteLogsByNodeType(type) {
return this._executeLogs.filter((log) => {
return log.node.type === type;
});
}
findExecuteLogsByNodeTypes(types) {
return this._executeLogs.filter((log) => {
return types.includes(log.node.type);
});
}
findExecuteLogsByLineBefore(line) {
return this._executeLogs.filter((log) => {
if (log.node.loc === null
|| typeof log.node.loc === "undefined") {
return false;
}
const locationFinder = log.trace.ensureLocationFinder();
const actualPosition = locationFinder.findSourceLocation(log.node.loc.end, log.node);
return actualPosition.line <= line;
});
}
findExecuteLogsByLingAfter(line) {
return this._executeLogs.filter((log) => {
if (log.node.loc === null
|| typeof log.node.loc === "undefined") {
return false;
}
const locationFinder = log.trace.ensureLocationFinder();
const actualPosition = locationFinder.findSourceLocation(log.node.loc.start, log.node);
return actualPosition.line >= line;
});
}
findExecuteLogsByLineBetween(startLine, endLine) {
return this._executeLogs.filter((log) => {
if (log.node.loc === null
|| typeof log.node.loc === "undefined") {
return false;
}
const locationFinder = log.trace.ensureLocationFinder();
const actualStartPosition = locationFinder.findSourceLocation(log.node.loc.start, log.node);
const actualEndPosition = locationFinder.findSourceLocation(log.node.loc.end, log.node);
return actualStartPosition.line >= startLine
&& actualEndPosition.line <= endLine;
});
}
}
exports.MarkedLogRecorder = MarkedLogRecorder;