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.
Babel 7.10 is going to support parsing stage-1 module attributes
Currently this plugin will transform the code above to
where module attributes are excluded.
Given that node
requiresupports JSON, I think the current situation is still acceptable, but only iftype: "json"is the only accepted in the proposal. That said, if the spec will allow othertypevalues in the future, we should decideShould 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.