Skip to content

Commit

Permalink
wip: support for remove empty block statements
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronm-2112 committed Jan 30, 2025
1 parent d3693eb commit ac9fb82
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/renderer/src/scripts/cleanupScripts/removeUnused.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,29 @@ module.exports = function(fileInfo, api) {
// .remove();

// transform identifiers matching the line and column from the esLint list of items to transform
root.find(j.Identifier, { name: 'path' })
.forEach(path => {
const start = path?.node?.loc?.start;
if(start) {
console.log(start)
if(start.line === line && start.column === column - 1) {
hits = hits + 1;
j(path).replaceWith(j.memberExpression(j.identifier('window'), j.identifier('path')));
}
}
});
// root.find(j.Identifier, { name: 'path' })
// .forEach(path => {
// const start = path?.node?.loc?.start;
// if(start) {
// console.log(start)
// if(start.line === line && start.column === column - 1) {
// hits = hits + 1;
// j(path).replaceWith(j.memberExpression(j.identifier('window'), j.identifier('path')));
// }
// }
// });


// Remove empty block statements
root.find(j.BlockStatement)
.filter(path => path.node.body.length === 0)
.forEach(path => {
.filter( path => {
const start = path.node.loc.start;
console.log(`Removing empty block statement at line ${start.line}, column ${start.column}`);
j(path).remove();
});
if (start.line === line) {
hits = hits + 1;
return path;
}
}).remove()

});

console.log(`Total hits for path: ${hits}`);
Expand Down

0 comments on commit ac9fb82

Please sign in to comment.