Skip to content

Commit 329d2ab

Browse files
committed
unisolating error surrounds when stx error happens in isolation
1 parent e9df3a0 commit 329d2ab

7 files changed

+18
-7
lines changed

examples/arrow-function-2.ts.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const foo = (x) => {
1818
### Output Program
1919

2020
```typescript
21-
const /*>>>*/ x /*<<<*/ = 13;
21+
const foo$1 = (x$2) => {
22+
const /*>>>*/ x /*<<<*/ = 13;
23+
};
2224
```
2325

examples/console-2.ts.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ consoel.log("hello world");
1515
### Output Program
1616

1717
```typescript
18-
consoel;
18+
/*>>>*/ consoel /*<<<*/
19+
.log("hello world");
1920
```
2021

src/library-manager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import stringify from "json-stringify-pretty-compact";
2121
import { init_global_context } from "./global-module";
2222
import { parse_dts } from "./parse-dts";
2323

24-
const cookie = "rewrite-ts-028";
24+
const cookie = "rewrite-ts-029";
2525

2626
type module_state =
2727
| { type: "initial" }

src/stx-error.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ export const in_isolation: <G extends { loc: Loc }>(
3232
loc: Loc,
3333
f: (loc: Loc) => Promise<G>,
3434
) => Promise<Omit<G, "loc"> & { loc: Loc }> = async (loc, f) => {
35-
return f(isolate(loc)).then(({ loc: res, ...g }) => ({ ...g, loc: unisolate(loc, res) }));
35+
return f(isolate(loc))
36+
.then(({ loc: res, ...g }) => ({ ...g, loc: unisolate(loc, res) }))
37+
.catch((err) => {
38+
if (err instanceof StxError) {
39+
throw new StxError(err.name, unisolate(loc, err.loc), err.error, err.info);
40+
} else {
41+
throw err;
42+
}
43+
});
3644
};
3745

3846
type LibraryManager = {

test-project/.rts/main.rts.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"cid": "test-project/main.rts rewrite-ts-visualized 0.0.0",
3-
"cookie": "rewrite-ts-028",
3+
"cookie": "rewrite-ts-029",
44
"imports": [
55
{
66
"pkg": {"name": "rewrite-ts-visualized", "version": "0.0.0"},

test-project/.rts/mod.rts.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"cid": "test-project/mod.rts rewrite-ts-visualized 0.0.0",
3-
"cookie": "rewrite-ts-028",
3+
"cookie": "rewrite-ts-029",
44
"imports": [],
55
"exported_identifiers": {
66
"x": [

test-project/.rts/sourcemap1.test.rts.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"cid": "test-project/sourcemap1.test.rts rewrite-ts-visualized 0.0.0",
3-
"cookie": "rewrite-ts-028",
3+
"cookie": "rewrite-ts-029",
44
"imports": [
55
{
66
"pkg": {"name": "vitest", "version": "2.1.8"},

0 commit comments

Comments
 (0)