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

Determine if a method is deprecated in code #22524

Closed
dougwilson opened this issue Aug 25, 2018 · 5 comments
Closed

Determine if a method is deprecated in code #22524

dougwilson opened this issue Aug 25, 2018 · 5 comments
Labels
deprecations Issues and PRs related to deprecations. question Issues that look for answers.

Comments

@dougwilson
Copy link
Member

dougwilson commented Aug 25, 2018

I'm looking for a method in which use-land Node.js code can determine if a method in Node.js has been marked deprecated or not prior to calling it. It looks like this is typically done with util.deprecate. It seems like from an issue discussion the method to do this is to use .propertyIsEnumerable. Is this the correct way to go about this type of detection?

If this is the agreeable way to detect the deprecated things in Node.js, I can volunteer to make a pull request to update the util.deprecate documentation and add a test to the test suite to validate things from util.deprecate work this way. I just wanted to make sure I'm understanding correctly and this is the right path for user-land detection prior to opening a PR 👍

Edit: I opened this as it's own issue so conversation wouldn't get lost in an unrelated PR.

@vsemozhetbyt vsemozhetbyt added question Issues that look for answers. deprecations Issues and PRs related to deprecations. labels Aug 25, 2018
@mscdex
Copy link
Contributor

mscdex commented Aug 25, 2018

Currently, for functions you could just check fn.name === 'deprecated' or something similar since deprecated methods are wrapped.

Similarly for non-function properties you could do something like:

var getter = Object.getOwnPropertyDescriptor(obj, 'property').get;
if (getter && getter.name === 'deprecated')
  // ...

Having a core API for determining all of this might be a good idea though.

@cjihrig
Copy link
Contributor

cjihrig commented Aug 25, 2018

Seems like another potential use case for #22302 (cc: @MylesBorins)

@dougwilson
Copy link
Member Author

Ah, thanks @mscdex! I will work on a PR to add that to the util.deprecate docs 👍

@devsnek devsnek closed this as completed Aug 26, 2018
@devsnek devsnek reopened this Aug 26, 2018
@devsnek
Copy link
Member

devsnek commented Aug 26, 2018

in some carnation of adding esm to the builtin modules I had a WeakSet of all the deprecated functions (incl. getters) which worked fairly well.

@dougwilson
Copy link
Member Author

I retract my offer to do this change. I'm going to stay away from Node.js core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecations Issues and PRs related to deprecations. question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

5 participants