Repository: parcel-bundler/parcel
File: packages/transformers/js/src/JSTransformer.js (JavaScript)

Code before:
          }
          dep.symbols.set(imported, local, convertLoc(loc));
        }
      }
      for (let {source, local, imported, loc} of hoist_result.re_exports) {
        for (let dep of nullthrows(deps.get(source))) {
          if (dep.specifierType !== 'esm') {
            continue;
          }
          if (local === '*' && imported === '*') {
            dep.symbols.set('*', '*', convertLoc(loc), true);
          } else {
            let reExportName =
              dep.symbols.get(imported)?.local ??
              `$${asset.id}$re_export$${local}`;
            asset.symbols.set(local, reExportName);
            dep.symbols.set(imported, reExportName, convertLoc(loc), true);
          }
        }
      }

      for (let specifier of hoist_result.wrapped_requires) {
        for (let dep of nullthrows(deps.get(specifier))) {
          dep.meta.shouldWrap = true;
        }
      }

      for (let name in hoist_result.dynamic_imports) {
        for (let dep of nullthrows(
          deps.get(hoist_result.dynamic_imports[name]),
        )) {
          dep.meta.promiseSymbol = name;
        }
      }

      if (hoist_result.self_references.length > 0) {
        let symbols = new Map();
        for (let name of hoist_result.self_references) {
          // Do not create a self-reference for the `default` symbol unless we have seen an __esModule flag.
          if (
            name === 'default' &&
            !asset.symbols.hasExportSymbol('__esModule')
          ) {
            continue;
          }

          let local = nullthrows(asset.symbols.get(name)).local;
          symbols.set(name, {
            local,
            isWeak: false,
            loc: null,

Review comment (suggestion):
`dep.meta.shouldWrap` will get set for every dependency with that specifier. But it should have been for the require dep only.

Code after:

      for (let {
        source,
        local,
        imported,
        loc,
        kind,
      } of hoist_result.imported_symbols) {
        let specifierType = '';
        if (kind === 'Import' || kind === 'Export') {
          specifierType = 'esm';
        }
        let dep = deps.get(source + specifierType);
        if (!dep) continue;
        dep.symbols.set(imported, local, convertLoc(loc));
      }

      for (let {source, local, imported, loc} of hoist_result.re_exports) {
        let dep = deps.get(source + 'esm');
        if (!dep) continue;
        if (local === '*' && imported === '*') {
          dep.symbols.set('*', '*', convertLoc(loc), true);
        } else {
          let reExportName =
            dep.symbols.get(imported)?.local ??
            `$${asset.id}$re_export$${local}`;
          asset.symbols.set(local, reExportName);
          dep.symbols.set(imported, reExportName, convertLoc(loc), true);
        }
      }

      for (let specifier of hoist_result.wrapped_requires) {
        let dep = deps.get(specifier);
        if (!dep) continue;
        dep.meta.shouldWrap = true;
      }

      for (let name in hoist_result.dynamic_imports) {
        let dep = deps.get(hoist_result.dynamic_imports[name]);
        if (!dep) continue;
        dep.meta.promiseSymbol = name;
      }

      if (hoist_result.self_references.length > 0) {
        let symbols = new Map();
        for (let name of hoist_result.self_references) {
          // Do not create a self-reference for the `default` symbol unless we have seen an __esModule flag.
          if (
            name === 'default' &&
            !asset.symbols.hasExportSymbol('__esModule')
          ) {