diff --git a/src/Symfony/Component/AssetMapper/Compiler/JavaScriptImportPathCompiler.php b/src/Symfony/Component/AssetMapper/Compiler/JavaScriptImportPathCompiler.php index 16a325a016cbf..9c10835b46004 100644 --- a/src/Symfony/Component/AssetMapper/Compiler/JavaScriptImportPathCompiler.php +++ b/src/Symfony/Component/AssetMapper/Compiler/JavaScriptImportPathCompiler.php @@ -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) @@ -49,7 +49,7 @@ final class JavaScriptImportPathCompiler implements AssetCompilerInterface | \bimport\( ) - \s*[\'"`](\.\/[^\'"`]+|(\.\.\/)*[^\'"`]+)[\'"`]\s*[;\)] + \s*[\'"`](\.\/[^\'"`\n]+|(\.\.\/)*[^\'"`\n]+)[\'"`]\s*[;\)] ? /mx'; diff --git a/src/Symfony/Component/AssetMapper/Tests/Compiler/JavaScriptImportPathCompilerTest.php b/src/Symfony/Component/AssetMapper/Tests/Compiler/JavaScriptImportPathCompilerTest.php index aa57145b3ce1d..0b1d09e980d7a 100644 --- a/src/Symfony/Component/AssetMapper/Tests/Compiler/JavaScriptImportPathCompilerTest.php +++ b/src/Symfony/Component/AssetMapper/Tests/Compiler/JavaScriptImportPathCompilerTest.php @@ -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'), @@ -90,6 +93,26 @@ public function testCompileFindsCorrectImports(string $input, array $expectedJav public static function provideCompileTests(): iterable { + yield 'standard_symfony_app_js' => [ + 'input' => << [ + '/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]],