Giter VIP home page Giter VIP logo

js-phpize's People

Contributors

gbokiau avatar kylekatarnls avatar sageptr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

js-phpize's Issues

Allow pseudo-callable to be output as string or boolean

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.

  1. When this array is passed to a condition (evaluated as a boolean) it's always true even if the right operand does not match anything truthy in the left operand.
  2. When it's sent to the output (evaluated as a string), it fails because PHP cannot cast arrays to string.

Expected:

  1. When this array is passed to a condition (evaluated as a boolean) it's always true even if the right operand does not match anything truthy in the left operand.
  2. When it's sent to the output (evaluated as a string), it fails because PHP cannot cast arrays to string.

Solution proposal:
This array should be wrapped in an object that:

  • can be cast to string according to the property/field value;
  • is callable as the original array would be;
  • provies a __toBoolean method that other libraries (like Phug/Pug-php) could use to cast it as a boolean.

Fix concatenation

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]

not parsable

Working on pugjs, I get with Phug ...

image

does not work either

image

[].concat, Object.keys() does not seem to work ...

Unwanted visitNode call

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);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.