diff --git a/src/babel/transformation/transformers/utility/dead-code-elimination.js b/src/babel/transformation/transformers/utility/dead-code-elimination.js index d5c975f6ac..d1ab736f5c 100644 --- a/src/babel/transformation/transformers/utility/dead-code-elimination.js +++ b/src/babel/transformation/transformers/utility/dead-code-elimination.js @@ -21,38 +21,6 @@ export var metadata = { optional: true }; -export function Identifier(node, parent, scope) { - if (!this.isReferenced()) return; - - var binding = scope.getBinding(node.name); - if (!binding || binding.references > 1 || !binding.constant) return; - - var replacement = binding.path.node; - if (t.isVariableDeclarator(replacement)) { - replacement = replacement.init; - } - t.toExpression(replacement); - - scope.removeBinding(node.name); - - binding.path.remove(); - return replacement; -} - -export function FunctionDeclaration(node, parent, scope) { - var bindingInfo = scope.getBinding(node.id.name); - if (bindingInfo && !bindingInfo.referenced) { - this.remove(); - } -} - -export { FunctionDeclaration as ClassDeclaration }; - -export function VariableDeclarator(node, parent, scope) { - if (!t.isIdentifier(node.id) || !scope.isPure(node.init)) return; - FunctionDeclaration.apply(this, arguments); -} - export function ConditionalExpression(node, parent, scope) { var evaluateTest = this.get("test").evaluateTruthy(); if (evaluateTest === true) { diff --git a/src/babel/traversal/binding.js b/src/babel/traversal/binding.js index 86fe6c5ab6..ee2cdddf0a 100644 --- a/src/babel/traversal/binding.js +++ b/src/babel/traversal/binding.js @@ -3,8 +3,6 @@ import * as t from "../types"; export default class Binding { constructor({ identifier, scope, path, kind }) { this.identifier = identifier; - this.references = 0; - this.referenced = false; this.constant = true; this.scope = scope; this.path = path; @@ -60,15 +58,6 @@ export default class Binding { } } - /** - * Description - */ - - reference() { - this.referenced = true; - this.references++; - } - /** * Description */ diff --git a/src/babel/traversal/path/index.js b/src/babel/traversal/path/index.js index 197e1fbdf3..3281a7eda7 100644 --- a/src/babel/traversal/path/index.js +++ b/src/babel/traversal/path/index.js @@ -319,12 +319,6 @@ export default class TraversalPath { var parent = this.parent; if (!parentPath) return; - // we've just removed the last declarator of a variable declaration so there's no point in - // keeping it - if (parentPath.isVariableDeclaration() && parent.declarations.length === 0) { - return parentPath.remove(); - } - // we're the child of an expression statement so we should remove the parent if (parentPath.isExpressionStatement()) { return parentPath.remove(); @@ -656,10 +650,6 @@ export default class TraversalPath { return this.shouldStop; } - /** - * Description - */ - getSibling(key) { return TraversalPath.get(this.parentPath, null, this.parent, this.container, key, this.file); } diff --git a/src/babel/traversal/scope.js b/src/babel/traversal/scope.js index 1d8c15fd5d..3f3c8a54a9 100644 --- a/src/babel/traversal/scope.js +++ b/src/babel/traversal/scope.js @@ -40,12 +40,8 @@ var functionVariableVisitor = { var programReferenceVisitor = { enter(node, parent, scope, state) { - if (t.isReferencedIdentifier(node, parent)) { - var bindingInfo = scope.getBinding(node.name); - if (bindingInfo) { - state.addGlobal(node); - bindingInfo.reference(); - } + if (t.isReferencedIdentifier(node, parent) && !scope.hasBinding(node.name)) { + state.addGlobal(node); } else if (t.isLabeledStatement(node)) { state.addGlobal(node); } else if (t.isAssignmentExpression(node)) { @@ -486,19 +482,6 @@ export default class Scope { this.crawl(); } - /** - * Description - */ - - isPure(node) { - if (t.isIdentifier(node)) { - var bindingInfo = this.getBinding(node.name); - return bindingInfo.constant; - } else { - return t.isPure(node); - } - } - /** * Description */ diff --git a/src/babel/types/alias-keys.json b/src/babel/types/alias-keys.json index 82ab44855c..512badff0a 100644 --- a/src/babel/types/alias-keys.json +++ b/src/babel/types/alias-keys.json @@ -26,9 +26,9 @@ "ExportNamedDeclaration": ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"], "ImportDeclaration": ["Statement", "Declaration", "ModuleDeclaration"], - "ArrowFunctionExpression": ["Scopable", "Function", "Expression", "Pure"], - "FunctionDeclaration": ["Scopable", "Function", "Statement", "Pure", "Declaration"], - "FunctionExpression": ["Scopable", "Function", "Expression", "Pure"], + "ArrowFunctionExpression": ["Scopable", "Function", "Expression"], + "FunctionDeclaration": ["Scopable", "Function", "Statement", "Declaration"], + "FunctionExpression": ["Scopable", "Function", "Expression"], "BlockStatement": ["Scopable", "Statement"], "Program": ["Scopable"], @@ -41,8 +41,8 @@ "SpreadProperty": ["UnaryLike"], "SpreadElement": ["UnaryLike"], - "ClassDeclaration": ["Scopable", "Class", "Pure", "Statement", "Declaration"], - "ClassExpression": ["Scopable", "Class", "Pure", "Expression"], + "ClassDeclaration": ["Scopable", "Class", "Statement", "Declaration"], + "ClassExpression": ["Scopable", "Class", "Expression"], "ForOfStatement": ["Scopable", "Statement", "For", "Loop"], "ForInStatement": ["Scopable", "Statement", "For", "Loop"], @@ -62,7 +62,7 @@ "ConditionalExpression": ["Expression"], "DoExpression": ["Expression"], "Identifier": ["Expression"], - "Literal": ["Expression", "Pure"], + "Literal": ["Expression"], "MemberExpression": ["Expression"], "MetaProperty": ["Expression"], "NewExpression": ["Expression"],