Comments (13)
This proposal is going to make trailing commas allowed in import()
.
from proposal-import-attributes.
I guess I don't see any real reason to police the number of arguments passed.
from proposal-import-attributes.
I don't understand why we treat import
special. Just give it arguments. Who cares if you pass 0 args, 1 arg, or 100. If the first arg can be resolved to a specifier, then you're fine. And if the second arg is provided, and its a real object, you're fine.
That import
is a special keyword shouldn't change they way we process the arguments you pass to it. And it certainly shouldn't make import(foo, bar)
behave differently if bar
resolved to undefined
.
from proposal-import-attributes.
That seems like it'd allow a bug; why not the following?
const assets = [
["ad-banner.mjs"],
["i18n/zh.json", { type: "json" }]
];
for (const [path, attrs] of assets) {
await attrs ? import(path, attrs) : import(path);
}
from proposal-import-attributes.
by convention we treat undefined and no argument the same now, it should be allowed.
from proposal-import-attributes.
@ljharb The attrs
can be an empty string but I am not gonna nit-picking.
Since the second argument is optional, developers may align it mentally to function calls where passing undefined
is almost same as no arguments, except for arguments
or other edge cases.
from proposal-import-attributes.
I agree with @devsnek , that undefined
should be treated the same as no second parameter. On the other hand, I'd expect null
to cause a TypeError due to getting the with
property from it.
In the current draft in the explainer, you'd use { with: { type: "json" } }
as the second argument to import()
. We could discuss changing this in a separate issue, if you have concerns about it.
from proposal-import-attributes.
@devsnek not for import()
, or import(a,)
would be allowed.
If, however, this proposal is going to make trailing commas in import()
allowed, then i agree it should match with function call expectations.
from proposal-import-attributes.
Why not just go all in and use |Arguments|
from proposal-import-attributes.
@devsnek I think the concern here is still valid for import(a, b)
: Supporting SpreadElement requires runtime error check on argument length.
from proposal-import-attributes.
It's not a function tho, and it's very important it not be treated as one. Functions can be passed around, import()
can't, and functions - most importantly - do not behave differently based on where they are invoked, while import()
can.
from proposal-import-attributes.
We invoke it like a function, and it returns a value like a function. Whether the callee is a real value or a syntax form shouldn't affect the way we treat its arguments.
from proposal-import-attributes.
I see I thumbs-upped the comment on the restriction initially, but I'd be OK with weakening it to general |Arguments|, or keeping the two-arg, no-spread restrictions as in the current spec outline. I see this as a post-Stage 2, non-core bikeshed, since there are multiple options that would each be non-fatal, and the task is to figure out which is best.
from proposal-import-attributes.
Related Issues (20)
- Forward compatibility of ignoring unknown keys in the import(…) options bag HOT 1
- Examples? HOT 2
- HTML integration compatibility with assertion invariant HOT 28
- Broken references in import assertions
- There should be an escape hatch to allow unknown import attributes HOT 3
- Tracking feasibility of unshipping `assert` contextual keyword in Chrome HOT 8
- No need for NLTH with `with` keyword HOT 9
- Stage 3 reviews HOT 15
- Inferring module type from MIME type vs `type` attribute needs clarification HOT 7
- Changes due to stage 3 reviews to present in July 2023 HOT 2
- return of dynamic import() HOT 1
- Invalid attributes keys in static imports should be a resolution/loading error and not a parsing error HOT 5
- Consider restricting attribute keys syntax to identifiers and strings again HOT 12
- Adding WPT tests HOT 2
- Restrict generalization by scoping private keys HOT 2
- how to use this feature in browser without polyfil? HOT 5
- Support gating with Progressive Enhancement or Graceful Degredation HOT 4
- Importing arbitrary files as raw bytes HOT 1
- Trouble with JSON Imports in JavaScript HOT 4
- [spam]
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-import-attributes.