Skip to content

Commit

Permalink
feature: minify: remove-return-undefined: exclude nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed May 9, 2023
1 parent 9061397 commit 59cd0a4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/minify/remove-return-undefinded/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
export const report = () => `Remove 'return undefined'`;

export const match = () => ({
'return undefined': check,
'return void 0': check,
});

export const replace = () => ({
'return undefined': '',
'return void 0': '',
});

function check(vars, {parentPath}) {
if (!parentPath.isBlockStatement())
return false;

return parentPath.parentPath.isFunction();
}
2 changes: 1 addition & 1 deletion test/fixture/function-fix.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
function hello(){}
function hello(){}function getWorld(){if(a)return void 0;return b;}
7 changes: 7 additions & 0 deletions test/fixture/function.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
function hello() {
return undefined;
}

function getWorld() {
if (a)
return undefined;

return b;
}

0 comments on commit 59cd0a4

Please sign in to comment.