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

Code before:
    let name: ?string;
    if (
      (isClassDeclaration(declaration) || isFunctionDeclaration(declaration)) &&
      declaration.id
    ) {
      name = declaration.id.name;
    } else if (isIdentifier(declaration)) {
      name = declaration.name;
    }

    if (name && hasExport(asset, name)) {
      identifier = t.identifier(name);
    }

    // Add assignment to exports object for namespace imports and commonjs.
    path.insertAfter(
      EXPORT_TEMPLATE({
        EXPORTS: getExportsIdentifier(asset, path.scope),
        NAME: t.stringLiteral('default'),
        LOCAL: t.clone(identifier),
      }),
    );

    if (
      isIdentifier(declaration) &&
      path.scope.hasBinding(declaration.name, true)
    ) {
      // Rename the variable being exported.
      safeRename(path, asset, declaration.name, identifier.name);
      path.remove();
    } else if (isExpression(declaration) || !declaration.id) {
      // $FlowFixMe[incompatible-call]
      let declarationExpr = t.toExpression(declaration);
      // Declare a variable to hold the exported value.
      path.replaceWith(
        t.variableDeclaration('var', [
          t.variableDeclarator(identifier, declarationExpr),
        ]),
      );

      path.scope.registerDeclaration(path);
    } else {
      invariant(isIdentifier(declaration.id));
      // Rename the declaration to the exported name.
      safeRename(path, asset, declaration.id.name, identifier.name);
      path.replaceWith(declaration);
    }

    if (!asset.symbols.hasExportSymbol('default')) {
      let binding = path.scope.getBinding(identifier.name);
      asset.symbols.set('default', identifier.name, convertBabelLoc(loc), {

Review comment (suggestion):
nit:

```suggestion
      path.scope.hasBinding(declaration.name, /* noGlobals */ true)
```

Code after:
    let name: ?string;
    if (
      (isClassDeclaration(declaration) || isFunctionDeclaration(declaration)) &&
      declaration.id
    ) {
      name = declaration.id.name;
    } else if (isIdentifier(declaration)) {
      name = declaration.name;
    }

    if (name && hasExport(asset, name)) {
      identifier = t.identifier(name);
    }

    // Add assignment to exports object for namespace imports and commonjs.
    path.insertAfter(
      EXPORT_TEMPLATE({
        EXPORTS: getExportsIdentifier(asset, path.scope),
        NAME: t.stringLiteral('default'),
        LOCAL: t.clone(identifier),
      }),
    );

    if (
      isIdentifier(declaration) &&
      path.scope.hasBinding(declaration.name, /* noGlobals */ true)
    ) {
      // Rename the variable being exported.
      safeRename(path, asset, declaration.name, identifier.name);
      path.remove();
    } else if (isExpression(declaration) || !declaration.id) {
      // $FlowFixMe[incompatible-call]
      let declarationExpr = t.toExpression(declaration);
      // Declare a variable to hold the exported value.
      path.replaceWith(
        t.variableDeclaration('var', [
          t.variableDeclarator(identifier, declarationExpr),
        ]),
      );

      path.scope.registerDeclaration(path);
    } else {
      invariant(isIdentifier(declaration.id));
      // Rename the declaration to the exported name.
      safeRename(path, asset, declaration.id.name, identifier.name);
      path.replaceWith(declaration);
    }

    if (!asset.symbols.hasExportSymbol('default')) {
      let binding = path.scope.getBinding(identifier.name);
      asset.symbols.set('default', identifier.name, convertBabelLoc(loc), {