Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "asty", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Abstract Syntax Tree (AST) Data Structure", | ||
@@ -5,0 +5,0 @@ "main": "lib/asty.browser.js", |
@@ -37,4 +37,5 @@ /* | ||
}, | ||
"gruntfile": [ "Gruntfile.js" ], | ||
"asty": [ "src/**/*.js" ] | ||
"gruntfile": [ "Gruntfile.js" ], | ||
"asty-src": [ "src/**/*.js" ], | ||
"asty-tst": [ "tst/**/*.js" ] | ||
}, | ||
@@ -78,7 +79,6 @@ browserify: { | ||
"asty": { | ||
src: [ "tst/*.js", "!tst/common.js" ] | ||
src: [ "tst/*.js" ] | ||
}, | ||
options: { | ||
reporter: "spec", | ||
require: "tst/common.js" | ||
reporter: "spec" | ||
} | ||
@@ -92,5 +92,4 @@ }, | ||
grunt.registerTask("default", [ "jshint", "browserify" ]); | ||
grunt.registerTask("test", [ "mochaTest" ]); | ||
grunt.registerTask("default", [ "jshint", "browserify", "mochaTest" ]); | ||
}; | ||
@@ -26,11 +26,11 @@ /* | ||
!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(_dereq_,module,exports){ | ||
"use strict";var _prototypeProperties=function(t,e,r){e&&Object.defineProperties(t,e),r&&Object.defineProperties(t.prototype,r)},ASTYBase=function(){function t(){}return _prototypeProperties(t,null,{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},writable:!0,configurable:!0},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")},writable:!0,configurable:!0},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")},writable:!0,configurable:!0},set:{value:function(){var t=this,e=arguments;if(1===arguments.length&&"object"==typeof arguments[0])!function(){var r=e;Object.keys(r[0]).forEach(function(e){t.A[e]=r[0][e]})}();else{if(2!==arguments.length)throw new Error("set: invalid arguments");this.A[arguments[0]]=arguments[1]}return this},writable:!0,configurable:!0},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]},writable:!0,configurable:!0},attrs:{value:function(){return Object.keys(this.A)},writable:!0,configurable:!0},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},writable:!0,configurable:!0},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},writable:!0,configurable:!0},childs:{value:function(){return this.C},writable:!0,configurable:!0},parent:{value:function(){return this.P},writable:!0,configurable:!0}}),t}();module.exports=ASTYBase; | ||
"use strict";var _prototypeProperties=function(t,e,r){e&&Object.defineProperties(t,e),r&&Object.defineProperties(t.prototype,r)},_classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},ASTYBase=function(){function t(){_classCallCheck(this,t)}return _prototypeProperties(t,null,{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},writable:!0,configurable:!0},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")},writable:!0,configurable:!0},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")},writable:!0,configurable:!0},set:{value:function(){var t=this,e=arguments;if(1===arguments.length&&"object"==typeof arguments[0])!function(){var r=e;Object.keys(r[0]).forEach(function(e){t.A[e]=r[0][e]})}();else{if(2!==arguments.length)throw new Error("set: invalid arguments");this.A[arguments[0]]=arguments[1]}return this},writable:!0,configurable:!0},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]},writable:!0,configurable:!0},attrs:{value:function(){return Object.keys(this.A)},writable:!0,configurable:!0},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},writable:!0,configurable:!0},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},writable:!0,configurable:!0},childs:{value:function(){return this.C},writable:!0,configurable:!0},parent:{value:function(){return this.P},writable:!0,configurable:!0}}),t}();module.exports=ASTYBase; | ||
},{}],2:[function(_dereq_,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(e){void 0===e&&(e=1/0);var r="";return this.walk(function(t,n){if(!(n>e)){for(var o=0;n>o;o++)r+=" ";r+=t.T+" ";var i=Object.keys(t.A);i.length>0&&!function(){r+="(";var e=!0;i.forEach(function(n){e?e=!1:r+=", ",r+=n+": ";var o=t.A[n];switch(typeof o){case"string":r+='"'+o.replace(/\n/,"\\n").replace(/"/,'\\"')+'"';break;case"object":r+=o instanceof RegExp?"/"+o.toString().replace(/^\//,"").replace(/\/$/,"").replace(/\//g,"\\/")+"/":JSON.stringify(o);break;default:r+=JSON.stringify(o)}}),r+=") "}(),r+="["+t.L.L+"/"+t.L.C+"]\n"}},"downward"),r},writable:!0,configurable:!0}}),e}();module.exports=ASTYDump; | ||
"use strict";var _prototypeProperties=function(e,t,r){t&&Object.defineProperties(e,t),r&&Object.defineProperties(e.prototype,r)},_classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},ASTYDump=function(){function e(){_classCallCheck(this,e)}return _prototypeProperties(e,null,{dump:{value:function(e){void 0===e&&(e=1/0);var t="";return this.walk(function(r,n){if(!(n>e)){for(var a=0;n>a;a++)t+=" ";t+=r.T+" ";var o=Object.keys(r.A);o.length>0&&!function(){t+="(";var e=!0;o.forEach(function(n){e?e=!1:t+=", ",t+=n+": ";var a=r.A[n];switch(typeof a){case"string":t+='"'+a.replace(/\n/,"\\n").replace(/"/,'\\"')+'"';break;case"object":t+=a instanceof RegExp?"/"+a.toString().replace(/^\//,"").replace(/\/$/,"").replace(/\//g,"\\/")+"/":JSON.stringify(a);break;default:t+=JSON.stringify(a)}}),t+=") "}(),t+="["+r.L.L+"/"+r.L.C+"]\n"}},"downward"),t},writable:!0,configurable:!0}}),e}();module.exports=ASTYDump; | ||
},{}],3:[function(_dereq_,module,exports){ | ||
"use strict";var _prototypeProperties=function(e,t,r){t&&Object.defineProperties(e,t),r&&Object.defineProperties(e.prototype,r)},ASTYMerge=function(){function e(){}return _prototypeProperties(e,null,{merge:{value:function(e,t,r){var o=this;if("object"!=typeof e)throw new Error("merge: invalid AST node argument");if("undefined"==typeof t&&(t=!1),"undefined"==typeof r&&(r={}),t){var n=e.pos();this.pos(n.L,n.C,n.O)}return e.attrs().forEach(function(t){var n="undefined"!=typeof r[t]?r[t]:t;null!==n&&o.set(n,e.get(t))}),e.childs().forEach(function(e){o.add(e)}),this},writable:!0,configurable:!0}}),e}();module.exports=ASTYMerge; | ||
"use strict";var _prototypeProperties=function(e,t,r){t&&Object.defineProperties(e,t),r&&Object.defineProperties(e.prototype,r)},_classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},ASTYMerge=function(){function e(){_classCallCheck(this,e)}return _prototypeProperties(e,null,{merge:{value:function(e,t,r){var n=this;if("object"!=typeof e)throw new Error("merge: invalid AST node argument");if("undefined"==typeof t&&(t=!1),"undefined"==typeof r&&(r={}),t){var o=e.pos();this.pos(o.L,o.C,o.O)}return e.attrs().forEach(function(t){var o="undefined"!=typeof r[t]?r[t]:t;null!==o&&n.set(o,e.get(t))}),e.childs().forEach(function(e){n.add(e)}),this},writable:!0,configurable:!0}}),e}();module.exports=ASTYMerge; | ||
},{}],4:[function(_dereq_,module,exports){ | ||
"use strict";var _prototypeProperties=function(t,e,r){e&&Object.defineProperties(t,e),r&&Object.defineProperties(t.prototype,r)},ASTYWalk=function(){function t(){}return _prototypeProperties(t,null,{walk:{value:function(t,e){"undefined"==typeof e&&(e="downward");var r=function(n,o,l){("downward"===e||"both"===e)&&t.call(null,n,o,l,"downward"),n.C.forEach(function(t){r(t,o+1,n)}),("upward"===e||"both"===e)&&t.call(null,n,o,l,"upward")};return r(this,0,null),this},writable:!0,configurable:!0}}),t}();module.exports=ASTYWalk; | ||
"use strict";var _prototypeProperties=function(n,t,e){t&&Object.defineProperties(n,t),e&&Object.defineProperties(n.prototype,e)},_classCallCheck=function(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function")},ASTYWalk=function(){function n(){_classCallCheck(this,n)}return _prototypeProperties(n,null,{walk:{value:function(n,t){"undefined"==typeof t&&(t="downward");var e=function(o,r,l){("downward"===t||"both"===t)&&n.call(null,o,r,l,"downward"),o.C.forEach(function(n){e(n,r+1,o)}),("upward"===t||"both"===t)&&n.call(null,o,r,l,"upward")};return e(this,0,null),this},writable:!0,configurable:!0}}),n}();module.exports=ASTYWalk; | ||
},{}],5:[function(_dereq_,module,exports){ | ||
"use strict";var _prototypeProperties=function(e,t,r){t&&Object.defineProperties(e,t),r&&Object.defineProperties(e.prototype,r)},ASTYBase=_dereq_("./asty-base.js"),ASTYMerge=_dereq_("./asty-merge.js"),ASTYWalk=_dereq_("./asty-walk.js"),ASTYDump=_dereq_("./asty-dump.js"),ASTYCtx=function(){function e(){var t=this;if(!(this instanceof e))return new e;this.ASTYNode=function(){};var r=[[ASTYBase,"init","type","pos","set","get","attrs","add","del","childs","parent"],[ASTYMerge,"merge"],[ASTYWalk,"walk"],[ASTYDump,"dump"]];return r.forEach(function(e){var r=e[0].prototype;e.slice(1).forEach(function(e){t.ASTYNode.prototype[e]=r[e]})}),this}return _prototypeProperties(e,null,{extend:{value:function(e){for(var t in e)e.hasOwnProperty(t)&&(this.ASTYNode.prototype[t]=e[t]);return this},writable:!0,configurable:!0},create:{value:function(e){return(new this.ASTYNode).init(e)},writable:!0,configurable:!0},isA:{value:function(e){return"object"==typeof e&&e instanceof this.ASTYNode&&"boolean"==typeof e.ASTy&&e.ASTy===!0},writable:!0,configurable:!0}}),e}();module.exports=ASTYCtx; | ||
"use strict";var _prototypeProperties=function(e,t,r){t&&Object.defineProperties(e,t),r&&Object.defineProperties(e.prototype,r)},_classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},ASTYBase=_dereq_("./asty-base.js"),ASTYMerge=_dereq_("./asty-merge.js"),ASTYWalk=_dereq_("./asty-walk.js"),ASTYDump=_dereq_("./asty-dump.js"),ASTYCtx=function(){function e(){var t=this;_classCallCheck(this,e),this.ASTYNode=function(){};var r=[[ASTYBase,"init","type","pos","set","get","attrs","add","del","childs","parent"],[ASTYMerge,"merge"],[ASTYWalk,"walk"],[ASTYDump,"dump"]];return r.forEach(function(e){var r=e[0].prototype;e.slice(1).forEach(function(e){t.ASTYNode.prototype[e]=r[e]})}),this}return _prototypeProperties(e,null,{extend:{value:function(e){for(var t in e)e.hasOwnProperty(t)&&(this.ASTYNode.prototype[t]=e[t]);return this},writable:!0,configurable:!0},create:{value:function(e){return(new this.ASTYNode).init(e)},writable:!0,configurable:!0},isA:{value:function(e){return"object"==typeof e&&e instanceof this.ASTYNode&&"boolean"==typeof e.ASTy&&e.ASTy===!0},writable:!0,configurable:!0}}),e}();module.exports=ASTYCtx; | ||
},{"./asty-base.js":1,"./asty-dump.js":2,"./asty-merge.js":3,"./asty-walk.js":4}]},{},[1,2,3,4,5])(5) | ||
@@ -37,0 +37,0 @@ }); |
@@ -30,2 +30,4 @@ /* | ||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; | ||
/* | ||
@@ -56,3 +58,5 @@ ** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
var ASTYBase = (function () { | ||
function ASTYBase() {} | ||
function ASTYBase() { | ||
_classCallCheck(this, ASTYBase); | ||
} | ||
@@ -222,2 +226,4 @@ _prototypeProperties(ASTYBase, null, { | ||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; | ||
/* | ||
@@ -248,3 +254,5 @@ ** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
var ASTYDump = (function () { | ||
function ASTYDump() {} | ||
function ASTYDump() { | ||
_classCallCheck(this, ASTYDump); | ||
} | ||
@@ -305,2 +313,4 @@ _prototypeProperties(ASTYDump, null, { | ||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; | ||
/* | ||
@@ -331,3 +341,5 @@ ** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
var ASTYMerge = (function () { | ||
function ASTYMerge() {} | ||
function ASTYMerge() { | ||
_classCallCheck(this, ASTYMerge); | ||
} | ||
@@ -370,2 +382,4 @@ _prototypeProperties(ASTYMerge, null, { | ||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; | ||
/* | ||
@@ -396,3 +410,5 @@ ** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
var ASTYWalk = (function () { | ||
function ASTYWalk() {} | ||
function ASTYWalk() { | ||
_classCallCheck(this, ASTYWalk); | ||
} | ||
@@ -429,2 +445,4 @@ _prototypeProperties(ASTYWalk, null, { | ||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; | ||
/* | ||
@@ -462,3 +480,4 @@ ** ASTy -- Abstract Syntax Tree (AST) Data Structure | ||
var _this = this; | ||
if (!(this instanceof ASTYCtx)) return new ASTYCtx(); | ||
_classCallCheck(this, ASTYCtx); | ||
this.ASTYNode = function () {}; | ||
@@ -465,0 +484,0 @@ var mixins = [[ASTYBase, "init", "type", "pos", "set", "get", "attrs", "add", "del", "childs", "parent"], [ASTYMerge, "merge"], [ASTYWalk, "walk"], [ASTYDump, "dump"]]; |
{ | ||
"name": "asty", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Abstract Syntax Tree (AST) Data Structure", | ||
@@ -30,3 +30,3 @@ "keywords": [ "ast", "abstract", "syntax", "tree", "data", "structure" ], | ||
"chai": "~1.10.0", | ||
"6to5ify": "~4.0.0", | ||
"6to5ify": "~4.1.0", | ||
"minifyify": "~6.1.0", | ||
@@ -33,0 +33,0 @@ "browserify-header": "~0.9.1", |
@@ -25,11 +25,9 @@ /* | ||
let ASTYBase = require("./asty-base.js"); | ||
let ASTYMerge = require("./asty-merge.js"); | ||
let ASTYWalk = require("./asty-walk.js"); | ||
let ASTYDump = require("./asty-dump.js"); | ||
let ASTYBase = require("./asty-base.js") | ||
let ASTYMerge = require("./asty-merge.js") | ||
let ASTYWalk = require("./asty-walk.js") | ||
let ASTYDump = require("./asty-dump.js") | ||
let ASTYCtx = class ASTYCtx { | ||
constructor () { | ||
if (!(this instanceof ASTYCtx)) | ||
return new ASTYCtx() | ||
this.ASTYNode = () => {} | ||
@@ -36,0 +34,0 @@ let mixins = [ |
@@ -25,9 +25,16 @@ /* | ||
var ASTy = require("../lib/asty.node.js"); | ||
/* global describe: false */ | ||
/* global it: false */ | ||
var chai = require("chai") | ||
var expect = chai.expect | ||
chai.config.includeStack = true | ||
var ASTy = require("../lib/asty.node.js") | ||
describe("ASTy Library", function () { | ||
it("node base functionality", function () { | ||
var asty = new ASTy(); | ||
var node = asty.create("foo"); | ||
expect(asty.isA(node)).to.be.true | ||
var asty = new ASTy() | ||
var node = asty.create("foo") | ||
expect(asty.isA(node)).to.be.true() | ||
expect(node).to.be.a("object") | ||
@@ -40,8 +47,8 @@ expect(node).to.include.keys("T", "L", "A", "P", "C") | ||
it("node tree structure", function () { | ||
var asty = new ASTy(); | ||
var node1 = asty.create("1"); | ||
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"); | ||
var asty = new ASTy() | ||
var node1 = asty.create("1") | ||
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) | ||
@@ -57,3 +64,3 @@ node12.add(node121, node122) | ||
it("node extension functionality", function () { | ||
var asty = new ASTy(); | ||
var asty = new ASTy() | ||
asty.extend({ | ||
@@ -64,8 +71,8 @@ foo: function (arg) { | ||
}) | ||
var node = asty.create("foo"); | ||
var node = asty.create("foo") | ||
expect(node).to.be.a("object") | ||
expect(node).to.respondTo("foo") | ||
expect(node.foo("bar")).to.be.equal("<bar>"); | ||
expect(node.foo("bar")).to.be.equal("<bar>") | ||
}) | ||
}) | ||
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
83409
16
1112