Skip to content

fix(webpack,vite): downlevel nested native classes and keep them on their own line - #11686

Merged
NathanWalker merged 3 commits into
mainfrom
fix/native-class-nested-downlevel
Dec 2, 2026
Merged

NathanWalker merged 3 commits into
mainfrom
fix/native-class-nested-downlevel

Conversation

@NathanWalker

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

Nested native classes break the module (webpack and Vite). When a @NativeClass() class is declared inside another native class, e.g.

@NativeClass()
class Outer extends NSObject {
	make() {
		@NativeClass()
		class Inner extends NSObject {}
		return Inner;
	}
}

both bundlers downlevel the inner class first, then splice the outer class back in using its original end offset. That offset no longer matches the edited text, so fragments of the inner class are left behind (__extends(B);, a dangling }(NSObject));, …) and the module fails to parse.

Vite also has #11681's missing newline. ts.transpileModule drops the snippet's leading newline, so a statement without a semicolon before a native class runs into it: const a = 1var Foo = …. #11683 fixed this for webpack only.

What is the new behavior?

  • Both bundlers only collect the outermost marked class. Transpiling it to ES5 already downlevels every class inside it, including the inner native class, and the enumerable: true rewrite covers the whole output.
  • webpack: the special no-source-map path for nested classes is removed, so these files now get source maps like any other. All markers in a snippet are stripped, not just the first.
  • Vite: each downleveled class starts with a newline, matching the webpack fix in fix(webpack): keep a newline before downleveled native classes #11683.

New specs (all fail without the fix):

  • packages/webpack5/__tests__/loaders/native-class-loaders.spec.ts: nested native class
  • packages/vite/helpers/nativeclass-transformer.spec.ts: nested native class; statement without semicolon before a native class

Verification: webpack loader specs 23/23, full Vite suite 1967/1967, tsc --noEmit for both packages. The full webpack5 jest run has the same 16 failures in __tests__/configuration/*.spec.ts as main does; they are unrelated to this change.

The nested path spliced the inner class first and then the outer class
at its original end offset, which no longer matched the edited text,
leaving fragments of the inner class behind and an unparseable module.

Only the outermost marked classes are collected now: transpiling the
outer class to ES5 already downlevels every class inside it. All
markers in the snippet are stripped, and nested files get the same
source map path as everything else.
… line

Edits were computed against the original text and applied back to
front, so a native class nested in another left the outer edit with a
stale end offset and produced broken output. Only the outermost marked
class is edited now; its ES5 transpile covers the inner one.

transpileModule also drops the snippet's leading newline, so a
statement without a semicolon before a native class ran into the
downleveled code (same as #11681 for webpack). The edit now starts
with a newline.
@nx-cloud

nx-cloud Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 00d7f82

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

💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-11-28 01:24:55 UTC

@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11686
npm i https://pkg.pr.new/@nativescript/vite@11686
npm i https://pkg.pr.new/@nativescript/webpack@11686

commit: 00d7f82

@NathanWalker
NathanWalker merged commit b5da6e2 into main Dec 2, 2026
13 of 14 checks passed
@NathanWalker
NathanWalker deleted the fix/native-class-nested-downlevel branch December 2, 2026 22:18
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