Fix TSFunctionType visitors definition (#9692)

When traversing a tree parsing for TypeScript syntax and hitting a `TSFunctionType` node, the `typeParameters` and `typeAnnotation` fields are correctly visited but the `parameters` field isn't. As a result visitors by default don't visit `foo` below:

```
var x: (foo) => void; // foo is never visited
```
```
module.exports = function() {
  return {
    visitor: {
      Identifier(path) {
        if (path.node.name == "foo") {
          // Never hit because it's nested within TSFunctionType.parameters
          path.node.name = "bar";
        }
      }
    }
  };
}
```

It appears to be a bug in babel-types/src/definitions/typescript.js which omits `parameters` in the visitors list for `fnOrCtr`. Fixed by adding it.
This commit is contained in:
Pelle Nielsen 2019-03-16 01:24:23 -07:00 committed by Nicolò Ribaudo
parent cc45608423
commit a35e5a314a
5 changed files with 17 additions and 1 deletions

View File

@ -0,0 +1 @@
let x: (number) => void;

View File

@ -0,0 +1,3 @@
{
"plugins": ["syntax-typescript", "./plugin"]
}

View File

@ -0,0 +1 @@
let x: (string) => void;

View File

@ -0,0 +1,11 @@
module.exports = function() {
return {
visitor: {
Identifier(path) {
if (path.node.name == "number") {
path.node.name = "string";
}
}
}
};
}

View File

@ -156,7 +156,7 @@ defineType("TSThisType", {
const fnOrCtr = { const fnOrCtr = {
aliases: ["TSType"], aliases: ["TSType"],
visitor: ["typeParameters", "typeAnnotation"], visitor: ["typeParameters", "parameters", "typeAnnotation"],
fields: signatureDeclarationCommon, fields: signatureDeclarationCommon,
}; };