Skip to content

fix(webpack): keep a newline before downleveled native classes - #11683

Merged
NathanWalker merged 2 commits into
NativeScript:mainfrom
mrichtsfeld:fix/native-class-downlevel-newline
Nov 25, 2026
Merged

NathanWalker merged 2 commits into
NativeScript:mainfrom
mrichtsfeld:fix/native-class-downlevel-newline

Conversation

@mrichtsfeld

Copy link
Copy Markdown
Contributor

ts.transpileModule drops the snippet's leading newline, so a statement without a semicolon before a native class ran into the downleveled code.

Closes #11681

PR Checklist

What is the current behavior?

native-class-downlevel-loader splices each downleveled /*__NativeClass__*/ class back at the class's full start, but ts.transpileModule drops the snippet's leading newline. When the statement before the class has no semicolon, the downleveled code runs into it:

const a = 1
/*__NativeClass__*/
class Foo extends NSObject {}

becomes

const a = 1var Foo = /** @class */ (function (_super) {

and the module no longer parses.

What is the new behavior?

The downleveled code starts with a newline, so the preceding statement stays separate. The newline is counted in leadingLines, so the source-map offsets from #11647 stay correct; the existing native-class-sourcemap spec fails if that count is missing.

#11588 (TypeScript 6) strips a "use strict" prologue from the same output. The newline is still missing after that strip, so both changes are needed.

A new spec in native-class-loaders.spec.ts covers the case; it fails without the fix.

Closes #11681.

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

✅ All contributors on this pull request have satisfied the NativeScript CLA.

ts.transpileModule drops the snippet's leading newline, so a statement
without a semicolon before a native class ran into the downleveled code.

Closes NativeScript#11681
@mrichtsfeld
mrichtsfeld force-pushed the fix/native-class-downlevel-newline branch from f107128 to a5b21ed Compare November 25, 2026 22:21
@mrichtsfeld

Copy link
Copy Markdown
Contributor Author

I have read the CLA and I hereby sign the CLA

@github-actions

Copy link
Copy Markdown
Contributor

Thanks @mrichtsfeld — your signature on this PR satisfies the CLA check, and you'll be recorded on the cla-signatures branch after this PR merges. The CLA check will re-run.

@NathanWalker NathanWalker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the fix and the regression test! Verified locally: the loader specs pass, the new spec fails without the newline, and the sourcemap spec fails without the leadingLines bump, so both halves are covered. Also checked class-at-file-start, export class, back-to-back classes, CRLF, and the full @NativeClass() strip-loader flow — all parse and map correctly. I pushed a one-line comment update noting the separator newline in leadingLines.

@NathanWalker
NathanWalker merged commit d64da45 into NativeScript:main Nov 25, 2026
5 checks passed
@mrichtsfeld

Copy link
Copy Markdown
Contributor Author

Thanks for approving and merging it so quickly. My pleasure to fix it.

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.

webpack: native-class-downlevel-loader joins a native class to the preceding statement

2 participants