vim-vimlparser icon indicating copy to clipboard operation
vim-vimlparser copied to clipboard

[converter]Separate let and define

Open mattn opened this issue 7 years ago • 2 comments

function! s:foo()
  if v:true
    let s = 1
  else
    let s = 2
  endif
endfunction

This script is translated to

(function (s:foo)
  (if v:true
    (let = s 1)
   else
    (let = s 2)))

But this should be

(function (s:foo)
  (let = s 0) ;;; define
  (if v:true
    (let = s 1) ;;; let
   else
    (let = s 2))) ;;; let

This can be fixes with traversing let nodes, maybe.

https://github.com/vim-jp/vim-vimlparser/pull/55

mattn avatar Jul 19 '17 10:07 mattn

Do you mean you want to add other translater or provide traversing utilities for translaters?

This is not needed for VimL->S-like-expression / Python / JavaScript translators. I'm not sure this is the problem of this repository.

But this should be ...

I don't think so. Translater should translate the script as same as possible basically. (except it's some optimization purpose or some other useful purpose.

haya14busa avatar Jul 19 '17 14:07 haya14busa

Yes, I didn't consider exists().

function! s:foo()
  if v:true
    let s = 1
  endif
  if exists('s')
    " blah blah
  endif
endfunction

We can't translate this into js since script author might expect this behavior as is. So we can't prepend define variable.

mattn avatar Jul 19 '17 14:07 mattn