WIP - add extractor, generate snippet_data

This commit is contained in:
Stefan Fejes
2019-08-20 15:52:05 +02:00
parent 88084d3d30
commit cc8f1d8a7a
37396 changed files with 4588842 additions and 133 deletions

7
node_modules/babel-helper-flip-expressions/README.md generated vendored Normal file
View File

@@ -0,0 +1,7 @@
# babel-helper-flip-expressions
## Installation
```sh
npm install babel-helper-flip-expressions
```

View File

@@ -0,0 +1,99 @@
"use strict";
var flipSeen = Symbol("flipSeen");
module.exports = function (t) {
return {
hasSeen(node) {
return !!node[flipSeen];
},
// Takes an expressions and determines if it has
// more nodes that could benifit from flipping than not.
shouldFlip(topNode) {
var savings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
visit(topNode);
return savings > 0;
function visit(node) {
if (t.isUnaryExpression(node, { operator: "!" })) {
savings++;
return;
}
if (t.isLogicalExpression(node)) {
visit(node.left);
visit(node.right);
return;
}
if (!(t.isBinaryExpression(node) && t.EQUALITY_BINARY_OPERATORS.indexOf(node.operator) > -1)) {
// Binary expressions wouldn't hurut because we know how to flip them
savings--;
}
}
},
flip(node, resultNotUsed) {
var lastNodeDesc = void 0;
var ret = visit(node);
ret[flipSeen] = true;
if (resultNotUsed && lastNodeDesc) {
var _lastNodeDesc = lastNodeDesc,
parent = _lastNodeDesc.parent,
key = _lastNodeDesc.key;
if (parent && key && t.isUnaryExpression(parent[key], { operator: "!" })) {
parent[key] = parent[key].argument;
}
}
return ret;
function visit(node, parent, key) {
lastNodeDesc = { parent, key };
if (t.isUnaryExpression(node, { operator: "!" })) {
return node.argument;
}
if (t.isLogicalExpression(node)) {
node.operator = node.operator === "&&" ? "||" : "&&";
node.left = visit(node.left, node, "left");
node.right = visit(node.right, node, "right");
return node;
}
if (t.isBinaryExpression(node)) {
var operator = void 0;
switch (node.operator) {
case "!==":
operator = "===";
break;
case "===":
operator = "!==";
break;
case "!=":
operator = "==";
break;
case "==":
operator = "!=";
break;
}
if (operator) {
node.operator = operator;
return node;
}
// Falls through to unary expression
}
return t.unaryExpression("!", node, true);
}
}
};
};

View File

@@ -0,0 +1,47 @@
{
"_from": "babel-helper-flip-expressions@^0.3.0",
"_id": "babel-helper-flip-expressions@0.3.0",
"_inBundle": false,
"_integrity": "sha512-kNGohWmtAG3b7tN1xocRQ5rsKkH/hpvZsMiGOJ1VwGJKhnwzR5KlB3rvKBaBPl5/IGHcopB2JN+r1SUEX1iMAw==",
"_location": "/babel-helper-flip-expressions",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "babel-helper-flip-expressions@^0.3.0",
"name": "babel-helper-flip-expressions",
"escapedName": "babel-helper-flip-expressions",
"rawSpec": "^0.3.0",
"saveSpec": null,
"fetchSpec": "^0.3.0"
},
"_requiredBy": [
"/babel-plugin-minify-guarded-expressions",
"/babel-plugin-minify-simplify"
],
"_resolved": "https://registry.npmjs.org/babel-helper-flip-expressions/-/babel-helper-flip-expressions-0.3.0.tgz",
"_shasum": "f5b6394bd5219b43cf8f7b201535ed540c6e7fa2",
"_spec": "babel-helper-flip-expressions@^0.3.0",
"_where": "/Users/stefanfejes/Projects/30-seconds-of-python-code/node_modules/babel-plugin-minify-guarded-expressions",
"author": {
"name": "amasad"
},
"bugs": {
"url": "https://github.com/babel/minify/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "## Installation",
"homepage": "https://github.com/babel/minify#readme",
"keywords": [
"babel-plugin"
],
"license": "MIT",
"main": "lib/index.js",
"name": "babel-helper-flip-expressions",
"repository": {
"type": "git",
"url": "https://github.com/babel/minify/tree/master/packages/babel-helper-flip-expressions"
},
"version": "0.3.0"
}