@litert/typeguard
Version:
An easy and powerful data validation code generator by JavaScript.
63 lines • 2.14 kB
JavaScript
"use strict";
/**
* Copyright 2023 Angus Fenying <fenying@litert.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Context = void 0;
const i = require("./Internal");
class Context {
constructor(vName, vTraceName, vTracePrefix, typeSlotName, referredTypes) {
this.vName = vName;
this.vTraceName = vTraceName;
this.vTracePrefix = vTracePrefix;
this.typeSlotName = typeSlotName;
this.referredTypes = referredTypes;
this.tracePath = '';
this.stack = [];
this.vCursor = 0;
this.flags = {};
}
trap(subjChanged = false) {
this.stack.push({
vName: this.vName,
flags: this.flags,
tracePath: this.tracePath,
});
const prevFlags = this.flags;
this.flags = {};
for (const key in prevFlags) {
if (subjChanged) {
if (prevFlags[key] === i.EFlagValue.ELEMENT_INHERIT) {
this.flags[key] = prevFlags[key];
}
}
else if (prevFlags[key] === i.EFlagValue.INHERIT ||
prevFlags[key] === i.EFlagValue.ELEMENT_INHERIT) {
this.flags[key] = prevFlags[key];
}
}
}
popUp() {
const prev = this.stack.pop();
if (!prev) {
throw new Error('Failed to pop stack.');
}
this.flags = prev.flags;
this.vName = prev.vName;
this.tracePath = prev.tracePath;
}
}
exports.Context = Context;
//# sourceMappingURL=Context.js.map