Skip to content

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

Done

Description

@mrichtsfeld

Issue Description

native-class-downlevel-loader (@nativescript/webpack) splices each downleveled
/*__NativeClass__*/ class back into the file at the class's full start.
ts.transpileModule drops the snippet's leading newline, so 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. This is a build-time error: the bundle fails
to parse.

Expected behavior: the downleveled class starts on its own line, so the code
before it is unaffected.

Still present on main and in 5.0.42. I have a fix with a regression test and
will open a PR.

Reproduction

Call the loader directly, as __tests__/loaders/native-class-loaders.spec.ts
does, with this source:

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

The output contains const a = 1var Foo = …. Parsing it fails with
"An identifier or keyword cannot immediately follow a numeric literal."

In an app: any .ts file with a statement without a trailing semicolon
directly before a @NativeClass() class.

Relevant log output (if applicable)

SyntaxError: Invalid or unexpected token

Environment

No response

Please accept these terms

Activity

  1. added
    bug-pending-triage
    on Nov 25, 2026
  2. added a commit that references this issue on Nov 25, 2026
    a5b21ed
  3. added a commit that references this issue on Nov 26, 2026
    d64da45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug-pending-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions