Skip to content

fix(plugin): handle decorators with property access expressions in getIdentifierFromName - #4042

Open
jorenl wants to merge 1 commit into
nestjs:masterfrom
jorenl:bugfix/plugin-get-identifier-from-name-property-access
Open

fix(plugin): handle decorators with property access expressions in getIdentifierFromName#4042
jorenl wants to merge 1 commit into
nestjs:masterfrom
jorenl:bugfix/plugin-get-identifier-from-name-property-access

Conversation

@jorenl

@jorenl jorenl commented Aug 5, 2026

Copy link
Copy Markdown

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • 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?

When the plugin inspects decorators that use a property access expression, such as with a namespace import in the below example, the getIdentifierFromName() utility function throws and the decorator is not handled.

import * as class_validator from "class-validator"

class TestDto {
  @class_validator.IsIn(["red", "green", "blue"])
  color: string;
}

Issue Number: N/A

What is the new behavior?

The decorator name identifier is returned, IsIn in the above example, and the decorator is handled.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Since getNameFromExpression right below has explicit support for property access expressions, I believe this is was a simple typo. (checking expression instead of identifier return by getNameFromExpression, which is then returned).

I ran into this issue while developing a different NestJS CLI plugin, which I want to run before the @nestjs/swagger one, which is generating class-validator and class-transformer decorators based on typescript types. Without using namespace imports, typescript strips the necessary import declarations when emitting, which I believe is why this plugin uses the same technique in abstract.visitor.ts.

This is my first PR in this repo, so if I'm not following correct patterns, let me know and I'll happily adjust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant