Skip to content

ambiguity with module type #72

@trusktr

Description

@trusktr
import source mod from './foo.dope'

if (mod instanceof WebAssembly.Module) console.log('a')
else if (mod instanceof ModuleSource) console.log('b')

Does this log "a" or "b"?

It seems like import attributes are required, otherwise if they are not, then that begs the question as to why import attributes are even required in the first place for importing anything other than JavaScript.

This seems to make sense:

import source mod from './foo.dope'

if (mod instanceof WebAssembly.Module) console.log('a')
else if (mod instanceof ModuleSource) console.log('b')  // THIS ONE
import source mod from './foo.dope' with { type: "wasm" }

if (mod instanceof WebAssembly.Module) console.log('a') // THIS ONE
else if (mod instanceof ModuleSource) console.log('b')

Otherwise without import attributes, we are saying that it is ok to determine the type of a module based on the file name, which we've already determined we do not want to do in the import attributes spec and that's why with { type: "whatever" } is required.

Seems there is a contradiction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions