askql
askql copied to clipboard
Unable to call object properties that are functions
The following code produces a parsing error when run on the playground
ask {
const sum = fun(a, b) {
a + b
}
const diff = fun(a, b) {
a - b
}
const myMath = { sum, diff }
myMath.sum(2, 2)
}
It works fine, when myMath
is destructured first:
const s = myMath.sum
s(2,2)
Used expression (myMath.sum(2, 2)
) should be translated into
<call
args={
<list>
{2}
{2}
</list>
}
>
<call
name="at"
args={
<list>
<ref name="myMath" />
{"sum"}
</list>
}
/>
</call>
Note that call
in AskJSX can accept either the name
property in args or function expression in its first child.
yesterday, while digging into the parser I had an idea that maybe we just change how .
works: https://github.com/CatchTheTornado/askql/blob/fea7233dd1c6967b7fddd96da6134e3fd92f88f9/src/askscript/parser/askscript.grammar.pegjs#L237 - somehow making it more like the :
I mean adding an option for a MethodCallApplied
transformation instead of KeyExpressionApplied
That's why it works by deconstruction - bc. when deconstructed it gets into: https://github.com/CatchTheTornado/askql/blob/fea7233dd1c6967b7fddd96da6134e3fd92f88f9/src/askscript/parser/askscript.grammar.pegjs#L234
@czerwinskilukasz1 what do you think about this?
@czerwinskilukasz1 we neeed your help! 🙏😁
Ack. I will try to reply tomorrow.
@czerwinskilukasz1 friendly ping :)
@czerwinskilukasz1 another friendly ping ;P
@lukasz-xfaang i've stuck on this :( I really need your help @lukasz-xfaang @czerwinskilukasz1