Skip to content

Commit

Permalink
Engine: fixed source mapping with strict types [Closes #205]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 17, 2019
1 parent 53d256f commit 090695a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Latte/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ public function compile(string $name): string
throw $e->setSource($source, $line, $name);
}

if (!preg_match('#\n|\?#', $name)) {
$code = "<?php\n// source: $name\n?>" . $code;
}
if ($this->strictTypes) {
$code = "<?php\ndeclare(strict_types=1);\n?>" . $code;
}
if (!preg_match('#\n|\?#', $name)) {
$code = "<?php\n// source: $name\n?>" . $code;
}
$code = PhpHelpers::reformatCode($code);
return $code;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Latte/Engine.strictTypes.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ require __DIR__ . '/../bootstrap.php';
$latte = new Latte\Engine;
$latte->setLoader(new Latte\Loaders\StringLoader);
Assert::notContains('declare(strict_types=1)', $latte->compile(''));
Assert::same('// source: {123}', explode("\n", $latte->compile('{123}'))[1]);

$latte->setStrictTypes(true);
Assert::contains('declare(strict_types=1)', $latte->compile(''));

Assert::noError(function () use ($latte) {
$latte->render('');
});

Assert::contains('declare(strict_types=1)', $latte->compile(''));
Assert::same('// source: {123}', explode("\n", $latte->compile('{123}'))[1]);

0 comments on commit 090695a

Please sign in to comment.