Comparing version 1.2.2 to 1.2.3
{ | ||
"name": "asty", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "Abstract Syntax Tree (AST) Data Structure", | ||
@@ -5,0 +5,0 @@ "main": "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 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:"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,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"]; | ||
},{}],2:[function(_dereq_,module,exports){ | ||
@@ -35,7 +35,7 @@ "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"]; | ||
},{}],5:[function(_dereq_,module,exports){ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var version={major:1,minor:2,micro:2,date:20150818};exports["default"]=version,module.exports=exports["default"]; | ||
"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"]; | ||
},{}],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"]; | ||
},{}],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","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(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) | ||
@@ -42,0 +42,0 @@ }); |
@@ -130,2 +130,16 @@ /* | ||
/* unset AST node attributes */ | ||
}, { | ||
key: "unset", | ||
value: function unset() { | ||
var _this2 = this; | ||
if (arguments.length === 1 && typeof arguments[0] === "object" && arguments[0] instanceof Array) { | ||
arguments[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"); | ||
return this; | ||
} | ||
/* get AST node attributes */ | ||
@@ -151,3 +165,3 @@ }, { | ||
value: function add() { | ||
var _this2 = this; | ||
var _this3 = this; | ||
@@ -163,4 +177,4 @@ if (arguments.length === 0) throw new Error("add: missing argument(s)"); | ||
if (typeof arg === "object" && arg instanceof Array) arg.forEach(function (child) { | ||
_add(_this2, child); | ||
});else if (arg !== null) _add(_this2, arg); | ||
_add(_this3, child); | ||
});else if (arg !== null) _add(_this3, arg); | ||
}); | ||
@@ -175,3 +189,3 @@ } | ||
value: function del() { | ||
var _this3 = this; | ||
var _this4 = this; | ||
@@ -181,5 +195,5 @@ if (arguments.length === 0) throw new Error("del: invalid argument"); | ||
var found = false; | ||
for (var j = 0; j < _this3.C.length; j++) { | ||
if (_this3.C[j] === arg) { | ||
_this3.C.splice(j, 1); | ||
for (var j = 0; j < _this4.C.length; j++) { | ||
if (_this4.C[j] === arg) { | ||
_this4.C.splice(j, 1); | ||
arg.P = null; | ||
@@ -530,4 +544,4 @@ found = true; | ||
/* global 2: false */ | ||
/* global 2: false */ | ||
/* global 20150818: false */ | ||
/* global 3: false */ | ||
/* global 20150819: false */ | ||
@@ -542,4 +556,4 @@ "use strict"; | ||
minor: 2, | ||
micro: 2, | ||
date: 20150818 | ||
micro: 3, | ||
date: 20150819 | ||
}; | ||
@@ -682,3 +696,3 @@ | ||
this.ASTYNode = function () {}; | ||
var mixins = [[_astyBaseJs2["default"], "init", "type", "pos", "set", "get", "attrs", "add", "del", "childs", "parent"], [_astyMergeJs2["default"], "merge"], [_astyWalkJs2["default"], "walk"], [_astyDumpJs2["default"], "dump"]]; | ||
var mixins = [[_astyBaseJs2["default"], "init", "type", "pos", "set", "unset", "get", "attrs", "add", "del", "childs", "parent"], [_astyMergeJs2["default"], "merge"], [_astyWalkJs2["default"], "walk"], [_astyDumpJs2["default"], "dump"]]; | ||
mixins.forEach(function (mixin) { | ||
@@ -685,0 +699,0 @@ var proto = mixin[0].prototype; |
{ | ||
"name": "asty", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "Abstract Syntax Tree (AST) Data Structure", | ||
@@ -5,0 +5,0 @@ "keywords": [ "ast", "abstract", "syntax", "tree", "data", "structure" ], |
@@ -88,4 +88,10 @@ | ||
- `ASTYNode#set(name: String, value: Object): ASTYNode`:<br/> | ||
Set a single attribute `name` to `value`. | ||
`ASTYNode#set({ [String]: Object }): ASTYNode`:<br/> | ||
Set a single attribute `name` to `value` or set multiple | ||
attributes to their corresponding value. | ||
- `ASTYNode#unset(name: String): ASTYNode`:<br/> | ||
`ASTYNode#unset(names: String[]): ASTYNode`:<br/> | ||
Unset a single attribute `name` or unset multiple attributes. | ||
- `ASTYNode#set({ [name: String]: [value: Object] }): ASTYNode`:<br/> | ||
@@ -92,0 +98,0 @@ Set multiple attributes, each consisting of name and value pairs. |
@@ -91,2 +91,16 @@ /* | ||
/* unset AST node attributes */ | ||
unset () { | ||
if (arguments.length === 1 && typeof arguments[0] === "object" && arguments[0] instanceof Array) { | ||
arguments[0].forEach((key) => { | ||
delete this.A[key] | ||
}) | ||
} | ||
else if (arguments.length === 1) | ||
delete this.A[arguments[0]] | ||
else | ||
throw new Error("unset: invalid arguments") | ||
return this | ||
} | ||
/* get AST node attributes */ | ||
@@ -93,0 +107,0 @@ get (key) { |
@@ -36,3 +36,3 @@ /* | ||
let mixins = [ | ||
[ ASTYBase, "init", "type", "pos", "set", "get", "attrs", "add", "del", "childs", "parent" ], | ||
[ ASTYBase, "init", "type", "pos", "set", "unset", "get", "attrs", "add", "del", "childs", "parent" ], | ||
[ ASTYMerge, "merge" ], | ||
@@ -39,0 +39,0 @@ [ ASTYWalk, "walk" ], |
@@ -78,2 +78,9 @@ /* | ||
var node1 = asty.create("1") | ||
node1.set("foo", "bar") | ||
expect(node1.get("foo")).to.be.equal("bar") | ||
node1.unset("foo") | ||
expect(node1.get("foo")).to.be.equal(undefined) | ||
node1.set("foo", "bar") | ||
node1.unset([ "foo" ]) | ||
expect(node1.get("foo")).to.be.equal(undefined) | ||
node1.set("foo", { bar: 42, quux: "7" }) | ||
@@ -80,0 +87,0 @@ var node11 = asty.create("1.1") |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
138750
1782
175