From 0bf875edb46786d45cbd35331bfab6ae2ca82689 Mon Sep 17 00:00:00 2001 From: Benny Neugebauer Date: Thu, 21 Nov 2024 14:41:57 +0100 Subject: [PATCH] refactor: Reuse values --- src/converter/replacer/replaceModuleExports.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/converter/replacer/replaceModuleExports.ts b/src/converter/replacer/replaceModuleExports.ts index 66ea201..13b3bbc 100644 --- a/src/converter/replacer/replaceModuleExports.ts +++ b/src/converter/replacer/replaceModuleExports.ts @@ -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 = ;` - 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. = ;` - const exportName = left.split('.')[2]; + const exportName = leftText.split('.')[2]; if (exportName) { namedExports.push(exportName); statement.remove();