Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support better error handling #48

Merged
merged 7 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/index.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
],
"devDependencies": {
"@types/jest": "^29.5.10",
"@types/node": "^20.11.6",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"typescript": "^5.3.2",
Expand Down
65 changes: 34 additions & 31 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/evaluator/environment/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Evaluated } from "../evaluated";
import type { Value } from "../value";
import Environment from "./";

describe("set()", () => {
it("set name and value", () => {
const env = new Environment();
const varName = "foo";
const varValue = {} as Evaluated;
const varValue = {} as Value;

expect(() => env.set(varName, varValue)).not.toThrow();
});
Expand All @@ -15,7 +15,7 @@ describe("get()", () => {
it("get value after setting the value", () => {
const env = new Environment();
const varName = "foo";
const varValue = {} as Evaluated;
const varValue = {} as Value;

env.set(varName, varValue);

Expand All @@ -33,7 +33,7 @@ describe("get()", () => {
describe("linked environment", () => {
it("set super environment and get via sub environment", () => {
const varNameInSuper = "foo";
const varValueInSuper = {} as Evaluated;
const varValueInSuper = {} as Value;

const superEnv = new Environment();
superEnv.set(varNameInSuper, varValueInSuper);
Expand Down
10 changes: 5 additions & 5 deletions src/evaluator/environment/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Evaluated } from "../evaluated";
import type { Value } from "../value";

export interface EnvironmentType {
get: (name: string) => Evaluated | null;
set: (name: string, value: Evaluated) => void;
get: (name: string) => Value | null;
set: (name: string, value: Value) => void;
}

export default class Environment implements EnvironmentType {
Expand All @@ -14,7 +14,7 @@ export default class Environment implements EnvironmentType {
this.table = new Map<string, any>;
}

get(name: string): Evaluated | null {
get(name: string): Value | null {
// return if found in current environment
const fetched = this.table.get(name);
if (fetched !== undefined) {
Expand All @@ -28,7 +28,7 @@ export default class Environment implements EnvironmentType {
return this.superEnvironment.get(name);
}

set(name: string, value: Evaluated): void {
set(name: string, value: Value): void {
this.table.set(name, value);
}
}
Loading
Loading