Skip to content

Commit 7012018

Browse files
authored
Merge pull request #4 from preprocess/feature/update-plugin
Update plugin
2 parents d7fc3b4 + b6e28db commit 7012018

File tree

12 files changed

+33
-232
lines changed

12 files changed

+33
-232
lines changed

composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"type": "pre-compiler",
44
"license": "MIT",
55
"require": {
6-
"pre/plugin": "^0.11.0",
7-
"nikic/php-parser": "^4.0",
8-
"gajus/dindent": "^2.0"
6+
"pre/plugin": "^0.11.3"
97
},
108
"require-dev": {
119
"phpunit/phpunit": "^5.0|^6.0"

composer.lock

Lines changed: 6 additions & 102 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/Parser.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,11 @@
33
namespace Pre\Phpx;
44

55
use Exception;
6-
use PhpParser\Error;
7-
use PhpParser\NodeDumper;
8-
use PhpParser\ParserFactory;
96

107
class Parser
118
{
129
private $printer;
1310

14-
public function __construct($printer = null)
15-
{
16-
if (is_null($printer)) {
17-
$this->printer = new Printer();
18-
}
19-
}
20-
2111
public function tokens($code)
2212
{
2313
$tokens = [];
@@ -353,15 +343,7 @@ public function translate($nodes, $quoteLiterals = false, $combineChildren = fal
353343

354344
public function format($code)
355345
{
356-
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
357-
358-
try {
359-
$parsed = $parser->parse($code);
360-
} catch (Exception $e) {
361-
// can't format, but we can still return...
362-
return $code;
363-
}
364-
365-
return $this->printer->prettyPrintFile($parsed);
346+
// left to avoid a version bump
347+
return $code;
366348
}
367349
}

source/Printer.php

Lines changed: 0 additions & 81 deletions
This file was deleted.

tests/CompileTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ public function test_can_compile()
1313
{
1414
$this->assertEquals(
1515
$this->fixtureCode("compile/can-compile", "php"),
16-
\Pre\Phpx\compile($this->fixtureCode("compile/can-compile", "pre"))
16+
\Pre\Plugin\format(\Pre\Phpx\compile($this->fixtureCode("compile/can-compile", "pre")))
1717
);
1818
}
1919

2020
public function test_supports_nested_component_names()
2121
{
2222
$this->assertEquals(
2323
$this->fixtureCode("compile/supports-nested-component-names", "php"),
24-
\Pre\Phpx\compile($this->fixtureCode("compile/supports-nested-component-names", "pre"))
24+
\Pre\Plugin\format(\Pre\Phpx\compile($this->fixtureCode("compile/supports-nested-component-names", "pre")))
2525
);
2626
}
2727
}

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ protected function parser()
1111

1212
protected function fixtureCode($path, $extension = "txt")
1313
{
14-
return trim(file_get_contents(__DIR__ . "/fixtures/{$path}.{$extension}"));
14+
return file_get_contents(__DIR__ . "/fixtures/{$path}.{$extension}");
1515
}
1616

1717
protected function fixtureData($path, $extension = "php")

tests/fixtures/compile/can-compile.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ function Error($props)
77
"render" => function ($error) {
88
return render("span", [
99
"className" => "error",
10-
"children" => $error,
10+
"children" => $error
1111
]);
1212
},
1313
"children" => [
1414
render("span", [
15-
"className" => "icon",
15+
"className" => "icon"
1616
]),
1717
"You forgot the",
1818
$props->name,
19-
"field",
20-
],
19+
"field"
20+
]
2121
]);
2222
}
2323

@@ -26,15 +26,15 @@ function ErrorRenderer($props)
2626
return render("Error", [
2727
"children" => function ($error) {
2828
return render("span", [
29-
"children" => $error,
29+
"children" => $error
3030
]);
31-
},
31+
}
3232
]);
3333
}
3434

3535
function InputRenderer($props)
3636
{
3737
return render("input", [
38-
"type" => $props->type,
38+
"type" => $props->type
3939
]);
4040
}
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
<?php
22

3-
namespace Example
4-
{
3+
namespace Example {
54
function MyComponent()
65
{
76
return render("div", [
8-
"children" => "hello world",
7+
"children" => "hello world"
98
]);
109
}
1110
}
1211

13-
namespace
14-
{
12+
namespace {
1513
function render($name, $props = null)
1614
{
1715
print $name;
1816
}
19-
20-
print render("Example\\MyComponent", []);
17+
18+
print render("Example\MyComponent", []);
2119
}

tests/fixtures/nodes/can-arrange-nodes.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function Error(\$props) {
1616
[
1717
[
1818
"type" => "literal",
19-
"value" => "\$error ",
19+
"value" => "\$error ~>",
2020
],
2121
[
2222
"type" => "tag",
@@ -38,11 +38,11 @@ function Error(\$props) {
3838
"value" => "\$error",
3939
],
4040
],
41-
"started" => 37,
41+
"started" => 36,
4242
],
4343
],
4444
"name" => "span",
45-
"started" => 30,
45+
"started" => 29,
4646
],
4747
],
4848
],

tests/fixtures/nodes/can-arrange-nodes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function Error($props) {
22
return (
3-
<div render={$error <span className={"error"}>{$error}</span>}>
3+
<div render={$error ~> <span className={"error"}>{$error}</span>}>
44
You forgot the {$props->name} field
55
</div>
66
);

0 commit comments

Comments
 (0)