Skip to content
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

Don't check type annotations when deciding params scope #11349

Merged
merged 2 commits into from Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/babel-plugin-transform-parameters/src/params.js
Expand Up @@ -36,6 +36,10 @@ const iifeVisitor = {
path.stop();
}
},
// type annotations don't use or introduce "real" bindings
"TypeAnnotation|TSTypeAnnotation"(path) {
Copy link
Contributor

@JLHwung JLHwung Mar 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we may expose bindingType of checkLVal to parseBindingList so we do not register bindings of lval when they are inside a type annotation.

BTW we should also skip TSTypeParameters.

function a(b = <T extends (c: any) => void>(): void => {}) {
  let c;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since identifiers are the most often created/moved nodes, I think that it would be safer to add a skip like this one to @babel/traverse rather than relying on what was initially parsed.

path.skip();
},
};

export default function convertFunctionParams(path, loose) {
Expand Down
@@ -0,0 +1,3 @@
function a(b: (c) => void = {}) {
let c;
}
@@ -0,0 +1,6 @@
{
"plugins": [
"transform-parameters",
"syntax-flow"
]
}
@@ -0,0 +1,4 @@
function a() {
let b: (c) => void = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
let c;
}
@@ -0,0 +1,3 @@
function a(b: (c) => void = {}) {
let c;
}
@@ -0,0 +1,6 @@
{
"plugins": [
"transform-parameters",
"syntax-typescript"
]
}
@@ -0,0 +1,4 @@
function a() {
let b: (c) => void = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
let c;
}