Skip to content

Commit

Permalink
Merge branch '6.4' into 7.0
Browse files Browse the repository at this point in the history
* 6.4:
  [DependencyInjection] Fix computing error messages involving service locators
  [Serializer] Fix unknown types normalization type when know type
  [ErrorHandler] Fix parsing messages that contain anonymous classes on PHP >= 8.3.3
  [AssetMapper] Fix enquoted string pattern
  [Validator] Review Romanian (ro) translations
  [Console] Fix display of Table on Windows OS
  [FrameworkBundle] Fix config builder with extensions extended in `build()`
  [Translation] Fix extracting qualified t() function calls
  Fix vertical table on windows
  Fix the `command -v` exception when the command option with a dash prefix
  [WebProfilerBundle] disable turbo in web profiler toolbar to avoid link prefetching
  explicitly cast boolean SSL stream options
  return the unchanged text if preg_replace_callback() fails
  the 'use_notify' option is on the factory, not on the postgres connection class
  review translations
  • Loading branch information
nicolas-grekas committed Feb 22, 2024
2 parents 3adedf5 + 07a7724 commit 7cd4215
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Compiler/JavaScriptImportPathCompiler.php
Expand Up @@ -35,9 +35,9 @@ final class JavaScriptImportPathCompiler implements AssetCompilerInterface
(?:\/\/.*) # Lines that start with comments
|
(?:
\'(?:[^\'\\\\]|\\\\.)*\' # Strings enclosed in single quotes
\'(?:[^\'\\\\\n]|\\\\.)*\' # Strings enclosed in single quotes
|
"(?:[^"\\\\]|\\\\.)*" # Strings enclosed in double quotes
"(?:[^"\\\\\n]|\\\\.)*" # Strings enclosed in double quotes
)
|
(?: # Import statements (script captured)
Expand All @@ -49,7 +49,7 @@ final class JavaScriptImportPathCompiler implements AssetCompilerInterface
|
\bimport\(
)
\s*[\'"`](\.\/[^\'"`]+|(\.\.\/)*[^\'"`]+)[\'"`]\s*[;\)]
\s*[\'"`](\.\/[^\'"`\n]+|(\.\.\/)*[^\'"`\n]+)[\'"`]\s*[;\)]
?
/mx';

Expand Down
23 changes: 23 additions & 0 deletions Tests/Compiler/JavaScriptImportPathCompilerTest.php
Expand Up @@ -68,8 +68,11 @@ public function testCompileFindsCorrectImports(string $input, array $expectedJav
->willReturnCallback(function ($path) {
return match ($path) {
'/project/assets/foo.js' => new MappedAsset('foo.js', '/can/be/anything.js', publicPathWithoutDigest: '/assets/foo.js'),
'/project/assets/bootstrap.js' => new MappedAsset('bootstrap.js', '/can/be/anything.js', publicPathWithoutDigest: '/assets/bootstrap.js'),
'/project/assets/other.js' => new MappedAsset('other.js', '/can/be/anything.js', publicPathWithoutDigest: '/assets/other.js'),
'/project/assets/subdir/foo.js' => new MappedAsset('subdir/foo.js', '/can/be/anything.js', publicPathWithoutDigest: '/assets/subdir/foo.js'),
'/project/assets/styles/app.css' => new MappedAsset('styles/app.css', '/can/be/anything.js', publicPathWithoutDigest: '/assets/styles/app.css'),
'/project/assets/styles/app.scss' => new MappedAsset('styles/app.scss', '/can/be/anything.js', publicPathWithoutDigest: '/assets/styles/app.scss'),
'/project/assets/styles.css' => new MappedAsset('styles.css', '/can/be/anything.js', publicPathWithoutDigest: '/assets/styles.css'),
'/project/assets/vendor/module_in_importmap_remote.js' => new MappedAsset('module_in_importmap_remote.js', '/can/be/anything.js', publicPathWithoutDigest: '/assets/module_in_importmap_remote.js'),
'/project/assets/vendor/@popperjs/core.js' => new MappedAsset('assets/vendor/@popperjs/core.js', '/can/be/anything.js', publicPathWithoutDigest: '/assets/@popperjs/core.js'),
Expand All @@ -90,6 +93,26 @@ public function testCompileFindsCorrectImports(string $input, array $expectedJav

public static function provideCompileTests(): iterable
{
yield 'standard_symfony_app_js' => [
'input' => <<<EOF
import './bootstrap.js';
/*
* Welcome to your app's main JavaScript file!
*
* This file will be included onto the page via the importmap() Twig function,
* which should already be in your base.html.twig.
*/
import './styles/app.css';
console.log('This log comes from assets/app.js - welcome to AssetMapper! 🎉');
EOF,
'expectedJavaScriptImports' => [
'/assets/bootstrap.js' => ['lazy' => false, 'asset' => 'bootstrap.js', 'add' => true],
'/assets/styles/app.css' => ['lazy' => false, 'asset' => 'styles/app.css', 'add' => true],
],
];

yield 'dynamic_simple_double_quotes' => [
'input' => 'import("./other.js");',
'expectedJavaScriptImports' => ['/assets/other.js' => ['lazy' => true, 'asset' => 'other.js', 'add' => true]],
Expand Down

0 comments on commit 7cd4215

Please sign in to comment.