Skip to content

Commit

Permalink
bla
Browse files Browse the repository at this point in the history
  • Loading branch information
keyz committed Apr 17, 2016
1 parent d9dbe24 commit f27b9c8
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 153 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
},
"dependencies": {
"babylon": "^6.7.0",
"fbjs": "^0.8.0",
"immutable": "^3.7.6"
},
"jest": {
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/babylon",
"<rootDir>/node_modules/immutable",
"<rootDir>/node_modules/fbjs",
"<rootDir>/src/utils"
]
}
Expand Down
148 changes: 0 additions & 148 deletions src/Interp.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/Interp/ExpressionInterp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
* https://github.com/estree/estree/blob/master/spec.md#expressions
*/
import {
// emptyEnv,
lookupEnv,
// extendEnv,
} from '../Environment';

import {
Expand Down
12 changes: 9 additions & 3 deletions src/Interp/StatementInterp.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import invariant from 'fbjs/lib/invariant';

import { interp as expInterp } from './ExpressionInterp';
import { extendEnv } from '../Environment';

Expand All @@ -13,12 +15,14 @@ const interp = (exp, env) => {

return expInterp(argument, currentEnv); // return!
}

case 'VariableDeclaration': {
const { kind, declarations } = currentExp;

if (kind !== 'const') {
throw new Error(`unsupported VariableDeclaration kind ${kind}`);
}
invariant(
kind === 'const',
`unsupported VariableDeclaration kind ${kind}`,
);

for (let j = 0; j < declarations.length; j++) {
const { id, init } = declarations[j];
Expand All @@ -28,10 +32,12 @@ const interp = (exp, env) => {
}
continue;
}

case 'ExpressionStatement': {
expInterp(currentExp.expression, currentEnv);
continue;
}

default: {
throw new Error(`unsupported BlockStatement type ${currentExp.type}`);
}
Expand Down
33 changes: 33 additions & 0 deletions src/Interp/__tests__/ExpressionInterp-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ describe('Interp', () => {
expect(interpExp('null')).toBe(null);
});

it('undefined', () => {
expect(interpExp('undefined')).toBe(void 0);
});


it('NumericLiteral', () => {
expect(interpExp('3.123')).toBe(3.123);
expect(interpExp('424')).toBe(424);
Expand Down Expand Up @@ -127,4 +132,32 @@ describe('Interp', () => {
return y + 12;
})()); // eslint-disable-line arrow-body-style
});

it('should make correct closures', () => {
expect(interpExp(`(() => {
const adder = (x) => (y) => x + y;
const add3 = adder(3);
return add3(39);
})()`)).toBe((() => {
const adder = (x) => (y) => x + y;
const add3 = adder(3);
return add3(39);
})());
});

it('should make correct closures', () => {
expect(interpExp(`(() => {
const x = 100;
const y = 200;
const adder = (x) => (y) => x + y;
const add3 = adder(3);
return add3(39);
})()`)).toBe((() => {
const x = 100; // eslint-disable-line no-unused-vars
const y = 200; // eslint-disable-line no-unused-vars
const adder = (x) => (y) => x + y; // eslint-disable-line no-shadow
const add3 = adder(3);
return add3(39);
})());
});
});
File renamed without changes.

0 comments on commit f27b9c8

Please sign in to comment.