remove dead code
This commit is contained in:
parent
f639f4bea7
commit
a195701de2
@ -34,13 +34,13 @@ export function ReferencedIdentifier(node, parent, scope) {
|
||||
if (!replacement) return;
|
||||
|
||||
// ensure it's a "pure" type
|
||||
if (!scope.isPure(replacement)) return;
|
||||
if (!scope.isPure(replacement, true)) return;
|
||||
|
||||
if (t.isClass(replacement) || t.isFunction(replacement)) {
|
||||
// don't change this if it's in a different scope, this can be bad
|
||||
// for performance since it may be inside a loop or deeply nested in
|
||||
// hot code
|
||||
if (!binding.path.scope.parent.is(scope)) return;
|
||||
if (binding.path.scope.parent !== scope) return;
|
||||
}
|
||||
|
||||
if (this.findParent((node) => node === replacement)) {
|
||||
@ -63,7 +63,7 @@ export function FunctionDeclaration(node, parent, scope) {
|
||||
export { FunctionDeclaration as ClassDeclaration };
|
||||
|
||||
export function VariableDeclarator(node, parent, scope) {
|
||||
if (!t.isIdentifier(node.id) || !scope.isPure(node.init)) return;
|
||||
if (!t.isIdentifier(node.id) || !scope.isPure(node.init, true)) return;
|
||||
FunctionDeclaration.apply(this, arguments);
|
||||
}
|
||||
|
||||
|
||||
@ -5,8 +5,7 @@ export var metadata = {
|
||||
optional: true
|
||||
};
|
||||
|
||||
export function Identifier(node, parent, scope, file) {
|
||||
if (!this.isReferenced()) return;
|
||||
export function ReferencedIdentifier(node, parent, scope, file) {
|
||||
if (scope.hasBinding(node.name)) return;
|
||||
|
||||
// get the closest declaration to offer as a suggestion
|
||||
|
||||
@ -69,7 +69,7 @@ export default class PathHoister {
|
||||
if (scope.path.isFunction()) {
|
||||
if (this.hasOwnParamBindings(scope)) {
|
||||
// should ignore this scope since it's ourselves
|
||||
if (this.scope.is(scope)) return;
|
||||
if (this.scope === scope) return;
|
||||
|
||||
// needs to be attached to the body
|
||||
return scope.path.get("body").get("body")[0];
|
||||
|
||||
@ -2,8 +2,8 @@ import * as t from "../../../types";
|
||||
|
||||
export var ReferencedIdentifier = {
|
||||
types: ["Identifier", "JSXIdentifier"],
|
||||
checkPath(path, opts) {
|
||||
return t.isReferencedIdentifier(path.node, path.parent, opts);
|
||||
checkPath({ node, parent }, opts) {
|
||||
return (t.isIdentifier(node, opts) || t.isJSXIdentifier(node, opts)) && t.isReferenced(node, parent);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -137,7 +137,7 @@ export default class Scope {
|
||||
if (cached && cached.parent === parent) {
|
||||
return cached;
|
||||
} else {
|
||||
//path.setData("scope", this);
|
||||
path.setData("scope", this);
|
||||
}
|
||||
|
||||
this.parent = parent;
|
||||
@ -149,7 +149,7 @@ export default class Scope {
|
||||
}
|
||||
|
||||
static globals = flatten([globals.builtin, globals.browser, globals.node].map(Object.keys));
|
||||
static contextVariables = ["this", "arguments", "super"];
|
||||
static contextVariables = ["this", "arguments", "super", "undefined"];
|
||||
|
||||
/**
|
||||
* Description
|
||||
@ -546,12 +546,14 @@ export default class Scope {
|
||||
* Description
|
||||
*/
|
||||
|
||||
isPure(node) {
|
||||
isPure(node, constantsOnly) {
|
||||
if (t.isIdentifier(node)) {
|
||||
var bindingInfo = this.getBinding(node.name);
|
||||
return bindingInfo && bindingInfo.constant;
|
||||
return !!bindingInfo && (!constantsOnly || (constantsOnly && bindingInfo.constant));
|
||||
} else if (t.isClass(node)) {
|
||||
return !node.superClass;
|
||||
} else if (t.isBinary(node)) {
|
||||
return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly);
|
||||
} else {
|
||||
return t.isPure(node);
|
||||
}
|
||||
|
||||
@ -56,29 +56,3 @@ getBindingIdentifiers.keys = {
|
||||
ArrayPattern: ["elements"],
|
||||
ObjectPattern: ["properties"]
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
export function getLastStatements(node: Object): Array<Object> {
|
||||
var nodes = [];
|
||||
|
||||
var add = function (node) {
|
||||
nodes = nodes.concat(getLastStatements(node));
|
||||
};
|
||||
|
||||
if (t.isIfStatement(node)) {
|
||||
add(node.consequent);
|
||||
add(node.alternate);
|
||||
} else if (t.isFor(node) || t.isWhile(node)) {
|
||||
add(node.body);
|
||||
} else if (t.isProgram(node) || t.isBlockStatement(node)) {
|
||||
add(node.body[node.body.length - 1]);
|
||||
} else if (t.isLoop()) {
|
||||
} else if (node) {
|
||||
nodes.push(node);
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
@ -112,14 +112,6 @@ export function isReferenced(node: Object, parent: Object): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the input `node` is an `Identifier` and `isReferenced`.
|
||||
*/
|
||||
|
||||
export function isReferencedIdentifier(node: Object, parent: Object, opts?: Object): boolean {
|
||||
return (t.isIdentifier(node, opts) || t.isJSXIdentifier(node, opts)) && t.isReferenced(node, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the input `name` is a valid identifier name
|
||||
* and isn't a reserved word.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user