Astools [new]

sg scan --pattern 'console.log($$$)' --rewrite 'logger.info($$$)' .

Using jscodeshift :

Understanding ASTs is not just for compiler engineers. It is fundamental to: astools

| Feature | Description | |-----------------------|-----------------------------------------------------------------------------| | | Convert source text into a typed AST with location metadata. | | Querying | XPath/CSS-selector-like queries on AST nodes (e.g., ast-grep patterns). | | Transformation | Modify nodes, insert/delete/replace subtrees, preserve formatting (optional). | | Code generation | Emit source code from AST, often with comments/whitespace retention. | | Validation | Check structural rules (e.g., no nested callbacks deeper than 3 levels). | sg scan --pattern 'console

Common implementations include:

| Text-based | ASTools | |--------------------------|------------------------------| | Fragile (whitespace, comments) | Structural, syntax-aware | | Needs escaping/special cases | Handles language semantics | | Cannot track scope | Knows variable bindings, imports | | Breaks string literals easily | Differentiates code from strings | | | Querying | XPath/CSS-selector-like queries on AST

sg scan --pattern 'console.log($$$)' --rewrite 'logger.info($$$)' .

Using jscodeshift :

Understanding ASTs is not just for compiler engineers. It is fundamental to:

| Feature | Description | |-----------------------|-----------------------------------------------------------------------------| | | Convert source text into a typed AST with location metadata. | | Querying | XPath/CSS-selector-like queries on AST nodes (e.g., ast-grep patterns). | | Transformation | Modify nodes, insert/delete/replace subtrees, preserve formatting (optional). | | Code generation | Emit source code from AST, often with comments/whitespace retention. | | Validation | Check structural rules (e.g., no nested callbacks deeper than 3 levels). |

Common implementations include:

| Text-based | ASTools | |--------------------------|------------------------------| | Fragile (whitespace, comments) | Structural, syntax-aware | | Needs escaping/special cases | Handles language semantics | | Cannot track scope | Knows variable bindings, imports | | Breaks string literals easily | Differentiates code from strings |