squiggle/packages/squiggle-lang/src/js/SqModule.ts

31 lines
813 B
TypeScript
Raw Normal View History

2022-08-27 17:46:43 +00:00
import * as RSModuleValue from "../rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Module.gen";
2022-08-28 17:45:15 +00:00
import { SqModuleValue, wrapValue } from "./SqValue";
import { SqValueLocation } from "./SqValueLocation";
2022-08-27 17:46:43 +00:00
2022-08-28 16:19:44 +00:00
export class SqModule {
constructor(
private _value: RSModuleValue.squiggleValue_Module,
public location: SqValueLocation
) {}
2022-08-28 17:45:15 +00:00
entries() {
return RSModuleValue.getKeyValuePairs(this._value).map(
([k, v]) => [k, wrapValue(v, this.location.extend(k))] as const
2022-08-28 17:45:15 +00:00
);
}
asValue() {
return new SqModuleValue(
RSModuleValue.toSquiggleValue(this._value),
this.location
);
2022-08-28 17:45:15 +00:00
}
get(k: string) {
const v = RSModuleValue.get(this._value, k);
return v === undefined || v === null
? undefined
: wrapValue(v, this.location.extend(k));
}
2022-08-27 17:46:43 +00:00
}