Skip to content

Commit

Permalink
work on evanw#184: use regex to find uncalled instrumentations
Browse files Browse the repository at this point in the history
  • Loading branch information
stoand committed Mar 1, 2023
1 parent 1702dfc commit 90d9eb8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion inst_experiments/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
./out.js
out.js
3 changes: 1 addition & 2 deletions inst_experiments/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const asdf = 1234;
function asdf2() {
console.log('asdf');


let b = 3;
let c = 4;
let a = b + 1 + c;
Expand All @@ -13,4 +12,4 @@ function asdf2() {
}
}

asdf2();
// asdf2();
23 changes: 21 additions & 2 deletions inst_experiments/run.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
let offsetsCovered = [];
let fs = require('fs');

let out = fs.readFileSync('./out.js', { encoding: 'utf8' })

let offsetsCovered = [ [0, out.split('').length ] ];

function __INST(start, end, expr = undefined) {
offsetsCovered.push([start, end]);
Expand All @@ -7,7 +11,22 @@ function __INST(start, end, expr = undefined) {

global.__INST = __INST;

require('./out.js');
function findInstumentedItems(source) {
let items = source.matchAll(/__INST\((\d+), (null|\d+)/g);

let matches = [];
for (let item of items) {
let start = Number(item[1]);
let end = item[2] == 'null' ? null : Number(item[2]);

matches.push([start, end]);
}

return matches;
}

Function(out)()

console.log('offsets covered:', offsetsCovered);

console.log('all instrumented', findInstumentedItems(out));

0 comments on commit 90d9eb8

Please sign in to comment.