WICG / import-maps

How to control the behavior of JavaScript imports
https://html.spec.whatwg.org/multipage/webappapis.html#import-maps
Other
2.65k stars 69 forks source link

An empty map was create twice if "imports" or "scopes" exists #271

Closed allstarschh closed 2 years ago

allstarschh commented 2 years ago

https://wicg.github.io/import-maps/#parse-an-import-map-string

  1. Let sortedAndNormalizedImports be an empty map.

The first empty map is created here.

4.2. Set sortedAndNormalizedImports to the result of sorting and normalizing a specifier map given parsed["imports"] and baseURL.

https://wicg.github.io/import-maps/#sort-and-normalize-a-specifier-map

  1. Let normalized be an empty map.

Here is the creation of the second empty map, in the sequence (when "imports" exists in import map) The first empty map is redundant.

guybedford commented 2 years ago

I believe this redundancy is just an intentional way of handling the second branch and declaration together to avoid unnecessary verbosity. If you'd like to suggest an editorial edit to explicitly have the else branch that might be an option.

domenic commented 2 years ago

Yes, precisely. This is not really redundant because if the "if" statement is not taken, then the variable still needs to be initialized, so we initialize it in step 3. If we don't overwrite it in step 4.2, this is useful. If we do, then that's fine too.