-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import assertion type: 'javascript'
#7342
Comments
I agree with your reading of the specification that @dandclark @domenic can you take a look? |
Looking more closely at the import assertions specification, it actually describes in the host integration notes treating JavaScript as |
I think you're both correct, the spec as written allows I'd intended I think it's unlikely that this behavior will ever be specified either way in TC39, but I'm open to considering either direction here for HTML and React. We could either leave the HTML spec as-is and change the Chromium implementation, or update the spec so that it explicitly bans As I see it, the advantage of allowing A minor disadvantage of allowing it is simply that there would be more than one way to do the exact same thing, which is maybe non-ideal. Overall I prefer to sidestep those issues by banning Regarding the https://tc39.es/proposal-import-assertions/#sec-host-integration section, that's non-normative and was written well before the HTML spec integration in order to paint a picture of that would eventually look like. Now that the HTML spec integration has been done, I'm thinking that maybe we could just delete that section, since the actual HTML spec is now the source of truth. |
So I’ve been refereeing (and somewhat part of) a debate in nodejs/node#40790 and tc39/proposal-import-attributes#114 regarding how to handle this. The part I feel strongly about is what I titled tc39/proposal-import-attributes#114: that every “module format” (like JavaScript, JSON, CSS and Wasm) have exactly one valid type. Doing so makes the implementation much simpler, and avoids race conditions and a lot of associated complexity. This constraint is already present in the HTML spec by virtue of unspecified modules getting
And I think moving this into a more formal/explicit part of the spec would be a good idea. Beyond that, though, my goal is to try to make code written for Node interoperable with browsers as much as possible. So I don’t want Node to require The place where this has become an issue is with regard to Wasm. @guybedford and others in the Wasm community would strongly prefer Wasm to be importable without a mandatory type assertion; so What @guybedford and I think might be the cleanest solution is to simply rename If you agree with import './module.js';
import './module.js' assert { type: 'executable' };
import './module.wasm';
import './module.wasm' assert { type: 'executable' }; These would correspond to two entries in the module map: I think it’s good to allow the implicit type to be specified, so that users can write code like Beyond potentially renaming |
This is not how this feature was intended or designed. A module format may have 0, 1, or N valid types. |
@dandclark I think we should ban it for now. We can revisit when we're tackling Wasm or TC39 decides it's useful to have a name for the default. |
I agree we should ban it - it makes more sense for the default to allow both JS and Wasm. Looks like Chromium already implements the ban, indeed. |
I don't think there's any work on wasm modules on the web right now, so we can't make that sort of decision for you at this point. Someone else can correct me if I'm wrong. |
There’s some discussion in WebAssembly/esm-integration#42. Essentially though, if “lack of type” is assigned to Whether the implicit type is renamed to |
I think we should keep the implicit type as "javascript", but disallow it from appearing explicitly. Then we can change it later in the spec if we decide to share it with webassembly, since such a change would be only in the spec and not observable. But for now the string in the spec should (accurately) reflect the fact that such modules, in the spec, are JavaScript modules. |
Agreed. I put together a PR for this: #7350. |
Do you mind sharing the thought process behind how this decision was made in the first place, and how you feel about it now? As in, why have a string I’m not trying to imply that the decision was wrong; I just want to understand it, to get a sense of how this team feels about import assertions generally so that I can try to predict the future of the HTML spec with regard to this feature. For example, the fact that |
The HTML standard defines these concepts:
The identifiers reflect these concepts. If WebAssembly module scripts become a thing and there's a collaborative decision that they are indistinguishable from JavaScript module scripts, I suspect we'd pick a new name that represents both. In other words, I wouldn't try to read too much into anything. Things are pretty flexible as long as they are not exposed to the web. |
This was the original intent of the import assertions integration, but type: "javascript" was unintentionally allowed to work due to a bug involving the spec's internal use of the "javascript" module type for JavaScript module scripts. Fixes #7342.
This was the original intent of the import assertions integration, but type: "javascript" was unintentionally allowed to work due to a bug involving the spec's internal use of the "javascript" module type for JavaScript module scripts. Fixes whatwg#7342.
This was the original intent of the import assertions integration, but type: "javascript" was unintentionally allowed to work due to a bug involving the spec's internal use of the "javascript" module type for JavaScript module scripts. Fixes whatwg#7342.
Hi, I’m implementing support for import assertions in Node.js. I’m trying to make Node’s support for the feature align with the HTML spec for the module types that both Node and browsers support (JavaScript, JSON, potentially WebAssembly). I’m also trying to match some of the requirements of the HTML spec, such as including the assertion type in the module cache key, so that Node behaves similarly to browsers with regard to race conditions and module identity.
While reading the spec, I saw language such as this:
And this:
And I assumed that this meant that the spec permitted
javascript
as a module type. In other words, thatimport './file.js' assert { type: 'javascript' }
should be allowed and treated equivalently asimport './file.js'
, and both imports would map to the same entry in the module map, because they have the same type. I was so certain of this reading of the spec that I opened tc39/proposal-import-attributes#114 to suggest upstreaming this “treat the lack of a declared type as iftype: 'javascript'
was specified” behavior into the import assertions proposal. I opened nodejs/node#40790 and an accompanying PR to propose adding this behavior to Node, and when someone there pointed out that Chrome errors ontype: 'javascript'
I opened https://bugs.chromium.org/p/chromium/issues/detail?id=1270635 to report what I assumed was a bug in Chrome.But . . . am I misreading the spec? Is there some intent to disallow an explicit
assert { type: 'javascript' }
? @dandclark seemed to think so when he pushed https://chromium-review.googlesource.com/c/chromium/src/+/2751188 to add tests to Chromium that it should error on an explicittype: 'javascript'
. I assumed that back when those tests were written perhaps the spec was different, and it’s since expanded the scope oftype: 'javascript'
; but am I wrong about this?At the very least, the spec could be clearer one way or the other about whether an explicit
assert { type: 'javascript' }
for a JavaScript module is expected to succeed or fail. Everything I read in the spec text led me to assume that it should succeed (because why should it fail, if it’s implied by a missing type) so if it’s supposed to error, I would be very curious as to why that is and what that means for the “default” or “implied” module type.The text was updated successfully, but these errors were encountered: