js-emacs / js2-refactor.el

A JavaScript refactoring library for emacs
GNU General Public License v3.0
373 stars 47 forks source link

Log location improvements #95

Closed felipeochoa closed 6 years ago

felipeochoa commented 7 years ago

Apologies that this PR contains two separate changes. They're split into one commit each:

  1. bugfix Using js2r-log-this and similar in a single-line function on a return statement inserts the logging call in the wrong location:
arr.forEach(function() { return this.|x })
// becomes
console.log("this.x = ", this.x);
arr.forEach(function() { return this.x })

With this change, it becomes:

arr.forEach(function() {
    console.log("this.x = ", this.x);return this.x })

(Not perfect, but at least correct, and usually enough for a temporary logging call)

  1. enhancement I usually need to include logging statement before the expression, since these are often expect calls. I added an option js2r-always-log-before to use the same placement as return logging calls. It defaults to nil for backward compatibility
felipeochoa commented 6 years ago

I finally got around to updating the tests for this! Better late than never I hope :)