Skip to content

Commit

Permalink
Fixed #405: Parser throws error when defining a function in a multili…
Browse files Browse the repository at this point in the history
…ne expression
  • Loading branch information
josdejong committed Jul 11, 2015
1 parent 0475924 commit 936386c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/expression/node/FunctionAssignmentNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function factory (type, config, load, typed) {
' };' +
' fn.syntax = "' + this.name + '(' + this.params.join(', ') + ')";' +
' return fn;' +
' })();';
' })()';
};

/**
Expand Down
12 changes: 12 additions & 0 deletions test/expression/parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ describe('parse', function() {
assert.deepEqual(parse('2*-\n3').compile().eval(), -6);
});

it('should parse multiple function assignments', function() {
var scope = {};
parse('f(x)=x*2;g(x)=x*3').compile().eval(scope);
assert.equal(scope.f(2), 4);
assert.equal(scope.g(2), 6);

var scope2 = {};
parse('a=2;f(x)=x^a;').compile().eval(scope2);
assert.equal(scope2.a, 2);
assert.equal(scope2.f(3), 9);
});

it('should spread a function over multiple lines', function() {
assert.deepEqual(parse('add(\n4\n,\n2\n)').compile().eval(), 6);
});
Expand Down

0 comments on commit 936386c

Please sign in to comment.