Skip to content

Commit

Permalink
refactor: adapt to new source-map API
Browse files Browse the repository at this point in the history
  • Loading branch information
ewanharris committed Jun 15, 2021
1 parent b1259b1 commit 2329197
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 46 deletions.
26 changes: 22 additions & 4 deletions Alloy/commands/debugger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var FUNCTIONS = {
original: 'originalPositionFor'
};

module.exports = function(args, program) {
module.exports = async function(args, program) {
// validate arguments
if (args.length === 0) {
U.die('Missing command and source map file');
Expand All @@ -24,17 +24,35 @@ module.exports = function(args, program) {
U.die('You must specify a source origin file (-z, --source) when querying for generated positions');
}

var line = 1;
var column = 1;
if (program.line) {
line = parseInt(program.line, 10);

if (isNaN(line)) {
U.die('--line must be a number');
}
}

if (program.column) {
column = parseInt(program.column, 10);

if (isNaN(column)) {
U.die('--column must be a number');
}
}

var sourceMapFile = args[1];
if (!fs.existsSync(sourceMapFile)) {
U.die('Source map file "' + sourceMapFile + '" does not exist');
}

// read the source map and generate the consumer
var sourceMap = fs.readFileSync(sourceMapFile, 'utf8');
var consumer = new SM.SourceMapConsumer(sourceMap);
var consumer = await new SM.SourceMapConsumer(sourceMap);
var obj = {
line: program.line,
column: program.column
line,
column
};
if (program.source) { obj.source = program.source; }

Expand Down
55 changes: 13 additions & 42 deletions tools/checkmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@
for each map
*/

var async = require('async'),
path = require('path'),
platforms = require('../platforms'),
var path = require('path'),
fs = require('fs'),
os = require('os'),
SM = require('source-map'),
_ = require('lodash');
_ = require('lodash'),
walkSync = require('walk-sync');

scan(path.join(__dirname, '..', 'test', 'projects', 'Harness', 'build', 'map', 'Resources'), '.map', function(err, files) {
// Do something with files that ends in '.ext'.
_.map(files, function(sourceMapFile) {


const resourcesDir = path.join(__dirname, '..', 'test', 'projects', 'Harness', 'build', 'map', 'Resources');
const files = walkSync(resourcesDir, { globs: ['**/*.map']});
(async () => {
for (const file of files) {
const sourceMapFile = path.join(resourcesDir, file);
console.log(path.basename(sourceMapFile));
console.log('------------------------------');
console.log('Generated line -> Original line');
var sourceMap = fs.readFileSync(sourceMapFile, {encoding: 'utf8'}),
lineArray = [];
var smc = new SM.SourceMapConsumer(sourceMap);
var smc = await new SM.SourceMapConsumer(sourceMap);
smc.eachMapping(function (m) {
lineArray.push({gen: m.generatedLine, orig: m.originalLine});
});
Expand All @@ -34,36 +36,5 @@ scan(path.join(__dirname, '..', 'test', 'projects', 'Harness', 'build', 'map', '
console.log(' ' + l.gen + spacer + l.orig);
});
console.log('');
});
});


function scan(dir, suffix, callback) {
fs.readdir(dir, function(err, files) {
var returnFiles = [];
async.each(files, function(file, next) {
var filePath = dir + '/' + file;
fs.stat(filePath, function(err, stat) {
if (err) {
return next(err);
}
if (stat.isDirectory()) {
scan(filePath, suffix, function(err, results) {
if (err) {
return next(err);
}
returnFiles = returnFiles.concat(results);
next();
});
} else if (stat.isFile()) {
if (file.indexOf(suffix, file.length - suffix.length) !== -1) {
returnFiles.push(filePath);
}
next();
}
});
}, function(err) {
callback(err, returnFiles);
});
});
}
}
})();

0 comments on commit 2329197

Please sign in to comment.