Skip to content
Open
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
14 changes: 7 additions & 7 deletions final/test/arrow-function/ArrowFunctionExpression.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const test = require('ava');
const { Scope, customEval } = require('../../eval');
const test = require("ava");
const { Scope, customEval } = require("../../eval");

test("ArrowFunctionExpression-1", t => {
test("ArrowFunctionExpression-1", (t) => {
const scope = new Scope({
name: "world"
name: "world",
});

const func = customEval(
Expand All @@ -22,7 +22,7 @@ module.exports = func;
t.deepEqual(func(), "hello world");
});

test("ArrowFunctionExpression-2", t => {
test("ArrowFunctionExpression-2", (t) => {
const scope = new Scope();

const func = customEval(
Expand All @@ -36,11 +36,11 @@ module.exports = func;

t.true(typeof func === "function");
t.deepEqual(func.length, 0);
t.deepEqual(func.name, "");
t.deepEqual(func.name, "func");
t.deepEqual(func(), "hello undefined");
});

test("ArrowFunctionExpression-3", t => {
test("ArrowFunctionExpression-3", (t) => {
const scope = new Scope();

const func = customEval(
Expand Down
27 changes: 24 additions & 3 deletions final/test/this/ThisExpression.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const test = require('ava');
const { customEval, Scope } = require('../../eval');
const test = require("ava");
const { customEval, Scope } = require("../../eval");

test("ThisExpression", t => {
test("ThisExpression", (t) => {
const scope = new Scope();

const func = customEval(
Expand All @@ -22,3 +22,24 @@ module.exports = t;

t.deepEqual(ctx.name, "hello");
});

test("ThisNestExpression", (t) => {
const func = customEval(`
function f(){
let b = 1;
let a = {
b:2,
c: ()=>{
if(this) this.b += 1
},
d: function() {
if(this) this.b += 1
}
}
a.d();
return [a.b , b];
}
module.exports = f;
`);
t.deepEqual(func(), [3, 1]);
});