Skip to content

Commit 4f99a28

Browse files
committed
Dedupe dependencies
1 parent df395ad commit 4f99a28

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/JsPhpize/JsPhpize.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function compile($input, $filename = null)
7878

7979
$dependencies = $compiler->getDependencies();
8080
if ($this->getOption('catchDependencies')) {
81-
$this->dependencies = array_merge($this->dependencies, $dependencies);
81+
$this->dependencies = array_unique(array_merge($this->dependencies, $dependencies));
8282
$dependencies = array();
8383
}
8484

tests/compile.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,30 @@ public function testCompileWithoutDependencies()
4848
$this->assertSame($expected, $actual);
4949
}
5050

51+
public function testDependenciesGrouping()
52+
{
53+
$jsPhpize = new JsPhpize(array(
54+
'catchDependencies' => true,
55+
));
56+
$jsPhpize->compileCode("a = 4 + 5;\n b = '9' + '3'");
57+
$jsPhpize->compileCode('4 + 5');
58+
$jsPhpize->compileCode('4 + 5 + 9');
59+
$jsPhpize->compileCode('a.b.c');
60+
$jsPhpize->compileCode("a.b();\nc = a.c");
61+
$jsPhpize->compileCode('a.b');
62+
$jsPhpize->compileCode('a.b');
63+
64+
$this->assertSame(1, mb_substr_count(
65+
$jsPhpize->compileDependencies(),
66+
'$GLOBALS[\'__jpv_dot\'] = function ($base) {'
67+
));
68+
69+
$this->assertSame(1, mb_substr_count(
70+
$jsPhpize->compileDependencies(),
71+
'$GLOBALS[\'__jpv_plus\'] = function ($base) {'
72+
));
73+
}
74+
5175
public function testTruncatedCode()
5276
{
5377
$jsPhpize = new JsPhpize(array(

0 commit comments

Comments
 (0)