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

abstract-syntax-tree

Package Overview
Dependencies
Maintainers
2
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 2.20.6 to 2.20.7

17

package.json
{
"name": "abstract-syntax-tree",
"version": "2.20.6",
"version": "2.20.7",
"description": "abstract syntax tree",

@@ -35,13 +35,14 @@ "main": "index.js",

"devDependencies": {
"ava": "^4.2.0",
"c8": "^7.11.0",
"standard": "^16.0.4"
"ava": "^5.3.0",
"c8": "^8.0.0",
"standard": "^17.1.0"
},
"dependencies": {
"ast-types": "0.14.2",
"astring": "^1.8.1",
"esquery": "^1.4.0",
"astring": "^1.8.6",
"esquery": "^1.5.0",
"estraverse": "^5.3.0",
"meriyah": "^4.2.1",
"source-map": "0.7.3"
"meriyah": "^4.3.7",
"pure-conditions": "^1.2.1",
"source-map": "^0.7.4"
},

@@ -48,0 +49,0 @@ "standard": {

@@ -0,1 +1,3 @@

const { isRegExp } = require('pure-conditions')
function isPrimitive (param) {

@@ -8,4 +10,12 @@ return typeof param === 'string' || typeof param === 'number' || typeof param === 'boolean' || param === null

this.type = 'Literal'
const options = isPrimitive(param) ? { value: param } : param
Object.assign(this, options)
if (isRegExp(param)) {
this.value = {}
this.regex = {
pattern: param.source || '',
flags: param.flags || ''
}
} else {
const options = isPrimitive(param) ? { value: param } : param
Object.assign(this, options)
}
}

@@ -12,0 +22,0 @@ }

const estemplate = require('./estemplate')
const parse = require('../parse')
const ArrayExpression = require('../nodes/ArrayExpression')
const Identifier = require('../nodes/Identifier')
const Literal = require('../nodes/Literal')
const UnaryExpression = require('../nodes/UnaryExpression')
// deprecated
const { builders } = require('ast-types')
const parse = require('../parse')

@@ -18,15 +23,27 @@ const typedArrays = {

function toAST (obj) {
if (typeof obj === 'undefined') { return builders.unaryExpression('void', builders.literal(0)) }
if (typeof obj === 'undefined') {
return new UnaryExpression({
operator: 'void',
argument: new Literal(0),
prefix: true
})
}
if (typeof obj === 'number') {
if (isNaN(obj)) { return builders.identifier('NaN') }
if (isNaN(obj)) { return new Identifier('NaN') }
if (obj === Infinity) { return builders.identifier('Infinity') }
if (obj === Infinity) { return new Identifier('Infinity') }
if (obj < 0) { return builders.unaryExpression('-', builders.literal(-obj)) }
if (obj < 0) {
return new UnaryExpression({
operator: '-',
argument: new Literal(-obj),
prefix: true
})
}
return builders.literal(obj)
return new Literal(obj)
}
if (obj === null || typeof obj === 'string' || typeof obj === 'boolean') { return builders.literal(obj) }
if (obj === null || typeof obj === 'string' || typeof obj === 'boolean') { return new Literal(obj) }

@@ -39,3 +56,3 @@ if (typeof obj === 'function') {

} catch (e) {
return builders.literal(null)
return new Literal(null)
}

@@ -45,9 +62,9 @@ }

if (Buffer.isBuffer(obj)) {
return builders.newExpression(builders.identifier('Buffer'), [
builders.literal(obj.toString('base64')),
builders.literal('base64')
return builders.newExpression(new Identifier('Buffer'), [
new Literal(obj.toString('base64')),
new Literal('base64')
])
}
if (Array.isArray(obj)) { return builders.arrayExpression(obj.map(toAST)) }
if (Array.isArray(obj)) { return new ArrayExpression(obj.map(toAST)) }

@@ -57,3 +74,3 @@ if (typeof obj === 'object') {

if (type === 'String' || type === 'Number' || type === 'Boolean') { return builders.newExpression(builders.identifier(type), [toAST(obj.valueOf())]) }
if (type === 'String' || type === 'Number' || type === 'Boolean') { return builders.newExpression(new Identifier(type), [toAST(obj.valueOf())]) }

@@ -71,10 +88,10 @@ if (type === 'ArrayBuffer') {

if (allZero) { return builders.newExpression(builders.identifier(type), [builders.literal(obj.byteLength)]) }
if (allZero) { return builders.newExpression(new Identifier(type), [new Literal(obj.byteLength)]) }
return builders.memberExpression(toAST(buf), builders.identifier('buffer'))
return builders.memberExpression(toAST(buf), new Identifier('buffer'))
}
if (typedArrays[type]) {
return builders.newExpression(builders.identifier(type), [
builders.arrayExpression(Array.prototype.slice.call(obj).map(toAST))
return builders.newExpression(new Identifier(type), [
new ArrayExpression(Array.prototype.slice.call(obj).map(toAST))
])

@@ -91,8 +108,8 @@ }

return builders.newExpression(builders.identifier(type), [d])
return builders.newExpression(new Identifier(type), [d])
}
if (type === 'Error') { return builders.newExpression(builders.identifier(obj.constructor.name), [toAST(obj.message)]) }
if (type === 'Error') { return builders.newExpression(new Identifier(obj.constructor.name), [toAST(obj.message)]) }
if (type === 'RegExp') { return builders.literal(obj) }
if (type === 'RegExp') { return new Literal(obj) }

@@ -104,3 +121,3 @@ if (typeof obj.toAST === 'function') { return obj.toAST() }

if (Object.prototype.hasOwnProperty.call(obj, key)) {
properties.push(builders.property('init', builders.literal(key), toAST(obj[key])))
properties.push(builders.property('init', new Literal(key), toAST(obj[key])))
}

@@ -107,0 +124,0 @@ }

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