-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 TSParameterProperty getting lost with transform-classes #8682
Conversation
existentialism
commented
Sep 11, 2018
•
edited
Loading
edited
Q | A |
---|---|
Fixed Issues? | Fixes #8669, Fixes #7074 |
Patch: Bug Fix? | Y |
Major: Breaking Change? | N |
Minor: New Feature? | N |
Tests Added + Pass? | Yes |
Documentation PR Link | |
Any Dependency Changes? | |
License | MIT |
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/9109/ |
@@ -190,10 +144,63 @@ export default declare((api, { jsxPragma = "React" }) => { | |||
// We do this here instead of in a `ClassProperty` visitor because the class transform |
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.
Nit: this comment is slightly out of date, now that this block contains both ClassProperty
and ClassMethod
logic.
param.type === "TSParameterProperty" && | ||
!PARSED_PARAMS.has(param.parameter) | ||
) { | ||
PARSED_PARAMS.add(param.parameter); |
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.
Mostly out of curiosity - it looks like this is the only real functional change added to this block, to prevent duplicate parameters from being added to the parameterProperties
list? What sort of case is this preventing? How would two different entries of childNode.params
have the same parameter
object?
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.
It requires a bit of understanding of the class transformation:
https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-classes/src/index.js#L41
Ultimately, it prevents params from getting parsed twice since the class transform converts it to an expression.
Thanks for fixing this! I believe this fix still depends on |
@existentialism Yo, just wanted to let you know about a related issue that this PR doesn't seem to fix, judging from the repl build results: #8692 |
child.node.typeAnnotation = null; | ||
const childNode = child.node; | ||
|
||
if (t.isClassMethod(childNode) && childNode.kind === "constructor") { |
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.
Nit: you can use t.isClassMethod(childNode, { kind: "constructor" })