Skip to content

@nativescript/[email protected], NativeClass Transformer does not recognize classes defined inside functions  #11092

@yaosheng79

Description

@yaosheng79

Issue Description

I've identified a regression in the NativeClass transformer starting from version 5.0.25. In previous versions (v5.0.24 and earlier), the transformer appeared to use a broader search (likely fullText.indexOf('@NativeClass')), which successfully captured classes defined within function scopes.

In the latest versions, the transformer seems to only scan top-level class declarations. Classes nested inside functions (local classes/closure classes) are ignored by the transformer, causing TypeScript to emit standard __decorate helpers. Since the NativeScript runtime does not define __decorate and requires specific class rewriting for native injection, this leads to a runtime error.

Reproduction

unzip ts-test.zip

npm i
npx webpack

Expected Behavior:
The nested class should be transformed/rewritten into the compatible ES5-like structure regardless of its nesting level.

Actual Behavior:
The transformer skips the class, and __decorate is emitted in dist/bundle.js

Relevant log output (if applicable)

Environment

No response

Please accept these terms

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions