Danack / PHP-to-Javascript

A tool for converting simple PHP objects/code to Javascript, so that code for manipulating objects can be used both server-side and client-side.
Other
104 stars 32 forks source link

Anonymous functions:important #29

Closed ghost closed 11 years ago

ghost commented 11 years ago

can you implement this? http://www.php.net/manual/en/functions.anonymous.php

for javascript is very important, (for jquery or events).

ghost commented 11 years ago

when you use this. then will be worked add to TokenSteam.php

function moveBack(){
    $this->current--;
}

add to FUNCTION.php

function    processToken($name, $value, $parsedToken) {
......
    if ($name=="("){
        $this->stateMachine->pushScope(CODE_SCOPE_FUNCTION_PARAMETERS, '', $this->stateMachine->variableFlags);
        $this->stateMachine->addJS("function ");
        $this->changeToState(CONVERTER_STATE_DEFAULT);
        $this->stateMachine->currentTokenStream->moveBack();
    }
}

test https://github.com/tito100/PHP-to-Javascript/blob/master/tests/AnonymusFunction.php

ghost commented 11 years ago
    Q::ajax(array(
         'foo'=>5,
         'callback'=>function(){

         }
    ));

is parsed bad. to

    Q.ajax({
         'foo':5,
         'callback':function (){

         }
    )}; // <- here is brackets exchanged
Danack commented 11 years ago

This should be supported, and has a test Closure.php.

Just to note, you can tell the state-machine to reprocess to reprocess any token (e.g. because the current state didn't process the token, but instead changed to a new state) which amazingly is one of the few comments in the code: https://github.com/Danack/PHP-to-Javascript/blob/master/src/PHPToJavascript/CodeConverterState.php#L27