microvium
Version:
A compact, embeddable scripting engine for microcontrollers for executing small scripts written in a subset of JavaScript.
69 lines • 2.61 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringifySourceMap = void 0;
const path_1 = __importDefault(require("path"));
// export function stringifySourceMap(sourceMap: SourceMap) {
// const aggregated: SourceMap['operations'] = [];
// // Merge adjacent operations with the same source location.
// for (const op of sourceMap.operations) {
// const last = aggregated[aggregated.length - 1];
// if (aggregated.length > 0 &&
// op.start === last.end &&
// sourceEqual(last.source, op.source)
// ) {
// last.end = op.end;
// } else {
// aggregated.push(op);
// }
// }
// const lines: string[] = [];
// const cwd = process.cwd();
// for (const [i, op] of aggregated.entries()) {
// // Gap between operations.
// if (i > 0 && aggregated[i - 1].end !== op.start) {
// lines.push(aggregated[i - 1].end.toString(16).padStart(4, '0'));
// lines.push('');
// }
// lines.push(`${
// op.start.toString(16).padStart(4, '0')
// } ${stringifyLoc(op.source)}`);
// }
// return lines.join('\n');
// function stringifyLoc(loc: IL.OperationSourceLoc){
// return `${
// path.relative(cwd, loc.filename)
// }:${
// loc.line
// }:${
// loc.column + 1
// }`;
// }
// function sourceEqual(a: IL.OperationSourceLoc, b: IL.OperationSourceLoc) {
// return a.filename === b.filename && a.line === b.line && a.column === b.column;
// }
// }
function stringifySourceMap(sourceMap) {
const lines = [];
const cwd = process.cwd();
const operations = sourceMap.operations;
for (const [i, op] of operations.entries()) {
// Gap between operations.
if (i > 0 && operations[i - 1].end !== op.start) {
lines.push(operations[i - 1].end.toString(16).padStart(4, '0'));
lines.push('');
}
lines.push(`${op.start.toString(16).padStart(4, '0')} ${op.op.opcode.padEnd(13, ' ')} ${stringifyLoc(op.source)}`);
}
return lines.join('\n');
function stringifyLoc(loc) {
return `${path_1.default.relative(cwd, loc.filename)}:${loc.line}:${loc.column + 1}`;
}
function sourceEqual(a, b) {
return a.filename === b.filename && a.line === b.line && a.column === b.column;
}
}
exports.stringifySourceMap = stringifySourceMap;
//# sourceMappingURL=source-map.js.map