Comparing version 0.9.1 to 0.9.2
/* | ||
** ASTy -- Generic Abstract Syntax Tree (AST) | ||
** Copyright (c) 2014 Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2015 Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -5,0 +5,0 @@ ** Permission is hereby granted, free of charge, to any person obtaining |
/* | ||
** ASTy -- Generic Abstract Syntax Tree (AST) | ||
** Copyright (c) 2014 Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2015 Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -26,8 +26,12 @@ ** Permission is hereby granted, free of charge, to any person obtaining | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.ASTY=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
"use strict";var ASTYBase=function(){var t=function(){};return t.prototype.init=function(t){if("undefined"==typeof t)throw new Error("init: invalid argument");return this.T=t,this.A={},this.C=[],this.P={L:0,C:0,O:0},this},t.prototype.merge=function(t,r,n){if("object"!=typeof t)throw new Error("merge: invalid AST node argument");"undefined"==typeof r&&(r=!1),"undefined"==typeof n&&(n={});var e=this;if(r){var o=t.pos();e.pos(o.L,o.C,o.O)}return t.attrs().forEach(function(r){var o="undefined"!=typeof n[r]?n[r]:r;null!==o&&e.set(o,t.get(r))}),t.childs().forEach(function(t){e.add(t)}),this},t.prototype.type=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")},t.prototype.pos=function(t,r,n){if(0===arguments.length)return this.P;if(arguments.length<=3)return this.P.L=t||0,this.P.C=r||0,this.P.O=n||0,this;throw new Error("pos: invalid number of arguments")},t.prototype.set=function(){if(1===arguments.length&&"object"==typeof arguments[0]){var t=this,r=arguments;Object.keys(r[0]).forEach(function(n){t.A[n]=r[0][n]})}else{if(2!==arguments.length)throw new Error("set: invalid arguments");this.A[arguments[0]]=arguments[1]}return this},t.prototype.get=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]},t.prototype.attrs=function(){return Object.keys(this.A)},t.prototype.add=function(){if(0===arguments.length)throw new Error("add: missing argument(s)");var t=function(t,r){if(!("object"==typeof r&&"string"==typeof r.T&&"object"==typeof r.P&&"object"==typeof r.A&&"object"==typeof r.C&&r.C instanceof Array))throw new Error("add: invalid AST node: "+JSON.stringify(r));t.push(r)};if(null!==arguments){var r=this;Array.prototype.slice.call(arguments,0).forEach(function(n){"object"==typeof n&&n instanceof Array?n.forEach(function(n){t(r.C,n)}):null!==n&&t(r.C,n)})}return this},t.prototype.del=function(){if(0===arguments.length)throw new Error("del: invalid argument");var t=this;return Array.prototype.slice.call(arguments,0).forEach(function(r){for(var n=!1,e=0;e<t.C.length;e++)if(t.C[e]===r){t.C.splice(e,1),n=!0;break}if(!n)throw new Error("del: child not found")}),this},t.prototype.childs=function(){return this.C},t.prototype.walk=function(t,r){"undefined"==typeof r&&(r="downward");var n=function(e,o,i){("downward"===r||"both"===r)&&t.call(null,e,o,i,"downward"),e.C.forEach(function(t){n(t,o+1,e)}),("upward"===r||"both"===r)&&t.call(null,e,o,i,"upward")};return n(this,0,null),this},t.prototype.dump=function(){var t="";return this.walk(function(r,n){for(var e=0;n>e;e++)t+=" ";t+=r.T+" ";var o=Object.keys(r.A);if(o.length>0){t+="(";var i=!0;o.forEach(function(n){i?i=!1:t+=", ",t+=n+": ";var e=r.A[n];switch(typeof e){case"string":t+='"'+e.replace(/\n/,"\\n").replace(/"/,'\\"')+'"';break;case"object":t+=e instanceof RegExp?"/"+e.toString().replace(/^\//,"").replace(/\/$/,"").replace(/\//g,"\\/")+"/":JSON.stringify(e);break;default:t+=JSON.stringify(e)}}),t+=") "}t+="["+r.P.L+"/"+r.P.C+"]\n"},"downward"),t},t}();module.exports=ASTYBase; | ||
"use strict";var _prototypeProperties=function(e,r,t){r&&Object.defineProperties(e,r),t&&Object.defineProperties(e.prototype,t)},ASTYBase=function(){function e(){}return _prototypeProperties(e,null,{init:{value:function(e){if("undefined"==typeof e)throw new Error("init: invalid argument");return this.T=e,this.A={},this.C=[],this.P={L:0,C:0,O:0},this},writable:!0,enumerable:!0,configurable:!0},merge:{value:function(e,r,t){if("object"!=typeof e)throw new Error("merge: invalid AST node argument");"undefined"==typeof r&&(r=!1),"undefined"==typeof t&&(t={});var n=this;if(r){var i=e.pos();n.pos(i.L,i.C,i.O)}return e.attrs().forEach(function(r){var i="undefined"!=typeof t[r]?t[r]:r;null!==i&&n.set(i,e.get(r))}),e.childs().forEach(function(e){n.add(e)}),this},writable:!0,enumerable:!0,configurable:!0},type:{value:function(e){if(0===arguments.length)return this.T;if(1===arguments.length)return this.T=e,this;throw new Error("type: invalid number of arguments")},writable:!0,enumerable:!0,configurable:!0},pos:{value:function(e,r,t){if(0===arguments.length)return this.P;if(arguments.length<=3)return this.P.L=e||0,this.P.C=r||0,this.P.O=t||0,this;throw new Error("pos: invalid number of arguments")},writable:!0,enumerable:!0,configurable:!0},set:{value:function(){if(1===arguments.length&&"object"==typeof arguments[0]){var e=this,r=arguments;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},writable:!0,enumerable:!0,configurable:!0},get:{value:function(e){if(1!==arguments.length)throw new Error("get: invalid number of arguments");if("string"!=typeof e)throw new Error("get: invalid argument");return this.A[e]},writable:!0,enumerable:!0,configurable:!0},attrs:{value:function(){return Object.keys(this.A)},writable:!0,enumerable:!0,configurable:!0},add:{value:function(){if(0===arguments.length)throw new Error("add: missing argument(s)");var e=function(e,r){if(!("object"==typeof r&&"string"==typeof r.T&&"object"==typeof r.P&&"object"==typeof r.A&&"object"==typeof r.C&&r.C instanceof Array))throw new Error("add: invalid AST node: "+JSON.stringify(r));e.push(r)};if(null!==arguments){var r=this;Array.prototype.slice.call(arguments,0).forEach(function(t){"object"==typeof t&&t instanceof Array?t.forEach(function(t){e(r.C,t)}):null!==t&&e(r.C,t)})}return this},writable:!0,enumerable:!0,configurable:!0},del:{value:function(){if(0===arguments.length)throw new Error("del: invalid argument");var e=this;return Array.prototype.slice.call(arguments,0).forEach(function(r){for(var t=!1,n=0;n<e.C.length;n++)if(e.C[n]===r){e.C.splice(n,1),t=!0;break}if(!t)throw new Error("del: child not found")}),this},writable:!0,enumerable:!0,configurable:!0},childs:{value:function(){return this.C},writable:!0,enumerable:!0,configurable:!0},walk:{value:function(e,r){"undefined"==typeof r&&(r="downward");var t=function(n,i,a){("downward"===r||"both"===r)&&e.call(null,n,i,a,"downward"),n.C.forEach(function(e){t(e,i+1,n)}),("upward"===r||"both"===r)&&e.call(null,n,i,a,"upward")};return t(this,0,null),this},writable:!0,enumerable:!0,configurable:!0}}),e}();module.exports=ASTYBase; | ||
},{}],2:[function(require,module,exports){ | ||
"use strict";var _prototypeProperties=function(e,r,t){r&&Object.defineProperties(e,r),t&&Object.defineProperties(e.prototype,t)},ASTYDump=function(){function e(){}return _prototypeProperties(e,null,{dump:{value:function(){var e="";return this.walk(function(r,t){for(var n=0;t>n;n++)e+=" ";e+=r.T+" ";var o=Object.keys(r.A);if(o.length>0){e+="(";var i=!0;o.forEach(function(t){i?i=!1:e+=", ",e+=t+": ";var n=r.A[t];switch(typeof n){case"string":e+='"'+n.replace(/\n/,"\\n").replace(/"/,'\\"')+'"';break;case"object":e+=n instanceof RegExp?"/"+n.toString().replace(/^\//,"").replace(/\/$/,"").replace(/\//g,"\\/")+"/":JSON.stringify(n);break;default:e+=JSON.stringify(n)}}),e+=") "}e+="["+r.P.L+"/"+r.P.C+"]\n"},"downward"),e},writable:!0,enumerable:!0,configurable:!0}}),e}();module.exports=ASTYDump; | ||
},{}],3:[function(require,module,exports){ | ||
"use strict";module.exports=function(){for(var t=function(){},r=0;r<arguments.length;r++){var o=arguments[r];"function"==typeof o&&(o=o.prototype);for(var e in o)Object.prototype.hasOwnProperty.call(o,e)&&(t.prototype[e]=o[e])}return t}; | ||
},{}],3:[function(require,module,exports){ | ||
"use strict";var _extends=function(e,t){e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),e.__proto__=t},ASTYBase=require("./asty-base.js"),mixins=require("./asty-mixins.js"),ASTY=function(e){var t=function r(){if(this instanceof r)return this.init.apply(this,arguments);var e=new r("");return e.init.apply(e,arguments)};return _extends(t,e),t}(mixins(ASTYBase));module.exports=ASTY; | ||
},{"./asty-base.js":1,"./asty-mixins.js":2}]},{},[1,2,3])(3) | ||
},{}],4:[function(require,module,exports){ | ||
"use strict";var ASTQuery=function(){};module.exports=ASTQuery; | ||
},{}],5:[function(require,module,exports){ | ||
"use strict";var _inherits=function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(e.__proto__=r)},ASTYBase=require("./asty-base.js"),ASTYQuery=require("./asty-query.js"),mixins=require("./asty-mixins.js"),ASTY=function(e){function r(){if(this instanceof r)return this.init.apply(this,arguments);var e=new r("");return e.init.apply(e,arguments)}return _inherits(r,e),r}(mixins(ASTYBase,ASTYQuery));module.exports=ASTY; | ||
},{"./asty-base.js":1,"./asty-mixins.js":3,"./asty-query.js":4}]},{},[1,2,3,4,5])(5) | ||
}); | ||
@@ -34,0 +38,0 @@ |
{ | ||
"name": "asty", | ||
"version": "0.9.1", | ||
"version": "0.9.2", | ||
"description": "Generic Abstract Syntax Tree (AST)", | ||
@@ -27,7 +27,7 @@ "keywords": [ "ast", "abstract", "syntax", "tree" ], | ||
"grunt-contrib-clean": "~0.6.0", | ||
"grunt-browserify": "~3.2.1", | ||
"6to5ify": "~2.0.0", | ||
"minifyify": "~4.4.0", | ||
"grunt-browserify": "~3.3.0", | ||
"6to5ify": "~3.1.2", | ||
"minifyify": "~5.0.0", | ||
"browserify-header": "~0.9.0" | ||
} | ||
} |
@@ -104,3 +104,3 @@ | ||
Copyright (c) 2014 Ralf S. Engelschall (http://engelschall.com/) | ||
Copyright (c) 2014-2015 Ralf S. Engelschall (http://engelschall.com/) | ||
@@ -107,0 +107,0 @@ Permission is hereby granted, free of charge, to any person obtaining |
/* | ||
** ASTy -- Generic Abstract Syntax Tree (AST) | ||
** Copyright (c) 2014 Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2015 Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -180,47 +180,2 @@ ** Permission is hereby granted, free of charge, to any person obtaining | ||
} | ||
/* dump the AST recursively */ | ||
dump () { | ||
var out = "" | ||
this.walk(function (node, depth /*, parent, when */) { | ||
for (var i = 0; i < depth; i++) | ||
out += " " | ||
out += node.T + " " | ||
var keys = Object.keys(node.A) | ||
if (keys.length > 0) { | ||
out += "(" | ||
var first = true | ||
keys.forEach(function (key) { | ||
if (!first) | ||
out += ", " | ||
else | ||
first = false | ||
out += key + ": " | ||
var value = node.A[key] | ||
switch (typeof value) { | ||
case "string": | ||
out += "\"" + value.replace(/\n/, "\\n").replace(/"/, "\\\"") + "\"" | ||
break | ||
case "object": | ||
if (value instanceof RegExp) | ||
out += "/" + | ||
value.toString() | ||
.replace(/^\//, "") | ||
.replace(/\/$/, "") | ||
.replace(/\//g, "\\/") + | ||
"/" | ||
else | ||
out += JSON.stringify(value) | ||
break | ||
default: | ||
out += JSON.stringify(value) | ||
break | ||
} | ||
}) | ||
out += ") " | ||
} | ||
out += "[" + node.P.L + "/" + node.P.C + "]\n" | ||
}, "downward") | ||
return out | ||
} | ||
} | ||
@@ -227,0 +182,0 @@ |
/* | ||
** ASTy -- Generic Abstract Syntax Tree (AST) | ||
** Copyright (c) 2014 Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2015 Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -5,0 +5,0 @@ ** Permission is hereby granted, free of charge, to any person obtaining |
/* | ||
** ASTy -- Generic Abstract Syntax Tree (AST) | ||
** Copyright (c) 2014 Ralf S. Engelschall <rse@engelschall.com> | ||
** Copyright (c) 2014-2015 Ralf S. Engelschall <rse@engelschall.com> | ||
** | ||
@@ -25,6 +25,7 @@ ** Permission is hereby granted, free of charge, to any person obtaining | ||
var ASTYBase = require("./asty-base.js"); | ||
var mixins = require("./asty-mixins.js"); | ||
var ASTYBase = require("./asty-base.js"); | ||
var ASTYQuery = require("./asty-query.js"); | ||
var mixins = require("./asty-mixins.js"); | ||
var ASTY = class ASTY extends mixins(ASTYBase) { | ||
var ASTY = class ASTY extends mixins(ASTYBase, ASTYQuery) { | ||
constructor () { | ||
@@ -31,0 +32,0 @@ if (!(this instanceof ASTY)) { |
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
51346
14
508