-
Notifications
You must be signed in to change notification settings - Fork 489
Open
Description
I'm using Jscodeshift to replace the following code in astexplorer testing, but I get different results using babel/ts
export const systemCoreApi = wrapApiClient<ISystemApi>({ namespace: 'system' })use babel parser
export const parser = "babel";
// Press ctrl+space for code completion
export default function transformer(file, api) {
const j = api.jscodeshift;
const root = j(file.source);
root
// .find(j.TSTypeReference)
.find(j.Identifier, { name: "ISystemApi" })
.replaceWith((path) => {
path.node.name = "ISystemCoreApi";
return path.node;
});
return root.toSource();
}output
export const systemCoreApi = wrapApiClient<ISystemCoreApi>({ namespace: 'system' })use ts parser
// jscodeshift can take a parser, like "babel", "babylon", "flow", "ts", or "tsx"
// Read more: https://github.com/facebook/jscodeshift#parser
export const parser = "ts";
// Press ctrl+space for code completion
export default function transformer(file, api) {
const j = api.jscodeshift;
const root = j(file.source);
root
// .find(j.TSTypeReference)
.find(j.Identifier, { name: "ISystemApi" })
.replaceWith((path) => {
path.node.name = "ISystemCoreApi";
return path.node;
});
return root.toSource();
}output
export const systemCoreApi = wrapApiClient<ISystemApi>({ namespace: 'system' })Lastly, I'm wondering how to use the @typescript-eslint/parser parser, it seems to work best for parsing ts in ast explorer (the result of ts parsing is very different from other parsers and jscodeshift's api)
Metadata
Metadata
Assignees
Labels
No labels

