Skip to content

Commit 1d03c03

Browse files
committed
chore: format
1 parent 11aba81 commit 1d03c03

33 files changed

Lines changed: 5102 additions & 4520 deletions

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</h5>
1111

1212
## To-do
13+
1314
- [ ] Handle all (`abort/throw/unreachable`) exceptions
1415
- [ ] Handle exceptions within functions or blocks
1516
- [ ] Handle nested (multiple) exceptions
@@ -43,7 +44,7 @@ Alternatively, add it to your `asconfig.json`
4344
```json
4445
{
4546
// ...
46-
"options": {"transform": ["as-try/transform"]}
47+
"options": { "transform": ["as-try/transform"] }
4748
}
4849
```
4950

@@ -52,6 +53,7 @@ If you'd like to see the code that the transform generates, run the build step w
5253
## 🪄 Usage
5354

5455
This library does all the work behind-the-scenes, so you, the developer, can use the classic `try/catch/finalize` syntax with no changes!
56+
5557
```js
5658
try {
5759
// Do something

assembly/__tests__/abort.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@ describe("Should catch abort in nested try block", () => {
108108
// This block should not be reached
109109
expect("Final Catch").toBe("This should not execute");
110110
}
111-
});
111+
});

assembly/test.transformed.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ import { ExceptionState, Exception } from "./types/exception";
2020
// }
2121
export function example(): void {
2222
do {
23-
console.log("Hey")
23+
console.log("Hey");
2424
if (true) break;
25-
console.log("skipped")
26-
} while (0)
25+
console.log("skipped");
26+
} while (0);
2727

28-
console.log('LOL')
28+
console.log("LOL");
2929
}
3030

31-
3231
function doSomething(shouldAbort: boolean = false): string {
3332
doSomethingElse(shouldAbort);
3433
if (ExceptionState.Failed) return changetype<string>(4294967295);
@@ -47,8 +46,8 @@ function doSomethingElse(shouldAbort: boolean = false): void {
4746
// 2nd Level Abort
4847
ExceptionState.Failed = false;
4948
{
50-
const foo = doSomething((false));
51-
if (!ExceptionState.Failed){
49+
const foo = doSomething(false);
50+
if (!ExceptionState.Failed) {
5251
console.log(foo);
5352
}
5453
}
@@ -60,4 +59,4 @@ if (ExceptionState.Failed) {
6059
{
6160
console.log("Finished");
6261
}
63-
}
62+
}

assembly/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ try {
3030
// } finally {
3131
// console.log("Gracefully shutting down...");
3232
// process.exit(0);
33-
// }
33+
// }

assembly/tsconfig.json

Lines changed: 96 additions & 98 deletions
Large diffs are not rendered by default.

assembly/types/exception.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export enum ExceptionType {
55
None,
66
Abort,
77
Error,
8-
Unreachable
8+
Unreachable,
99
}
1010

1111
export namespace ExceptionState {
@@ -35,10 +35,11 @@ export class Exception {
3535
out = "abort";
3636
if (AbortState.msg) out += ": " + AbortState.msg!;
3737
if (AbortState.fileName) out += " in " + AbortState.fileName!;
38-
if (AbortState.lineNumber) out += ` in (${AbortState.lineNumber}:${AbortState.columnNumber})`;
38+
if (AbortState.lineNumber)
39+
out += ` in (${AbortState.lineNumber}:${AbortState.columnNumber})`;
3940
} else if (this.type == ExceptionType.Error) {
4041
out = "Error: " + ErrorState.message;
4142
}
4243
return out;
4344
}
44-
}
45+
}

index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
try {
2-
console.log("try");
3-
throw 1234
2+
console.log("try");
3+
throw 1234;
44
} catch (e) {
5-
console.log("error")
6-
console.log(e)
5+
console.log("error");
6+
console.log(e);
77
} finally {
8-
console.log("finally")
9-
}
8+
console.log("finally");
9+
}

0 commit comments

Comments
 (0)