diff --git a/.gitignore b/.gitignore index de4235f..2c2ea55 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ bin/plovr phpunit.xml +composer.lock config.php vendor/ tmp/ diff --git a/.travis.yml b/.travis.yml index 5488a3a..282b0aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,7 @@ language: php php: - 5.3 + - 5.6 + - 7.0 +sudo: false script: make test diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 index 49b1fa7..0dac9a5 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { "php": ">=5.3.2", - "twig/twig": ">=1.8,<2.0-dev" + "twig/twig": "^1.25" }, "require-dev": { @@ -22,6 +22,7 @@ }, "minimum-stability": "dev", + "prefer-stable": true, "autoload": { "psr-0": { "TwigJs": "src/" } }, diff --git a/composer.lock b/composer.lock deleted file mode 100644 index 6d85d38..0000000 --- a/composer.lock +++ /dev/null @@ -1,800 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" - ], - "hash": "1a06686557bec9eff8b957d65bcf7c72", - "packages": [ - { - "name": "twig/twig", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/fabpot/Twig.git", - "reference": "b0ee99d6d69b30a512064c8b4fac536f862a0d23" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/fabpot/Twig/zipball/b0ee99d6d69b30a512064c8b4fac536f862a0d23", - "reference": "b0ee99d6d69b30a512064c8b4fac536f862a0d23", - "shasum": "" - }, - "require": { - "php": ">=5.2.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.15-dev" - } - }, - "autoload": { - "psr-0": { - "Twig_": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com", - "homepage": "http://fabien.potencier.org", - "role": "Lead Developer" - }, - { - "name": "Armin Ronacher", - "email": "armin.ronacher@active-4.com", - "role": "Project Founder" - }, - { - "name": "Twig Team", - "homepage": "https://github.com/fabpot/Twig/graphs/contributors", - "role": "Contributors" - } - ], - "description": "Twig, the flexible, fast, and secure template language for PHP", - "homepage": "http://twig.sensiolabs.org", - "keywords": [ - "templating" - ], - "time": "2014-02-13 10:36:05" - } - ], - "packages-dev": [ - { - "name": "dnode/dnode", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/bergie/dnode-php.git", - "reference": "048deef50afe95e21ef25c026bd79b2917920f3b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/bergie/dnode-php/zipball/048deef50afe95e21ef25c026bd79b2917920f3b", - "reference": "048deef50afe95e21ef25c026bd79b2917920f3b", - "shasum": "" - }, - "require": { - "evenement/evenement": "~1.0", - "php": ">=5.3.0", - "react/socket": "0.3.*" - }, - "type": "library", - "autoload": { - "psr-0": { - "DNode": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Igor Wiedler", - "email": "igor@wiedler.ch", - "homepage": "http://wiedler.ch/igor/" - }, - { - "name": "Henri Bergius", - "email": "henri.bergius@iki.fi", - "homepage": "http://bergie.iki.fi/" - } - ], - "description": "DNode RPC protocol for PHP 5.3", - "homepage": "https://github.com/bergie/dnode-php", - "keywords": [ - "dnode", - "nodejs", - "rpc" - ], - "time": "2014-01-31 09:12:55" - }, - { - "name": "evenement/evenement", - "version": "1.0.x-dev", - "source": { - "type": "git", - "url": "https://github.com/igorw/evenement.git", - "reference": "8b0918f8374327dfed4408fe467980ab41d556dd" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/igorw/evenement/zipball/8b0918f8374327dfed4408fe467980ab41d556dd", - "reference": "8b0918f8374327dfed4408fe467980ab41d556dd", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0-dev" - } - }, - "autoload": { - "psr-0": { - "Evenement": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Igor Wiedler", - "email": "igor@wiedler.ch", - "homepage": "http://wiedler.ch/igor/" - } - ], - "description": "Événement is a very simple event dispatching library for PHP 5.3", - "keywords": [ - "event-dispatcher" - ], - "time": "2012-12-29 17:04:52" - }, - { - "name": "phpunit/php-code-coverage", - "version": "1.2.x-dev", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "61fed79803b6c75d461b909dfac05bbef5cd4f46" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/61fed79803b6c75d461b909dfac05bbef5cd4f46", - "reference": "61fed79803b6c75d461b909dfac05bbef5cd4f46", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "phpunit/php-file-iterator": ">=1.3.0@stable", - "phpunit/php-text-template": ">=1.2.0@stable", - "phpunit/php-token-stream": ">=1.1.3@stable" - }, - "require-dev": { - "phpunit/phpunit": "3.7.*@dev" - }, - "suggest": { - "ext-dom": "*", - "ext-xdebug": ">=2.0.5" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, - "autoload": { - "classmap": [ - "PHP/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", - "homepage": "https://github.com/sebastianbergmann/php-code-coverage", - "keywords": [ - "coverage", - "testing", - "xunit" - ], - "time": "2014-05-19 01:58:57" - }, - { - "name": "phpunit/php-file-iterator", - "version": "1.3.4", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb", - "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "File/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "FilterIterator implementation that filters files based on a list of suffixes.", - "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", - "keywords": [ - "filesystem", - "iterator" - ], - "time": "2013-10-10 15:34:57" - }, - { - "name": "phpunit/php-text-template", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", - "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "Text/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Simple template engine.", - "homepage": "https://github.com/sebastianbergmann/php-text-template/", - "keywords": [ - "template" - ], - "time": "2014-01-30 17:20:04" - }, - { - "name": "phpunit/php-timer", - "version": "1.0.5", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c", - "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "PHP/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Utility class for timing", - "homepage": "https://github.com/sebastianbergmann/php-timer/", - "keywords": [ - "timer" - ], - "time": "2013-08-02 07:42:54" - }, - { - "name": "phpunit/php-token-stream", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "955c24b708f8bfd6a05f303217a8dac3a443d531" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/955c24b708f8bfd6a05f303217a8dac3a443d531", - "reference": "955c24b708f8bfd6a05f303217a8dac3a443d531", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2-dev" - } - }, - "autoload": { - "classmap": [ - "PHP/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Wrapper around PHP's tokenizer extension.", - "homepage": "https://github.com/sebastianbergmann/php-token-stream/", - "keywords": [ - "tokenizer" - ], - "time": "2014-05-12 05:34:42" - }, - { - "name": "phpunit/phpunit", - "version": "3.7.x-dev", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "ae6cefd7cc84586a5ef27e04bae11ee940ec63dc" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ae6cefd7cc84586a5ef27e04bae11ee940ec63dc", - "reference": "ae6cefd7cc84586a5ef27e04bae11ee940ec63dc", - "shasum": "" - }, - "require": { - "ext-ctype": "*", - "ext-dom": "*", - "ext-json": "*", - "ext-pcre": "*", - "ext-reflection": "*", - "ext-spl": "*", - "php": ">=5.3.3", - "phpunit/php-code-coverage": "~1.2", - "phpunit/php-file-iterator": "~1.3", - "phpunit/php-text-template": "~1.1", - "phpunit/php-timer": "~1.0", - "phpunit/phpunit-mock-objects": "~1.2", - "symfony/yaml": "~2.0" - }, - "require-dev": { - "pear-pear.php.net/pear": "1.9.4" - }, - "suggest": { - "phpunit/php-invoker": "~1.1" - }, - "bin": [ - "composer/bin/phpunit" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.7.x-dev" - } - }, - "autoload": { - "classmap": [ - "PHPUnit/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "", - "../../symfony/yaml/" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "The PHP Unit Testing framework.", - "homepage": "http://www.phpunit.de/", - "keywords": [ - "phpunit", - "testing", - "xunit" - ], - "time": "2014-04-30 12:24:19" - }, - { - "name": "phpunit/phpunit-mock-objects", - "version": "1.2.x-dev", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "c39c4511c3b007539eb170c32cbc2af49a07351a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/c39c4511c3b007539eb170c32cbc2af49a07351a", - "reference": "c39c4511c3b007539eb170c32cbc2af49a07351a", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "phpunit/php-text-template": ">=1.1.1@stable" - }, - "require-dev": { - "phpunit/phpunit": "3.7.*@dev" - }, - "suggest": { - "ext-soap": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, - "autoload": { - "classmap": [ - "PHPUnit/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Mock Object library for PHPUnit", - "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", - "keywords": [ - "mock", - "xunit" - ], - "time": "2014-02-16 12:43:56" - }, - { - "name": "react/event-loop", - "version": "0.3.x-dev", - "target-dir": "React/EventLoop", - "source": { - "type": "git", - "url": "https://github.com/reactphp/event-loop.git", - "reference": "235cddfa999a392e7d63dc9bef2e042492608d9f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/event-loop/zipball/235cddfa999a392e7d63dc9bef2e042492608d9f", - "reference": "235cddfa999a392e7d63dc9bef2e042492608d9f", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "suggest": { - "ext-libev": "*", - "ext-libevent": ">=0.0.5" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.3-dev" - } - }, - "autoload": { - "psr-0": { - "React\\EventLoop": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Event loop abstraction layer that libraries can use for evented I/O.", - "keywords": [ - "event-loop" - ], - "time": "2013-07-21 02:23:09" - }, - { - "name": "react/socket", - "version": "0.3.x-dev", - "target-dir": "React/Socket", - "source": { - "type": "git", - "url": "https://github.com/reactphp/socket.git", - "reference": "19bc0c4309243717396022ffb2e59be1cc784327" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/socket/zipball/19bc0c4309243717396022ffb2e59be1cc784327", - "reference": "19bc0c4309243717396022ffb2e59be1cc784327", - "shasum": "" - }, - "require": { - "evenement/evenement": "1.0.*", - "php": ">=5.3.3", - "react/event-loop": "0.3.*", - "react/stream": "0.3.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.3-dev" - } - }, - "autoload": { - "psr-0": { - "React\\Socket": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Library for building an evented socket server.", - "keywords": [ - "Socket" - ], - "time": "2014-02-17 22:32:00" - }, - { - "name": "react/stream", - "version": "0.3.x-dev", - "target-dir": "React/Stream", - "source": { - "type": "git", - "url": "https://github.com/reactphp/stream.git", - "reference": "feef56628afe3fa861f0da5f92c909e029efceac" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/stream/zipball/feef56628afe3fa861f0da5f92c909e029efceac", - "reference": "feef56628afe3fa861f0da5f92c909e029efceac", - "shasum": "" - }, - "require": { - "evenement/evenement": "1.0.*", - "php": ">=5.3.3" - }, - "suggest": { - "react/event-loop": "0.3.*", - "react/promise": "~1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.3-dev" - } - }, - "autoload": { - "psr-0": { - "React\\Stream": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Basic readable and writable stream interfaces that support piping.", - "keywords": [ - "pipe", - "stream" - ], - "time": "2014-02-16 19:48:52" - }, - { - "name": "squizlabs/php_codesniffer", - "version": "1.5.2", - "source": { - "type": "git", - "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "a76a39b317ce8106abe6264daa505e24e1731860" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/a76a39b317ce8106abe6264daa505e24e1731860", - "reference": "a76a39b317ce8106abe6264daa505e24e1731860", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": ">=5.1.2" - }, - "suggest": { - "phpunit/php-timer": "dev-master" - }, - "bin": [ - "scripts/phpcs" - ], - "type": "library", - "autoload": { - "classmap": [ - "CodeSniffer.php", - "CodeSniffer/CLI.php", - "CodeSniffer/Exception.php", - "CodeSniffer/File.php", - "CodeSniffer/Report.php", - "CodeSniffer/Reporting.php", - "CodeSniffer/Sniff.php", - "CodeSniffer/Tokens.php", - "CodeSniffer/Reports/", - "CodeSniffer/CommentParser/", - "CodeSniffer/Tokenizers/", - "CodeSniffer/DocGenerators/", - "CodeSniffer/Standards/AbstractPatternSniff.php", - "CodeSniffer/Standards/AbstractScopeSniff.php", - "CodeSniffer/Standards/AbstractVariableSniff.php", - "CodeSniffer/Standards/IncorrectPatternException.php", - "CodeSniffer/Standards/Generic/Sniffs/", - "CodeSniffer/Standards/MySource/Sniffs/", - "CodeSniffer/Standards/PEAR/Sniffs/", - "CodeSniffer/Standards/PSR1/Sniffs/", - "CodeSniffer/Standards/PSR2/Sniffs/", - "CodeSniffer/Standards/Squiz/Sniffs/", - "CodeSniffer/Standards/Zend/Sniffs/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Greg Sherwood", - "role": "lead" - } - ], - "description": "PHP_CodeSniffer tokenises PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "http://www.squizlabs.com/php-codesniffer", - "keywords": [ - "phpcs", - "standards" - ], - "time": "2014-02-04 23:49:58" - }, - { - "name": "symfony/yaml", - "version": "dev-master", - "target-dir": "Symfony/Component/Yaml", - "source": { - "type": "git", - "url": "https://github.com/symfony/Yaml.git", - "reference": "b01d366060f33e18fd98b0008c41a01b0d25c95c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/b01d366060f33e18fd98b0008c41a01b0d25c95c", - "reference": "b01d366060f33e18fd98b0008c41a01b0d25c95c", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.6-dev" - } - }, - "autoload": { - "psr-0": { - "Symfony\\Component\\Yaml\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com", - "homepage": "http://fabien.potencier.org", - "role": "Lead Developer" - }, - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" - } - ], - "description": "Symfony Yaml Component", - "homepage": "http://symfony.com", - "time": "2014-06-04 06:43:44" - } - ], - "aliases": [ - - ], - "minimum-stability": "dev", - "stability-flags": { - "dnode/dnode": 20, - "phpunit/phpunit": 20 - }, - "platform": { - "php": ">=5.3.2" - }, - "platform-dev": [ - - ] -} diff --git a/src/TwigJs/Compiler/Expression/GetAttrCompiler.php b/src/TwigJs/Compiler/Expression/GetAttrCompiler.php index c4522ad..cf93801 100644 --- a/src/TwigJs/Compiler/Expression/GetAttrCompiler.php +++ b/src/TwigJs/Compiler/Expression/GetAttrCompiler.php @@ -57,7 +57,7 @@ public function compile(JsCompiler $compiler, \Twig_NodeInterface $node) ->subcompile($node->getNode('attribute')) ; - $defaultArguments = 0 === count($node->getNode('arguments')); + $defaultArguments = 0 === ($node->hasNode('arguments') ? count($node->getNode('arguments')) : 0); $defaultAccess = \Twig_TemplateInterface::ANY_CALL === $node->getAttribute('type'); $defaultTest = false == $node->getAttribute('is_defined_test'); diff --git a/src/TwigJs/Compiler/Expression/Test/DefinedCompiler.php b/src/TwigJs/Compiler/Expression/Test/DefinedCompiler.php old mode 100644 new mode 100755 index 1d388e7..9e1f491 --- a/src/TwigJs/Compiler/Expression/Test/DefinedCompiler.php +++ b/src/TwigJs/Compiler/Expression/Test/DefinedCompiler.php @@ -27,7 +27,7 @@ public function compile(JsCompiler $compiler, \Twig_NodeInterface $node) new \Twig_Node_Expression_Test( $node->getNode('node'), $node->getAttribute('name'), - $node->getNode('arguments'), + $node->hasNode('arguments') ? $node->getNode('arguments') : null, $node->getLine() ) ); diff --git a/src/TwigJs/Compiler/Expression/Test/EvenCompiler.php b/src/TwigJs/Compiler/Expression/Test/EvenCompiler.php old mode 100644 new mode 100755 index a763b43..ca96516 --- a/src/TwigJs/Compiler/Expression/Test/EvenCompiler.php +++ b/src/TwigJs/Compiler/Expression/Test/EvenCompiler.php @@ -27,7 +27,7 @@ public function compile(JsCompiler $compiler, \Twig_NodeInterface $node) new \Twig_Node_Expression_Test( $node->getNode('node'), $node->getAttribute('name'), - $node->getNode('arguments'), + $node->hasNode('arguments') ? $node->getNode('arguments') : null, $node->getLine() ) ); diff --git a/src/TwigJs/Compiler/Expression/Test/NullCompiler.php b/src/TwigJs/Compiler/Expression/Test/NullCompiler.php index 5489a28..3a3c89d 100644 --- a/src/TwigJs/Compiler/Expression/Test/NullCompiler.php +++ b/src/TwigJs/Compiler/Expression/Test/NullCompiler.php @@ -27,7 +27,7 @@ public function compile(JsCompiler $compiler, \Twig_NodeInterface $node) new \Twig_Node_Expression_Test( $node->getNode('node'), $node->getAttribute('name'), - $node->getNode('arguments'), + $node->hasNode('arguments') ? $node->getNode('arguments') : null, $node->getLine() ) ); diff --git a/src/TwigJs/Compiler/Expression/Test/OddCompiler.php b/src/TwigJs/Compiler/Expression/Test/OddCompiler.php old mode 100644 new mode 100755 index 05a201e..c3d47bb --- a/src/TwigJs/Compiler/Expression/Test/OddCompiler.php +++ b/src/TwigJs/Compiler/Expression/Test/OddCompiler.php @@ -27,7 +27,7 @@ public function compile(JsCompiler $compiler, \Twig_NodeInterface $node) new \Twig_Node_Expression_Test( $node->getNode('node'), $node->getAttribute('name'), - $node->getNode('arguments'), + $node->hasNode('arguments') ? $node->getNode('arguments') : null, $node->getLine() ) ); diff --git a/src/TwigJs/Compiler/ForCompiler.php b/src/TwigJs/Compiler/ForCompiler.php old mode 100644 new mode 100755 index 58d48d0..ed3852a --- a/src/TwigJs/Compiler/ForCompiler.php +++ b/src/TwigJs/Compiler/ForCompiler.php @@ -73,7 +73,7 @@ public function compile(JsCompiler $compiler, \Twig_NodeInterface $node) ->raw(";\n") ; - if (null !== $node->getNode('else')) { + if ($node->hasNode('else') && null !== $node->getNode('else')) { $compiler->write("var $iteratedName = false;\n"); } @@ -117,7 +117,7 @@ public function compile(JsCompiler $compiler, \Twig_NodeInterface $node) $ref = new \ReflectionProperty($node, 'loop'); $ref->setAccessible(true); $loop = $ref->getValue($node); - $loop->setAttribute('else', null !== $node->getNode('else')); + $loop->setAttribute('else', $node->hasNode('else') && null !== $node->getNode('else')); $loop->setAttribute('with_loop', $node->getAttribute('with_loop')); $loop->setAttribute('ifexpr', $node->getAttribute('ifexpr')); @@ -135,7 +135,7 @@ public function compile(JsCompiler $compiler, \Twig_NodeInterface $node) ->write("}, this);\n") ; - if (null !== $node->getNode('else')) { + if ($node->hasNode('else') && null !== $node->getNode('else')) { $compiler ->write("if (!$iteratedName) {\n") ->indent() diff --git a/src/TwigJs/Compiler/IncludeCompiler.php b/src/TwigJs/Compiler/IncludeCompiler.php old mode 100644 new mode 100755 index fa1acf5..8c505da --- a/src/TwigJs/Compiler/IncludeCompiler.php +++ b/src/TwigJs/Compiler/IncludeCompiler.php @@ -80,7 +80,7 @@ public function compile(JsCompiler $compiler, \Twig_NodeInterface $node) $compiler->isTemplateName = false; if (false === $node->getAttribute('only')) { - if (null === $node->getNode('variables')) { + if (!$node->hasNode('variables') || null === $node->getNode('variables')) { $compiler->raw('context'); } else { $compiler diff --git a/src/TwigJs/Compiler/ModuleCompiler.php b/src/TwigJs/Compiler/ModuleCompiler.php old mode 100644 new mode 100755 index d02008f..c433f12 --- a/src/TwigJs/Compiler/ModuleCompiler.php +++ b/src/TwigJs/Compiler/ModuleCompiler.php @@ -57,7 +57,7 @@ protected function compileGetParent(JsCompiler $compiler, \Twig_NodeInterface $n ->write('return ') ; - if (null === $node->getNode('parent')) { + if (!$node->hasNode('parent') || null === $node->getNode('parent')) { $compiler->repr(false); } else { $compiler @@ -82,7 +82,7 @@ protected function compileDisplayBody(JsCompiler $compiler, \Twig_NodeInterface ->leaveScope() ; - if (null !== $node->getNode('parent')) { + if ($node->hasNode('parent') && null !== $node->getNode('parent')) { $compiler ->write("this.getParent(context).render_(sb, context, twig.extend({}, this.getBlocks(), blocks));\n") ; @@ -228,7 +228,7 @@ protected function compileIsTraitable(JsCompiler $compiler, \Twig_NodeInterface // // Put another way, a template can be used as a trait if it // only contains blocks and use statements. - $traitable = null === $node->getNode('parent') && 0 === count($node->getNode('macros')); + $traitable = (!$node->hasNode('parent') || null === $node->getNode('parent')) && 0 === count($node->getNode('macros')); if ($traitable) { if (!count($nodes = $node->getNode('body'))) { $nodes = new Twig_Node(array($node->getNode('body'))); diff --git a/src/TwigJs/JsCompiler.php b/src/TwigJs/JsCompiler.php index 4b102b0..534c4c5 100644 --- a/src/TwigJs/JsCompiler.php +++ b/src/TwigJs/JsCompiler.php @@ -180,7 +180,70 @@ public function __construct(\Twig_Environment $env) 'Twig_Node_Expression_Test_Null' => new Compiler\Expression\Test\NullCompiler(), 'Twig_Node_Expression_Test_Odd' => new Compiler\Expression\Test\OddCompiler(), 'Twig_Node_Expression_Test_Sameas' => new Compiler\Expression\Test\SameasCompiler(), - + \Twig\Node\Node::class => new NodeCompiler(), + \Twig\Node\BodyNode::class => new BodyCompiler(), + \Twig\Node\ModuleNode::class => new ModuleCompiler\GoogleCompiler(), + \Twig\Node\BlockNode::class => new BlockCompiler(), + \Twig\Node\TextNode::class => new TextCompiler(), + \Twig\Node\IfNode::class => new IfCompiler(), + \Twig\Node\PrintNode::class => new PrintCompiler(), + \Twig\Node\ForNode::class => new ForCompiler(), + \Twig\Node\ForLoopNode::class => new ForLoopCompiler(), + \Twig\Node\SetNode::class => new SetCompiler(), + \Twig\Node\IncludeNode::class => new IncludeCompiler(), + \Twig\Node\SpacelessNode::class => new SpacelessCompiler(), + \Twig\Node\SetTempNode::class => new SetTempCompiler(), + \Twig_Node_Expression_ExtensionReference::class => new ExtensionReferenceCompiler(), + \Twig\Node\BlockReferenceNode::class => new BlockReferenceCompiler(), + \Twig\Node\AutoEscapeNode::class => new AutoEscapeCompiler(), + \Twig\Node\ImportNode::class => new ImportCompiler(), + \Twig\Node\MacroNode::class => new MacroCompiler(), + \Twig\Node\Expression\TempNameExpression::class => new TempNameCompiler(), + \Twig\Node\Expression\ConditionalExpression::class => new ConditionalCompiler(), + \Twig\Node\Expression\ArrayExpression::class => new ArrayCompiler(), + \Twig\Node\Expression\FunctionExpression::class => new FunctionCompiler(), + \Twig\Node\Expression\ParentExpression::class => new ParentCompiler(), + \Twig\Node\Expression\BlockReferenceExpression::class => new ExpressionBlockReferenceCompiler(), + \Twig\Node\Expression\AssignNameExpression::class => new AssignNameCompiler(), + \Twig\Node\Expression\TestExpression::class => new TestCompiler(), + \Twig\Node\Expression\NameExpression::class => new NameCompiler(), + \Twig\Node\Expression\FilterExpression::class => new FilterCompiler(), + \Twig\Node\Expression\Filter\DefaultFilter::class => new Compiler\Expression\Filter\DefaultCompiler(), + \Twig\Node\Expression\ConstantExpression::class => new ConstantCompiler(), + \Twig\Node\Expression\GetAttrExpression::class => new GetAttrCompiler(), + \Twig\Node\Expression\MethodCallExpression::class => new Compiler\Expression\MethodCallCompiler(), + \Twig\Node\Expression\Binary\AddBinary::class => new AddCompiler(), + \Twig\Node\Expression\Binary\AndBinary::class => new AndCompiler(), + \Twig\Node\Expression\Binary\BitwiseAndBinary::class => new BitwiseAndCompiler(), + \Twig\Node\Expression\Binary\BitwiseOrBinary::class => new BitwiseOrCompiler(), + \Twig\Node\Expression\Binary\BitwiseXorBinary::class => new BitwiseXorCompiler(), + \Twig\Node\Expression\Binary\ConcatBinary::class => new ConcatCompiler(), + \Twig\Node\Expression\Binary\DivBinary::class => new DivCompiler(), + \Twig\Node\Expression\Binary\EqualBinary::class => new EqualCompiler(), + \Twig\Node\Expression\Binary\FloorDivBinary::class => new FloorDivCompiler(), + \Twig\Node\Expression\Binary\GreaterBinary::class => new GreaterCompiler(), + \Twig\Node\Expression\Binary\GreaterEqualBinary::class => new GreaterEqualCompiler(), + \Twig\Node\Expression\Binary\InBinary::class => new InCompiler(), + \Twig\Node\Expression\Binary\LessBinary::class => new LessCompiler(), + \Twig\Node\Expression\Binary\LessEqualBinary::class => new LessEqualCompiler(), + \Twig\Node\Expression\Binary\ModBinary::class => new ModCompiler(), + \Twig\Node\Expression\Binary\MulBinary::class => new MulCompiler(), + \Twig\Node\Expression\Binary\NotEqualBinary::class => new NotEqualCompiler(), + \Twig\Node\Expression\Binary\NotInBinary::class => new NotInCompiler(), + \Twig\Node\Expression\Binary\OrBinary::class => new OrCompiler(), + \Twig\Node\Expression\Binary\PowerBinary::class => new PowerCompiler(), + \Twig\Node\Expression\Binary\RangeBinary::class => new RangeCompiler(), + \Twig\Node\Expression\Binary\SubBinary::class => new SubCompiler(), + \Twig\Node\Expression\Unary\NegUnary::class => new NegCompiler(), + \Twig\Node\Expression\Unary\NotUnary::class => new NotCompiler(), + \Twig\Node\Expression\Unary\PosUnary::class => new PosCompiler(), + \Twig\Node\Expression\Test\ConstantTest::class => new Compiler\Expression\Test\ConstantCompiler(), + \Twig\Node\Expression\Test\DefinedTest::class => new Compiler\Expression\Test\DefinedCompiler(), + \Twig\Node\Expression\Test\DivisiblebyTest::class => new Compiler\Expression\Test\DivisiblebyCompiler(), + \Twig\Node\Expression\Test\EvenTest::class => new Compiler\Expression\Test\EvenCompiler(), + \Twig\Node\Expression\Test\NullTest::class => new Compiler\Expression\Test\NullCompiler(), + \Twig\Node\Expression\Test\OddTest::class => new Compiler\Expression\Test\OddCompiler(), + \Twig\Node\Expression\Test\SameasTest::class => new Compiler\Expression\Test\SameasCompiler(), ); $this->testCompilers = array(