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

crash when compiling empty or type-only file with sourcemaps #7822

Closed
jbedard opened this issue Aug 16, 2023 · 3 comments · Fixed by #8544
Closed

crash when compiling empty or type-only file with sourcemaps #7822

jbedard opened this issue Aug 16, 2023 · 3 comments · Fixed by #8544
Assignees
Labels
Milestone

Comments

@jbedard
Copy link

jbedard commented Aug 16, 2023

Describe the bug

A panic occurs when generating source-maps for an empty or types-only file. Seems to only happen with the binary and not the npm cli.

See the line it crashes on. Note the version of sourcemap is not the latest.

Type-only fails with commonjs modules and sourcemaps enabled:
swcrc.json:

{
  "module": {
    "type": "commonjs"
  },
  "jsc": {
    "parser": {
      "syntax": "typescript"
    }
  }
}
> echo "export type Foo = number" > b.ts
> swc-darwin-x64 compile --source-file-name b.ts --config-file swcrc.json --source-maps true --out-file b.js b.ts
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sourcemap-6.2.3/src/types.rs:655:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Empty fails without any swcrc:

> echo '' > d.ts
> ./swc-darwin-x64 compile --source-file-name d.ts --source-maps true --out-file d.js d.ts
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sourcemap-6.2.3/src/types.rs:655:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Input code

export type Foo = number

Config

{
  "module": {
    "type": "commonjs"
  },
  "jsc": {
    "parser": {
      "syntax": "typescript"
    }
  }
}

Playground link

No response

Expected behavior

Output an empty file + sourcemap

Actual behavior

No response

Version

SWC 0.91.63 (from v1.3.77)

Additional context

No response

@supercairos
Copy link

I have the same issue :(

@Zemnmez
Copy link

Zemnmez commented Nov 27, 2023

I have found a workaround to this issue: putting a single comment in the file fixes it, assumedly because it makes the JS file length nonzero.

@swc-bot
Copy link
Collaborator

swc-bot commented Feb 23, 2024

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Feb 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

5 participants