Fix: class transform should not drop method definition when key contains non-BMP characters#14897
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/52872/ |
|
I didn't even notice this failure due to the failed CI.😰 |
| * @template N The unamed expression type | ||
| * @param {({ | ||
| * node: N; | ||
| * parent?: NodePath<N>["parent"]; | ||
| * scope: Scope; | ||
| * id?: t.LVal | t.StringLiteral | t.NumericLiteral | t.BigIntLiteral; | ||
| * })} { | ||
| * node, | ||
| * parent, | ||
| * scope, | ||
| * id, | ||
| * } `node`, `parent` and `scope` are generally extracted from a given NodePath. `id` is the fallback naming source when the helper | ||
| * can not infer the function name from the AST |
There was a problem hiding this comment.
JSDoc does not support destructuring, but we can do something like this:
| * @template N The unamed expression type | |
| * @param {({ | |
| * node: N; | |
| * parent?: NodePath<N>["parent"]; | |
| * scope: Scope; | |
| * id?: t.LVal | t.StringLiteral | t.NumericLiteral | t.BigIntLiteral; | |
| * })} { | |
| * node, | |
| * parent, | |
| * scope, | |
| * id, | |
| * } `node`, `parent` and `scope` are generally extracted from a given NodePath. `id` is the fallback naming source when the helper | |
| * can not infer the function name from the AST | |
| * @param {NodePath<t.FunctionExpression | t.Class>} The function or class to name. |
Also, id is not a fallback: if there is already an id we exit early, and the fallback behavior is to infer it.
There was a problem hiding this comment.
If we have node.id, then node is a named function/class expression, we exit early.
Then the helper tries to determine id from the AST, and if it can't determine and the fallback id is not provided, we exit early.
Then the helper determine a name from id, exit early if the name can't be determined.
In this way the id is the fallback naming source. And because id does not exist in a NodePath, we can't put NodePath here.
| babelHelpers.createClass(o, [{ | ||
| key: "\uD842\uDFB7\u91CE\u5BB6", | ||
| value: function 𠮷野家() {} |
There was a problem hiding this comment.
In current main it is transformed to
babelHelpers.createClass(o, [{
key: "\uD842\uDFB7\u91CE\u5BB6"
}]here the value is dropped because nameFunction returns undefined.
96f90d9 to
880f117
Compare

The PR starts from polishing the typings/docs of
@babel/helper-function-nameand then the type checker catches a bug of the class transform.