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 1.7.9 to 1.7.10

2

lib/asty.browser.js

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

(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ASTY = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(_dereq_,module,exports){
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var ASTYBase=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"init",value:function(e,t,n,r){if(arguments.length<2)throw new Error("init: invalid number of arguments");if(this.ctx=e,this.ASTy=!0,this.T=t,this.L={L:0,C:0,O:0},this.A={},this.C=[],this.P=null,"object"===(void 0===n?"undefined":_typeof(n)))for(var i in n)n.hasOwnProperty(i)&&this.set(i,n[i]);return"object"===(void 0===r?"undefined":_typeof(r))&&r instanceof Array&&this.add(r),this}},{key:"create",value:function(e,t,n){return this.ctx.create(e,t,n)}},{key:"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")}},{key:"pos",value:function(e,t,n){if(0===arguments.length)return{line:this.L.L,column:this.L.C,offset:this.L.O};if(arguments.length<=3)return this.L.L=e||0,this.L.C=t||0,this.L.O=n||0,this;throw new Error("pos: invalid number of arguments")}},{key:"set",value:function(){for(var e=this,t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];if(1===n.length&&"object"===_typeof(n[0]))Object.keys(n[0]).forEach(function(t){void 0!==n[0][t]?e.A[t]=n[0][t]:delete e.A[t]});else{if(2!==n.length)throw new Error("set: invalid number of arguments");void 0!==n[1]?this.A[n[0]]=n[1]:delete this.A[n[0]]}return this}},{key:"unset",value:function(){for(var e=this,t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];if(1===n.length&&"object"===_typeof(n[0])&&n[0]instanceof Array)n[0].forEach(function(t){delete e.A[t]});else{if(1!==n.length)throw new Error("unset: invalid number of arguments");delete this.A[n[0]]}return this}},{key:"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 key argument");return this.A[e]}},{key:"attrs",value:function(){return Object.keys(this.A)}},{key:"nth",value:function(){if(null===this.P)return 1;var e=this.P.C.indexOf(this);if(e<0)throw new Error("nth: internal error -- node not in childs of its parent");return e}},{key:"ins",value:function(e){for(var t=this,n=arguments.length,r=Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];if(0===r.length)throw new Error("ins: invalid number of arguments");if(e<0&&(e=this.C.length+1-e),!(e>=0&&e<=this.C.length))throw new Error("ins: invalid position");var o=function(n){if(!t.ctx.isA(n))throw new Error("ins: invalid AST node argument");t.C.splice(e++,0,n),n.P=t};return r.forEach(function(e){"object"===(void 0===e?"undefined":_typeof(e))&&e instanceof Array?e.forEach(function(e){o(e)}):null!==e&&o(e)}),this}},{key:"add",value:function(){for(var e=this,t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];if(0===n.length)throw new Error("add: invalid number of arguments");var i=function(t){if(!e.ctx.isA(t))throw new Error("add: invalid AST node argument");e.C.push(t),t.P=e};return n.forEach(function(e){"object"===(void 0===e?"undefined":_typeof(e))&&e instanceof Array?e.forEach(function(e){i(e)}):null!==e&&i(e)}),this}},{key:"del",value:function(){for(var e=this,t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];if(0===n.length)throw new Error("del: invalid number of arguments");return n.forEach(function(t){if(!e.ctx.isA(t))throw new Error("del: invalid AST node argument");for(var n=!1,r=0;r<e.C.length;r++)if(e.C[r]===t){e.C.splice(r,1),t.P=null,n=!0;break}if(!n)throw new Error("del: AST node not found in childs")}),this}},{key:"childs",value:function(){if(arguments.length>2)throw new Error("childs: invalid number of arguments");if(2===arguments.length&&"number"==typeof(arguments.length<=0?void 0:arguments[0])&&"number"==typeof(arguments.length<=1?void 0:arguments[1]))return this.C.slice(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1]);if(1===arguments.length&&"number"==typeof(arguments.length<=0?void 0:arguments[0]))return this.C.slice(arguments.length<=0?void 0:arguments[0]);if(0===arguments.length)return this.C;throw new Error("childs: invalid type of arguments")}},{key:"child",value:function(e){if("number"!=typeof e)throw new Error("child: invalid argument");return e<this.C.length?this.C[e]:null}},{key:"parent",value:function(){return this.P}},{key:"serialize",value:function(){return this.ctx.__serialize(this)}}]),e}();exports.default=ASTYBase;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var ASTYBase=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"init",value:function(e,t,n,r){if(arguments.length<2)throw new Error("init: invalid number of arguments");if(this.ctx=e,this.ASTy=!0,this.T=t,this.L={L:0,C:0,O:0},this.A={},this.C=[],this.P=null,"object"===(void 0===n?"undefined":_typeof(n)))for(var i in n)n.hasOwnProperty(i)&&this.set(i,n[i]);return"object"===(void 0===r?"undefined":_typeof(r))&&r instanceof Array&&this.add(r),this}},{key:"create",value:function(e,t,n){return this.ctx.create(e,t,n)}},{key:"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")}},{key:"pos",value:function(e,t,n){if(0===arguments.length)return{line:this.L.L,column:this.L.C,offset:this.L.O};if(arguments.length<=3)return this.L.L=e||0,this.L.C=t||0,this.L.O=n||0,this;throw new Error("pos: invalid number of arguments")}},{key:"set",value:function(){for(var e=this,t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];if(1===n.length&&"object"===_typeof(n[0]))Object.keys(n[0]).forEach(function(t){void 0!==n[0][t]?e.A[t]=n[0][t]:delete e.A[t]});else{if(2!==n.length)throw new Error("set: invalid number of arguments");void 0!==n[1]?this.A[n[0]]=n[1]:delete this.A[n[0]]}return this}},{key:"unset",value:function(){for(var e=this,t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];if(1===n.length&&"object"===_typeof(n[0])&&n[0]instanceof Array)n[0].forEach(function(t){delete e.A[t]});else{if(1!==n.length)throw new Error("unset: invalid number of arguments");delete this.A[n[0]]}return this}},{key:"get",value:function(){for(var e=this,t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];if(1!==n.length)throw new Error("get: invalid number of arguments");if("object"===_typeof(n[0])&&n[0]instanceof Array)return n[0].map(function(t){if("string"!=typeof t)throw new Error("get: invalid key argument");return e.A[t]});var i=n[0];if("string"!=typeof i)throw new Error("get: invalid key argument");return this.A[i]}},{key:"attrs",value:function(){return Object.keys(this.A)}},{key:"nth",value:function(){if(null===this.P)return 1;var e=this.P.C.indexOf(this);if(e<0)throw new Error("nth: internal error -- node not in childs of its parent");return e}},{key:"ins",value:function(e){for(var t=this,n=arguments.length,r=Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];if(0===r.length)throw new Error("ins: invalid number of arguments");if(e<0&&(e=this.C.length+1-e),!(e>=0&&e<=this.C.length))throw new Error("ins: invalid position");var o=function(n){if(!t.ctx.isA(n))throw new Error("ins: invalid AST node argument");t.C.splice(e++,0,n),n.P=t};return r.forEach(function(e){"object"===(void 0===e?"undefined":_typeof(e))&&e instanceof Array?e.forEach(function(e){o(e)}):null!==e&&o(e)}),this}},{key:"add",value:function(){for(var e=this,t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];if(0===n.length)throw new Error("add: invalid number of arguments");var i=function(t){if(!e.ctx.isA(t))throw new Error("add: invalid AST node argument");e.C.push(t),t.P=e};return n.forEach(function(e){"object"===(void 0===e?"undefined":_typeof(e))&&e instanceof Array?e.forEach(function(e){i(e)}):null!==e&&i(e)}),this}},{key:"del",value:function(){for(var e=this,t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];if(0===n.length)throw new Error("del: invalid number of arguments");return n.forEach(function(t){if(!e.ctx.isA(t))throw new Error("del: invalid AST node argument");for(var n=!1,r=0;r<e.C.length;r++)if(e.C[r]===t){e.C.splice(r,1),t.P=null,n=!0;break}if(!n)throw new Error("del: AST node not found in childs")}),this}},{key:"childs",value:function(){if(arguments.length>2)throw new Error("childs: invalid number of arguments");if(2===arguments.length&&"number"==typeof(arguments.length<=0?void 0:arguments[0])&&"number"==typeof(arguments.length<=1?void 0:arguments[1]))return this.C.slice(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1]);if(1===arguments.length&&"number"==typeof(arguments.length<=0?void 0:arguments[0]))return this.C.slice(arguments.length<=0?void 0:arguments[0]);if(0===arguments.length)return this.C;throw new Error("childs: invalid type of arguments")}},{key:"child",value:function(e){if("number"!=typeof e)throw new Error("child: invalid argument");return e<this.C.length?this.C[e]:null}},{key:"parent",value:function(){return this.P}},{key:"serialize",value:function(){return this.ctx.__serialize(this)}}]),e}();exports.default=ASTYBase;
},{}],2:[function(_dereq_,module,exports){

@@ -29,0 +29,0 @@ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var tree={mid:{unicode:String.fromCharCode(9500),ascii:"+"},last:{unicode:String.fromCharCode(9492),ascii:"+"},down:{unicode:String.fromCharCode(9474),ascii:"|"},left:{unicode:String.fromCharCode(9472),ascii:"-"}},ASTYDump=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"dump",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1/0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(e,t){return t},r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],n="",o=this;return this.walk(function(a,i){if(!(i>e)){if(i>0){var c=function(e){var t=0,r=0;return null!==e.P&&(t=e.P.C.indexOf(e),r=e.P.C.length-1),{nth:t,max:r}},u=c(a),l=u.nth,f=u.max,s=" ";s=r?""+tree.left.unicode+tree.left.unicode+s:""+tree.left.ascii+tree.left.ascii+s,s=l<f?""+(r?tree.mid.unicode:tree.mid.ascii)+s:""+(r?tree.last.unicode:tree.last.ascii)+s;for(var p=a.P;null!==p&&p!==o;p=p.P)if(null!==p.P){var d=c(p);s=d.nth<d.max?(r?tree.down.unicode:tree.down.ascii)+" "+s:" "+s}n+=t("tree",s)}n+=t("type",a.T)+" ";var g=Object.keys(a.A);if(g.length>0){n+=t("parenthesis","(");var m=!0;g.forEach(function(e){m?m=!1:n+=t("comma",",")+" ",n+=t("key",e)+t("colon",":")+" ";var r=a.A[e];switch(void 0===r?"undefined":_typeof(r)){case"boolean":case"number":n+=t("value",r.toString());break;case"string":var o=function(e){return e.charCodeAt(0).toString(16).toUpperCase()};n+=t("value",'"'+r.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E\x0F]/g,function(e){return"\\x0"+o(e)}).replace(/[\x10-\x1F\x80-\xFF]/g,function(e){return"\\x"+o(e)}).replace(/[\u0100-\u0FFF]/g,function(e){return"\\u0"+o(e)}).replace(/[\u1000-\uFFFF]/g,function(e){return"\\u"+o(e)})+'"');break;case"object":r instanceof RegExp?n+=t("value","/"+r.source+"/"):n+=t("value",JSON.stringify(r));break;default:n+=t("value",JSON.stringify(r))}}),n+=t("parenthesis",")")+" "}n+=t("position",t("bracket","[")+t("line",a.L.L)+t("slash",",")+t("column",a.L.C)+t("bracket","]")),n+="\n"}},"downward"),n}}]),e}();exports.default=ASTYDump;

@@ -167,6 +167,20 @@ /*

key: "get",
value: function get(key) {
if (arguments.length !== 1) throw new Error("get: invalid number of arguments");
if (typeof key !== "string") throw new Error("get: invalid key argument");
return this.A[key];
value: function get() {
var _this3 = this;
for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
if (args.length !== 1) throw new Error("get: invalid number of arguments");
if (typeof args[0] === "object" && args[0] instanceof Array) {
return args[0].map(function (key) {
if (typeof key !== "string") throw new Error("get: invalid key argument");
return _this3.A[key];
});
} else {
var key = args[0];
if (typeof key !== "string") throw new Error("get: invalid key argument");
return this.A[key];
}
}

@@ -198,6 +212,6 @@

value: function ins(pos) {
var _this3 = this;
var _this4 = this;
for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
args[_key3 - 1] = arguments[_key3];
for (var _len4 = arguments.length, args = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
args[_key4 - 1] = arguments[_key4];
}

@@ -209,5 +223,5 @@

var _ins = function _ins(node) {
if (!_this3.ctx.isA(node)) throw new Error("ins: invalid AST node argument");
_this3.C.splice(pos++, 0, node);
node.P = _this3;
if (!_this4.ctx.isA(node)) throw new Error("ins: invalid AST node argument");
_this4.C.splice(pos++, 0, node);
node.P = _this4;
};

@@ -227,6 +241,6 @@ args.forEach(function (arg) {

value: function add() {
var _this4 = this;
var _this5 = this;
for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
args[_key4] = arguments[_key4];
for (var _len5 = arguments.length, args = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
args[_key5] = arguments[_key5];
}

@@ -236,5 +250,5 @@

var _add = function _add(node) {
if (!_this4.ctx.isA(node)) throw new Error("add: invalid AST node argument");
_this4.C.push(node);
node.P = _this4;
if (!_this5.ctx.isA(node)) throw new Error("add: invalid AST node argument");
_this5.C.push(node);
node.P = _this5;
};

@@ -254,6 +268,6 @@ args.forEach(function (arg) {

value: function del() {
var _this5 = this;
var _this6 = this;
for (var _len5 = arguments.length, args = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
args[_key5] = arguments[_key5];
for (var _len6 = arguments.length, args = Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
args[_key6] = arguments[_key6];
}

@@ -263,7 +277,7 @@

args.forEach(function (node) {
if (!_this5.ctx.isA(node)) throw new Error("del: invalid AST node argument");
if (!_this6.ctx.isA(node)) throw new Error("del: invalid AST node argument");
var found = false;
for (var j = 0; j < _this5.C.length; j++) {
if (_this5.C[j] === node) {
_this5.C.splice(j, 1);
for (var j = 0; j < _this6.C.length; j++) {
if (_this6.C[j] === node) {
_this6.C.splice(j, 1);
node.P = null;

@@ -270,0 +284,0 @@ found = true;

{
"name": "asty",
"version": "1.7.9",
"version": "1.7.10",
"description": "Abstract Syntax Tree (AST) Data Structure",

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

@@ -95,3 +95,5 @@

- `ASTYNode#get(name: String): Object`:<br/>
Get value of attribute `name`.
`ASTYNode#get(names: String[]): Object[]`:<br/>
Get value of a particular attribute `name`,
or get array of values corresponding to each name in `names`.

@@ -98,0 +100,0 @@ - `ASTYNode#attrs(): String[]`:<br/>

@@ -121,8 +121,18 @@ /*

/* get AST node attributes */
get (key) {
if (arguments.length !== 1)
get (...args) {
if (args.length !== 1)
throw new Error("get: invalid number of arguments")
if (typeof key !== "string")
throw new Error("get: invalid key argument")
return this.A[key]
if (typeof args[0] === "object" && args[0] instanceof Array) {
return args[0].map((key) => {
if (typeof key !== "string")
throw new Error("get: invalid key argument")
return this.A[key]
})
}
else {
let key = args[0]
if (typeof key !== "string")
throw new Error("get: invalid key argument")
return this.A[key]
}
}

@@ -129,0 +139,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