What are the best frameworks and tools based on AST and LST for Angular upgrade from…
- User
What are the best frameworks and tools based on AST and LST for Angular upgrade from version 11 to Version 20 . How should the upgrade be planned
Assistant
Upgrading an Angular application from version 11 to version 20 is a significant leap, as it involves crossing multiple major versions. Angular follows Semantic Versioning (SemVer) and releases new major versions approximately every six months, each introducing breaking changes, deprecations, and improvements.
To perform this upgrade successfully, especially for large codebases, you can leverage tools based on Abstract Syntax Trees (ASTs) and Lexical Symbol Tables (LSTs) to automate or assist with code transformations, migrations, and refactoring.
🔧 Tools & Frameworks Based on AST / LST for Angular Upgrade
1. Angular CLI / Schematics
- Type: Schematic-based tool using TypeScript AST (
ts-morph,typescriptcompiler). - Use: Built-in Angular CLI commands like
ng updateuse schematics that parse your code via AST to apply transformations. - Key Features:
- Automates dependency updates.
- Applies migration rules for breaking changes.
- Can be extended with custom schematics.
- Docs: https://angular.io/cli
2. ts-morph
- Type: TypeScript AST manipulation library.
- Use: Useful for writing custom codemods to migrate deprecated APIs, change imports, or refactor components.
- Why Use It?
- Powerful AST traversal and transformation.
- Easier than raw TypeScript compiler API.
- Docs: https://ts-morph.com/
3. jscodeshift
- Type: Codemod toolkit using Babel parser (AST-based).
- Use: While not Angular-specific, it's used in the JavaScript ecosystem to write reusable transforms.
- Can Be Used For:
- Custom scripts to migrate patterns across files.
- Especially useful if you have many manual changes to make.
- Docs: https://github.com/facebook/jscodeshift
4. Angular Update Tooling (NGT)
- Type: Internal tool used by Angular team; not public, but its logic powers
ng update. - You Can Use:
- The official Angular migration schematics found in
@angular/core/schematics/migrations.
- The official Angular migration schematics found in
5. Codemods for Angular
- Community Packages:
@angular/cdk/schematics: Contains helpers for material upgrades.@angular/material/schematics: Helps migrate Material design breaking changes.- Third-party libraries often provide their own codemods.
- GitHub Repositories:
- Search for "angular codemod" or "ng11 to ngXX migration".
🧭 Strategy for Upgrading Angular from v11 to v20
Since Angular does not support skipping more than one major version at a time via
ng update, you must upgrade incrementally, typically one major version at a time.Step-by-Step Upgrade Plan:
1. ✅ Assess Your Codebase
- Identify third-party dependencies and check their compatibility.
- Look for deprecated APIs still in use.
- Audit build system: Webpack, Rollup, etc., may need updates.
2. 🛠️ Set Up Development Environment
- Ensure Node.js and npm/yarn/pnpm versions are compatible with Angular 20.
- Use Angular CLI v20 for final testing.
3. ⚙️ Incremental Upgrade Path
Upgrade one version at a time (e.g., 11 → 12 → 13 → ... → 20). Each step includes:
Step Action 1 Run ng update @angular/core@<next-version> @angular/cli@<next-version>2 Fix breaking changes using schematic migrations 3 Review deprecation warnings and fix them 4 Run tests and ensure all features work 5 Commit changes before moving to next version 4. 📜 Write Custom Migrations Using AST
If certain changes are repetitive across versions, create custom schematics using:
ts-morphto traverse and transform TypeScript files.- AST inspection to find and replace outdated patterns.
Example:
// Example using ts-morph import { Project } from 'ts-morph'; const project = new Project(); project.addSourceFilesAtPaths('src/**/*.ts'); const sourceFiles = project.getSourceFiles(); sourceFiles.forEach(sourceFile => { sourceFile.getDescendantsOfKind(ts.SyntaxKind.Identifier) .forEach(identifier => { if (identifier.getText() === 'MyDeprecatedService') { identifier.rename('NewService'); } }); });5. 🧪 Test After Every Major Version
- Run unit tests (
ng test) - Run e2e tests (
ng e2e) - Manually verify critical functionality
- Monitor browser console for runtime errors
6. 📦 Update Dependencies
- Update third-party libraries to match current Angular version.
- Use tools like
npm-check-updatesto auto-update package.json.
7. 🧹 Clean Up
- Remove deprecated APIs and polyfills no longer needed.
- Modernize RxJS usage (e.g., pipeable operators).
- Update Angular Material, CDK, or other UI frameworks.
8. 🧬 Final Validation
- Run
ng build --prod(or--configuration=production) - Test app in production-like environment
- Ensure performance hasn’t regressed
📌 Best Practices
Practice Description Automate Where Possible Use schematics and AST-based codemods for repetitive tasks Version Control Commit after each successful upgrade step CI Integration Integrate upgrade steps into CI/CD pipeline for regression checks Documentation Keep track of manual fixes and decisions made during upgrade Deprecation Tracking Regularly run ng buildand watch for deprecation warnings
🧰 Optional Tools
Tool Purpose Angular Console GUI interface to Angular CLI commands Renovate Bot Auto-updates dependencies Angular DevTools (Chrome Extension) Debugging Angular apps in-browser
📚 Resources
- Angular Update Guide
- Angular CLI Docs
- ts-morph GitHub
- Angular Schematics Docs
- Angular Migration Recipes
✅ Summary
To upgrade from Angular 11 to Angular 20:
- Use Angular CLI + Schematics for automated migrations.
- Leverage AST-based tools like
ts-morphorjscodeshiftfor custom codemods. - Perform the upgrade incrementally, one major version at a time.
- Validate with tests, manual QA, and performance monitoring.
- Document and automate everything to reduce risk.
Would you like a sample custom schematic or codemod script to help with specific changes?
- Type: Schematic-based tool using TypeScript AST (
- User
how do these compare with OPenRewrite recipes for Angular upgrade
Assistant
Great question!
OpenRewrite (formerly known as moditect/rewrite) is a powerful, declarative code transformation engine that uses Abstract Syntax Trees (ASTs) to perform safe, repeatable code changes. It's especially useful for large-scale refactoring and version upgrades across multiple projects.
When comparing Angular CLI Schematics, ts-morph, or jscodeshift with OpenRewrite recipes, here’s how they stack up in the context of an Angular v11 → v20 upgrade:
🧰 Comparison: OpenRewrite vs Angular Ecosystem Tools
Feature OpenRewrite Angular CLI / Schematics ts-morph jscodeshift Built-in Angular Support? ❌ No native support for Angular (yet) ✅ Native support via ng update✅ TypeScript AST focused ⚠️ JS-focused, can be adapted Declarative Recipes ✅ Yes (YAML-based or Java DSL) ⚠️ Schematics are imperative ⚠️ Imperative API ⚠️ Imperative API Language Support ✅ Java, TypeScript, JavaScript, Kotlin, etc. ✅ TypeScript only ✅ TypeScript only ✅ JavaScript + JSX TypeScript AST Support ⚠️ Limited (via Babel parser or custom parsers) ✅ Full TypeScript compiler ✅ Based on TypeScript compiler ⚠️ Babel parser (not full TS) Community & Tooling Growing ecosystem (Java-centric) ✅ Strong Angular community ✅ Good ✅ Facebook-backed Use Case Fit for Angular Upgrade ⚠️ Medium – requires custom recipes ✅ High – built by Angular team ✅ High – great for codemods ✅ Medium – less TS coverage IDE Integration ✅ IntelliJ, VS Code (plugins), CI tools ✅ VS Code + Angular Language Service ✅ VS Code plugin support ⚠️ Less IDE integration Migration Automation ✅ Can automate across versions ✅ Version-specific migrations ✅ Customizable ✅ Codemod scripts Learning Curve ⚠️ Steeper (DSL, Java-based toolchain) ✅ Low if using Angular CLI ✅ Moderate ✅ Moderate
🔁 How They're Similar
All these tools use AST-based parsing, which means:
- They understand your code structure accurately.
- They avoid fragile regex-based replacements.
- They allow precise transformations based on language semantics.
This makes them ideal for tasks like:
- Renaming imports
- Updating method signatures
- Replacing deprecated APIs
- Refactoring module imports
🧱 When to Use OpenRewrite Over Angular CLI / ts-morph?
✅ Use OpenRewrite when:
- You're working in a multi-language monorepo (e.g., Java + TypeScript).
- You want declarative, version-agnostic refactorings.
- You're planning long-term maintenance of migration rules.
- You want to run transformations outside of Angular CLI.
- You're already using OpenRewrite for backend migrations and want to unify tooling.
Example: If you have Spring Boot services and Angular frontends, and you're migrating both, OpenRewrite could offer a unified strategy.
✅ Use Angular CLI / Schematics when:
- You’re doing a standard Angular major version upgrade.
- You want officially supported, tested migrations.
- You don’t need cross-language support.
- You prefer low-effort automation over customization.
✅ Use ts-morph when:
- You need fine-grained control over TypeScript AST.
- You're writing custom schematics or codemods.
- You're integrating into a Node.js-based build pipeline.
✅ Use jscodeshift when:
- You're dealing with legacy JS codebases.
- You're comfortable writing codemod scripts.
- You're not strictly limited to TypeScript.
📦 Sample OpenRewrite Recipe (YAML)
Here's a basic rewrite recipe for replacing a deprecated service import:
type: specs.openrewrite.org/v1beta/recipe name: com.example.ReplaceOldServiceImport displayName: Replace Old Service Import description: Migrates usage of DeprecatedService to NewService. recipeList: - org.openrewrite.ts.ChangeType: oldFullyQualifiedTypeName: com.example.OldService newFullyQualifiedTypeName: com.example.NewServiceYou’d then apply it via CLI or Maven/Gradle plugin.
🧪 Real-World Angular Migration Scenario
Suppose you're upgrading from Angular 11 to 20 and several breaking changes occur:
Change Best Tool Update RenderertoRenderer2Angular CLI / Schematics Rename ViewChild({ read })usagets-morph Replace HttpModulewithHttpClientModuleOpenRewrite (if part of multi-language repo) Fix RxJS pipeable operators ts-morph or jscodeshift Remove enableProdMode()in Ivy appsAngular CLI Replace @angular/materialbreaking changesMaterial schematics
🧩 Recommendation: Hybrid Strategy
For large Angular upgrades like v11 → v20, consider this hybrid plan:
- Use Angular CLI / Schematics for official migrations between each major version.
- Write custom codemods with
ts-morphfor repetitive manual fixes. - Leverage OpenRewrite if you're also managing backend code or want reusable, declarative recipes.
- Automate testing and linting after each step.
📚 Resources
Would you like help creating an OpenRewrite recipe for Angular or a custom schematic/codemod for specific breaking changes during your upgrade? I can generate examples!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.