Skip to content

Commit

Permalink
feat(collectcalls): include the location of the code
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz committed Aug 30, 2019
1 parent 8b59c5d commit 1ab1eab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/combineVisitors.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ export default function combineVisitors(visitors) {
});
}

return (path, options) => {
return (path, options, state) => {
path.traverse(combinedVisitors, {
state,
options,
functionCounters: path.functionCounters,
});
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default () => ({

try {
for (const visitor of visitors) {
visitor(path, options);
visitor(path, options, state);
}
} catch (err) {
throw err;
Expand Down
12 changes: 10 additions & 2 deletions src/visitors/collectCalls.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@ export default {
}

if (stream === null) {
const filePath = osPath.join(__dirname, 'log.js');
const filePath = osPath.join(
__dirname,
`log-${new Date(Date.now()).toISOString().replace(/:/g, '.')}.js`,
);
stream = fs.createWriteStream(filePath, { flags: 'w' });
console.log('Writing calls to ' + filePath);
}

stream.write(`const x${++count} = ${generate(path.node).code};\n\n`);
const location = path.node.loc.start;
stream.write(
`// ${this.state.filename}:${location.line}:${location.column}\nconst x${++count} = ${
generate(path.node).code
};\n\n`,
);
},
};

0 comments on commit 1ab1eab

Please sign in to comment.