diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
index 445cf6b954..91c2dab87e 100644
a
|
b
|
import posixpath
|
4 | 4 | import re |
5 | 5 | from urllib.parse import unquote, urldefrag, urlsplit, urlunsplit |
6 | 6 | |
| 7 | import pyparsing |
| 8 | |
7 | 9 | from django.conf import STATICFILES_STORAGE_ALIAS, settings |
8 | 10 | from django.contrib.staticfiles.utils import check_settings, matches_patterns |
9 | 11 | from django.core.exceptions import ImproperlyConfigured |
… |
… |
class HashedFilesMixin:
|
103 | 105 | super().__init__(*args, **kwargs) |
104 | 106 | self._patterns = {} |
105 | 107 | self.hashed_files = {} |
| 108 | self.comment_remover = pyparsing.cpp_style_comment.suppress() |
106 | 109 | for extension, patterns in self.patterns: |
107 | 110 | for pattern in patterns: |
108 | 111 | if isinstance(pattern, (tuple, list)): |
… |
… |
class HashedFilesMixin:
|
363 | 366 | try: |
364 | 367 | content = pattern.sub(converter, content) |
365 | 368 | except ValueError as exc: |
366 | | yield name, None, exc, False |
| 369 | # Try a second time with comments removed. |
| 370 | content = self.comment_remover.transform_string(content) |
| 371 | try: |
| 372 | content = pattern.sub(converter, content) |
| 373 | except ValueError as exc: |
| 374 | yield name, None, exc, False |
367 | 375 | if hashed_file_exists: |
368 | 376 | self.delete(hashed_name) |
369 | 377 | # then save the processed result |
diff --git a/tests/staticfiles_tests/project/documents/cached/module.js b/tests/staticfiles_tests/project/documents/cached/module.js
index 7764e740d6..61def68e9b 100644
a
|
b
|
export {
|
20 | 20 | firstVar as firstVarAlias, |
21 | 21 | secondVar as secondVarAlias |
22 | 22 | } from "./module_test.js"; |
| 23 | |
| 24 | // Imports inside comments should be ignored. |
| 25 | /** |
| 26 | * @param {HTMLElement} elt |
| 27 | * @returns {import("./htmx").HtmxTriggerSpecification[]} |
| 28 | */ |
diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py
index 11b160945e..482ee3b5a3 100644
a
|
b
|
class TestHashedFiles:
|
179 | 179 | |
180 | 180 | def test_module_import(self): |
181 | 181 | relpath = self.hashed_file_path("cached/module.js") |
182 | | self.assertEqual(relpath, "cached/module.55fd6938fbc5.js") |
| 182 | self.assertEqual(relpath, "cached/module.7b546b090392.js") |
183 | 183 | tests = [ |
184 | 184 | # Relative imports. |
185 | 185 | b'import testConst from "./module_test.477bbebe77f0.js";', |
… |
… |
class TestHashedFiles:
|
207 | 207 | |
208 | 208 | def test_aggregating_modules(self): |
209 | 209 | relpath = self.hashed_file_path("cached/module.js") |
210 | | self.assertEqual(relpath, "cached/module.55fd6938fbc5.js") |
| 210 | self.assertEqual(relpath, "cached/module.7b546b090392.js") |
211 | 211 | tests = [ |
212 | 212 | b'export * from "./module_test.477bbebe77f0.js";', |
213 | 213 | b'export { testConst } from "./module_test.477bbebe77f0.js";', |