UNPKG

@sequeljs/ast

Version:

A SQL AST manager for JavaScript

50 lines 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Attribute_1 = require("../attributes/Attribute"); const VisitorError_1 = require("../errors/VisitorError"); class Visitor { accept(object, collector) { return this.visit(object, collector); } visit(object, collector) { let objectType; if (object === null) { objectType = 'Null'; } else if (typeof object === 'bigint') { objectType = 'BigInt'; } else if (typeof object === 'boolean') { objectType = 'Boolean'; } else if (typeof object === 'number') { objectType = 'Number'; } else if (typeof object === 'string') { objectType = 'String'; } else if (typeof object === 'symbol') { objectType = 'Symbol'; } else if (object instanceof Attribute_1.default) { objectType = `Attributes${object.constructor.name}`; } else { let prototype = object.constructor; objectType = prototype.name; while (!(`visit${objectType}` in this.constructor.prototype) && objectType !== '') { prototype = Object.getPrototypeOf(prototype); objectType = prototype.name; } } if (objectType !== '' && `visit${objectType}` in this.constructor.prototype) { const visitFunction = this.constructor.prototype[`visit${objectType}`].bind(this); return visitFunction(object, collector); } throw new VisitorError_1.default(`Cannot visit ${objectType}`); } } exports.default = Visitor; //# sourceMappingURL=Visitor.js.map