Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid unreachable code after return warning #357

Merged
merged 1 commit into from
Jan 12, 2022
Merged

Avoid unreachable code after return warning #357

merged 1 commit into from
Jan 12, 2022

Conversation

sandstrom
Copy link
Contributor

@sandstrom sandstrom commented Jan 11, 2022

This code seems to be optimized by babel, uglify or similar into something like this:

define("@ember/test-waiters/build-waiter", [ "exports", "@ember/debug", "@ember/test-waiters/token", "@ember/test-waiters/waiter-manager" ], (function(e, t, r, n) {
  "use strict";
  Object.defineProperty(e, "__esModule", {
    value: !0
  });
  e._resetWaiterNames = function() {
    a = new Set;
  };
  e.default = function(e) {
    0;
    return new l(e); // <---- SEE HERE!!! [added comment]
    return new s(e);
  };
  function i(e, t, r) {
    t in e ? Object.defineProperty(e, t, {
      value: r,
      enumerable: !0,
      configurable: !0,
      writable: !0
    }) : e[t] = r;
    return e;
  }
  let a;
  function o() {
    return new r.default;
  }
  class s {
    constructor(e, t) {
      i(this, "isRegistered", !1);
      i(this, "items", new Map);
      i(this, "completedOperationsForTokens", new WeakMap);
      i(this, "completedOperationsForPrimitives", new Map);
      this.name = e;
      this.nextToken = t || o;
    }
    beginAsync(e = this.nextToken(), t) {
      this._register();
      if (this.items.has(e)) throw new Error(`beginAsync called for ${e} but it is already pending.`);
      let r = new Error;
      this.items.set(e, {
        get stack() {
          return r.stack;
        },
        label: t
      });
      return e;
    }
    endAsync(e) {
      if (!this.items.has(e) && !this._getCompletedOperations(e).has(e)) throw new Error("endAsync called with no preceding beginAsync call.");
      this.items.delete(e);
      this._getCompletedOperations(e).set(e, !0);
    }
    waitUntil() {
      return 0 === this.items.size;
    }
    debugInfo() {
      let e = [];
      this.items.forEach((t => {
        e.push(t);
      }));
      return e;
    }
    reset() {
      this.items.clear();
    }
    _register() {
      if (!this.isRegistered) {
        (0, n.register)(this);
        this.isRegistered = !0;
      }
    }
    _getCompletedOperations(e) {
      let t = typeof e;
      return !("function" === t) && !(null !== e && "object" === t) ? this.completedOperationsForPrimitives : this.completedOperationsForTokens;
    }
  }
  class l {
    constructor(e) {
      this.name = e;
    }
    beginAsync() {
      return this;
    }
    endAsync() {}
    waitUntil() {
      return !0;
    }
    debugInfo() {
      return [];
    }
    reset() {}
  }
}));

The following lines generates an "Avoid unreachable code after return" warning in Chrome Developer Tools:

    return new l(e);
    return new s(e);

image

Obviously harmless, but it creates noise.

Hopefully this adjustment will resolve it.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Copy link
Collaborator

@scalvert scalvert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! Agree that this is an annoying byproduct of transpilation.

@scalvert
Copy link
Collaborator

Looks like that helped. Thanks!

Screen Shot 2022-01-11 at 5 29 08 PM

@scalvert scalvert merged commit 4013fdb into emberjs:master Jan 12, 2022
@scalvert scalvert added the bug Something isn't working label Jan 12, 2022
@sandstrom sandstrom deleted the patch-1 branch January 12, 2022 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants