locutusjs / locutus

Bringing stdlibs of other programming languages to JavaScript for educational purposes

Home Page:https://locutus.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

locutus.d.ts : "var" has been reserved .

hookclaw opened this issue · comments

I'm in trouble.
I tried make "locutus.d.ts".
Since the word "var" has been reserved.

You will not be able to consider changing the alias definitions and names .

It did not work .

declare module "locutus" {
    namespace php {
        namespace var {
            export function var_dump(v:string):void;
        }
    }
}

For example,

module.exports['var'] = require('./var')
and
module.exports['Var'] = require('./var')

declare module "locutus" {
    namespace php {
        namespace Var {
            export function var_dump(v:string):void;
        }
    }
}

"net-gopher" too.

err) locutus.php.net-gopher.gopher_parsedir();
ok) locutus.php['net-gopher'].gopher_parsedir();

For example,

        namespace net_gopher {
            export function gopher_parsedir(...args:any[]):any;
        }

What language is this? With the targetted platform, commonjs, you should be able to save the module under any name

Sent from mobile, pardon the brevity.

On 5 mei 2016, at 07:53, hookclaw notifications@github.com wrote:

I'm in trouble.
I tried make "locutus.d.ts".
Since the word "var" has been reserved.

You will not be able to consider changing the alias definitions and names .

It did not work .

declare module "locutus" {
namespace php {
namespace var {
export function var_dump(v:string):void;
}
}
}

For example,

module.exports['var'] = require('./var')
and
module.exports['Var'] = require('./var')

declare module "locutus" {
namespace php {
namespace Var {
export function var_dump(v:string):void;
}
}
}


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub

We rude .

This will be the TypeScript.
TypeScript is , in JavaScript, a language to perform the strong typing.
TypeScript , by compiling , JavaScript is generated , you can use the locutus.

I am creating an application that converts an application written in PHP to TypeScript.
In other words, you can convert an application that was written in PHP to JavaScript.
This application , should be the ones that increase the value of locutus.

Again , we will explain in detail.

For example , if you want to take advantage of locutus/php/var/var_dump.

In TypeScript, declares as follows .

/typings/locutus.d.ts

// https://github.com/kvz/locutus/blob/master/src/index.js
declare module "locutus" {
    namespace X {
        namespace php {
            namespace var { // Error "var"
                function var_dump(v:any):void;
            }
        }
    }
    export = X;
}
// https://github.com/kvz/locutus/blob/master/src/php/index.js
declare module "locutus/php" {
    namespace X {
        namespace var { // Error "var"
            function var_dump(v:any):void;
        }
        namespace net-gopher { // Error "net-gopher"
            function gopher_parsedir(dirent:string):{type:number,title:string,path:string,host:string,port:string};
        }
    }
    export = X;
}
// https://github.com/kvz/locutus/blob/master/src/php/var/index.js
declare module "locutus/php/var" {
    namespace X {
        function var_dump(v:any):void;
    }
    export = X;
}
// https://github.com/kvz/locutus/blob/master/src/php/var/var_dump.js
declare module "locutus/php/var/var_dump" {
    function var_dump(v:any):void;
    export = var_dump;
}

If you want to use them in TypeScript, it will be as follows .

any.ts

import locutus = require('locutus');
import locutus_php = require('locutus/php');
import Var = require('locutus/php/var');
locutus.php.var.var_dump('any');    // Type checking works.
locutus_php.var.var_dump('any');    // Type checking works.
Var.var_dump('any');    // Type checking works.
locutus.php['var'].var_dump('any'); // Type checking will not work .
locutus_php['var'].var_dump('any'); // Type checking will not work .

When you compile a any.ts, it will be as follows .
(In fact , a compile error , no code is generated .)

any.js

define(["require", "exports", 'locutus', 'locutus/php', 'locutus/php/var'], function (require, exports, locutus, locutus_php, Var) {
    "use strict";
    locutus.php.var.var_dump('any');
    locutus_php.var.var_dump('any');
    Var.var_dump('any');
    locutus.php['var'].var_dump('any');
    locutus_php['var'].var_dump('any');
});

Though not a use case we support, I think your problems might be resolved by not creating a namespace for the php extensions. So just importing all functions directly. Either that, or doing something like namespace = extension.replace('-' + '_') + '_ext'.