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

add typeonly example with crashing swcrc #208

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions examples/typeonly/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
load("@aspect_rules_swc//swc:defs.bzl", "swc")
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")
load("@aspect_bazel_lib//lib:testing.bzl", "assert_json_matches")

# Example test reproducing https://github.com/swc-project/swc/issues/7822

swc(
name = "compile",
srcs = [
"a.ts",
"b.ts",
"c.d.ts",
"e.ts",
],
out_dir = "out",
source_maps = True,
swcrc = "swcrc.json",
)

# Assert that the output of "compile" rule matches the expected file.
write_source_files(
name = "test",
files = {
"expected/a.js": ":out/a.js",
"expected/b.js": ":out/b.js",
},
)

[
assert_json_matches(
name = "test_%s" % f.replace("/", "-"),
file1 = ":out/%s.js.map" % f,
file2 = "expected/%s.js.map.golden" % f,
filter1 = ".sourceRoot,.sources",
filter2 = ".sourceRoot,.sources",
)
for f in [
"a",
"b",
]
]
13 changes: 13 additions & 0 deletions examples/typeonly/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Can also be reproduced using the swc-binary. Not (yet) reproduced using @swc/cli

```
> ./swc-darwin-x64 compile --source-file-name c.d.ts --config-file swcrc.json --source-maps true --out-file c.js c.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
```

```
> ./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
```
7 changes: 7 additions & 0 deletions examples/typeonly/a.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Foo } from "./b"
import { Bar } from "./c"

const a: Foo = 1
const b: Bar = 2

console.log(a, b)
1 change: 1 addition & 0 deletions examples/typeonly/b.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Foo = number
1 change: 1 addition & 0 deletions examples/typeonly/c.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Bar = number
Empty file added examples/typeonly/e.ts
Empty file.
6 changes: 6 additions & 0 deletions examples/typeonly/expected/a.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions examples/typeonly/expected/a.js.map.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sources": [
"../a.ts"
]
}
3 changes: 3 additions & 0 deletions examples/typeonly/expected/b.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions examples/typeonly/expected/b.js.map.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sources": [
"../b.ts"
]
}
30 changes: 30 additions & 0 deletions examples/typeonly/swcrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"sourceMaps": true,
"module": {
"type": "commonjs",
"strictMode": true,
"noInterop": true
},
"jsc": {
"externalHelpers": true,
"target": "es2015",
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": true,
"dynamicImport": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true,
"react": {
"throwIfNamespace": false,
"useBuiltins": false,
"pragma": "React.createElement",
"pragmaFrag": "React.Fragment",
"importSource": "react"
}
},
"keepClassNames": false
}
}
Loading