packages/dce/src/used-exports.js
function onInstanceThenFn(fn, acc) {
  if (t.isArrowFunctionExpression(fn) === false) {
    throw new Error("Unsupported function type: " + fn.type);
  }

  let [localIdent] = fn.params;

  /**
   * `then(({exports}) => ...)`
   *
   * We need to resolve the identifier (binding) from the ObjectPattern.
   *
   * TODO(sven): handle renaming the binding here
   */
  if (t.isObjectPattern(localIdent) === true) {
    // ModuleInstance has the exports prop by spec
    localIdent = t.identifier("exports");
  }

  traverse(fn.body, {
    noScope: true,

    MemberExpression(path) {
      const { object, property } = path.node;

      /**
       * Search for `localIdent.exports`
       */
      if (
        identEq(object, localIdent) === true &&
        t.isIdentifier(property, { name: "exports" })
      ) {
        /**
         * We are looking for the right branch of the parent MemberExpression:
         * `(localIdent.exports).x`
         *                       ^
         */
        const { property } = path.parentPath.node;

        // Found an usage of an export
        acc.push(property.name);

        path.stop();
      } else if (identEq(object, localIdent) === true) {
        /**
         * `exports` might be a local binding (from destructuring)
         */
        // Found an usage of an export
        acc.push(property.name);

        path.stop();
      }
    }
  });
}
function onInstanceThenFn(fn, acc) {
  if (t.isArrowFunctionExpression(fn) === false) {
    throw new Error("Unsupported function type: " + fn.type);
  }

  let [localIdent] = fn.params;

  /**
   * `then(({exports}) => ...)`
   *
   * We need to resolve the identifier (binding) from the ObjectPattern.
   *
   * TODO(sven): handle renaming the binding here
   */
  if (t.isObjectPattern(localIdent) === true) {
    // ModuleInstance has the exports prop by spec
    localIdent = t.identifier("exports");
  }

  traverse(fn.body, {
    noScope: true,

    MemberExpression(path) {
      const { object, property } = path.node;

      /**
       * Search for `localIdent.exports`
       */
      if (
        identEq(object, localIdent) === true &&
        t.isIdentifier(property, { name: "exports" })
      ) {
        /**
         * We are looking for the right branch of the parent MemberExpression:
         * `(localIdent.exports).x`
         *                       ^
         */
        const { property } = path.parentPath.node;

        // Found an usage of an export
        acc.push(property.name);

        path.stop();
      } else if (identEq(object, localIdent) === true) {
        /**
         * `exports` might be a local binding (from destructuring)
         */
        // Found an usage of an export
        acc.push(property.name);

        path.stop();
      }
    }
  });
}
function onInstanceThenFn ( fn , acc ) { if ( t . isArrowFunctionExpression ( fn ) === false ) { throw new Error ( "Unsupported function type: " + fn . type ) ; } let [ localIdent ] = fn . params ; /**
   * `then(({exports}) => ...)`
   *
   * We need to resolve the identifier (binding) from the ObjectPattern.
   *
   * TODO(sven): handle renaming the binding here
   */ if ( t . isObjectPattern ( localIdent ) === true ) { // ModuleInstance has the exports prop by spec localIdent = t . identifier ( "exports" ) ; } traverse ( fn . body , { noScope : true , MemberExpression ( path ) { const { object , property } = path . node ; /**
       * Search for `localIdent.exports`
       */ if ( identEq ( object , localIdent ) === true && t . isIdentifier ( property , { name : "exports" } ) ) { /**
         * We are looking for the right branch of the parent MemberExpression:
         * `(localIdent.exports).x`
         *                       ^
         */ const { property } = path . parentPath . node ; // Found an usage of an export acc . push ( property . name ) ; path . stop ( ) ; } else if ( identEq ( object , localIdent ) === true ) { /**
         * `exports` might be a local binding (from destructuring)
         */ // Found an usage of an export acc . push ( property . name ) ; path . stop ( ) ; } } } ) ; }
We found the function handling the module instance

`makeX().then(...)`
We found the function handling the module instance