typir
Version:
General purpose type checking library
54 lines • 2.23 kB
JavaScript
/******************************************************************************
* Copyright 2024 TypeFox GmbH
* This program and the accompanying materials are made available under the
* terms of the MIT License, which is available in the project root.
******************************************************************************/
import { registerInferCurrentTypeRules } from '../../utils/utils-definitions.js';
import { assertTrue } from '../../utils/utils.js';
import { BottomType } from './bottom-type.js';
export const BottomKindName = 'BottomKind';
export class BottomKind {
constructor(services, options) {
this.options = this.collectOptions(options);
this.$name = this.options.$name;
this.services = services;
this.services.infrastructure.Kinds.register(this);
}
collectOptions(options) {
return Object.assign({
// the default values:
$name: BottomKindName, name: 'never' }, options);
}
get(typeDetails) {
const key = this.calculateIdentifier(typeDetails);
return this.services.infrastructure.Graph.getType(key);
}
create(typeDetails) {
assertTrue(this.get(typeDetails) === undefined, 'The bottom type already exists.');
return new BottomConfigurationChainImpl(this.services, this, typeDetails);
}
calculateIdentifier(_typeDetails) {
return this.options.name;
}
}
export function isBottomKind(kind) {
return kind instanceof BottomKind;
}
class BottomConfigurationChainImpl {
constructor(services, kind, typeDetails) {
this.services = services;
this.kind = kind;
this.typeDetails = Object.assign(Object.assign({}, typeDetails), { inferenceRules: [] });
}
inferenceRule(rule) {
this.typeDetails.inferenceRules.push(rule);
return this;
}
finish() {
const bottomType = new BottomType(this.kind, this.kind.calculateIdentifier(this.typeDetails), this.typeDetails);
this.services.infrastructure.Graph.addNode(bottomType);
registerInferCurrentTypeRules(this.typeDetails.inferenceRules, bottomType, this.services);
return bottomType;
}
}
//# sourceMappingURL=bottom-kind.js.map