Skip to content

Commit

Permalink
let tailwind parser fail silently
Browse files Browse the repository at this point in the history
  • Loading branch information
heidkaemper committed Aug 4, 2024
1 parent e1d0165 commit 1c03718
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Breakpoints/Parser/TailwindParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Heidkaemper\Toolbar\Breakpoints\Parser;

use Illuminate\Support\Facades\Log;
use Peast\Peast;
use Peast\Syntax\Node\ObjectExpression;
use Peast\Syntax\Node\Property;
Expand Down Expand Up @@ -63,9 +64,18 @@ private function parseConfigFile($filename): void

$source = file_get_contents(base_path($filename));

$ast = Peast::latest($source, [
'sourceType' => Peast::SOURCE_TYPE_MODULE,
])->parse();
try {
$ast = Peast::latest($source, [
'sourceType' => Peast::SOURCE_TYPE_MODULE,
])->parse();
} catch (\Exception $exception) {
Log::debug('Failed to parse Tailwind CSS configuration', [
'message' => $exception->getMessage(),
'filename' => base_path($filename),
]);

return;
}

// search for 'screens' config
$query = $ast->query("Property[key.name='screens']");
Expand Down
12 changes: 12 additions & 0 deletions tests/Feature/TailwindBreakpointsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,15 @@
'test-max' => 'max-width: 456px',
]);
});

it('failes silent returns default values', function () {
file_put_contents($this->config, '{;;wrong syntax}');

expect($this->parser->parse())->toBe([
'sm' => 'min-width: 640px',
'md' => 'min-width: 768px',
'lg' => 'min-width: 1024px',
'xl' => 'min-width: 1280px',
'2xl' => 'min-width: 1536px',
]);
});

0 comments on commit 1c03718

Please sign in to comment.