Skip to content

Commit b7a0b66

Browse files
committed
Keep mixin call position trace
1 parent 13fc3f4 commit b7a0b66

File tree

2 files changed

+53
-7
lines changed

2 files changed

+53
-7
lines changed

src/Phug/Compiler/NodeCompiler/MixinCallNodeCompiler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function compileNode(ParserNodeInterface $node, ElementInterface $parent
2323
$node
2424
);
2525

26-
$mixinCall = new MixinCallElement();
26+
$mixinCall = new MixinCallElement($node, $parent);
2727

2828
/** @var MixinCallNode $node */
2929
$name = $node->getName();

tests/Phug/Compiler/NodeCompiler/MixinCallNodeCompilerTest.php

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class MixinCallNodeCompilerTest extends AbstractCompilerTest
1414
{
1515
/**
16-
* @group mixins
16+
* @group mixins
1717
* @covers ::<public>
1818
* @covers \Phug\Compiler\NodeCompiler\BlockNodeCompiler::<public>
1919
* @covers \Phug\Compiler\NodeCompiler\BlockNodeCompiler::compileAnonymousBlock
@@ -51,7 +51,7 @@ public function testCompile()
5151
}
5252

5353
/**
54-
* @group mixins
54+
* @group mixins
5555
* @covers ::<public>
5656
*/
5757
public function testCompileNestedMixins()
@@ -79,7 +79,7 @@ public function testCompileNestedMixins()
7979
}
8080

8181
/**
82-
* @group mixins
82+
* @group mixins
8383
* @covers ::<public>
8484
*/
8585
public function testCompileVariadicMixin()
@@ -101,7 +101,7 @@ public function testCompileVariadicMixin()
101101
}
102102

103103
/**
104-
* @group mixins
104+
* @group mixins
105105
* @covers ::<public>
106106
* @covers \Phug\Compiler\NodeCompiler\BlockNodeCompiler::<public>
107107
* @covers \Phug\Compiler\NodeCompiler\BlockNodeCompiler::compileAnonymousBlock
@@ -121,7 +121,7 @@ public function testDoubleBlock()
121121
}
122122

123123
/**
124-
* @group mixins
124+
* @group mixins
125125
* @covers ::<public>
126126
* @covers \Phug\Compiler::compileDocument
127127
* @covers \Phug\Compiler\NodeCompiler\BlockNodeCompiler::compileAnonymousBlock
@@ -174,7 +174,7 @@ public function testDynamicMixins()
174174
}
175175

176176
/**
177-
* @group mixins
177+
* @group mixins
178178
* @covers ::<public>
179179
* @covers \Phug\Compiler\NodeCompiler\MixinNodeCompiler::<public>
180180
*/
@@ -229,6 +229,49 @@ public function testOuterNodes()
229229
}
230230

231231
/**
232+
* @group mixins
233+
*/
234+
public function testMissingMixin()
235+
{
236+
$code = [
237+
'div'."\n",
238+
' p: +yolo()',
239+
];
240+
$exception = null;
241+
242+
try {
243+
$this->assertRender(
244+
[],
245+
$code,
246+
[
247+
'debug' => true,
248+
]
249+
);
250+
} catch (\InvalidArgumentException $e) {
251+
ob_end_clean();
252+
$exception = $e;
253+
} catch (\Exception $e) {
254+
ob_end_clean();
255+
$exception = $e;
256+
} catch (\Throwable $e) {
257+
ob_end_clean();
258+
$exception = $e;
259+
}
260+
261+
self::assertInstanceOf(\InvalidArgumentException::class, $exception);
262+
self::assertSame('Unknown yolo mixin called.', $exception->getMessage());
263+
264+
$php = $this->compiler->compile(implode("\n", $code));
265+
$lines = explode("\n", $php);
266+
$before = implode("\n", array_slice($lines, 0, $exception->getLine()));
267+
$pos = strrpos($before, '// PUG_DEBUG:');
268+
$after = str_replace('?><?php', '', substr($php, $pos));
269+
270+
self::assertSame('</p></div>', explode('?>', $after)[1]);
271+
}
272+
273+
/**
274+
* @group mixins
232275
* @covers ::<public>
233276
* @covers \Phug\Compiler\NodeCompiler\BlockNodeCompiler::<public>
234277
* @covers \Phug\Compiler\NodeCompiler\BlockNodeCompiler::compileAnonymousBlock
@@ -253,6 +296,7 @@ public function testMixinAttributes()
253296
}
254297

255298
/**
299+
* @group mixins
256300
* @covers ::<public>
257301
* @covers \Phug\Compiler\NodeCompiler\BlockNodeCompiler::<public>
258302
* @covers \Phug\Compiler\NodeCompiler\BlockNodeCompiler::compileAnonymousBlock
@@ -277,6 +321,7 @@ public function testMixinBlocks()
277321
}
278322

279323
/**
324+
* @group mixins
280325
* @covers ::<public>
281326
* @expectedException \Phug\CompilerException
282327
*/
@@ -292,6 +337,7 @@ public function testException()
292337
}
293338

294339
/**
340+
* @group mixins
295341
* @covers ::<public>
296342
* @expectedException \InvalidArgumentException
297343
*/

0 commit comments

Comments
 (0)