> On 5 Mar 2019, at 20.15, Bob Pepin <
b...@pepin.io> wrote:
>
> On 5 Mar 2019, at 12.53, Bram Moolenaar <
Br...@moolenaar.net> wrote:
>>
>> I wonder, is this also possible for Typescript? It's like a better
>> version of Javascript, and its popularity is growing.
>
> How well this works in practice remains to be seen, I will try to play around with it a bit.
>
First results look promising, with the latest vim-duktape git and after downloading typescript.js from
https://raw.githubusercontent.com/Microsoft/TypeScript/master/lib/typescript.js and putting it into a runtimepath directory:
Entering Ex mode. Type "visual" to go to Normal mode.
:duk var ts = require('typescript.js')
:duk var source = 'for(const x of [1, 2, 3]) msg(x)'
:duk var result = ts.transpileModule(source, {})
:duk JSON.stringify(result.outputText)
Duktape result: "for (var _i = 0, _a = [1, 2, 3]; _i < _a.length; _i++) {\r\n
var x = _a[_i];\r\n msg(x);\r\n}\r\n"
:duk var fun = compile(result.outputText, "<inline>", {})
:duk fun()
1
2
3
Performance-wise, we are at 500 ms for require(’typescript.js’) and 9 ms for everything else.
I will see if I can integrate the TypeScript module system with Vim sometime this week.
Bob