Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error when import(path) statement on type with generic argument. #9802

Open
samchon opened this issue Dec 18, 2024 · 0 comments · May be fixed by #9806
Open

Compilation error when import(path) statement on type with generic argument. #9802

samchon opened this issue Dec 18, 2024 · 0 comments · May be fixed by #9806
Assignees
Labels
Milestone

Comments

@samchon
Copy link

samchon commented Dec 18, 2024

Describe the bug

When declare a type with import(path).target statement with generic argument, SWC throws a compilation error like below.

npx swc src/index.ts
  x Expected '=>', got ':'
    ,-[src/index.ts:3[9](https://github.com/samchon/typia-issue-1429-by-swc-bug/actions/runs/12394600488/job/34598422473#step:5:10):1]
 36 |   };
 37 |   return (
 38 |     input: string
 39 |   ): import("typia").IValidation<import("typia").Primitive<number>> =>
    :    ^
 40 |     __validate(JSON.parse(input)) as any;
 41 | })();
    `----

You can reproduce the bug by below commands, or preview by its workflow result.

git clone https://github.com/samchon/typia-issue-1429-by-swc-bug
cd typia-issue-1429-by-swc-bug
npm install
npm start

Input code

Here is the code occuring the compilation bug of SWC.

The last return statement (its return type) is occuring the bug.

https://github.com/samchon/typia-issue-1429-by-swc-bug/blob/master/src/index.ts

import * as __typia_transform__validateReport from "typia/lib/internal/_validateReport.js";
import typia from "typia";
export const parse = (() => {
  const __is = (input: any): input is number => "number" === typeof input;
  let errors: any;
  let _report: any;
  const __validate = (input: any): import("typia").IValidation<number> => {
    if (false === __is(input)) {
      errors = [];
      _report = (__typia_transform__validateReport._validateReport as any)(
        errors
      );
      ((input: any, _path: string, _exceptionable: boolean = true) =>
        "number" === typeof input ||
        _report(true, {
          path: _path + "",
          expected: "number",
          value: input,
        }))(input, "$input", true);
      const success = 0 === errors.length;
      return success
        ? {
            success,
            data: input,
          }
        : ({
            success,
            errors,
            data: input,
          } as any);
    }
    return {
      success: true,
      data: input,
    } as any;
  };
  return (
    input: string
  ): import("typia").IValidation<import("typia").Primitive<number>> =>
    __validate(JSON.parse(input)) as any;
})();

Config

No special configuration, but only the `npx swc src/index.ts` command.

Playground link (or link to the minimal reproduction)

https://github.com/samchon/typia-issue-1429-by-swc-bug

SWC Info output

Operating System:
    Platform: win32
    Arch: x64
    Machine Type: x86_64
    Version: Windows 11 Home
    CPU: (16 cores)
        Models: AMD Ryzen 9 7940HS w/ Radeon 780M Graphics     

Binaries:
    Node: 20.10.0
    npm: N/A
    Yarn: N/A
    pnpm: N/A

Relevant Packages:
    @swc/core: 1.10.1
    @swc/helpers: N/A
    @swc/types: 0.1.17
    typescript: 5.7.2

SWC Config:
    output: N/A
    .swcrc path: N/A

Next.js info:
    output: N/A

Expected behavior

No compilation error

Actual behavior

Compilation error with below message

npx swc src/index.ts
  x Expected '=>', got ':'
    ,-[src/index.ts:3[9](https://github.com/samchon/typia-issue-1429-by-swc-bug/actions/runs/12394600488/job/34598422473#step:5:10):1]
 36 |   };
 37 |   return (
 38 |     input: string
 39 |   ): import("typia").IValidation<import("typia").Primitive<number>> =>
    :    ^
 40 |     __validate(JSON.parse(input)) as any;
 41 | })();
    `----

Version

1.10.1

Additional context

I'm developer of typia, and my library's key features are shut down by this bug.

Thank you for maintaining great ecosystem, and hope to be fixed ASAP.

@samchon samchon added the C-bug label Dec 18, 2024
@kdy1 kdy1 self-assigned this Dec 19, 2024
@kdy1 kdy1 added this to the Planned milestone Dec 19, 2024
devin-ai-integration bot added a commit that referenced this issue Dec 19, 2024
This fixes the 'Expected =>, got :' error when parsing function parameters
with import type annotations. The issue occurred because the parser was
trying to parse import types as function types. By checking for import
types first in parse_ts_non_conditional_type, we ensure they are parsed
correctly.

Fixes #9802

Co-Authored-By: 강동윤 <kdy.1997.dev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants