Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot call functions returned by functions #587

Closed
phillipskevin opened this issue Sep 6, 2018 · 4 comments
Closed

Cannot call functions returned by functions #587

phillipskevin opened this issue Sep 6, 2018 · 4 comments
Assignees

Comments

@phillipskevin
Copy link
Contributor

This template:

  stache("<p>{{foo()()}}</p>")({
    foo() {
      return () => {
        return "Hello"
      }
    }
  });

...gives this error:

Uncaught Error: Unable to understand expression foo()()

@phillipskevin
Copy link
Contributor Author

This makes things like <p on:click="scope.find('foo')()"> impossible.

@justinbmeyer
Copy link
Contributor

Step 1

make a test for getting the expression AST built right. Example test:

test("expression.ast - everything", function(){

An expression like foo()() results in:

{
	type: "Call",
	children: [
		{
			type: "Call",
			method: {type: "Lookup", "@foo"},
			children: []
		}
	]
}

Step 2

Update the parse to create this.

That will happen somewhere around here:

throw new Error("Unable to understand expression "+tokens.join(''));

Step 3

This ast can hydrate correctly into nested Call expressions.

This hydration happens around here:

else if(ast.type === "Call" || ast.type === "Helper") {

Might want to write a test for hydration. Example:

exprData = expression.parse("equal(foo(), [bar])");

Step 4

Make sure the Call expression type can actually do what you need. (test first)

Testing foo(1)(2) might look something like:

expr = new expression.Call(
                new expression.Call({
                  new expression.Lookup("bar"),
                  [ new expression.Literal(1) ]
                }),
	       [ new expression.Literal(2) ]
	);
	compute = expr.value(
		new Scope(
			new SimpleMap({foo: function( one){ return function( two ){ ... } } })
		)
	);

Might need to change

var method = this.methodExpr.value(scope, { proxyMethods: false });
to make this work, but I think it will already.

@chasenlehara
Copy link
Member

@Mattchewone Can this be closed now?

@Mattchewone
Copy link
Contributor

Yup still haven't got the hang of having the MR's close issues :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants