comment-value icon indicating copy to clipboard operation
comment-value copied to clipboard

Variable comments confuse expression comments after it

Open bahmutov opened this issue 8 years ago • 1 comments

Seems by inserting statements we break the expressions later

const x = 2
// x:
function add(a, b) {
  return a + b
}
add(x, 3) //>

crashes with

Error: missing line 6 for comment {
  "start": 111,
  "text": ">",
  "from": {
    "line": 7,
    "column": 10
  },
  "to": {
    "line": 7,
    "column": 13
  },
  "filename": "/Users/gleb/git/comment-value/test/combined/index.js",
  "commentStart": ">",
  "index": 0
}
    at lazyAssLogic (/Users/gleb/git/comment-value/node_modules/lazy-ass/index.js:110:14)
    at lazyAss (/Users/gleb/git/comment-value/node_modules/lazy-ass/index.js:115:28)
    at updateComment (/Users/gleb/git/comment-value/src/update.js:64:5)

Removing the variable comment from line 2 solves the crash

const x = 2
// x:
function add(a, b) {
  return a + b
}
add(x, 3) //> 5

bahmutov avatar Jan 29 '17 04:01 bahmutov

Test case in test/combined/index.js

bahmutov avatar Jan 29 '17 05:01 bahmutov