Skip to content

Conversation

@mhsdesign
Copy link
Contributor

@mhsdesign mhsdesign commented Apr 23, 2023

The proposed expected php transpilation is inspired how EEL archieves it:
https://github.com/neos/flow-development-collection/blob/70bc49cc946c443dadfe26c49a19d710ece4ad48/Neos.Eel/Classes/CompilingEelParser.php#L163-L180
the simplified eel transpilation of "||" would look like: ($leftExpressionResult = $leftExpression) ? $leftExpressionResult : $rightExpression

Todo:

  • We need to have a concept for generating temporal variable ids without nameclash

While thinking of other differences in php and javascript, the truthyness came to my mind.
If we are not carefull a string "0" will be considered by the transpiled php falsy instead of truthy (by es standard)

The biggest problem is see, is that our testcases will be obscurified. Currently its super easy to read them as they nearly transpile 1 to 1 to php. But when we want ecmascript behaviour we need to use our own truthy helpers and transpile "and" and "or" correctly. This will lead to more bloat in the transpilation everywhere. We currently mostly test the AST and parsing by asserting the transpilation worked correctly, and if we want to write less transpilation tests we dont test the parsing that extensively anymore. Maybe we can build an easy back to AFX transpiler so we know that parsing worked without asserting the AST structure?

Todo:
We need to have a concept for generating temporal variable ids without nameclash

The transpilation is inspired how EEL does it:
https://github.com/neos/flow-development-collection/blob/70bc49cc946c443dadfe26c49a19d710ece4ad48/Neos.Eel/Classes/CompilingEelParser.php#L163-L180

simplified the eel transpilation of or would look like:
`($leftExpressionResult = $leftExpression) ? $leftExpressionResult : $rightExpression`
@mhsdesign mhsdesign changed the title WIP: Add tests, which obviously fail ^^ WIP: Transpile || and && correctly to php (with ecmascript behaviour) Apr 23, 2023
@mhsdesign mhsdesign changed the title WIP: Transpile || and && correctly to php (with ecmascript behaviour) DISCUSSION: WIP: Transpile || and && correctly to php (with ecmascript behaviour) Apr 24, 2023
@mhsdesign mhsdesign added the help wanted Extra attention is needed label Apr 24, 2023
@grebaldi
Copy link
Member

This is somewhat similar in spirit to #8, in that I'd also like to suggest to deviate from ECMAScript behavior and opt for the imho more obvious behavior of PHP (boolean operation -> boolean result).

@mhsdesign
Copy link
Contributor Author

Yes we discussed this and i agree. We could always introduce the ?? operator for this usecase.

I think that php and js have a different truthy and falsy behaviour is (bool)okayish.

The only difference, that might cause trouble, is that "0" is considered falsy in php but thruthy in js. But its not worth imo to handle this now.

I will close this discussion for know ;)

@mhsdesign mhsdesign closed this May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants