Use export default
for main exported classes
#1631
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.