Git Product home page Git Product logo

js-trailing-closure-toy-compiler's Introduction

js-trailing-closure-toy-compiler

这个简单的编译器可以编译我们在JavaScript中使用的Swift的尾闭包语法,将其变成正常的JavaScript语法。

关于Swift的尾闭包如果你不是很理解,可以参考Swift关于 Closures 的文档

通过这个编译器我们可以将下面的代码:

a(){}

转换为:

a(() => {});

或者将:

a(1, "hello"){ b, c in
    d()
    d{}
    d(1, "hello")
    d(1, "hello"){}
    d(1, "hello"){ e, f in
        g()
    }
}

转换为:

a(1, "hello", (b, c) => {
    d();
    d(() => {});
    d(1, "hello");
    d(1, "hello", () => {});
    d(1, "hello", (e, f) => {
        g()
    })
})

项目的在线演示地址:JavaScript Trailing Closure Toy Compiler

关于项目代码部分的详细解释可以阅读这篇文章:动手写一个简单的编译器:在JavaScript中使用Swift的尾闭包语法

如果你对这个项目有什么建议和意见,欢迎提 issues 或者 Pull requests

这个项目受到 jamiebuildsthe-super-tiny-compiler 项目的启发,参考了里面的一些内容。


Creative Commons License

This work is licensed under a Creative Commons Attribution 4.0 International License.

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.