Skip to content

Commit 8f92617

Browse files
authored
Merge pull request #4 from maxmorozoff/ts-plugin
feat: introduce ts-plugin
2 parents 6b19af2 + 903e46f commit 8f92617

35 files changed

+2452
-207
lines changed

.changeset/lazy-insects-hammer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@maxmorozoff/try-catch-tuple": patch
3+
---
4+
5+
introduce branded tuple type

.changeset/slow-showers-matter.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@maxmorozoff/try-catch-tuple-ts-plugin": patch
3+
---
4+
5+
introduce ts plugin and transformer

LICENSE

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
MIT License
2-
3-
Copyright (c) 2025 Flowscripter
1+
The MIT License (MIT)
2+
Copyright (c) 2025 Max Morozov
43

54
Permission is hereby granted, free of charge, to any person obtaining a copy
65
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 341 additions & 118 deletions
Large diffs are not rendered by default.

biome.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"linter": {
2727
"enabled": true,
2828
"rules": {
29-
"recommended": true
29+
"recommended": true,
30+
"suspicious": { "noExplicitAny": "off" }
3031
}
3132
},
3233
"javascript": {

bun.lock

Lines changed: 112 additions & 32 deletions
Large diffs are not rendered by default.
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
2+
3+
# Logs
4+
5+
logs
6+
_.log
7+
npm-debug.log_
8+
yarn-debug.log*
9+
yarn-error.log*
10+
lerna-debug.log*
11+
.pnpm-debug.log*
12+
13+
# Caches
14+
15+
.cache
16+
17+
# Diagnostic reports (https://nodejs.org/api/report.html)
18+
19+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
20+
21+
# Runtime data
22+
23+
pids
24+
_.pid
25+
_.seed
26+
*.pid.lock
27+
28+
# Directory for instrumented libs generated by jscoverage/JSCover
29+
30+
lib-cov
31+
32+
# Coverage directory used by tools like istanbul
33+
34+
coverage
35+
*.lcov
36+
37+
# nyc test coverage
38+
39+
.nyc_output
40+
41+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
42+
43+
.grunt
44+
45+
# Bower dependency directory (https://bower.io/)
46+
47+
bower_components
48+
49+
# node-waf configuration
50+
51+
.lock-wscript
52+
53+
# Compiled binary addons (https://nodejs.org/api/addons.html)
54+
55+
build/Release
56+
57+
# Dependency directories
58+
59+
node_modules/
60+
jspm_packages/
61+
62+
# Snowpack dependency directory (https://snowpack.dev/)
63+
64+
web_modules/
65+
66+
# TypeScript cache
67+
68+
*.tsbuildinfo
69+
70+
# Optional npm cache directory
71+
72+
.npm
73+
74+
# Optional eslint cache
75+
76+
.eslintcache
77+
78+
# Optional stylelint cache
79+
80+
.stylelintcache
81+
82+
# Microbundle cache
83+
84+
.rpt2_cache/
85+
.rts2_cache_cjs/
86+
.rts2_cache_es/
87+
.rts2_cache_umd/
88+
89+
# Optional REPL history
90+
91+
.node_repl_history
92+
93+
# Output of 'npm pack'
94+
95+
*.tgz
96+
97+
# Yarn Integrity file
98+
99+
.yarn-integrity
100+
101+
# dotenv environment variable files
102+
103+
.env
104+
.env.development.local
105+
.env.test.local
106+
.env.production.local
107+
.env.local
108+
109+
# parcel-bundler cache (https://parceljs.org/)
110+
111+
.parcel-cache
112+
113+
# Next.js build output
114+
115+
.next
116+
out
117+
118+
# Nuxt.js build / generate output
119+
120+
.nuxt
121+
dist
122+
123+
# Gatsby files
124+
125+
# Comment in the public line in if your project uses Gatsby and not Next.js
126+
127+
# https://nextjs.org/blog/next-9-1#public-directory-support
128+
129+
# public
130+
131+
# vuepress build output
132+
133+
.vuepress/dist
134+
135+
# vuepress v2.x temp and cache directory
136+
137+
.temp
138+
139+
# Docusaurus cache and generated files
140+
141+
.docusaurus
142+
143+
# Serverless directories
144+
145+
.serverless/
146+
147+
# FuseBox cache
148+
149+
.fusebox/
150+
151+
# DynamoDB Local files
152+
153+
.dynamodb/
154+
155+
# TernJS port file
156+
157+
.tern-port
158+
159+
# Stores VSCode versions used for testing VSCode extensions
160+
161+
.vscode-test
162+
163+
# yarn v2
164+
165+
.yarn/cache
166+
.yarn/unplugged
167+
.yarn/build-state.yml
168+
.yarn/install-state.gz
169+
.pnp.*
170+
171+
# IntelliJ based IDEs
172+
.idea
173+
174+
# Finder (MacOS) folder config
175+
.DS_Store
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# test-ts-plugin
2+
3+
To install dependencies:
4+
5+
```bash
6+
bun install
7+
```
8+
9+
To run:
10+
11+
```bash
12+
bun run index.ts
13+
```
14+
15+
This project was created using `bun init` in bun v1.2.2. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { tryCatch } from "@maxmorozoff/try-catch-tuple";
2+
3+
{
4+
const [user, error] = tryCatch(parseUserJson('{"id":1}')); // ok
5+
}
6+
{
7+
const [user, ,] = tryCatch(parseUserJson('{"id":1}')); // ok
8+
}
9+
{
10+
const [user] = tryCatch(parseUserJson('{"id":1}'));
11+
}
12+
{
13+
const wrappedTryCatch = () => tryCatch(parseUserJson('{"id":1}'));
14+
const [user] = wrappedTryCatch();
15+
}
16+
{
17+
const wrappedTryCatch = () => tryCatch(fetchMeUser);
18+
const user = await wrappedTryCatch();
19+
}
20+
21+
{
22+
const [result] = await tryCatch(fetchMeUser);
23+
}
24+
{
25+
const result = tryCatch(() => null);
26+
}
27+
function foo() {
28+
const result = tryCatch(() => null);
29+
}
30+
const bar = () => {
31+
const result = tryCatch(() => null);
32+
};
33+
// const data = tryCatch(() => null);
34+
// let data1 = tryCatch(() => null);
35+
// export const result = tryCatch(() => null);
36+
37+
{
38+
{
39+
const [result] = tryCatch(() => null);
40+
}
41+
{
42+
// biome-ignore lint/complexity/noUselessLoneBlockStatements:
43+
// biome-ignore lint/style/noVar:
44+
// biome-ignore lint/correctness/noInnerDeclarations:
45+
var [result] = tryCatch(() => null);
46+
}
47+
{
48+
// biome-ignore lint/style/useSingleVarDeclarator:
49+
const foo = "bar",
50+
[result] = tryCatch(() => null);
51+
}
52+
{
53+
const wrappedTryCatch = () => tryCatch(() => null);
54+
const [result] = wrappedTryCatch();
55+
}
56+
{
57+
const wrappedTryCatch = () => tryCatch(async () => null);
58+
const [result] = await wrappedTryCatch();
59+
}
60+
{
61+
const [result] = await tryCatch(async () => null);
62+
}
63+
{
64+
const result = tryCatch(() => null);
65+
}
66+
function foo() {
67+
const result = tryCatch(() => null);
68+
}
69+
const bar = () => {
70+
const result = tryCatch(() => null);
71+
};
72+
const data = tryCatch(() => null);
73+
// biome-ignore lint/style/useConst: <explanation>
74+
let data1 = tryCatch(() => null);
75+
const result = tryCatch(() => null);
76+
}
77+
78+
type User = { id: number };
79+
async function fetchMeUser() {
80+
return {} as User;
81+
}
82+
function parseUserJson(jsonString: string) {
83+
return () => JSON.parse(jsonString) as User;
84+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "test-ts-plugin",
3+
"private": true,
4+
"license": "MIT",
5+
"author": "Max Morozov <[email protected]",
6+
"homepage": "https://github.com/maxmorozoff/try-catch-tuple#readme",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/maxmorozoff/try-catch-tuple.git"
10+
},
11+
"type": "module",
12+
"scripts": {
13+
"test:unit": "bun test",
14+
"test:types": "tspc --project ./tsconfig.transformer.json",
15+
"clean": "rm -rf out && echo done"
16+
},
17+
"dependencies": {
18+
"@maxmorozoff/try-catch-tuple": "workspace:*",
19+
"@maxmorozoff/try-catch-tuple-ts-plugin": "workspace:*"
20+
},
21+
"devDependencies": {
22+
"@types/bun": "^1.2.5",
23+
"ts-patch": "^3.3.0",
24+
"typescript": "^5.0.0"
25+
}
26+
}

0 commit comments

Comments
 (0)