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

asty

Package Overview
Dependencies
Maintainers
1
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asty - npm Package Compare versions

Comparing version 0.9.4 to 0.9.5

2

lib/asty.js

@@ -26,3 +26,3 @@ /*

!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.ASTY=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
"use strict";var _prototypeProperties=function(e,r,t){r&&Object.defineProperties(e,r),t&&Object.defineProperties(e.prototype,t)},ASTYBase=function(){function e(){}return _prototypeProperties(e,null,{init:{value:function(e){if("undefined"==typeof e)throw new Error("init: invalid argument");return this.T=e,this.A={},this.C=[],this.P={L:0,C:0,O:0},this},writable:!0,enumerable:!0,configurable:!0},merge:{value:function(e,r,t){if("object"!=typeof e)throw new Error("merge: invalid AST node argument");"undefined"==typeof r&&(r=!1),"undefined"==typeof t&&(t={});var n=this;if(r){var i=e.pos();n.pos(i.L,i.C,i.O)}return e.attrs().forEach(function(r){var i="undefined"!=typeof t[r]?t[r]:r;null!==i&&n.set(i,e.get(r))}),e.childs().forEach(function(e){n.add(e)}),this},writable:!0,enumerable:!0,configurable:!0},type:{value:function(e){if(0===arguments.length)return this.T;if(1===arguments.length)return this.T=e,this;throw new Error("type: invalid number of arguments")},writable:!0,enumerable:!0,configurable:!0},pos:{value:function(e,r,t){if(0===arguments.length)return this.P;if(arguments.length<=3)return this.P.L=e||0,this.P.C=r||0,this.P.O=t||0,this;throw new Error("pos: invalid number of arguments")},writable:!0,enumerable:!0,configurable:!0},set:{value:function(){if(1===arguments.length&&"object"==typeof arguments[0]){var e=this,r=arguments;Object.keys(r[0]).forEach(function(t){e.A[t]=r[0][t]})}else{if(2!==arguments.length)throw new Error("set: invalid arguments");this.A[arguments[0]]=arguments[1]}return this},writable:!0,enumerable:!0,configurable:!0},get:{value:function(e){if(1!==arguments.length)throw new Error("get: invalid number of arguments");if("string"!=typeof e)throw new Error("get: invalid argument");return this.A[e]},writable:!0,enumerable:!0,configurable:!0},attrs:{value:function(){return Object.keys(this.A)},writable:!0,enumerable:!0,configurable:!0},add:{value:function(){if(0===arguments.length)throw new Error("add: missing argument(s)");var e=function(e,r){if(!("object"==typeof r&&"string"==typeof r.T&&"object"==typeof r.P&&"object"==typeof r.A&&"object"==typeof r.C&&r.C instanceof Array))throw new Error("add: invalid AST node: "+JSON.stringify(r));e.push(r)};if(null!==arguments){var r=this;Array.prototype.slice.call(arguments,0).forEach(function(t){"object"==typeof t&&t instanceof Array?t.forEach(function(t){e(r.C,t)}):null!==t&&e(r.C,t)})}return this},writable:!0,enumerable:!0,configurable:!0},del:{value:function(){if(0===arguments.length)throw new Error("del: invalid argument");var e=this;return Array.prototype.slice.call(arguments,0).forEach(function(r){for(var t=!1,n=0;n<e.C.length;n++)if(e.C[n]===r){e.C.splice(n,1),t=!0;break}if(!t)throw new Error("del: child not found")}),this},writable:!0,enumerable:!0,configurable:!0},childs:{value:function(){return this.C},writable:!0,enumerable:!0,configurable:!0},walk:{value:function(e,r){"undefined"==typeof r&&(r="downward");var t=function(n,i,a){("downward"===r||"both"===r)&&e.call(null,n,i,a,"downward"),n.C.forEach(function(e){t(e,i+1,n)}),("upward"===r||"both"===r)&&e.call(null,n,i,a,"upward")};return t(this,0,null),this},writable:!0,enumerable:!0,configurable:!0}}),e}();module.exports=ASTYBase;
"use strict";var _prototypeProperties=function(e,t,r){t&&Object.defineProperties(e,t),r&&Object.defineProperties(e.prototype,r)},ASTYBase=function(){function e(){}return _prototypeProperties(e,null,{init:{value:function(e){if("undefined"==typeof e)throw new Error("init: invalid argument");return this.ASTy=!0,this.T=e,this.L={L:0,C:0,O:0},this.A={},this.C=[],this.P=null,this},writable:!0,enumerable:!0,configurable:!0},merge:{value:function(e,t,r){if("object"!=typeof e)throw new Error("merge: invalid AST node argument");"undefined"==typeof t&&(t=!1),"undefined"==typeof r&&(r={});var n=this;if(t){var i=e.pos();n.pos(i.L,i.C,i.O)}return e.attrs().forEach(function(t){var i="undefined"!=typeof r[t]?r[t]:t;null!==i&&n.set(i,e.get(t))}),e.childs().forEach(function(e){n.add(e)}),this},writable:!0,enumerable:!0,configurable:!0},type:{value:function(e){if(0===arguments.length)return this.T;if(1===arguments.length)return this.T=e,this;throw new Error("type: invalid number of arguments")},writable:!0,enumerable:!0,configurable:!0},pos:{value:function(e,t,r){if(0===arguments.length)return this.L;if(arguments.length<=3)return this.L.L=e||0,this.L.C=t||0,this.L.O=r||0,this;throw new Error("pos: invalid number of arguments")},writable:!0,enumerable:!0,configurable:!0},set:{value:function(){if(1===arguments.length&&"object"==typeof arguments[0]){var e=this,t=arguments;Object.keys(t[0]).forEach(function(r){e.A[r]=t[0][r]})}else{if(2!==arguments.length)throw new Error("set: invalid arguments");this.A[arguments[0]]=arguments[1]}return this},writable:!0,enumerable:!0,configurable:!0},get:{value:function(e){if(1!==arguments.length)throw new Error("get: invalid number of arguments");if("string"!=typeof e)throw new Error("get: invalid argument");return this.A[e]},writable:!0,enumerable:!0,configurable:!0},attrs:{value:function(){return Object.keys(this.A)},writable:!0,enumerable:!0,configurable:!0},add:{value:function(){if(0===arguments.length)throw new Error("add: missing argument(s)");var e=function(e,t){if(!("object"==typeof t&&"string"==typeof t.T&&"object"==typeof t.L&&"object"==typeof t.A&&"object"==typeof t.P&&"object"==typeof t.C&&t.C instanceof Array))throw new Error("add: invalid AST node: "+JSON.stringify(t));e.C.push(t),t.P=e};if(null!==arguments){var t=this;Array.prototype.slice.call(arguments,0).forEach(function(r){"object"==typeof r&&r instanceof Array?r.forEach(function(r){e(t,r)}):null!==r&&e(t,r)})}return this},writable:!0,enumerable:!0,configurable:!0},del:{value:function(){if(0===arguments.length)throw new Error("del: invalid argument");var e=this;return Array.prototype.slice.call(arguments,0).forEach(function(t){for(var r=!1,n=0;n<e.C.length;n++)if(e.C[n]===t){e.C.splice(n,1),t.P=null,r=!0;break}if(!r)throw new Error("del: child not found")}),this},writable:!0,enumerable:!0,configurable:!0},childs:{value:function(){return this.C},writable:!0,enumerable:!0,configurable:!0},parent:{value:function(){return this.P},writable:!0,enumerable:!0,configurable:!0},walk:{value:function(e,t){"undefined"==typeof t&&(t="downward");var r=function(n,i,a){("downward"===t||"both"===t)&&e.call(null,n,i,a,"downward"),n.C.forEach(function(e){r(e,i+1,n)}),("upward"===t||"both"===t)&&e.call(null,n,i,a,"upward")};return r(this,0,null),this},writable:!0,enumerable:!0,configurable:!0}}),e}();module.exports=ASTYBase;
},{}],2:[function(require,module,exports){

@@ -29,0 +29,0 @@ "use strict";var _prototypeProperties=function(e,r,t){r&&Object.defineProperties(e,r),t&&Object.defineProperties(e.prototype,t)},ASTYDump=function(){function e(){}return _prototypeProperties(e,null,{dump:{value:function(){var e="";return this.walk(function(r,t){for(var n=0;t>n;n++)e+=" ";e+=r.T+" ";var o=Object.keys(r.A);if(o.length>0){e+="(";var i=!0;o.forEach(function(t){i?i=!1:e+=", ",e+=t+": ";var n=r.A[t];switch(typeof n){case"string":e+='"'+n.replace(/\n/,"\\n").replace(/"/,'\\"')+'"';break;case"object":e+=n instanceof RegExp?"/"+n.toString().replace(/^\//,"").replace(/\/$/,"").replace(/\//g,"\\/")+"/":JSON.stringify(n);break;default:e+=JSON.stringify(n)}}),e+=") "}e+="["+r.P.L+"/"+r.P.C+"]\n"},"downward"),e},writable:!0,enumerable:!0,configurable:!0}}),e}();module.exports=ASTYDump;

{
"name": "asty",
"version": "0.9.4",
"version": "0.9.5",
"description": "Generic Abstract Syntax Tree (AST)",

@@ -5,0 +5,0 @@ "keywords": [ "ast", "abstract", "syntax", "tree" ],

@@ -91,2 +91,5 @@

- `ASTY#parent(): ASTY[]`:<br/>
Get parent node.
- `ASTY#walk(callback: (node: ASTY, depth: Number, parent: ASTY, when: String) => Void, when?: String): ASTY`:<br/>

@@ -93,0 +96,0 @@ Recursively walk the AST starting at this node (at depth 0). For

@@ -30,6 +30,8 @@ /*

throw new Error("init: invalid argument")
this.ASTy = true
this.T = T
this.L = { L: 0, C: 0, O: 0 }
this.A = {}
this.C = []
this.P = { L: 0, C: 0, O: 0 }
this.P = null
return this

@@ -78,7 +80,7 @@ }

if (arguments.length === 0)
return this.P
return this.L
else if (arguments.length <= 3) {
this.P.L = L || 0
this.P.C = C || 0
this.P.O = O || 0
this.L.L = L || 0
this.L.C = C || 0
this.L.O = O || 0
return this

@@ -122,10 +124,12 @@ }

throw new Error("add: missing argument(s)")
var _add = function (C, node) {
if (!((typeof node === "object") &&
(typeof node.T === "string") &&
(typeof node.P === "object") &&
(typeof node.A === "object") &&
(typeof node.C === "object" && node.C instanceof Array)))
throw new Error("add: invalid AST node: " + JSON.stringify(node))
C.push(node)
var _add = function (node, child) {
if (!((typeof child === "object") &&
(typeof child.T === "string") &&
(typeof child.L === "object") &&
(typeof child.A === "object") &&
(typeof child.P === "object") &&
(typeof child.C === "object" && child.C instanceof Array)))
throw new Error("add: invalid AST node: " + JSON.stringify(child))
node.C.push(child)
child.P = node
}

@@ -136,5 +140,5 @@ if (arguments !== null) {

if (typeof arg === "object" && arg instanceof Array)
arg.forEach(function (child) { _add(self.C, child) })
arg.forEach(function (child) { _add(self, child) })
else if (arg !== null)
_add(self.C, arg)
_add(self, arg)
})

@@ -155,2 +159,3 @@ }

self.C.splice(j, 1)
arg.P = null
found = true

@@ -171,2 +176,7 @@ break

/* get parent AST node */
parent () {
return this.P
}
/* walk the AST recursively */

@@ -173,0 +183,0 @@ walk (cb, when) {

@@ -26,13 +26,29 @@ /*

describe("ASTy Library", function () {
it("basic functionality", function () {
it("node base functionality", function () {
var ASTy = require("../lib/asty.js");
var ast = new ASTy("foo");
expect(ast).to.be.a("object")
expect(ast).to.include.keys("T", "A", "C", "P")
expect(ast.T).to.be.equal("foo")
expect(ast).to.include.keys("T", "L", "A", "P", "C")
expect(ast.type()).to.be.equal("foo")
expect(ast).to.respondTo("type")
expect(ast).to.respondTo("dump")
})
it("extension functionality", function () {
it("node tree structure", function () {
var ASTy = require("../lib/asty.js");
var node1 = new ASTy("1");
var node11 = new ASTy("1.1");
var node12 = new ASTy("1.2");
var node121 = new ASTy("1.2.1");
var node122 = new ASTy("1.2.2");
node1.add(node11, node12)
node12.add(node121, node122)
expect(node1.parent()).to.be.equal(null)
expect(node1.childs()).to.have.members([ node11, node12 ])
expect(node12.parent()).to.be.equal(node1)
expect(node12.childs()).to.have.members([ node121, node122 ])
expect(node121.parent()).to.be.equal(node12)
expect(node122.parent()).to.be.equal(node12)
})
it("node extension functionality", function () {
var ASTy = require("../lib/asty.js");
ASTy.extend({

@@ -39,0 +55,0 @@ foo: function (arg) {

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