With the switch to ECMAScript modules, main Reffy functions were exported as named exports but there was no default export, meaning Reffy could be imported through:
import * as reffy from 'reffy';
import { crawlSpecs } from 'reffy';
... but there was no way to write:
import reffy from 'reffy';
This update makes it possible to do either:
import reffy from 'reffy';
import { crawlSpecs } from 'reffy';
Now, the dark side of this feature requires lines some might consider to be unnatural... In particular, that requires writing similar things 3 times in index.js:
First, to import named exports from the different modules
Second, to create named exports
Third, to create a default Reffy export, a sort of static class that exposes the functions.
There's no way to reduce that (if there is a way, I don't know how :)). That makes me wonder whether this approach is good practice?
For example, there is a specific syntax in JavaScript for re-exporting values from other modules:
export { crawlSpecs } from "./src/lib/specs-crawler.js";
That is tempting! But that syntax does not import crawlSpecs and so cannot be used to also create a default export with crawlSpecs as a property.
Also, while they are written the same way, the values of the export and export default syntaxes cannot be combined because they are conceptually different beasts: the former is a list of names, the latter an object with properties.
The update does similar magic for the parse-webidl.js module. The post-processor module only exports the processor as a sort of static class and does not create named exports, because that's how the module is used in practice.
With the switch to ECMAScript modules, main Reffy functions were exported as named exports but there was no default export, meaning Reffy could be imported through:
... but there was no way to write:
This update makes it possible to do either:
Now, the dark side of this feature requires lines some might consider to be unnatural... In particular, that requires writing similar things 3 times in
index.js
:There's no way to reduce that (if there is a way, I don't know how :)). That makes me wonder whether this approach is good practice?
For example, there is a specific syntax in JavaScript for re-exporting values from other modules:
That is tempting! But that syntax does not import
crawlSpecs
and so cannot be used to also create a default export withcrawlSpecs
as a property.Also, while they are written the same way, the values of the
export
andexport default
syntaxes cannot be combined because they are conceptually different beasts: the former is a list of names, the latter an object with properties.The update does similar magic for the
parse-webidl.js
module. The post-processor module only exports the processor as a sort of static class and does not create named exports, because that's how the module is used in practice.