Git Product home page Git Product logo

Comments (12)

tbosch avatar tbosch commented on April 19, 2024

Changed parser to just eat up the generics, no change to the AST yet.
See https://github.com/angular/angular/blob/master/tools/js2dart/src/parser.js#L12

from angular.

vicb avatar vicb commented on April 19, 2024

Traceur has just added support for generics, see google/traceur-compiler@32aadd5

from angular.

Alxandr avatar Alxandr commented on April 19, 2024

This means @InjectPromise(UserList) userList should be changed to userList: Promise<UserList> with regards to di injection, right?

from angular.

vojtajina avatar vojtajina commented on April 19, 2024

Here is my understanding of the state of this feature (@vicb can correct me):
Traceur does parse the generics (type arguments). That is all.

We are missing:

  • generate runtime annotations
  • generate runtime type assertions (probably the same format as annotations)
  • output the generics in the dart code
  • output the generics in the ES6 code (we don't need this, but would be nice)

How do we generate type annotations and runtime type assertions? I suggest this:

function foo(a: Bar, b: Bar<Baz>) {}

// Currently we generate this:
foo.parameters = [[Bar]];

// I suggest to generate this:
foo.parameters = [[new TypeAnnotation(Bar)], [new TypeAnnotation(Bar, Baz)]];

That means, traceur-runtime need to define the TypeAnnotation class.

How about type assertions? Should we do something like this?

function foo(a, b) {
  assert.argumentTypes(a, new TypeAnnotation(Bar), b, new TypeAnnotation(Bar, Baz));
}

Thoughts? @mhevery @arv

from angular.

mhevery avatar mhevery commented on April 19, 2024

I was thinking something along these lines:

function foo(a: Bar, b: Bar<Baz>) {}

foo.parameters = [Bar, Bar.parameterize(Baz)];

This means that only types which define parameterize method can be generecized. The purpose of the parameterize is to crate (or returned a cache) of a new type which is parameterize on such a type an which can than be used for assertions as normal.

Thoughts?

from angular.

Alxandr avatar Alxandr commented on April 19, 2024

@mhevery That would indicate that if I write a generic class, it would generate a parameterize static method automagically?

from angular.

vojtajina avatar vojtajina commented on April 19, 2024

@mhevery I like this! It would be good to limit the amount of garbage we create.

@Alxandr yes, we can generate the .parameterize method. That just reminds me we need one more thing - update the parser to allow class Foo<...> so that you can actually define parametrizable types. For these, Traceur would also generate the parametrize method.

from angular.

vojtajina avatar vojtajina commented on April 19, 2024

So here's the updated list of tasks:

  • parse class Foo<Bar, Baz> (and generate parametrize method), see google/traceur-compiler#1525
  • output the generics in the dart code
  • generate runtime annotations
  • generate runtime type assertions (probably the same format as annotations)
  • make sure $traceurRuntime.genericType(A2, B2, C2) === $traceurRuntime.genericType(A2, B2, C2), see google/traceur-compiler#1523
  • update rtts_assert library to deal with generics
  • output the generics in the ES6 code (we don't need this, but would be nice)

from angular.

vojtajina avatar vojtajina commented on April 19, 2024

I'm going to work on this today.

from angular.

arv avatar arv commented on April 19, 2024

For Traceur, I currently transform the TypeReference

A<B, C>

to

$traceurRuntime.genericType(A2, B2, C2);
// where A2 is the transformed A

which in turn creates a new instance of $traceurRuntime.GenericType. The last step is important so that the assertion library can do instanceof to see if it is a generic.

google/traceur-compiler@633acbc#diff-c5472491bfb53e84718d853046894688R39

This is all very adhoc at the moment.

from angular.

tbosch avatar tbosch commented on April 19, 2024

We actually never removed our hack from our transpiler, so we never used the new feature from traceur. See #554

from angular.

angular-automatic-lock-bot avatar angular-automatic-lock-bot commented on April 19, 2024

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

from angular.

Related Issues (20)

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.