GithubHelp home page GithubHelp logo

pcan / reflec-ts Goto Github PK

View Code? Open in Web Editor NEW
119.0 119.0 3.0 264.51 MB

TypeScript compiler with Reflection capabilities

License: Other

TypeScript 99.98% JavaScript 0.01% PowerShell 0.01% Batchfile 0.01% Shell 0.01% HTML 0.01% Groovy 0.01%
metadata reflection types typescript

reflec-ts's People

Contributors

abubakerb avatar ahejlsberg avatar ahmad-farid avatar aozgaa avatar billti avatar chrisbubernak avatar cyrusnajmabadi avatar danielrosenwasser avatar danquirk avatar dickvdbrink avatar herringtondarkholme avatar ivogabe avatar jramsay avatar jsonfreeman avatar mhegazy avatar pcan avatar rbuckton avatar riknoll avatar ryancavanaugh avatar sandersn avatar saschanaz avatar sheetalkamat avatar shyykoserhiy avatar steveluc avatar tinganho avatar vladima avatar vvakame avatar weswigham avatar yuichinukiyama avatar zhengbli 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

reflec-ts's Issues

Its not good idea to extends Interfaces , classes with reflector functions

Hello, thank you for this project.

Now we can write somthng like this

interface UiButtonProps {
    description: string;
}

for (let member of UiButtonProps.members) {
    let memberDescription = `Member ${member.name} is ${member.type.kind}`;
    if (member.type.kind === 'interface' || member.type.kind === 'class') {
        memberDescription += ' - name: ' + (<NamedType>member.type).name;
    }
    console.log(memberDescription);
}

But i think it's not good;
Standard reflection framework just provide functions to reflect.
And we can just pass Class or Interface to function;

If your aim - jsut provide intellisence for usage reflector functions - we can create any type like Type in .Net reflection

 interface Type {
     members: Array<any>,
     /...
 }
// and then 

import reflect from 'ts-reflect';
class MyTestClass{
}
reflect(MyTestClass).members.forEach( member=> console.log(member));

I know tha we can't pass interface to function cause it's typescript syntax limitation;

What do you think about it?

Use target and module for Reflection.js

Read target and module options in compilerOptions when emitting Reflection.js. For example, there is no need to do environment checks like typeof module == 'object' ... if we are targeting to a particular module system.

Dynamic loading of classes by name

Implement dynamic class loading in classForName. We want to achieve something like this

let clazz = Reflection.classForName("folder1.folder2.sourceFile#module1.MyClass");
let ctor = clazz.getConstructor();
let obj = new ctor();

Note that folder1/folder2/sourceFile.js has not been loaded yet, so registerClass has not been executed yet for MyClass.

At the moment, we have to deal with:

  • node/commonjs: synchronous loading (we can leave the API as is)
  • AMD: if we want to support AMD, classForName has to return something like a promise, or take a callback function as argument.

We would not want to make two different APIs for the two systems. One possible solution may be an async function version of Reflection.classForName, but this will force us to drop support for targets before ES2015 (due to a TypeScript compiler rule).

Suggestions are welcome.

Write flat type package in Reflection.js

Instead of building an object hierarchy for types in Reflection.js, use a flat structure like the following:

Reflection.$libs['default'] = {
    'main' : {
        'MainClass': _l[1],
    },
    'common.file1' : {
        'MyClass': _l[2],
        'module1.MyInterface': _l[3],
    },
    'common.file2' : {
        'MyService': _l[0],
    }
};

Reflection.js is broken when using type reference with parameters

Reflection.js will contain invalid code if there is a parameterized type for some field.
The following code reproduces it:

interface TypedInterface<T> {
    a: T;
}
interface Broken {
    brokenField: TypedInterface<string>;
}

Expected output in Reflection.js:

    _t.kind = 'reference';
    _t.type = _l[3];
    _t.typeParameters = [_type_string, ];

Actual output in Reflection.js:

    _t.kind = 'reference';
    _t.type = _l[3];
    typeParameters: [_type_string, ],

Add classForName and interfaceForName

Add classForName and interfaceForName to the Reflection namespace. Each of these function will accept one or two strings:

  • One string: will have this format folder1.folder2.fileName#module1.module2.ClassOrInterface
  • Two strings: will have this format folder1.folder2.fileName and module.module2.ClassOrInterface

and it will return the Class or Interface object, respectively.

Add RegisterClass decorator

Create a RegisterClass decorator that delegates to registerClass function. When experimentalDecorators is enabled, we can decorate classes instead of passing constructors to registerClass.

Remove $reflection synthetic variable

Remove $reflection variable and introduce constants for interfaces. Each module won't export $reflection any more, so each class/interface will preserve its level of visibility.
In order to get class metadata, a new method getClass() will be added to Function.

Error: Debug Failure. False expression: length must be non-negative, is NaN

Using reflec-ts 0.3.9 with Node 8.6.0. I have the following basic project structure:

src/tests.js

class testClassA {
    a: string
}

console.log(new testClassA());

tsconfig.json

{
    "compileOnSave": true,
    "include": [
        "src/*"
    ],
    "compilerOptions": {
        "target": "ES2017",
        "noImplicitAny": true,
        "removeComments": false,
        "sourceMap": true,
        "outDir": "build"
    },
    "reflectionEnabled": true
}

I'm running this command:

node d:\git\test-project\node_modules\reflec-ts\bin\tsc -p d:\git\test-project

I get the following output:

d:\git\test-project\node_modules\reflec-ts\lib\tsc.js:53636
throw e;
^

Error: Debug Failure. False expression: length must be non-negative, is NaN
at Object.assert (d:\git\test-project\node_modules\reflec-ts\lib\tsc.js:2834:23)
at Object.createFileDiagnostic (d:\git\test-project\node_modules\reflec-ts\lib\tsc.js:2004:15)
at createDiagnosticForNodeInSourceFile (d:\git\test-project\node_modules\reflec-ts\lib\tsc.js:7304:19)
at Object.createDiagnosticForNode (d:\git\test-project\node_modules\reflec-ts\lib\tsc.js:7299:16)
at error (d:\git\test-project\node_modules\reflec-ts\lib\tsc.js:22449:22)
at resolveName (d:\git\test-project\node_modules\reflec-ts\lib\tsc.js:22891:25)
at getResolvedSymbol (d:\git\test-project\node_modules\reflec-ts\lib\tsc.js:29693:67)
at checkIdentifier (d:\git\test-project\node_modules\reflec-ts\lib\tsc.js:30742:26)
at checkExpressionWorker (d:\git\test-project\node_modules\reflec-ts\lib\tsc.js:34344:28)
at checkExpression (d:\git\test-project\node_modules\reflec-ts\lib\tsc.js:34328:42)
The terminal process terminated with exit code: 1

If I change reflectionEnabled to false in tsconfig.json then the build succeeds. Not sure what I'm doing wrong! It's weird because I've successfully used reflec-ts before, but it was on a different PC.

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.