Vue Metamorph is a robust codemod framework designed for manipulating Abstract Syntax Trees (ASTs) across various file types, including JavaScript, TypeScript, Vue Single File Components (SFCs), CSS, SCSS, LESS, SASS, and Stylus. Currently stable at version 3.3.4, the library sees active development with frequent dependency updates and minor feature enhancements, as evidenced by its recent changelog. It differentiates itself by providing a comprehensive, AST-based approach to large-scale code changes in Vue projects, addressing limitations of regex-based transformations. Unlike some alternatives, Vue Metamorph offers a full recast-like experience for entire Vue SFCs, allowing for reliable and precise manipulation of script, template, and style sections.
npm install vue-metamorphVerified import paths — ran on the pinned version, not inferred.
Demonstrates defining a Vue Metamorph codemod to rename a Vue component and add an attribute to its usage in a Vue SFC template, and how to execute it via the CLI.
Review existing codemods for direct imports or assumptions about `recast` or `ast-types`. Replace with `recast-x` and `ast-types-x` imports where applicable and test thoroughly. Consult the `recast-x` and `ast-types-x` documentation for any specific migration notes.
Be aware of potential limitations when processing files with very new or complex TypeScript syntax. Ensure your environment uses the specified Babel parser version if encountering parsing errors for these specific TS constructs, or update `vue-metamorph` to a version that addresses this with a newer parser.
Ensure source files are syntactically correct before running codemods for predictable results. If unusual transformation outcomes occur, verify the integrity of the source code. The `errorRecovery` option is a fallback, not a substitute for valid syntax.
For running codemods, leverage the provided CLI via `npx vue-metamorph your-codemod.ts --files 'path/to/files/**/*'` as the primary execution mechanism. If programmatic execution is strictly required, investigate the `vue-metamorph` source code for how it invokes codemod plugins, but be aware this is an undocumented and potentially unstable API.
Integrate a code formatter like Prettier or ESLint with auto-fix into your codemod workflow. Run the formatter on the affected files immediately after executing `vue-metamorph` to maintain code style and minimize diff noise.
This issue was specifically addressed by downgrading the Babel parser in `vue-metamorph` v3.2.4. Ensure you are using `vue-metamorph` version 3.2.4 or newer. If the problem persists, check for new updates that might further resolve parser compatibility.
Upgrade `vue-metamorph` to version 3.2.3 or higher. This version replaces `recast` and `ast-types` with their actively maintained forks, `recast-x` and `ast-types-x`, which are more robust with modern syntax.
Update your `vue-metamorph` package to the latest version. Recent releases frequently bump parser dependencies like `vue-eslint-parser` to support newer Vue features and syntax. If the issue persists with the latest version, consider filing an issue with the `vue-metamorph` project.