flow like the river
This commit is contained in:
commit
013fe673f3
42435 changed files with 5764238 additions and 0 deletions
42
BACK_BACK/node_modules/falafel/.github/workflows/ci.yml
generated
vendored
Executable file
42
BACK_BACK/node_modules/falafel/.github/workflows/ci.yml
generated
vendored
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
name: Node CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version:
|
||||
- '0.8'
|
||||
- '0.10'
|
||||
- '0.12'
|
||||
- '4.x'
|
||||
- '6.x'
|
||||
- '8.x'
|
||||
- '10.x'
|
||||
- '12.x'
|
||||
- '14.x'
|
||||
- '16.x'
|
||||
- '17.x'
|
||||
- '18.x'
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- run: npm install
|
||||
if: matrix.node-version != '0.8'
|
||||
- name: Run npm install for Node.js 0.8
|
||||
run: |
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
|
||||
. "$HOME/.nvm/nvm.sh"
|
||||
nvm install-latest-npm
|
||||
npm install
|
||||
env:
|
||||
NPM_CONFIG_STRICT_SSL: 'false'
|
||||
if: matrix.node-version == '0.8'
|
||||
- run: npm test
|
||||
21
BACK_BACK/node_modules/falafel/LICENSE
generated
vendored
Executable file
21
BACK_BACK/node_modules/falafel/LICENSE
generated
vendored
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2012 James Halliday
|
||||
|
||||
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.
|
||||
14
BACK_BACK/node_modules/falafel/example/array.js
generated
vendored
Executable file
14
BACK_BACK/node_modules/falafel/example/array.js
generated
vendored
Executable file
|
|
@ -0,0 +1,14 @@
|
|||
var falafel = require('../');
|
||||
|
||||
var src = '(' + function () {
|
||||
var xs = [ 1, 2, [ 3, 4 ] ];
|
||||
var ys = [ 5, 6 ];
|
||||
console.dir([ xs, ys ]);
|
||||
} + ')()';
|
||||
|
||||
var output = falafel(src, function (node) {
|
||||
if (node.type === 'ArrayExpression') {
|
||||
node.update('fn(' + node.source() + ')');
|
||||
}
|
||||
});
|
||||
console.log(output);
|
||||
16
BACK_BACK/node_modules/falafel/example/keyword.js
generated
vendored
Executable file
16
BACK_BACK/node_modules/falafel/example/keyword.js
generated
vendored
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
var falafel = require('../');
|
||||
var src = 'console.log(beep "boop", "BOOP");';
|
||||
|
||||
function isKeyword (id) {
|
||||
if (id === 'beep') return true;
|
||||
}
|
||||
|
||||
var output = falafel(src, { isKeyword: isKeyword }, function (node) {
|
||||
if (node.type === 'UnaryExpression'
|
||||
&& node.operator === 'beep') {
|
||||
node.update(
|
||||
'String(' + node.argument.source() + ').toUpperCase()'
|
||||
);
|
||||
}
|
||||
});
|
||||
console.log(output);
|
||||
49
BACK_BACK/node_modules/falafel/example/prompt.js
generated
vendored
Executable file
49
BACK_BACK/node_modules/falafel/example/prompt.js
generated
vendored
Executable file
|
|
@ -0,0 +1,49 @@
|
|||
var falafel = require('../');
|
||||
var vm = require('vm');
|
||||
|
||||
var termExps = [
|
||||
'Identifier',
|
||||
'CallExpression',
|
||||
'BinaryExpression',
|
||||
'UpdateExpression',
|
||||
'UnaryExpression'
|
||||
].reduce(function (acc, key) { acc[key] = true; return acc }, {});
|
||||
|
||||
function terminated (node) {
|
||||
for (var p = node; p.parent; p = p.parent) {
|
||||
if (termExps[p.type]) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
var src = '{"a":[2,~9,prompt(":d")],"b":4,"c":prompt("beep"),"d":6}';
|
||||
|
||||
var offsets = [];
|
||||
var output = falafel('(' + src + ')', function (node) {
|
||||
var isLeaf = node.parent
|
||||
&& !terminated(node.parent) && terminated(node)
|
||||
;
|
||||
|
||||
if (isLeaf) {
|
||||
var s = node.source();
|
||||
var prompted = false;
|
||||
var res = vm.runInNewContext('(' + s + ')', {
|
||||
prompt : function (x) {
|
||||
setTimeout(function () {
|
||||
node.update(x.toUpperCase());
|
||||
}, Math.random() * 50);
|
||||
prompted = true;
|
||||
}
|
||||
});
|
||||
if (!prompted) {
|
||||
var s_ = JSON.stringify(res);
|
||||
node.update(s_);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
console.log(src);
|
||||
console.log('---');
|
||||
console.log(output);
|
||||
}, 200);
|
||||
BIN
BACK_BACK/node_modules/falafel/falafel.png
generated
vendored
Executable file
BIN
BACK_BACK/node_modules/falafel/falafel.png
generated
vendored
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 48 KiB |
85
BACK_BACK/node_modules/falafel/index.js
generated
vendored
Executable file
85
BACK_BACK/node_modules/falafel/index.js
generated
vendored
Executable file
|
|
@ -0,0 +1,85 @@
|
|||
var acorn = require('acorn');
|
||||
var isArray = require('isarray');
|
||||
var util = require('util');
|
||||
|
||||
module.exports = function (src, opts, fn) {
|
||||
if (typeof opts === 'function') {
|
||||
fn = opts;
|
||||
opts = {};
|
||||
}
|
||||
if (src && typeof src === 'object' && src.constructor.name === 'Buffer') {
|
||||
src = src.toString();
|
||||
}
|
||||
else if (src && typeof src === 'object') {
|
||||
opts = src;
|
||||
src = opts.source;
|
||||
delete opts.source;
|
||||
}
|
||||
src = src === undefined ? opts.source : src;
|
||||
if (typeof src !== 'string') src = String(src);
|
||||
var parser = opts.parser || acorn;
|
||||
var ast = parser.parse(src, opts);
|
||||
|
||||
var result = {
|
||||
chunks : src.split(''),
|
||||
toString : function () { return result.chunks.join('') },
|
||||
inspect : function () { return result.toString() }
|
||||
};
|
||||
if (util.inspect.custom) {
|
||||
result[util.inspect.custom] = result.toString;
|
||||
}
|
||||
var index = 0;
|
||||
|
||||
(function walk (node, parent) {
|
||||
insertHelpers(node, parent, result.chunks);
|
||||
|
||||
for (var key in node) {
|
||||
if (key === 'parent' || !Object.prototype.hasOwnProperty.call(node, key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var child = node[key];
|
||||
if (isArray(child)) {
|
||||
for (var i = 0; i < child.length; i += 1) {
|
||||
if (child[i] && typeof child[i].type === 'string') {
|
||||
walk(child[i], node);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (child && typeof child.type === 'string') {
|
||||
walk(child, node);
|
||||
}
|
||||
}
|
||||
fn(node);
|
||||
})(ast, undefined);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
function insertHelpers (node, parent, chunks) {
|
||||
node.parent = parent;
|
||||
|
||||
node.source = function () {
|
||||
return chunks.slice(node.start, node.end).join('');
|
||||
};
|
||||
|
||||
if (node.update && typeof node.update === 'object') {
|
||||
var prev = node.update;
|
||||
for (var key in prev) {
|
||||
if (Object.prototype.hasOwnProperty.call(prev, key)) {
|
||||
update[key] = prev[key];
|
||||
}
|
||||
}
|
||||
node.update = update;
|
||||
}
|
||||
else {
|
||||
node.update = update;
|
||||
}
|
||||
|
||||
function update (s) {
|
||||
chunks[node.start] = s;
|
||||
for (var i = node.start + 1; i < node.end; i++) {
|
||||
chunks[i] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
21
BACK_BACK/node_modules/falafel/node_modules/isarray/LICENSE
generated
vendored
Executable file
21
BACK_BACK/node_modules/falafel/node_modules/isarray/LICENSE
generated
vendored
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>
|
||||
|
||||
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.
|
||||
38
BACK_BACK/node_modules/falafel/node_modules/isarray/README.md
generated
vendored
Executable file
38
BACK_BACK/node_modules/falafel/node_modules/isarray/README.md
generated
vendored
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
|
||||
# isarray
|
||||
|
||||
`Array#isArray` for older browsers and deprecated Node.js versions.
|
||||
|
||||
[](http://travis-ci.org/juliangruber/isarray)
|
||||
[](https://www.npmjs.org/package/isarray)
|
||||
|
||||
[
|
||||
](https://ci.testling.com/juliangruber/isarray)
|
||||
|
||||
__Just use Array.isArray directly__, unless you need to support those older versions.
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var isArray = require('isarray');
|
||||
|
||||
console.log(isArray([])); // => true
|
||||
console.log(isArray({})); // => false
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
With [npm](https://npmjs.org) do
|
||||
|
||||
```bash
|
||||
$ npm install isarray
|
||||
```
|
||||
|
||||
Then bundle for the browser with
|
||||
[browserify](https://github.com/substack/node-browserify).
|
||||
|
||||
## Sponsors
|
||||
|
||||
This module is proudly supported by my [Sponsors](https://github.com/juliangruber/sponsors)!
|
||||
|
||||
Do you want to support modules like this to improve their quality, stability and weigh in on new features? Then please consider donating to my [Patreon](https://www.patreon.com/juliangruber). Not sure how much of my modules you're using? Try [feross/thanks](https://github.com/feross/thanks)!
|
||||
5
BACK_BACK/node_modules/falafel/node_modules/isarray/index.js
generated
vendored
Executable file
5
BACK_BACK/node_modules/falafel/node_modules/isarray/index.js
generated
vendored
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
var toString = {}.toString;
|
||||
|
||||
module.exports = Array.isArray || function (arr) {
|
||||
return toString.call(arr) == '[object Array]';
|
||||
};
|
||||
48
BACK_BACK/node_modules/falafel/node_modules/isarray/package.json
generated
vendored
Executable file
48
BACK_BACK/node_modules/falafel/node_modules/isarray/package.json
generated
vendored
Executable file
|
|
@ -0,0 +1,48 @@
|
|||
{
|
||||
"name": "isarray",
|
||||
"description": "Array#isArray for older browsers",
|
||||
"version": "2.0.5",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/juliangruber/isarray.git"
|
||||
},
|
||||
"homepage": "https://github.com/juliangruber/isarray",
|
||||
"main": "index.js",
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"tape": "~2.13.4"
|
||||
},
|
||||
"keywords": [
|
||||
"browser",
|
||||
"isarray",
|
||||
"array"
|
||||
],
|
||||
"author": {
|
||||
"name": "Julian Gruber",
|
||||
"email": "mail@juliangruber.com",
|
||||
"url": "http://juliangruber.com"
|
||||
},
|
||||
"license": "MIT",
|
||||
"testling": {
|
||||
"files": "test.js",
|
||||
"browsers": [
|
||||
"ie/8..latest",
|
||||
"firefox/17..latest",
|
||||
"firefox/nightly",
|
||||
"chrome/22..latest",
|
||||
"chrome/canary",
|
||||
"opera/12..latest",
|
||||
"opera/next",
|
||||
"safari/5.1..latest",
|
||||
"ipad/6.0..latest",
|
||||
"iphone/6.0..latest",
|
||||
"android-browser/4.2..latest"
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tape test.js"
|
||||
}
|
||||
}
|
||||
71
BACK_BACK/node_modules/falafel/package.json
generated
vendored
Executable file
71
BACK_BACK/node_modules/falafel/package.json
generated
vendored
Executable file
|
|
@ -0,0 +1,71 @@
|
|||
{
|
||||
"name": "falafel",
|
||||
"description": "transform the ast on a recursive walk",
|
||||
"version": "2.2.5",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/substack/node-falafel.git"
|
||||
},
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
"ast",
|
||||
"burrito",
|
||||
"source",
|
||||
"syntax",
|
||||
"traversal",
|
||||
"tree"
|
||||
],
|
||||
"directories": {
|
||||
"example": "example",
|
||||
"test": "test"
|
||||
},
|
||||
"scripts": {
|
||||
"coverage": "covert test/*.js",
|
||||
"test": "node --harmony test/bin/run.js test/*.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"acorn": "^7.1.1",
|
||||
"isarray": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"acorn-jsx": "^5.2.0",
|
||||
"covert": "^1.1.0",
|
||||
"glob": "^6.0.4",
|
||||
"safe-buffer": "^5.2.0",
|
||||
"semver": "^6.0.0",
|
||||
"tape": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
},
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
"email": "mail@substack.net",
|
||||
"name": "James Halliday",
|
||||
"url": "http://substack.net"
|
||||
},
|
||||
"testling": {
|
||||
"browsers": {
|
||||
"chrome": [
|
||||
"20.0"
|
||||
],
|
||||
"firefox": [
|
||||
"10.0",
|
||||
"15.0"
|
||||
],
|
||||
"iexplore": [
|
||||
"6.0",
|
||||
"7.0",
|
||||
"8.0",
|
||||
"9.0"
|
||||
],
|
||||
"opera": [
|
||||
"12.0"
|
||||
],
|
||||
"safari": [
|
||||
"5.1"
|
||||
]
|
||||
},
|
||||
"files": "test/*.js"
|
||||
}
|
||||
}
|
||||
122
BACK_BACK/node_modules/falafel/readme.markdown
generated
vendored
Executable file
122
BACK_BACK/node_modules/falafel/readme.markdown
generated
vendored
Executable file
|
|
@ -0,0 +1,122 @@
|
|||
# falafel
|
||||
|
||||
Transform the [ast](http://en.wikipedia.org/wiki/Abstract_syntax_tree) on a
|
||||
recursive walk.
|
||||
|
||||
[](http://ci.testling.com/substack/node-falafel)
|
||||
|
||||
[](https://github.com/substack/node-falafel/actions)
|
||||
|
||||
This modules uses [acorn](https://npmjs.org/package/acorn) to create an AST from
|
||||
source code.
|
||||
|
||||

|
||||
|
||||
# example
|
||||
|
||||
## array.js
|
||||
|
||||
Put a function wrapper around all array literals.
|
||||
|
||||
``` js
|
||||
var falafel = require('falafel');
|
||||
|
||||
var src = '(' + function () {
|
||||
var xs = [ 1, 2, [ 3, 4 ] ];
|
||||
var ys = [ 5, 6 ];
|
||||
console.dir([ xs, ys ]);
|
||||
} + ')()';
|
||||
|
||||
var output = falafel(src, function (node) {
|
||||
if (node.type === 'ArrayExpression') {
|
||||
node.update('fn(' + node.source() + ')');
|
||||
}
|
||||
});
|
||||
console.log(output);
|
||||
```
|
||||
|
||||
output:
|
||||
|
||||
```
|
||||
(function () {
|
||||
var xs = fn([ 1, 2, fn([ 3, 4 ]) ]);
|
||||
var ys = fn([ 5, 6 ]);
|
||||
console.dir(fn([ xs, ys ]));
|
||||
})()
|
||||
```
|
||||
|
||||
# methods
|
||||
|
||||
``` js
|
||||
var falafel = require('falafel')
|
||||
```
|
||||
|
||||
## falafel(src, opts={}, fn)
|
||||
|
||||
Transform the string source `src` with the function `fn`, returning a
|
||||
string-like transformed output object.
|
||||
|
||||
For every node in the ast, `fn(node)` fires. The recursive walk is a
|
||||
post-order traversal, so children get called before their parents.
|
||||
|
||||
Performing a post-order traversal makes it easier to write nested transforms since
|
||||
transforming parents often requires transforming all its children first.
|
||||
|
||||
The return value is string-like (it defines `.toString()` and `.inspect()`) so
|
||||
that you can call `node.update()` asynchronously after the function has
|
||||
returned and still capture the output.
|
||||
|
||||
Instead of passing a `src` you can also use `opts.source`.
|
||||
|
||||
All of the `opts` will be passed directly to
|
||||
[acorn](https://npmjs.org/package/acorn).
|
||||
|
||||
## custom parser
|
||||
|
||||
You may pass in an instance of acorn to the opts as `opts.parser` to use that
|
||||
version instead of the version of acorn packaged with this library.
|
||||
|
||||
```js
|
||||
var acorn = require('acorn-jsx');
|
||||
|
||||
falafel(src, {parser: acorn, plugins: { jsx: true }}, function(node) {
|
||||
// this will parse jsx
|
||||
});
|
||||
```
|
||||
|
||||
# nodes
|
||||
|
||||
Aside from the regular [acorn](https://npmjs.org/package/acorn) data, you can also call
|
||||
some inserted methods on nodes.
|
||||
|
||||
Aside from updating the current node, you can also reach into sub-nodes to call
|
||||
update functions on children from parent nodes.
|
||||
|
||||
## node.source()
|
||||
|
||||
Return the source for the given node, including any modifications made to
|
||||
children nodes.
|
||||
|
||||
## node.update(s)
|
||||
|
||||
Transform the source for the present node to the string `s`.
|
||||
|
||||
Note that in `'ForStatement'` node types, there is an existing subnode called
|
||||
`update`. For those nodes all the properties are copied over onto the
|
||||
`node.update()` function.
|
||||
|
||||
## node.parent
|
||||
|
||||
Reference to the parent element or `null` at the root element.
|
||||
|
||||
# install
|
||||
|
||||
With [npm](http://npmjs.org) do:
|
||||
|
||||
```
|
||||
npm install falafel
|
||||
```
|
||||
|
||||
# license
|
||||
|
||||
MIT
|
||||
35
BACK_BACK/node_modules/falafel/test/array.js
generated
vendored
Executable file
35
BACK_BACK/node_modules/falafel/test/array.js
generated
vendored
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
var falafel = require('../');
|
||||
var test = require('tape');
|
||||
|
||||
test('array', function (t) {
|
||||
t.plan(5);
|
||||
|
||||
var src = '(' + function () {
|
||||
var xs = [ 1, 2, [ 3, 4 ] ];
|
||||
var ys = [ 5, 6 ];
|
||||
g([ xs, ys ]);
|
||||
} + ')()';
|
||||
|
||||
var output = falafel(src, function (node) {
|
||||
if (node.type === 'ArrayExpression') {
|
||||
node.update('fn(' + node.source() + ')');
|
||||
}
|
||||
});
|
||||
|
||||
var arrays = [
|
||||
[ 3, 4 ],
|
||||
[ 1, 2, [ 3, 4 ] ],
|
||||
[ 5, 6 ],
|
||||
[ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ],
|
||||
];
|
||||
|
||||
Function(['fn','g'], output)(
|
||||
function (xs) {
|
||||
t.same(arrays.shift(), xs);
|
||||
return xs;
|
||||
},
|
||||
function (xs) {
|
||||
t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
|
||||
}
|
||||
);
|
||||
});
|
||||
42
BACK_BACK/node_modules/falafel/test/async.js
generated
vendored
Executable file
42
BACK_BACK/node_modules/falafel/test/async.js
generated
vendored
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
var falafel = require('../');
|
||||
var test = require('tape');
|
||||
|
||||
test('async', function (t) {
|
||||
t.plan(5);
|
||||
|
||||
var src = '(function () {'
|
||||
+ 'var xs = [ 1, 2, [ 3, 4 ] ];'
|
||||
+ 'var ys = [ 5, 6 ];'
|
||||
+ 'g([ xs, ys ]);'
|
||||
+ '})()';
|
||||
|
||||
var pending = 0;
|
||||
var output = falafel(src, function (node) {
|
||||
if (node.type === 'ArrayExpression') {
|
||||
pending ++;
|
||||
setTimeout(function () {
|
||||
node.update('fn(' + node.source() + ')');
|
||||
if (--pending === 0) check();
|
||||
}, 50 * pending * 2);
|
||||
}
|
||||
});
|
||||
|
||||
var arrays = [
|
||||
[ 3, 4 ],
|
||||
[ 1, 2, [ 3, 4 ] ],
|
||||
[ 5, 6 ],
|
||||
[ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ],
|
||||
];
|
||||
|
||||
function check () {
|
||||
Function([ 'fn', 'g' ], output)(
|
||||
function (xs) {
|
||||
t.same(arrays.shift(), xs);
|
||||
return xs;
|
||||
},
|
||||
function (xs) {
|
||||
t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
10
BACK_BACK/node_modules/falafel/test/bin/run.js
generated
vendored
Executable file
10
BACK_BACK/node_modules/falafel/test/bin/run.js
generated
vendored
Executable file
|
|
@ -0,0 +1,10 @@
|
|||
var path = require('path');
|
||||
var glob = require('glob');
|
||||
|
||||
for (var i = 2; i < process.argv.length; i++) {
|
||||
glob(process.argv[i], function (er, files) {
|
||||
files.forEach(function (file) {
|
||||
require(path.resolve(process.cwd(), file));
|
||||
});
|
||||
});
|
||||
}
|
||||
46
BACK_BACK/node_modules/falafel/test/custom-parser.js
generated
vendored
Executable file
46
BACK_BACK/node_modules/falafel/test/custom-parser.js
generated
vendored
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
var falafel = require('../');
|
||||
var test = require('tape');
|
||||
var semver = require('semver');
|
||||
|
||||
// acorn-jsx requires node 4
|
||||
test('custom parser', { skip: semver.satisfies(process.version, '< 4.0.0') },function (t) {
|
||||
var acorn = require('acorn');
|
||||
var jsx = require('acorn-jsx');
|
||||
var acornWithJsx = acorn.Parser.extend(jsx());
|
||||
|
||||
var src = '(function() { var f = {a: "b"}; var a = <div {...f} className="test"></div>; })()';
|
||||
|
||||
var nodeTypes = [
|
||||
'Identifier',
|
||||
'Identifier',
|
||||
'Literal',
|
||||
'Property',
|
||||
'ObjectExpression',
|
||||
'VariableDeclarator',
|
||||
'VariableDeclaration',
|
||||
'Identifier',
|
||||
'Identifier',
|
||||
'JSXSpreadAttribute',
|
||||
'JSXIdentifier',
|
||||
'Literal',
|
||||
'JSXAttribute',
|
||||
'JSXIdentifier',
|
||||
'JSXOpeningElement',
|
||||
'JSXIdentifier',
|
||||
'JSXClosingElement',
|
||||
'JSXElement',
|
||||
'VariableDeclarator',
|
||||
'VariableDeclaration',
|
||||
'BlockStatement',
|
||||
'FunctionExpression',
|
||||
'CallExpression',
|
||||
'ExpressionStatement',
|
||||
'Program'
|
||||
];
|
||||
|
||||
t.plan(nodeTypes.length);
|
||||
|
||||
var output = falafel(src, {parser: acornWithJsx, ecmaVersion: 6, plugins: { jsx: true }}, function(node) {
|
||||
t.equal(node.type, nodeTypes.shift());
|
||||
});
|
||||
});
|
||||
17
BACK_BACK/node_modules/falafel/test/es6.js
generated
vendored
Executable file
17
BACK_BACK/node_modules/falafel/test/es6.js
generated
vendored
Executable file
|
|
@ -0,0 +1,17 @@
|
|||
var falafel = require('../');
|
||||
var test = require('tape');
|
||||
var semver = require('semver');
|
||||
|
||||
// it runs the generator so needs node 4+
|
||||
test('generators', { skip: semver.satisfies(process.version, '< 4.0.0') }, function (t) {
|
||||
t.plan(1);
|
||||
|
||||
var src = 'console.log((function * () { yield 3 })().next().value)';
|
||||
var output = falafel(src, { ecmaVersion: 6 }, function (node) {
|
||||
if (node.type === 'Literal') {
|
||||
node.update('555');
|
||||
}
|
||||
});
|
||||
Function(['console'],output)({log:log});
|
||||
function log (n) { t.equal(n, 555) }
|
||||
});
|
||||
30
BACK_BACK/node_modules/falafel/test/for.js
generated
vendored
Executable file
30
BACK_BACK/node_modules/falafel/test/for.js
generated
vendored
Executable file
|
|
@ -0,0 +1,30 @@
|
|||
var falafel = require('../');
|
||||
var test = require('tape');
|
||||
|
||||
test('for loop', function (t) {
|
||||
t.plan(7);
|
||||
|
||||
var src = '(function () {'
|
||||
+ 'var sum = 0;'
|
||||
+ 'for (var i = 0; i < 10; i++)'
|
||||
+ 'sum += i;'
|
||||
+ 'if (true)'
|
||||
+ 'for (var i = 0; i < 10; i++)'
|
||||
+ 'sum += i;'
|
||||
+ 'return sum;'
|
||||
+ '})()';
|
||||
|
||||
var output = falafel(src, function (node) {
|
||||
if (node.type === 'ForStatement') {
|
||||
t.equal(node.update.source(), 'i++');
|
||||
t.equal(node.update.type, "UpdateExpression");
|
||||
node.update.update('i+=2');
|
||||
}
|
||||
if (node.type === 'UpdateExpression') {
|
||||
t.equal(node.source(), 'i++');
|
||||
}
|
||||
});
|
||||
|
||||
var res = Function('return ' + output)();
|
||||
t.equal(res, 2 + 4 + 6 + 8 + 2 + 4 + 6 + 8);
|
||||
});
|
||||
38
BACK_BACK/node_modules/falafel/test/inspect.js
generated
vendored
Executable file
38
BACK_BACK/node_modules/falafel/test/inspect.js
generated
vendored
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
var falafel = require('../');
|
||||
var test = require('tape');
|
||||
var util = require('util');
|
||||
|
||||
test('inspect', function (t) {
|
||||
t.plan(7);
|
||||
|
||||
var src = '(function () {'
|
||||
+ 'var xs = [ 1, 2, [ 3, 4 ] ];'
|
||||
+ 'var ys = [ 5, 6 ];'
|
||||
+ 'g([ xs, ys ]);'
|
||||
+ '})()';
|
||||
|
||||
var output = falafel(src, function (node) {
|
||||
if (node.type === 'ArrayExpression') {
|
||||
node.update('fn(' + node.source() + ')');
|
||||
}
|
||||
});
|
||||
t.equal(output.inspect(), output.toString());
|
||||
t.equal(util.inspect(output), output.toString());
|
||||
|
||||
var arrays = [
|
||||
[ 3, 4 ],
|
||||
[ 1, 2, [ 3, 4 ] ],
|
||||
[ 5, 6 ],
|
||||
[ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ],
|
||||
];
|
||||
|
||||
Function(['fn','g'], output)(
|
||||
function (xs) {
|
||||
t.same(arrays.shift(), xs);
|
||||
return xs;
|
||||
},
|
||||
function (xs) {
|
||||
t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
|
||||
}
|
||||
);
|
||||
});
|
||||
135
BACK_BACK/node_modules/falafel/test/opts.js
generated
vendored
Executable file
135
BACK_BACK/node_modules/falafel/test/opts.js
generated
vendored
Executable file
|
|
@ -0,0 +1,135 @@
|
|||
var falafel = require('../');
|
||||
var Buffer = require('safe-buffer').Buffer;
|
||||
var test = require('tape');
|
||||
|
||||
test('first opts arg', function (t) {
|
||||
t.plan(5);
|
||||
|
||||
var src = '(function () {'
|
||||
+ 'var xs = [ 1, 2, [ 3, 4 ] ];'
|
||||
+ 'var ys = [ 5, 6 ];'
|
||||
+ 'g([ xs, ys ]);'
|
||||
+ '})()';
|
||||
|
||||
var output = falafel({ source: src }, function (node) {
|
||||
if (node.type === 'ArrayExpression') {
|
||||
node.update('fn(' + node.source() + ')');
|
||||
}
|
||||
});
|
||||
|
||||
var arrays = [
|
||||
[ 3, 4 ],
|
||||
[ 1, 2, [ 3, 4 ] ],
|
||||
[ 5, 6 ],
|
||||
[ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ],
|
||||
];
|
||||
|
||||
Function(['fn','g'], output)(
|
||||
function (xs) {
|
||||
t.same(arrays.shift(), xs);
|
||||
return xs;
|
||||
},
|
||||
function (xs) {
|
||||
t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test('opts.source', function (t) {
|
||||
t.plan(5);
|
||||
|
||||
var src = '(function () {'
|
||||
+ 'var xs = [ 1, 2, [ 3, 4 ] ];'
|
||||
+ 'var ys = [ 5, 6 ];'
|
||||
+ 'g([ xs, ys ]);'
|
||||
+ '})()';
|
||||
|
||||
var output = falafel(undefined, { source: src }, function (node) {
|
||||
if (node.type === 'ArrayExpression') {
|
||||
node.update('fn(' + node.source() + ')');
|
||||
}
|
||||
});
|
||||
|
||||
var arrays = [
|
||||
[ 3, 4 ],
|
||||
[ 1, 2, [ 3, 4 ] ],
|
||||
[ 5, 6 ],
|
||||
[ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ],
|
||||
];
|
||||
|
||||
Function(['fn','g'], output)(
|
||||
function (xs) {
|
||||
t.same(arrays.shift(), xs);
|
||||
return xs;
|
||||
},
|
||||
function (xs) {
|
||||
t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test('Buffer opts.source', function (t) {
|
||||
t.plan(5);
|
||||
|
||||
var src = Buffer.from('(function () {'
|
||||
+ 'var xs = [ 1, 2, [ 3, 4 ] ];'
|
||||
+ 'var ys = [ 5, 6 ];'
|
||||
+ 'g([ xs, ys ]);'
|
||||
+ '})()');
|
||||
|
||||
var output = falafel({ source: src }, function (node) {
|
||||
if (node.type === 'ArrayExpression') {
|
||||
node.update('fn(' + node.source() + ')');
|
||||
}
|
||||
});
|
||||
|
||||
var arrays = [
|
||||
[ 3, 4 ],
|
||||
[ 1, 2, [ 3, 4 ] ],
|
||||
[ 5, 6 ],
|
||||
[ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ],
|
||||
];
|
||||
|
||||
Function(['fn','g'], output)(
|
||||
function (xs) {
|
||||
t.same(arrays.shift(), xs);
|
||||
return xs;
|
||||
},
|
||||
function (xs) {
|
||||
t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test('Buffer source', function (t) {
|
||||
t.plan(5);
|
||||
|
||||
var src = Buffer.from('(function () {'
|
||||
+ 'var xs = [ 1, 2, [ 3, 4 ] ];'
|
||||
+ 'var ys = [ 5, 6 ];'
|
||||
+ 'g([ xs, ys ]);'
|
||||
+ '})()');
|
||||
|
||||
var output = falafel(src, function (node) {
|
||||
if (node.type === 'ArrayExpression') {
|
||||
node.update('fn(' + node.source() + ')');
|
||||
}
|
||||
});
|
||||
|
||||
var arrays = [
|
||||
[ 3, 4 ],
|
||||
[ 1, 2, [ 3, 4 ] ],
|
||||
[ 5, 6 ],
|
||||
[ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ],
|
||||
];
|
||||
|
||||
Function(['fn','g'], output)(
|
||||
function (xs) {
|
||||
t.same(arrays.shift(), xs);
|
||||
return xs;
|
||||
},
|
||||
function (xs) {
|
||||
t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
|
||||
}
|
||||
);
|
||||
});
|
||||
33
BACK_BACK/node_modules/falafel/test/parent.js
generated
vendored
Executable file
33
BACK_BACK/node_modules/falafel/test/parent.js
generated
vendored
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
var falafel = require('../');
|
||||
var test = require('tape');
|
||||
|
||||
test('parent', function (t) {
|
||||
t.plan(5);
|
||||
|
||||
var src = '(function () {'
|
||||
+ 'var xs = [ 1, 2, 3 ];'
|
||||
+ 'fn(ys);'
|
||||
+ '})()';
|
||||
|
||||
var output = falafel(src, function (node) {
|
||||
if (node.type === 'ArrayExpression') {
|
||||
t.equal(node.parent.type, 'VariableDeclarator');
|
||||
t.equal(
|
||||
ffBracket(node.parent.source()),
|
||||
'xs = [ 1, 2, 3 ]'
|
||||
);
|
||||
t.equal(node.parent.parent.type, 'VariableDeclaration');
|
||||
t.equal(
|
||||
ffBracket(node.parent.parent.source()),
|
||||
'var xs = [ 1, 2, 3 ];'
|
||||
);
|
||||
node.parent.update('ys = 4;');
|
||||
}
|
||||
});
|
||||
|
||||
Function(['fn'], output)(function (x) { t.equal(x, 4) });
|
||||
});
|
||||
|
||||
function ffBracket (s) {
|
||||
return s.replace(/\[\s*/, '[ ').replace(/\s*\]/, ' ]');
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue