UNPKG

siphon-cli

Version:

Simple bundler for web applications. 📦🔧🧡

76 lines (75 loc) • 3.38 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); var types_1 = require("../../../../types"); var config_1 = require("./config"); var Traverser = (function () { function Traverser() { } Traverser.prototype.traverse = function (node, config) { return this.visit(node, __assign({}, config), { parent: node, scope: new config_1.Scope(node), route: [node] }); }; Traverser.prototype.visit = function (node, config, path) { var _this = this; var _a, _b, _c, _d; if (/Block/.test(node.type)) { path.scope = new config_1.Scope(node, path.scope); } switch (true) { case node instanceof types_1.FunctionDeclaration: case node instanceof types_1.VariableDeclarator && !/For/.test(path.parent.type): case node instanceof types_1.ClassDeclaration: path.scope.variables.set(node.id.name, node.id); break; case node instanceof types_1.BlockStatement && /Function/.test(path.parent.type): var parent_1 = path.parent; for (var _i = 0, _e = parent_1.params; _i < _e.length; _i++) { var param = _e[_i]; switch (param.type) { case "Identifier": path.scope.variables.set(param.name, param); break; case "AssignmentPattern": path.scope.variables.set(param.left.name, param.left); break; case "RestElement": path.scope.variables.set(param.argument.name, param.argument); } } break; } Object.keys(node).forEach(function (key) { if (node[key] instanceof Array) { for (var i = 0; node[key][i]; i++) { if (node[key][i] instanceof types_1.JSNode) { node[key][i] = _this.visit(node[key][i], config, { parent: node, scope: path.scope, route: path.route, }); } } } else if (node[key] instanceof types_1.JSNode) { node[key] = _this.visit(node[key], config, { parent: node, scope: path.scope, route: path.route, }); } }); return ((_d = (_b = ((_a = config["enter"]) !== null && _a !== void 0 ? _a : (function () { }))(node, path)) !== null && _b !== void 0 ? _b : ((_c = config[node.type]) !== null && _c !== void 0 ? _c : (function () { }))(node, path)) !== null && _d !== void 0 ? _d : node); }; return Traverser; }()); exports.default = Traverser;