Repository: parcel-bundler/parcel
File: packages/shared/scope-hoisting/src/formats/commonjs.js (JavaScript)

Code before:
              IDENTIFIER: t.identifier(exportsId),
            }),
          );
        }
      }
    } else {
      for (let {exportSymbol, symbol} of bundleGraph.getExportedSymbols(
        entry,
      )) {
        if (symbol) {
          symbol = replacements.get(symbol) || symbol;
        }

        // If there is an existing binding with the exported name (e.g. an import),
        // rename it so we can use the name for the export instead.
        if (path.scope.hasBinding(exportSymbol) && exportSymbol !== symbol) {
          rename(
            path.scope,
            exportSymbol,
            path.scope.generateUid(exportSymbol),
          );
        }

        let binding = path.scope.getBinding(symbol);
        let id =
          exportSymbol === 'default'
            ? path.scope.generateUid(exportSymbol)
            : exportSymbol;
        rename(path.scope, symbol, id);

        binding.path.getStatementParent().insertAfter(
          EXPORT_TEMPLATE({
            NAME: t.identifier(exportSymbol),
            IDENTIFIER: t.identifier(id),
          }),
        );

        // Exports other than the default export are live bindings. Insert an assignment
        // after each constant violation so this remains true.
        if (exportSymbol !== 'default') {
          for (let path of binding.constantViolations) {
            path.insertAfter(
              EXPORT_TEMPLATE({
                NAME: t.identifier(exportSymbol),
                IDENTIFIER: t.identifier(id),
              }),
            );
          }
        }
      }
    }

Review comment (suggestion):
```suggestion
          !t.isValidIdentifier(exportSymbol)
```

Code after:
              IDENTIFIER: t.identifier(exportsId),
            }),
          );
        }
      }
    } else {
      for (let {exportSymbol, symbol} of bundleGraph.getExportedSymbols(
        entry,
      )) {
        if (symbol) {
          symbol = replacements.get(symbol) || symbol;
        }

        // If there is an existing binding with the exported name (e.g. an import),
        // rename it so we can use the name for the export instead.
        if (path.scope.hasBinding(exportSymbol) && exportSymbol !== symbol) {
          rename(
            path.scope,
            exportSymbol,
            path.scope.generateUid(exportSymbol),
          );
        }

        let binding = path.scope.getBinding(symbol);
        let id = !t.isValidIdentifier(exportSymbol)
          ? path.scope.generateUid(exportSymbol)
          : exportSymbol;
        rename(path.scope, symbol, id);

        binding.path.getStatementParent().insertAfter(
          EXPORT_TEMPLATE({
            NAME: t.identifier(exportSymbol),
            IDENTIFIER: t.identifier(id),
          }),
        );

        // Exports other than the default export are live bindings. Insert an assignment
        // after each constant violation so this remains true.
        if (exportSymbol !== 'default') {
          for (let path of binding.constantViolations) {
            path.insertAfter(
              EXPORT_TEMPLATE({
                NAME: t.identifier(exportSymbol),
                IDENTIFIER: t.identifier(id),
              }),
            );
          }
        }
      }
    }
  }