Repository: parcel-bundler/parcel
File: packages/core/integration-tests/test/scope-hoisting.js (JavaScript)

Code before:
          mode: 'production',
          defaultTargetOptions: {
            sourceMaps: false,
          },
        },
      );

      let constants = ['BLOGGER', 'PREMIUM', 'MONTHS_IN_YEAR'];

      for (let bundle of b.getBundles()) {
        let contents = await outputFS.readFile(bundle.filePath, 'utf8');

        // Check constant export names are NOT present in the bundles
        assert(
          constants.every(constant => !contents.includes(constant)),
          `Bundle didn't inline constant values`,
        );
      }

      // Run the bundle to make sure it's valid
      await run(b);
    });
  });

  describe('commonjs', function () {
    it('should wrap when this could refer to an export', async function () {
      let b = await bundle(
        path.join(__dirname, '/integration/exports-this/a.js'),
        {
          mode: 'production',
          defaultTargetOptions: {
            shouldScopeHoist: true,
            shouldOptimize: false,
          },
        },
      );

      let contents = await outputFS.readFile(
        b.getBundles().find(b => /a\.js/.test(b.filePath)).filePath,
        'utf8',
      );

      let wrapped = contents.includes('exports.bar()');
      assert.equal(wrapped, true);
    });

    it('supports require of commonjs modules', async function () {
      let b = await bundle(
        path.join(
          __dirname,
          '/integration/scope-hoisting/commonjs/require/a.js',

Review comment (suggestion):
Please also move the test case to `/integration/scope-hoisting/commonjs/...`

And it looks like there is already a similar case `exports-self-reference`, so maybe call this one similarly. Though this isn't really a good system to make it easier for humans to find test cases again...

Code after:
          mode: 'production',
          defaultTargetOptions: {
            sourceMaps: false,
          },
        },
      );

      let constants = ['BLOGGER', 'PREMIUM', 'MONTHS_IN_YEAR'];

      for (let bundle of b.getBundles()) {
        let contents = await outputFS.readFile(bundle.filePath, 'utf8');

        // Check constant export names are NOT present in the bundles
        assert(
          constants.every(constant => !contents.includes(constant)),
          `Bundle didn't inline constant values`,
        );
      }

      // Run the bundle to make sure it's valid
      await run(b);
    });
  });

  describe('commonjs', function () {
    it('should wrap when this could refer to an export', async function () {
      let b = await bundle(
        path.join(
          __dirname,
          '/integration/scope-hoisting/commonjs/exports-this/a.js',
        ),
      );

      let contents = await outputFS.readFile(
        b.getBundles()[0].filePath,
        'utf8',
      );

      let wrapped = contents.includes('exports.bar()');
      assert.equal(wrapped, true);
    });

    it('supports require of commonjs modules', async function () {
      let b = await bundle(
        path.join(
          __dirname,
          '/integration/scope-hoisting/commonjs/require/a.js',
        ),
      );

      let output = await run(b);