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
Fix: class transform should not drop method definition when key contains non-BMP characters #14897
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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-name
and then the type checker catches a bug of the class transform.