Skip to content

Commit

Permalink
Blade newline fixes (#32026)
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell authored Mar 19, 2020
1 parent bcb7cda commit d35856b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/View/Compilers/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ protected function getRawPlaceholder($replace)
*/
protected function addFooters($result)
{
return ltrim($result, PHP_EOL)
.PHP_EOL.implode(PHP_EOL, array_reverse($this->footer));
return ltrim($result, "\n")
."\n".implode("\n", array_reverse($this->footer));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/View/Compilers/Concerns/CompilesComponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static function newComponentHash(string $component)
*/
public static function compileClassComponentOpening(string $component, string $data, string $hash)
{
return implode(PHP_EOL, [
return implode("\n", [
'<?php if (isset($component)) { $__componentOriginal'.$hash.' = $component; } ?>',
'<?php $component = $__env->getContainer()->make('.Str::finish($component, '::class').', '.($data ?: '[]').'); ?>',
'<?php if ($component->shouldRender()): ?>',
Expand All @@ -76,7 +76,7 @@ protected function compileEndComponent()
{
$hash = array_pop(static::$componentHashStack);

return implode(PHP_EOL, [
return implode("\n", [
'<?php if (isset($__componentOriginal'.$hash.')): ?>',
'<?php $component = $__componentOriginal'.$hash.'; ?>',
'<?php unset($__componentOriginal'.$hash.'); ?>',
Expand All @@ -92,7 +92,7 @@ protected function compileEndComponent()
*/
public function compileEndComponentClass()
{
return static::compileEndComponent().PHP_EOL.implode(PHP_EOL, [
return static::compileEndComponent()."\n".implode("\n", [
'<?php endif; ?>',
]);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/View/Blade/BladeComponentTagCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testSlotsCanBeCompiled()
$result = (new ComponentTagCompiler)->compileSlots('<x-slot name="foo">
</x-slot>');

$this->assertSame("@slot('foo') ".PHP_EOL.' @endslot', trim($result));
$this->assertSame("@slot('foo') \n".' @endslot', trim($result));
}

public function testBasicComponentParsing()
Expand Down
12 changes: 6 additions & 6 deletions tests/View/Blade/BladeExtendsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ public function testExtendsAreCompiled()
{
$string = '@extends(\'foo\')
test';
$expected = 'test'.PHP_EOL.'<?php echo $__env->make(\'foo\', \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>';
$expected = "test\n".'<?php echo $__env->make(\'foo\', \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>';
$this->assertEquals($expected, $this->compiler->compileString($string));

$string = '@extends(name(foo))'.PHP_EOL.'test';
$expected = 'test'.PHP_EOL.'<?php echo $__env->make(name(foo), \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>';
$string = '@extends(name(foo))'."\n".'test';
$expected = "test\n".'<?php echo $__env->make(name(foo), \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>';
$this->assertEquals($expected, $this->compiler->compileString($string));
}

public function testSequentialCompileStringCalls()
{
$string = '@extends(\'foo\')
test';
$expected = 'test'.PHP_EOL.'<?php echo $__env->make(\'foo\', \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>';
$expected = "test\n".'<?php echo $__env->make(\'foo\', \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>';
$this->assertEquals($expected, $this->compiler->compileString($string));

// use the same compiler instance to compile another template with @extends directive
$string = '@extends(name(foo))'.PHP_EOL.'test';
$expected = 'test'.PHP_EOL.'<?php echo $__env->make(name(foo), \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>';
$string = "@extends(name(foo))\ntest";
$expected = "test\n".'<?php echo $__env->make(name(foo), \Illuminate\Support\Arr::except(get_defined_vars(), [\'__data\', \'__path\']))->render(); ?>';
$this->assertEquals($expected, $this->compiler->compileString($string));
}
}

0 comments on commit d35856b

Please sign in to comment.