0

I recently found a bit of code in our node.js/electron application:

    async function doStuff(pkg, name) {
        await fsExtra.remove, path.join(pkg, name);
    }

I am not a JS guru and would really appreciate the help. Does this code even do anything?

I kind of think that it means a call to fsExtra.remove with no arguments, and creating a file path from pkg and name and then throwing this path away. So to me it looks like the code doesn't do anything. Is this correct or am I missing something?

Thanks in advance!

UPDATE: Problem solved, thank you!

Dmitri Trofimov
  • 753
  • 3
  • 14
  • 1
    [What does this symbol mean in JavaScript?](https://stackoverflow.com/questions/9549780/what-does-this-symbol-mean-in-javascript/) -> _Comma operator_ – Andreas Mar 10 '21 at 09:47
  • 3
    This code doesn't do anything except that it will reject the promise it returns if `fsExtra` does not exist (it does not call `fsExtra.remove()`) or if `path.join()` throws for any reason. Otherwise, it just resolves with `undefined`. I can think of no good reason to code this way. – jfriend00 Mar 10 '21 at 09:50
  • 1
    Comma separated statements mean to execute both statements in order and the resulting value is the value of the last statement. – jfriend00 Mar 10 '21 at 09:51
  • 2
    _"I recently found a bit of code **in our** node.js/electron application"_ - Get the person responsible for that piece of code that doesn't do anything useful and ask him/her about it. – Andreas Mar 10 '21 at 09:53
  • 1
    This looks like it's supposed to be `return fsExtra.remove(path.join(pkg, name))`. – jfriend00 Mar 10 '21 at 09:54
  • Thanks guys! With your help I now understand how it works and what it does. What got me confused is when I change it to `return fsExtra.remove(path.join(pkg, name))` then it breaks stuff. I also looked at the evolution of this function and before it was `q.nfcall(fsExtra.remove, path.join(pkg, name))`, but at some point it changed. And then some other code changed and now making this function correct breaks stuff. So I'll need to fix both of the things. – Dmitri Trofimov Mar 10 '21 at 10:11

0 Answers0