first commit
This commit is contained in:
8
build/node_modules/astw/.travis.yml
generated
vendored
Normal file
8
build/node_modules/astw/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.8"
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
- "iojs"
|
||||
before_install:
|
||||
- npm install -g npm@~1.4.6
|
||||
18
build/node_modules/astw/LICENSE
generated
vendored
Normal file
18
build/node_modules/astw/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
This software is released under the MIT license:
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
8
build/node_modules/astw/example/types.js
generated
vendored
Normal file
8
build/node_modules/astw/example/types.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
var astw = require('../');
|
||||
var deparse = require('escodegen').generate;
|
||||
var walk = astw('4 + beep(5 * 2)');
|
||||
|
||||
walk(function (node) {
|
||||
var src = deparse(node);
|
||||
console.log(node.type + ' :: ' + JSON.stringify(src));
|
||||
});
|
||||
52
build/node_modules/astw/index.js
generated
vendored
Normal file
52
build/node_modules/astw/index.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
var parse = require('acorn').parse;
|
||||
|
||||
module.exports = function (src, opts) {
|
||||
if (!opts) opts = {}
|
||||
var ast = src;
|
||||
if (typeof src === 'string') {
|
||||
try {
|
||||
ast = parse(src, {
|
||||
ecmaVersion: opts.ecmaVersion || 8,
|
||||
allowReturnOutsideFunction: true
|
||||
})
|
||||
}
|
||||
catch (err) { ast = parse('(' + src + ')') }
|
||||
}
|
||||
return function (cb) {
|
||||
walk(ast, undefined, cb);
|
||||
};
|
||||
};
|
||||
|
||||
function walk (node, parent, cb) {
|
||||
var keys = objectKeys(node);
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var key = keys[i];
|
||||
if (key === 'parent') continue;
|
||||
|
||||
var child = node[key];
|
||||
if (isArray(child)) {
|
||||
for (var j = 0; j < child.length; j++) {
|
||||
var c = child[j];
|
||||
if (c && typeof c.type === 'string') {
|
||||
c.parent = node;
|
||||
walk(c, node, cb);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (child && typeof child.type === 'string') {
|
||||
child.parent = node;
|
||||
walk(child, node, cb);
|
||||
}
|
||||
}
|
||||
cb(node);
|
||||
}
|
||||
|
||||
var isArray = Array.isArray || function (xs) {
|
||||
return Object.prototype.toString.call(xs) === '[object Array]';
|
||||
};
|
||||
|
||||
var objectKeys = Object.keys || function (obj) {
|
||||
var keys = [];
|
||||
for (var key in obj) keys.push(key);
|
||||
return keys;
|
||||
};
|
||||
73
build/node_modules/astw/package.json
generated
vendored
Normal file
73
build/node_modules/astw/package.json
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
{
|
||||
"_from": "astw@^2.0.0",
|
||||
"_id": "astw@2.2.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-e9QXhNMkk5h66yOba04cV6hzuRc=",
|
||||
"_location": "/astw",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "astw@^2.0.0",
|
||||
"name": "astw",
|
||||
"escapedName": "astw",
|
||||
"rawSpec": "^2.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^2.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/lexical-scope"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/astw/-/astw-2.2.0.tgz",
|
||||
"_shasum": "7bd41784d32493987aeb239b6b4e1c57a873b917",
|
||||
"_spec": "astw@^2.0.0",
|
||||
"_where": "/Users/asciidisco/Desktop/asciidisco.com/build/node_modules/lexical-scope",
|
||||
"author": {
|
||||
"name": "James Halliday",
|
||||
"email": "mail@substack.net",
|
||||
"url": "http://substack.net"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/substack/astw/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"acorn": "^4.0.3"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "walk the ast with references to parent nodes",
|
||||
"devDependencies": {
|
||||
"escodegen": "~0.0.17",
|
||||
"tape": "~2.4.1"
|
||||
},
|
||||
"homepage": "https://github.com/substack/astw",
|
||||
"keywords": [
|
||||
"ast",
|
||||
"walk",
|
||||
"source",
|
||||
"acorn"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "astw",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/substack/astw.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tape test/*.js"
|
||||
},
|
||||
"testling": {
|
||||
"files": "test/*.js",
|
||||
"browsers": [
|
||||
"ie/6..latest",
|
||||
"chrome/20..latest",
|
||||
"firefox/10..latest",
|
||||
"safari/latest",
|
||||
"opera/11.0..latest",
|
||||
"iphone/6",
|
||||
"ipad/6"
|
||||
]
|
||||
},
|
||||
"version": "2.2.0"
|
||||
}
|
||||
56
build/node_modules/astw/readme.markdown
generated
vendored
Normal file
56
build/node_modules/astw/readme.markdown
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
# astw
|
||||
|
||||
walk the ast
|
||||
|
||||
[](http://ci.testling.com/substack/astw)
|
||||
|
||||
[](http://travis-ci.org/substack/astw)
|
||||
|
||||
This module is a faster version of
|
||||
[falafel](https://github.com/substack/node-falafel)
|
||||
that only does ast walking and `.parent` tracking, not source transforms.
|
||||
|
||||
# example
|
||||
|
||||
``` js
|
||||
var astw = require('astw');
|
||||
var deparse = require('escodegen').generate;
|
||||
var walk = astw('4 + beep(5 * 2)');
|
||||
|
||||
walk(function (node) {
|
||||
var src = deparse(node);
|
||||
console.log(node.type + ' :: ' + JSON.stringify(src));
|
||||
});
|
||||
```
|
||||
|
||||
# methods
|
||||
|
||||
``` js
|
||||
var astw = require('astw')
|
||||
```
|
||||
|
||||
## var walk = astw(src, opts={})
|
||||
|
||||
Return a `walk()` function from the source string or ast object `src`.
|
||||
|
||||
Optionally:
|
||||
|
||||
* `opts.ecmaVersion` - default: 8
|
||||
|
||||
## walk(cb)
|
||||
|
||||
Walk the nodes in the ast with `cb(node)` where `node` is each element in the
|
||||
ast from [esprima](http://esprima.org/) but with an additional `.parent`
|
||||
reference to the parent node.
|
||||
|
||||
# install
|
||||
|
||||
With [npm](https://npmjs.org) do:
|
||||
|
||||
```
|
||||
npm install astw
|
||||
```
|
||||
|
||||
# license
|
||||
|
||||
MIT
|
||||
13
build/node_modules/astw/test/json.js
generated
vendored
Normal file
13
build/node_modules/astw/test/json.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
var astw = require('../');
|
||||
var test = require('tape');
|
||||
|
||||
test('json', function (t) {
|
||||
t.plan(2);
|
||||
var numbers = [ 1, 2 ];
|
||||
var walk = astw('{"a":1,"b":2}');
|
||||
walk(function (node) {
|
||||
if (node.type === 'Literal' && typeof node.value === 'number') {
|
||||
t.equal(node.value, numbers.shift());
|
||||
}
|
||||
});
|
||||
});
|
||||
25
build/node_modules/astw/test/parent.js
generated
vendored
Normal file
25
build/node_modules/astw/test/parent.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
var astw = require('../');
|
||||
var test = require('tape');
|
||||
var generate = require('escodegen').generate;
|
||||
|
||||
function unparse (s) {
|
||||
return generate(s, { format: { compact: true } });
|
||||
}
|
||||
|
||||
test('parent', function (t) {
|
||||
t.plan(4);
|
||||
|
||||
var walk = astw('(' + function () {
|
||||
var xs = [ 1, 2, 3 ];
|
||||
fn(ys);
|
||||
} + ')()');
|
||||
|
||||
walk(function (node) {
|
||||
if (node.type === 'ArrayExpression') {
|
||||
t.equal(node.parent.type, 'VariableDeclarator');
|
||||
t.equal(unparse(node.parent), 'xs=[1,2,3]');
|
||||
t.equal(node.parent.parent.type, 'VariableDeclaration');
|
||||
t.equal(unparse(node.parent.parent), 'var xs=[1,2,3];');
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user