Skip to content

fix(webpack): downlevel NativeClass classes in files updated by earlier transformers - #11314

Merged
NathanWalker merged 1 commit into
mainfrom
fix/webpack-native-class-synthesized-source-file
Jul 23, 2026
Merged

NathanWalker merged 1 commit into
mainfrom
fix/webpack-native-class-synthesized-source-file

Conversation

@edusperoni

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

In Angular projects, any file that contains both an Angular-decorated class (@Injectable, @Directive, @Component, ...) and a @NativeClass class is silently skipped by the NativeClass transformer. The @NativeClass decorator survives into the emitted bundle as __decorate([NativeClass()], ...) and the app crashes at runtime with:

ReferenceError: NativeClass is not defined

Root cause: in the Angular webpack flavor the NativeClass transformer runs after Angular's Ivy transform. On files containing Angular-decorated classes, Ivy rebuilds the file via factory.updateSourceFile(), so the resulting SourceFile node itself carries ts.NodeFlags.Synthesized. The transformer's visitNode bails out on any Synthesized node before reaching its isSourceFile branch, so the whole file is returned untouched. Files without Angular decorators pass through Ivy unchanged (original SourceFile, no flag), which is why only this mixed-content case breaks.

What is the new behavior?

visitNode handles the SourceFile before the Synthesized bail-out, so files rebuilt by earlier transformers are still processed. The per-statement Synthesized check in transformStatements continues to protect statements generated by earlier transformers (e.g. Ivy's added imports and rewritten Angular classes) as well as the transformer's own helper output.

Includes a regression test that runs the transformer after a preceding transformer which rebuilds the source file (simulating Ivy) — it fails without the fix and passes with it.

…er transformers

The NativeClass transformer's visitNode bailed out on any node flagged
NodeFlags.Synthesized before checking for the SourceFile itself. A source
file rebuilt by a preceding transformer (e.g. Angular's Ivy transform on
files containing Angular-decorated classes) is itself flagged Synthesized,
so the transformer skipped the entire file and @nativeclass decorators
survived into the emitted bundle, crashing at runtime with
'ReferenceError: NativeClass is not defined'.

Handle the SourceFile before the Synthesized bail-out; the per-statement
Synthesized check in transformStatements still protects statements
generated by earlier transformers and the transformer's own helper output.
@nx-cloud

nx-cloud Bot commented Jul 23, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 95849d6

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 3m 37s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-07-23 17:58:40 UTC

@NathanWalker
NathanWalker merged commit dd32f22 into main Jul 23, 2026
7 of 8 checks passed
@NathanWalker
NathanWalker deleted the fix/webpack-native-class-synthesized-source-file branch July 23, 2026 17:54
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.

2 participants