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

Commit

Permalink
feat: support SequenceExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Mar 13, 2018
1 parent c7cf98e commit 6202fef
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ const visitors: EvaluateMap = {
if (isIdentifier(node.left)) {
const { name } = node.left;
const varOrNot = scope.$find(name);

if (!varOrNot) {
// here to define global var
const globalScope = scope.$global;
Expand Down Expand Up @@ -1218,7 +1219,11 @@ const visitors: EvaluateMap = {
next(evaluate(path.$child(path.node.argument))); // call next
},
SequenceExpression(path) {
//
let result;
for (const expression of path.node.expressions) {
result = evaluate(path.$child(expression));
}
return result;
},
TaggedTemplateExpression(path) {
const str = path.node.quasi.quasis.map(v => v.value.cooked);
Expand Down
57 changes: 57 additions & 0 deletions test/ecma5/sequence/SequenceExpression.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import test from "ava";

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

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

const a: any = vm.runInContext(
`
var a = (1 , 2);
module.exports = a;
`,
sandbox
);
t.deepEqual(a, 2);
});

test("with call expression", t => {
const sandbox: any = vm.createContext({});

const { a, b }: any = vm.runInContext(
`
var a = (get() , 2);
var b;
function get(){
b = 3;
}
module.exports = {a: a, b: b};
`,
sandbox
);
t.deepEqual(a, 2);
t.deepEqual(b, undefined);
});

test("with call expression", t => {
const sandbox: any = vm.createContext({});

const { a, b }: any = vm.runInContext(
`
var b;
var a = (get() , 2);
function get(){
b = 3;
}
module.exports = {a: a, b: b};
`,
sandbox
);
t.deepEqual(a, 2);
t.deepEqual(b, 3);
});

0 comments on commit 6202fef

Please sign in to comment.