-
Couldn't load subscription status.
- Fork 13.1k
Closed
Labels
ES6Relates to the ES6 SpecRelates to the ES6 SpecWon't FixThe severity and priority of this issue do not warrant the time or complexity needed to fix itThe severity and priority of this issue do not warrant the time or complexity needed to fix it
Milestone
Description
This issue has been asked as a question on StackOverflow.
I have a TypeScript class, and I'm doing some metaprogramming where I need to be able to access instance.func.name, however TypeScript omits the function name in the compiled JS.
TypeScript:
class ClassName {
// ...
func(): ReturnType {
// ...
}
}Compiled JavaScript:
// ...
ClassName.prototype.func = function () {
// ...
};Desired JavaScript:
ClassName.prototype.func = function func() {
// ... ^^^^
};Not sure if this is a bug or by design, but the source of the result is emitter.ts.
A proposed solution on StackOverflow was:
// src/compiler/emitter.ts:4671
function shouldEmitFunctionName(node) {
if (node.kind === 173 /* FunctionExpression */) {
// Emit name if one is present
return !!node.name;
}
if (node.kind === 213 /* FunctionDeclaration */) {
// Emit name if one is present, or emit generated name in down-level case (for export default case)
return !!node.name || languageVersion < 2 /* ES6 */;
}
// MODIFIED
if (node.kind === 143 /* MethodDeclaration */) {
return true;
}
}rob3c, pinyin, sonicd300, elado, jfahrenkrug and 5 more
Metadata
Metadata
Assignees
Labels
ES6Relates to the ES6 SpecRelates to the ES6 SpecWon't FixThe severity and priority of this issue do not warrant the time or complexity needed to fix itThe severity and priority of this issue do not warrant the time or complexity needed to fix it