File tree 1 file changed +26
-1
lines changed
Filter options
src/Symfony/Component/AssetMapper/Compiler
1 file changed +26
-1
lines changed
Original file line number Diff line number Diff line change @@ -35,7 +35,32 @@ public function __construct(
35
35
36
36
public function compile (string $ content , MappedAsset $ asset , AssetMapperInterface $ assetMapper ): string
37
37
{
38
- return preg_replace_callback (self ::ASSET_URL_PATTERN , function ($ matches ) use ($ asset , $ assetMapper ) {
38
+ preg_match_all ('/\/\*|\*\// ' , $ content , $ commentMatches , \PREG_OFFSET_CAPTURE );
39
+
40
+ $ start = null ;
41
+ $ commentBlocks = [];
42
+ foreach ($ commentMatches [0 ] as $ match ) {
43
+ if ('/* ' === $ match [0 ]) {
44
+ $ start = $ match [1 ];
45
+ } elseif ($ start ) {
46
+ $ commentBlocks [] = [$ start , $ match [1 ]];
47
+ $ start = null ;
48
+ }
49
+ }
50
+
51
+ return preg_replace_callback (self ::ASSET_URL_PATTERN , function ($ matches ) use ($ asset , $ assetMapper , $ commentBlocks ) {
52
+ $ matchPos = $ matches [0 ][1 ];
53
+
54
+ // Ignore matchs inside comments
55
+ foreach ($ commentBlocks as $ block ) {
56
+ if ($ matchPos > $ block [0 ]) {
57
+ if ($ matchPos < $ block [1 ]) {
58
+ return $ matches [0 ][0 ];
59
+ }
60
+ break ;
61
+ }
62
+ }
63
+
39
64
try {
40
65
$ resolvedSourcePath = Path::join (\dirname ($ asset ->sourcePath ), $ matches [1 ]);
41
66
} catch (RuntimeException $ e ) {
You can’t perform that action at this time.
0 commit comments