Skip to content
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

Should type: "js" work? #49

Open
dandclark opened this issue Mar 26, 2020 · 12 comments
Open

Should type: "js" work? #49

dandclark opened this issue Mar 26, 2020 · 12 comments

Comments

@dandclark
Copy link
Collaborator

Not sure if this has been discussed yet, but it occurred to me that we should consider allowing "js" (or maybe the full "javascript") as a valid value for the type key, e.g.:

import {whatever} from "./foo.js" with type: "js";

Which would be exactly equivalent to just:

import {whatever} from "./foo.js";

Pro: Consistency. It could be surprising to developers that specifying the type for "js" is is an error while other module types require it to be specified.
Con: Now there would be two ways to do the same thing since JS is the default.

Thoughts? I'm leaning towards saying that it should be supported but this is not a strongly held opinion.

@devsnek
Copy link
Member

devsnek commented Mar 26, 2020

type: 'source-text-module' perhaps, but not type: 'js'

@MylesBorins
Copy link
Member

MylesBorins commented Mar 26, 2020 via email

@devsnek
Copy link
Member

devsnek commented Mar 26, 2020

@MylesBorins maybe my intent was lost... all these modules are modules, but I assume the suggestion here is about modules authored as source text ecmascript modules. type: module seems like a tautology to me, all modules are modules.

@Jack-Works
Copy link
Member

Allowing a "js" type may simplify the code generation work

@littledan
Copy link
Member

I'd suggest omitting this. We will have to support the case where no type is specified. Is there really that significant of a benefit to include multiple ways to spell this case?

(The type: "module" suggestion seems pretty confusing to me, since all of these things are modules... The notion of type here does not correspond to classic/script vs module. I'd prefer type: "js" or type: "javascript" if we include one of these.)

@littledan littledan added this to the stage 3 milestone May 20, 2020
@littledan
Copy link
Member

I want to suggest: we can come back and add this between Stage 2 and 3 (or even later, after initially shipping, why not), but that we don't need type: "js" for a basic proposal when assessing coherence/viability of it. So I think coming to a conclusion on this question blocks Stage 3, but not Stage 2.

@xtuc
Copy link
Member

xtuc commented Jun 13, 2020

If an enviroment would want to only load modules with a type attribute we need to allow JS, however I'm not convienced that developers would use it if not necessary.

@Jamesernator
Copy link

I imagine people would want to use it in dynamic imports just for completeness e.g.:

const types = {
    ".js": "js",
    ".wasm": "webassembly",
    ".json": "json",
    ".html": "html",
}

const module = await import(url, { if: { type: types[getExtension(url)] } });

@guybedford
Copy link

"type": "javascript" is currently not implemented in Chrome. While a missing type is treated as JS equivalent in the spec, I think it would be useful to have further implementation guidance from the spec if hosts are expected to implement this type or not, which also relates to the JS / WebAssembly assertion discussion. If guidance is still unclear here then that should also be clarified in the spec.

@GeoffreyBooth
Copy link

If guidance is still unclear here then that should also be clarified in the spec.

In #114 I suggested that the proposal include type: 'javascript' to align with the HTML spec. Basically, the lack of an assertion type implies type: 'javascript', and cannot imply any other type.

@ljharb
Copy link
Member

ljharb commented Nov 15, 2021

That's not what was discussed in plenary, where consensus (as i recall) was to allow hosts to make any number of optional types that can mean the same thing as "no assertion".

@ljharb
Copy link
Member

ljharb commented Nov 15, 2021

There's the additional piece that Ecma doesn't own the copyright to the word "javascript" and I'm not sure if we'd be able to encode that in the spec.

@nicolo-ribaudo nicolo-ribaudo removed this from the stage 3 milestone Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests