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
Support Flow this
parameter annotations
#12234
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/40277/ |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit bd8d4df:
|
Looks like this is currently failing CI's linting step due to a Flow issue. Mind fixing the typing issue so that we can review? :) |
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.
Can you add an integration test with transform-parameters
like we did in #9714?
@@ -1461,6 +1524,7 @@ export default (superClass: Class<Parser>): Class<Parser> => | |||
|
|||
node.params = tmp.params; | |||
node.rest = tmp.rest; | |||
node.this = tmp._this; |
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.
Can you also update
babel/packages/babel-parser/src/types.js
Line 161 in d6816f0
export type BodilessFunctionOrMethodBase = HasDecorators & { |
"this"
property in the AST node.
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 new "this"
property is only present in the FunctionTypeAnnotation
node. For regular function nodes the "this"
is the first member of the parameter list (to match the Flow parser's behavior).
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.
This also matches the AST we use for this
type annotations in TS.
Not sure what the create react app failure is, seems unrelated to these changes. |
@dsainati1 it's def unrelated, we're seeing it on all recent prs (terser/terser#854) |
Any updates on this? |
We'll release this in the next minor version. |
@dsainati1 Could you rebase this, or enabling "Allow edit by maintainers" in the right sidebar? |
I have the "Allow edit by maintainers" box checked. |
@dsainati1 Although "Allow edit by maintainers" is checked, we can not push to your repo because the PR is from the default branch |
OK I think I got it, but let me know if you still need something from me here. |
Hmmm it seems the |
@dsainati1 If an For debug purpose you can add {
"plugins": ["estree", "flow"]
} |
Given that this test was not failing when I submitted this PR initially, I am not sure what would have changed between now and then that causes this test to fail. Are there any recent changes I should know about that would result in different behavior here? |
The test was likely broken before you rebased, but it was not reported then because before 8478027 we never ensure that the parser tests throw same errors when |
@@ -1160,6 +1182,12 @@ export default (superClass: Class<Parser>): Class<Parser> => | |||
if (kind === "get" || kind === "set") { | |||
this.flowCheckGetterSetterParams(node); | |||
} | |||
if (node.key.name === "constructor" && node.value.this) { |
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.
As you can see from https://astexplorer.net/#/gist/e4e0c3380467882e445d5ddd8193feac/8bf60fc83e55d1fff70cd5b0ad4d3255e9fb5691, when estree
plugin is enabled, the AST is slightly different. node.value
becomes a function expression. The error is thrown, very likely because node.value.this
is no longer true
when estree
is enabled.
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.
Can you add a new test case on string literal constructor?
class A {
"constructor"() {}
}
It is semantically equivalent to the identifier constructor.
This adds support for
this
parameter annotations.Example:
This is already supported in the Flow parser: facebook/flow@8efdc8c