Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixin generates duplicated php codes #109

Closed
YamiOdymel opened this issue Jun 18, 2016 · 5 comments
Closed

Mixin generates duplicated php codes #109

YamiOdymel opened this issue Jun 18, 2016 · 5 comments

Comments

@YamiOdymel
Copy link

YamiOdymel commented Jun 18, 2016

tale-jade installed via composer today,

and here's the jade file

mixin item(link, icon, label)
    a.item(href=$link)
        span.icon(class=$icon)
        $label

+item('photo', 'icon--picture', 'A')
+item('photo', 'icon--circles', 'B')
+item('photo', 'icon--music'  , 'C')
+item('photo', 'icon--draw'   , 'D')
+item('photo', 'icon--dna'    , 'E')
+item('photo', 'icon--gamepad', 'F')

output

2016-06-19 3 36 48

Is it normal? Because if I use more and more mixins, it will be a disaster ..

I tried it on the demo site (http://sandbox.jade.talesoft.io/), it generated a normal code.

2016-06-19 3 44 05

@TorbenKoehn
Copy link
Member

Yep, that looks pretty messy.

I could put that $__ignore stuff in an own, global variable but then i'd pollute the global scope again :(

But maybe I can put that in some kind of freeze_scope compiler function, I'll think about it :)

@TorbenKoehn
Copy link
Member

I just want to leave a note, I didn't forget this.

I looked into this and it's actually a real problem. I can decide if I want to make the ignored variables configurable and have it messy or have them static and have it clean.

I'm working on a solution, but it will take a while. It's not a bug, it's a cosmetic thing, so it's at the end of my to-do list :)

TorbenKoehn pushed a commit that referenced this issue Aug 23, 2016
Updated composer.json

Updated Symfony mb polyfill to 1.2.0

Addressed #100, still not satisfied with the solution (but it works well, for ternary operators at least)

Addressed #109, the ignored variables are now a constant Tale\Jade\Compiler\IGNORED_SCOPE_VARIABLES. Define it prior to loading Tale Jade to specify own ignored variables (separated by `:`)
@TorbenKoehn
Copy link
Member

I adressed this in the latest patch. Can you pull *@dev and check if it produces less bloat?

I think I even reduced it to less than it has ever been. There's still more possible, working on it :)

@YamiOdymel
Copy link
Author

Wow, great work! It's much shorter now.

Tale Jade

mixin item(label)
    =$label

+item('A')
+item('B')
+item('C')
+item('D')
+item('E')
+item('F')

Outputted

f611a93 (Newest)

Size: 1,566 byte

2016-08-23 11 06 36

<?php $__mixins = [];?><?php $__mixins['item'] = function(array $__arguments, array $__scope) {$__defaults = ['label' => null];extract(array_replace($__scope, array_replace($__defaults, $__arguments)));?><?=htmlentities(isset($label) ? $label : '', \ENT_QUOTES, 'UTF-8')?><?php };?><?php $__scope = \Tale\Jade\Compiler\create_scope(get_defined_vars()); $__mixinCallArgs = ['label' => 'A'];call_user_func($__mixins['item'], $__mixinCallArgs, $__scope); unset($__scope); unset($__mixinCallArgs); ?><?php $__scope = \Tale\Jade\Compiler\create_scope(get_defined_vars()); $__mixinCallArgs = ['label' => 'B'];call_user_func($__mixins['item'], $__mixinCallArgs, $__scope); unset($__scope); unset($__mixinCallArgs); ?><?php $__scope = \Tale\Jade\Compiler\create_scope(get_defined_vars()); $__mixinCallArgs = ['label' => 'C'];call_user_func($__mixins['item'], $__mixinCallArgs, $__scope); unset($__scope); unset($__mixinCallArgs); ?><?php $__scope = \Tale\Jade\Compiler\create_scope(get_defined_vars()); $__mixinCallArgs = ['label' => 'D'];call_user_func($__mixins['item'], $__mixinCallArgs, $__scope); unset($__scope); unset($__mixinCallArgs); ?><?php $__scope = \Tale\Jade\Compiler\create_scope(get_defined_vars()); $__mixinCallArgs = ['label' => 'E'];call_user_func($__mixins['item'], $__mixinCallArgs, $__scope); unset($__scope); unset($__mixinCallArgs); ?><?php $__scope = \Tale\Jade\Compiler\create_scope(get_defined_vars()); $__mixinCallArgs = ['label' => 'F'];call_user_func($__mixins['item'], $__mixinCallArgs, $__scope); unset($__scope); unset($__mixinCallArgs); ?>

4134b0a

Size: 3,828 byte

2016-08-23 11 06 47

<?php $__mixins = [];?><?php $__mixins['item'] = function(array $__arguments, array $__scope) {$__defaults = ['label' => null];extract(array_replace($__scope, array_replace($__defaults, $__arguments)));?><?=htmlentities(isset($label) ? $label : '', \ENT_QUOTES, 'UTF-8')?><?php };?><?php $__ignore = array_flip([0 => 'GLOBALS', 1 => '_SERVER', 2 => '_GET', 3 => '_POST', 4 => '_FILES', 5 => '_REQUEST', 6 => '_SESSION', 7 => '_ENV', 8 => '_COOKIE', 9 => 'php_errormsg', 10 => 'HTTP_RAW_POST_DATA', 11 => 'http_response_header', 12 => 'argc', 13 => 'argv', 14 => '__scope', 15 => '__arguments', 16 => '__ignore', 17 => '__block']);$__scope = array_diff_key(array_replace(get_defined_vars(), $__ignore), $__ignore);   $__mixinCallArgs = ['label' => 'A'];call_user_func($__mixins['item'], $__mixinCallArgs, $__scope);unset($__ignore);unset($__scope);unset($__mixinCallArgs);?><?php $__ignore = array_flip([0 => 'GLOBALS', 1 => '_SERVER', 2 => '_GET', 3 => '_POST', 4 => '_FILES', 5 => '_REQUEST', 6 => '_SESSION', 7 => '_ENV', 8 => '_COOKIE', 9 => 'php_errormsg', 10 => 'HTTP_RAW_POST_DATA', 11 => 'http_response_header', 12 => 'argc', 13 => 'argv', 14 => '__scope', 15 => '__arguments', 16 => '__ignore', 17 => '__block']);$__scope = array_diff_key(array_replace(get_defined_vars(), $__ignore), $__ignore);   $__mixinCallArgs = ['label' => 'B'];call_user_func($__mixins['item'], $__mixinCallArgs, $__scope);unset($__ignore);unset($__scope);unset($__mixinCallArgs);?><?php $__ignore = array_flip([0 => 'GLOBALS', 1 => '_SERVER', 2 => '_GET', 3 => '_POST', 4 => '_FILES', 5 => '_REQUEST', 6 => '_SESSION', 7 => '_ENV', 8 => '_COOKIE', 9 => 'php_errormsg', 10 => 'HTTP_RAW_POST_DATA', 11 => 'http_response_header', 12 => 'argc', 13 => 'argv', 14 => '__scope', 15 => '__arguments', 16 => '__ignore', 17 => '__block']);$__scope = array_diff_key(array_replace(get_defined_vars(), $__ignore), $__ignore);   $__mixinCallArgs = ['label' => 'C'];call_user_func($__mixins['item'], $__mixinCallArgs, $__scope);unset($__ignore);unset($__scope);unset($__mixinCallArgs);?><?php $__ignore = array_flip([0 => 'GLOBALS', 1 => '_SERVER', 2 => '_GET', 3 => '_POST', 4 => '_FILES', 5 => '_REQUEST', 6 => '_SESSION', 7 => '_ENV', 8 => '_COOKIE', 9 => 'php_errormsg', 10 => 'HTTP_RAW_POST_DATA', 11 => 'http_response_header', 12 => 'argc', 13 => 'argv', 14 => '__scope', 15 => '__arguments', 16 => '__ignore', 17 => '__block']);$__scope = array_diff_key(array_replace(get_defined_vars(), $__ignore), $__ignore);   $__mixinCallArgs = ['label' => 'D'];call_user_func($__mixins['item'], $__mixinCallArgs, $__scope);unset($__ignore);unset($__scope);unset($__mixinCallArgs);?><?php $__ignore = array_flip([0 => 'GLOBALS', 1 => '_SERVER', 2 => '_GET', 3 => '_POST', 4 => '_FILES', 5 => '_REQUEST', 6 => '_SESSION', 7 => '_ENV', 8 => '_COOKIE', 9 => 'php_errormsg', 10 => 'HTTP_RAW_POST_DATA', 11 => 'http_response_header', 12 => 'argc', 13 => 'argv', 14 => '__scope', 15 => '__arguments', 16 => '__ignore', 17 => '__block']);$__scope = array_diff_key(array_replace(get_defined_vars(), $__ignore), $__ignore);   $__mixinCallArgs = ['label' => 'E'];call_user_func($__mixins['item'], $__mixinCallArgs, $__scope);unset($__ignore);unset($__scope);unset($__mixinCallArgs);?><?php $__ignore = array_flip([0 => 'GLOBALS', 1 => '_SERVER', 2 => '_GET', 3 => '_POST', 4 => '_FILES', 5 => '_REQUEST', 6 => '_SESSION', 7 => '_ENV', 8 => '_COOKIE', 9 => 'php_errormsg', 10 => 'HTTP_RAW_POST_DATA', 11 => 'http_response_header', 12 => 'argc', 13 => 'argv', 14 => '__scope', 15 => '__arguments', 16 => '__ignore', 17 => '__block']);$__scope = array_diff_key(array_replace(get_defined_vars(), $__ignore), $__ignore);   $__mixinCallArgs = ['label' => 'F'];call_user_func($__mixins['item'], $__mixinCallArgs, $__scope);unset($__ignore);unset($__scope);unset($__mixinCallArgs);?>

@TorbenKoehn
Copy link
Member

Awesome!

Thank you for testing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants