Skip to content

Commit

Permalink
Merge pull request #4 from preprocess/feature/update-plugin
Browse files Browse the repository at this point in the history
Update plugin
  • Loading branch information
assertchris authored Oct 8, 2018
2 parents d7fc3b4 + b6e28db commit 7012018
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 232 deletions.
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"type": "pre-compiler",
"license": "MIT",
"require": {
"pre/plugin": "^0.11.0",
"nikic/php-parser": "^4.0",
"gajus/dindent": "^2.0"
"pre/plugin": "^0.11.3"
},
"require-dev": {
"phpunit/phpunit": "^5.0|^6.0"
Expand Down
108 changes: 6 additions & 102 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 2 additions & 20 deletions source/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,11 @@
namespace Pre\Phpx;

use Exception;
use PhpParser\Error;
use PhpParser\NodeDumper;
use PhpParser\ParserFactory;

class Parser
{
private $printer;

public function __construct($printer = null)
{
if (is_null($printer)) {
$this->printer = new Printer();
}
}

public function tokens($code)
{
$tokens = [];
Expand Down Expand Up @@ -353,15 +343,7 @@ public function translate($nodes, $quoteLiterals = false, $combineChildren = fal

public function format($code)
{
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);

try {
$parsed = $parser->parse($code);
} catch (Exception $e) {
// can't format, but we can still return...
return $code;
}

return $this->printer->prettyPrintFile($parsed);
// left to avoid a version bump
return $code;
}
}
81 changes: 0 additions & 81 deletions source/Printer.php

This file was deleted.

4 changes: 2 additions & 2 deletions tests/CompileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public function test_can_compile()
{
$this->assertEquals(
$this->fixtureCode("compile/can-compile", "php"),
\Pre\Phpx\compile($this->fixtureCode("compile/can-compile", "pre"))
\Pre\Plugin\format(\Pre\Phpx\compile($this->fixtureCode("compile/can-compile", "pre")))
);
}

public function test_supports_nested_component_names()
{
$this->assertEquals(
$this->fixtureCode("compile/supports-nested-component-names", "php"),
\Pre\Phpx\compile($this->fixtureCode("compile/supports-nested-component-names", "pre"))
\Pre\Plugin\format(\Pre\Phpx\compile($this->fixtureCode("compile/supports-nested-component-names", "pre")))
);
}
}
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ protected function parser()

protected function fixtureCode($path, $extension = "txt")
{
return trim(file_get_contents(__DIR__ . "/fixtures/{$path}.{$extension}"));
return file_get_contents(__DIR__ . "/fixtures/{$path}.{$extension}");
}

protected function fixtureData($path, $extension = "php")
Expand Down
14 changes: 7 additions & 7 deletions tests/fixtures/compile/can-compile.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ function Error($props)
"render" => function ($error) {
return render("span", [
"className" => "error",
"children" => $error,
"children" => $error
]);
},
"children" => [
render("span", [
"className" => "icon",
"className" => "icon"
]),
"You forgot the",
$props->name,
"field",
],
"field"
]
]);
}

Expand All @@ -26,15 +26,15 @@ function ErrorRenderer($props)
return render("Error", [
"children" => function ($error) {
return render("span", [
"children" => $error,
"children" => $error
]);
},
}
]);
}

function InputRenderer($props)
{
return render("input", [
"type" => $props->type,
"type" => $props->type
]);
}
12 changes: 5 additions & 7 deletions tests/fixtures/compile/supports-nested-component-names.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<?php

namespace Example
{
namespace Example {
function MyComponent()
{
return render("div", [
"children" => "hello world",
"children" => "hello world"
]);
}
}

namespace
{
namespace {
function render($name, $props = null)
{
print $name;
}
print render("Example\\MyComponent", []);

print render("Example\MyComponent", []);
}
6 changes: 3 additions & 3 deletions tests/fixtures/nodes/can-arrange-nodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function Error(\$props) {
[
[
"type" => "literal",
"value" => "\$error ",
"value" => "\$error ~>",
],
[
"type" => "tag",
Expand All @@ -38,11 +38,11 @@ function Error(\$props) {
"value" => "\$error",
],
],
"started" => 37,
"started" => 36,
],
],
"name" => "span",
"started" => 30,
"started" => 29,
],
],
],
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/nodes/can-arrange-nodes.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function Error($props) {
return (
<div render={$error <span className={"error"}>{$error}</span>}>
<div render={$error ~> <span className={"error"}>{$error}</span>}>
You forgot the {$props->name} field
</div>
);
Expand Down
Loading

0 comments on commit 7012018

Please sign in to comment.