UNPKG

typhonjs-ast-walker

Version:

Provides a simple Javascript AST traversal utility that traverses all nodes / children regardless of type.

53 lines (39 loc) 1.44 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; exports.onPluginLoad = onPluginLoad; var _ASTWalker = require('./ASTWalker.js'); var _ASTWalker2 = _interopRequireDefault(_ASTWalker); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Default walker instance. * @type {ASTWalker} */ var walker = new _ASTWalker2.default(); /** * Provides a default ASTWalker instance. */ exports.default = walker; /** * Wires up walker on the plugin eventbus. * * @param {PluginEvent} ev - The plugin event. * * @see https://www.npmjs.com/package/typhonjs-plugin-manager * @ignore */ function onPluginLoad(ev) { var eventbus = ev.eventbus; var eventPrepend = 'typhonjs'; var options = ev.pluginOptions; // Apply any plugin options. if ((typeof options === 'undefined' ? 'undefined' : _typeof(options)) === 'object') { // If `eventPrepend` is defined then it is prepended before all event bindings. if (typeof options.eventPrepend === 'string') { eventPrepend = options.eventPrepend + ':'; } } eventbus.on(eventPrepend + ':ast:walker:traverse', walker.traverse, walker); }