When transforming EMS code to CJS with platform: 'node', using the export as syntax with the as side being a string literal that is not also a valid identifier name results in invalid output.
For example, this is perfectly valid ESM:
const something = "stub";
export default something;
export { something as "foo.bar" };
But the output of transforming this ends with
0 && (module.exports = {
"foo.bar"
});
Which is not valid syntax.
According to the ECMAScript spec, the right side of an export as statement is allowed to be an arbitrary string literal (an ExportSpecifier can be of the form ModuleExportName or ModuleExportName as ModuleExportName, where ModuleExportName can be either an IdentifierName or a StringLiteral).
This pattern was observed in the wild in v1.0.0 of the async-function package, specifically in the require.mjs file.
Playground reproduction link: https://esbuild.github.io/try/#dAAwLjI1LjAAewogIGZvcm1hdDogJ2NqcycsCiAgcGxhdGZvcm06ICdub2RlJwp9AGNvbnN0IHNvbWV0aGluZyA9ICJzdHViIjsKZXhwb3J0IGRlZmF1bHQgc29tZXRoaW5nOwpleHBvcnQgeyBzb21ldGhpbmcgYXMgImZvby5iYXIiIH07