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

Code before:
      for (let dep of asset.getDependencies()) {
        if (!deps.has(dep.meta.placeholder ?? dep.specifier)) {
          deps.set(dep.meta.placeholder ?? dep.specifier, []);
        }
        deps.get(dep.meta.placeholder ?? dep.specifier)?.push(dep);
      }
      for (let depArr of deps.values()) {
        for (let dep of depArr) {
          dep.symbols.ensure();
        }
      }

      for (let {
        source,
        local,
        imported,
        loc,
        kind,
      } of hoist_result.imported_symbols) {
        for (let dep of nullthrows(deps.get(source))) {
          if (
            !dep ||
            ((dep.meta.kind === 'Require' ||
              dep.meta.kind === 'Import' ||
              dep.meta.kind === 'DynamicImport') &&
              dep.meta.kind !== kind)
          ) {
            continue;
          }
          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) 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))) {
          if (!dep) continue;

Review comment (suggestion):
`dep.meta.kind` is a `DependencyKind` rather than a `ImportKind` so I wasn't really sure what to do here..

Code after:
          meta,
          resolveFrom: isHelper ? __filename : undefined,
          range,
          env,
        });
      }
    }

    asset.meta.id = asset.id;
    if (hoist_result) {
      asset.symbols.ensure();
      for (let {exported, local, loc} of hoist_result.exported_symbols) {
        asset.symbols.set(exported, local, convertLoc(loc));
      }

      // deps is a map of dependencies that are keyed by placeholder or specifier
      // If a placeholder is present, that is used first since placeholders are
      // hashed with DependencyKind's.
      // If not, the specifier is used along with its specifierType appended to
      // it to separate dependencies with the same specifier.
      let deps = new Map(
        asset
          .getDependencies()
          .map(dep => [
            dep.meta.placeholder ??
              dep.specifier +
                (dep.specifierType === 'esm' ? dep.specifierType : ''),
            dep,
          ]),
      );
      for (let dep of deps.values()) {
        dep.symbols.ensure();
      }

      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) {