Giter Site home page Giter Site logo

Comments (13)

littledan avatar littledan commented on July 24, 2024 1

This proposal is going to make trailing commas allowed in import().

from proposal-import-attributes.

devsnek avatar devsnek commented on July 24, 2024 1

I guess I don't see any real reason to police the number of arguments passed.

from proposal-import-attributes.

jridgewell avatar jridgewell commented on July 24, 2024 1

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.

ljharb avatar ljharb commented on July 24, 2024

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.

devsnek avatar devsnek commented on July 24, 2024

by convention we treat undefined and no argument the same now, it should be allowed.

from proposal-import-attributes.

JLHwung avatar JLHwung commented on July 24, 2024

@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.

littledan avatar littledan commented on July 24, 2024

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.

ljharb avatar ljharb commented on July 24, 2024

@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.

devsnek avatar devsnek commented on July 24, 2024

Why not just go all in and use |Arguments|

from proposal-import-attributes.

JLHwung avatar JLHwung commented on July 24, 2024

@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.

ljharb avatar ljharb commented on July 24, 2024

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.

jridgewell avatar jridgewell commented on July 24, 2024

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.

littledan avatar littledan commented on July 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.