GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - eternalphane/Swift2TypeScript: Swift4 to TypeScript Transpiler.

BranchesTags
Open more actions menu

Latest commit

 

History

14 Commits
14 Commits

Folders and files

NameName
Last commit message
Last commit date
.vscode
.vscode
 
 
grammar
grammar
 
 
src
src
 
 
static
static
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 
tslint.json
tslint.json
 
 

Repository files navigation

Swift2TS Cross-Platform Solution

This is an open source cross-platform solution which can convert native iOS app written in Swift to cross-platform web app. The build-in Swift4 to TypeScript transpiler is powered by ANTLR4.

WIP

Transpiler Examples

Data Types

  • Numeric Types

    Swift:

    let i: Int = 2, d: Double = 0.33
    var j: Int = i + 2
    print(j)

    TypeScript:

    /**
     * In `Foundation.ts`:
     * interface int extends Number { }
     * interface double extends Number { }
     */
    const i: int = 2, d: double = 0.33;
    let j: int = (i as number) + 2;
    console.log(j)

Functions

  • Argument Label

    Swift:

    func do_sth(code: Int, _ msg: String, extra x: Double) {
        // ...
    }
    do_sth(code: 1, "error", extra: 1.5)

    TypeScript:

    function do_sth(_: { code: int, 1: string, extra: double }): void {
        let code: int = _.code, msg: string = _[1], x: double = _.extra;
        // ...
    }
    do_sth({ code: 1 , 1: 'error', extra: 1.5 });
  • Overloading

    Swift:

    func version(_ str: String) {
        print("version: \(str)")
    }
    func version(_ major: Int, _ minor: Int) {
        print("version: \(major).\(minor)")
    }
    
    func var_dump(_ val: Int) {
        print("[Int] \(val)")
    }
    func var_dump(_ val: String) {
        print("[String] \(val)")
    }
    func var_dump(val x: Int) {
        print("[Int](val) \(x)")
    }

    TypeScript:

    function version(_: { 0: string }): void;
    function version(_: { 0: int, 1: int }): void;
    function version(_: { 0: string } | { 0: int, 1: int }): void {
        if ('string' === typeof _[0]) {
            let str: string = _[0];
            console.log(`version: ${str}`);
        } else if (_[0] instanceof int) {
            let major: int = _[0], minor: int = _[1];
            console.log(`version: ${major}.${minor}`);
        }
    }
    
    function var_dump(_: { 0: int }): void;
    function var_dump(_: { 0: string }): void;
    function var_dump(_: { val: int }): void;
    function var_dump(_: { 0: int } | { 0: string } | { val: int }): void {
        if (_[0] instanceof int) {
            let val: int = _[0];
            console.log(`[Int] ${val}`);
        } else if ('string' === typeof _[0]) {
            let val: string = _[0];
            console.log(`[String] ${val}`);
        } else if (_.val instanceof int) {
            let val: int = _[0];
            console.log(`[Int](val) ${val}`);
        }
    }
  • In-Out Parameters

    Swift:

    func add(_ inc: Int, to x: inout Int) {
        x += inc
    }
    var a: Int = 1
    add(3, to: &a)
    print(a) // prints "4"

    TypeScript:

    function add(_: { 0: int, to: { 0: int } }): void {
        let inc: int = _[0], x: { 0: int } = _.to;
        (x[0] as number) += (inc as number);
    }
    let a: int = 1;
    add({ 0: 3, to: { get 0(): int { return a; }, set 0(_: int) { a = _; } } });
    console.log(a); // prints "4"

About

Swift4 to TypeScript Transpiler.

Resources

Readme
MIT license
Activity

Stars

3 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.