Use general key-value syntax, or a single string? · Issue #12 · tc39/proposal-import-attributes (original) (raw)
In the original thread at WICG/webcomponents#839, there are several suggestions of syntax which includes a single string, rather than key-value syntax. Let's discuss the advantages and disadvantages of this option in this thread.
For example, the syntax for an import statement could be:
import json from "./foo.json" as "json";
Advantages of a single string
- Less to type: save 6 characters of "
type:
". Including the type will be annoying enough as is! - Less overall complexity for the syntax and semantics
- Less to coordinate across environments (c.f., Use cases for module attributes besides module type #8, h/t to @MylesBorins for raising this issue)
Advantages of key-value syntax
- Generalizes to other use cases (c.f., Use cases for module attributes besides module type #8). Additional module parameters was an idea tossed around from even before this issue, so even if we don't find one of those use cases persuading now, we have some circumstantial evidence that it may come up in the future.
- If we don't provide a general k/v syntax, there's a chance that people will see the need to do so inside the string (as was already proposed for the module specifier, see Should a syntax within module specifiers be used for this data instead? #11)
- The
as
keyword is likely to be pretty confusing, as it's also a keyword with completely different meaning in other parts of an import statement
My opinion is that the advantages of a general key-value syntax outweigh the advantages for a single string. It's circumstantial evidence (since this proposal doesn't suggest acting on any of them yet), but the relatively high number of other possible use cases points to a k/v syntax to me. This would be analogous to the decision to make import.meta
an object, rather than just adding a syntax for import.meta.url
.