Skip to content
This repository has been archived by the owner on Sep 10, 2023. It is now read-only.

Commit

Permalink
feat: support for in
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Mar 4, 2018
1 parent 8dea4a0 commit 385ef60
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ const evaluate_map = {
for (const value in evaluate(node.right, scope)) {
const new_scope = new Scope("loop", scope);
new_scope.invasived = true;
scope.$declar(kind, name, value);

new_scope.$declar(kind, name, value);

const result = evaluate(node.body, new_scope);
if (result === BREAK_SINGAL) {
break;
Expand Down
27 changes: 27 additions & 0 deletions test/ForInStatement.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import test from "ava";
import * as fs from "fs";

import vm from "../src/vm";

test("ForInStatement-1", t => {
const sandbox: any = vm.createContext({});

const obj: any = vm.runInContext(
`
const obj = {
1: false,
2: false
};
for (let attr in obj) {
obj[attr] = true;
}
module.exports = obj;
`,
sandbox
);

t.true(obj[1]);
t.true(obj[2]);
});

0 comments on commit 385ef60

Please sign in to comment.