Comparing version 1.8.18 to 1.8.19
/* | ||
** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
** Copyright (c) 2014-2022 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2023 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -5,0 +5,0 @@ ** Permission is hereby granted, free of charge, to any person obtaining |
/* | ||
** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
** Copyright (c) 2014-2022 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2023 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -26,16 +26,16 @@ ** Permission is hereby granted, free of charge, to any person obtaining | ||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ASTY = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(_dereq_,module,exports){ | ||
"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(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)}}function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var ASTYBase=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"init",value:function(e,t,n,r){if(arguments.length<2)throw new Error("init: invalid number of arguments");if(this.ctx=e,this.ASTy=!0,this.T=t,this.L={L:0,C:0,O:0},this.A={},this.C=[],this.P=null,"object"===_typeof(n))for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&this.set(i,n[i]);return"object"===_typeof(r)&&r instanceof Array&&this.add(r),this}},{key:"create",value:function(e,t,n){return this.ctx.create(e,t,n)}},{key:"type",value:function(e){if(0===arguments.length)return this.T;if(1===arguments.length)return this.T=e,this;throw new Error("type: invalid number of arguments")}},{key:"pos",value:function(e,t,n){if(0===arguments.length)return{line:this.L.L,column:this.L.C,offset:this.L.O};if(arguments.length<=3)return this.L.L=e||0,this.L.C=t||0,this.L.O=n||0,this;throw new Error("pos: invalid number of arguments")}},{key:"set",value:function(){for(var e=this,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];if(1===n.length&&"object"===_typeof(n[0]))Object.keys(n[0]).forEach(function(t){void 0!==n[0][t]?e.A[t]=n[0][t]:delete e.A[t]});else{if(2!==n.length)throw new Error("set: invalid number of arguments");void 0!==n[1]?this.A[n[0]]=n[1]:delete this.A[n[0]]}return this}},{key:"unset",value:function(){for(var e=this,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];if(1===n.length&&"object"===_typeof(n[0])&&n[0]instanceof Array)n[0].forEach(function(t){delete e.A[t]});else{if(1!==n.length)throw new Error("unset: invalid number of arguments");delete this.A[n[0]]}return this}},{key:"get",value:function(){for(var e=this,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];if(1!==n.length)throw new Error("get: invalid number of arguments");if("object"===_typeof(n[0])&&n[0]instanceof Array)return n[0].map(function(t){if("string"!=typeof t)throw new Error("get: invalid key argument");return e.A[t]});var i=n[0];if("string"!=typeof i)throw new Error("get: invalid key argument");return this.A[i]}},{key:"attrs",value:function(){return Object.keys(this.A)}},{key:"nth",value:function(){if(null===this.P)return 1;var e=this.P.C.indexOf(this);if(e<0)throw new Error("nth: internal error -- node not in childs of its parent");return e}},{key:"ins",value:function(e){for(var t=this,n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];if(0===r.length)throw new Error("ins: invalid number of arguments");if(e<0&&(e=this.C.length+1-e),!(e>=0&&e<=this.C.length))throw new Error("ins: invalid position");var o=function(n){if(!t.ctx.isA(n))throw new Error("ins: invalid AST node argument");t.C.splice(e++,0,n),n.P=t};return r.forEach(function(e){"object"===_typeof(e)&&e instanceof Array?e.forEach(function(e){o(e)}):null!==e&&o(e)}),this}},{key:"add",value:function(){for(var e=this,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];if(0===n.length)throw new Error("add: invalid number of arguments");var i=function(t){if(!e.ctx.isA(t))throw new Error("add: invalid AST node argument");e.C.push(t),t.P=e};return n.forEach(function(e){"object"===_typeof(e)&&e instanceof Array?e.forEach(function(e){i(e)}):null!==e&&i(e)}),this}},{key:"del",value:function(){for(var e=this,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];if(0===n.length)throw new Error("del: invalid number of arguments");return n.forEach(function(t){if(!e.ctx.isA(t))throw new Error("del: invalid AST node argument");for(var n=!1,r=0;r<e.C.length;r++)if(e.C[r]===t){e.C.splice(r,1),t.P=null,n=!0;break}if(!n)throw new Error("del: AST node not found in childs")}),this}},{key:"childs",value:function(){if(arguments.length>2)throw new Error("childs: invalid number of arguments");if(2===arguments.length&&"number"==typeof(arguments.length<=0?void 0:arguments[0])&&"number"==typeof(arguments.length<=1?void 0:arguments[1]))return this.C.slice(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1]);if(1===arguments.length&&"number"==typeof(arguments.length<=0?void 0:arguments[0]))return this.C.slice(arguments.length<=0?void 0:arguments[0]);if(0===arguments.length)return this.C;throw new Error("childs: invalid type of arguments")}},{key:"child",value:function(e){if("number"!=typeof e)throw new Error("child: invalid argument");return e<this.C.length?this.C[e]:null}},{key:"parent",value:function(){return this.P}},{key:"serialize",value:function(){return this.ctx.__serialize(this)}}]),e}();exports.default=ASTYBase; | ||
"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(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,_toPropertyKey(n.key),n)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"===_typeof(t)?t:String(t)}function _toPrimitive(e,t){if("object"!==_typeof(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var ASTYBase=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"init",value:function(e,t,r,n){if(arguments.length<2)throw new Error("init: invalid number of arguments");if(this.ctx=e,this.ASTy=!0,this.T=t,this.L={L:0,C:0,O:0},this.A={},this.C=[],this.P=null,"object"===_typeof(r))for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&this.set(i,r[i]);return"object"===_typeof(n)&&n instanceof Array&&this.add(n),this}},{key:"create",value:function(e,t,r){return this.ctx.create(e,t,r)}},{key:"type",value:function(e){if(0===arguments.length)return this.T;if(1===arguments.length)return this.T=e,this;throw new Error("type: invalid number of arguments")}},{key:"pos",value:function(e,t,r){if(0===arguments.length)return{line:this.L.L,column:this.L.C,offset:this.L.O};if(arguments.length<=3)return this.L.L=e||0,this.L.C=t||0,this.L.O=r||0,this;throw new Error("pos: invalid number of arguments")}},{key:"set",value:function(){for(var e=this,t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];if(1===r.length&&"object"===_typeof(r[0]))Object.keys(r[0]).forEach(function(t){void 0!==r[0][t]?e.A[t]=r[0][t]:delete e.A[t]});else{if(2!==r.length)throw new Error("set: invalid number of arguments");void 0!==r[1]?this.A[r[0]]=r[1]:delete this.A[r[0]]}return this}},{key:"unset",value:function(){for(var e=this,t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];if(1===r.length&&"object"===_typeof(r[0])&&r[0]instanceof Array)r[0].forEach(function(t){delete e.A[t]});else{if(1!==r.length)throw new Error("unset: invalid number of arguments");delete this.A[r[0]]}return this}},{key:"get",value:function(){for(var e=this,t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];if(1!==r.length)throw new Error("get: invalid number of arguments");if("object"===_typeof(r[0])&&r[0]instanceof Array)return r[0].map(function(t){if("string"!=typeof t)throw new Error("get: invalid key argument");return e.A[t]});var i=r[0];if("string"!=typeof i)throw new Error("get: invalid key argument");return this.A[i]}},{key:"attrs",value:function(){return Object.keys(this.A)}},{key:"nth",value:function(){if(null===this.P)return 1;var e=this.P.C.indexOf(this);if(e<0)throw new Error("nth: internal error -- node not in childs of its parent");return e}},{key:"ins",value:function(e){for(var t=this,r=arguments.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=arguments[i];if(0===n.length)throw new Error("ins: invalid number of arguments");if(e<0&&(e=this.C.length+1-e),!(e>=0&&e<=this.C.length))throw new Error("ins: invalid position");var o=function(r){if(!t.ctx.isA(r))throw new Error("ins: invalid AST node argument");t.C.splice(e++,0,r),r.P=t};return n.forEach(function(e){"object"===_typeof(e)&&e instanceof Array?e.forEach(function(e){o(e)}):null!==e&&o(e)}),this}},{key:"add",value:function(){for(var e=this,t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];if(0===r.length)throw new Error("add: invalid number of arguments");var i=function(t){if(!e.ctx.isA(t))throw new Error("add: invalid AST node argument");e.C.push(t),t.P=e};return r.forEach(function(e){"object"===_typeof(e)&&e instanceof Array?e.forEach(function(e){i(e)}):null!==e&&i(e)}),this}},{key:"del",value:function(){for(var e=this,t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];if(0===r.length)throw new Error("del: invalid number of arguments");return r.forEach(function(t){if(!e.ctx.isA(t))throw new Error("del: invalid AST node argument");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: AST node not found in childs")}),this}},{key:"childs",value:function(){if(arguments.length>2)throw new Error("childs: invalid number of arguments");if(2===arguments.length&&"number"==typeof(arguments.length<=0?void 0:arguments[0])&&"number"==typeof(arguments.length<=1?void 0:arguments[1]))return this.C.slice(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1]);if(1===arguments.length&&"number"==typeof(arguments.length<=0?void 0:arguments[0]))return this.C.slice(arguments.length<=0?void 0:arguments[0]);if(0===arguments.length)return this.C;throw new Error("childs: invalid type of arguments")}},{key:"child",value:function(e){if("number"!=typeof e)throw new Error("child: invalid argument");return e<this.C.length?this.C[e]:null}},{key:"parent",value:function(){return this.P}},{key:"serialize",value:function(){return this.ctx.__serialize(this)}}]),e}();exports.default=ASTYBase; | ||
},{}],2:[function(_dereq_,module,exports){ | ||
"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(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)}}function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var tree={mid:{unicode:String.fromCharCode(9500),ascii:"+"},last:{unicode:String.fromCharCode(9492),ascii:"+"},down:{unicode:String.fromCharCode(9474),ascii:"|"},left:{unicode:String.fromCharCode(9472),ascii:"-"}},ASTYDump=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"dump",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1/0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(e,t){return t},n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r="",o=this;return this.walk(function(c,a){if(!(a>e)){if(a>0){var i=function(e){var t=0,n=0;return null!==e.P&&(t=e.P.C.indexOf(e),n=e.P.C.length-1),{nth:t,max:n}},u=i(c),l=u.nth,f=u.max,s=" ";s=n?"".concat(tree.left.unicode).concat(tree.left.unicode).concat(s):"".concat(tree.left.ascii).concat(tree.left.ascii).concat(s),s=l<f?"".concat(n?tree.mid.unicode:tree.mid.ascii).concat(s):"".concat(n?tree.last.unicode:tree.last.ascii).concat(s);for(var p=c.P;null!==p&&p!==o;p=p.P)if(null!==p.P){var d=i(p);s=d.nth<d.max?"".concat(n?tree.down.unicode:tree.down.ascii," ").concat(s):" ".concat(s)}r+=t("tree",s)}r+=t("type",c.T)+" ";var y=Object.keys(c.A).filter(function(e){return!e.match(/^__/)});if(y.length>0){r+=t("parenthesis","(");var g=!0;y.forEach(function(e){g?g=!1:r+=t("comma",",")+" ",r+=t("key",e)+t("colon",":")+" ";var n=c.A[e];switch(_typeof(n)){case"boolean":case"number":r+=t("value",n.toString());break;case"string":var o=function(e){return e.charCodeAt(0).toString(16).toUpperCase()};r+=t("value",'"'+n.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E\x0F]/g,function(e){return"\\x0"+o(e)}).replace(/[\x10-\x1F\x80-\xFF]/g,function(e){return"\\x"+o(e)}).replace(/[\u0100-\u0FFF]/g,function(e){return"\\u0"+o(e)}).replace(/[\u1000-\uFFFF]/g,function(e){return"\\u"+o(e)})+'"');break;case"object":n instanceof RegExp?r+=t("value","/"+n.source+"/"):r+=t("value",JSON.stringify(n));break;default:r+=t("value",JSON.stringify(n))}}),r+=t("parenthesis",")")+" "}r+=t("position",t("bracket","[")+t("line",c.L.L)+t("slash",",")+t("column",c.L.C)+t("bracket","]")),r+="\n"}},"downward"),r}}]),e}();exports.default=ASTYDump; | ||
"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(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,_toPropertyKey(n.key),n)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"===_typeof(t)?t:String(t)}function _toPrimitive(e,t){if("object"!==_typeof(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var tree={mid:{unicode:String.fromCharCode(9500),ascii:"+"},last:{unicode:String.fromCharCode(9492),ascii:"+"},down:{unicode:String.fromCharCode(9474),ascii:"|"},left:{unicode:String.fromCharCode(9472),ascii:"-"}},ASTYDump=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"dump",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1/0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(e,t){return t},r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],n="",o=this;return this.walk(function(i,a){if(!(a>e)){if(a>0){var c=function(e){var t=0,r=0;return null!==e.P&&(t=e.P.C.indexOf(e),r=e.P.C.length-1),{nth:t,max:r}},u=c(i),l=u.nth,f=u.max,s=" ";s=r?"".concat(tree.left.unicode).concat(tree.left.unicode).concat(s):"".concat(tree.left.ascii).concat(tree.left.ascii).concat(s),s=l<f?"".concat(r?tree.mid.unicode:tree.mid.ascii).concat(s):"".concat(r?tree.last.unicode:tree.last.ascii).concat(s);for(var p=i.P;null!==p&&p!==o;p=p.P)if(null!==p.P){var d=c(p);s=d.nth<d.max?"".concat(r?tree.down.unicode:tree.down.ascii," ").concat(s):" ".concat(s)}n+=t("tree",s)}n+=t("type",i.T)+" ";var y=Object.keys(i.A).filter(function(e){return!e.match(/^__/)});if(y.length>0){n+=t("parenthesis","(");var m=!0;y.forEach(function(e){m?m=!1:n+=t("comma",",")+" ",n+=t("key",e)+t("colon",":")+" ";var r=i.A[e];switch(_typeof(r)){case"boolean":case"number":n+=t("value",r.toString());break;case"string":var o=function(e){return e.charCodeAt(0).toString(16).toUpperCase()};n+=t("value",'"'+r.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E\x0F]/g,function(e){return"\\x0"+o(e)}).replace(/[\x10-\x1F\x80-\xFF]/g,function(e){return"\\x"+o(e)}).replace(/[\u0100-\u0FFF]/g,function(e){return"\\u0"+o(e)}).replace(/[\u1000-\uFFFF]/g,function(e){return"\\u"+o(e)})+'"');break;case"object":r instanceof RegExp?n+=t("value","/"+r.source+"/"):n+=t("value",JSON.stringify(r));break;default:n+=t("value",JSON.stringify(r))}}),n+=t("parenthesis",")")+" "}n+=t("position",t("bracket","[")+t("line",i.L.L)+t("slash",",")+t("column",i.L.C)+t("bracket","]")),n+="\n"}},"downward"),n}}]),e}();exports.default=ASTYDump; | ||
},{}],3:[function(_dereq_,module,exports){ | ||
"use strict";function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(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)}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var ASTYMerge=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"merge",value:function(e){var r=this,t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(null===e)return this;if(!this.ctx.isA(e))throw new Error("merge: invalid AST node argument");if(t){var i=e.pos();this.pos(i.line,i.column,i.offset)}e.attrs().forEach(function(t){var i=void 0!==n[t]?n[t]:t;null!==i&&r.set(i,e.get(t))}),e.childs().forEach(function(t){e.del(t),r.add(t)});var o=e.parent();return null!==o&&o.del(e),this}}]),e}();exports.default=ASTYMerge; | ||
"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"===_typeof(t)?t:String(t)}function _toPrimitive(e,t){if("object"!==_typeof(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,t||"default");if("object"!==_typeof(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var 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]&&arguments[1],o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(null===e)return this;if(!this.ctx.isA(e))throw new Error("merge: invalid AST node argument");if(r){var n=e.pos();this.pos(n.line,n.column,n.offset)}e.attrs().forEach(function(r){var n=void 0!==o[r]?o[r]:r;null!==n&&t.set(n,e.get(r))}),e.childs().forEach(function(r){e.del(r),t.add(r)});var i=e.parent();return null!==i&&i.del(e),this}}]),e}();exports.default=ASTYMerge; | ||
},{}],4:[function(_dereq_,module,exports){ | ||
"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(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)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var ASTYSerialize=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"serialize",value:function(e,t){if(!e.isA(t))throw new Error("serialize: not an ASTy node");return JSON.stringify({ASTy:function e(t){var r={T:t.T,L:{L:t.L.L,C:t.L.C,O:t.L.O}},n=Object.keys(t.A);return n.length>0&&(r.A={},n.forEach(function(e){var n=t.A[e];switch(_typeof(n)){case"boolean":case"number":case"string":r.A[e]=n;break;default:r.A[e]=JSON.parse(JSON.stringify(n))}})),t.C.length>0&&(r.C=t.C.map(function(t){return e(t)})),r}(t)})}},{key:"unserialize",value:function(e,t){var r=JSON.parse(t);if("object"!==_typeof(r)||"object"!==_typeof(r.ASTy))throw new Error("unserialize: not an ASTy JSON export");return function t(r){var n=e.create(r.T);return n.pos(r.L.L,r.L.C,r.L.O),"object"===_typeof(r.A)&&Object.keys(r.A).forEach(function(e){var t=r.A[e];switch(_typeof(t)){case"boolean":case"number":case"string":n.set(e,t);break;default:n.set(e,JSON.parse(JSON.stringify(t)))}}),"object"===_typeof(r.C)&&r.C instanceof Array&&n.add(r.C.map(function(e){return t(e)})),n}(r.ASTy)}}]),e}();exports.default=ASTYSerialize; | ||
"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"===_typeof(t)?t:String(t)}function _toPrimitive(e,t){if("object"!==_typeof(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,t||"default");if("object"!==_typeof(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var ASTYSerialize=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"serialize",value:function(e,t){if(!e.isA(t))throw new Error("serialize: not an ASTy node");return JSON.stringify({ASTy:function e(t){var r={T:t.T,L:{L:t.L.L,C:t.L.C,O:t.L.O}},o=Object.keys(t.A);return o.length>0&&(r.A={},o.forEach(function(e){var o=t.A[e];switch(_typeof(o)){case"boolean":case"number":case"string":r.A[e]=o;break;default:r.A[e]=JSON.parse(JSON.stringify(o))}})),t.C.length>0&&(r.C=t.C.map(function(t){return e(t)})),r}(t)})}},{key:"unserialize",value:function(e,t){var r=JSON.parse(t);if("object"!==_typeof(r)||"object"!==_typeof(r.ASTy))throw new Error("unserialize: not an ASTy JSON export");return function t(r){var o=e.create(r.T);return o.pos(r.L.L,r.L.C,r.L.O),"object"===_typeof(r.A)&&Object.keys(r.A).forEach(function(e){var t=r.A[e];switch(_typeof(t)){case"boolean":case"number":case"string":o.set(e,t);break;default:o.set(e,JSON.parse(JSON.stringify(t)))}}),"object"===_typeof(r.C)&&r.C instanceof Array&&o.add(r.C.map(function(e){return t(e)})),o}(r.ASTy)}}]),e}();exports.default=ASTYSerialize; | ||
},{}],5:[function(_dereq_,module,exports){ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var version={major:1,minor:8,micro:18,date:20220701},_default=version;exports.default=_default; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var version={major:1,minor:8,micro:19,date:20230827},_default=version;exports.default=_default; | ||
},{}],6:[function(_dereq_,module,exports){ | ||
"use strict";function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(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)}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var ASTYWalk=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"walk",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"downward";return function t(n,a,o){"downward"!==r&&"both"!==r||e(n,a,o,"downward"),n.C.forEach(function(e){t(e,a+1,n)}),"upward"!==r&&"both"!==r||e(n,a,o,"upward")}(this,0,null),this}}]),e}();exports.default=ASTYWalk; | ||
"use strict";function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var r=0;r<e.length;r++){var o=e[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,_toPropertyKey(o.key),o)}}function _createClass(t,e,r){return e&&_defineProperties(t.prototype,e),r&&_defineProperties(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function _toPropertyKey(t){var e=_toPrimitive(t,"string");return"symbol"===_typeof(e)?e:String(e)}function _toPrimitive(t,e){if("object"!==_typeof(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,e||"default");if("object"!==_typeof(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var ASTYWalk=function(){function t(){_classCallCheck(this,t)}return _createClass(t,[{key:"walk",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"downward";return function r(o,n,i){"downward"!==e&&"both"!==e||t(o,n,i,"downward"),o.C.forEach(function(t){r(t,n+1,o)}),"upward"!==e&&"both"!==e||t(o,n,i,"upward")}(this,0,null),this}}]),t}();exports.default=ASTYWalk; | ||
},{}],7:[function(_dereq_,module,exports){ | ||
"use strict";var _astyBase=_interopRequireDefault(_dereq_("./asty-base.js")),_astyMerge=_interopRequireDefault(_dereq_("./asty-merge.js")),_astyWalk=_interopRequireDefault(_dereq_("./asty-walk.js")),_astyDump=_interopRequireDefault(_dereq_("./asty-dump.js")),_astySerialize=_interopRequireDefault(_dereq_("./asty-serialize.js")),_astyVersion=_interopRequireDefault(_dereq_("./asty-version.js"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}var ASTYCtx=function(){function e(){var t=this;return _classCallCheck(this,e),this.ASTYNode=_createClass(function e(){_classCallCheck(this,e)}),[[_astyBase.default,"init","create","type","pos","set","unset","get","attrs","nth","ins","add","del","childs","child","parent","serialize"],[_astyMerge.default,"merge"],[_astyWalk.default,"walk"],[_astyDump.default,"dump"]].forEach(function(e){var r=e[0].prototype;e.slice(1).forEach(function(e){t.ASTYNode.prototype[e]=r[e]})}),this}return _createClass(e,[{key:"version",value:function(){return _astyVersion.default}},{key:"extend",value:function(e){for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(this.ASTYNode.prototype[t]=e[t]);return this}},{key:"create",value:function(e,t,r){return(new this.ASTYNode).init(this,e,t,r)}},{key:"isA",value:function(e){return"object"===_typeof(e)&&e instanceof this.ASTYNode&&"boolean"==typeof e.ASTy&&!0===e.ASTy}},{key:"__serialize",value:function(t){return e.serialize(t)}}],[{key:"serialize",value:function(e){return _astySerialize.default.serialize(e.ctx,e)}},{key:"unserialize",value:function(e){return _astySerialize.default.unserialize(new this,e)}}]),e}();module.exports=ASTYCtx; | ||
"use strict";var _astyBase=_interopRequireDefault(_dereq_("./asty-base.js")),_astyMerge=_interopRequireDefault(_dereq_("./asty-merge.js")),_astyWalk=_interopRequireDefault(_dereq_("./asty-walk.js")),_astyDump=_interopRequireDefault(_dereq_("./asty-dump.js")),_astySerialize=_interopRequireDefault(_dereq_("./asty-serialize.js")),_astyVersion=_interopRequireDefault(_dereq_("./asty-version.js"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,_toPropertyKey(i.key),i)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"===_typeof(t)?t:String(t)}function _toPrimitive(e,t){if("object"!==_typeof(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var i=r.call(e,t||"default");if("object"!==_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var ASTYCtx=function(){function e(){var t=this;return _classCallCheck(this,e),this.ASTYNode=_createClass(function e(){_classCallCheck(this,e)}),[[_astyBase.default,"init","create","type","pos","set","unset","get","attrs","nth","ins","add","del","childs","child","parent","serialize"],[_astyMerge.default,"merge"],[_astyWalk.default,"walk"],[_astyDump.default,"dump"]].forEach(function(e){var r=e[0].prototype;e.slice(1).forEach(function(e){t.ASTYNode.prototype[e]=r[e]})}),this}return _createClass(e,[{key:"version",value:function(){return _astyVersion.default}},{key:"extend",value:function(e){for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(this.ASTYNode.prototype[t]=e[t]);return this}},{key:"create",value:function(e,t,r){return(new this.ASTYNode).init(this,e,t,r)}},{key:"isA",value:function(e){return"object"===_typeof(e)&&e instanceof this.ASTYNode&&"boolean"==typeof e.ASTy&&!0===e.ASTy}},{key:"__serialize",value:function(t){return e.serialize(t)}}],[{key:"serialize",value:function(e){return _astySerialize.default.serialize(e.ctx,e)}},{key:"unserialize",value:function(e){return _astySerialize.default.unserialize(new this,e)}}]),e}();module.exports=ASTYCtx; | ||
},{"./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) | ||
}); |
/* | ||
** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
** Copyright (c) 2014-2022 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2023 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -32,6 +32,5 @@ ** Permission is hereby granted, free of charge, to any person obtaining | ||
exports.default = void 0; | ||
/* | ||
** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
** Copyright (c) 2014-2022 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2023 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -57,2 +56,3 @@ ** Permission is hereby granted, free of charge, to any person obtaining | ||
*/ | ||
class ASTYBase { | ||
@@ -73,19 +73,15 @@ /* AST node initialization */ | ||
this.P = null; | ||
if (typeof A === "object") { | ||
for (let name in A) if (Object.prototype.hasOwnProperty.call(A, name)) this.set(name, A[name]); | ||
} | ||
if (typeof C === "object" && C instanceof Array) this.add(C); | ||
return this; | ||
} | ||
/* create new AST node */ | ||
create(T, A, C) { | ||
return this.ctx.create(T, A, C); | ||
} | ||
/* check the type of an AST node */ | ||
type(T) { | ||
@@ -97,5 +93,4 @@ if (arguments.length === 0) return this.T;else if (arguments.length === 1) { | ||
} | ||
/* set the parsing position */ | ||
pos(line, column, offset) { | ||
@@ -113,5 +108,4 @@ if (arguments.length === 0) return { | ||
} | ||
/* set AST node attributes */ | ||
set(...args) { | ||
@@ -125,8 +119,6 @@ if (args.length === 1 && typeof args[0] === "object") { | ||
} else throw new Error("set: invalid number of arguments"); | ||
return this; | ||
} | ||
/* unset AST node attributes */ | ||
unset(...args) { | ||
@@ -138,11 +130,8 @@ if (args.length === 1 && typeof args[0] === "object" && args[0] instanceof Array) { | ||
} else if (args.length === 1) delete this.A[args[0]];else throw new Error("unset: invalid number of arguments"); | ||
return this; | ||
} | ||
/* get AST node attributes */ | ||
get(...args) { | ||
if (args.length !== 1) throw new Error("get: invalid number of arguments"); | ||
if (typeof args[0] === "object" && args[0] instanceof Array) { | ||
@@ -159,11 +148,9 @@ return args[0].map(key => { | ||
} | ||
/* get names of all AST node attributes */ | ||
attrs() { | ||
return Object.keys(this.A); | ||
} | ||
/* return current sibling position */ | ||
nth() { | ||
@@ -175,5 +162,4 @@ if (this.P === null) return 1; | ||
} | ||
/* insert child AST node(s) */ | ||
ins(pos, ...args) { | ||
@@ -183,3 +169,2 @@ if (args.length === 0) throw new Error("ins: invalid number of arguments"); | ||
if (!(pos >= 0 && pos <= this.C.length)) throw new Error("ins: invalid position"); | ||
let _ins = node => { | ||
@@ -190,3 +175,2 @@ if (!this.ctx.isA(node)) throw new Error("ins: invalid AST node argument"); | ||
}; | ||
args.forEach(arg => { | ||
@@ -199,8 +183,6 @@ if (typeof arg === "object" && arg instanceof Array) arg.forEach(arg => { | ||
} | ||
/* add child AST node(s) */ | ||
add(...args) { | ||
if (args.length === 0) throw new Error("add: invalid number of arguments"); | ||
let _add = node => { | ||
@@ -211,3 +193,2 @@ if (!this.ctx.isA(node)) throw new Error("add: invalid AST node argument"); | ||
}; | ||
args.forEach(arg => { | ||
@@ -220,5 +201,4 @@ if (typeof arg === "object" && arg instanceof Array) arg.forEach(arg => { | ||
} | ||
/* delete child AST node(s) */ | ||
del(...args) { | ||
@@ -229,3 +209,2 @@ if (args.length === 0) throw new Error("del: invalid number of arguments"); | ||
let found = false; | ||
for (let j = 0; j < this.C.length; j++) { | ||
@@ -239,3 +218,2 @@ if (this.C[j] === node) { | ||
} | ||
if (!found) throw new Error("del: AST node not found in childs"); | ||
@@ -245,5 +223,4 @@ }); | ||
} | ||
/* get all or some child AST nodes */ | ||
childs(...args) { | ||
@@ -253,5 +230,4 @@ if (args.length > 2) throw new Error("childs: invalid number of arguments"); | ||
} | ||
/* get one child AST node */ | ||
child(pos) { | ||
@@ -261,17 +237,13 @@ if (typeof pos !== "number") throw new Error("child: invalid argument"); | ||
} | ||
/* get parent AST node */ | ||
parent() { | ||
return this.P; | ||
} | ||
/* serialize AST node recursively */ | ||
serialize() { | ||
return this.ctx.__serialize(this); | ||
} | ||
} | ||
exports.default = ASTYBase; | ||
@@ -286,6 +258,5 @@ | ||
exports.default = void 0; | ||
/* | ||
** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
** Copyright (c) 2014-2022 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2023 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -311,2 +282,3 @@ ** Permission is hereby granted, free of charge, to any person obtaining | ||
*/ | ||
const tree = { | ||
@@ -330,3 +302,2 @@ mid: { | ||
}; | ||
class ASTYDump { | ||
@@ -337,9 +308,7 @@ /* dump the AST recursively */ | ||
let self = this; | ||
this.walk((node, depth | ||
/*, parent, when */ | ||
) => { | ||
this.walk((node, depth /*, parent, when */) => { | ||
/* short-circuit processing at a certain depth */ | ||
if (depth > maxDepth) return; | ||
/* draw tree structure */ | ||
if (depth > 0) { | ||
@@ -349,3 +318,2 @@ const nodeIndex = node => { | ||
let max = 0; | ||
if (node.P !== null) { | ||
@@ -355,3 +323,2 @@ nth = node.P.C.indexOf(node); | ||
} | ||
return { | ||
@@ -362,3 +329,2 @@ nth, | ||
}; | ||
let { | ||
@@ -371,3 +337,2 @@ nth, | ||
if (nth < max) prefix = `${unicode ? tree.mid.unicode : tree.mid.ascii}${prefix}`;else prefix = `${unicode ? tree.last.unicode : tree.last.ascii}${prefix}`; | ||
for (let parent = node.P; parent !== null && parent !== self; parent = parent.P) { | ||
@@ -382,13 +347,10 @@ if (parent.P !== null) { | ||
} | ||
out += colorize("tree", prefix); | ||
} | ||
/* draw node type */ | ||
out += colorize("type", node.T) + " "; | ||
out += colorize("type", node.T) + " "; | ||
/* draw node attributes */ | ||
let keys = Object.keys(node.A).filter(key => !key.match(/^__/)); | ||
if (keys.length > 0) { | ||
@@ -401,3 +363,2 @@ out += colorize("parenthesis", "("); | ||
let value = node.A[key]; | ||
switch (typeof value) { | ||
@@ -408,3 +369,2 @@ case "boolean": | ||
break; | ||
case "string": | ||
@@ -414,12 +374,8 @@ { | ||
/* eslint no-control-regex: off */ | ||
out += colorize("value", "\"" + value.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, ch => "\\x0" + hex(ch)).replace(/[\x10-\x1F\x80-\xFF]/g, ch => "\\x" + hex(ch)).replace(/[\u0100-\u0FFF]/g, ch => "\\u0" + hex(ch)).replace(/[\u1000-\uFFFF]/g, ch => "\\u" + hex(ch)) + "\""); | ||
break; | ||
} | ||
case "object": | ||
if (value instanceof RegExp) out += colorize("value", "/" + value.source + "/");else out += colorize("value", JSON.stringify(value)); | ||
break; | ||
default: | ||
@@ -432,5 +388,4 @@ out += colorize("value", JSON.stringify(value)); | ||
} | ||
/* draw node position */ | ||
out += colorize("position", colorize("bracket", "[") + colorize("line", node.L.L) + colorize("slash", ",") + colorize("column", node.L.C) + colorize("bracket", "]")); | ||
@@ -441,5 +396,3 @@ out += "\n"; | ||
} | ||
} | ||
exports.default = ASTYDump; | ||
@@ -454,6 +407,5 @@ | ||
exports.default = void 0; | ||
/* | ||
** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
** Copyright (c) 2014-2022 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2023 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -479,2 +431,3 @@ ** Permission is hereby granted, free of charge, to any person obtaining | ||
*/ | ||
class ASTYMerge { | ||
@@ -485,3 +438,2 @@ /* merge attributes and childs of an AST node */ | ||
if (!this.ctx.isA(node)) throw new Error("merge: invalid AST node argument"); | ||
if (takePos) { | ||
@@ -491,3 +443,2 @@ let pos = node.pos(); | ||
} | ||
node.attrs().forEach(attrSource => { | ||
@@ -505,5 +456,3 @@ let attrTarget = typeof attrMap[attrSource] !== "undefined" ? attrMap[attrSource] : attrSource; | ||
} | ||
} | ||
exports.default = ASTYMerge; | ||
@@ -518,6 +467,5 @@ | ||
exports.default = void 0; | ||
/* | ||
** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
** Copyright (c) 2014-2022 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2023 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -543,2 +491,3 @@ ** Permission is hereby granted, free of charge, to any person obtaining | ||
*/ | ||
class ASTYSerialize { | ||
@@ -557,3 +506,2 @@ /* recursively serialize AST nodes into JSON string */ | ||
let keys = Object.keys(node.A); | ||
if (keys.length > 0) { | ||
@@ -563,3 +511,2 @@ clone.A = {}; | ||
let value = node.A[key]; | ||
switch (typeof value) { | ||
@@ -571,3 +518,2 @@ case "boolean": | ||
break; | ||
default: | ||
@@ -580,7 +526,5 @@ /* use the slow approach only for non-atomic attributes */ | ||
} | ||
if (node.C.length > 0) clone.C = node.C.map(C => serializeNode(C)); | ||
return clone; | ||
}; | ||
if (!asty.isA(node)) throw new Error("serialize: not an ASTy node"); | ||
@@ -591,5 +535,4 @@ return JSON.stringify({ | ||
} | ||
/* recursively unserialize JSON string into AST nodes */ | ||
static unserialize(asty, json) { | ||
@@ -599,7 +542,5 @@ const unserializeNode = clone => { | ||
node.pos(clone.L.L, clone.L.C, clone.L.O); | ||
if (typeof clone.A === "object") { | ||
Object.keys(clone.A).forEach(key => { | ||
let value = clone.A[key]; | ||
switch (typeof value) { | ||
@@ -611,3 +552,2 @@ case "boolean": | ||
break; | ||
default: | ||
@@ -620,7 +560,5 @@ /* use the slow approach only for non-atomic attributes */ | ||
} | ||
if (typeof clone.C === "object" && clone.C instanceof Array) node.add(clone.C.map(C => unserializeNode(C))); | ||
return node; | ||
}; | ||
let obj = JSON.parse(json); | ||
@@ -630,5 +568,3 @@ if (typeof obj !== "object" || typeof obj.ASTy !== "object") throw new Error("unserialize: not an ASTy JSON export"); | ||
} | ||
} | ||
exports.default = ASTYSerialize; | ||
@@ -643,6 +579,5 @@ | ||
exports.default = void 0; | ||
/* | ||
** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
** Copyright (c) 2014-2022 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2023 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -670,13 +605,11 @@ ** Permission is hereby granted, free of charge, to any person obtaining | ||
/* global 1: false */ | ||
/* global 8: false */ | ||
/* global 19: false */ | ||
/* global 20230827: false */ | ||
/* global 18: false */ | ||
/* global 20220701: false */ | ||
const version = { | ||
major: 1, | ||
minor: 8, | ||
micro: 18, | ||
date: 20220701 | ||
micro: 19, | ||
date: 20230827 | ||
}; | ||
@@ -693,6 +626,5 @@ var _default = version; | ||
exports.default = void 0; | ||
/* | ||
** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
** Copyright (c) 2014-2022 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2023 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -718,2 +650,3 @@ ** Permission is hereby granted, free of charge, to any person obtaining | ||
*/ | ||
class ASTYWalk { | ||
@@ -729,10 +662,6 @@ /* walk the AST recursively */ | ||
}; | ||
_walk(this, 0, null); | ||
return this; | ||
} | ||
} | ||
exports.default = ASTYWalk; | ||
@@ -744,18 +673,11 @@ | ||
var _astyBase = _interopRequireDefault(_dereq_("./asty-base.js")); | ||
var _astyMerge = _interopRequireDefault(_dereq_("./asty-merge.js")); | ||
var _astyWalk = _interopRequireDefault(_dereq_("./asty-walk.js")); | ||
var _astyDump = _interopRequireDefault(_dereq_("./asty-dump.js")); | ||
var _astySerialize = _interopRequireDefault(_dereq_("./asty-serialize.js")); | ||
var _astyVersion = _interopRequireDefault(_dereq_("./asty-version.js")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* | ||
** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
** Copyright (c) 2014-2022 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2023 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -781,2 +703,3 @@ ** Permission is hereby granted, free of charge, to any person obtaining | ||
*/ | ||
class ASTYCtx { | ||
@@ -794,29 +717,21 @@ constructor() { | ||
} | ||
version() { | ||
return _astyVersion.default; | ||
} | ||
extend(mixin) { | ||
for (let method in mixin) if (Object.prototype.hasOwnProperty.call(mixin, method)) this.ASTYNode.prototype[method] = mixin[method]; | ||
return this; | ||
} | ||
create(type, attrs, childs) { | ||
return new this.ASTYNode().init(this, type, attrs, childs); | ||
} | ||
isA(node) { | ||
return typeof node === "object" && node instanceof this.ASTYNode && typeof node.ASTy === "boolean" && node.ASTy === true; | ||
} | ||
__serialize(node) { | ||
return ASTYCtx.serialize(node); | ||
} | ||
static serialize(node) { | ||
return _astySerialize.default.serialize(node.ctx, node); | ||
} | ||
static unserialize(json) { | ||
@@ -826,8 +741,6 @@ let Ctx = this; | ||
} | ||
} | ||
} | ||
/* export the traditional way for interoperability reasons | ||
(as Babel would export an object with a 'default' field) */ | ||
module.exports = ASTYCtx; | ||
@@ -834,0 +747,0 @@ |
{ | ||
"name": "asty", | ||
"version": "1.8.18", | ||
"version": "1.8.19", | ||
"description": "Abstract Syntax Tree (AST) Data Structure", | ||
@@ -21,3 +21,3 @@ "keywords": [ "ast", "abstract", "syntax", "tree", "data", "structure" ], | ||
"devDependencies": { | ||
"grunt": "1.5.3", | ||
"grunt": "1.6.1", | ||
"grunt-cli": "1.4.3", | ||
@@ -27,13 +27,13 @@ "grunt-contrib-clean": "2.0.1", | ||
"grunt-mocha-test": "0.13.3", | ||
"grunt-eslint": "24.0.0", | ||
"@babel/core": "7.18.6", | ||
"eslint": "8.18.0", | ||
"eslint-config-standard": "17.0.0", | ||
"eslint-plugin-promise": "6.0.0", | ||
"eslint-plugin-import": "2.26.0", | ||
"grunt-eslint": "24.3.0", | ||
"@babel/core": "7.22.11", | ||
"eslint": "8.48.0", | ||
"eslint-config-standard": "17.1.0", | ||
"eslint-plugin-promise": "6.1.1", | ||
"eslint-plugin-import": "2.28.1", | ||
"eslint-plugin-node": "11.1.0", | ||
"mocha": "10.0.0", | ||
"chai": "4.3.6", | ||
"mocha": "10.2.0", | ||
"chai": "4.3.8", | ||
"babelify": "10.0.0", | ||
"@babel/preset-env": "7.18.6", | ||
"@babel/preset-env": "7.22.10", | ||
"uglifyify": "5.0.2", | ||
@@ -40,0 +40,0 @@ "browserify-header": "1.1.0", |
@@ -7,8 +7,8 @@ | ||
<p/> | ||
<img src="https://nodei.co/npm/asty.png?downloads=true&stars=true" alt=""/> | ||
[![github (author stars)](https://img.shields.io/github/stars/rse?logo=github&label=author%20stars&color=%233377aa)](https://github.com/rse) | ||
[![github (author followers)](https://img.shields.io/github/followers/rse?label=author%20followers&logo=github&color=%234477aa)](https://github.com/rse) | ||
<br/> | ||
[![npm (project release)](https://img.shields.io/npm/v/asty?logo=npm&label=npm%20release&color=%23cc3333)](https://npmjs.com/asty) | ||
[![npm (project downloads)](https://img.shields.io/npm/dm/asty?logo=npm&label=npm%20downloads&color=%23cc3333)](https://npmjs.com/asty) | ||
<p/> | ||
<img src="https://david-dm.org/rse/asty.png" alt=""/> | ||
Installation | ||
@@ -182,3 +182,3 @@ ------------ | ||
Copyright (c) 2014-2022 Dr. Ralf S. Engelschall (http://engelschall.com/) | ||
Copyright © 2014-2023 Dr. Ralf S. Engelschall (http://engelschall.com/) | ||
@@ -185,0 +185,0 @@ Permission is hereby granted, free of charge, to any person obtaining |
/* | ||
** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
** Copyright (c) 2014-2022 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2023 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -5,0 +5,0 @@ ** Permission is hereby granted, free of charge, to any person obtaining |
/* | ||
** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
** Copyright (c) 2014-2022 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2023 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -5,0 +5,0 @@ ** Permission is hereby granted, free of charge, to any person obtaining |
/* | ||
** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
** Copyright (c) 2014-2022 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2023 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -5,0 +5,0 @@ ** Permission is hereby granted, free of charge, to any person obtaining |
/* | ||
** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
** Copyright (c) 2014-2022 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2023 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -5,0 +5,0 @@ ** Permission is hereby granted, free of charge, to any person obtaining |
/* | ||
** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
** Copyright (c) 2014-2022 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2023 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -5,0 +5,0 @@ ** Permission is hereby granted, free of charge, to any person obtaining |
/* | ||
** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
** Copyright (c) 2014-2022 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2023 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -5,0 +5,0 @@ ** Permission is hereby granted, free of charge, to any person obtaining |
/* | ||
** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
** Copyright (c) 2014-2022 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2023 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -5,0 +5,0 @@ ** Permission is hereby granted, free of charge, to any person obtaining |
/* | ||
** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
** Copyright (c) 2014-2022 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2023 Dr. Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -5,0 +5,0 @@ ** Permission is hereby granted, free of charge, to any person obtaining |
Sorry, the diff of this file is not supported yet
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
98967
1631