Giter VIP home page Giter VIP logo

bowlerhatllc / dts2as Goto Github PK

View Code? Open in Web Editor NEW
40.0 40.0 4.0 331 KB

Convert TypeScript definitions (d.ts files) into ActionScript classes and interfaces for use as external libraries with Apache FlexJS

Home Page: https://www.npmjs.com/package/dts2as

License: Apache License 2.0

TypeScript 97.47% JavaScript 2.53%
actionscript apache-flexjs flexjs nextgen-actionscript swc typescript typescript-definitions

dts2as's People

Contributors

joshtynjala 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

Watchers

 avatar  avatar  avatar  avatar

dts2as's Issues

PIXI SWC issue

Hi Josh, when I try to compile this example http://nextgenactionscript.com/tutorials/dts2as-typescript-definitions-with-actionscript/ I got an error. In result I've just one line in the js-release/Main.js: //# sourceMappingURL=./Main.js.map.

Here is the compilation logs (same issue on OS X and Windows):

Aymerics-iMac:PixiAS3 Aymeric$ /Users/Aymeric/Documents/Workspace/SDKs/flex_js/js/bin/asjsc --external-library-path+=lib/pixijs.swc src/Main.as 
Using Falcon codebase: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/js/bin/../..
Using Flex SDK: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/js/bin/../..
Picked up _JAVA_OPTIONS: -Xms1024m -Xmx4096m -XX:MaxPermSize=1024
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=1024; support was removed in 8.0
Compiling file: /Users/Aymeric/Documents/Workspace/HTML5/PixiAS3/bin/js-debug/Main.js
using extern: /Users/Aymeric/Documents/Workspace/HTML5/PixiAS3/bin/js-debug/externs/svg.js
using extern: /Users/Aymeric/Documents/Workspace/HTML5/PixiAS3/bin/js-debug/externs/pixijs.js
using SWC: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/js/libs/js.swc
using SWC: /Users/Aymeric/Documents/Workspace/HTML5/PixiAS3/lib/pixijs.swc
using SWC: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/frameworks/libs/Binding.swc
using SWC: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/frameworks/libs/Charts.swc
using SWC: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/frameworks/libs/Collections.swc
using SWC: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/frameworks/libs/Core.swc
using SWC: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/frameworks/libs/CreateJS.swc
using SWC: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/frameworks/libs/DragDrop.swc
using SWC: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/frameworks/libs/Effects.swc
using SWC: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/frameworks/libs/Flat.swc
using SWC: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/frameworks/libs/Formatters.swc
using SWC: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/frameworks/libs/GoogleMaps.swc
using SWC: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/frameworks/libs/Graphics.swc
using SWC: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/frameworks/libs/HTML.swc
using SWC: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/frameworks/libs/HTML5.swc
using SWC: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/frameworks/libs/JQuery.swc
using SWC: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/frameworks/libs/Mobile.swc
using SWC: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/frameworks/libs/Network.swc
using SWC: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/frameworks/libs/Reflection.swc
using SWC: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/frameworks/libs/Storage.swc
using SWC: /Users/Aymeric/Documents/Workspace/SDKs/flex_js/frameworks/libs/player/21.0/playerglobal.swc
Dependencies calculated for '/Users/Aymeric/Documents/Workspace/HTML5/PixiAS3/bin/js-debug/Main.js'
Dependencies calculated for '/Users/Aymeric/Documents/Workspace/HTML5/PixiAS3/bin/js-debug/org/apache/flex/utils/Language.js'
mai 26, 2016 9:25:14 AM com.google.javascript.jscomp.LoggerErrorManager println
GRAVE: /Users/Aymeric/Documents/Workspace/HTML5/PixiAS3/bin/js-debug/externs/pixijs.js:3613: ERROR - Parse error. Duplicate parameter name "crossorigin"
PIXI.extras.TilingSprite.fromImage = function(imageId, crossorigin, scaleMode, crossorigin, scaleMode) {};
                                             ^

mai 26, 2016 9:25:14 AM com.google.javascript.jscomp.LoggerErrorManager println
GRAVE: /Users/Aymeric/Documents/Workspace/HTML5/PixiAS3/bin/js-debug/externs/pixijs.js:3613: ERROR - Parse error. Duplicate parameter name "scaleMode"
PIXI.extras.TilingSprite.fromImage = function(imageId, crossorigin, scaleMode, crossorigin, scaleMode) {};
                                             ^

mai 26, 2016 9:25:14 AM com.google.javascript.jscomp.LoggerErrorManager printSummary
AVERTISSEMENT: 2 error(s), 0 warning(s)
The project 'Main' has been successfully compiled and optimized.
``

Add argument to enable function parameters and properties to be typed as strict interfaces instead of falling back to Object

TypeScript interfaces are looser than ActionScript interfaces because they allow any object to be passed to function parameters or properties as long as it has the required members. The object's class doesn't need to explicitly implement the interface. ActionScript interfaces must always be explicitly implemented.

dts2as types these parameters or properties as Object so that developers don't need to manually implement the interface. This is usually the most desirable behavior when working with JavaScript libraries, but there may be edge cases where a developer might want to use a strict interface.

Errors when generating swc

Hi Josh, first time trying dts2as and I run into several issues. I'm building on OS X.

dts2as --flexHome /Users/Aymeric/Documents/Workspace/SDKs/flex_js --outSWC pixijs.swc pixi.js.d.ts

usr/local/lib/node_modules/dts2as/bin/cli.js:74
                if (!path.isAbsolute(swcOutputPath)) {
                          ^
TypeError: Object #<Object> has no method 'isAbsolute'
    at Object.<anonymous> (/usr/local/lib/node_modules/dts2as/bin/cli.js:74:27)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/dts2as/bin/dts2as:2:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)

So I commetend this line but then I got:

/usr/local/lib/node_modules/dts2as/bin/cli.js:369
    var result = child_process.spawnSync(compcCommand, compcArgs, {
                               ^
TypeError: Object #<Object> has no method 'spawnSync'
    at compileSWC (/usr/local/lib/node_modules/dts2as/bin/cli.js:369:32)
    at Object.<anonymous> (/usr/local/lib/node_modules/dts2as/bin/cli.js:290:24)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/dts2as/bin/dts2as:2:1)
    at Module._compile (module.js:456:26)

Any ideas?

ast2ts

how to as2ts or as2dts?Planning Support?

Custom types are not found when populating parameters in functions

Trying to generate the SWC file for the PixiJS library d.ts definition found in:

https://github.com/pixijs/pixi-typescript

I got the error:

Error: Type interaction.InteractionEventTypes not found for parameter event in function on.

The type seems to be correctly defined in the namespace, and VSCode correctly represents it with no error warnings:

export namespace interaction {
...
        type InteractionPointerEvents = "pointerdown" | "pointercancel" | "pointerup" | "pointertap" | "pointerupoutside" | "pointermove" | "pointerover" | "pointerout";
        type InteractionTouchEvents = "touchstart" | "touchcancel" | "touchend" | "touchendoutside" | "touchmove" | "tap";
        type InteractionMouseEvents = "rightdown" | "mousedown" | "rightup" | "mouseup" | "rightclick" | "click" | "rightupoutside" | "mouseupoutside" | "mousemove" | "mouseover" | "mouseout" | "mouseover";
        type InteractionEventTypes = InteractionPointerEvents | InteractionTouchEvents | InteractionMouseEvents;
}

I changed all references of this type to string (all located in the DisplayObject class) and the tool correctly generates the SWC file.

Angular Material/AngularJS conversion issue

I am trying to convert the Angular Material typescript definition file to a swc. It has dependencies on AngularJS and JQuery. I have attached the files I am using to this issue. Here are the errors that I am encountering:

C:\p\flexroot\git\flex-asjs\examples\native\TodoMVC\lib>dts2as --flexHome "C:\Pr
ogram Files\Adobe\Adobe Flash Builder 4.7 (64 Bit)\sdks\flexjs_nightly_0.6.0" --
outSWC angularmaterial.swc angularmaterial.d.ts
C:\Users\omuppirala\AppData\Roaming\npm\node_modules\dts2as\bin\parser.js:1712
            throw new Error("Return type " + this.getAS3FullyQualifiedNameFromTS
TypeNode(functionDeclaration.type) + " not found for method " + methodName + "()
 on type " + as3Type.getFullyQualifiedName() + ".");
            ^

Error: Return type ng.auto.IInjectorService not found for method resumeBootstrap
() on type angular.IAngularStatic.
    at TS2ASParser.populateMethod (C:\Users\omuppirala\AppData\Roaming\npm\node_
modules\dts2as\bin\parser.js:1712:19)
    at TS2ASParser.populateMember (C:\Users\omuppirala\AppData\Roaming\npm\node_
modules\dts2as\bin\parser.js:1530:26)
    at C:\Users\omuppirala\AppData\Roaming\npm\node_modules\dts2as\bin\parser.js
:945:19
    at Array.forEach (native)
    at TS2ASParser.populateMembers (C:\Users\omuppirala\AppData\Roaming\npm\node
_modules\dts2as\bin\parser.js:944:17)
    at TS2ASParser.populateInterfaceMembers (C:\Users\omuppirala\AppData\Roaming
\npm\node_modules\dts2as\bin\parser.js:1234:14)
    at TS2ASParser.populatePackageLevelDefinitions (C:\Users\omuppirala\AppData\
Roaming\npm\node_modules\dts2as\bin\parser.js:911:26)
    at C:\Users\omuppirala\AppData\Roaming\npm\node_modules\dts2as\bin\parser.js
:501:22
    at visitEachNode (C:\Users\omuppirala\AppData\Roaming\npm\node_modules\dts2a
s\node_modules\typescript\lib\typescript.js:7252:30)
    at Object.forEachChild (C:\Users\omuppirala\AppData\Roaming\npm\node_modules
\dts2as\node_modules\typescript\lib\typescript.js:7407:24)

Can you please take a look?

angularmaterial.d.ts.txt
jquery.d.ts.txt
angular.d.ts.txt

dts2as and VSCode

How do I get code completion and type definitions from the generated swc in VSCode?

Error when try to convert pixi.js.d.ts to pixijs.swc

D:\HelloPixi>dts2as --flexHome D:\flexjs --outSWC pixijs.swc pixi.js.d.ts
C:\Users\a\AppData\Roaming\npm\node_modules\dts2as\bin\parser.js:437
var result = this._currentSourceFile.text.substring(ts["skipTrivia"](this._currentSourceFile.text, name.pos), name.end);
^

TypeError: Cannot read property 'pos' of undefined
at TS2ASParser.declarationNameToString (C:\Users\a\AppData\Roaming\npm\node_modules\dts2as\bin\parser.js:437:112)
at TS2ASParser.readClass (C:\Users\a\AppData\Roaming\npm\node_modules\dts2as\bin\parser.js:1006:30)
at TS2ASParser.readPackageLevelDefinitions (C:\Users\a\AppData\Roaming\npm\node_modules\dts2as\bin\parser.js:640:41)
at C:\Users\a\AppData\Roaming\npm\node_modules\dts2as\bin\parser.js:548:31
at visitEachNode (C:\Users\a\AppData\Roaming\npm\node_modules\dts2as\node_modules\typescript\lib\typescript.js:7195:30)
at Object.forEachChild (C:\Users\a\AppData\Roaming\npm\node_modules\dts2as\node_modules\typescript\lib\typescript.js:7352:24)
at TS2ASParser.readPackageLevelDefinitions (C:\Users\a\AppData\Roaming\npm\node_modules\dts2as\bin\parser.js:539:24)
at TS2ASParser.readSourceFile (C:\Users\a\AppData\Roaming\npm\node_modules\dts2as\bin\parser.js:225:14)
at C:\Users\a\AppData\Roaming\npm\node_modules\dts2as\bin\parser.js:124:19
at Array.forEach (native)

Tonejs problem

I found this definition as I want to experiment with web audio;

https://raw.githubusercontent.com/lukephills/Typings-Tone/master/tone.d.ts

But I get the following, I think some of the errors are due to needing web audio swc api. Is there a way to add swc deps, I didn't see any?


Teoti@TEOTI-PC /c/SDKs/JSLibs
$ dts2as --flexHome C:/SDKs/FlexJS_0.6-RC2 --outSWC tonejs.swc tone.d.ts
C:\SDKs\JSLibs\dts2as_generated\src\Tone.as:25
Warning: Incompatible initializer value of type 'int' where 'Function' is expected. An initial value of null will be used instead.
public function extend(child:Function, parent:Function = undefined):void {}
                                                         ^

C:\SDKs\JSLibs\dts2as_generated\src\Tone.as:44
Warning: Incompatible initializer value of type 'int' where 'AudioNode' is expected. An initial value of null will be used instead.
public function receive(channelName:String, input:AudioNode = undefined):Tone { return null; }
                                                              ^

C:\SDKs\JSLibs\dts2as_generated\src\Tone\Buffer.as:6
Warning: Incompatible initializer value of type 'int' where 'Function' is expected. An initial value of null will be used instead.
public function Buffer(url:Object = undefined, callback:Function = undefined) {}
                                                                   ^

C:\SDKs\JSLibs\dts2as_generated\src\Tone\Buffer.as:25
Warning: Incompatible initializer value of type 'int' where 'Function' is expected. An initial value of null will be used instead.
public function load(url:String, callback:Function = undefined):Buffer { return null; }
                                                     ^

C:\SDKs\JSLibs\dts2as_generated\src\Tone\Convolver.as:11
Warning: Incompatible initializer value of type 'int' where 'Function' is expected. An initial value of null will be used instead.
public function load(url:String, callback:Function = undefined):Convolver { return null; }
                                                     ^

C:\SDKs\JSLibs\dts2as_generated\src\Tone\Filter.as:6
Warning: Incompatible initializer value of type 'int' where 'String' is expected. An initial value of "0" will be used instead.
public function Filter(freq:Object = undefined, type:String = undefined, rolloff:Number = undefined) {}
                                                              ^

C:\SDKs\JSLibs\dts2as_generated\src\Tone\Note.as:12
Warning: Incompatible initializer value of type 'int' where 'Function' is expected. An initial value of null will be used instead.
public function route(channel:Object, callback:Function = undefined):void {}
                                                          ^

C:\SDKs\JSLibs\dts2as_generated\src\Tone\Note.as:13
Warning: Incompatible initializer value of type 'int' where 'Function' is expected. An initial value of null will be used instead.
public function unroute(channel:Object, callback:Function = undefined):void {}
                                                            ^

C:\SDKs\JSLibs\dts2as_generated\src\Tone\OmniOscillator.as:6
Warning: Incompatible initializer value of type 'int' where 'String' is expected. An initial value of "0" will be used instead.
public function OmniOscillator(frequency:Object = undefined, type:String = undefined) {}
                                                                           ^

C:\SDKs\JSLibs\dts2as_generated\src\Tone\Oscillator.as:6
Warning: Incompatible initializer value of type 'int' where 'String' is expected. An initial value of "0" will be used instead.
public function Oscillator(frequency:Object = undefined, type:String = undefined) {}
                                                                       ^

C:\SDKs\JSLibs\dts2as_generated\src\Tone\Player.as:6
Warning: Incompatible initializer value of type 'int' where 'Function' is expected. An initial value of null will be used instead.
public function Player(url:Object = undefined, onload:Function = undefined) {}
                                                                 ^

C:\SDKs\JSLibs\dts2as_generated\src\Tone\Player.as:30
Warning: Incompatible initializer value of type 'int' where 'Function' is expected. An initial value of null will be used instead.
public function load(url:Object, callback:Function = undefined):Player { return null; }
                                                     ^

C:\SDKs\JSLibs\dts2as_generated\src\Tone\PolySynth.as:6
Warning: Incompatible initializer value of type 'int' where 'Function' is expected. An initial value of null will be used instead.
public function PolySynth(voicesAmount:Object = undefined, voice:Function = undefined) {}
                                                                            ^

C:\SDKs\JSLibs\dts2as_generated\src\Tone\PolySynth.as:12
Warning: Incompatible initializer value of type 'int' where 'Array' is expected. An initial value of null will be used instead.
public function get(params:Array = undefined):void {}
                                   ^

C:\SDKs\JSLibs\dts2as_generated\src\Tone\Sampler.as:22
Warning: Incompatible initializer value of type 'int' where 'String' is expected. An initial value of "0" will be used instead.
public function triggerAttack(sample:String = undefined, time:Object = undefined, velocity:Number = undefined):Sampler { return null; }
                                              ^

C:\SDKs\JSLibs\dts2as_generated\src\Tone\Signal.as:9
Error: Type was not found or was not a compile-time constant: Type.
public function get units():Type { return null; }
                            ^

C:\SDKs\JSLibs\dts2as_generated\src\Tone\Signal.as:10
Error: Type was not found or was not a compile-time constant: Type.
public function set units(value:Type):void {}
                                ^

C:\SDKs\JSLibs\dts2as_generated\src\Tone\Source.as:13
Error: Type was not found or was not a compile-time constant: State.
public function get state():Tone.Source.State { return null; }
                            ^

C:\SDKs\JSLibs\dts2as_generated\src\Tone\Source.as:14
Error: Type was not found or was not a compile-time constant: State.
public function set state(value:Tone.Source.State):void {}
                                ^

C:\SDKs\JSLibs\dts2as_generated\src\Tone\Transport.as:34
Warning: Incompatible initializer value of type 'int' where 'String' is expected. An initial value of "0" will be used instead.
public function nextBeat(subdivision:String = undefined):Number { return 0; }
                                              ^


Could not create SWC file. The generated ActionScript contains compile-time errors.

Teoti@TEOTI-PC /c/SDKs/JSLibs
$

Windows 10: "no such file or directory" and "was unexpected at this time" errors

SWC will not build:
Following the exact same steps as the dts2as example here, and using the exact same ts-d file : http://nextgenactionscript.com/tutorials/dts2as-typescript-definitions-with-actionscript/

This results in the following error:

G:\rs\typescript\pixi>dts2as --outSWC pixijs.swc pixi.js.d.ts

fs.js:584

return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);

               ^

Error: ENOENT: no such file or directory, open 'G:\rs\typescript\pixi\dts2as_generated\pixijs.js'
at Error (native)
at Object.fs.openSync (fs.js:584:18)
at Object.fs.writeFileSync (fs.js:1224:33)
at Object. (C:\Users\Tommy\AppData\Roaming\npm\node_modules\dts2as\bin\cli.js:258:4)
at Module._compile (module.js:425:26)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)

Same error happens for most tested ts typedefinition files.
Using Node-js 5.1.0 on Windows 10 with [email protected]

There is no "dts2as_generated" folder, and using the option -outDir does not create one either.

Using Node 4.2.2 the error is different:

The SWC could not be created. The generated ActionScript contains compile-time errors."
..and with 4.2.2 using the -outDir option sometimes .as files are created.

Have tested on several win10 computers, and the error is the same...

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.