# \`import source\`: why not an attribute?

**URL:** <https://es.discourse.group/t/import-source-why-not-an-attribute/2621>\
**Category:** I have questions\
**Created:** [July 18, 2026, 9:11am UTC](https://es.discourse.group/t/import-source-why-not-an-attribute/2621 "2026-07-18T09:11:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh-Cena](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/josh-cena/32/1408_2.png) [@Josh-Cena](https://es.discourse.group/u/Josh-Cena)\
**Post date:** [July 18, 2026, 9:11am UTC](https://es.discourse.group/t/import-source-why-not-an-attribute/2621/1 "2026-07-18T09:11:03Z")

</div>

I'm finding the new `import source` syntax barely justifiable because we already have the now-omnipotent `with` that can basically change everything about module-importing, so I'm wondering: what benefits does `import source x from "x"` offer over `import x from "x" with { phase: "source" }`, given that both are statically analyzable, and that both `import("x", { phase: "source" })` and `import.source("x")` are only statically analyzable to a limited extent?

(I might have seen this discussion in one of the proposal repos, but there are too many with overlapping concerns.)

---

<div class="post-metadata">

**Author:** ![juner](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/juner/32/2377_2.png) [@juner](https://es.discourse.group/u/juner)\
**Post date:** [July 21, 2026, 1:40am UTC](https://es.discourse.group/t/import-source-why-not-an-attribute/2621/2 "2026-07-21T01:40:12Z")

</div>

I wonder if the key issue is that `phase` and import attributes are intended to live at different conceptual layers.

My understanding is that `with { ... }` is specifically for _import attributes_: metadata that influences how the referenced module is handled by the host. By contrast, `phase` seems to affect what kind of thing the import operation itself yields. For example, a source-phase import produces a `ModuleSource`-like value rather than the usual module namespace object.

If that's the distinction being drawn, then `phase` may not naturally fit into the import-attributes space at all. In that framing, the alternatives would be:

- a dedicated syntax such as `import source ...`
- some separate syntactic position for phase information (analogous to how dynamic import could conceptually separate `{ phase, with }`)

rather than expressing it as another entry inside `with { ... }`.

So perhaps the question is less "why not `with { phase: "source" }`?" and more "should `phase` be considered an import attribute in the first place?"

---

<div class="post-metadata">

**Author:** ![Josh-Cena](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/josh-cena/32/1408_2.png) [@Josh-Cena](https://es.discourse.group/u/Josh-Cena)\
**Post date:** [July 21, 2026, 7:09am UTC](https://es.discourse.group/t/import-source-why-not-an-attribute/2621/3 "2026-07-21T07:09:11Z")

</div>

Now when I look back at it, the biggest difference might be module caching? `import x from "foo"` and `import source x from "foo"` both import from `foo` so the module wouldn't be fetched and evaluated twice. `import x from "foo"` and `import x from "foo" with { phase: "foo" }` will be two different modules.

---

<div class="post-metadata">

**Author:** ![juner](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/juner/32/2377_2.png) [@juner](https://es.discourse.group/u/juner)\
**Post date:** [July 21, 2026, 8:27am UTC](https://es.discourse.group/t/import-source-why-not-an-attribute/2621/4 "2026-07-21T08:27:45Z")

</div>

That's an interesting point. Although I wonder if that might itself be evidence that `phase` doesn't fit naturally into the import-attributes model.

If import attributes participate in module identity and caching, but source-phase imports are expected to refer to the same underlying module record as normal imports, then perhaps `phase` is describing a different aspect of the import system entirely rather than an attribute of the module request.

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [July 21, 2026, 8:34am UTC](https://es.discourse.group/t/import-source-why-not-an-attribute/2621/5 "2026-07-21T08:34:20Z")

</div>

Caching is certainly one aspect for sure.

`import source` doesn't evaluate the module but you're right that it wouldn't be fetched twice in that example. The cache key for module source is the combination of: referrer, specifier, and attributes.

So:

```javascript
import source src from "here" with { someHostAttribute: "42" };
import * as namespace from "here" { someHostAttribute: "42" };
const namespace2 = await import(src);
// The spec says that the following must hold:
assert(namespace2 === namespace);

```

The spec could have reserved "phase" as a special attribute that is handled at a different layer but the champions felt it was better to keep the layering syntactically separate.

---

<div class="post-metadata">

**Author:** ![Josh-Cena](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/josh-cena/32/1408_2.png) [@Josh-Cena](https://es.discourse.group/u/Josh-Cena)\
**Post date:** [July 21, 2026, 8:50am UTC](https://es.discourse.group/t/import-source-why-not-an-attribute/2621/6 "2026-07-21T08:50:56Z")

</div>

Thanks, that makes sense. By "not evaluated twice", I mean that with `await import(src)` as well as `import * as namespace`, the module in `"here"` will only be evaluated once, right?

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [July 21, 2026, 9:17am UTC](https://es.discourse.group/t/import-source-why-not-an-attribute/2621/7 "2026-07-21T09:17:42Z")

</div>

Yep exactly
