-
Notifications
You must be signed in to change notification settings - Fork 9
Compiler should throw a warning if classes set to export JSON have any logic in them #191
Description
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.