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
Set function name for decorated private non-field elements #16144
Changes from 3 commits
6ee8e54
fcc342c
7a47338
07d90a7
c08c75c
f7cfc6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* @minVersion 7.23.5 */ | ||
|
||
// https://tc39.es/ecma262/#sec-setfunctionname | ||
export default function setFunctionName( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that the various decorators helpers are exclusive (and everything except for legacy and 2023-05) will be dropped in Babel 8, could we just inline the helper instead? Or maybe we could even just fix this in 2023-05. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The helper is isolated because we will eventually emit // input.js
function dec(target, context) {
// print '[Symbol.iterator]'
console.log(target.name);
}
class Dummy {
[Symbol.iterator] = @dec class {}
} to // output.js
function dec(_, context) {
// print '[Symbol.iterator]'
console.log(context.name);
}
var computedKey = Symbol.iterator;
class Dummy {
[computedKey] = (setFunctionName(class {
static {
[_decorated_class, _initClass] = _applyDecs(this, [], [dec]).c;
}
static {
_initClass();
}
}, computedKey), _decorated_class);
} In this example we will also pass a symbol, which is also a valid property key, to the Currently we have not implemented such transform yet. It was addressed in #15122 but I will open new PR to do so. |
||
fn: Function, | ||
name: symbol | string, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In which case we are passing a symbol name to this helper? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #16144 (comment). |
||
prefix?: string, | ||
) { | ||
if (typeof name === "symbol") { | ||
var description = name.description; | ||
name = description ? "[" + description + "]" : ""; | ||
} | ||
name += ""; | ||
if (prefix) { | ||
name = prefix + " " + name; | ||
} | ||
// In some older browsers .name was non-configurable, here we catch any | ||
// errors thrown by defineProperty. | ||
try { | ||
return Object.defineProperty(fn, "name", { | ||
configurable: true, | ||
value: name, | ||
}); | ||
} catch (_) { | ||
return fn; | ||
} | ||
} | ||
JLHwung marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
The TS emits dedicated
setFunctionName
call here:Here we merge the
setFunctionName
call with theapplyMemberDecs
to optimize the output size.