-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Only functions can be constructor functions #27369
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
Only functions can be constructor functions #27369
Conversation
`@constructor` put on anything incorrectly makes it a JS constructor. This is a problem for actual constructors, because getJSClassType doesn't work on actual classes. The fix is to make isJSConstructor require that its declaration is a function.
@sandersn What about an odd pattern like: /**
* @constructor
*/
var MyClass = mixin(MyClassBaseCtor, MyMixin); ? |
@weswigham That [1] might be supported in the future, but right now [1] It wouldn't make a difference for |
Something like that yeah. Or like |
@weswigham Since you took a look earlier, mind signing off on this one? |
return false; | ||
} | ||
const func = isFunctionDeclaration(node) || isFunctionExpression(node) ? node : | ||
isVariableDeclaration(node) && node.initializer && isFunctionExpression(node.initializer) ? node.initializer : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about node.initializer = some Conditional expression that uses functionExpression in each branch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, but that doesn't actually work today either, and you can put the annotation on the individual function expressions like so:
const Weird = b ?
/** @constructor */
function () { this. x = 1 } :
/** @constructor */
function () { this.y = 'yes' };
I'd rather address that as a new feature instead of as a 3.1 bugfix.
This is now in master as well. |
`@constructor` put on anything incorrectly makes it a JS constructor. This is a problem for actual constructors, because getJSClassType doesn't work on actual classes. The fix is to make isJSConstructor require that its declaration is a function.
@constructor
put on anything incorrectly makes it a JS constructor. This is a problem for actual constructors, because getJSClassType doesn't work on actual classes. The fix is to make isJSConstructor require that its declaration is a function.Fixes #27345