Skip to content

Commit

Permalink
add typeonly example with crashing swcrc
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed Aug 16, 2023
1 parent 39bace9 commit 329a8c8
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 0 deletions.
39 changes: 39 additions & 0 deletions examples/typeonly/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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")

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

# 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
}
}

0 comments on commit 329a8c8

Please sign in to comment.