pug-php / js-phpize Goto Github PK
View Code? Open in Web Editor NEWConvert js-like syntax to standalone PHP code.
License: MIT License
Convert js-like syntax to standalone PHP code.
License: MIT License
Fixes BKWLD/laravel-pug#82
Observed:
When the dot fails to know if the right operand is a field/property of the left operand, it returns an array [left, right] so it can be tried as a callable if called.
Expected:
Solution proposal:
This array should be wrapped in an object that:
Next to the following error posted in pug-php:
pug-php/pug#71
This issue aims to delegate it to js-phpize.
return "group[" + group.id + "]"
With $group->id = 4, should return group[4]
Hi everyone!
Thank you for this library so much, it really helpfull!
But turns out there extra visitNode call which leads to recursion and may increase calls of visitNode a lot.
Let's run this script:
<?php
$jsPhpize = new \JsPhpize\JsPhpize();
$compiled = $jsPhpize->compile('var media_5=/* + ragetmera66ragetmera66 + */rahttpsra21rahttpsra21 + /* + rabcomra40rabcomra40 + */rawwwra38rawwwra38 + /* + ravjzty2ra41ravjzty2ra41 + */rapornhura70rapornhura70 + /* + rahttpsra21rahttpsra21 + */rabcomra40rabcomra40 + /* + ravjzty2ra41ravjzty2ra41 + */ravideora93ravideora93 + /* + rad9b815ra33rad9b815ra33 + */ragetmera66ragetmera66 + /* + rammeymzra84rammeymzra84 + */radiasra12radiasra12 + /* + rabcomra40rabcomra40 + */raeyjrijra51raeyjrijra51 + /* + razhmjgxra100razhmjgxra100 + */raoiode4ra78raoiode4ra78 + /* + rapornhura70rapornhura70 + */raodi2owra55raodi2owra55 + /* + ratpra63ratpra63 + */raexmdizra37raexmdizra37 + /* + raeyjrijra51raeyjrijra51 + */razmu4ogra66razmu4ogra66 + /* + ravjzty2ra41ravjzty2ra41 + */razhnmuzra26razhnmuzra26 + /* + raodi2owra55raodi2owra55 + */raogiwnzra60raogiwnzra60 + /* + rae2nziyra35rae2nziyra35 + */ravjzty2ra41ravjzty2ra41 + /* + razhnmuzra26razhnmuzra26 + */rantq1otra93rantq1otra93 + /* + ra57e0ra18ra57e0ra18 + */razhmjgxra100razhmjgxra100 + /* + raeyjrijra51raeyjrijra51 + */ran2eyyjra32ran2eyyjra32 + /* + rau1m2i4ra7rau1m2i4ra7 + */rau1m2i4ra7rau1m2i4ra7 + /* + ra57e0ra18ra57e0ra18 + */ramgi2zmra48ramgi2zmra48 + /* + rainqiojra44rainqiojra44 + */rarlowm0ra25rarlowm0ra25 + /* + rah624eera83rah624eera83 + */rammeymzra84rammeymzra84 + /* + raq2zsisra26raq2zsisra26 + */raq2zsisra26raq2zsisra26 + /* + ran2eyyjra32ran2eyyjra32 + */rainqiojra44rainqiojra44 + /* + rainqiojra44rainqiojra44 + */rae2nziyra35rae2nziyra35 + /* + raexmdizra37raexmdizra37 + */rantcwmzra44rantcwmzra44 + /* + rapornhura70rapornhura70 + */raf9vpra44raf9vpra44 + /* + rantq1otra93rantq1otra93 + */rah624eera83rah624eera83 + /* + raodi2owra55raodi2owra55 + */rad9b815ra33rad9b815ra33 + /* + ramgi2zmra48ramgi2zmra48 + */ra57e0ra18ra57e0ra18 + /* + rau1m2i4ra7rau1m2i4ra7 + */ratpra63ratpra63;');
var_dump($compiled);
Seems like there is no chance to get result in reasonable time.
Let's check the code:
here https://github.com/pug-php/js-phpize/blob/master/src/JsPhpize/Compiler/Compiler.php#L192-L204
call of $arguments[] = $this->visitNode($dyiade->rightHand, $indent);
will produce call of visitDyade
and so on
but then we just removing the result from array.
I'd like to suggest an addition, which should fix this problem - seems like it works fine:
<?php
case '+':
$arguments = [$leftHand, $rightHand];
if (($dyiade->rightHand) instanceof Dyiade && $dyiade->rightHand->operator === '+') {
$last = $dyiade;
array_pop($arguments);
while (
($dyiade = $dyiade->rightHand) instanceof Dyiade &&
$dyiade->operator === '+'
) {
$last = $dyiade;
$arguments[] = $this->visitNode($dyiade->leftHand, $indent);
}
if ($last instanceof Dyiade && $last->operator === '+') {
$arguments[] = $value = $this->visitNode($last->rightHand, $indent);
}
}
return $this->helperWrap($this->engine->getHelperName('plus'), $arguments);
Expected to get:
`${`r`}`
Compiled into:
"" . "r" . ""
Actual output:
Throw an exception
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.