Skip to content

Commit

Permalink
Support transpilation of Printer
Browse files Browse the repository at this point in the history
  • Loading branch information
tyru committed Nov 22, 2017
1 parent 29cf46a commit b055fa7
Show file tree
Hide file tree
Showing 4 changed files with 1,594 additions and 14 deletions.
13 changes: 9 additions & 4 deletions js/jscompiler.vim
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ function s:JavascriptCompiler.compile_function(node)
unlet rlist[-1]
let va = 1
endif
if left =~ '^\(VimLParser\|ExprTokenizer\|ExprParser\|LvalueParser\|StringReader\|Compiler\|RegexpParser\)\.'
if left =~ '^\(VimLParser\|ExprTokenizer\|ExprParser\|LvalueParser\|StringReader\|Compiler\|RegexpParser\|Printer\)\.'
let [_0, klass, name; _] = matchlist(left, '^\(.*\)\.\(.*\)$')
if name == 'new'
return
Expand Down Expand Up @@ -344,10 +344,10 @@ function s:JavascriptCompiler.compile_let(node)
call self.out('function LvalueParser() { ExprParser.apply(this, arguments); this.__init__.apply(this, arguments); }')
call self.out('LvalueParser.prototype = Object.create(ExprParser.prototype);')
return
elseif left =~ '^\(VimLParser\|ExprTokenizer\|ExprParser\|LvalueParser\|StringReader\|Compiler\|RegexpParser\)$'
elseif left =~ '^\(VimLParser\|ExprTokenizer\|ExprParser\|LvalueParser\|StringReader\|Compiler\|RegexpParser\|Printer\)$'
call self.out('function %s() { this.__init__.apply(this, arguments); }', left)
return
elseif left =~ '^\(VimLParser\|ExprTokenizer\|ExprParser\|LvalueParser\|StringReader\|Compiler\|RegexpParser\)\.'
elseif left =~ '^\(VimLParser\|ExprTokenizer\|ExprParser\|LvalueParser\|StringReader\|Compiler\|RegexpParser\|Printer\)\.'
let [_0, klass, name; _] = matchlist(left, '^\(.*\)\.\(.*\)$')
call self.out('%s.prototype.%s %s %s;', klass, name, op, right)
return
Expand Down Expand Up @@ -798,6 +798,10 @@ function s:JavascriptCompiler.compile_identifier(node)
let name = 'a000'
elseif name == 'v:val'
let name = 'vval'
elseif name == 'a:0'
let name = 'a000.length'
elseif name =~ '^a:[1-9]$'
let name = 'a000[' . (str2nr(name[2:]) - 1) . ']'
elseif name =~ '^[sa]:'
let name = name[2:]
elseif name == 'self'
Expand Down Expand Up @@ -859,7 +863,8 @@ function! s:convert(in, out) abort
\ ' module.exports = {',
\ ' VimLParser: VimLParser,',
\ ' StringReader: StringReader,',
\ ' Compiler: Compiler',
\ ' Compiler: Compiler,',
\ ' Printer: Printer',
\ ' };',
\ '}',
\ ]
Expand Down
Loading

0 comments on commit b055fa7

Please sign in to comment.