Code Monkey home page Code Monkey logo

go-typescript's Introduction

This package provides a thin wrapper around goja (a native Javascript runtime for Go). There are no direct dependencies besides goja, and testify (for testing only). This package supports the following features:

  • Typescript compilation and evaluation.
  • A context-aware evaluation API to support cancellation.
  • AMD-style modules using the built-in Almond module loader.
  • Custom Typescript version registration with built-in support for versions 3.8.3, 3.9.9, 4.1.2, 4.1.3, 4.1.4, 4.1.5, 4.2.2, 4.2.3, 4.2.4, and 4.7.2.
  • 90%+ test coverage

Installation

go get github.com/clarkmcc/go-typescript

Examples

go-typescript's People

Contributors

clarkmcc avatar ptxmac avatar tommyo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

go-typescript's Issues

Question about typescript versions ๐Ÿ˜„

First of all, this is REALLY helpful!!!
Thank you for taking the time to build this awesome library!

My question is around how you acquired the typescript files in the versions directory.
I was following a thread on goja and it seems like these files are a minified version of typescripServices.js. Did you do anything special to compress/minify them so they work with goja? I couldn't get it to work out of the box.

Again, thank you for the hard work! ๐Ÿš€

Failing to evaluate an AMD module

//md.ts

    function factory(exports) {
    class Person {
        name: string;
    
        constructor(name: string) {
            this.name = name
        }
    
        public greet(): string {
            return `Hello ${this.name}!`
        }
    }
        exports.multiply = Person ;
    }
    define("myModule", ["exports"], factory);

//md_test.ts

    import { Person } from 'myModule';
    const me = new Person("John Doe******")
    me.greet()

//main.go

    func buildCommand2() {
        mdFile, _ := os.Open("./tscript/md2.ts")
        if mdFile == nil {
    
        }
        mdTestFile, _ := os.Open("./tscript/md2_test.ts")
        js, e := typescript.Transpile(mdTestFile)
        fmt.Println(e, js)
    
        result, err := typescript.Evaluate(mdTestFile,
	        typescript.WithTranspile(),
	        typescript.WithAlmondModuleLoader(),
	        typescript.WithEvaluateBefore(mdFile),
        )
        if err != nil {
	        panic(err)
        }
        fmt.Println(result.ToInteger())
    }

AMD Module Loading

In order to evaluate with access to Typescript bundles, add support for an optional AMD module loader.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.