Skip to content

How should we deal with module attributes? #92

@JLHwung

Description

@JLHwung

Babel 7.10 is going to support parsing stage-1 module attributes

await import("./package.json", { with: { type: "json" } })

Currently this plugin will transform the code above to

await Promise.resolve().then(() => _interopRequireWildcard(require("./package.json")));

where module attributes are excluded.

Given that node require supports JSON, I think the current situation is still acceptable, but only if type: "json" is the only accepted in the proposal. That said, if the spec will allow other type values in the future, we should decide

Should we skip the import node with module attributes? Since we can offer a custom plugin to transform module attributes into bundler-specific annotations, e.g. import(/* webpackChunkName: "lodash" */ 'lodash')

Or should we still treat them as those without attributes? A warning message can be printed since it may not be natively supported on node.js, but users may intend to pass the transpiled sources through bundlers which may support them via file extensions.

I don't have preference between these two solutions, or maybe we should even pursuit for an option. Other solutions are definitely welcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions