bobpepin / vim

Fork of the official Vim repository, with Duktape JavaScript / ECMAScript support (duktape branch)
http://www.vim.org
8 stars 0 forks source link

use :es and :esfile instead of :duktape and :dukfile #2

Open prabirshrestha opened 5 years ago

prabirshrestha commented 5 years ago

This would allow in the future to easily change the runtime and since scripts should be use feature detection I don't think it would be a problem for them.

bobpepin commented 5 years ago

I had the same thoughts, I didn't want to over engineer to begin with. Two is a crowd so I'll change duk to es for the public API :) Any thoughts on identifying TypeScript and different versions of ES? Right now I just transpile inside require() whenever the file ends in .ts.

prabirshrestha commented 5 years ago

While I do use typescript for all my JS projects, I think embedding typescript in vim would not be a good idea at all due to breaking changes. Breaking changes will cause more pain to plugin authors. https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes. This means we would have to stick with what ever typescript version vim ships with.

Personally I would still ship my plugins as plain JS even if I write in typescript.

bobpepin commented 5 years ago

Ah I see, I have mostly been using it as an ES2017 transpiler that runs on Vanilla ES5 and with a documented ES interface. Using Babel without Node seems to require a deep-dive into the source code :(

prabirshrestha commented 5 years ago

You could easily compile ts to js without any babel.

a.ts

import { b } from './b';

const result = b(1, 2);

b.ts

export function b(x: number, y: number): number {
    return x+ y;
}

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "es2015"
  }
}

This will generate the following with just tsc and no babel configuration.

a.js

import { b } from './b';
var result = b(1, 2);

b.js

export function b(x, y) {
    return x + y;
}

This could be left to the plugin author. for example lot of vim plugins supports running post install task. We could then do Plug 'prabirshrestha/myvimjs-plugin, { 'do': {->myvimjsplugin#install() } }. The install can then run custom build task or even download tar files and unzip it automatically.

bobpepin commented 5 years ago

I was more thinking of a setup similar to Emacs .el / .elc files. Plugins are always shipped as source code so that they are easy to inspect and modify. Duktape bytecode would be cached on the filesystem when modules are loaded, and after they have been transpiled by babel or something similar. The transpiler will also need to run inside Vim in order to provide recent ES features in a REPL or notebook interface.