Skip to content

Commit

Permalink
Merge pull request #48 from wcho21/dev
Browse files Browse the repository at this point in the history
support better error handling
  • Loading branch information
wcho21 authored Jan 31, 2024
2 parents 96a5780 + b49c6b6 commit 5301e07
Show file tree
Hide file tree
Showing 59 changed files with 3,571 additions and 2,734 deletions.
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

0 comments on commit 5301e07

Please sign in to comment.