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:
60
node_modules/babel-plugin-transform-merge-sibling-variables/README.md
generated
vendored
Normal file
60
node_modules/babel-plugin-transform-merge-sibling-variables/README.md
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
# babel-plugin-transform-merge-sibling-variables
|
||||
|
||||
Merge sibling variables into one.
|
||||
|
||||
## Example
|
||||
|
||||
**In**
|
||||
|
||||
```javascript
|
||||
// merge into a single VariableDeclaration
|
||||
var foo = "bar";
|
||||
var bar = "foo";
|
||||
foobar();
|
||||
|
||||
// merge into the next for loop
|
||||
var i = 0;
|
||||
for (var x = 0; x < 10; x++) {}
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```javascript
|
||||
var foo = "bar",
|
||||
bar = "foo";
|
||||
foobar();
|
||||
|
||||
for (var i = 0, x = 0; x < 10; x++) {}
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install babel-plugin-transform-merge-sibling-variables
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Via `.babelrc` (Recommended)
|
||||
|
||||
**.babelrc**
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": ["transform-merge-sibling-variables"]
|
||||
}
|
||||
```
|
||||
|
||||
### Via CLI
|
||||
|
||||
```sh
|
||||
babel --plugins transform-merge-sibling-variables script.js
|
||||
```
|
||||
|
||||
### Via Node API
|
||||
|
||||
```javascript
|
||||
require("@babel/core").transform("code", {
|
||||
plugins: ["transform-merge-sibling-variables"]
|
||||
});
|
||||
```
|
109
node_modules/babel-plugin-transform-merge-sibling-variables/lib/index.js
generated
vendored
Normal file
109
node_modules/babel-plugin-transform-merge-sibling-variables/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function ({
|
||||
types: t
|
||||
}) {
|
||||
function liftDeclaration(path, body, kind) {
|
||||
if (body[0] && body[0].isVariableDeclaration({
|
||||
kind: kind
|
||||
})) {
|
||||
if (body[0].node.declarations.length > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (body[1] && body[1].isVariableDeclaration({
|
||||
kind: kind
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
|
||||
const firstNode = body[0].node.declarations[0];
|
||||
|
||||
if (!t.isIdentifier(firstNode.id) || !firstNode.init) {
|
||||
return;
|
||||
}
|
||||
|
||||
const init = path.get("init");
|
||||
|
||||
if (!init.isVariableDeclaration({
|
||||
kind: kind
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
|
||||
init.pushContainer("declarations", t.variableDeclarator(firstNode.id));
|
||||
body[0].replaceWith(t.assignmentExpression("=", t.clone(firstNode.id), t.clone(firstNode.init)));
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
name: "transform-merge-sibling-variables",
|
||||
visitor: {
|
||||
ForStatement(path) {
|
||||
// Lift declarations to the loop initializer
|
||||
let body = path.get("body");
|
||||
body = body.isBlockStatement() ? body.get("body") : [body];
|
||||
liftDeclaration(path, body, "var");
|
||||
liftDeclaration(path, body, "let");
|
||||
},
|
||||
|
||||
VariableDeclaration: {
|
||||
enter: [// concat variables of the same kind with their siblings
|
||||
function (path) {
|
||||
if (!path.inList) {
|
||||
return;
|
||||
}
|
||||
|
||||
const node = path.node;
|
||||
let sibling = path.getSibling(path.key + 1);
|
||||
let declarations = [];
|
||||
|
||||
while (sibling.isVariableDeclaration({
|
||||
kind: node.kind
|
||||
})) {
|
||||
declarations = declarations.concat(sibling.node.declarations);
|
||||
sibling.remove();
|
||||
sibling = path.getSibling(path.key + 1);
|
||||
}
|
||||
|
||||
if (declarations.length > 0) {
|
||||
path.replaceWith(t.variableDeclaration(node.kind, [...node.declarations, ...declarations]));
|
||||
}
|
||||
}, // concat `var` declarations next to for loops with it's initialisers.
|
||||
// block-scoped `let` and `const` are not moved because the for loop
|
||||
// is a different block scope.
|
||||
function (path) {
|
||||
if (!path.inList) {
|
||||
return;
|
||||
}
|
||||
|
||||
const node = path.node;
|
||||
|
||||
if (node.kind !== "var") {
|
||||
return;
|
||||
}
|
||||
|
||||
const next = path.getSibling(path.key + 1);
|
||||
|
||||
if (!next.isForStatement()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const init = next.get("init");
|
||||
|
||||
if (!init.isVariableDeclaration({
|
||||
kind: node.kind
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
|
||||
const declarations = node.declarations.concat(init.node.declarations); // temporary workaround to forces babel recalculate scope,
|
||||
// references and binding until babel/babel#4818 resolved
|
||||
|
||||
path.remove();
|
||||
init.replaceWith(t.variableDeclaration("var", declarations));
|
||||
}]
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
46
node_modules/babel-plugin-transform-merge-sibling-variables/package.json
generated
vendored
Normal file
46
node_modules/babel-plugin-transform-merge-sibling-variables/package.json
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"_from": "babel-plugin-transform-merge-sibling-variables@^6.9.2",
|
||||
"_id": "babel-plugin-transform-merge-sibling-variables@6.9.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-mUqQBKecefDJHEluii28fptz97Q=",
|
||||
"_location": "/babel-plugin-transform-merge-sibling-variables",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "babel-plugin-transform-merge-sibling-variables@^6.9.2",
|
||||
"name": "babel-plugin-transform-merge-sibling-variables",
|
||||
"escapedName": "babel-plugin-transform-merge-sibling-variables",
|
||||
"rawSpec": "^6.9.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^6.9.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/babel-preset-minify"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/babel-plugin-transform-merge-sibling-variables/-/babel-plugin-transform-merge-sibling-variables-6.9.2.tgz",
|
||||
"_shasum": "994a9004a79c79f0c91c496e8a2dbc7e9b73f7b4",
|
||||
"_spec": "babel-plugin-transform-merge-sibling-variables@^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": "Merge sibling variables into one.",
|
||||
"homepage": "https://github.com/babel/minify#readme",
|
||||
"keywords": [
|
||||
"babel-plugin"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"name": "babel-plugin-transform-merge-sibling-variables",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/minify/tree/master/packages/babel-plugin-transform-merge-sibling-variables"
|
||||
},
|
||||
"version": "6.9.2"
|
||||
}
|
Reference in New Issue
Block a user