rename minification tests to utility
This commit is contained in:
parent
9e5d94126c
commit
e3daa28e60
@ -1,4 +1,8 @@
|
||||
{
|
||||
"selfContained": "runtime",
|
||||
"unicode-regex": "regex.unicode"
|
||||
"unicode-regex": "regex.unicode",
|
||||
|
||||
"minification.deadCodeElimination": "utility.deadCodeElimination",
|
||||
"minification.removeConsoleCalls": "utility.removeConsole",
|
||||
"minification.removeDebugger": "utility.removeDebugger"
|
||||
}
|
||||
|
||||
@ -103,10 +103,12 @@ export default {
|
||||
"es3.propertyLiterals": require("./es3/property-literals"),
|
||||
"es3.memberExpressionLiterals": require("./es3/member-expression-literals"),
|
||||
|
||||
"minification.removeDebugger": require("./minification/remove-debugger"),
|
||||
"minification.removeConsoleCalls": require("./minification/remove-console-calls"),
|
||||
"minification.deadCodeElimination": require("./minification/dead-code-elimination"),
|
||||
"minification.renameLocalVariables": require("./minification/rename-local-variables"),
|
||||
"utility.removeDebugger": require("./utility/remove-debugger"),
|
||||
"utility.removeConsole": require("./utility/remove-console"),
|
||||
|
||||
"utility.inlineEnvironmentVariables": require("./utility/inline-environment-variables"),
|
||||
"utility.inlineExpressions": require("./utility/inline-expressions"),
|
||||
"utility.deadCodeElimination": require("./utility/dead-code-elimination"),
|
||||
|
||||
_cleanUp: require("./internal/cleanup")
|
||||
};
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
//import t from "../../../types";
|
||||
|
||||
export var optional = true;
|
||||
|
||||
export function Scopable() {
|
||||
//for (var name in scope.bindings) {
|
||||
// scope.rename(name, scope.generateUidIdentifier("a").name);
|
||||
//}
|
||||
}
|
||||
@ -1,27 +1,35 @@
|
||||
import t from "../../../types";
|
||||
|
||||
function toStatements(node) {
|
||||
if (t.isBlockStatement(node)) {
|
||||
var hasBlockScoped = false;
|
||||
|
||||
for (var i = 0; i < node.body.length; i++) {
|
||||
var bodyNode = node.body[i];
|
||||
if (t.isBlockScoped(bodyNode)) hasBlockScoped = true;
|
||||
}
|
||||
|
||||
if (!hasBlockScoped) {
|
||||
return node.body;
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
export var optional = true;
|
||||
|
||||
export function ExpressionStatement(node) {
|
||||
// remove consequence-less expressions such as local variables and literals
|
||||
// note: will remove directives
|
||||
//
|
||||
// var foo = true; foo; -> var foo = true;
|
||||
// "foo"; ->
|
||||
//
|
||||
|
||||
var expr = node.expression;
|
||||
if (t.isLiteral(expr) || (t.isIdentifier(node) && t.hasBinding(node.name))) {
|
||||
this.remove();
|
||||
export function ConditionalExpression(node) {
|
||||
var evaluateTest = t.evaluateTruthy(node.test);
|
||||
if (evaluateTest === true) {
|
||||
return node.consequent;
|
||||
} else if (evaluateTest === false) {
|
||||
return node.alternate;
|
||||
}
|
||||
}
|
||||
|
||||
export var IfStatement = {
|
||||
exit(node) {
|
||||
// todo: in scenarios where we can just return the consequent or
|
||||
// alternate we should drop the block statement if it contains no
|
||||
// block scoped variables
|
||||
|
||||
var consequent = node.consequent;
|
||||
var alternate = node.alternate;
|
||||
var test = node.test;
|
||||
@ -36,7 +44,7 @@ export var IfStatement = {
|
||||
//
|
||||
|
||||
if (evaluateTest === true) {
|
||||
return consequent;
|
||||
return toStatements(consequent);
|
||||
}
|
||||
|
||||
// we can check if a test will be falsy 100% and if so we can inline the
|
||||
@ -48,7 +56,7 @@ export var IfStatement = {
|
||||
|
||||
if (evaluateTest === false) {
|
||||
if (alternate) {
|
||||
return alternate;
|
||||
return toStatements(alternate);
|
||||
} else {
|
||||
return this.remove();
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
import t from "../../../types";
|
||||
|
||||
export var optional = true;
|
||||
|
||||
var match = t.buildMatchMemberExpression("process.env");
|
||||
|
||||
export function MemberExpression(node) {
|
||||
if (match(node.object)) {
|
||||
var key = t.toComputedKey(node, node.property);
|
||||
if (t.isLiteral(key)) {
|
||||
return t.valueToNode(process.env[key.value]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
import t from "../../../types";
|
||||
|
||||
export var optional = true;
|
||||
|
||||
export function Expression(node) {
|
||||
var res = t.evaluate(node);
|
||||
if (res.confident) return t.valueToNode(res.value);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user