├── .gitignore ├── README.md ├── lib ├── helpers │ └── polyfills │ │ ├── index.js │ │ ├── Array.forEach.js │ │ └── Array.map.js └── index.js ├── tests ├── data │ └── script.js └── anatomia.spec.js ├── gulpfile.js ├── package.json ├── LICENSE └── npm-debug.log /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # anatomia 2 | Smart JavaScript analyzer 3 | -------------------------------------------------------------------------------- /lib/helpers/polyfills/index.js: -------------------------------------------------------------------------------- 1 | require('./Array.map'); 2 | require('./Array.forEach'); -------------------------------------------------------------------------------- /tests/data/script.js: -------------------------------------------------------------------------------- 1 | var character = 'Jon Snow'; 2 | @import test 3 | var kingsLanding = function () { 4 | return 'The capital of the Seven Kingdoms'; 5 | } -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | require('./helpers/polyfills'); 2 | 3 | var acorn = require("acorn"); 4 | 5 | module.exports = function () { 6 | var api = {}; 7 | 8 | api.parse = function (code) { 9 | var ast = acorn.parse(code); 10 | console.log(ast); 11 | }; 12 | 13 | return api; 14 | }; -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var shell = require('gulp-shell'); 3 | var gutil = require('gulp-util'); 4 | var exec = require('child_process').exec; 5 | 6 | gulp.task('watchers', function () { 7 | gulp.watch('./node_modules/acorn/src/**/*.js').on('change', compileAcorn) 8 | }); 9 | 10 | var compileAcorn = function () { 11 | gutil.log('Compiling acorn'); 12 | exec( 13 | 'npm run prepublish', 14 | { cwd: './node_modules/acorn' }, 15 | function(error, stdout, stderr) { 16 | gutil.log(stdout); 17 | } 18 | ); 19 | }; 20 | 21 | gulp.task('default', ['watchers']); 22 | compileAcorn(); -------------------------------------------------------------------------------- /tests/anatomia.spec.js: -------------------------------------------------------------------------------- 1 | 2 | var fs = require('fs'); 3 | var chai = require('chai'); 4 | var expect = chai.expect; 5 | 6 | var anatomia; 7 | 8 | var getFileContent = function (file) { 9 | return fs.readFileSync(file).toString('utf8'); 10 | } 11 | 12 | suite('Basics', function() { 13 | 14 | beforeEach(function () { 15 | anatomia = require('../lib')(); 16 | }); 17 | 18 | test.only('Using a middleware', function () { 19 | var script = "var something = 10; var answer/Validate/ = 'Jon Snow';\ 20 | function test() { return 20; };\ 21 | "; 22 | var result = anatomia.parse(script); 23 | }); 24 | 25 | }); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "anatomia", 3 | "version": "0.0.2", 4 | "description": "Smart JavaScript analyzer", 5 | "main": "", 6 | "author": { 7 | "name": "Krasimir Tsonev", 8 | "email": "info@krasimirtsonev.com", 9 | "url": "http://krasimirtsonev.com" 10 | }, 11 | "license": "MIT", 12 | "dependencies": { 13 | "acorn": "2.0.4" 14 | }, 15 | "devDependencies": { 16 | "chai": "3.0.0", 17 | "gulp": "3.9.0", 18 | "gulp-shell": "0.4.2", 19 | "gulp-util": "^3.0.6", 20 | "jshint": "2.5.10", 21 | "mocha": "2.0.1" 22 | }, 23 | "keywords": [ 24 | "ast", 25 | "analyze", 26 | "anatomy", 27 | "architecture" 28 | ], 29 | "repository": { 30 | "type": "git", 31 | "url": "https://github.com/krasimir/anatomia.git" 32 | }, 33 | "scripts": { 34 | "test": "./node_modules/mocha/bin/mocha --ui tdd --recursive ./tests/*.spec.js && (./node_modules/jshint/bin/jshint lib/ ; echo)" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Krasimir Tsonev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /npm-debug.log: -------------------------------------------------------------------------------- 1 | 0 info it worked if it ends with ok 2 | 1 verbose cli [ 'node', '/usr/local/bin/npm', 'run', 'prepublish' ] 3 | 2 info using npm@2.7.1 4 | 3 info using node@v0.12.0 5 | 4 verbose stack Error: missing script: prepublish 6 | 4 verbose stack at run (/usr/local/lib/node_modules/npm/lib/run-script.js:165:19) 7 | 4 verbose stack at /usr/local/lib/node_modules/npm/lib/run-script.js:81:5 8 | 4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:52:40 9 | 4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:376:33 10 | 4 verbose stack at checkBinReferences_ (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:341:59) 11 | 4 verbose stack at final (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:373:17) 12 | 4 verbose stack at then (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:127:33) 13 | 4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:332:40 14 | 4 verbose stack at evalmachine.:336:14 15 | 4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:102:5 16 | 5 verbose cwd /Users/krasimir/Work/Krasimir/anatomia 17 | 6 error Darwin 14.4.0 18 | 7 error argv "node" "/usr/local/bin/npm" "run" "prepublish" 19 | 8 error node v0.12.0 20 | 9 error npm v2.7.1 21 | 10 error missing script: prepublish 22 | 11 error If you need help, you may report this error at: 23 | 11 error 24 | 12 verbose exit [ 1, true ] 25 | -------------------------------------------------------------------------------- /lib/helpers/polyfills/Array.forEach.js: -------------------------------------------------------------------------------- 1 | // Production steps of ECMA-262, Edition 5, 15.4.4.18 2 | // Reference: http://es5.github.io/#x15.4.4.18 3 | if (!Array.prototype.forEach) { 4 | 5 | Array.prototype.forEach = function(callback, thisArg) { 6 | 7 | var T, k; 8 | 9 | if (this === null) { 10 | throw new TypeError(' this is null or not defined'); 11 | } 12 | 13 | // 1. Let O be the result of calling ToObject passing the |this| value as the argument. 14 | var O = Object(this); 15 | 16 | // 2. Let lenValue be the result of calling the Get internal method of O with the argument "length". 17 | // 3. Let len be ToUint32(lenValue). 18 | var len = O.length >>> 0; 19 | 20 | // 4. If IsCallable(callback) is false, throw a TypeError exception. 21 | // See: http://es5.github.com/#x9.11 22 | if (typeof callback !== "function") { 23 | throw new TypeError(callback + ' is not a function'); 24 | } 25 | 26 | // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. 27 | if (arguments.length > 1) { 28 | T = thisArg; 29 | } 30 | 31 | // 6. Let k be 0 32 | k = 0; 33 | 34 | // 7. Repeat, while k < len 35 | while (k < len) { 36 | 37 | var kValue; 38 | 39 | // a. Let Pk be ToString(k). 40 | // This is implicit for LHS operands of the in operator 41 | // b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk. 42 | // This step can be combined with c 43 | // c. If kPresent is true, then 44 | if (k in O) { 45 | 46 | // i. Let kValue be the result of calling the Get internal method of O with argument Pk. 47 | kValue = O[k]; 48 | 49 | // ii. Call the Call internal method of callback with T as the this value and 50 | // argument list containing kValue, k, and O. 51 | callback.call(T, kValue, k, O); 52 | } 53 | // d. Increase k by 1. 54 | k++; 55 | } 56 | // 8. return undefined 57 | }; 58 | } -------------------------------------------------------------------------------- /lib/helpers/polyfills/Array.map.js: -------------------------------------------------------------------------------- 1 | // Production steps of ECMA-262, Edition 5, 15.4.4.19 2 | // Reference: http://es5.github.io/#x15.4.4.19 3 | if (!Array.prototype.map) { 4 | 5 | Array.prototype.map = function(callback, thisArg) { 6 | 7 | var T, A, k; 8 | 9 | if (this === null) { 10 | throw new TypeError(' this is null or not defined'); 11 | } 12 | 13 | // 1. Let O be the result of calling ToObject passing the |this| 14 | // value as the argument. 15 | var O = Object(this); 16 | 17 | // 2. Let lenValue be the result of calling the Get internal 18 | // method of O with the argument "length". 19 | // 3. Let len be ToUint32(lenValue). 20 | var len = O.length >>> 0; 21 | 22 | // 4. If IsCallable(callback) is false, throw a TypeError exception. 23 | // See: http://es5.github.com/#x9.11 24 | if (typeof callback !== 'function') { 25 | throw new TypeError(callback + ' is not a function'); 26 | } 27 | 28 | // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. 29 | if (arguments.length > 1) { 30 | T = thisArg; 31 | } 32 | 33 | // 6. Let A be a new array created as if by the expression new Array(len) 34 | // where Array is the standard built-in constructor with that name and 35 | // len is the value of len. 36 | A = new Array(len); 37 | 38 | // 7. Let k be 0 39 | k = 0; 40 | 41 | // 8. Repeat, while k < len 42 | while (k < len) { 43 | 44 | var kValue, mappedValue; 45 | 46 | // a. Let Pk be ToString(k). 47 | // This is implicit for LHS operands of the in operator 48 | // b. Let kPresent be the result of calling the HasProperty internal 49 | // method of O with argument Pk. 50 | // This step can be combined with c 51 | // c. If kPresent is true, then 52 | if (k in O) { 53 | 54 | // i. Let kValue be the result of calling the Get internal 55 | // method of O with argument Pk. 56 | kValue = O[k]; 57 | 58 | // ii. Let mappedValue be the result of calling the Call internal 59 | // method of callback with T as the this value and argument 60 | // list containing kValue, k, and O. 61 | mappedValue = callback.call(T, kValue, k, O); 62 | 63 | // iii. Call the DefineOwnProperty internal method of A with arguments 64 | // Pk, Property Descriptor 65 | // { Value: mappedValue, 66 | // Writable: true, 67 | // Enumerable: true, 68 | // Configurable: true }, 69 | // and false. 70 | 71 | // In browsers that support Object.defineProperty, use the following: 72 | // Object.defineProperty(A, k, { 73 | // value: mappedValue, 74 | // writable: true, 75 | // enumerable: true, 76 | // configurable: true 77 | // }); 78 | 79 | // For best browser support, use the following: 80 | A[k] = mappedValue; 81 | } 82 | // d. Increase k by 1. 83 | k++; 84 | } 85 | 86 | // 9. return A 87 | return A; 88 | }; 89 | } --------------------------------------------------------------------------------