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.2.3 to 1.3.0

2

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

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

@@ -26,15 +26,15 @@ /*

(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 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";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),ASTYBase=function(){function t(){_classCallCheck(this,t)}return _createClass(t,[{key:"init",value:function(t,e,n){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 r in e)e.hasOwnProperty(r)&&this.set(r,e[r]);return"object"==typeof n&&n instanceof Array&&this.add(n),this}},{key:"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")}},{key:"pos",value:function(t,e,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=t||0,this.L.C=e||0,this.L.O=n||0,this;throw new Error("pos: invalid number of arguments")}},{key:"set",value:function(){var t=arguments,e=this;if(1===arguments.length&&"object"==typeof arguments[0])!function(){var n=t;Object.keys(n[0]).forEach(function(t){e.A[t]=n[0][t]})}();else{if(2!==arguments.length)throw new Error("set: invalid arguments");this.A[arguments[0]]=arguments[1]}return this}},{key:"unset",value:function(){var t=this;if(1===arguments.length&&"object"==typeof arguments[0]&&arguments[0]instanceof Array)arguments[0].forEach(function(e){delete t.A[e]});else{if(1!==arguments.length)throw new Error("unset: invalid arguments");delete this.A[arguments[0]]}return this}},{key:"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]}},{key:"attrs",value:function(){return Object.keys(this.A)}},{key:"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(n){"object"==typeof n&&n instanceof Array?n.forEach(function(n){e(t,n)}):null!==n&&e(t,n)}),this}},{key:"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 n=!1,r=0;r<t.C.length;r++)if(t.C[r]===e){t.C.splice(r,1),e.P=null,n=!0;break}if(!n)throw new Error("del: child not found")}),this}},{key:"childs",value:function(){return this.C}},{key:"parent",value:function(){return this.P}}]),t}();exports["default"]=ASTYBase,module.exports=exports["default"];
"use strict";function _classCallCheck(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function t(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}(),ASTYBase=function(){function t(){_classCallCheck(this,t)}return _createClass(t,[{key:"init",value:function(t,n,e,r){if(arguments.length<2)throw new Error("init: invalid number of arguments");if(this.ctx=t,this.ASTy=!0,this.T=n,this.L={L:0,C:0,O:0},this.A={},this.C=[],this.P=null,"object"==typeof e)for(var i in e)e.hasOwnProperty(i)&&this.set(i,e[i]);return"object"==typeof r&&r instanceof Array&&this.add(r),this}},{key:"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")}},{key:"pos",value:function(t,n,e){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=t||0,this.L.C=n||0,this.L.O=e||0,this;throw new Error("pos: invalid number of arguments")}},{key:"set",value:function(){for(var t=this,n=arguments.length,e=Array(n),r=0;n>r;r++)e[r]=arguments[r];if(1===e.length&&"object"==typeof e[0])Object.keys(e[0]).forEach(function(n){t.A[n]=e[0][n]});else{if(2!==e.length)throw new Error("set: invalid number of arguments");this.A[e[0]]=e[1]}return this}},{key:"unset",value:function(){for(var t=this,n=arguments.length,e=Array(n),r=0;n>r;r++)e[r]=arguments[r];if(1===e.length&&"object"==typeof e[0]&&e[0]instanceof Array)e[0].forEach(function(n){delete t.A[n]});else{if(1!==e.length)throw new Error("unset: invalid number of arguments");delete this.A[e[0]]}return this}},{key:"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 key argument");return this.A[t]}},{key:"attrs",value:function(){return Object.keys(this.A)}},{key:"nth",value:function n(){if(null===this.P)return 1;var n=this.P.C.indexOf(this);if(0>n)throw new Error("nth: internal error -- node not in childs of its parent");return n}},{key:"ins",value:function(t){for(var n=this,e=arguments.length,r=Array(e>1?e-1:0),i=1;e>i;i++)r[i-1]=arguments[i];if(0===r.length)throw new Error("ins: invalid number of arguments");if(0>t&&(t=this.C.length+1-t),!(t>0&&t<this.C.length))throw new Error("ins: invalid position");var o=function(e){if(!n.ctx.isA(e))throw new Error("ins: invalid AST node argument: "+JSON.stringify(e));n.C.splice(t++,0,e),e.P=n};r.forEach(function(t){"object"==typeof t&&t instanceof Array?t.forEach(function(t){o(t)}):null!==t&&o(t)})}},{key:"add",value:function(){for(var t=this,n=arguments.length,e=Array(n),r=0;n>r;r++)e[r]=arguments[r];if(0===e.length)throw new Error("add: invalid number of arguments");var i=function(n){if(!t.ctx.isA(n))throw new Error("add: invalid AST node argument: "+JSON.stringify(n));t.C.push(n),n.P=t};e.forEach(function(t){"object"==typeof t&&t instanceof Array?t.forEach(function(t){i(t)}):null!==t&&i(t)})}},{key:"del",value:function(){for(var t=this,n=arguments.length,e=Array(n),r=0;n>r;r++)e[r]=arguments[r];if(0===e.length)throw new Error("del: invalid number of argument");return e.forEach(function(n){if(!t.ctx.isA(n))throw new Error("del: invalid AST node argument: "+JSON.stringify(n));for(var e=!1,r=0;r<t.C.length;r++)if(t.C[r]===n){t.C.splice(r,1),n.P=null,e=!0;break}if(!e)throw new Error("del: AST node not found in childs")}),this}},{key:"childs",value:function(){return this.C}},{key:"parent",value:function(){return this.P}}]),t}();exports["default"]=ASTYBase,module.exports=exports["default"];
},{}],2:[function(_dereq_,module,exports){
"use strict";function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,r){for(var n=0;n<r.length;n++){var t=r[n];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}return function(r,n,t){return n&&e(r.prototype,n),t&&e(r,t),r}}(),ASTYDump=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"dump",value:function(e){void 0===e&&(e=1/0);var r="";return this.walk(function(n,t){if(!(t>e)){for(var a=0;t>a;a++)r+=" ";r+=n.T+" ";var c=Object.keys(n.A);c.length>0&&!function(){r+="(";var e=!0;c.forEach(function(t){e?e=!1:r+=", ",r+=t+": ";var a=n.A[t];switch(typeof a){case"string":var c=function(e){return e.charCodeAt(0).toString(16).toUpperCase()};r+='"'+a.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"+c(e)}).replace(/[\x10-\x1F\x80-\xFF]/g,function(e){return"\\x"+c(e)}).replace(/[\u0100-\u0FFF]/g,function(e){return"\\u0"+c(e)}).replace(/[\u1000-\uFFFF]/g,function(e){return"\\u"+c(e)})+'"';break;case"object":r+=a instanceof RegExp?a.source:JSON.stringify(a);break;default:r+=JSON.stringify(a)}}),r+=") "}(),r+="["+n.L.L+"/"+n.L.C+"]\n"}},"downward"),r}}]),e}();exports["default"]=ASTYDump,module.exports=exports["default"];
},{}],3:[function(_dereq_,module,exports){
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _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}}(),ASTYMerge=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"merge",value:function(e,t,n){var r=this;if("object"!=typeof e)throw new Error("merge: invalid AST node argument");if("undefined"==typeof t&&(t=!1),"undefined"==typeof n&&(n={}),t){var o=e.pos();this.pos(o.L,o.C,o.O)}return e.attrs().forEach(function(t){var o="undefined"!=typeof n[t]?n[t]:t;null!==o&&r.set(o,e.get(t))}),e.childs().forEach(function(e){r.add(e)}),this}}]),e}();exports["default"]=ASTYMerge,module.exports=exports["default"];
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _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}}(),ASTYMerge=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"merge",value:function(e){var t=this,r=arguments.length<=1||void 0===arguments[1]?!1:arguments[1],n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];if(!this.ctx.isA(e))throw new Error("merge: invalid AST node argument");if(r){var a=e.pos();this.pos(a.L,a.C,a.O)}return e.attrs().forEach(function(r){var a="undefined"!=typeof n[r]?n[r]:r;null!==a&&t.set(a,e.get(r))}),e.childs().forEach(function(e){t.add(e)}),this}}]),e}();exports["default"]=ASTYMerge,module.exports=exports["default"];
},{}],4:[function(_dereq_,module,exports){
"use strict";function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}(),ASTYSerialize=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"serialize",value:function(e,r){var t=function n(e){var r={T:e.T,L:{L:e.L.L,C:e.L.C,O:e.L.O}},t=Object.keys(e.A);return t.length>0&&(r.A={},t.forEach(function(t){var n=e.A[t];switch(typeof n){case"boolean":case"number":case"string":r.A[t]=n;break;default:r.A[t]=JSON.parse(JSON.stringify(n))}})),e.C.length>0&&(r.C=e.C.map(function(e){return n(e)})),r};if(!e.isA(r))throw new Error("failed to serialize: not an ASTy node");return JSON.stringify({ASTy:t(r)})}},{key:"unserialize",value:function(e,r){var t=function a(r){var t=e.create(r.T);return t.pos(r.L.L,r.L.C,r.L.O),"object"==typeof r.A&&Object.keys(r.A).forEach(function(e){var n=r.A[e];switch(typeof n){case"boolean":case"number":case"string":t.set(e,n);break;default:t.set(e,JSON.parse(JSON.stringify(n)))}}),"object"==typeof r.C&&r.C instanceof Array&&t.add(r.C.map(function(e){return a(e)})),t},n=JSON.parse(r);if("object"!=typeof n||"object"!=typeof n.ASTy)throw new Error("failed to unserialize: not an ASTy JSON export");return t(n.ASTy)}}]),e}();exports["default"]=ASTYSerialize,module.exports=exports["default"];
"use strict";function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}(),ASTYSerialize=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"serialize",value:function(e,r){var t=function n(e){var r={T:e.T,L:{L:e.L.L,C:e.L.C,O:e.L.O}},t=Object.keys(e.A);return t.length>0&&(r.A={},t.forEach(function(t){var n=e.A[t];switch(typeof n){case"boolean":case"number":case"string":r.A[t]=n;break;default:r.A[t]=JSON.parse(JSON.stringify(n))}})),e.C.length>0&&(r.C=e.C.map(function(e){return n(e)})),r};if(!e.isA(r))throw new Error("serialize: not an ASTy node");return JSON.stringify({ASTy:t(r)})}},{key:"unserialize",value:function(e,r){var t=function a(r){var t=e.create(r.T);return t.pos(r.L.L,r.L.C,r.L.O),"object"==typeof r.A&&Object.keys(r.A).forEach(function(e){var n=r.A[e];switch(typeof n){case"boolean":case"number":case"string":t.set(e,n);break;default:t.set(e,JSON.parse(JSON.stringify(n)))}}),"object"==typeof r.C&&r.C instanceof Array&&t.add(r.C.map(function(e){return a(e)})),t},n=JSON.parse(r);if("object"!=typeof n||"object"!=typeof n.ASTy)throw new Error("unserialize: not an ASTy JSON export");return t(n.ASTy)}}]),e}();exports["default"]=ASTYSerialize,module.exports=exports["default"];
},{}],5:[function(_dereq_,module,exports){
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var version={major:1,minor:2,micro:3,date:20150819};exports["default"]=version,module.exports=exports["default"];
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var version={major:1,minor:3,micro:0,date:20150819};exports["default"]=version,module.exports=exports["default"];
},{}],6:[function(_dereq_,module,exports){
"use strict";function _classCallCheck(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,n){for(var t=0;t<n.length;t++){var a=n[t];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(n,t,a){return t&&e(n.prototype,t),a&&e(n,a),n}}(),ASTYWalk=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"walk",value:function(e,n){"undefined"==typeof n&&(n="downward");var t=function a(t,r,l){("downward"===n||"both"===n)&&e.call(null,t,r,l,"downward"),t.C.forEach(function(e){a(e,r+1,t)}),("upward"===n||"both"===n)&&e.call(null,t,r,l,"upward")};return t(this,0,null),this}}]),e}();exports["default"]=ASTYWalk,module.exports=exports["default"];
"use strict";function _classCallCheck(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,n){for(var t=0;t<n.length;t++){var a=n[t];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(n,t,a){return t&&e(n.prototype,t),a&&e(n,a),n}}(),ASTYWalk=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"walk",value:function(e){var n=arguments.length<=1||void 0===arguments[1]?"downward":arguments[1],t=function a(t,r,l){("downward"===n||"both"===n)&&e.call(null,t,r,l,"downward"),t.C.forEach(function(e){a(e,r+1,t)}),("upward"===n||"both"===n)&&e.call(null,t,r,l,"upward")};return t(this,0,null),this}}]),e}();exports["default"]=ASTYWalk,module.exports=exports["default"];
},{}],7:[function(_dereq_,module,exports){
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,t){for(var s=0;s<t.length;s++){var a=t[s];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,s,a){return s&&e(t.prototype,s),a&&e(t,a),t}}(),_astyBaseJs=_dereq_("./asty-base.js"),_astyBaseJs2=_interopRequireDefault(_astyBaseJs),_astyMergeJs=_dereq_("./asty-merge.js"),_astyMergeJs2=_interopRequireDefault(_astyMergeJs),_astyWalkJs=_dereq_("./asty-walk.js"),_astyWalkJs2=_interopRequireDefault(_astyWalkJs),_astyDumpJs=_dereq_("./asty-dump.js"),_astyDumpJs2=_interopRequireDefault(_astyDumpJs),_astySerializeJs=_dereq_("./asty-serialize.js"),_astySerializeJs2=_interopRequireDefault(_astySerializeJs),_astyVersionJs=_dereq_("./asty-version.js"),_astyVersionJs2=_interopRequireDefault(_astyVersionJs),ASTYCtx=function(){function e(){var t=this;_classCallCheck(this,e),this.ASTYNode=function(){};var s=[[_astyBaseJs2["default"],"init","type","pos","set","unset","get","attrs","add","del","childs","parent"],[_astyMergeJs2["default"],"merge"],[_astyWalkJs2["default"],"walk"],[_astyDumpJs2["default"],"dump"]];return s.forEach(function(e){var s=e[0].prototype;e.slice(1).forEach(function(e){t.ASTYNode.prototype[e]=s[e]})}),this}return _createClass(e,[{key:"version",value:function(){return _astyVersionJs2["default"]}},{key:"extend",value:function(e){for(var t in e)e.hasOwnProperty(t)&&(this.ASTYNode.prototype[t]=e[t]);return this}},{key:"create",value:function(e){return(new this.ASTYNode).init(e)}},{key:"isA",value:function(e){return"object"==typeof e&&e instanceof this.ASTYNode&&"boolean"==typeof e.ASTy&&e.ASTy===!0}},{key:"serialize",value:function(e){return _astySerializeJs2["default"].serialize(this,e)}},{key:"unserialize",value:function(e){return _astySerializeJs2["default"].unserialize(this,e)}}]),e}();exports["default"]=ASTYCtx,module.exports=exports["default"];
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,t){for(var s=0;s<t.length;s++){var a=t[s];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,s,a){return s&&e(t.prototype,s),a&&e(t,a),t}}(),_astyBaseJs=_dereq_("./asty-base.js"),_astyBaseJs2=_interopRequireDefault(_astyBaseJs),_astyMergeJs=_dereq_("./asty-merge.js"),_astyMergeJs2=_interopRequireDefault(_astyMergeJs),_astyWalkJs=_dereq_("./asty-walk.js"),_astyWalkJs2=_interopRequireDefault(_astyWalkJs),_astyDumpJs=_dereq_("./asty-dump.js"),_astyDumpJs2=_interopRequireDefault(_astyDumpJs),_astySerializeJs=_dereq_("./asty-serialize.js"),_astySerializeJs2=_interopRequireDefault(_astySerializeJs),_astyVersionJs=_dereq_("./asty-version.js"),_astyVersionJs2=_interopRequireDefault(_astyVersionJs),ASTYCtx=function(){function e(){var t=this;_classCallCheck(this,e),this.ASTYNode=function(){};var s=[[_astyBaseJs2["default"],"init","type","pos","set","unset","get","attrs","add","del","childs","parent"],[_astyMergeJs2["default"],"merge"],[_astyWalkJs2["default"],"walk"],[_astyDumpJs2["default"],"dump"]];return s.forEach(function(e){var s=e[0].prototype;e.slice(1).forEach(function(e){t.ASTYNode.prototype[e]=s[e]})}),this}return _createClass(e,[{key:"version",value:function(){return _astyVersionJs2["default"]}},{key:"extend",value:function(e){for(var t in e)e.hasOwnProperty(t)&&(this.ASTYNode.prototype[t]=e[t]);return this}},{key:"create",value:function(e){return(new this.ASTYNode).init(this,e)}},{key:"isA",value:function(e){return"object"==typeof e&&e instanceof this.ASTYNode&&"boolean"==typeof e.ASTy&&e.ASTy===!0}},{key:"serialize",value:function(e){return _astySerializeJs2["default"].serialize(this,e)}},{key:"unserialize",value:function(e){return _astySerializeJs2["default"].unserialize(this,e)}}]),e}();exports["default"]=ASTYCtx,module.exports=exports["default"];
},{"./asty-base.js":1,"./asty-dump.js":2,"./asty-merge.js":3,"./asty-serialize.js":4,"./asty-version.js":5,"./asty-walk.js":6}]},{},[1,2,3,4,5,6,7])(7)

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

@@ -69,4 +69,5 @@ /*

/* AST node initialization */
value: function init(T, A, C) {
if (typeof T === "undefined") throw new Error("init: invalid argument");
value: function init(ctx, T, A, C) {
if (arguments.length < 2) throw new Error("init: invalid number of arguments");
this.ctx = ctx;
this.ASTy = true;

@@ -117,13 +118,13 @@ this.T = T;

value: function set() {
var _arguments = arguments,
_this = this;
var _this = this;
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");
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
if (args.length === 1 && typeof args[0] === "object") {
Object.keys(args[0]).forEach(function (key) {
_this.A[key] = args[0][key];
});
} else if (args.length === 2) this.A[args[0]] = args[1];else throw new Error("set: invalid number of arguments");
return this;

@@ -138,7 +139,11 @@ }

if (arguments.length === 1 && typeof arguments[0] === "object" && arguments[0] instanceof Array) {
arguments[0].forEach(function (key) {
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
if (args.length === 1 && typeof args[0] === "object" && args[0] instanceof Array) {
args[0].forEach(function (key) {
delete _this2.A[key];
});
} else if (arguments.length === 1) delete this.A[arguments[0]];else throw new Error("unset: invalid arguments");
} else if (args.length === 1) delete this.A[args[0]];else throw new Error("unset: invalid number of arguments");
return this;

@@ -152,3 +157,3 @@ }

if (arguments.length !== 1) throw new Error("get: invalid number of arguments");
if (typeof key !== "string") throw new Error("get: invalid argument");
if (typeof key !== "string") throw new Error("get: invalid key argument");
return this.A[key];

@@ -164,2 +169,37 @@ }

/* return current sibling position */
}, {
key: "nth",
value: function nth() {
if (this.P === null) return 1;
var nth = this.P.C.indexOf(this);
if (nth < 0) throw new Error("nth: internal error -- node not in childs of its parent");
return nth;
}
/* insert child AST node(s) */
}, {
key: "ins",
value: function ins(pos) {
var _this3 = this;
for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
args[_key3 - 1] = arguments[_key3];
}
if (args.length === 0) throw new Error("ins: invalid number of arguments");
if (pos < 0) pos = this.C.length + 1 - pos;
if (!(0 < pos && pos < this.C.length)) throw new Error("ins: invalid position");
var _ins = function _ins(node) {
if (!_this3.ctx.isA(node)) throw new Error("ins: invalid AST node argument: " + JSON.stringify(node));
_this3.C.splice(pos++, 0, node);
node.P = _this3;
};
args.forEach(function (arg) {
if (typeof arg === "object" && arg instanceof Array) arg.forEach(function (arg) {
_ins(arg);
});else if (arg !== null) _ins(arg);
});
}
/* add child AST node(s) */

@@ -169,18 +209,19 @@ }, {

value: function add() {
var _this3 = this;
var _this4 = this;
if (arguments.length === 0) throw new Error("add: missing argument(s)");
var _add = function _add(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;
for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
args[_key4] = arguments[_key4];
}
if (args.length === 0) throw new Error("add: invalid number of arguments");
var _add = function _add(node) {
if (!_this4.ctx.isA(node)) throw new Error("add: invalid AST node argument: " + JSON.stringify(node));
_this4.C.push(node);
node.P = _this4;
};
if (arguments !== null) {
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
if (typeof arg === "object" && arg instanceof Array) arg.forEach(function (child) {
_add(_this3, child);
});else if (arg !== null) _add(_this3, arg);
});
}
return this;
args.forEach(function (arg) {
if (typeof arg === "object" && arg instanceof Array) arg.forEach(function (arg) {
_add(arg);
});else if (arg !== null) _add(arg);
});
}

@@ -192,11 +233,16 @@

value: function del() {
var _this4 = this;
var _this5 = this;
if (arguments.length === 0) throw new Error("del: invalid argument");
Array.prototype.slice.call(arguments, 0).forEach(function (arg) {
for (var _len5 = arguments.length, args = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
args[_key5] = arguments[_key5];
}
if (args.length === 0) throw new Error("del: invalid number of argument");
args.forEach(function (node) {
if (!_this5.ctx.isA(node)) throw new Error("del: invalid AST node argument: " + JSON.stringify(node));
var found = false;
for (var j = 0; j < _this4.C.length; j++) {
if (_this4.C[j] === arg) {
_this4.C.splice(j, 1);
arg.P = null;
for (var j = 0; j < _this5.C.length; j++) {
if (_this5.C[j] === node) {
_this5.C.splice(j, 1);
node.P = null;
found = true;

@@ -206,3 +252,3 @@ break;

}
if (!found) throw new Error("del: child not found");
if (!found) throw new Error("del: AST node not found in childs");
});

@@ -376,8 +422,9 @@ return this;

/* merge attributes and childs of an AST node */
value: function merge(node, takePos, attrMap) {
value: function merge(node) {
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 = {};
var takePos = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
var attrMap = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
if (!this.ctx.isA(node)) throw new Error("merge: invalid AST node argument");
if (takePos) {

@@ -477,3 +524,3 @@ var pos = node.pos();

};
if (!asty.isA(node)) throw new Error("failed to serialize: not an ASTy node");
if (!asty.isA(node)) throw new Error("serialize: not an ASTy node");
return JSON.stringify({ ASTy: serializeNode(node) });

@@ -511,3 +558,3 @@ }

var obj = JSON.parse(json);
if (typeof obj !== "object" || typeof obj.ASTy !== "object") throw new Error("failed to unserialize: not an ASTy JSON export");
if (typeof obj !== "object" || typeof obj.ASTy !== "object") throw new Error("unserialize: not an ASTy JSON export");
return unserializeNode(obj.ASTy);

@@ -549,4 +596,4 @@ }

/* global 1: false */
/* global 2: false */
/* global 3: false */
/* global 0: false */
/* global 20150819: false */

@@ -561,4 +608,4 @@

major: 1,
minor: 2,
micro: 3,
minor: 3,
micro: 0,
date: 20150819

@@ -614,4 +661,5 @@ };

/* walk the AST recursively */
value: function walk(cb, when) {
if (typeof when === "undefined") when = "downward";
value: function walk(cb) {
var when = arguments.length <= 1 || arguments[1] === undefined ? "downward" : arguments[1];
var _walk = function _walk(node, depth, parent) {

@@ -728,3 +776,3 @@ if (when === "downward" || when === "both") cb.call(null, node, depth, parent, "downward");

value: function create(type) {
return new this.ASTYNode().init(type);
return new this.ASTYNode().init(this, type);
}

@@ -731,0 +779,0 @@ }, {

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

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

@@ -105,6 +105,15 @@

- `ASTYNode#nth(): Number:<br/>
Get position among sibling nodes in parent's child node list.
The positions start at 0.
- `ASTYNode#ins(pos: Number, childs: ASTYNode[]): ASTYNode`:<br/>
Add one or more childs to a node, at a fixed position `pos`. The array `childs`
can either contain ASTYNode objects or even arrays of ASTYNode objects.
If `pos` is negative it counts from the end of child list,
with `-1` the position after the last existing child.
- `ASTYNode#add(childs: ASTYNode[]): ASTYNode`:<br/>
Add one or more childs to a node. The array `childs`
can either contain ASTYNode objects or even arrays
of ASTYNode objects.
Add one or more childs to a node, at the end of the child list. The array `childs`
can either contain ASTYNode objects or even arrays of ASTYNode objects.

@@ -111,0 +120,0 @@ - `ASTYNode#del(childs: ASTYNode[]): ASTYNode`:<br/>

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

/* AST node initialization */
init (T, A, C) {
if (typeof T === "undefined")
throw new Error("init: invalid argument")
init (ctx, T, A, C) {
if (arguments.length < 2)
throw new Error("init: invalid number of arguments")
this.ctx = ctx
this.ASTy = true

@@ -78,5 +79,5 @@ this.T = T

/* set AST node attributes */
set () {
if (arguments.length === 1 && typeof arguments[0] === "object") {
let args = arguments
set (...args) {
if ( args.length === 1
&& typeof args[0] === "object") {
Object.keys(args[0]).forEach((key) => {

@@ -86,6 +87,6 @@ this.A[key] = args[0][key]

}
else if (arguments.length === 2)
this.A[arguments[0]] = arguments[1]
else if (args.length === 2)
this.A[args[0]] = args[1]
else
throw new Error("set: invalid arguments")
throw new Error("set: invalid number of arguments")
return this

@@ -95,12 +96,14 @@ }

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

@@ -114,3 +117,3 @@ }

if (typeof key !== "string")
throw new Error("get: invalid argument")
throw new Error("get: invalid key argument")
return this.A[key]

@@ -124,38 +127,64 @@ }

/* return current sibling position */
nth () {
if (this.P === null)
return 1
let nth = this.P.C.indexOf(this)
if (nth < 0)
throw new Error("nth: internal error -- node not in childs of its parent")
return nth
}
/* insert child AST node(s) */
ins (pos, ...args) {
if (args.length === 0)
throw new Error("ins: invalid number of arguments")
if (pos < 0)
pos = (this.C.length + 1) - pos
if (!(0 < pos && pos < this.C.length))
throw new Error("ins: invalid position")
let _ins = (node) => {
if (!this.ctx.isA(node))
throw new Error(`ins: invalid AST node argument: ${ JSON.stringify(node) }`)
this.C.splice(pos++, 0, node)
node.P = this
}
args.forEach((arg) => {
if (typeof arg === "object" && arg instanceof Array)
arg.forEach((arg) => { _ins(arg) })
else if (arg !== null)
_ins(arg)
})
}
/* add child AST node(s) */
add () {
if (arguments.length === 0)
throw new Error("add: missing argument(s)")
let _add = (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
add (...args) {
if (args.length === 0)
throw new Error("add: invalid number of arguments")
let _add = (node) => {
if (!this.ctx.isA(node))
throw new Error(`add: invalid AST node argument: ${ JSON.stringify(node) }`)
this.C.push(node)
node.P = this
}
if (arguments !== null) {
Array.prototype.slice.call(arguments, 0).forEach((arg) => {
if (typeof arg === "object" && arg instanceof Array)
arg.forEach((child) => { _add(this, child) })
else if (arg !== null)
_add(this, arg)
})
}
return this
args.forEach((arg) => {
if (typeof arg === "object" && arg instanceof Array)
arg.forEach((arg) => { _add(arg) })
else if (arg !== null)
_add(arg)
})
}
/* delete child AST node(s) */
del () {
if (arguments.length === 0)
throw new Error("del: invalid argument")
Array.prototype.slice.call(arguments, 0).forEach((arg) => {
del (...args) {
if (args.length === 0)
throw new Error("del: invalid number of argument")
args.forEach((node) => {
if (!this.ctx.isA(node))
throw new Error(`del: invalid AST node argument: ${ JSON.stringify(node) }`)
let found = false
for (let j = 0; j < this.C.length; j++) {
if (this.C[j] === arg) {
if (this.C[j] === node) {
this.C.splice(j, 1)
arg.P = null
node.P = null
found = true

@@ -166,3 +195,3 @@ break

if (!found)
throw new Error("del: child not found")
throw new Error("del: AST node not found in childs")
})

@@ -169,0 +198,0 @@ return this

@@ -27,9 +27,5 @@ /*

/* merge attributes and childs of an AST node */
merge (node, takePos, attrMap) {
if (typeof node !== "object")
merge (node, takePos = false, attrMap = {}) {
if (!this.ctx.isA(node))
throw new Error("merge: invalid AST node argument")
if (typeof takePos === "undefined")
takePos = false
if (typeof attrMap === "undefined")
attrMap = {}
if (takePos) {

@@ -36,0 +32,0 @@ let pos = node.pos()

@@ -56,3 +56,3 @@ /*

if (!asty.isA(node))
throw new Error("failed to serialize: not an ASTy node")
throw new Error("serialize: not an ASTy node")
return JSON.stringify({ ASTy: serializeNode(node) })

@@ -88,3 +88,3 @@ }

if (typeof obj !== "object" || typeof obj.ASTy !== "object")
throw new Error("failed to unserialize: not an ASTy JSON export")
throw new Error("unserialize: not an ASTy JSON export")
return unserializeNode(obj.ASTy)

@@ -91,0 +91,0 @@ }

@@ -27,5 +27,3 @@ /*

/* walk the AST recursively */
walk (cb, when) {
if (typeof when === "undefined")
when = "downward"
walk (cb, when = "downward") {
let _walk = (node, depth, parent) => {

@@ -32,0 +30,0 @@ if (when === "downward" || when === "both")

@@ -59,3 +59,3 @@ /*

create (type) {
return (new this.ASTYNode()).init(type)
return (new this.ASTYNode()).init(this, type)
}

@@ -62,0 +62,0 @@ isA (node) {

Sorry, the diff of this file is not supported yet

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