Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transpiler: constructor and typed field semantics #11

Closed
tbosch opened this issue Sep 25, 2014 · 8 comments
Closed

transpiler: constructor and typed field semantics #11

tbosch opened this issue Sep 25, 2014 · 8 comments
Assignees

Comments

@tbosch
Copy link
Contributor

tbosch commented Sep 25, 2014

  1. Only allow assignments to fields in constructor and translate these assignment into constructor initializers
  2. Make field declaration explicit through @FIELD annotation
  3. Make const constructors in Dart through @CONST annotation

Example:

class Annotation {
  @FIELD('final name:String')
  @FIELD('final age:int')
  @CONST constructor(name:String, age:int) {
    this.name = 'Hello ' + name;
    this.age = age + 0;
  }
}

@Annotation('usage', 5)
class Foo {}

this needs to transpile to:

class Annotation {
  final String name;
  final int age;
  const Annotation(String name, int age): 
     name = 'Hello ' + name,
     age = age + 0;
}

@Annotation('usage', 5)
class Foo {}
@naomiblack naomiblack changed the title js2dart: constructor and typed field semantics transpiler: constructor and typed field semantics Sep 29, 2014
@mhevery
Copy link
Contributor

mhevery commented Sep 29, 2014

@vicb Please let us know when you can start working on it.

@mhevery mhevery modified the milestone: October Sep 29, 2014
@vojtajina
Copy link
Contributor

new syntax that we agreed on...

class Foo {

  @FINAL('bar,name,age')
  @CONST
  constructor(age: number, name: string) {
    this.bar:boolean = true;
    this.name:string = 'Hello ' + name;
    this.age = age;
  }
}

get transpiled into....

class Foo {

  final int age;
  final String name;
  final bool bar;
  const Foo(int age, String name) : bar = true, age = age, name = 'Hello ' + name {
    // Note how final fields have been hoisted into the "initializer", after the colon.
  }
}

@vicb
Copy link
Contributor

vicb commented Sep 30, 2014

What would be the purpose of the @FINAL here ? All fields have to be final with a constant constructor.

@FINAL could be useful for non-const ctor to force members to be final. What about @FINAL(['bar', 'name', 'age']) ? In a second step the final modifier could probably be added automatically by visiting the class. If we agree on this we should probably evaluate the effort of writing the "final transfomer" and if it is not too complex then skip the intermediate @FINAL. What do you think ?

side notes:

@vicb
Copy link
Contributor

vicb commented Sep 30, 2014

@mhevery I want to fix #24 before and then I'll start working on this issue. Probably later today or tomorrow.

@vojtajina
Copy link
Contributor

+1 for Making all fields final by default if the constructor is const

As for your sidenotes: yes, yes.

vicb added a commit to vicb/angular that referenced this issue Oct 1, 2014
fixes angular#11 (constructor and typed field semantics)
fixes angular#42 (Should we infer class property types from ctor args ?)
fixes angular#17 (number (js) should map to num (dart))
vicb added a commit to vicb/angular that referenced this issue Oct 1, 2014
fixes angular#11 (constructor and typed field semantics)
fixes angular#42 (Should we infer class property types from ctor args ?)
fixes angular#17 (number (js) should map to num (dart))
vicb added a commit to vicb/angular that referenced this issue Oct 1, 2014
fixes angular#11 (constructor and typed field semantics)
fixes angular#42 (Should we infer class property types from ctor args ?)
fixes angular#17 (number (js) should map to num (dart))
@mhevery
Copy link
Contributor

mhevery commented Oct 1, 2014

@vicb [https://github.com//issues/11#issuecomment-57293151] sounds good to me, also agree with @vojtajina and making @FINAL optional.

@vicb vicb added in progress and removed ready labels Oct 2, 2014
vicb added a commit to vicb/angular that referenced this issue Oct 2, 2014
fixes angular#11 (constructor and typed field semantics)
fixes angular#42 (Should we infer class property types from ctor args ?)
fixes angular#17 (number (js) should map to num (dart))
vicb added a commit to vicb/angular that referenced this issue Oct 2, 2014
fixes angular#11 (constructor and typed field semantics)
fixes angular#42 (Should we infer class property types from ctor args ?)
fixes angular#17 (number (js) should map to num (dart))
vicb added a commit to vicb/angular that referenced this issue Oct 2, 2014
fixes angular#11 (constructor and typed field semantics)
fixes angular#42 (Should we infer class property types from ctor args ?)
fixes angular#17 (number (js) should map to num (dart))
vicb added a commit to vicb/angular that referenced this issue Oct 2, 2014
fixes angular#11 (constructor and typed field semantics)
fixes angular#42 (Should we infer class property types from ctor args ?)
fixes angular#17 (number (js) should map to num (dart))
vicb added a commit to vicb/angular that referenced this issue Oct 2, 2014
fixes angular#11 (constructor and typed field semantics)
fixes angular#42 (Should we infer class property types from ctor args ?)
fixes angular#17 (number (js) should map to num (dart))
vicb added a commit that referenced this issue Oct 3, 2014
fixes #11 (constructor and typed field semantics)
fixes #42 (Should we infer class property types from ctor args ?)
fixes #17 (number (js) should map to num (dart))

Closes #45
@vicb vicb closed this as completed in 089a2f1 Oct 3, 2014
@vicb vicb removed the in progress label Oct 3, 2014
@usernamealreadyis
Copy link

:shipit:🔫

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants