Comments (3)
I definitely agree both would be useful, in particular for webassembly import source
is what you would be wanting if you are intending to use WebAssembly.instantiate
yourself.
import instance
is more useful when you just want a module to link/evaluate later, i.e. for transferring to a Worker
or just lazily evaluating the module. In these cases you don't really care what the source is (WASM or JS) just that provides the right module namespace when finally imported with import(...)
.
This is not achievable if this proposal only supports reflecting the module instance (and encourages us to use
module.source
to get the source) because the import will fail at the first time and there is no chance to get the source.
This is only true if import instance
also fetches all recursive dependencies, which Module
as proposed doesn't do anyway. It is the import(...)
of a module that triggers recursively fetching/linking, so only at that point would you actually hit the error.
i.e. If we had invalid module for browsers:
// some-node-dependent-module.js
import fs from "fs";
// do thing with fs
Then we had a loader than created a browser fs like you're doing (supposing only the equivalent of import instance
existed):
import instance browserFs from "browserFs";
// The browser could SPECULATIVELY try to link this module, but failures in linking
// won't be shown till import(...) on someNodeDependentModule is attempted
import instance someNodeDependentModule from "./some-node-dependent-module.js";
// Browser hasn't linked someNodeDependentModule so this is fine
const someNodeDependentModule = new Module(someNodeDependentModule.source, {
importHook(spec) {
if (spec === "fs") return browserFs;
},
});
// But trying this will fail as the browser would now attempt to link it
await import(someNodeDependentModule); // can't resolve "fs"
from proposal-source-phase-imports.
This is only true if import instance also fetches all recursive dependencies, which Module as proposed doesn't do anyway. It is the import(...) of a module that triggers recursively fetching/linking, so only at that point would you actually hit the error.
Thanks! You're correct, so instance reflection actually works?
from proposal-source-phase-imports.
We are deferring module instance reflection until module expression or module loader hooks progresses.
from proposal-source-phase-imports.
Related Issues (20)
- Parameterized Evaluators HOT 3
- trusted type representation superceding asset references HOT 6
- Relationship to asset references proposal HOT 14
- Use extensible object syntax? HOT 68
- Use special module specifier format HOT 2
- Reflect string versus boolean HOT 2
- Lazy versus eager reflection HOT 2
- Reflect with transitive dependencies HOT 6
- Stage 3 reviews HOT 8
- Consider a method-like `import` metaproperty for source phase imports HOT 6
- Disallow newlines between phase and identifier HOT 1
- Consider cost of `import source from` ambiguity
- `export source x from "y"` HOT 4
- Missing sources should throw a *SyntaxError* when imported HOT 3
- Is %AbstractModuleSource% synchronously reachable from script? HOT 2
- Bikeshedding the `source` keyword HOT 17
- Bikeshedding the `source` keyword: voting HOT 16
- WebAssembly compile-time imports HOT 7
- Name bikeshedding HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proposal-source-phase-imports.