Skip to content

Commit

Permalink
refactor: Reuse values
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode committed Nov 21, 2024
1 parent 5f3c3e6 commit 0bf875e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/converter/replacer/replaceModuleExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ export function replaceModuleExports(sourceFile: SourceFile) {
return;
}

const left = binaryExpression.getLeft().getText();
const left = binaryExpression.getLeft();
const leftText = left.getText();
const right = binaryExpression.getRight();
const {comment} = NodeUtil.extractComment(left);

// Handle `module.exports = <expression>;`
if (left === 'module.exports') {
const {comment} = NodeUtil.extractComment(binaryExpression.getLeft());
if (leftText === 'module.exports') {
defaultExport = right.getText();
sourceFile.addStatements(`${comment}export default ${defaultExport};`);
statement.remove();
} else if (left.startsWith('module.exports.')) {
} else if (leftText.startsWith('module.exports.')) {
// Handle `module.exports.<name> = <value>;`
const exportName = left.split('.')[2];
const exportName = leftText.split('.')[2];
if (exportName) {
namedExports.push(exportName);
statement.remove();
Expand Down

0 comments on commit 0bf875e

Please sign in to comment.