Skip to content

Always used TypeScript parser options#319

Merged
ijlee2 merged 5 commits into
mainfrom
simplify-ast-javascript
May 28, 2026
Merged

Always used TypeScript parser options#319
ijlee2 merged 5 commits into
mainfrom
simplify-ast-javascript

Conversation

@ijlee2
Copy link
Copy Markdown
Owner

@ijlee2 ijlee2 commented May 28, 2026

Background

Until now, @codemod-utils/ast-javascript allowed end-developers to use a different set of parser options for JavaScript files. This, however, sometimes results in additional code (e.g. 'Literal' vs. 'StringLiteral') for early exits and in lint errors because a recast property may exist in one but not the other.

Going forward, the set for TypeScript will be used to handle both JavaScript and TypeScript files. This should be okay since TypeScript is a superset of JavaScript, and helps the invocations for @codemod-utils/ast-javascript and @codemod-utils/ast-template become even more similar. It will also help me simplify the main tutorial.

How to migrate

AST.traverse now accepts 0 arguments. Remove the 1st argument, then run pnpm test to see if you need to update the 2nd argument for traverse.

import { AST } from '@codemod-utils/ast-javascript';

type Data = {
  isTypeScript: boolean;
};

function transform(file: string, data: Data): string {
-   const traverse = AST.traverse(data.isTypeScript);
+   const traverse = AST.traverse();

  const ast = traverse(file, {
    // ...
  });

  return AST.print(ast);
}

In the example above, if data.isTypeScript isn't used by the 2nd argument for traverse, you can remove data from transform and run pnpm lint to find additional dead code in /src and /tests.

See #324 for additional changes in @codemod-utils/ast-javascript@v4.

@ijlee2 ijlee2 added enhance: code Issue asks for new feature or refactor breaking Breaking change will result in a new major version labels May 28, 2026
@ijlee2 ijlee2 merged commit a2e2a4b into main May 28, 2026
3 checks passed
@ijlee2 ijlee2 deleted the simplify-ast-javascript branch May 28, 2026 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Breaking change will result in a new major version enhance: code Issue asks for new feature or refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant