Skip to content

V8 Natives Syntax #339

Open
Open

Description

@PandaWorker

I need to use native syntax for debugging, but amaro (swc) thinks it's invalid syntax.

//@ts-expect-error
%DebugPrint(null);
//@ts-expect-error
%DebugPrint(null);
^

SyntaxError [ERR_INVALID_TYPESCRIPT_SYNTAX]: Expression expected

Activity

  1. acutmore commented on Dec 3, 2025

    @acutmore

    Maybe you could use eval("%DebugPrint(null)")?

  2. marco-ippolito commented on Dec 5, 2025

    @marco-ippolito
    Member

    I dont know if swc supports this syntax @kdy1

  3. kdy1 commented on Dec 5, 2025

    @kdy1
    Member

    No. It does not support such syntax atm. Does SWC should?

  4. marco-ippolito commented on Dec 5, 2025

    @marco-ippolito
    Member

    No. It does not support such syntax atm. Does SWC should?

    Maybe behind a flag? So it does not throw when encountering this syntax.
    So when user pass --allow-native-syntax we enable it

  5. acutmore commented on Dec 5, 2025

    @acutmore

    This syntax is specific to v8. It is neither valid TypeScript or JavaScript.

    It is not parsed by tsc either: https://www.typescriptlang.org/play/?#code/PTAEAEBcGcFoFMAeAHeBjSCBOWD2WAoAUgBF4AjAVwHMAFLASwDtIAKJygG04EoBuAkA(the %DebugPrint() becomes % DebugPrint()). It's just that tsc will still attempt to output JS even if there is a syntax error. In this particular case it turns out that v8 is OK will the re-printing of the input.

    In other invalid syntax cases TypeScript will insert a ; as the parser recovers:

    https://www.typescriptlang.org/play/?#code/PTAEAEBcGcFoFMAeAHeBjSCBOWD2WAoAO10lABJQA3AQwBsBLAEwG4g (not $ valid becomes not; $; valid;).

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions