Skip to content
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

Full Typescript support #51

Merged
merged 9 commits into from Jan 4, 2021
Merged

Conversation

DavidDeSimone
Copy link
Member

@DavidDeSimone DavidDeSimone commented Jan 3, 2021

Opening this PR as a WIP as I work through some design issues - however as of opening this PR, you can run and execute typescript within emacs-ng: Now ready for merge.

Major callout- I had to fork deno to get this working in the way I wanted. I added deno as a submodule to make syncing with upline easy. My changes are trivial and we should be able to merge upstream deno easily.

Update 1: Integrating Typescript was actually much easier than I anticipated. I am removing the WIP from this, and calling it ready for review @yyoncho .

Additions:

  • (eval-js-file) will evaluate your file as typescript if it has a typescript extension. You can force it to evaluate it as typescript with the arguments ("filename" :typescript t)
  • (eval-js) has the ability to execute typescript via (eval-js "let x: string = 'f';" :typescript t)
  • Added two new endpoints, (eval-ts-buffer) and (eval-ts-region), which evaluate their respective domains as typescript.
  • Adding debugging support. You can enable it with (js-initialize :inspect t). Once running, you can open the chrome debugger via chrome://inspect, and connect.
  • Fixed bugs with the lisp.make functions.
  • Enables remote imports - a 'killer' Deno feature. You can now do this (credit to https://deno.land/manual/linking_to_external_code):
import { assertEquals } from "https://deno.land/std@0.83.0/testing/asserts.ts";

assertEquals("hello", "hello");
assertEquals("world", "world");

console.log("Asserted! ✓");

What's really exciting about this is we can add a lot of value to our lisp API doing the following as an example:

main.ts

import * as elisp from './elisp.ts';

let b: elisp.Buffer = elisp.getBufferCreate('basic');
// would error on compile ->
// let b: elisp.Buffer = elisp.getBufferCreate(6);
elisp.setBuffer(b); // would error on compile for setBuffer(4.3333);
elisp.insert("Hello World");
let s: string = elisp.bufferString();

elisp.ts

export type Buffer = {
    len?: number
};

let global = (1,eval)('this');

export function bufferString(): string {
    return global.lisp.buffer_string();
}

export function setBuffer(b: Buffer): void {
    global.lisp.set_buffer(b);
}

export function getBufferCreate(s: string): Buffer {
    return global.lisp.get_buffer_create(s);
}

export function insert(s: string): void {
    global.lisp.insert(s);
}

While we manually have to create the type definitions, it would allow us to have type safety in dealing with elisp types. typescript has a very powerful type system that can handle lisp's dynamic nature.

@DavidDeSimone DavidDeSimone changed the title [WIP] Full Typescript support Full Typescript support Jan 3, 2021
@DavidDeSimone DavidDeSimone merged commit 0c43568 into emacs-ng:master Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants