DISCUSSION: WIP: Transpile || and && correctly to php (with ecmascript behaviour)
#17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 : $rightExpressionTodo:
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?