mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-03 12:20:04 +02:00
add some packages
This commit is contained in:
49
node_modules/babel-plugin-transform-simplify-comparison-operators/README.md
generated
vendored
Normal file
49
node_modules/babel-plugin-transform-simplify-comparison-operators/README.md
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
# babel-plugin-transform-simplify-comparison-operators
|
||||
|
||||
Convert `===` and `!==` to `==` and `!=` if their types are inferred to be the same.
|
||||
|
||||
## Example
|
||||
|
||||
**In**
|
||||
|
||||
```javascript
|
||||
typeof foo === "object";
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```javascript
|
||||
typeof foo == "object";
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install babel-plugin-transform-simplify-comparison-operators
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Via `.babelrc` (Recommended)
|
||||
|
||||
**.babelrc**
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": ["transform-simplify-comparison-operators"]
|
||||
}
|
||||
```
|
||||
|
||||
### Via CLI
|
||||
|
||||
```sh
|
||||
babel --plugins transform-simplify-comparison-operators script.js
|
||||
```
|
||||
|
||||
### Via Node API
|
||||
|
||||
```javascript
|
||||
require("@babel/core").transform("code", {
|
||||
plugins: ["transform-simplify-comparison-operators"]
|
||||
});
|
||||
```
|
109
node_modules/babel-plugin-transform-simplify-comparison-operators/lib/index.js
generated
vendored
Normal file
109
node_modules/babel-plugin-transform-simplify-comparison-operators/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function ({
|
||||
types: t
|
||||
}) {
|
||||
// custom implementation of getTypeAnnotation that fixes
|
||||
// the type information that is lost during sequence expression transformation
|
||||
// https://github.com/babel/minify/issues/323
|
||||
function customTypeAnnotation(path) {
|
||||
if (path.typeAnnotation) {
|
||||
return path.typeAnnotation;
|
||||
} // We are not handling the case of literals and other base types
|
||||
// since they are already handled via getTypeAnnotation
|
||||
|
||||
|
||||
const node = path.node;
|
||||
const binding = path.parentPath.scope.getBinding(node.name);
|
||||
const types = [];
|
||||
|
||||
if (binding && binding.constantViolations) {
|
||||
if (binding.identifier.typeAnnotation) {
|
||||
return binding.identifier.typeAnnotation;
|
||||
}
|
||||
|
||||
if (binding.constantViolations) {
|
||||
const violations = binding.constantViolations;
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = violations[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
let violation = _step.value;
|
||||
types.push(violation.getTypeAnnotation());
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (types.length > 0) {
|
||||
return t.createUnionTypeAnnotation(types);
|
||||
}
|
||||
|
||||
return types;
|
||||
} // Based on the type inference in Babel
|
||||
|
||||
|
||||
function baseTypeStrictlyMatches(left, right) {
|
||||
let leftTypes, rightTypes;
|
||||
|
||||
if (t.isIdentifier(left)) {
|
||||
leftTypes = customTypeAnnotation(left);
|
||||
} else if (t.isIdentifier(right)) {
|
||||
rightTypes = customTypeAnnotation(right);
|
||||
} // Early exit
|
||||
|
||||
|
||||
if (t.isAnyTypeAnnotation(leftTypes) || t.isAnyTypeAnnotation(rightTypes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
leftTypes = [].concat(leftTypes, left.getTypeAnnotation());
|
||||
rightTypes = [].concat(rightTypes, right.getTypeAnnotation());
|
||||
leftTypes = t.createUnionTypeAnnotation(leftTypes);
|
||||
rightTypes = t.createUnionTypeAnnotation(rightTypes);
|
||||
|
||||
if (!t.isAnyTypeAnnotation(leftTypes) && t.isFlowBaseAnnotation(leftTypes)) {
|
||||
return leftTypes.type === rightTypes.type;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
name: "transform-simplify-comparison-operators",
|
||||
visitor: {
|
||||
// simplify comparison operations if we're 100% certain
|
||||
// that each value will always be of the same type
|
||||
BinaryExpression(path) {
|
||||
const node = path.node;
|
||||
const op = node.operator;
|
||||
|
||||
if (op !== "===" && op !== "!==") {
|
||||
return;
|
||||
}
|
||||
|
||||
const left = path.get("left");
|
||||
const right = path.get("right");
|
||||
const strictMatch = baseTypeStrictlyMatches(left, right);
|
||||
|
||||
if (strictMatch) {
|
||||
node.operator = node.operator.slice(0, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
};
|
46
node_modules/babel-plugin-transform-simplify-comparison-operators/package.json
generated
vendored
Normal file
46
node_modules/babel-plugin-transform-simplify-comparison-operators/package.json
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"_from": "babel-plugin-transform-simplify-comparison-operators@^6.9.2",
|
||||
"_id": "babel-plugin-transform-simplify-comparison-operators@6.9.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-DA6a+nMpJPA6qYL9Y8ktBAi9VlY=",
|
||||
"_location": "/babel-plugin-transform-simplify-comparison-operators",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "babel-plugin-transform-simplify-comparison-operators@^6.9.2",
|
||||
"name": "babel-plugin-transform-simplify-comparison-operators",
|
||||
"escapedName": "babel-plugin-transform-simplify-comparison-operators",
|
||||
"rawSpec": "^6.9.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^6.9.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/babel-preset-minify"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/babel-plugin-transform-simplify-comparison-operators/-/babel-plugin-transform-simplify-comparison-operators-6.9.2.tgz",
|
||||
"_shasum": "0c0e9afa732924f03aa982fd63c92d0408bd5656",
|
||||
"_spec": "babel-plugin-transform-simplify-comparison-operators@^6.9.2",
|
||||
"_where": "/home/s2/Documents/Code/minifyfromhtml/node_modules/babel-preset-minify",
|
||||
"author": {
|
||||
"name": "amasad"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/babel/minify/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Convert === and !== to == and != if their types are inferred to be the same.",
|
||||
"homepage": "https://github.com/babel/minify#readme",
|
||||
"keywords": [
|
||||
"babel-plugin"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"name": "babel-plugin-transform-simplify-comparison-operators",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/minify/tree/master/packages/babel-plugin-transform-simplify-comparison-operators"
|
||||
},
|
||||
"version": "6.9.2"
|
||||
}
|
Reference in New Issue
Block a user