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

Compiler should throw a warning if classes set to export JSON have any logic in them #191

Open
jeffxpx opened this issue Oct 5, 2013 · 0 comments

Comments

@jeffxpx
Copy link
Contributor

jeffxpx commented Oct 5, 2013

This was originally going to be a bug report for JSON exports using the constructor argument names instead of class member names, but I realized how much work that would be to have the compiler use the class member names.

The compiler's emitters work on a statement by statement basis, so at emitting time, a constructor function written like this:

[JavaScript(export="false", name="Object", mode="json")]
class Person {
  public var firstName : String;
  public var lastName : String

  public function Person(p_firstName : String, p_lastName : String) {
    this.firstName = p_firstName;
    this.lastName = p_lastName;
  }
}

When the emitter is doing the export, the statement: new Person("John", "Smith") where you would expect {firstName: "John", lastName: "Smith"}, you actually get {p_firstName: "John", p_lastName: "Smith"}.

You'd have to have an interpreter to know that p_firstName correlates to firstName.

Additionally, what if inside the constructor it was: this.firstName = p_firstName.charAt(0).toUpperCase() + p_firstName.substr(1).toLowerCase()? I know that's a little convoluted, but there's no way you'd be able to export what you'd expect to export via JSON.

Because of that, if you have a class that has the metadata set to JSON mode and no export, I think the compiler should throw a warning or even an error if there's anything other than public property definitions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant