Skip to content

Commit 093f7ce

Browse files
authored
Merge pull request #11 from pug-php/dependencies-merge
Dependencies merge
2 parents 6ca4d78 + 0376d04 commit 093f7ce

File tree

5 files changed

+31
-18
lines changed

5 files changed

+31
-18
lines changed

src/JsPhpize/JsPhpize.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function compile($input, $filename = null)
5454

5555
$dependencies = $compiler->getDependencies();
5656
if ($this->getOption('catchDependencies')) {
57-
$this->dependencies = $dependencies;
57+
$this->dependencies = array_merge($this->dependencies, $dependencies);
5858
$dependencies = array();
5959
}
6060
$php = $compiler->compileDependencies($dependencies) . $php;
@@ -98,6 +98,18 @@ public function compileDependencies()
9898
return $compiler->compileDependencies($this->dependencies);
9999
}
100100

101+
/**
102+
* Flush all saved dependencies.
103+
*
104+
* @return $this
105+
*/
106+
public function flushDependencies()
107+
{
108+
$this->dependencies = array();
109+
110+
return $this;
111+
}
112+
101113
/**
102114
* Compile and return the code execution result.
103115
*

src/JsPhpize/Parser/Parser.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ protected function parseParentheses()
9393

9494
continue;
9595
}
96-
$this->unexpected($token);
96+
throw $this->unexpected($token);
9797
}
9898
if ($value = $this->getValueFromToken($token)) {
9999
$expectComma = true;
100100
$parentheses->addNode($value);
101101

102102
continue;
103103
}
104-
$this->unexpected($token);
104+
throw $this->unexpected($token);
105105
}
106106

107107
throw new Exception('Missing ) to match ' . $exceptionInfos, 5);
@@ -122,15 +122,15 @@ protected function parseHooksArray()
122122

123123
continue;
124124
}
125-
$this->unexpected($token);
125+
throw $this->unexpected($token);
126126
}
127127
if ($value = $this->getValueFromToken($token)) {
128128
$expectComma = true;
129129
$array->addItem($value);
130130

131131
continue;
132132
}
133-
$this->unexpected($token);
133+
throw $this->unexpected($token);
134134
}
135135

136136
throw new Exception('Missing ] to match ' . $exceptionInfos, 6);
@@ -151,7 +151,7 @@ protected function parseBracketsArray()
151151

152152
continue;
153153
}
154-
$this->unexpected($token);
154+
throw $this->unexpected($token);
155155
}
156156
if ($pair = $this->getBracketsArrayItemKeyFromToken($token)) {
157157
list($key, $value) = $pair;
@@ -160,7 +160,7 @@ protected function parseBracketsArray()
160160

161161
continue;
162162
}
163-
$this->unexpected($token);
163+
throw $this->unexpected($token);
164164
}
165165

166166
throw new Exception('Missing } to match ' . $exceptionInfos, 7);
@@ -237,13 +237,13 @@ protected function parseFunction($token)
237237
$token = $this->get(0);
238238
}
239239
if (!$token->is('(')) {
240-
$this->unexpected($token);
240+
throw $this->unexpected($token);
241241
}
242242
$this->skip();
243243
$function->setValue($this->parseParentheses());
244244
$token = $this->get(0);
245245
if (!$token->is('{')) {
246-
$this->unexpected($token);
246+
throw $this->unexpected($token);
247247
}
248248
$this->skip();
249249
$this->parseBlock($function);
@@ -291,7 +291,7 @@ protected function parseLet($token)
291291
{
292292
$letVariable = $this->get(0);
293293
if (!$letVariable->is('variable')) {
294-
$this->unexpected($letVariable, $token);
294+
throw $this->unexpected($letVariable, $token);
295295
}
296296

297297
return $letVariable->value;
@@ -319,7 +319,7 @@ protected function parseInstructions($block)
319319
$block->endInstruction();
320320
continue;
321321
}
322-
$this->unexpected($token);
322+
throw $this->unexpected($token);
323323
}
324324
}
325325

src/JsPhpize/Parser/TokenCrawler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ protected function exceptionInfos()
3737

3838
protected function unexpected($token)
3939
{
40-
throw new Exception('Unexpected ' . $token->type . rtrim(' ' . ($token->value ?: '')) . $this->exceptionInfos(), 8);
40+
return new Exception('Unexpected ' . $token->type . rtrim(' ' . ($token->value ?: '')) . $this->exceptionInfos(), 8);
4141
}
4242
}

src/JsPhpize/Parser/TokenExtractor.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected function getBracketsArrayItemKeyFromToken($token)
3131
throw new Exception('Missing value after ' . $value . $this->exceptionInfos(), 12);
3232
}
3333
if (!$token->is(':')) {
34-
$this->unexpected($token);
34+
throw $this->unexpected($token);
3535
}
3636
$key = new Constant($type, $value);
3737
$value = $this->expectValue($this->next());
@@ -50,7 +50,7 @@ protected function getVariableChildFromToken($token)
5050
return new Constant('string', var_export($token->value, true));
5151
}
5252

53-
$this->unexpected($token);
53+
throw $this->unexpected($token);
5454
}
5555

5656
if ($token->is('[')) {
@@ -68,7 +68,7 @@ protected function getVariableChildFromToken($token)
6868
return $value;
6969
}
7070

71-
$this->unexpected($token);
71+
throw $this->unexpected($token);
7272
}
7373
}
7474

@@ -145,7 +145,7 @@ protected function appendFunctionsCalls(&$value)
145145
{
146146
while ($token = $this->get(0)) {
147147
if ($token->is('{') || $token->expectNoLeftMember()) {
148-
$this->unexpected($this->next());
148+
throw $this->unexpected($this->next());
149149
}
150150
if ($token->is('?')) {
151151
$this->skip();
@@ -191,13 +191,13 @@ protected function expectValue($next, $token = null)
191191
{
192192
if (!$next) {
193193
if ($token) {
194-
$this->unexpected($token);
194+
throw $this->unexpected($token);
195195
}
196196
throw new Exception('Value expected after ' . $this->exceptionInfos(), 20);
197197
}
198198
$value = $this->getValueFromToken($next);
199199
if (!$value) {
200-
$this->unexpected($next);
200+
throw $this->unexpected($next);
201201
}
202202

203203
return $value;

tests/mainMethods.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function testCompileFile()
3434
$this->assertSame($expected, $actual);
3535

3636
$actual = $jsPhpizeCatchDeps->compileDependencies();
37+
$jsPhpizeCatchDeps->flushDependencies();
3738
$expected = '$GLOBALS[\'__jpv_dot\'] = ' . file_get_contents(__DIR__ . '/../src/JsPhpize/Compiler/Helpers/Dot.h') . ';';
3839
$expected .= '$GLOBALS[\'__jpv_plus\'] = ' . file_get_contents(__DIR__ . '/../src/JsPhpize/Compiler/Helpers/Plus.h') . ';';
3940

0 commit comments

Comments
 (0)