Skip to content

Commit 75ddfca

Browse files
Default export name no longer required with parsing happening following rollup transformations (#66)
1 parent cc97f6c commit 75ddfca

File tree

1 file changed

+1
-33
lines changed

1 file changed

+1
-33
lines changed

src/transformers/exports.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
ClassDeclaration,
2424
} from 'estree';
2525
import { TransformSourceDescription, OutputChunk } from 'rollup';
26-
import { NamedDeclaration, DefaultDeclaration, defaultUnamedExportName } from './parsing-utilities';
26+
import { NamedDeclaration, DefaultDeclaration } from './parsing-utilities';
2727
import { isESMFormat } from '../options';
2828
import {
2929
ExportNameToClosureMapping,
@@ -84,36 +84,6 @@ export default class ExportTransform extends Transform implements TransformInter
8484
return void 0;
8585
}
8686

87-
/**
88-
* Rollup's naming scheme for default exports can sometimes clash with reserved
89-
* words.
90-
*
91-
* Rollup protects output by renaming the values with it's own algorithm, so we need to
92-
* ensure that when it changes the name of a default export this transform is aware of its
93-
* new name in the output.
94-
*
95-
* i.e. default class {} => window._class = class {} => default class {}.
96-
* @param chunk OutputChunk from Rollup for this code.
97-
* @param id Rollup id reference to the source
98-
*/
99-
private repairExportMapping(chunk: any, id: string): void {
100-
const defaultExportName = defaultUnamedExportName(id);
101-
if (
102-
chunk.exportNames &&
103-
chunk.exportNames.default &&
104-
chunk.exportNames.default.safeName &&
105-
defaultExportName !== chunk.exportNames.default.safeName &&
106-
this.originalExports[defaultExportName]
107-
) {
108-
// If there was a detected default export, we need to ensure Rollup
109-
// did not rename the export.
110-
this.originalExports[chunk.exportNames.default.safeName] = this.originalExports[
111-
defaultExportName
112-
];
113-
delete this.originalExports[defaultExportName];
114-
}
115-
}
116-
11787
/**
11888
* Before Closure Compiler modifies the source, we need to ensure it has window scoped
11989
* references to the named exports. This prevents Closure from mangling their names.
@@ -132,8 +102,6 @@ export default class ExportTransform extends Transform implements TransformInter
132102
'Rollup Plugin Closure Compiler, OutputOptions not known before Closure Compiler invocation.',
133103
);
134104
} else if (isESMFormat(this.outputOptions.format)) {
135-
this.repairExportMapping(chunk, id);
136-
137105
const source = new MagicString(code);
138106
// Window scoped references for each key are required to ensure Closure Compilre retains the code.
139107
Object.keys(this.originalExports).forEach(key => {

0 commit comments

Comments
 (0)