#35553: HashedFilesMixin for ES modules does not work with `import*as ...` 
syntax
-------------------------------------+-------------------------------------
     Reporter:  Michael              |                    Owner:  Farhan
                                     |  Ali
         Type:  Bug                  |                   Status:  assigned
    Component:  contrib.staticfiles  |                  Version:  5.0
     Severity:  Normal               |               Resolution:
     Keywords:  Manifest  Static     |             Triage Stage:  Accepted
  Files Storage, javascript module   |
  scripts                            |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Farhan Ali):

 {{{#!diff

 diff --git a/django/contrib/staticfiles/storage.py
 b/django/contrib/staticfiles/storage.py
 index 85172ea42d..394975c9de 100644
 --- a/django/contrib/staticfiles/storage.py
 +++ b/django/contrib/staticfiles/storage.py
 @@ -73,6 +73,10 @@ class HashedFilesMixin:
                  r"""(?P<matched>import\(["'](?P<url>.*?)["']\))""",
                  """import("%(url)s")""",
              ),
 +            (
 +
 
r"""(?P<matched>(?P<import_as>import\s*\*as\s\S+)\s+from\s*["'](?P<url>[./].*?)["']\s*;)""",
 +                """%(import_as)s from "%(url)s";""",
 +            ),
          ),
      )
      patterns = (
 @@ -287,12 +291,10 @@ class HashedFilesMixin:

          # where to store the new paths
          hashed_files = {}
 -
          # build a list of adjustable files
          adjustable_paths = [
              path for path in paths if matches_patterns(path,
 self._patterns)
          ]
 -
          # Adjustable files to yield at end, keyed by the original path.
          processed_adjustable_paths = {}

 diff --git a/tests/staticfiles_tests/project/documents/cached/module.js
 b/tests/staticfiles_tests/project/documents/cached/module.js
 index 7764e740d6..602561798f 100644
 --- a/tests/staticfiles_tests/project/documents/cached/module.js
 +++ b/tests/staticfiles_tests/project/documents/cached/module.js
 @@ -2,6 +2,7 @@
  import rootConst from "/static/absolute_root.js";
  import testConst from "./module_test.js";
  import * as NewModule from "./module_test.js";
 +import *as m from "./module_test.js";
  import { testConst as alias } from "./module_test.js";
  import { firstConst, secondConst } from "./module_test.js";
  import {
 diff --git a/tests/staticfiles_tests/test_storage.py
 b/tests/staticfiles_tests/test_storage.py
 index dc8607a307..6290d9d51a 100644
 --- a/tests/staticfiles_tests/test_storage.py
 +++ b/tests/staticfiles_tests/test_storage.py
 @@ -643,7 +643,7 @@ class
 TestCollectionJSModuleImportAggregationManifestStorage(CollectionTestCase)

      def test_module_import(self):
          relpath = self.hashed_file_path("cached/module.js")
 -        self.assertEqual(relpath, "cached/module.55fd6938fbc5.js")
 +        self.assertEqual(relpath, "cached/module.0415cd43ac63.js")
          tests = [
              # Relative imports.
              b'import testConst from "./module_test.477bbebe77f0.js";',
 @@ -655,6 +655,8 @@ class
 TestCollectionJSModuleImportAggregationManifestStorage(CollectionTestCase)
              b'const dynamicModule =
 import("./module_test.477bbebe77f0.js");',
              # Creating a module object.
              b'import * as NewModule from
 "./module_test.477bbebe77f0.js";',
 +            # Creating a minified module object.
 +            b'import*as m from "./module_test.477bbebe77f0.js";',
              # Aliases.
              b'import { testConst as alias } from
 "./module_test.477bbebe77f0.js";',
              b"import {\n"
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35553#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701905b6be5cb-eb36266b-59d7-4d59-975a-2212e74aa095-000000%40eu-central-1.amazonses.com.

Reply via email to