-
Notifications
You must be signed in to change notification settings - Fork 26
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
Unmixing type from other attributes #63
Comments
I would be fine disambiguating assertion based attributes with evaluator attributes. However, I do not currently see
Note: |
@bmeck (perhaps you've already done so) but could you elaborate on what other kinds of assertions you foresee applying? |
@ljharb some that come to mind off top of my head
|
|
yes, and WASM modules. see things like nodejs/node#33605 (comment) where this is also relevant to node, it also means that you don't have as many parallelism concerns in code like: import 'has-async-side-effects';
import 'needs-those-effects' with async=false;
The concern about JSON is the arbitrary code evaluation on export function foo() {
// code can go here
} Does not have any JS code that runs on
You cannot put a |
Sure, but timeout only really makes sense for dynamic import, as you said. If “declarative” is a thing, why is the type needed at all? |
@ljharb assertions are just about applying checks/guarantees and the different guarantees are all about being able to specify those clearly. An expectation of JSON as a type is different in nature to expectation of lack of effects. The web is interested in the JSON check currently. |
My understanding, though, is that the actual thing the web is interested in is what "declarative" does - ensuring that something that has no effects when you type the code, can't suddenly start having effects later. |
The particular web integration privilege escalation issue isn't about side effects or JSON per se but more about the privilege to run arbitrary code. You could imagine side effects which don't have the privilege to run arbitrary code (though my mind runs a little blank), or things which don't have that privilege which aren't JSON (e.g., CSS modules). We also talked about a "noexecute" flag, but ultimately that would also have to be some kind of thing associated with the module on the request's side, not the response. |
I strongly agree with this. But how do we achieve this? In future, it would be strange if a host doesn't support |
I like this idea 🎉 |
Yes, it does (not strictly). // hack.js
export function then() {
console.log('Ah ha')
return {}
}
// main.js
import('./hack.js', { declarative: true }).then(console.log)
// logs "Ah ha", the side effects. |
@littledan this entire proposal is for the request’s side, not the response’s? |
Things like #63 (comment) make me think that the JSON case is much simpler as a starting point than trying to iron out all possible places where code execution may occur due to things like string property protocols. I think starting with JSON is much simpler than trying to do most of these other attributes. E.G. Similar semantic concerns about |
I very much agree that any new attribute needs to be fully thought out and go through the process - I’m not on board with the current host grab bag approach. |
The way modules are served to JS engines is handled by the host; I don't see how we could move more into the JS spec. It's a core goal of this proposal to enable module types which aren't required to be supported in all JS implementations (e.g., HTML, CSS, and WebAssembly modules). This proposal tries to make This proposal works to require as much as possible in common between platforms. However, there are JS platforms that do not try to align with the web in how their module system works (e.g., XS/TC53), and this proposal works to not overstep those bounds, or prohibit future directions that have been proposed in this repository. |
Having read through the other issues, I note that this part of the proposal isn't exactly accurate:
As currently envisioned, the
type
option is indeed special. It defines the loader to use to transform the resource into its imported form. Any other additional attributes are really arguments for that loader.I mean, the reason there's a need for
type
in the first place is that we can't trust that a network request for a.json
file actually resolves to be a JSON file;type
is fulfilling the role that file extensions have traditionally taken.Making a keyword-based
type
explicitly special would also provide a way for those attributes not to need to be defined inline and separately for each import, by providing a key to use in a central registry for other attribute defaults.Finally, the simplicity of a string
as
value and the power of awith
key:value set of attributes are not mutually exhaustive. Why not have both?This sort of syntax would provide both simplicity and flexibility, allowing for often-used attribute sets to be controlled centrally, while maintaining the liberty of defining specific values for a single instance.
Overall, the role of module attributes seems rather similar to that fulfilled e.g. by Webpack loaders. This is what the Webpack docs say on this now, based on a few years of experience:
The text was updated successfully, but these errors were encountered: