KoryNunn / presh

An immutable interpreted expression language.
MIT License
6 stars 2 forks source link

Function calls fail under certain conditions #20

Closed markwylde closed 3 years ago

markwylde commented 3 years ago

When calling a function inside presh (e.g. add(one(), { a: 2 }), if one argument contains a function result, and the next argument immediately after is an object, the javascript function will be given only 1 argument of [Function: resultFn]

Example to reproduce:

const presh = require('presh')

const result = presh(`add(2, 3, one(), { a: 2 }, 2, 3)`, {
  one: () => 1,
  add: function (...args) {
    console.log(...args)
    return 1
  }
})

console.log(result)

Outputs:

$ node test.js         
2 3 [Function: resultFn] 2 3
{ type: 'value', context: undefined, value: 1, _value: {} }
markwylde commented 3 years ago

The solution (possibly temporary) to this is to only allow functions to be defined if the opening brackets are immediately after the parenthesis.

For example:

example () { }

Would need to be changed to:

example (){ }