8000 [AssetMapper] Fix enquoted string pattern · symfony/symfony@df618bd · GitHub
[go: up one dir, main page]

Skip to content

Commit df618bd

Browse files
smnandrefabpot
authored andcommitted
[AssetMapper] Fix enquoted string pattern
1 parent 243db27 commit df618bd

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/Symfony/Component/AssetMapper/Compiler/JavaScriptImportPathCompiler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ final class JavaScriptImportPathCompiler implements AssetCompilerInterface
3535
(?:\/\/.*) # Lines that start with comments
3636
|
3737
(?:
38-
\'(?:[^\'\\\\]|\\\\.)*\' # Strings enclosed in single quotes
38+
\'(?:[^\'\\\\\n]|\\\\.)*\' # Strings enclosed in single quotes
3939
|
40-
"(?:[^"\\\\]|\\\\.)*" # Strings enclosed in double quotes
40+
"(?:[^"\\\\\n]|\\\\.)*" # Strings enclosed in double quotes
4141
)
4242
|
4343
(?: # Import statements (script captured)
@@ -49,7 +49,7 @@ final class JavaScriptImportPathCompiler implements AssetCompilerInterface
4949
|
5050
\bimport\(
5151
)
52-
\s*[\'"`](\.\/[^\'"`]+|(\.\.\/)*[^\'"`]+)[\'"`]\s*[;\)]
52+
\s*[\'"`](\.\/[^\'"`\n]+|(\.\.\/)*[^\'"`\n]+)[\'"`]\s*[;\)]
5353
?
5454
/mx';
5555

src/Symfony/Component/AssetMapper/Tests/Compiler/JavaScriptImportPathCompilerTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@ public function testCompileFindsCorrectImports(string $input, array $expectedJav
6868
->willReturnCallback(function ($path) {
6969
return match ($path) {
7070
'/project/assets/foo.js' => new MappedAsset('foo.js', '/can/be/anything.js', publicPathWithoutDigest: '/assets/foo.js'),
71+
'/project/assets/bootstrap.js' => new MappedAsset('bootstrap.js', '/can/be/anything.js', publicPathWithoutDigest: '/assets/bootstrap.js'),
7172
'/project/assets/other.js' => new MappedAsset('other.js', '/can/be/anything.js', publicPathWithoutDigest: '/assets/other.js'),
7273
'/project/assets/subdir/foo.js' => new MappedAsset('subdir/foo.js', '/can/be/anything.js', publicPathWithoutDigest: '/assets/subdir/foo.js'),
74+
'/project/assets/styles/app.css' => new MappedAsset('styles/app.css', '/can/be/anything.js', publicPathWithoutDigest: '/assets/styles/app.css'),
75+
'/project/assets/styles/app.scss' => new MappedAsset('styles/app.scss', '/can/be/anything.js', publicPathWithoutDigest: '/assets/styles/app.scss'),
7376
'/project/assets/styles.css' => new MappedAsset('styles.css', '/can/be/anything.js', publicPathWithoutDigest: '/assets/styles.css'),
7477
'/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'),
7578
'/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
9093

9194
public static function provideCompileTests(): iterable
9295
{
96+
yield 'standard_symfony_app_js' => [
97+
'input' => <<<EOF
98+
import './bootstrap.js';
99+
100+
/*
101+
* Welcome to your app's main JavaScript file!
102+
*
103+
* This file will be included onto the page via the importmap() Twig function,
104+
* which should already be in your base.html.twig.
105+
*/
106+
import './styles/app.css';
107+
108+
console.log('This log comes from assets/app.js - welcome to AssetMapper! 🎉');
109+
EOF,
110+
'expectedJavaScriptImports' => [
111+
'/assets/bootstrap.js' => ['lazy' => false, 'asset' => 'bootstrap.js', 'add' => true],
112+
'/assets/styles/app.css' => ['lazy' => false, 'asset' => 'styles/app.css', 'add' => true],
113+
],
114+
];
115+
93116
yield 'dynamic_simple_double_quotes' => [
94117
'input' => 'import("./other.js");',
95118
'expectedJavaScriptImports' => ['/assets/other.js' => ['lazy' => true, 'asset' => 'other.js', 'add' => true]],

0 commit comments

Comments
 (0)
0