Skip to content

Add ESM #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion js/jscompiler.vim
Original file line number Diff line number Diff line change
@@ -386,7 +386,9 @@ endfunction

function s:JavascriptCompiler.compile_unlet(node)
let list = map(a:node.list, 'self.compile(v:val)')
call self.out('delete %s;', join(list, ', '))
"For strict mode of JavaScript, we prohibit to delete variables.
"call self.out('delete %s;', join(list, ', '))
call self.out('%s;', join(list, ', '))
endfunction

function s:JavascriptCompiler.compile_lockvar(node)
@@ -864,6 +866,11 @@ function! s:convert(in, out) abort
\ '}',
\ ]
call writefile(head + lines + tail, a:out)
let esmtail = [
\ 'export { VimLParser, StringReader, Compiler };',
\ ]
let esmhead = map(head, { _, line -> substitute(line, "var \\(\\w*\\) = require('\\(\\w*\\)')", 'import \1 from "\2"', 'g')})
call writefile(esmhead + lines + esmtail, substitute(a:out, '\.js', '\.mjs', ''))
catch
throw substitute(v:throwpoint, '\.\.\zs\d\+', '\=s:numtoname(submatch(0))', 'g') . "\n" . v:exception
endtry
5,965 changes: 5,965 additions & 0 deletions js/vimlparser.mjs

Large diffs are not rendered by default.