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

Use .toString() as functions' representation, fix #5140 #5189

Merged
merged 1 commit into from
Nov 2, 2020

Conversation

OpportunityLiu
Copy link
Contributor

Use .toString() as functions' representation.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: #5140

What is the new behavior?

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

Use .toString() as functions' representation.
@@ -47,7 +47,7 @@ export class ModuleTokenFactory {

private replacer(key: string, value: any) {
if (typeof value === 'function') {
Copy link
Member

Choose a reason for hiding this comment

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

We should check if the value is a class here and use value.name if so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To check if a value is a class, toString() is still needed to be called.

I think there is no need to do so since the returned value is proceeded by a hash function immediately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

What I'm trying to say is that it would be great if we could still return value.name for classes, not .toString().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean,... How?

@@ -47,7 +47,7 @@ export class ModuleTokenFactory {

private replacer(key: string, value: any) {
if (typeof value === 'function') {
return value.name;
return value.toString();
Copy link
Member

Choose a reason for hiding this comment

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

We can very likely limit the number of characters (slice) to slightly optimize this process. ~50 should be enough to distinguish arrow functions

@kamilmysliwiec kamilmysliwiec merged commit 2f1e470 into nestjs:master Nov 2, 2020
@kamilmysliwiec kamilmysliwiec added this to the 7.5.0 milestone Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants