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,61 @@
# babel-plugin-transform-remove-console
This plugin removes all `console.*` calls.
## Example
**In**
```javascript
console.log("foo");
console.error("bar");
```
**Out**
```javascript
```
## Installation
```sh
npm install babel-plugin-transform-remove-console
```
## Usage
### Via `.babelrc` (Recommended)
**.babelrc**
```json
// without options
{
"plugins": ["transform-remove-console"]
}
```
```json
// with options
{
"plugins": [ ["transform-remove-console", { "exclude": [ "error", "warn"] }] ]
}
```
### Via CLI
```sh
babel --plugins transform-remove-console script.js
```
### Via Node API
```javascript
require("@babel/core").transform("code", {
plugins: ["transform-remove-console"]
});
```
## Options
+ `exclude` - An array of console methods to exclude from removal.

View File

@@ -0,0 +1,82 @@
"use strict";
module.exports = function ({
types: t
}) {
return {
name: "transform-remove-console",
visitor: {
CallExpression(path, state) {
const callee = path.get("callee");
if (!callee.isMemberExpression()) return;
if (isIncludedConsole(callee, state.opts.exclude)) {
// console.log()
if (path.parentPath.isExpressionStatement()) {
path.remove();
} else {
path.replaceWith(createVoid0());
}
} else if (isIncludedConsoleBind(callee, state.opts.exclude)) {
// console.log.bind()
path.replaceWith(createNoop());
}
},
MemberExpression: {
exit(path, state) {
if (isIncludedConsole(path, state.opts.exclude) && !path.parentPath.isMemberExpression()) {
if (path.parentPath.isAssignmentExpression() && path.parentKey === "left") {
path.parentPath.get("right").replaceWith(createNoop());
} else {
path.replaceWith(createNoop());
}
}
}
}
}
};
function isGlobalConsoleId(id) {
const name = "console";
return id.isIdentifier({
name
}) && !id.scope.getBinding(name) && id.scope.hasGlobal(name);
}
function isExcluded(property, excludeArray) {
return excludeArray && excludeArray.some(name => property.isIdentifier({
name
}));
}
function isIncludedConsole(memberExpr, excludeArray) {
const object = memberExpr.get("object");
const property = memberExpr.get("property");
if (isExcluded(property, excludeArray)) return false;
if (isGlobalConsoleId(object)) return true;
return isGlobalConsoleId(object.get("object")) && (property.isIdentifier({
name: "call"
}) || property.isIdentifier({
name: "apply"
}));
}
function isIncludedConsoleBind(memberExpr, excludeArray) {
const object = memberExpr.get("object");
if (!object.isMemberExpression()) return false;
if (isExcluded(object.get("property"), excludeArray)) return false;
return isGlobalConsoleId(object.get("object")) && memberExpr.get("property").isIdentifier({
name: "bind"
});
}
function createNoop() {
return t.functionExpression(null, [], t.blockStatement([]));
}
function createVoid0() {
return t.unaryExpression("void", t.numericLiteral(0));
}
};

View File

@@ -0,0 +1,46 @@
{
"_from": "babel-plugin-transform-remove-console@^6.9.2",
"_id": "babel-plugin-transform-remove-console@6.9.2",
"_inBundle": false,
"_integrity": "sha1-6KDCfVbJUDyhbihPa2Tb1LldIek=",
"_location": "/babel-plugin-transform-remove-console",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "babel-plugin-transform-remove-console@^6.9.2",
"name": "babel-plugin-transform-remove-console",
"escapedName": "babel-plugin-transform-remove-console",
"rawSpec": "^6.9.2",
"saveSpec": null,
"fetchSpec": "^6.9.2"
},
"_requiredBy": [
"/babel-preset-minify"
],
"_resolved": "https://registry.npmjs.org/babel-plugin-transform-remove-console/-/babel-plugin-transform-remove-console-6.9.2.tgz",
"_shasum": "e8a0c27d56c9503ca16e284f6b64dbd4b95d21e9",
"_spec": "babel-plugin-transform-remove-console@^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": "Remove all console.* calls.",
"homepage": "https://github.com/babel/minify#readme",
"keywords": [
"babel-plugin"
],
"license": "MIT",
"main": "lib/index.js",
"name": "babel-plugin-transform-remove-console",
"repository": {
"type": "git",
"url": "https://github.com/babel/minify/tree/master/packages/babel-plugin-transform-remove-console"
},
"version": "6.9.2"
}