I received an issue on GitHub about my ES2015 module import/export validating plugin for ESLint not recognizing the default
export in the following syntax:
export {
foo as default,
bar
}
where my plugin will lint the following (equivalent?) syntax no problem:
export default foo;
export const bar = ..;
Both Babel and Esprima parse similar syntax without errors, and this works for code using Babel on both ends (import and export).
However, I'm not convinced the spec allows the former export { x as default }
form:
For each
IdentifierName
n
inReferencedBindings
ofExportClause
: It is a Syntax Error if StringValue of n is a ReservedWord or if the StringValue of n is one of: "implements", "interface", "let", "package", "private", "protected", "public", "static", or "yield".
ReservedWord
does include default
, though I think one could argue that ReferencedBindings
is referring specifically to the module-local identifier names that are being exported (i.e. foo
) and not the exported name itself.
It also generally seems like a weird thing to be able to export reserved words; Babel will happily also allow something like
// ./foo.js
export { foo as yield }
// ./mod.js
import { yield as nonReservedIdentifier } from './foo'
So, in summary: is export { foo as default }
a valid way to export a default in ES2015?