69 lines
2.9 KiB
JavaScript
69 lines
2.9 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.Visitor = void 0;
|
|
const utils_1 = require("../utils");
|
|
const interface_1 = require("./interface");
|
|
class Visitor {
|
|
constructor(overrides) {
|
|
Object.defineProperty(this, "overrides", {
|
|
enumerable: true,
|
|
configurable: true,
|
|
writable: true,
|
|
value: void 0
|
|
});
|
|
this.overrides = overrides;
|
|
}
|
|
static from(visitor) {
|
|
if (visitor instanceof Visitor || (0, interface_1.isVisitor)(visitor)) {
|
|
return visitor;
|
|
}
|
|
return new this(visitor);
|
|
}
|
|
visitBoolean(value) {
|
|
var _a, _b, _c;
|
|
return (_c = (_b = (_a = this.overrides) === null || _a === void 0 ? void 0 : _a.visitBoolean) === null || _b === void 0 ? void 0 : _b.call(_a, value)) !== null && _c !== void 0 ? _c : value;
|
|
}
|
|
visitNumber(value) {
|
|
var _a, _b, _c;
|
|
return (_c = (_b = (_a = this.overrides) === null || _a === void 0 ? void 0 : _a.visitNumber) === null || _b === void 0 ? void 0 : _b.call(_a, value)) !== null && _c !== void 0 ? _c : value;
|
|
}
|
|
visitBigInt(value) {
|
|
var _a, _b, _c;
|
|
return (_c = (_b = (_a = this.overrides) === null || _a === void 0 ? void 0 : _a.visitBigInt) === null || _b === void 0 ? void 0 : _b.call(_a, value)) !== null && _c !== void 0 ? _c : value;
|
|
}
|
|
visitString(value) {
|
|
var _a, _b, _c;
|
|
return (_c = (_b = (_a = this.overrides) === null || _a === void 0 ? void 0 : _a.visitString) === null || _b === void 0 ? void 0 : _b.call(_a, value)) !== null && _c !== void 0 ? _c : value;
|
|
}
|
|
visitSymbol(value) {
|
|
var _a, _b, _c;
|
|
return (_c = (_b = (_a = this.overrides) === null || _a === void 0 ? void 0 : _a.visitSymbol) === null || _b === void 0 ? void 0 : _b.call(_a, value)) !== null && _c !== void 0 ? _c : value;
|
|
}
|
|
visitNull() {
|
|
var _a, _b, _c;
|
|
return (_c = (_b = (_a = this.overrides) === null || _a === void 0 ? void 0 : _a.visitNull) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : null;
|
|
}
|
|
visitObject(access) {
|
|
var _a, _b;
|
|
if ((0, utils_1.isFunction)((_a = this.overrides) === null || _a === void 0 ? void 0 : _a.visitObject)) {
|
|
return (_b = this.overrides) === null || _b === void 0 ? void 0 : _b.visitObject(access);
|
|
}
|
|
const result = [];
|
|
for (const entry of access) {
|
|
result.push(entry);
|
|
}
|
|
return Object.fromEntries(result);
|
|
}
|
|
visitIterable(access) {
|
|
var _a, _b;
|
|
if ((0, utils_1.isFunction)((_a = this.overrides) === null || _a === void 0 ? void 0 : _a.visitIterable)) {
|
|
return (_b = this.overrides) === null || _b === void 0 ? void 0 : _b.visitIterable(access);
|
|
}
|
|
const result = [];
|
|
for (const element of access) {
|
|
result.push(element);
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
exports.Visitor = Visitor;
|