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.1.5 to 1.2.0

src/asty-serialize.js

2

bower.json
{
"name": "asty",
"version": "1.1.5",
"version": "1.2.0",
"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 r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),ASTYBase=function(){function t(){_classCallCheck(this,t)}return _createClass(t,[{key:"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}},{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,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")}},{key:"set",value:function(){var t=arguments,e=this;if(1===arguments.length&&"object"==typeof arguments[0])!function(){var r=t;Object.keys(r[0]).forEach(function(t){e.A[t]=r[0][t]})}();else{if(2!==arguments.length)throw new Error("set: invalid arguments");this.A[arguments[0]]=arguments[1]}return this}},{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(r){"object"==typeof r&&r instanceof Array?r.forEach(function(r){e(t,r)}):null!==r&&e(t,r)}),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 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}},{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:"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){

@@ -33,8 +33,10 @@ "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"];

},{}],4:[function(_dereq_,module,exports){
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var version={major:1,minor:1,micro:5,date:20150530};exports["default"]=version,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("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"];
},{}],5:[function(_dereq_,module,exports){
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var version={major:1,minor:2,micro:0,date:20150531};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"];
},{}],6:[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),_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}}]),e}();exports["default"]=ASTYCtx,module.exports=exports["default"];
},{"./asty-base.js":1,"./asty-dump.js":2,"./asty-merge.js":3,"./asty-version.js":4,"./asty-walk.js":5}]},{},[1,2,3,4,5,6])(6)
},{}],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"];
},{"./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 +43,0 @@

@@ -99,7 +99,11 @@ /*

/* 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;
value: function pos(line, column, offset) {
if (arguments.length === 0) return {
line: this.L.L,
column: this.L.C,
offset: this.L.O
};else if (arguments.length <= 3) {
this.L.L = line || 0;
this.L.C = column || 0;
this.L.O = offset || 0;
return this;

@@ -403,6 +407,123 @@ } else throw new Error("pos: invalid number of arguments");

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var ASTYSerialize = (function () {
function ASTYSerialize() {
_classCallCheck(this, ASTYSerialize);
}
_createClass(ASTYSerialize, null, [{
key: "serialize",
/* recursively serialize AST nodes into JSON string */
value: function serialize(asty, node) {
var serializeNode = function serializeNode(node) {
var clone = {
T: node.T,
L: { L: node.L.L, C: node.L.C, O: node.L.O }
};
var keys = Object.keys(node.A);
if (keys.length > 0) {
clone.A = {};
keys.forEach(function (key) {
var value = node.A[key];
switch (typeof value) {
case "boolean":
case "number":
case "string":
clone.A[key] = value;
break;
default:
/* use the slow approach only for non-atomic attributes */
clone.A[key] = JSON.parse(JSON.stringify(value));
break;
}
});
}
if (node.C.length > 0) clone.C = node.C.map(function (C) {
return serializeNode(C);
});
return clone;
};
if (!asty.isA(node)) throw new Error("failed to serialize: not an ASTy node");
return JSON.stringify({ ASTy: serializeNode(node) });
}
}, {
key: "unserialize",
/* recursively unserialize JSON string into AST nodes */
value: function unserialize(asty, json) {
var unserializeNode = function unserializeNode(clone) {
var node = asty.create(clone.T);
node.pos(clone.L.L, clone.L.C, clone.L.O);
if (typeof clone.A === "object") {
Object.keys(clone.A).forEach(function (key) {
var value = clone.A[key];
switch (typeof value) {
case "boolean":
case "number":
case "string":
node.set(key, value);
break;
default:
/* use the slow approach only for non-atomic attributes */
node.set(key, JSON.parse(JSON.stringify(value)));
break;
}
});
}
if (typeof clone.C === "object" && clone.C instanceof Array) node.add(clone.C.map(function (C) {
return unserializeNode(C);
}));
return node;
};
var obj = JSON.parse(json);
if (typeof obj !== "object" || typeof obj.ASTy !== "object") throw new Error("failed to unserialize: not an ASTy JSON export");
return unserializeNode(obj.ASTy);
}
}]);
return ASTYSerialize;
})();
exports["default"] = ASTYSerialize;
module.exports = exports["default"];
},{}],5:[function(_dereq_,module,exports){
/*
** ASTy -- Abstract Syntax Tree (AST) Data Structure
** Copyright (c) 2014-2015 Ralf S. Engelschall <rse@engelschall.com>
**
** Permission is hereby granted, free of charge, to any person obtaining
** a copy of this software and associated documentation files (the
** "Software"), to deal in the Software without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Software, and to
** permit persons to whom the Software is furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* global 1: false */
/* global 1: false */
/* global 5: false */
/* global 20150530: false */
/* global 2: false */
/* global 0: false */
/* global 20150531: false */

@@ -416,5 +537,5 @@ "use strict";

major: 1,
minor: 1,
micro: 5,
date: 20150530
minor: 2,
micro: 0,
date: 20150531
};

@@ -425,3 +546,3 @@

},{}],5:[function(_dereq_,module,exports){
},{}],6:[function(_dereq_,module,exports){
/*

@@ -490,3 +611,3 @@ ** ASTy -- Abstract Syntax Tree (AST) Data Structure

},{}],6:[function(_dereq_,module,exports){
},{}],7:[function(_dereq_,module,exports){
/*

@@ -544,2 +665,6 @@ ** ASTy -- Abstract Syntax Tree (AST) Data Structure

var _astySerializeJs = _dereq_("./asty-serialize.js");
var _astySerializeJs2 = _interopRequireDefault(_astySerializeJs);
var _astyVersionJs = _dereq_("./asty-version.js");

@@ -588,2 +713,12 @@

}
}, {
key: "serialize",
value: function serialize(node) {
return _astySerializeJs2["default"].serialize(this, node);
}
}, {
key: "unserialize",
value: function unserialize(json) {
return _astySerializeJs2["default"].unserialize(this, json);
}
}]);

@@ -597,3 +732,3 @@

},{"./asty-base.js":1,"./asty-dump.js":2,"./asty-merge.js":3,"./asty-version.js":4,"./asty-walk.js":5}]},{},[1,2,3,4,5,6])(6)
},{"./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)
});
{
"name": "asty",
"version": "1.1.5",
"version": "1.2.0",
"description": "Abstract Syntax Tree (AST) Data Structure",
"keywords": [ "ast", "abstract", "syntax", "tree", "data", "structure" ],
"main": "lib/asty.node.js",
"license": "MIT",
"repository": {

@@ -16,6 +17,2 @@ "type": "git",

},
"licenses": [{
"type": "MIT",
"url": "http://opensource.org/licenses/MIT"
}],
"homepage": "https://github.com/rse/asty",

@@ -31,3 +28,3 @@ "bugs": "https://github.com/rse/asty/issues",

"grunt-mocha-test": "~0.12.7",
"grunt-eslint": "~13.0.0",
"grunt-eslint": "~14.0.0",
"babel-eslint": "~3.1.9",

@@ -34,0 +31,0 @@ "mocha": "~2.2.5",

@@ -54,2 +54,5 @@

- `ASTYCtx#version(): { major: Number, minor: Number, micro: Number, date: Number }`:<br/>
Return the ASTy version detals. The date is in numeric format `YYYYMMDD`.
- `ASTYCtx#extend(object: { [methodName: String]: [methodFunc: Function] }): ASTYCtx`:<br/>

@@ -65,2 +68,8 @@ Extend the internal ASTYNode prototype with additional methods which are then available on each

- `ASTYCtx#serialize(node: ASTYNode): String`:<br/>
Serializes (formats) ASTy nodes to JSON string. Use this for exporting an AST.
- `ASTYCtx#unserialize(json: String): ASTYNode`:<br/>
Unserializes (parses) JSON string to ASTy nodes. Use this for importing an AST.
### ASTy Node (ASTYNode)

@@ -77,3 +86,3 @@

- `ASTYNode#pos(line: Number, column: Number, offset: Number): ASTYNode`:<br/>
`ASTYNode#pos(): Object`:<br/>
`ASTYNode#pos(): { line: Number, column: Number, offset: Number }`:<br/>
Set or get the position for the node.

@@ -80,0 +89,0 @@

@@ -59,9 +59,13 @@ /*

/* set the parsing position */
pos (L, C, O) {
pos (line, column, offset) {
if (arguments.length === 0)
return this.L
return {
line: this.L.L,
column: this.L.C,
offset: this.L.O
}
else if (arguments.length <= 3) {
this.L.L = L || 0
this.L.C = C || 0
this.L.O = O || 0
this.L.L = line || 0
this.L.C = column || 0
this.L.O = offset || 0
return this

@@ -68,0 +72,0 @@ }

@@ -25,7 +25,8 @@ /*

import ASTYBase from "./asty-base.js"
import ASTYMerge from "./asty-merge.js"
import ASTYWalk from "./asty-walk.js"
import ASTYDump from "./asty-dump.js"
import ASTYVersion from "./asty-version.js"
import ASTYBase from "./asty-base.js"
import ASTYMerge from "./asty-merge.js"
import ASTYWalk from "./asty-walk.js"
import ASTYDump from "./asty-dump.js"
import ASTYSerialize from "./asty-serialize.js"
import ASTYVersion from "./asty-version.js"

@@ -69,3 +70,9 @@ export default class ASTYCtx {

}
serialize (node) {
return ASTYSerialize.serialize(this, node)
}
unserialize (json) {
return ASTYSerialize.unserialize(this, json)
}
}

@@ -75,3 +75,17 @@ /*

})
it("node serialize/unserialize functionality", function () {
var asty = new ASTy()
var node1 = asty.create("1")
node1.set("foo", { bar: 42, quux: "7" })
var node11 = asty.create("1.1")
var node12 = asty.create("1.2")
var node121 = asty.create("1.2.1")
var node122 = asty.create("1.2.2")
node1.add(node11, node12)
node12.add(node121, node122)
var dump1 = node1.dump()
var dump2 = asty.unserialize(asty.serialize(node1)).dump()
expect(dump1).to.be.equal(dump2)
})
})

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