1
0
mirror of https://github.com/S2-/minifyfromhtml.git synced 2025-08-03 04:10:04 +02:00

add some packages

This commit is contained in:
s2
2018-05-05 13:54:07 +02:00
parent 48c1138518
commit ff6e20677d
3738 changed files with 215920 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
# babel-plugin-minify-dead-code-elimination
Inlines bindings when possible. Tries to evaluate expressions and prunes unreachable as a result.
## Example
**In**
```javascript
function foo() {var x = 1;}
function bar() { var x = f(); }
function baz() {
var x = 1;
console.log(x);
function unused() {
return 5;
}
}
```
**Out**
```javascript
function foo() {}
function bar() { f(); }
function baz() {
console.log(1);
}
```
## Installation
```sh
npm install babel-plugin-minify-dead-code-elimination
```
## Usage
### Via `.babelrc` (Recommended)
**.babelrc**
```json
// without options
{
"plugins": ["minify-dead-code-elimination"]
}
// with options
{
"plugins": ["minify-dead-code-elimination", { "optimizeRawSize": true }]
}
```
### Via CLI
```sh
babel --plugins minify-dead-code-elimination script.js
```
### Via Node API
```javascript
require("@babel/core").transform("code", {
plugins: ["minify-dead-code-elimination"]
});
```
## Options
+ `keepFnName` - prevent plugin from removing function name. Useful for code depending on `fn.name`
+ `keepFnArgs` - prevent plugin from removing function args. Useful for code depending on `fn.length`
+ `keepClassName` - prevent plugin from removing class name. Useful for code depending on `cls.name`
+ `tdz` - Account for TDZ (Temporal Dead Zone)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,48 @@
"use strict";
module.exports = removeUseStrict;
const newIssueUrl = "https://github.com/babel/minify/issues/new";
const useStrict = "use strict";
/**
* Remove redundant use strict
* If the parent has a "use strict" directive, it is not required in
* the children
*
* @param {NodePath} block BlockStatement
*/
function removeUseStrict(block) {
if (!block.isBlockStatement()) {
throw new Error(`Received ${block.type}. Expected BlockStatement. ` + `Please report at ${newIssueUrl}`);
}
const useStricts = getUseStrictDirectives(block); // early exit
if (useStricts.length < 1) return; // only keep the first use strict
if (useStricts.length > 1) {
for (let i = 1; i < useStricts.length; i++) {
useStricts[i].remove();
}
} // check if parent has an use strict
if (hasStrictParent(block)) {
useStricts[0].remove();
}
}
function hasStrictParent(path) {
return path.findParent(parent => parent.isBlockStatement() && isStrict(parent));
}
function isStrict(block) {
return getUseStrictDirectives(block).length > 0;
}
function getUseStrictDirectives(block) {
var dir = block.get("directives");
return Array.isArray(dir) ? dir.filter(function (directive) {
return directive.node.value.value === useStrict;
}) : [];
}

View File

@@ -0,0 +1,52 @@
{
"_from": "babel-plugin-minify-dead-code-elimination@^0.4.1",
"_id": "babel-plugin-minify-dead-code-elimination@0.4.1",
"_inBundle": false,
"_integrity": "sha1-81/PNIk06wqslEUCrTA3KRgu6yE=",
"_location": "/babel-plugin-minify-dead-code-elimination",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "babel-plugin-minify-dead-code-elimination@^0.4.1",
"name": "babel-plugin-minify-dead-code-elimination",
"escapedName": "babel-plugin-minify-dead-code-elimination",
"rawSpec": "^0.4.1",
"saveSpec": null,
"fetchSpec": "^0.4.1"
},
"_requiredBy": [
"/babel-preset-minify"
],
"_resolved": "https://registry.npmjs.org/babel-plugin-minify-dead-code-elimination/-/babel-plugin-minify-dead-code-elimination-0.4.1.tgz",
"_shasum": "f35fcf348934eb0aac944502ad303729182eeb21",
"_spec": "babel-plugin-minify-dead-code-elimination@^0.4.1",
"_where": "/home/s2/Documents/Code/minifyfromhtml/node_modules/babel-preset-minify",
"author": {
"name": "amasad"
},
"bugs": {
"url": "https://github.com/babel/minify/issues"
},
"bundleDependencies": false,
"dependencies": {
"babel-helper-evaluate-path": "^0.4.1",
"babel-helper-mark-eval-scopes": "^0.4.1",
"babel-helper-remove-or-void": "^0.4.1",
"lodash.some": "^4.6.0"
},
"deprecated": false,
"description": "Inlines bindings when possible. Tries to evaluate expressions and prunes unreachable as a result.",
"homepage": "https://github.com/babel/minify#readme",
"keywords": [
"babel-plugin"
],
"license": "MIT",
"main": "lib/index.js",
"name": "babel-plugin-minify-dead-code-elimination",
"repository": {
"type": "git",
"url": "https://github.com/babel/minify/tree/master/packages/babel-plugin-minify-dead-code-elimination"
},
"version": "0.4.1"
}