Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

abstract-syntax-tree

Package Overview
Dependencies
Maintainers
3
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abstract-syntax-tree - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

4

CHANGELOG.md
# abstract-syntax-tree changelog
## 1.1.0
* add: update replace method to handle array and null value
## 1.0.3

@@ -4,0 +8,0 @@

7

index.js

@@ -10,2 +10,3 @@ const cherow = require('cherow')

const sourcemap = require('source-map')
const replace = require('./src/replace')

@@ -105,3 +106,3 @@ class AbstractSyntaxTree {

replace (options) {
return estraverse.replace(this.ast, options)
return replace(this.ast, options)
}

@@ -139,2 +140,4 @@

beautify (source, options) {
if (typeof options === 'boolean') { options = {} }
options = { parser: 'babylon', ...options }
return prettier.format(source, options)

@@ -206,3 +209,3 @@ }

static replace (node, callback) {
return estraverse.replace(node, { enter: callback })
return replace(node, { enter: callback })
}

@@ -209,0 +212,0 @@ }

{
"name": "abstract-syntax-tree",
"version": "1.0.3",
"version": "1.1.0",
"description": "abstract syntax tree class for js",

@@ -13,3 +13,3 @@ "main": "index.js",

"engines": {
"node": ">=8.11.1"
"node": ">=10.14.1"
},

@@ -36,3 +36,3 @@ "repository": {

"benchmark": "^2.1.4",
"leakage": "^0.4.0",
"prettier": "^1.15.1",
"standard": "^11.0.1"

@@ -47,3 +47,2 @@ },

"estraverse": "^4.2.0",
"prettier": "^1.12.1",
"source-map": "^0.7.2",

@@ -50,0 +49,0 @@ "to-ast": "^1.0.0"

# abstract-syntax-tree
[![Build Status](https://travis-ci.org/buxlabs/abstract-syntax-tree.svg?branch=master)](https://travis-ci.org/buxlabs/ast) [![NSP Status](https://nodesecurity.io/orgs/buxlabs/projects/4b0bfe3e-43d0-4597-b407-dd44cec2f3d6/badge)](https://nodesecurity.io/orgs/buxlabs/projects/4b0bfe3e-43d0-4597-b407-dd44cec2f3d6)
![npm](https://img.shields.io/npm/v/abstract-syntax-tree.svg) [![Build Status](https://travis-ci.org/buxlabs/abstract-syntax-tree.svg?branch=master)](https://travis-ci.org/buxlabs/ast)
## What is an abstract syntax tree?
An abstract syntax tree is a way to represent the source code. In case of this library it is represented in the [estree](https://github.com/estree/estree) format.
For example, the following source code:
```js
const answer = 42
```
Has the following representation:
```json
{
"type": "Program",
"body": [
{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "answer"
},
"init": {
"type": "Literal",
"value": 42
}
}
],
"kind": "const"
}
]
}
```
## What are abstract syntax trees used for?
They're used e.g. for code's:
- highligthing
- linting
- refactoring
- transformations
- analysis
- minification
- obfuscation
- generation
- source maps
## Installation
`npm install abstract-syntax-tree`
## Key Features

@@ -12,11 +66,7 @@

## Installation
`npm install abstract-syntax-tree`
## Methods
### has
### find
Check if ast contains a node of given type.
Find all nodes of given type.

@@ -26,18 +76,18 @@ ```javascript

const ast = new AbstractSyntaxTree(source)
ast.has('VariableDeclaration')
ast.find('VariableDeclaration')
```
### count
### each
Count ast nodes of given type.
Iterate over all nodes of given type.
```javascript
const source = 'const a = "x"; const b = "y";'
const source = 'const a = "x";'
const ast = new AbstractSyntaxTree(source)
ast.count('VariableDeclaration')
ast.each('VariableDeclaration', node => {})
```
### find
### has
Find all nodes of given type.
Check if ast contains a node of given type.

@@ -47,13 +97,13 @@ ```javascript

const ast = new AbstractSyntaxTree(source)
ast.find('VariableDeclaration')
ast.has('VariableDeclaration')
```
### each
### count
Iterate over all nodes of given type.
Count ast nodes of given type.
```javascript
const source = 'const a = "x";'
const source = 'const a = "x"; const b = "y";'
const ast = new AbstractSyntaxTree(source)
ast.each('VariableDeclaration', node => {})
ast.count('VariableDeclaration')
```

@@ -60,0 +110,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc