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:
parent
cc45608423
commit
a35e5a314a
1
packages/babel-traverse/test/fixtures/regression/visit-tsfunctiontype-parameters/input.ts
vendored
Normal file
1
packages/babel-traverse/test/fixtures/regression/visit-tsfunctiontype-parameters/input.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
let x: (number) => void;
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["syntax-typescript", "./plugin"]
|
||||||
|
}
|
||||||
1
packages/babel-traverse/test/fixtures/regression/visit-tsfunctiontype-parameters/output.js
vendored
Normal file
1
packages/babel-traverse/test/fixtures/regression/visit-tsfunctiontype-parameters/output.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
let x: (string) => void;
|
||||||
11
packages/babel-traverse/test/fixtures/regression/visit-tsfunctiontype-parameters/plugin.js
vendored
Normal file
11
packages/babel-traverse/test/fixtures/regression/visit-tsfunctiontype-parameters/plugin.js
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
module.exports = function() {
|
||||||
|
return {
|
||||||
|
visitor: {
|
||||||
|
Identifier(path) {
|
||||||
|
if (path.node.name == "number") {
|
||||||
|
path.node.name = "string";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -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,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user