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.0.0 to 1.0.1

2

bower.json
{
"name": "asty",
"version": "1.0.0",
"version": "1.0.1",
"description": "Abstract Syntax Tree (AST) Data Structure",

@@ -5,0 +5,0 @@ "main": "lib/asty.browser.js",

@@ -26,11 +26,11 @@ /*

!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(_dereq_,module,exports){
"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,t,r){if("undefined"==typeof e)throw new Error("init: invalid argument");if(this.ASTy=!0,this.T=e,this.L={L:0,C:0,O:0},this.A={},this.C=[],this.P=null,"object"==typeof t)for(var n in t)t.hasOwnProperty(n)&&this.set(n,t[n]);return"object"==typeof r&&r instanceof Array&&this.add(r),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}}),e}();module.exports=ASTYBase;
"use strict";var _prototypeProperties=function(t,e,r){e&&Object.defineProperties(t,e),r&&Object.defineProperties(t.prototype,r)},ASTYBase=function(){function t(){}return _prototypeProperties(t,null,{init:{value:function(t,e,r){if("undefined"==typeof t)throw new Error("init: invalid argument");if(this.ASTy=!0,this.T=t,this.L={L:0,C:0,O:0},this.A={},this.C=[],this.P=null,"object"==typeof e)for(var n in e)e.hasOwnProperty(n)&&this.set(n,e[n]);return"object"==typeof r&&r instanceof Array&&this.add(r),this},writable:!0,configurable:!0},type:{value:function(t){if(0===arguments.length)return this.T;if(1===arguments.length)return this.T=t,this;throw new Error("type: invalid number of arguments")},writable:!0,configurable:!0},pos:{value:function(t,e,r){if(0===arguments.length)return this.L;if(arguments.length<=3)return this.L.L=t||0,this.L.C=e||0,this.L.O=r||0,this;throw new Error("pos: invalid number of arguments")},writable:!0,configurable:!0},set:{value:function(){var t=this,e=arguments;if(1===arguments.length&&"object"==typeof arguments[0])!function(){var r=e;Object.keys(r[0]).forEach(function(e){t.A[e]=r[0][e]})}();else{if(2!==arguments.length)throw new Error("set: invalid arguments");this.A[arguments[0]]=arguments[1]}return this},writable:!0,configurable:!0},get:{value:function(t){if(1!==arguments.length)throw new Error("get: invalid number of arguments");if("string"!=typeof t)throw new Error("get: invalid argument");return this.A[t]},writable:!0,configurable:!0},attrs:{value:function(){return Object.keys(this.A)},writable:!0,configurable:!0},add:{value:function(){var t=this;if(0===arguments.length)throw new Error("add: missing argument(s)");var e=function(t,e){if(!("object"==typeof e&&"string"==typeof e.T&&"object"==typeof e.L&&"object"==typeof e.A&&"object"==typeof e.P&&"object"==typeof e.C&&e.C instanceof Array))throw new Error("add: invalid AST node: "+JSON.stringify(e));t.C.push(e),e.P=t};return null!==arguments&&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)}),this},writable:!0,configurable:!0},del:{value:function(){var t=this;if(0===arguments.length)throw new Error("del: invalid argument");return Array.prototype.slice.call(arguments,0).forEach(function(e){for(var r=!1,n=0;n<t.C.length;n++)if(t.C[n]===e){t.C.splice(n,1),e.P=null,r=!0;break}if(!r)throw new Error("del: child not found")}),this},writable:!0,configurable:!0},childs:{value:function(){return this.C},writable:!0,configurable:!0},parent:{value:function(){return this.P},writable:!0,configurable:!0}}),t}();module.exports=ASTYBase;
},{}],2:[function(_dereq_,module,exports){
"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(e){void 0===e&&(e=1/0);var r="";return this.walk(function(t,n){if(!(n>e)){for(var i=0;n>i;i++)r+=" ";r+=t.T+" ";var o=Object.keys(t.A);if(o.length>0){r+="(";var a=!0;o.forEach(function(e){a?a=!1:r+=", ",r+=e+": ";var n=t.A[e];switch(typeof n){case"string":r+='"'+n.replace(/\n/,"\\n").replace(/"/,'\\"')+'"';break;case"object":r+=n instanceof RegExp?"/"+n.toString().replace(/^\//,"").replace(/\/$/,"").replace(/\//g,"\\/")+"/":JSON.stringify(n);break;default:r+=JSON.stringify(n)}}),r+=") "}r+="["+t.L.L+"/"+t.L.C+"]\n"}},"downward"),r},writable:!0,enumerable:!0,configurable:!0}}),e}();module.exports=ASTYDump;
"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(e){void 0===e&&(e=1/0);var r="";return this.walk(function(t,n){if(!(n>e)){for(var o=0;n>o;o++)r+=" ";r+=t.T+" ";var i=Object.keys(t.A);i.length>0&&!function(){r+="(";var e=!0;i.forEach(function(n){e?e=!1:r+=", ",r+=n+": ";var o=t.A[n];switch(typeof o){case"string":r+='"'+o.replace(/\n/,"\\n").replace(/"/,'\\"')+'"';break;case"object":r+=o instanceof RegExp?"/"+o.toString().replace(/^\//,"").replace(/\/$/,"").replace(/\//g,"\\/")+"/":JSON.stringify(o);break;default:r+=JSON.stringify(o)}}),r+=") "}(),r+="["+t.L.L+"/"+t.L.C+"]\n"}},"downward"),r},writable:!0,configurable:!0}}),e}();module.exports=ASTYDump;
},{}],3:[function(_dereq_,module,exports){
"use strict";var _prototypeProperties=function(e,t,r){t&&Object.defineProperties(e,t),r&&Object.defineProperties(e.prototype,r)},ASTYMerge=function(){function e(){}return _prototypeProperties(e,null,{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 o=this;if(t){var n=e.pos();o.pos(n.L,n.C,n.O)}return e.attrs().forEach(function(t){var n="undefined"!=typeof r[t]?r[t]:t;null!==n&&o.set(n,e.get(t))}),e.childs().forEach(function(e){o.add(e)}),this},writable:!0,enumerable:!0,configurable:!0}}),e}();module.exports=ASTYMerge;
"use strict";var _prototypeProperties=function(e,t,r){t&&Object.defineProperties(e,t),r&&Object.defineProperties(e.prototype,r)},ASTYMerge=function(){function e(){}return _prototypeProperties(e,null,{merge:{value:function(e,t,r){var o=this;if("object"!=typeof e)throw new Error("merge: invalid AST node argument");if("undefined"==typeof t&&(t=!1),"undefined"==typeof r&&(r={}),t){var n=e.pos();this.pos(n.L,n.C,n.O)}return e.attrs().forEach(function(t){var n="undefined"!=typeof r[t]?r[t]:t;null!==n&&o.set(n,e.get(t))}),e.childs().forEach(function(e){o.add(e)}),this},writable:!0,configurable:!0}}),e}();module.exports=ASTYMerge;
},{}],4:[function(_dereq_,module,exports){
"use strict";var _prototypeProperties=function(e,t,r){t&&Object.defineProperties(e,t),r&&Object.defineProperties(e.prototype,r)},ASTYWalk=function(){function e(){}return _prototypeProperties(e,null,{walk:{value:function(e,t){"undefined"==typeof t&&(t="downward");var r=function(n,o,l){("downward"===t||"both"===t)&&e.call(null,n,o,l,"downward"),n.C.forEach(function(e){r(e,o+1,n)}),("upward"===t||"both"===t)&&e.call(null,n,o,l,"upward")};return r(this,0,null),this},writable:!0,enumerable:!0,configurable:!0}}),e}();module.exports=ASTYWalk;
"use strict";var _prototypeProperties=function(t,e,r){e&&Object.defineProperties(t,e),r&&Object.defineProperties(t.prototype,r)},ASTYWalk=function(){function t(){}return _prototypeProperties(t,null,{walk:{value:function(t,e){"undefined"==typeof e&&(e="downward");var r=function(n,o,l){("downward"===e||"both"===e)&&t.call(null,n,o,l,"downward"),n.C.forEach(function(t){r(t,o+1,n)}),("upward"===e||"both"===e)&&t.call(null,n,o,l,"upward")};return r(this,0,null),this},writable:!0,configurable:!0}}),t}();module.exports=ASTYWalk;
},{}],5:[function(_dereq_,module,exports){
"use strict";var _prototypeProperties=function(e,t,r){t&&Object.defineProperties(e,t),r&&Object.defineProperties(e.prototype,r)},ASTYBase=_dereq_("./asty-base.js"),ASTYMerge=_dereq_("./asty-merge.js"),ASTYWalk=_dereq_("./asty-walk.js"),ASTYDump=_dereq_("./asty-dump.js"),ASTYCtx=function(){function e(){var t=this;if(!(this instanceof e))return new e;this.ASTYNode=function(){};var r=[ASTYBase,ASTYMerge,ASTYWalk,ASTYDump];return r.forEach(function(e){for(var r in e.prototype)e.prototype.hasOwnProperty(r)&&(t.ASTYNode.prototype[r]=e.prototype[r])}),this}return _prototypeProperties(e,null,{extend:{value:function(e){for(var t in e)e.hasOwnProperty(t)&&(this.ASTYNode.prototype[t]=e[t]);return this},writable:!0,enumerable:!0,configurable:!0},create:{value:function(e){return(new this.ASTYNode).init(e)},writable:!0,enumerable:!0,configurable:!0},isA:{value:function(e){return"object"==typeof e&&e instanceof this.ASTYNode&&"boolean"==typeof e.ASTy&&e.ASTy===!0},writable:!0,enumerable:!0,configurable:!0}}),e}();module.exports=ASTYCtx;
"use strict";var _prototypeProperties=function(e,t,r){t&&Object.defineProperties(e,t),r&&Object.defineProperties(e.prototype,r)},ASTYBase=_dereq_("./asty-base.js"),ASTYMerge=_dereq_("./asty-merge.js"),ASTYWalk=_dereq_("./asty-walk.js"),ASTYDump=_dereq_("./asty-dump.js"),ASTYCtx=function(){function e(){var t=this;if(!(this instanceof e))return new e;this.ASTYNode=function(){};var r=[ASTYBase,ASTYMerge,ASTYWalk,ASTYDump];return r.forEach(function(e){for(var r in e.prototype)e.prototype.hasOwnProperty(r)&&(t.ASTYNode.prototype[r]=e.prototype[r])}),this}return _prototypeProperties(e,null,{extend:{value:function(e){for(var t in e)e.hasOwnProperty(t)&&(this.ASTYNode.prototype[t]=e[t]);return this},writable:!0,configurable:!0},create:{value:function(e){return(new this.ASTYNode).init(e)},writable:!0,configurable:!0},isA:{value:function(e){return"object"==typeof e&&e instanceof this.ASTYNode&&"boolean"==typeof e.ASTy&&e.ASTy===!0},writable:!0,configurable:!0}}),e}();module.exports=ASTYCtx;
},{"./asty-base.js":1,"./asty-dump.js":2,"./asty-merge.js":3,"./asty-walk.js":4}]},{},[1,2,3,4,5])(5)

@@ -37,0 +37,0 @@ });

@@ -28,6 +28,3 @@ /*

var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); };

@@ -59,165 +56,158 @@ /*

var ASTYBase = (function () {
function ASTYBase() {}
function ASTYBase() {}
_prototypeProperties(ASTYBase, null, {
init: {
/* AST node initialization */
value: function init(T, A, C) {
if (typeof T === "undefined") 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 = null;
if (typeof A === "object") {
for (var name in A) {
if (A.hasOwnProperty(name)) this.set(name, A[name]);
}
}
if (typeof C === "object" && C instanceof Array) this.add(C);
return this;
},
writable: true,
enumerable: true,
configurable: true
},
type: {
_prototypeProperties(ASTYBase, null, {
init: {
/* AST node initialization */
value: function init(T, A, C) {
if (typeof T === "undefined") 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 = null;
if (typeof A === "object") {
for (var _name in A) {
if (A.hasOwnProperty(_name)) this.set(_name, A[_name]);
}
}
if (typeof C === "object" && C instanceof Array) this.add(C);
return this;
},
writable: true,
configurable: true
},
type: {
/* check the type of an AST node */
value: function type(T) {
if (arguments.length === 0) return this.T;else if (arguments.length === 1) {
this.T = T;
return this;
} else throw new Error("type: invalid number of arguments");
},
writable: true,
enumerable: true,
configurable: true
},
pos: {
/* check the type of an AST node */
value: function type(T) {
if (arguments.length === 0) return this.T;else if (arguments.length === 1) {
this.T = T;
return this;
} else throw new Error("type: invalid number of arguments");
},
writable: true,
configurable: true
},
pos: {
/* set the parsing position */
value: function pos(L, C, O) {
if (arguments.length === 0) return this.L;else if (arguments.length <= 3) {
this.L.L = L || 0;
this.L.C = C || 0;
this.L.O = O || 0;
return this;
} else throw new Error("pos: invalid number of arguments");
},
writable: true,
enumerable: true,
configurable: true
},
set: {
/* set the parsing position */
value: function pos(L, C, O) {
if (arguments.length === 0) return this.L;else if (arguments.length <= 3) {
this.L.L = L || 0;
this.L.C = C || 0;
this.L.O = O || 0;
return this;
} else throw new Error("pos: invalid number of arguments");
},
writable: true,
configurable: true
},
set: {
/* set AST node attributes */
value: function set() {
if (arguments.length === 1 && typeof arguments[0] === "object") {
var self = this;
var args = arguments;
Object.keys(args[0]).forEach(function (key) {
self.A[key] = args[0][key];
});
} else if (arguments.length === 2) this.A[arguments[0]] = arguments[1];else throw new Error("set: invalid arguments");
return this;
},
writable: true,
enumerable: true,
configurable: true
},
get: {
/* set AST node attributes */
value: function set() {
var _this = this;
var _arguments = arguments;
if (arguments.length === 1 && typeof arguments[0] === "object") {
(function () {
var args = _arguments;
Object.keys(args[0]).forEach(function (key) {
_this.A[key] = args[0][key];
});
})();
} else if (arguments.length === 2) this.A[arguments[0]] = arguments[1];else throw new Error("set: invalid arguments");
return this;
},
writable: true,
configurable: true
},
get: {
/* get AST node attributes */
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 argument");
return this.A[key];
},
writable: true,
enumerable: true,
configurable: true
},
attrs: {
/* get AST node attributes */
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 argument");
return this.A[key];
},
writable: true,
configurable: true
},
attrs: {
/* get names of all AST node attributes */
value: function attrs() {
return Object.keys(this.A);
},
writable: true,
enumerable: true,
configurable: true
},
add: {
/* get names of all AST node attributes */
value: function attrs() {
return Object.keys(this.A);
},
writable: true,
configurable: true
},
add: {
/* add child AST node(s) */
value: function add() {
if (arguments.length === 0) throw new Error("add: missing argument(s)");
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;
};
if (arguments !== null) {
var self = this;
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
if (typeof arg === "object" && arg instanceof Array) arg.forEach(function (child) {
_add(self, child);
});else if (arg !== null) _add(self, arg);
});
}
return this;
},
writable: true,
enumerable: true,
configurable: true
},
del: {
/* add child AST node(s) */
value: function add() {
var _this = this;
if (arguments.length === 0) throw new Error("add: missing argument(s)");
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;
};
if (arguments !== null) {
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
if (typeof arg === "object" && arg instanceof Array) arg.forEach(function (child) {
_add(_this, child);
});else if (arg !== null) _add(_this, arg);
});
}
return this;
},
writable: true,
configurable: true
},
del: {
/* delete child AST node(s) */
value: function del() {
if (arguments.length === 0) throw new Error("del: invalid argument");
var self = this;
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
var found = false;
for (var j = 0; j < self.C.length; j++) {
if (self.C[j] === arg) {
self.C.splice(j, 1);
arg.P = null;
found = true;
break;
}
}
if (!found) throw new Error("del: child not found");
});
return this;
},
writable: true,
enumerable: true,
configurable: true
},
childs: {
/* delete child AST node(s) */
value: function del() {
var _this = this;
if (arguments.length === 0) throw new Error("del: invalid argument");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
var found = false;
for (var j = 0; j < _this.C.length; j++) {
if (_this.C[j] === arg) {
_this.C.splice(j, 1);
arg.P = null;
found = true;
break;
}
}
if (!found) throw new Error("del: child not found");
});
return this;
},
writable: true,
configurable: true
},
childs: {
/* get child AST nodes */
value: function childs() {
return this.C;
},
writable: true,
enumerable: true,
configurable: true
},
parent: {
/* get child AST nodes */
value: function childs() {
return this.C;
},
writable: true,
configurable: true
},
parent: {
/* get parent AST node */
value: function parent() {
return this.P;
},
writable: true,
enumerable: true,
configurable: true
}
});
/* get parent AST node */
value: function parent() {
return this.P;
},
writable: true,
configurable: true
}
});
return ASTYBase;
return ASTYBase;
})();

@@ -230,6 +220,3 @@

var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); };

@@ -261,47 +248,49 @@ /*

var ASTYDump = (function () {
function ASTYDump() {}
function ASTYDump() {}
_prototypeProperties(ASTYDump, null, {
dump: {
/* dump the AST recursively */
value: function dump(maxDepth) {
if (maxDepth === undefined) maxDepth = Infinity;
var out = "";
this.walk(function (node, depth /*, parent, when */) {
if (depth > maxDepth) return;
for (var i = 0; i < depth; i++) out += " ";
out += node.T + " ";
var keys = Object.keys(node.A);
if (keys.length > 0) {
out += "(";
var first = true;
keys.forEach(function (key) {
if (!first) out += ", ";else first = false;
out += key + ": ";
var value = node.A[key];
switch (typeof value) {
case "string":
out += "\"" + value.replace(/\n/, "\\n").replace(/"/, "\\\"") + "\"";
break;
case "object":
if (value instanceof RegExp) out += "/" + value.toString().replace(/^\//, "").replace(/\/$/, "").replace(/\//g, "\\/") + "/";else out += JSON.stringify(value);
break;
default:
out += JSON.stringify(value);
break;
}
});
out += ") ";
}
out += "[" + node.L.L + "/" + node.L.C + "]\n";
}, "downward");
return out;
},
writable: true,
enumerable: true,
configurable: true
}
});
_prototypeProperties(ASTYDump, null, {
dump: {
/* dump the AST recursively */
value: function dump(maxDepth) {
if (maxDepth === undefined) maxDepth = Infinity;
var out = "";
this.walk(function (node, depth /*, parent, when */) {
if (depth > maxDepth) return;
for (var i = 0; i < depth; i++) {
out += " ";
}out += node.T + " ";
var keys = Object.keys(node.A);
if (keys.length > 0) {
(function () {
out += "(";
var first = true;
keys.forEach(function (key) {
if (!first) out += ", ";else first = false;
out += key + ": ";
var value = node.A[key];
switch (typeof value) {
case "string":
out += "\"" + value.replace(/\n/, "\\n").replace(/"/, "\\\"") + "\"";
break;
case "object":
if (value instanceof RegExp) out += "/" + value.toString().replace(/^\//, "").replace(/\/$/, "").replace(/\//g, "\\/") + "/";else out += JSON.stringify(value);
break;
default:
out += JSON.stringify(value);
break;
}
});
out += ") ";
})();
}
out += "[" + node.L.L + "/" + node.L.C + "]\n";
}, "downward");
return out;
},
writable: true,
configurable: true
}
});
return ASTYDump;
return ASTYDump;
})();

@@ -314,6 +303,3 @@

var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); };

@@ -345,32 +331,31 @@ /*

var ASTYMerge = (function () {
function ASTYMerge() {}
function ASTYMerge() {}
_prototypeProperties(ASTYMerge, null, {
merge: {
/* merge attributes and childs of an AST node */
value: function merge(node, takePos, attrMap) {
if (typeof node !== "object") throw new Error("merge: invalid AST node argument");
if (typeof takePos === "undefined") takePos = false;
if (typeof attrMap === "undefined") attrMap = {};
var self = this;
if (takePos) {
var pos = node.pos();
self.pos(pos.L, pos.C, pos.O);
_prototypeProperties(ASTYMerge, null, {
merge: {
/* merge attributes and childs of an AST node */
value: function merge(node, takePos, attrMap) {
var _this = this;
if (typeof node !== "object") throw new Error("merge: invalid AST node argument");
if (typeof takePos === "undefined") takePos = false;
if (typeof attrMap === "undefined") attrMap = {};
if (takePos) {
var pos = node.pos();
this.pos(pos.L, pos.C, pos.O);
}
node.attrs().forEach(function (attrSource) {
var attrTarget = typeof attrMap[attrSource] !== "undefined" ? attrMap[attrSource] : attrSource;
if (attrTarget !== null) _this.set(attrTarget, node.get(attrSource));
});
node.childs().forEach(function (child) {
_this.add(child);
});
return this;
},
writable: true,
configurable: true
}
node.attrs().forEach(function (attrSource) {
var attrTarget = typeof attrMap[attrSource] !== "undefined" ? attrMap[attrSource] : attrSource;
if (attrTarget !== null) self.set(attrTarget, node.get(attrSource));
});
node.childs().forEach(function (child) {
self.add(child);
});
return this;
},
writable: true,
enumerable: true,
configurable: true
}
});
});
return ASTYMerge;
return ASTYMerge;
})();

@@ -383,6 +368,3 @@

var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); };

@@ -414,26 +396,25 @@ /*

var ASTYWalk = (function () {
function ASTYWalk() {}
function ASTYWalk() {}
_prototypeProperties(ASTYWalk, null, {
walk: {
/* walk the AST recursively */
value: function walk(cb, when) {
if (typeof when === "undefined") when = "downward";
var _walk = function (node, depth, parent) {
if (when === "downward" || when === "both") cb.call(null, node, depth, parent, "downward");
node.C.forEach(function (child) {
_walk(child, depth + 1, node);
});
if (when === "upward" || when === "both") cb.call(null, node, depth, parent, "upward");
};
_walk(this, 0, null);
return this;
},
writable: true,
enumerable: true,
configurable: true
}
});
_prototypeProperties(ASTYWalk, null, {
walk: {
/* walk the AST recursively */
value: function walk(cb, when) {
if (typeof when === "undefined") when = "downward";
var _walk = function (node, depth, parent) {
if (when === "downward" || when === "both") cb.call(null, node, depth, parent, "downward");
node.C.forEach(function (child) {
_walk(child, depth + 1, node);
});
if (when === "upward" || when === "both") cb.call(null, node, depth, parent, "upward");
};
_walk(this, 0, null);
return this;
},
writable: true,
configurable: true
}
});
return ASTYWalk;
return ASTYWalk;
})();

@@ -446,6 +427,3 @@

var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); };

@@ -482,45 +460,42 @@ /*

var ASTYCtx = (function () {
function ASTYCtx() {
var _this = this;
if (!(this instanceof ASTYCtx)) return new ASTYCtx();
this.ASTYNode = function () {};
var mixins = [ASTYBase, ASTYMerge, ASTYWalk, ASTYDump];
mixins.forEach(function (mixin) {
for (var method in mixin.prototype) {
if (mixin.prototype.hasOwnProperty(method)) _this.ASTYNode.prototype[method] = mixin.prototype[method];
}
function ASTYCtx() {
var _this = this;
if (!(this instanceof ASTYCtx)) return new ASTYCtx();
this.ASTYNode = function () {};
var mixins = [ASTYBase, ASTYMerge, ASTYWalk, ASTYDump];
mixins.forEach(function (mixin) {
for (var method in mixin.prototype) {
if (mixin.prototype.hasOwnProperty(method)) _this.ASTYNode.prototype[method] = mixin.prototype[method];
}
});
return this;
}
_prototypeProperties(ASTYCtx, null, {
extend: {
value: function extend(mixin) {
for (var method in mixin) {
if (mixin.hasOwnProperty(method)) this.ASTYNode.prototype[method] = mixin[method];
}return this;
},
writable: true,
configurable: true
},
create: {
value: function create(type) {
return new this.ASTYNode().init(type);
},
writable: true,
configurable: true
},
isA: {
value: function isA(node) {
return typeof node === "object" && node instanceof this.ASTYNode && typeof node.ASTy === "boolean" && node.ASTy === true;
},
writable: true,
configurable: true
}
});
return this;
}
_prototypeProperties(ASTYCtx, null, {
extend: {
value: function extend(mixin) {
for (var method in mixin) {
if (mixin.hasOwnProperty(method)) this.ASTYNode.prototype[method] = mixin[method];
}return this;
},
writable: true,
enumerable: true,
configurable: true
},
create: {
value: function create(type) {
return new this.ASTYNode().init(type);
},
writable: true,
enumerable: true,
configurable: true
},
isA: {
value: function isA(node) {
return typeof node === "object" && node instanceof this.ASTYNode && typeof node.ASTy === "boolean" && node.ASTy === true;
},
writable: true,
enumerable: true,
configurable: true
}
});
return ASTYCtx;
return ASTYCtx;
})();

@@ -527,0 +502,0 @@

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

@@ -30,3 +30,3 @@ "keywords": [ "ast", "abstract", "syntax", "tree", "data", "structure" ],

"chai": "~1.10.0",
"6to5ify": "~3.1.2",
"6to5ify": "~4.0.0",
"minifyify": "~6.1.0",

@@ -33,0 +33,0 @@ "browserify-header": "~0.9.1",

@@ -123,2 +123,15 @@

Implementation Notice
---------------------
Although ASTy is written in ECMAScript 6, it is transpiled to ECMAScript
5 and this way runs in really all(!) current (as of 2015) JavaScript
environments, of course.
Additionally, there are two transpilation results: first, there is
`asty.browser.js` (plus `asty.browser.map`) for Browser environments.
This is a size-compressed variant but still with source-map for
debugging. Second, there is `asty.node.js` for Node.js/IO.js
environments. This is a variant without compression and no source-maps.
License

@@ -125,0 +138,0 @@ -------

@@ -75,5 +75,6 @@ /*

if (arguments.length === 1 && typeof arguments[0] === "object") {
var self = this
var args = arguments
Object.keys(args[0]).forEach(function (key) { self.A[key] = args[0][key]; })
let args = arguments
Object.keys(args[0]).forEach((key) => {
this.A[key] = args[0][key]
})
}

@@ -105,3 +106,3 @@ else if (arguments.length === 2)

throw new Error("add: missing argument(s)")
var _add = function (node, child) {
let _add = (node, child) => {
if (!((typeof child === "object") &&

@@ -118,8 +119,7 @@ (typeof child.T === "string") &&

if (arguments !== null) {
var self = this
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
Array.prototype.slice.call(arguments, 0).forEach((arg) => {
if (typeof arg === "object" && arg instanceof Array)
arg.forEach(function (child) { _add(self, child) })
arg.forEach((child) => { _add(this, child) })
else if (arg !== null)
_add(self, arg)
_add(this, arg)
})

@@ -134,8 +134,7 @@ }

throw new Error("del: invalid argument")
var self = this
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
var found = false
for (var j = 0; j < self.C.length; j++) {
if (self.C[j] === arg) {
self.C.splice(j, 1)
Array.prototype.slice.call(arguments, 0).forEach((arg) => {
let found = false
for (let j = 0; j < this.C.length; j++) {
if (this.C[j] === arg) {
this.C.splice(j, 1)
arg.P = null

@@ -142,0 +141,0 @@ found = true

@@ -30,14 +30,14 @@ /*

maxDepth = Infinity
var out = ""
this.walk(function (node, depth /*, parent, when */) {
let out = ""
this.walk((node, depth /*, parent, when */) => {
if (depth > maxDepth)
return
for (var i = 0; i < depth; i++)
for (let i = 0; i < depth; i++)
out += " "
out += node.T + " "
var keys = Object.keys(node.A)
let keys = Object.keys(node.A)
if (keys.length > 0) {
out += "("
var first = true
keys.forEach(function (key) {
let first = true
keys.forEach((key) => {
if (!first)

@@ -48,3 +48,3 @@ out += ", "

out += key + ": "
var value = node.A[key]
let value = node.A[key]
switch (typeof value) {

@@ -51,0 +51,0 @@ case "string":

@@ -34,15 +34,17 @@ /*

attrMap = {}
var self = this
if (takePos) {
var pos = node.pos()
self.pos(pos.L, pos.C, pos.O)
let pos = node.pos()
this.pos(pos.L, pos.C, pos.O)
}
node.attrs().forEach(function (attrSource) {
var attrTarget = (typeof attrMap[attrSource] !== "undefined" ?
attrMap[attrSource] : attrSource)
node.attrs().forEach((attrSource) => {
let attrTarget = (
typeof attrMap[attrSource] !== "undefined"
? attrMap[attrSource]
: attrSource
)
if (attrTarget !== null)
self.set(attrTarget, node.get(attrSource))
this.set(attrTarget, node.get(attrSource))
})
node.childs().forEach(function (child) {
self.add(child)
node.childs().forEach((child) => {
this.add(child)
})

@@ -49,0 +51,0 @@ return this

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

when = "downward"
var _walk = function (node, depth, parent) {
let _walk = (node, depth, parent) => {
if (when === "downward" || when === "both")
cb.call(null, node, depth, parent, "downward")
node.C.forEach(function (child) { _walk(child, depth + 1, node) })
node.C.forEach((child) => {
_walk(child, depth + 1, node)
})
if (when === "upward" || when === "both")

@@ -36,0 +38,0 @@ cb.call(null, node, depth, parent, "upward")

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