-
Notifications
You must be signed in to change notification settings - Fork 483
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
jscodeshift removes 'override' keyword from ClassMethod when setting returnType #513
Comments
I can't repro on ASTExplorer when using the TypeScript parser: https://astexplorer.net/#/gist/5874ee54ffac67d5b889eda5b82ee883/cd476bad72ae8c6f5164483f93172bd8699590af ASTExplorer is using an older version of JSCodeshift though, so I wonder if this is a regression in a newer version? |
```
class Bar extends Foo {
override foo();
}
```
foo() needs curly braces, or else it can't be found by the query.
Otherwise the whole thing comes back unmodified. I wouldn't be
surprised if the issue is that ast/recast doesn't yet support
override, but the jury's still out on that one.
…On Tue, Jul 19, 2022 at 8:54 PM Daniel Lo Nigro ***@***.***> wrote:
I can't repro on ASTExplorer when using the TypeScript parser:
https://astexplorer.net/#/gist/5874ee54ffac67d5b889eda5b82ee883/cd476bad72ae8c6f5164483f93172bd8699590af
—
Reply to this email directly, view it on GitHub
<#513 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/APE6QJQI6XUW2Q573UX3JKDVU5E2TANCNFSM54BOIFWQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Ah, good catch @ElonVolo! Now I can repro. https://astexplorer.net/#/gist/5874ee54ffac67d5b889eda5b82ee883/5bb310ff6c635a7963f2c340975c50612550c3d8 |
There's a few other typos. This works for me to reproduce.
```
import { Transform } from 'jscodeshift';
const transform: Transform = (file, api) => {
const j = api.jscodeshift;
const root = j.withParser('ts')(file.source);
root.find(j.ClassMethod).forEach(path => {
path.value.returnType = j.tsTypeAnnotation(j.tsTypeReference(j.identifier(
'string')));
});
return root.toSource({ parser: 'ts' });
};
export default transform;
```
…On Tue, Jul 19, 2022 at 9:27 PM Daniel Lo Nigro ***@***.***> wrote:
Ah, good catch @ElonVolo <https://github.com/ElonVolo>! Now I can repro.
https://astexplorer.net/#/gist/5874ee54ffac67d5b889eda5b82ee883/5bb310ff6c635a7963f2c340975c50612550c3d8
—
Reply to this email directly, view it on GitHub
<#513 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/APE6QJRWRCISKUJTWWZDCS3VU5IW5ANCNFSM54BOIFWQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
This reproduces it for me.
```
import { Transform } from 'jscodeshift';
const transform: Transform = (file, api) => {
const j = api.jscodeshift;
const root = j.withParser('ts')(file.source);
root.find(j.ClassMethod).forEach(path => {
path.value.returnType =
j.tsTypeAnnotation(j.tsTypeReference(j.identifier('string')));
});
return root.toSource({ parser: 'ts' });
};
export default transform;
```
…On Tue, Jul 19, 2022 at 9:27 PM Daniel Lo Nigro ***@***.***> wrote:
Ah, good catch @ElonVolo <https://github.com/ElonVolo>! Now I can repro.
https://astexplorer.net/#/gist/5874ee54ffac67d5b889eda5b82ee883/5bb310ff6c635a7963f2c340975c50612550c3d8
—
Reply to this email directly, view it on GitHub
<#513 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/APE6QJRWRCISKUJTWWZDCS3VU5IW5ANCNFSM54BOIFWQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Looks like |
Recast doesn't include an |
```
class Bar extends Foo {
override foo();
}
```
Needs curly braces, or else it can't be found by the query.
…On Tue, Jul 19, 2022 at 8:54 PM Daniel Lo Nigro ***@***.***> wrote:
I can't repro on ASTExplorer when using the TypeScript parser:
https://astexplorer.net/#/gist/5874ee54ffac67d5b889eda5b82ee883/cd476bad72ae8c6f5164483f93172bd8699590af
—
Reply to this email directly, view it on GitHub
<#513 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/APE6QJQI6XUW2Q573UX3JKDVU5E2TANCNFSM54BOIFWQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Given an input:
and a transform:
This will output the class with typed ClassMethod definition but without override:
I expect override to be carried over. One thing I noticed was the
jscodeshift
types andast-types
types for methods do not include anoverride
boolean property, but during runtimeClassMethod
object will containoverride: true
property if the method signature includesoverride
keyword.The text was updated successfully, but these errors were encountered: