initial commit taken from gitlab.lrz.de

This commit is contained in:
privatereese
2018-08-24 18:09:42 +02:00
parent ae54ed4c48
commit fc05486403
28494 changed files with 2159823 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
node_modules
*.log
src
test

View File

@@ -0,0 +1,142 @@
# babel-plugin-transform-es2015-for-of
> Compile ES2015 for...of to ES5
## Example
**In**
```js
for (var i of foo) {}
```
**Out**
```js
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = foo[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var i = _step.value;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
```
## Installation
```sh
npm install --save-dev babel-plugin-transform-es2015-for-of
```
## Usage
### Via `.babelrc` (Recommended)
**.babelrc**
```js
// without options
{
"plugins": ["transform-es2015-for-of"]
}
// with options
{
"plugins": [
["transform-es2015-for-of", {
"loose": true
}]
]
}
```
### Via CLI
```sh
babel --plugins transform-es2015-for-of script.js
```
### Via Node API
```javascript
require("babel-core").transform("code", {
plugins: ["transform-es2015-for-of"]
});
```
## Options
### `loose`
`boolean`, defaults to `false`
In loose mode, arrays are put in a fast path, thus heavily increasing performance.
All other iterables will continue to work fine.
#### Example
**In**
```js
for (var i of foo) {}
```
**Out**
```js
for (var _iterator = foo, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var i = _ref;
}
```
#### Abrupt completions
In loose mode an iterator's `return` method will not be called on abrupt completions caused by thrown errors.
Please see [google/traceur-compiler#1773](https://github.com/google/traceur-compiler/issues/1773) and
[babel/babel#838](https://github.com/babel/babel/issues/838) for more information.
### Optimization
If a basic array is used, Babel will compile the for-of loop down to a regular for loop.
**In**
```js
for (let a of [1,2,3]) {}
```
**Out**
```js
var _arr = [1, 2, 3];
for (var _i = 0; _i < _arr.length; _i++) {
var a = _arr[_i];
}
```

View File

@@ -0,0 +1,199 @@
"use strict";
exports.__esModule = true;
exports.default = function (_ref) {
var messages = _ref.messages,
template = _ref.template,
t = _ref.types;
var buildForOfArray = template("\n for (var KEY = 0; KEY < ARR.length; KEY++) BODY;\n ");
var buildForOfLoose = template("\n for (var LOOP_OBJECT = OBJECT,\n IS_ARRAY = Array.isArray(LOOP_OBJECT),\n INDEX = 0,\n LOOP_OBJECT = IS_ARRAY ? LOOP_OBJECT : LOOP_OBJECT[Symbol.iterator]();;) {\n var ID;\n if (IS_ARRAY) {\n if (INDEX >= LOOP_OBJECT.length) break;\n ID = LOOP_OBJECT[INDEX++];\n } else {\n INDEX = LOOP_OBJECT.next();\n if (INDEX.done) break;\n ID = INDEX.value;\n }\n }\n ");
var buildForOf = template("\n var ITERATOR_COMPLETION = true;\n var ITERATOR_HAD_ERROR_KEY = false;\n var ITERATOR_ERROR_KEY = undefined;\n try {\n for (var ITERATOR_KEY = OBJECT[Symbol.iterator](), STEP_KEY; !(ITERATOR_COMPLETION = (STEP_KEY = ITERATOR_KEY.next()).done); ITERATOR_COMPLETION = true) {\n }\n } catch (err) {\n ITERATOR_HAD_ERROR_KEY = true;\n ITERATOR_ERROR_KEY = err;\n } finally {\n try {\n if (!ITERATOR_COMPLETION && ITERATOR_KEY.return) {\n ITERATOR_KEY.return();\n }\n } finally {\n if (ITERATOR_HAD_ERROR_KEY) {\n throw ITERATOR_ERROR_KEY;\n }\n }\n }\n ");
function _ForOfStatementArray(path) {
var node = path.node,
scope = path.scope;
var nodes = [];
var right = node.right;
if (!t.isIdentifier(right) || !scope.hasBinding(right.name)) {
var uid = scope.generateUidIdentifier("arr");
nodes.push(t.variableDeclaration("var", [t.variableDeclarator(uid, right)]));
right = uid;
}
var iterationKey = scope.generateUidIdentifier("i");
var loop = buildForOfArray({
BODY: node.body,
KEY: iterationKey,
ARR: right
});
t.inherits(loop, node);
t.ensureBlock(loop);
var iterationValue = t.memberExpression(right, iterationKey, true);
var left = node.left;
if (t.isVariableDeclaration(left)) {
left.declarations[0].init = iterationValue;
loop.body.body.unshift(left);
} else {
loop.body.body.unshift(t.expressionStatement(t.assignmentExpression("=", left, iterationValue)));
}
if (path.parentPath.isLabeledStatement()) {
loop = t.labeledStatement(path.parentPath.node.label, loop);
}
nodes.push(loop);
return nodes;
}
return {
visitor: {
ForOfStatement: function ForOfStatement(path, state) {
if (path.get("right").isArrayExpression()) {
if (path.parentPath.isLabeledStatement()) {
return path.parentPath.replaceWithMultiple(_ForOfStatementArray(path));
} else {
return path.replaceWithMultiple(_ForOfStatementArray(path));
}
}
var callback = spec;
if (state.opts.loose) callback = loose;
var node = path.node;
var build = callback(path, state);
var declar = build.declar;
var loop = build.loop;
var block = loop.body;
path.ensureBlock();
if (declar) {
block.body.push(declar);
}
block.body = block.body.concat(node.body.body);
t.inherits(loop, node);
t.inherits(loop.body, node.body);
if (build.replaceParent) {
path.parentPath.replaceWithMultiple(build.node);
path.remove();
} else {
path.replaceWithMultiple(build.node);
}
}
}
};
function loose(path, file) {
var node = path.node,
scope = path.scope,
parent = path.parent;
var left = node.left;
var declar = void 0,
id = void 0;
if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) {
id = left;
} else if (t.isVariableDeclaration(left)) {
id = scope.generateUidIdentifier("ref");
declar = t.variableDeclaration(left.kind, [t.variableDeclarator(left.declarations[0].id, id)]);
} else {
throw file.buildCodeFrameError(left, messages.get("unknownForHead", left.type));
}
var iteratorKey = scope.generateUidIdentifier("iterator");
var isArrayKey = scope.generateUidIdentifier("isArray");
var loop = buildForOfLoose({
LOOP_OBJECT: iteratorKey,
IS_ARRAY: isArrayKey,
OBJECT: node.right,
INDEX: scope.generateUidIdentifier("i"),
ID: id
});
if (!declar) {
loop.body.body.shift();
}
var isLabeledParent = t.isLabeledStatement(parent);
var labeled = void 0;
if (isLabeledParent) {
labeled = t.labeledStatement(parent.label, loop);
}
return {
replaceParent: isLabeledParent,
declar: declar,
node: labeled || loop,
loop: loop
};
}
function spec(path, file) {
var node = path.node,
scope = path.scope,
parent = path.parent;
var left = node.left;
var declar = void 0;
var stepKey = scope.generateUidIdentifier("step");
var stepValue = t.memberExpression(stepKey, t.identifier("value"));
if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) {
declar = t.expressionStatement(t.assignmentExpression("=", left, stepValue));
} else if (t.isVariableDeclaration(left)) {
declar = t.variableDeclaration(left.kind, [t.variableDeclarator(left.declarations[0].id, stepValue)]);
} else {
throw file.buildCodeFrameError(left, messages.get("unknownForHead", left.type));
}
var iteratorKey = scope.generateUidIdentifier("iterator");
var template = buildForOf({
ITERATOR_HAD_ERROR_KEY: scope.generateUidIdentifier("didIteratorError"),
ITERATOR_COMPLETION: scope.generateUidIdentifier("iteratorNormalCompletion"),
ITERATOR_ERROR_KEY: scope.generateUidIdentifier("iteratorError"),
ITERATOR_KEY: iteratorKey,
STEP_KEY: stepKey,
OBJECT: node.right,
BODY: null
});
var isLabeledParent = t.isLabeledStatement(parent);
var tryBody = template[3].block.body;
var loop = tryBody[0];
if (isLabeledParent) {
tryBody[0] = t.labeledStatement(parent.label, loop);
}
return {
replaceParent: isLabeledParent,
declar: declar,
loop: loop,
node: template
};
}
};
module.exports = exports["default"];

View File

@@ -0,0 +1,93 @@
{
"_args": [
[
"babel-plugin-transform-es2015-for-of@^6.8.0",
"/home/bernhard/freifunk-app/node_modules/babel-preset-fbjs"
]
],
"_from": "babel-plugin-transform-es2015-for-of@>=6.8.0 <7.0.0",
"_id": "babel-plugin-transform-es2015-for-of@6.23.0",
"_inCache": true,
"_installable": true,
"_location": "/babel-plugin-transform-es2015-for-of",
"_nodeVersion": "6.9.1",
"_npmOperationalInternal": {
"host": "packages-12-west.internal.npmjs.com",
"tmp": "tmp/babel-plugin-transform-es2015-for-of-6.23.0.tgz_1487027061167_0.7569211190566421"
},
"_npmUser": {
"email": "loganfsmyth@gmail.com",
"name": "loganfsmyth"
},
"_npmVersion": "3.10.8",
"_phantomChildren": {},
"_requested": {
"name": "babel-plugin-transform-es2015-for-of",
"raw": "babel-plugin-transform-es2015-for-of@^6.8.0",
"rawSpec": "^6.8.0",
"scope": null,
"spec": ">=6.8.0 <7.0.0",
"type": "range"
},
"_requiredBy": [
"/babel-preset-fbjs",
"/babel-preset-react-native"
],
"_resolved": "https://registry.npmjs.org/babel-plugin-transform-es2015-for-of/-/babel-plugin-transform-es2015-for-of-6.23.0.tgz",
"_shasum": "f47c95b2b613df1d3ecc2fdb7573623c75248691",
"_shrinkwrap": null,
"_spec": "babel-plugin-transform-es2015-for-of@^6.8.0",
"_where": "/home/bernhard/freifunk-app/node_modules/babel-preset-fbjs",
"dependencies": {
"babel-runtime": "^6.22.0"
},
"description": "Compile ES2015 for...of to ES5",
"devDependencies": {
"babel-helper-plugin-test-runner": "^6.22.0"
},
"directories": {},
"dist": {
"shasum": "f47c95b2b613df1d3ecc2fdb7573623c75248691",
"tarball": "https://registry.npmjs.org/babel-plugin-transform-es2015-for-of/-/babel-plugin-transform-es2015-for-of-6.23.0.tgz"
},
"keywords": [
"babel-plugin"
],
"license": "MIT",
"main": "lib/index.js",
"maintainers": [
{
"name": "amasad",
"email": "amjad.masad@gmail.com"
},
{
"name": "hzoo",
"email": "hi@henryzoo.com"
},
{
"name": "jmm",
"email": "npm-public@jessemccarthy.net"
},
{
"name": "loganfsmyth",
"email": "loganfsmyth@gmail.com"
},
{
"name": "sebmck",
"email": "sebmck@gmail.com"
},
{
"name": "thejameskyle",
"email": "me@thejameskyle.com"
}
],
"name": "babel-plugin-transform-es2015-for-of",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-for-of"
},
"scripts": {},
"version": "6.23.0"
}