UNPKG

siphon-cli

Version:

Simple bundler for web applications. 📦🔧🧡

44 lines (43 loc) • 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var __1 = require("../.."); var types_1 = require("../../../../../types"); var minify_1 = require("./minify"); function default_1(ast) { var isUsed = new Map(); function remove_unused(node, path) { path.scope.variables.forEach(function (variable) { if (isUsed.get(variable) === undefined) variable.__unused = false; }); } __1.default.traverse(ast, { Program: remove_unused, BlockStatement: remove_unused, Identifier: function (node, path) { if ((0, minify_1.isNotRenamable)(node, path)) return; if (/Declar/.test(path.parent.type) && path.parent.id === node) return; if (path.scope.variables.has(node.name)) { isUsed.set(path.scope.variables.get(node.name), true); } else path.scope.ancestors.forEach(function (ancestor) { if (ancestor.variables.has(node.name)) isUsed.set(ancestor.variables.get(node.name), true); }); }, ExportNamedDeclaration: function (node, path) { if (node.declaration instanceof types_1.FunctionDeclaration || node.declaration instanceof types_1.ClassDeclaration) { isUsed.set(node.declaration.id, true); } else if (node.declaration instanceof types_1.VariableDeclaration) node.declaration.declarations.forEach(function (decs) { isUsed.set(decs, true); }); }, }); } exports.default = default_1;