-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fixing codegen issues with reserved classes #945
base: master
Are you sure you want to change the base?
Fixing codegen issues with reserved classes #945
Conversation
The initial issue should have been fixed by merging #913. Not sure about the other changes because #870 (comment). |
Thank you for taking a look at this, and for merging #913! To give you some context for the other issue, the current implementation generates the following code when given a message with the name of a built-in javascript class (e.g, SpecialString.String = (function() {
/**
* Properties of a String.
* @memberof root.context.SpecialString
* @interface IString
* @property {string|null} [locale] String locale
* @property {string|null} [text] String text
*/
/**
* Constructs a new String.
* @memberof root.context.SpecialString
* @classdesc Represents a String.
* @implements IString
* @constructor
* @param {root.context.SpecialString.IString=} [properties] Properties to set
*/
function String(properties) {
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
/**
* String locale.
* @member {string} locale
* @memberof root.context.SpecialString.String
* @instance
*/
String.prototype.locale = ""; This will fail at runtime because it will use the reserved Now, if I add SpecialString.String_ = (function() {
/**
* Properties of a String.
* @memberof root.context.SpecialString
* @interface IString
* @property {string|null} [locale] String locale
* @property {string|null} [text] String text
*/
/**
* Constructs a new String.
* @memberof root.context.SpecialString
* @classdesc Represents a String.
* @implements IString
* @constructor
* @param {root.context.SpecialString.IString_=} [properties] Properties to set
*/
function String(properties) {
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
/**
* String locale.
* @member {string} locale
* @memberof root.context.SpecialString.String_
* @instance
*/
String_.prototype.locale = ""; It seemed to me the simplest way to fix this is to escape the names of all types initially, so that the Type constructor generator doesn't need to worry about the function name. Let me know what you suggest in terms of approach! |
Not sure if this PR is still alive, but the same issue happens for |
-Added built in classes
String
andArray
to reserved words-Sanitized all names in the namespace before building the namespace to avoid issue with constructors and interfaces